Util
import mathy_core.util
compare_equation_values¶
compare_equation_values(
from_expression: mathy_core.expressions.MathExpression,
to_expression: mathy_core.expressions.MathExpression,
eval_context: Dict[str, Union[float, int]],
) -> None
Raises ValueError if the equations do not hold when evaluated with the given context.
compare_expression_string_values¶
compare_expression_string_values(
from_expression: str,
to_expression: str,
history: Optional[List[Any]] = None,
) -> None
compare_expression_values¶
compare_expression_values(
from_expression: mathy_core.expressions.MathExpression,
to_expression: mathy_core.expressions.MathExpression,
history: Optional[List[Any]] = None,
) -> None
factor¶
factor(value: Union[float, int]) -> Dict[Union[float, int], Union[float, int]]
This builds a dictionary of factors for a given value that contains both arrangements of terms so that all factors are accessible by key. That is, factoring 2 would return result = { 1 : 2 2 : 1 }
get_term_ex¶
get_term_ex(
node: Optional[mathy_core.expressions.MathExpression],
) -> Optional[mathy_core.util.TermEx]
Info
This doesn't care about whether the node is part of a larger term, it only looks at its children.
Example
TermEx(coefficient=4, variable="x", exponent=7)
get_terms¶
get_terms(
expression: mathy_core.expressions.MathExpression,
) -> List[mathy_core.expressions.MathExpression]
Arguments
- expression (MathExpression): the expression to find term nodes in
Returns
(List[MathExpression])
: a list of term nodes
has_like_terms¶
has_like_terms(expression: mathy_core.expressions.MathExpression) -> bool
Examples
x + y + z
=False
x^2 + x
=False
y + 2x
=True
x^2 + 4x^3 + 2y
=True
is_add_or_sub¶
is_add_or_sub(node: mathy_core.expressions.MathExpression) -> bool
is_debug_mode¶
is_debug_mode() -> bool
is_preferred_term_form¶
is_preferred_term_form(expression: mathy_core.expressions.MathExpression) -> bool
Return True if a given term has been simplified so that it only has a max of one coefficient and variable, with the variable on the right and the coefficient on the left side
Examples
- Complex = 2 * 2x^2
- Simple = x^2 * 4
- Preferred = 4x^2
is_simple_term¶
is_simple_term(node: mathy_core.expressions.MathExpression) -> bool
Examples
- Simple = 2x^2 * 2y
- Complex = 2x * 2x * 2y
- Simple = x^2 * 4
- Complex = 2 * 2x^2
pad_array¶
pad_array(in_list: List[Any], max_length: int, value: Any = 0) -> List[Any]
Arguments:
in_list (List[Any]): List of values to pad to the given length max_length (int): The desired length of the array value (Any): a value to insert in order to pad the array to max length
Returns
(List[Any])
: An array padded to max_length
size
TermEx¶
TermEx(self, args, kwargs)
coefficient¶
An optional integer or float coefficient
exponent¶
An optional integer or float exponent
variable¶
An optional variable
terms_are_like¶
terms_are_like(
one: Union[mathy_core.util.TermResult, mathy_core.expressions.MathExpression, Literal[False]],
two: Union[mathy_core.util.TermResult, mathy_core.expressions.MathExpression, Literal[False]],
) -> bool
Arguments
- one (MathExpression): A math expression that represents a term
- two (MathExpression): Another math expression that represents a term
Returns
(bool)
: Whether the terms are like or not.
unlink¶
unlink(
node: Optional[mathy_core.expressions.MathExpression] = None,
) -> Optional[mathy_core.expressions.MathExpression]
- Clear expression references in
parent
- Clear
parent
in expression