Class representing the MathML <power> operator.
Definition at line 5692 of file pycml.py.
def CellMLToNektar.pycml.mathml_power._reduce |
( |
|
self | ) |
|
|
private |
Reduce this expression by evaluating its static parts.
If the whole expression is static, proceed as normal for an <apply>.
Otherwise check if the exponent is static and the expression being exponentiated
is a <ci>. If so, and the exponent is equal to 2, 3, or 4, convert the expression
to a multiplication.
Definition at line 5728 of file pycml.py.
References CellMLToNektar.pycml.mathml.eval().
5730 """Reduce this expression by evaluating its static parts.
5732 If the whole expression is static, proceed as normal for an <apply>.
5733 Otherwise check if the exponent is static and the expression being exponentiated
5734 is a <ci>. If so, and the exponent is equal to 2, 3, or 4, convert the expression
5735 to a multiplication.
5737 app = self.xml_parent
5738 bt = app._get_binding_time()
5740 if bt != BINDING_TIMES.static
and self.model.get_option(
'pe_convert_power'):
5741 base, expt = list(app.operands())
5742 expt_bt = app._get_element_binding_time(expt)
5743 if expt_bt == BINDING_TIMES.static
and isinstance(base, mathml_ci):
5744 expt_val = self.
eval(expt)
5745 if expt_val
in [2,3,4]:
5747 app.safe_remove_child(base)
5749 for _
in range(1, expt_val):
5750 operands.append(base.clone_self())
5751 base.variable._used()
5752 new_app = mathml_apply.create_new(app,
u'times', operands)
5753 app.replace_child(app, new_app, app.xml_parent)
5759 app._reduce(check_operator=
False)