Expressions
import mathy_core.expressions
AbsExpression¶
AbsExpression(
self,
child: Optional[mathy_core.expressions.MathExpression] = None,
child_on_left: bool = False,
)
AddExpression¶
AddExpression(
self,
left: Optional[mathy_core.expressions.MathExpression] = None,
right: Optional[mathy_core.expressions.MathExpression] = None,
)
BinaryExpression¶
BinaryExpression(
self,
left: Optional[mathy_core.expressions.MathExpression] = None,
right: Optional[mathy_core.expressions.MathExpression] = None,
)
get_priority¶
BinaryExpression.get_priority(self) -> int
locked
with respect to another node, i.e. the other node must be resolved first during evaluation because of it's priority. to_math_ml_fragment¶
BinaryExpression.to_math_ml_fragment(self) -> str
ConstantExpression¶
ConstantExpression(self, value: Optional[float, int] = None)
node.value
DivideExpression¶
DivideExpression(
self,
left: Optional[mathy_core.expressions.MathExpression] = None,
right: Optional[mathy_core.expressions.MathExpression] = None,
)
EqualExpression¶
EqualExpression(
self,
left: Optional[mathy_core.expressions.MathExpression] = None,
right: Optional[mathy_core.expressions.MathExpression] = None,
)
operate¶
EqualExpression.operate(
self,
one: Union[float, int],
two: Union[float, int],
) -> Union[float, int]
Raise ValueError if both sides of the equation don't agree.
FactorialExpression¶
FactorialExpression(
self,
child: Optional[mathy_core.expressions.MathExpression] = None,
child_on_left: bool = False,
)
5
evaluates to 120
FunctionExpression¶
FunctionExpression(
self,
child: Optional[mathy_core.expressions.MathExpression] = None,
child_on_left: bool = False,
)
MathExpression¶
MathExpression(
self,
id: Optional[str] = None,
left: Optional[MathExpression] = None,
right: Optional[MathExpression] = None,
parent: Optional[MathExpression] = None,
)
add_class¶
MathExpression.add_class(
self,
classes: Union[List[str], str],
) -> 'MathExpression'
See MathExpression.to_math_ml_fragment
all_changed¶
MathExpression.all_changed(self) -> None
clear_classes¶
MathExpression.clear_classes(self) -> None
clone¶
MathExpression.clone(self) -> 'MathExpression'
See MathExpression.clone_from_root
for more details.
clone_from_root¶
MathExpression.clone_from_root(
self,
node: Optional[MathExpression] = None,
) -> 'MathExpression'
Arguments
- node (MathExpression): The node to clone.
Returns
(MathExpression)
: The cloned node.
color¶
Color to use for this node when rendering it as changed with .terminal_text
evaluate¶
MathExpression.evaluate(
self,
context: Optional[Dict[str, Union[float, int]]] = None,
) -> Union[float, int]
find_id¶
MathExpression.find_id(self, id: str) -> Optional[MathExpression]
Returns: The found MathExpression
or None
find_type¶
MathExpression.find_type(self, instanceType: Type[~NodeType]) -> List[~NodeType]
- instanceType: The type to check for instances of
Returns the found MathExpression
objects of the given type.
make_ml_tag¶
MathExpression.make_ml_tag(
self,
tag: str,
content: str,
classes: List[str] = [],
) -> str
Arguments
- tag (str): The ML tag name to create.
- content (str): The ML content to place inside of the tag. classes (List[str]) An array of classes to attach to this tag.
Returns
(str)
: A MathML element with the given tag, content, and classes
path_to_root¶
MathExpression.path_to_root(self) -> str
raw¶
raw text representation of the expression.
set_changed¶
MathExpression.set_changed(self) -> None
terminal_text¶
Text output of this node that includes terminal color codes that highlight which nodes have been changed in this tree as a result of a transformation.
to_list¶
MathExpression.to_list(
self,
visit: str = 'preorder',
) -> List[MathExpression]
to_math_ml¶
MathExpression.to_math_ml(self) -> str
to_math_ml_fragment¶
MathExpression.to_math_ml_fragment(self) -> str
with_color¶
MathExpression.with_color(self, text: str, style: str = 'bright') -> str
MultiplyExpression¶
MultiplyExpression(
self,
left: Optional[mathy_core.expressions.MathExpression] = None,
right: Optional[mathy_core.expressions.MathExpression] = None,
)
NegateExpression¶
NegateExpression(
self,
child: Optional[mathy_core.expressions.MathExpression] = None,
child_on_left: bool = False,
)
4
becomes -4
to_math_ml_fragment¶
NegateExpression.to_math_ml_fragment(self) -> str
PowerExpression¶
PowerExpression(
self,
left: Optional[mathy_core.expressions.MathExpression] = None,
right: Optional[mathy_core.expressions.MathExpression] = None,
)
SgnExpression¶
SgnExpression(
self,
child: Optional[mathy_core.expressions.MathExpression] = None,
child_on_left: bool = False,
)
operate¶
SgnExpression.operate(self, value: Union[float, int]) -> Union[float, int]
Returns
(int)
: -1 if negative, 1 if positive, 0 if 0
SubtractExpression¶
SubtractExpression(
self,
left: Optional[mathy_core.expressions.MathExpression] = None,
right: Optional[mathy_core.expressions.MathExpression] = None,
)
UnaryExpression¶
UnaryExpression(
self,
child: Optional[mathy_core.expressions.MathExpression] = None,
child_on_left: bool = False,
)