You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2047 lines
94 KiB
2047 lines
94 KiB
5 months ago
|
from sympy.calculus.accumulationbounds import AccumBounds
|
||
|
from sympy.concrete.summations import Sum
|
||
|
from sympy.core.basic import Basic
|
||
|
from sympy.core.containers import Tuple
|
||
|
from sympy.core.function import Derivative, Lambda, diff, Function
|
||
|
from sympy.core.numbers import (zoo, Float, Integer, I, oo, pi, E,
|
||
|
Rational)
|
||
|
from sympy.core.relational import Lt, Ge, Ne, Eq
|
||
|
from sympy.core.singleton import S
|
||
|
from sympy.core.symbol import symbols, Symbol
|
||
|
from sympy.core.sympify import sympify
|
||
|
from sympy.functions.combinatorial.factorials import (factorial2,
|
||
|
binomial, factorial)
|
||
|
from sympy.functions.combinatorial.numbers import (lucas, bell,
|
||
|
catalan, euler, tribonacci, fibonacci, bernoulli)
|
||
|
from sympy.functions.elementary.complexes import re, im, conjugate, Abs
|
||
|
from sympy.functions.elementary.exponential import exp, LambertW, log
|
||
|
from sympy.functions.elementary.hyperbolic import (tanh, acoth, atanh,
|
||
|
coth, asinh, acsch, asech, acosh, csch, sinh, cosh, sech)
|
||
|
from sympy.functions.elementary.integers import ceiling, floor
|
||
|
from sympy.functions.elementary.miscellaneous import Max, Min
|
||
|
from sympy.functions.elementary.trigonometric import (csc, sec, tan,
|
||
|
atan, sin, asec, cot, cos, acot, acsc, asin, acos)
|
||
|
from sympy.functions.special.delta_functions import Heaviside
|
||
|
from sympy.functions.special.elliptic_integrals import (elliptic_pi,
|
||
|
elliptic_f, elliptic_k, elliptic_e)
|
||
|
from sympy.functions.special.error_functions import (fresnelc,
|
||
|
fresnels, Ei, expint)
|
||
|
from sympy.functions.special.gamma_functions import (gamma, uppergamma,
|
||
|
lowergamma)
|
||
|
from sympy.functions.special.mathieu_functions import (mathieusprime,
|
||
|
mathieus, mathieucprime, mathieuc)
|
||
|
from sympy.functions.special.polynomials import (jacobi, chebyshevu,
|
||
|
chebyshevt, hermite, assoc_legendre, gegenbauer, assoc_laguerre,
|
||
|
legendre, laguerre)
|
||
|
from sympy.functions.special.singularity_functions import SingularityFunction
|
||
|
from sympy.functions.special.zeta_functions import (polylog, stieltjes,
|
||
|
lerchphi, dirichlet_eta, zeta)
|
||
|
from sympy.integrals.integrals import Integral
|
||
|
from sympy.logic.boolalg import (Xor, Or, false, true, And, Equivalent,
|
||
|
Implies, Not)
|
||
|
from sympy.matrices.dense import Matrix
|
||
|
from sympy.matrices.expressions.determinant import Determinant
|
||
|
from sympy.matrices.expressions.matexpr import MatrixSymbol
|
||
|
from sympy.ntheory.factor_ import (totient, reduced_totient, primenu,
|
||
|
primeomega)
|
||
|
from sympy.physics.quantum import (ComplexSpace, FockSpace, hbar,
|
||
|
HilbertSpace, Dagger)
|
||
|
from sympy.printing.mathml import (MathMLPresentationPrinter,
|
||
|
MathMLPrinter, MathMLContentPrinter, mathml)
|
||
|
from sympy.series.limits import Limit
|
||
|
from sympy.sets.contains import Contains
|
||
|
from sympy.sets.fancysets import Range
|
||
|
from sympy.sets.sets import (Interval, Union, SymmetricDifference,
|
||
|
Complement, FiniteSet, Intersection, ProductSet)
|
||
|
from sympy.stats.rv import RandomSymbol
|
||
|
from sympy.tensor.indexed import IndexedBase
|
||
|
from sympy.vector import (Divergence, CoordSys3D, Cross, Curl, Dot,
|
||
|
Laplacian, Gradient)
|
||
|
from sympy.testing.pytest import raises
|
||
|
|
||
|
x, y, z, a, b, c, d, e, n = symbols('x:z a:e n')
|
||
|
mp = MathMLContentPrinter()
|
||
|
mpp = MathMLPresentationPrinter()
|
||
|
|
||
|
|
||
|
def test_mathml_printer():
|
||
|
m = MathMLPrinter()
|
||
|
assert m.doprint(1+x) == mp.doprint(1+x)
|
||
|
|
||
|
|
||
|
def test_content_printmethod():
|
||
|
assert mp.doprint(1 + x) == '<apply><plus/><ci>x</ci><cn>1</cn></apply>'
|
||
|
|
||
|
|
||
|
def test_content_mathml_core():
|
||
|
mml_1 = mp._print(1 + x)
|
||
|
assert mml_1.nodeName == 'apply'
|
||
|
nodes = mml_1.childNodes
|
||
|
assert len(nodes) == 3
|
||
|
assert nodes[0].nodeName == 'plus'
|
||
|
assert nodes[0].hasChildNodes() is False
|
||
|
assert nodes[0].nodeValue is None
|
||
|
assert nodes[1].nodeName in ['cn', 'ci']
|
||
|
if nodes[1].nodeName == 'cn':
|
||
|
assert nodes[1].childNodes[0].nodeValue == '1'
|
||
|
assert nodes[2].childNodes[0].nodeValue == 'x'
|
||
|
else:
|
||
|
assert nodes[1].childNodes[0].nodeValue == 'x'
|
||
|
assert nodes[2].childNodes[0].nodeValue == '1'
|
||
|
|
||
|
mml_2 = mp._print(x**2)
|
||
|
assert mml_2.nodeName == 'apply'
|
||
|
nodes = mml_2.childNodes
|
||
|
assert nodes[1].childNodes[0].nodeValue == 'x'
|
||
|
assert nodes[2].childNodes[0].nodeValue == '2'
|
||
|
|
||
|
mml_3 = mp._print(2*x)
|
||
|
assert mml_3.nodeName == 'apply'
|
||
|
nodes = mml_3.childNodes
|
||
|
assert nodes[0].nodeName == 'times'
|
||
|
assert nodes[1].childNodes[0].nodeValue == '2'
|
||
|
assert nodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
mml = mp._print(Float(1.0, 2)*x)
|
||
|
assert mml.nodeName == 'apply'
|
||
|
nodes = mml.childNodes
|
||
|
assert nodes[0].nodeName == 'times'
|
||
|
assert nodes[1].childNodes[0].nodeValue == '1.0'
|
||
|
assert nodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
|
||
|
def test_content_mathml_functions():
|
||
|
mml_1 = mp._print(sin(x))
|
||
|
assert mml_1.nodeName == 'apply'
|
||
|
assert mml_1.childNodes[0].nodeName == 'sin'
|
||
|
assert mml_1.childNodes[1].nodeName == 'ci'
|
||
|
|
||
|
mml_2 = mp._print(diff(sin(x), x, evaluate=False))
|
||
|
assert mml_2.nodeName == 'apply'
|
||
|
assert mml_2.childNodes[0].nodeName == 'diff'
|
||
|
assert mml_2.childNodes[1].nodeName == 'bvar'
|
||
|
assert mml_2.childNodes[1].childNodes[
|
||
|
0].nodeName == 'ci' # below bvar there's <ci>x/ci>
|
||
|
|
||
|
mml_3 = mp._print(diff(cos(x*y), x, evaluate=False))
|
||
|
assert mml_3.nodeName == 'apply'
|
||
|
assert mml_3.childNodes[0].nodeName == 'partialdiff'
|
||
|
assert mml_3.childNodes[1].nodeName == 'bvar'
|
||
|
assert mml_3.childNodes[1].childNodes[
|
||
|
0].nodeName == 'ci' # below bvar there's <ci>x/ci>
|
||
|
|
||
|
|
||
|
def test_content_mathml_limits():
|
||
|
# XXX No unevaluated limits
|
||
|
lim_fun = sin(x)/x
|
||
|
mml_1 = mp._print(Limit(lim_fun, x, 0))
|
||
|
assert mml_1.childNodes[0].nodeName == 'limit'
|
||
|
assert mml_1.childNodes[1].nodeName == 'bvar'
|
||
|
assert mml_1.childNodes[2].nodeName == 'lowlimit'
|
||
|
assert mml_1.childNodes[3].toxml() == mp._print(lim_fun).toxml()
|
||
|
|
||
|
|
||
|
def test_content_mathml_integrals():
|
||
|
integrand = x
|
||
|
mml_1 = mp._print(Integral(integrand, (x, 0, 1)))
|
||
|
assert mml_1.childNodes[0].nodeName == 'int'
|
||
|
assert mml_1.childNodes[1].nodeName == 'bvar'
|
||
|
assert mml_1.childNodes[2].nodeName == 'lowlimit'
|
||
|
assert mml_1.childNodes[3].nodeName == 'uplimit'
|
||
|
assert mml_1.childNodes[4].toxml() == mp._print(integrand).toxml()
|
||
|
|
||
|
|
||
|
def test_content_mathml_matrices():
|
||
|
A = Matrix([1, 2, 3])
|
||
|
B = Matrix([[0, 5, 4], [2, 3, 1], [9, 7, 9]])
|
||
|
mll_1 = mp._print(A)
|
||
|
assert mll_1.childNodes[0].nodeName == 'matrixrow'
|
||
|
assert mll_1.childNodes[0].childNodes[0].nodeName == 'cn'
|
||
|
assert mll_1.childNodes[0].childNodes[0].childNodes[0].nodeValue == '1'
|
||
|
assert mll_1.childNodes[1].nodeName == 'matrixrow'
|
||
|
assert mll_1.childNodes[1].childNodes[0].nodeName == 'cn'
|
||
|
assert mll_1.childNodes[1].childNodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert mll_1.childNodes[2].nodeName == 'matrixrow'
|
||
|
assert mll_1.childNodes[2].childNodes[0].nodeName == 'cn'
|
||
|
assert mll_1.childNodes[2].childNodes[0].childNodes[0].nodeValue == '3'
|
||
|
mll_2 = mp._print(B)
|
||
|
assert mll_2.childNodes[0].nodeName == 'matrixrow'
|
||
|
assert mll_2.childNodes[0].childNodes[0].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[0].childNodes[0].childNodes[0].nodeValue == '0'
|
||
|
assert mll_2.childNodes[0].childNodes[1].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[0].childNodes[1].childNodes[0].nodeValue == '5'
|
||
|
assert mll_2.childNodes[0].childNodes[2].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[0].childNodes[2].childNodes[0].nodeValue == '4'
|
||
|
assert mll_2.childNodes[1].nodeName == 'matrixrow'
|
||
|
assert mll_2.childNodes[1].childNodes[0].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[1].childNodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert mll_2.childNodes[1].childNodes[1].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[1].childNodes[1].childNodes[0].nodeValue == '3'
|
||
|
assert mll_2.childNodes[1].childNodes[2].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[1].childNodes[2].childNodes[0].nodeValue == '1'
|
||
|
assert mll_2.childNodes[2].nodeName == 'matrixrow'
|
||
|
assert mll_2.childNodes[2].childNodes[0].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[2].childNodes[0].childNodes[0].nodeValue == '9'
|
||
|
assert mll_2.childNodes[2].childNodes[1].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[2].childNodes[1].childNodes[0].nodeValue == '7'
|
||
|
assert mll_2.childNodes[2].childNodes[2].nodeName == 'cn'
|
||
|
assert mll_2.childNodes[2].childNodes[2].childNodes[0].nodeValue == '9'
|
||
|
|
||
|
|
||
|
def test_content_mathml_sums():
|
||
|
summand = x
|
||
|
mml_1 = mp._print(Sum(summand, (x, 1, 10)))
|
||
|
assert mml_1.childNodes[0].nodeName == 'sum'
|
||
|
assert mml_1.childNodes[1].nodeName == 'bvar'
|
||
|
assert mml_1.childNodes[2].nodeName == 'lowlimit'
|
||
|
assert mml_1.childNodes[3].nodeName == 'uplimit'
|
||
|
assert mml_1.childNodes[4].toxml() == mp._print(summand).toxml()
|
||
|
|
||
|
|
||
|
def test_content_mathml_tuples():
|
||
|
mml_1 = mp._print([2])
|
||
|
assert mml_1.nodeName == 'list'
|
||
|
assert mml_1.childNodes[0].nodeName == 'cn'
|
||
|
assert len(mml_1.childNodes) == 1
|
||
|
|
||
|
mml_2 = mp._print([2, Integer(1)])
|
||
|
assert mml_2.nodeName == 'list'
|
||
|
assert mml_2.childNodes[0].nodeName == 'cn'
|
||
|
assert mml_2.childNodes[1].nodeName == 'cn'
|
||
|
assert len(mml_2.childNodes) == 2
|
||
|
|
||
|
|
||
|
def test_content_mathml_add():
|
||
|
mml = mp._print(x**5 - x**4 + x)
|
||
|
assert mml.childNodes[0].nodeName == 'plus'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeName == 'minus'
|
||
|
assert mml.childNodes[1].childNodes[1].nodeName == 'apply'
|
||
|
|
||
|
|
||
|
def test_content_mathml_Rational():
|
||
|
mml_1 = mp._print(Rational(1, 1))
|
||
|
"""should just return a number"""
|
||
|
assert mml_1.nodeName == 'cn'
|
||
|
|
||
|
mml_2 = mp._print(Rational(2, 5))
|
||
|
assert mml_2.childNodes[0].nodeName == 'divide'
|
||
|
|
||
|
|
||
|
def test_content_mathml_constants():
|
||
|
mml = mp._print(I)
|
||
|
assert mml.nodeName == 'imaginaryi'
|
||
|
|
||
|
mml = mp._print(E)
|
||
|
assert mml.nodeName == 'exponentiale'
|
||
|
|
||
|
mml = mp._print(oo)
|
||
|
assert mml.nodeName == 'infinity'
|
||
|
|
||
|
mml = mp._print(pi)
|
||
|
assert mml.nodeName == 'pi'
|
||
|
|
||
|
assert mathml(hbar) == '<hbar/>'
|
||
|
assert mathml(S.TribonacciConstant) == '<tribonacciconstant/>'
|
||
|
assert mathml(S.GoldenRatio) == '<cn>φ</cn>'
|
||
|
mml = mathml(S.EulerGamma)
|
||
|
assert mml == '<eulergamma/>'
|
||
|
|
||
|
mml = mathml(S.EmptySet)
|
||
|
assert mml == '<emptyset/>'
|
||
|
|
||
|
mml = mathml(S.true)
|
||
|
assert mml == '<true/>'
|
||
|
|
||
|
mml = mathml(S.false)
|
||
|
assert mml == '<false/>'
|
||
|
|
||
|
mml = mathml(S.NaN)
|
||
|
assert mml == '<notanumber/>'
|
||
|
|
||
|
|
||
|
def test_content_mathml_trig():
|
||
|
mml = mp._print(sin(x))
|
||
|
assert mml.childNodes[0].nodeName == 'sin'
|
||
|
|
||
|
mml = mp._print(cos(x))
|
||
|
assert mml.childNodes[0].nodeName == 'cos'
|
||
|
|
||
|
mml = mp._print(tan(x))
|
||
|
assert mml.childNodes[0].nodeName == 'tan'
|
||
|
|
||
|
mml = mp._print(cot(x))
|
||
|
assert mml.childNodes[0].nodeName == 'cot'
|
||
|
|
||
|
mml = mp._print(csc(x))
|
||
|
assert mml.childNodes[0].nodeName == 'csc'
|
||
|
|
||
|
mml = mp._print(sec(x))
|
||
|
assert mml.childNodes[0].nodeName == 'sec'
|
||
|
|
||
|
mml = mp._print(asin(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arcsin'
|
||
|
|
||
|
mml = mp._print(acos(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arccos'
|
||
|
|
||
|
mml = mp._print(atan(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arctan'
|
||
|
|
||
|
mml = mp._print(acot(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arccot'
|
||
|
|
||
|
mml = mp._print(acsc(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arccsc'
|
||
|
|
||
|
mml = mp._print(asec(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arcsec'
|
||
|
|
||
|
mml = mp._print(sinh(x))
|
||
|
assert mml.childNodes[0].nodeName == 'sinh'
|
||
|
|
||
|
mml = mp._print(cosh(x))
|
||
|
assert mml.childNodes[0].nodeName == 'cosh'
|
||
|
|
||
|
mml = mp._print(tanh(x))
|
||
|
assert mml.childNodes[0].nodeName == 'tanh'
|
||
|
|
||
|
mml = mp._print(coth(x))
|
||
|
assert mml.childNodes[0].nodeName == 'coth'
|
||
|
|
||
|
mml = mp._print(csch(x))
|
||
|
assert mml.childNodes[0].nodeName == 'csch'
|
||
|
|
||
|
mml = mp._print(sech(x))
|
||
|
assert mml.childNodes[0].nodeName == 'sech'
|
||
|
|
||
|
mml = mp._print(asinh(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arcsinh'
|
||
|
|
||
|
mml = mp._print(atanh(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arctanh'
|
||
|
|
||
|
mml = mp._print(acosh(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arccosh'
|
||
|
|
||
|
mml = mp._print(acoth(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arccoth'
|
||
|
|
||
|
mml = mp._print(acsch(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arccsch'
|
||
|
|
||
|
mml = mp._print(asech(x))
|
||
|
assert mml.childNodes[0].nodeName == 'arcsech'
|
||
|
|
||
|
|
||
|
def test_content_mathml_relational():
|
||
|
mml_1 = mp._print(Eq(x, 1))
|
||
|
assert mml_1.nodeName == 'apply'
|
||
|
assert mml_1.childNodes[0].nodeName == 'eq'
|
||
|
assert mml_1.childNodes[1].nodeName == 'ci'
|
||
|
assert mml_1.childNodes[1].childNodes[0].nodeValue == 'x'
|
||
|
assert mml_1.childNodes[2].nodeName == 'cn'
|
||
|
assert mml_1.childNodes[2].childNodes[0].nodeValue == '1'
|
||
|
|
||
|
mml_2 = mp._print(Ne(1, x))
|
||
|
assert mml_2.nodeName == 'apply'
|
||
|
assert mml_2.childNodes[0].nodeName == 'neq'
|
||
|
assert mml_2.childNodes[1].nodeName == 'cn'
|
||
|
assert mml_2.childNodes[1].childNodes[0].nodeValue == '1'
|
||
|
assert mml_2.childNodes[2].nodeName == 'ci'
|
||
|
assert mml_2.childNodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
mml_3 = mp._print(Ge(1, x))
|
||
|
assert mml_3.nodeName == 'apply'
|
||
|
assert mml_3.childNodes[0].nodeName == 'geq'
|
||
|
assert mml_3.childNodes[1].nodeName == 'cn'
|
||
|
assert mml_3.childNodes[1].childNodes[0].nodeValue == '1'
|
||
|
assert mml_3.childNodes[2].nodeName == 'ci'
|
||
|
assert mml_3.childNodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
mml_4 = mp._print(Lt(1, x))
|
||
|
assert mml_4.nodeName == 'apply'
|
||
|
assert mml_4.childNodes[0].nodeName == 'lt'
|
||
|
assert mml_4.childNodes[1].nodeName == 'cn'
|
||
|
assert mml_4.childNodes[1].childNodes[0].nodeValue == '1'
|
||
|
assert mml_4.childNodes[2].nodeName == 'ci'
|
||
|
assert mml_4.childNodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
|
||
|
def test_content_symbol():
|
||
|
mml = mp._print(x)
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeValue == 'x'
|
||
|
del mml
|
||
|
|
||
|
mml = mp._print(Symbol("x^2"))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeName == 'mml:msup'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
del mml
|
||
|
|
||
|
mml = mp._print(Symbol("x__2"))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeName == 'mml:msup'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
del mml
|
||
|
|
||
|
mml = mp._print(Symbol("x_2"))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeName == 'mml:msub'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
del mml
|
||
|
|
||
|
mml = mp._print(Symbol("x^3_2"))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeName == 'mml:msubsup'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
assert mml.childNodes[0].childNodes[2].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[2].childNodes[0].nodeValue == '3'
|
||
|
del mml
|
||
|
|
||
|
mml = mp._print(Symbol("x__3_2"))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeName == 'mml:msubsup'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
assert mml.childNodes[0].childNodes[2].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[2].childNodes[0].nodeValue == '3'
|
||
|
del mml
|
||
|
|
||
|
mml = mp._print(Symbol("x_2_a"))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeName == 'mml:msub'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mrow'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].childNodes[
|
||
|
0].nodeValue == '2'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[1].nodeName == 'mml:mo'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[1].childNodes[
|
||
|
0].nodeValue == ' '
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[2].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[2].childNodes[
|
||
|
0].nodeValue == 'a'
|
||
|
del mml
|
||
|
|
||
|
mml = mp._print(Symbol("x^2^a"))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeName == 'mml:msup'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mrow'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].childNodes[
|
||
|
0].nodeValue == '2'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[1].nodeName == 'mml:mo'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[1].childNodes[
|
||
|
0].nodeValue == ' '
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[2].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[2].childNodes[
|
||
|
0].nodeValue == 'a'
|
||
|
del mml
|
||
|
|
||
|
mml = mp._print(Symbol("x__2__a"))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeName == 'mml:msup'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mrow'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].childNodes[
|
||
|
0].nodeValue == '2'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[1].nodeName == 'mml:mo'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[1].childNodes[
|
||
|
0].nodeValue == ' '
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[2].nodeName == 'mml:mi'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[2].childNodes[
|
||
|
0].nodeValue == 'a'
|
||
|
del mml
|
||
|
|
||
|
|
||
|
def test_content_mathml_greek():
|
||
|
mml = mp._print(Symbol('alpha'))
|
||
|
assert mml.nodeName == 'ci'
|
||
|
assert mml.childNodes[0].nodeValue == '\N{GREEK SMALL LETTER ALPHA}'
|
||
|
|
||
|
assert mp.doprint(Symbol('alpha')) == '<ci>α</ci>'
|
||
|
assert mp.doprint(Symbol('beta')) == '<ci>β</ci>'
|
||
|
assert mp.doprint(Symbol('gamma')) == '<ci>γ</ci>'
|
||
|
assert mp.doprint(Symbol('delta')) == '<ci>δ</ci>'
|
||
|
assert mp.doprint(Symbol('epsilon')) == '<ci>ε</ci>'
|
||
|
assert mp.doprint(Symbol('zeta')) == '<ci>ζ</ci>'
|
||
|
assert mp.doprint(Symbol('eta')) == '<ci>η</ci>'
|
||
|
assert mp.doprint(Symbol('theta')) == '<ci>θ</ci>'
|
||
|
assert mp.doprint(Symbol('iota')) == '<ci>ι</ci>'
|
||
|
assert mp.doprint(Symbol('kappa')) == '<ci>κ</ci>'
|
||
|
assert mp.doprint(Symbol('lambda')) == '<ci>λ</ci>'
|
||
|
assert mp.doprint(Symbol('mu')) == '<ci>μ</ci>'
|
||
|
assert mp.doprint(Symbol('nu')) == '<ci>ν</ci>'
|
||
|
assert mp.doprint(Symbol('xi')) == '<ci>ξ</ci>'
|
||
|
assert mp.doprint(Symbol('omicron')) == '<ci>ο</ci>'
|
||
|
assert mp.doprint(Symbol('pi')) == '<ci>π</ci>'
|
||
|
assert mp.doprint(Symbol('rho')) == '<ci>ρ</ci>'
|
||
|
assert mp.doprint(Symbol('varsigma')) == '<ci>ς</ci>'
|
||
|
assert mp.doprint(Symbol('sigma')) == '<ci>σ</ci>'
|
||
|
assert mp.doprint(Symbol('tau')) == '<ci>τ</ci>'
|
||
|
assert mp.doprint(Symbol('upsilon')) == '<ci>υ</ci>'
|
||
|
assert mp.doprint(Symbol('phi')) == '<ci>φ</ci>'
|
||
|
assert mp.doprint(Symbol('chi')) == '<ci>χ</ci>'
|
||
|
assert mp.doprint(Symbol('psi')) == '<ci>ψ</ci>'
|
||
|
assert mp.doprint(Symbol('omega')) == '<ci>ω</ci>'
|
||
|
|
||
|
assert mp.doprint(Symbol('Alpha')) == '<ci>Α</ci>'
|
||
|
assert mp.doprint(Symbol('Beta')) == '<ci>Β</ci>'
|
||
|
assert mp.doprint(Symbol('Gamma')) == '<ci>Γ</ci>'
|
||
|
assert mp.doprint(Symbol('Delta')) == '<ci>Δ</ci>'
|
||
|
assert mp.doprint(Symbol('Epsilon')) == '<ci>Ε</ci>'
|
||
|
assert mp.doprint(Symbol('Zeta')) == '<ci>Ζ</ci>'
|
||
|
assert mp.doprint(Symbol('Eta')) == '<ci>Η</ci>'
|
||
|
assert mp.doprint(Symbol('Theta')) == '<ci>Θ</ci>'
|
||
|
assert mp.doprint(Symbol('Iota')) == '<ci>Ι</ci>'
|
||
|
assert mp.doprint(Symbol('Kappa')) == '<ci>Κ</ci>'
|
||
|
assert mp.doprint(Symbol('Lambda')) == '<ci>Λ</ci>'
|
||
|
assert mp.doprint(Symbol('Mu')) == '<ci>Μ</ci>'
|
||
|
assert mp.doprint(Symbol('Nu')) == '<ci>Ν</ci>'
|
||
|
assert mp.doprint(Symbol('Xi')) == '<ci>Ξ</ci>'
|
||
|
assert mp.doprint(Symbol('Omicron')) == '<ci>Ο</ci>'
|
||
|
assert mp.doprint(Symbol('Pi')) == '<ci>Π</ci>'
|
||
|
assert mp.doprint(Symbol('Rho')) == '<ci>Ρ</ci>'
|
||
|
assert mp.doprint(Symbol('Sigma')) == '<ci>Σ</ci>'
|
||
|
assert mp.doprint(Symbol('Tau')) == '<ci>Τ</ci>'
|
||
|
assert mp.doprint(Symbol('Upsilon')) == '<ci>Υ</ci>'
|
||
|
assert mp.doprint(Symbol('Phi')) == '<ci>Φ</ci>'
|
||
|
assert mp.doprint(Symbol('Chi')) == '<ci>Χ</ci>'
|
||
|
assert mp.doprint(Symbol('Psi')) == '<ci>Ψ</ci>'
|
||
|
assert mp.doprint(Symbol('Omega')) == '<ci>Ω</ci>'
|
||
|
|
||
|
|
||
|
def test_content_mathml_order():
|
||
|
expr = x**3 + x**2*y + 3*x*y**3 + y**4
|
||
|
|
||
|
mp = MathMLContentPrinter({'order': 'lex'})
|
||
|
mml = mp._print(expr)
|
||
|
|
||
|
assert mml.childNodes[1].childNodes[0].nodeName == 'power'
|
||
|
assert mml.childNodes[1].childNodes[1].childNodes[0].data == 'x'
|
||
|
assert mml.childNodes[1].childNodes[2].childNodes[0].data == '3'
|
||
|
|
||
|
assert mml.childNodes[4].childNodes[0].nodeName == 'power'
|
||
|
assert mml.childNodes[4].childNodes[1].childNodes[0].data == 'y'
|
||
|
assert mml.childNodes[4].childNodes[2].childNodes[0].data == '4'
|
||
|
|
||
|
mp = MathMLContentPrinter({'order': 'rev-lex'})
|
||
|
mml = mp._print(expr)
|
||
|
|
||
|
assert mml.childNodes[1].childNodes[0].nodeName == 'power'
|
||
|
assert mml.childNodes[1].childNodes[1].childNodes[0].data == 'y'
|
||
|
assert mml.childNodes[1].childNodes[2].childNodes[0].data == '4'
|
||
|
|
||
|
assert mml.childNodes[4].childNodes[0].nodeName == 'power'
|
||
|
assert mml.childNodes[4].childNodes[1].childNodes[0].data == 'x'
|
||
|
assert mml.childNodes[4].childNodes[2].childNodes[0].data == '3'
|
||
|
|
||
|
|
||
|
def test_content_settings():
|
||
|
raises(TypeError, lambda: mathml(x, method="garbage"))
|
||
|
|
||
|
|
||
|
def test_content_mathml_logic():
|
||
|
assert mathml(And(x, y)) == '<apply><and/><ci>x</ci><ci>y</ci></apply>'
|
||
|
assert mathml(Or(x, y)) == '<apply><or/><ci>x</ci><ci>y</ci></apply>'
|
||
|
assert mathml(Xor(x, y)) == '<apply><xor/><ci>x</ci><ci>y</ci></apply>'
|
||
|
assert mathml(Implies(x, y)) == '<apply><implies/><ci>x</ci><ci>y</ci></apply>'
|
||
|
assert mathml(Not(x)) == '<apply><not/><ci>x</ci></apply>'
|
||
|
|
||
|
|
||
|
def test_content_finite_sets():
|
||
|
assert mathml(FiniteSet(a)) == '<set><ci>a</ci></set>'
|
||
|
assert mathml(FiniteSet(a, b)) == '<set><ci>a</ci><ci>b</ci></set>'
|
||
|
assert mathml(FiniteSet(FiniteSet(a, b), c)) == \
|
||
|
'<set><ci>c</ci><set><ci>a</ci><ci>b</ci></set></set>'
|
||
|
|
||
|
A = FiniteSet(a)
|
||
|
B = FiniteSet(b)
|
||
|
C = FiniteSet(c)
|
||
|
D = FiniteSet(d)
|
||
|
|
||
|
U1 = Union(A, B, evaluate=False)
|
||
|
U2 = Union(C, D, evaluate=False)
|
||
|
I1 = Intersection(A, B, evaluate=False)
|
||
|
I2 = Intersection(C, D, evaluate=False)
|
||
|
C1 = Complement(A, B, evaluate=False)
|
||
|
C2 = Complement(C, D, evaluate=False)
|
||
|
# XXX ProductSet does not support evaluate keyword
|
||
|
P1 = ProductSet(A, B)
|
||
|
P2 = ProductSet(C, D)
|
||
|
|
||
|
assert mathml(U1) == \
|
||
|
'<apply><union/><set><ci>a</ci></set><set><ci>b</ci></set></apply>'
|
||
|
assert mathml(I1) == \
|
||
|
'<apply><intersect/><set><ci>a</ci></set><set><ci>b</ci></set>' \
|
||
|
'</apply>'
|
||
|
assert mathml(C1) == \
|
||
|
'<apply><setdiff/><set><ci>a</ci></set><set><ci>b</ci></set></apply>'
|
||
|
assert mathml(P1) == \
|
||
|
'<apply><cartesianproduct/><set><ci>a</ci></set><set><ci>b</ci>' \
|
||
|
'</set></apply>'
|
||
|
|
||
|
assert mathml(Intersection(A, U2, evaluate=False)) == \
|
||
|
'<apply><intersect/><set><ci>a</ci></set><apply><union/><set>' \
|
||
|
'<ci>c</ci></set><set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(Intersection(U1, U2, evaluate=False)) == \
|
||
|
'<apply><intersect/><apply><union/><set><ci>a</ci></set><set>' \
|
||
|
'<ci>b</ci></set></apply><apply><union/><set><ci>c</ci></set>' \
|
||
|
'<set><ci>d</ci></set></apply></apply>'
|
||
|
|
||
|
# XXX Does the parenthesis appear correctly for these examples in mathjax?
|
||
|
assert mathml(Intersection(C1, C2, evaluate=False)) == \
|
||
|
'<apply><intersect/><apply><setdiff/><set><ci>a</ci></set><set>' \
|
||
|
'<ci>b</ci></set></apply><apply><setdiff/><set><ci>c</ci></set>' \
|
||
|
'<set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(Intersection(P1, P2, evaluate=False)) == \
|
||
|
'<apply><intersect/><apply><cartesianproduct/><set><ci>a</ci></set>' \
|
||
|
'<set><ci>b</ci></set></apply><apply><cartesianproduct/><set>' \
|
||
|
'<ci>c</ci></set><set><ci>d</ci></set></apply></apply>'
|
||
|
|
||
|
assert mathml(Union(A, I2, evaluate=False)) == \
|
||
|
'<apply><union/><set><ci>a</ci></set><apply><intersect/><set>' \
|
||
|
'<ci>c</ci></set><set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(Union(I1, I2, evaluate=False)) == \
|
||
|
'<apply><union/><apply><intersect/><set><ci>a</ci></set><set>' \
|
||
|
'<ci>b</ci></set></apply><apply><intersect/><set><ci>c</ci></set>' \
|
||
|
'<set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(Union(C1, C2, evaluate=False)) == \
|
||
|
'<apply><union/><apply><setdiff/><set><ci>a</ci></set><set>' \
|
||
|
'<ci>b</ci></set></apply><apply><setdiff/><set><ci>c</ci></set>' \
|
||
|
'<set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(Union(P1, P2, evaluate=False)) == \
|
||
|
'<apply><union/><apply><cartesianproduct/><set><ci>a</ci></set>' \
|
||
|
'<set><ci>b</ci></set></apply><apply><cartesianproduct/><set>' \
|
||
|
'<ci>c</ci></set><set><ci>d</ci></set></apply></apply>'
|
||
|
|
||
|
assert mathml(Complement(A, C2, evaluate=False)) == \
|
||
|
'<apply><setdiff/><set><ci>a</ci></set><apply><setdiff/><set>' \
|
||
|
'<ci>c</ci></set><set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(Complement(U1, U2, evaluate=False)) == \
|
||
|
'<apply><setdiff/><apply><union/><set><ci>a</ci></set><set>' \
|
||
|
'<ci>b</ci></set></apply><apply><union/><set><ci>c</ci></set>' \
|
||
|
'<set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(Complement(I1, I2, evaluate=False)) == \
|
||
|
'<apply><setdiff/><apply><intersect/><set><ci>a</ci></set><set>' \
|
||
|
'<ci>b</ci></set></apply><apply><intersect/><set><ci>c</ci></set>' \
|
||
|
'<set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(Complement(P1, P2, evaluate=False)) == \
|
||
|
'<apply><setdiff/><apply><cartesianproduct/><set><ci>a</ci></set>' \
|
||
|
'<set><ci>b</ci></set></apply><apply><cartesianproduct/><set>' \
|
||
|
'<ci>c</ci></set><set><ci>d</ci></set></apply></apply>'
|
||
|
|
||
|
assert mathml(ProductSet(A, P2)) == \
|
||
|
'<apply><cartesianproduct/><set><ci>a</ci></set>' \
|
||
|
'<apply><cartesianproduct/><set><ci>c</ci></set>' \
|
||
|
'<set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(ProductSet(U1, U2)) == \
|
||
|
'<apply><cartesianproduct/><apply><union/><set><ci>a</ci></set>' \
|
||
|
'<set><ci>b</ci></set></apply><apply><union/><set><ci>c</ci></set>' \
|
||
|
'<set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(ProductSet(I1, I2)) == \
|
||
|
'<apply><cartesianproduct/><apply><intersect/><set><ci>a</ci></set>' \
|
||
|
'<set><ci>b</ci></set></apply><apply><intersect/><set>' \
|
||
|
'<ci>c</ci></set><set><ci>d</ci></set></apply></apply>'
|
||
|
assert mathml(ProductSet(C1, C2)) == \
|
||
|
'<apply><cartesianproduct/><apply><setdiff/><set><ci>a</ci></set>' \
|
||
|
'<set><ci>b</ci></set></apply><apply><setdiff/><set>' \
|
||
|
'<ci>c</ci></set><set><ci>d</ci></set></apply></apply>'
|
||
|
|
||
|
|
||
|
def test_presentation_printmethod():
|
||
|
assert mpp.doprint(1 + x) == '<mrow><mi>x</mi><mo>+</mo><mn>1</mn></mrow>'
|
||
|
assert mpp.doprint(x**2) == '<msup><mi>x</mi><mn>2</mn></msup>'
|
||
|
assert mpp.doprint(x**-1) == '<mfrac><mn>1</mn><mi>x</mi></mfrac>'
|
||
|
assert mpp.doprint(x**-2) == \
|
||
|
'<mfrac><mn>1</mn><msup><mi>x</mi><mn>2</mn></msup></mfrac>'
|
||
|
assert mpp.doprint(2*x) == \
|
||
|
'<mrow><mn>2</mn><mo>⁢</mo><mi>x</mi></mrow>'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_core():
|
||
|
mml_1 = mpp._print(1 + x)
|
||
|
assert mml_1.nodeName == 'mrow'
|
||
|
nodes = mml_1.childNodes
|
||
|
assert len(nodes) == 3
|
||
|
assert nodes[0].nodeName in ['mi', 'mn']
|
||
|
assert nodes[1].nodeName == 'mo'
|
||
|
if nodes[0].nodeName == 'mn':
|
||
|
assert nodes[0].childNodes[0].nodeValue == '1'
|
||
|
assert nodes[2].childNodes[0].nodeValue == 'x'
|
||
|
else:
|
||
|
assert nodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert nodes[2].childNodes[0].nodeValue == '1'
|
||
|
|
||
|
mml_2 = mpp._print(x**2)
|
||
|
assert mml_2.nodeName == 'msup'
|
||
|
nodes = mml_2.childNodes
|
||
|
assert nodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert nodes[1].childNodes[0].nodeValue == '2'
|
||
|
|
||
|
mml_3 = mpp._print(2*x)
|
||
|
assert mml_3.nodeName == 'mrow'
|
||
|
nodes = mml_3.childNodes
|
||
|
assert nodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert nodes[1].childNodes[0].nodeValue == '⁢'
|
||
|
assert nodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
mml = mpp._print(Float(1.0, 2)*x)
|
||
|
assert mml.nodeName == 'mrow'
|
||
|
nodes = mml.childNodes
|
||
|
assert nodes[0].childNodes[0].nodeValue == '1.0'
|
||
|
assert nodes[1].childNodes[0].nodeValue == '⁢'
|
||
|
assert nodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_functions():
|
||
|
mml_1 = mpp._print(sin(x))
|
||
|
assert mml_1.childNodes[0].childNodes[0
|
||
|
].nodeValue == 'sin'
|
||
|
assert mml_1.childNodes[1].childNodes[0
|
||
|
].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
mml_2 = mpp._print(diff(sin(x), x, evaluate=False))
|
||
|
assert mml_2.nodeName == 'mrow'
|
||
|
assert mml_2.childNodes[0].childNodes[0
|
||
|
].childNodes[0].childNodes[0].nodeValue == 'ⅆ'
|
||
|
assert mml_2.childNodes[1].childNodes[1
|
||
|
].nodeName == 'mfenced'
|
||
|
assert mml_2.childNodes[0].childNodes[1
|
||
|
].childNodes[0].childNodes[0].nodeValue == 'ⅆ'
|
||
|
|
||
|
mml_3 = mpp._print(diff(cos(x*y), x, evaluate=False))
|
||
|
assert mml_3.childNodes[0].nodeName == 'mfrac'
|
||
|
assert mml_3.childNodes[0].childNodes[0
|
||
|
].childNodes[0].childNodes[0].nodeValue == '∂'
|
||
|
assert mml_3.childNodes[1].childNodes[0
|
||
|
].childNodes[0].nodeValue == 'cos'
|
||
|
|
||
|
|
||
|
def test_print_derivative():
|
||
|
f = Function('f')
|
||
|
d = Derivative(f(x, y, z), x, z, x, z, z, y)
|
||
|
assert mathml(d) == \
|
||
|
'<apply><partialdiff/><bvar><ci>y</ci><ci>z</ci><degree><cn>2</cn></degree><ci>x</ci><ci>z</ci><ci>x</ci></bvar><apply><f/><ci>x</ci><ci>y</ci><ci>z</ci></apply></apply>'
|
||
|
assert mathml(d, printer='presentation') == \
|
||
|
'<mrow><mfrac><mrow><msup><mo>∂</mo><mn>6</mn></msup></mrow><mrow><mo>∂</mo><mi>y</mi><msup><mo>∂</mo><mn>2</mn></msup><mi>z</mi><mo>∂</mo><mi>x</mi><mo>∂</mo><mi>z</mi><mo>∂</mo><mi>x</mi></mrow></mfrac><mrow><mi>f</mi><mfenced><mi>x</mi><mi>y</mi><mi>z</mi></mfenced></mrow></mrow>'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_limits():
|
||
|
lim_fun = sin(x)/x
|
||
|
mml_1 = mpp._print(Limit(lim_fun, x, 0))
|
||
|
assert mml_1.childNodes[0].nodeName == 'munder'
|
||
|
assert mml_1.childNodes[0].childNodes[0
|
||
|
].childNodes[0].nodeValue == 'lim'
|
||
|
assert mml_1.childNodes[0].childNodes[1
|
||
|
].childNodes[0].childNodes[0
|
||
|
].nodeValue == 'x'
|
||
|
assert mml_1.childNodes[0].childNodes[1
|
||
|
].childNodes[1].childNodes[0
|
||
|
].nodeValue == '→'
|
||
|
assert mml_1.childNodes[0].childNodes[1
|
||
|
].childNodes[2].childNodes[0
|
||
|
].nodeValue == '0'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_integrals():
|
||
|
assert mpp.doprint(Integral(x, (x, 0, 1))) == \
|
||
|
'<mrow><msubsup><mo>∫</mo><mn>0</mn><mn>1</mn></msubsup>'\
|
||
|
'<mi>x</mi><mo>ⅆ</mo><mi>x</mi></mrow>'
|
||
|
assert mpp.doprint(Integral(log(x), x)) == \
|
||
|
'<mrow><mo>∫</mo><mrow><mi>log</mi><mfenced><mi>x</mi>'\
|
||
|
'</mfenced></mrow><mo>ⅆ</mo><mi>x</mi></mrow>'
|
||
|
assert mpp.doprint(Integral(x*y, x, y)) == \
|
||
|
'<mrow><mo>∬</mo><mrow><mi>x</mi><mo>⁢</mo>'\
|
||
|
'<mi>y</mi></mrow><mo>ⅆ</mo><mi>y</mi><mo>ⅆ</mo><mi>x</mi></mrow>'
|
||
|
z, w = symbols('z w')
|
||
|
assert mpp.doprint(Integral(x*y*z, x, y, z)) == \
|
||
|
'<mrow><mo>∭</mo><mrow><mi>x</mi><mo>⁢</mo>'\
|
||
|
'<mi>y</mi><mo>⁢</mo><mi>z</mi></mrow><mo>ⅆ</mo>'\
|
||
|
'<mi>z</mi><mo>ⅆ</mo><mi>y</mi><mo>ⅆ</mo><mi>x</mi></mrow>'
|
||
|
assert mpp.doprint(Integral(x*y*z*w, x, y, z, w)) == \
|
||
|
'<mrow><mo>∫</mo><mo>∫</mo><mo>∫</mo>'\
|
||
|
'<mo>∫</mo><mrow><mi>w</mi><mo>⁢</mo>'\
|
||
|
'<mi>x</mi><mo>⁢</mo><mi>y</mi>'\
|
||
|
'<mo>⁢</mo><mi>z</mi></mrow><mo>ⅆ</mo><mi>w</mi>'\
|
||
|
'<mo>ⅆ</mo><mi>z</mi><mo>ⅆ</mo><mi>y</mi><mo>ⅆ</mo><mi>x</mi></mrow>'
|
||
|
assert mpp.doprint(Integral(x, x, y, (z, 0, 1))) == \
|
||
|
'<mrow><msubsup><mo>∫</mo><mn>0</mn><mn>1</mn></msubsup>'\
|
||
|
'<mo>∫</mo><mo>∫</mo><mi>x</mi><mo>ⅆ</mo><mi>z</mi>'\
|
||
|
'<mo>ⅆ</mo><mi>y</mi><mo>ⅆ</mo><mi>x</mi></mrow>'
|
||
|
assert mpp.doprint(Integral(x, (x, 0))) == \
|
||
|
'<mrow><msup><mo>∫</mo><mn>0</mn></msup><mi>x</mi><mo>ⅆ</mo>'\
|
||
|
'<mi>x</mi></mrow>'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_matrices():
|
||
|
A = Matrix([1, 2, 3])
|
||
|
B = Matrix([[0, 5, 4], [2, 3, 1], [9, 7, 9]])
|
||
|
mll_1 = mpp._print(A)
|
||
|
assert mll_1.childNodes[0].nodeName == 'mtable'
|
||
|
assert mll_1.childNodes[0].childNodes[0].nodeName == 'mtr'
|
||
|
assert len(mll_1.childNodes[0].childNodes) == 3
|
||
|
assert mll_1.childNodes[0].childNodes[0].childNodes[0].nodeName == 'mtd'
|
||
|
assert len(mll_1.childNodes[0].childNodes[0].childNodes) == 1
|
||
|
assert mll_1.childNodes[0].childNodes[0].childNodes[0
|
||
|
].childNodes[0].childNodes[0].nodeValue == '1'
|
||
|
assert mll_1.childNodes[0].childNodes[1].childNodes[0
|
||
|
].childNodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert mll_1.childNodes[0].childNodes[2].childNodes[0
|
||
|
].childNodes[0].childNodes[0].nodeValue == '3'
|
||
|
mll_2 = mpp._print(B)
|
||
|
assert mll_2.childNodes[0].nodeName == 'mtable'
|
||
|
assert mll_2.childNodes[0].childNodes[0].nodeName == 'mtr'
|
||
|
assert len(mll_2.childNodes[0].childNodes) == 3
|
||
|
assert mll_2.childNodes[0].childNodes[0].childNodes[0].nodeName == 'mtd'
|
||
|
assert len(mll_2.childNodes[0].childNodes[0].childNodes) == 3
|
||
|
assert mll_2.childNodes[0].childNodes[0].childNodes[0
|
||
|
].childNodes[0].childNodes[0].nodeValue == '0'
|
||
|
assert mll_2.childNodes[0].childNodes[0].childNodes[1
|
||
|
].childNodes[0].childNodes[0].nodeValue == '5'
|
||
|
assert mll_2.childNodes[0].childNodes[0].childNodes[2
|
||
|
].childNodes[0].childNodes[0].nodeValue == '4'
|
||
|
assert mll_2.childNodes[0].childNodes[1].childNodes[0
|
||
|
].childNodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert mll_2.childNodes[0].childNodes[1].childNodes[1
|
||
|
].childNodes[0].childNodes[0].nodeValue == '3'
|
||
|
assert mll_2.childNodes[0].childNodes[1].childNodes[2
|
||
|
].childNodes[0].childNodes[0].nodeValue == '1'
|
||
|
assert mll_2.childNodes[0].childNodes[2].childNodes[0
|
||
|
].childNodes[0].childNodes[0].nodeValue == '9'
|
||
|
assert mll_2.childNodes[0].childNodes[2].childNodes[1
|
||
|
].childNodes[0].childNodes[0].nodeValue == '7'
|
||
|
assert mll_2.childNodes[0].childNodes[2].childNodes[2
|
||
|
].childNodes[0].childNodes[0].nodeValue == '9'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_sums():
|
||
|
summand = x
|
||
|
mml_1 = mpp._print(Sum(summand, (x, 1, 10)))
|
||
|
assert mml_1.childNodes[0].nodeName == 'munderover'
|
||
|
assert len(mml_1.childNodes[0].childNodes) == 3
|
||
|
assert mml_1.childNodes[0].childNodes[0].childNodes[0
|
||
|
].nodeValue == '∑'
|
||
|
assert len(mml_1.childNodes[0].childNodes[1].childNodes) == 3
|
||
|
assert mml_1.childNodes[0].childNodes[2].childNodes[0
|
||
|
].nodeValue == '10'
|
||
|
assert mml_1.childNodes[1].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_add():
|
||
|
mml = mpp._print(x**5 - x**4 + x)
|
||
|
assert len(mml.childNodes) == 5
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0
|
||
|
].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0
|
||
|
].nodeValue == '5'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeValue == '-'
|
||
|
assert mml.childNodes[2].childNodes[0].childNodes[0
|
||
|
].nodeValue == 'x'
|
||
|
assert mml.childNodes[2].childNodes[1].childNodes[0
|
||
|
].nodeValue == '4'
|
||
|
assert mml.childNodes[3].childNodes[0].nodeValue == '+'
|
||
|
assert mml.childNodes[4].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_Rational():
|
||
|
mml_1 = mpp._print(Rational(1, 1))
|
||
|
assert mml_1.nodeName == 'mn'
|
||
|
|
||
|
mml_2 = mpp._print(Rational(2, 5))
|
||
|
assert mml_2.nodeName == 'mfrac'
|
||
|
assert mml_2.childNodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert mml_2.childNodes[1].childNodes[0].nodeValue == '5'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_constants():
|
||
|
mml = mpp._print(I)
|
||
|
assert mml.childNodes[0].nodeValue == 'ⅈ'
|
||
|
|
||
|
mml = mpp._print(E)
|
||
|
assert mml.childNodes[0].nodeValue == 'ⅇ'
|
||
|
|
||
|
mml = mpp._print(oo)
|
||
|
assert mml.childNodes[0].nodeValue == '∞'
|
||
|
|
||
|
mml = mpp._print(pi)
|
||
|
assert mml.childNodes[0].nodeValue == 'π'
|
||
|
|
||
|
assert mathml(hbar, printer='presentation') == '<mi>ℏ</mi>'
|
||
|
assert mathml(S.TribonacciConstant, printer='presentation'
|
||
|
) == '<mi>TribonacciConstant</mi>'
|
||
|
assert mathml(S.EulerGamma, printer='presentation'
|
||
|
) == '<mi>γ</mi>'
|
||
|
assert mathml(S.GoldenRatio, printer='presentation'
|
||
|
) == '<mi>Φ</mi>'
|
||
|
|
||
|
assert mathml(zoo, printer='presentation') == \
|
||
|
'<mover><mo>∞</mo><mo>~</mo></mover>'
|
||
|
|
||
|
assert mathml(S.NaN, printer='presentation') == '<mi>NaN</mi>'
|
||
|
|
||
|
def test_presentation_mathml_trig():
|
||
|
mml = mpp._print(sin(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'sin'
|
||
|
|
||
|
mml = mpp._print(cos(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'cos'
|
||
|
|
||
|
mml = mpp._print(tan(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'tan'
|
||
|
|
||
|
mml = mpp._print(asin(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'arcsin'
|
||
|
|
||
|
mml = mpp._print(acos(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'arccos'
|
||
|
|
||
|
mml = mpp._print(atan(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'arctan'
|
||
|
|
||
|
mml = mpp._print(sinh(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'sinh'
|
||
|
|
||
|
mml = mpp._print(cosh(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'cosh'
|
||
|
|
||
|
mml = mpp._print(tanh(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'tanh'
|
||
|
|
||
|
mml = mpp._print(asinh(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'arcsinh'
|
||
|
|
||
|
mml = mpp._print(atanh(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'arctanh'
|
||
|
|
||
|
mml = mpp._print(acosh(x))
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'arccosh'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_relational():
|
||
|
mml_1 = mpp._print(Eq(x, 1))
|
||
|
assert len(mml_1.childNodes) == 3
|
||
|
assert mml_1.childNodes[0].nodeName == 'mi'
|
||
|
assert mml_1.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml_1.childNodes[1].nodeName == 'mo'
|
||
|
assert mml_1.childNodes[1].childNodes[0].nodeValue == '='
|
||
|
assert mml_1.childNodes[2].nodeName == 'mn'
|
||
|
assert mml_1.childNodes[2].childNodes[0].nodeValue == '1'
|
||
|
|
||
|
mml_2 = mpp._print(Ne(1, x))
|
||
|
assert len(mml_2.childNodes) == 3
|
||
|
assert mml_2.childNodes[0].nodeName == 'mn'
|
||
|
assert mml_2.childNodes[0].childNodes[0].nodeValue == '1'
|
||
|
assert mml_2.childNodes[1].nodeName == 'mo'
|
||
|
assert mml_2.childNodes[1].childNodes[0].nodeValue == '≠'
|
||
|
assert mml_2.childNodes[2].nodeName == 'mi'
|
||
|
assert mml_2.childNodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
mml_3 = mpp._print(Ge(1, x))
|
||
|
assert len(mml_3.childNodes) == 3
|
||
|
assert mml_3.childNodes[0].nodeName == 'mn'
|
||
|
assert mml_3.childNodes[0].childNodes[0].nodeValue == '1'
|
||
|
assert mml_3.childNodes[1].nodeName == 'mo'
|
||
|
assert mml_3.childNodes[1].childNodes[0].nodeValue == '≥'
|
||
|
assert mml_3.childNodes[2].nodeName == 'mi'
|
||
|
assert mml_3.childNodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
mml_4 = mpp._print(Lt(1, x))
|
||
|
assert len(mml_4.childNodes) == 3
|
||
|
assert mml_4.childNodes[0].nodeName == 'mn'
|
||
|
assert mml_4.childNodes[0].childNodes[0].nodeValue == '1'
|
||
|
assert mml_4.childNodes[1].nodeName == 'mo'
|
||
|
assert mml_4.childNodes[1].childNodes[0].nodeValue == '<'
|
||
|
assert mml_4.childNodes[2].nodeName == 'mi'
|
||
|
assert mml_4.childNodes[2].childNodes[0].nodeValue == 'x'
|
||
|
|
||
|
|
||
|
def test_presentation_symbol():
|
||
|
mml = mpp._print(x)
|
||
|
assert mml.nodeName == 'mi'
|
||
|
assert mml.childNodes[0].nodeValue == 'x'
|
||
|
del mml
|
||
|
|
||
|
mml = mpp._print(Symbol("x^2"))
|
||
|
assert mml.nodeName == 'msup'
|
||
|
assert mml.childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[1].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
del mml
|
||
|
|
||
|
mml = mpp._print(Symbol("x__2"))
|
||
|
assert mml.nodeName == 'msup'
|
||
|
assert mml.childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[1].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
del mml
|
||
|
|
||
|
mml = mpp._print(Symbol("x_2"))
|
||
|
assert mml.nodeName == 'msub'
|
||
|
assert mml.childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[1].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
del mml
|
||
|
|
||
|
mml = mpp._print(Symbol("x^3_2"))
|
||
|
assert mml.nodeName == 'msubsup'
|
||
|
assert mml.childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[1].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
assert mml.childNodes[2].nodeName == 'mi'
|
||
|
assert mml.childNodes[2].childNodes[0].nodeValue == '3'
|
||
|
del mml
|
||
|
|
||
|
mml = mpp._print(Symbol("x__3_2"))
|
||
|
assert mml.nodeName == 'msubsup'
|
||
|
assert mml.childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[1].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeValue == '2'
|
||
|
assert mml.childNodes[2].nodeName == 'mi'
|
||
|
assert mml.childNodes[2].childNodes[0].nodeValue == '3'
|
||
|
del mml
|
||
|
|
||
|
mml = mpp._print(Symbol("x_2_a"))
|
||
|
assert mml.nodeName == 'msub'
|
||
|
assert mml.childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[1].nodeName == 'mrow'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert mml.childNodes[1].childNodes[1].nodeName == 'mo'
|
||
|
assert mml.childNodes[1].childNodes[1].childNodes[0].nodeValue == ' '
|
||
|
assert mml.childNodes[1].childNodes[2].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[2].childNodes[0].nodeValue == 'a'
|
||
|
del mml
|
||
|
|
||
|
mml = mpp._print(Symbol("x^2^a"))
|
||
|
assert mml.nodeName == 'msup'
|
||
|
assert mml.childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[1].nodeName == 'mrow'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert mml.childNodes[1].childNodes[1].nodeName == 'mo'
|
||
|
assert mml.childNodes[1].childNodes[1].childNodes[0].nodeValue == ' '
|
||
|
assert mml.childNodes[1].childNodes[2].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[2].childNodes[0].nodeValue == 'a'
|
||
|
del mml
|
||
|
|
||
|
mml = mpp._print(Symbol("x__2__a"))
|
||
|
assert mml.nodeName == 'msup'
|
||
|
assert mml.childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[1].nodeName == 'mrow'
|
||
|
assert mml.childNodes[1].childNodes[0].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[0].childNodes[0].nodeValue == '2'
|
||
|
assert mml.childNodes[1].childNodes[1].nodeName == 'mo'
|
||
|
assert mml.childNodes[1].childNodes[1].childNodes[0].nodeValue == ' '
|
||
|
assert mml.childNodes[1].childNodes[2].nodeName == 'mi'
|
||
|
assert mml.childNodes[1].childNodes[2].childNodes[0].nodeValue == 'a'
|
||
|
del mml
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_greek():
|
||
|
mml = mpp._print(Symbol('alpha'))
|
||
|
assert mml.nodeName == 'mi'
|
||
|
assert mml.childNodes[0].nodeValue == '\N{GREEK SMALL LETTER ALPHA}'
|
||
|
|
||
|
assert mpp.doprint(Symbol('alpha')) == '<mi>α</mi>'
|
||
|
assert mpp.doprint(Symbol('beta')) == '<mi>β</mi>'
|
||
|
assert mpp.doprint(Symbol('gamma')) == '<mi>γ</mi>'
|
||
|
assert mpp.doprint(Symbol('delta')) == '<mi>δ</mi>'
|
||
|
assert mpp.doprint(Symbol('epsilon')) == '<mi>ε</mi>'
|
||
|
assert mpp.doprint(Symbol('zeta')) == '<mi>ζ</mi>'
|
||
|
assert mpp.doprint(Symbol('eta')) == '<mi>η</mi>'
|
||
|
assert mpp.doprint(Symbol('theta')) == '<mi>θ</mi>'
|
||
|
assert mpp.doprint(Symbol('iota')) == '<mi>ι</mi>'
|
||
|
assert mpp.doprint(Symbol('kappa')) == '<mi>κ</mi>'
|
||
|
assert mpp.doprint(Symbol('lambda')) == '<mi>λ</mi>'
|
||
|
assert mpp.doprint(Symbol('mu')) == '<mi>μ</mi>'
|
||
|
assert mpp.doprint(Symbol('nu')) == '<mi>ν</mi>'
|
||
|
assert mpp.doprint(Symbol('xi')) == '<mi>ξ</mi>'
|
||
|
assert mpp.doprint(Symbol('omicron')) == '<mi>ο</mi>'
|
||
|
assert mpp.doprint(Symbol('pi')) == '<mi>π</mi>'
|
||
|
assert mpp.doprint(Symbol('rho')) == '<mi>ρ</mi>'
|
||
|
assert mpp.doprint(Symbol('varsigma')) == '<mi>ς</mi>'
|
||
|
assert mpp.doprint(Symbol('sigma')) == '<mi>σ</mi>'
|
||
|
assert mpp.doprint(Symbol('tau')) == '<mi>τ</mi>'
|
||
|
assert mpp.doprint(Symbol('upsilon')) == '<mi>υ</mi>'
|
||
|
assert mpp.doprint(Symbol('phi')) == '<mi>φ</mi>'
|
||
|
assert mpp.doprint(Symbol('chi')) == '<mi>χ</mi>'
|
||
|
assert mpp.doprint(Symbol('psi')) == '<mi>ψ</mi>'
|
||
|
assert mpp.doprint(Symbol('omega')) == '<mi>ω</mi>'
|
||
|
|
||
|
assert mpp.doprint(Symbol('Alpha')) == '<mi>Α</mi>'
|
||
|
assert mpp.doprint(Symbol('Beta')) == '<mi>Β</mi>'
|
||
|
assert mpp.doprint(Symbol('Gamma')) == '<mi>Γ</mi>'
|
||
|
assert mpp.doprint(Symbol('Delta')) == '<mi>Δ</mi>'
|
||
|
assert mpp.doprint(Symbol('Epsilon')) == '<mi>Ε</mi>'
|
||
|
assert mpp.doprint(Symbol('Zeta')) == '<mi>Ζ</mi>'
|
||
|
assert mpp.doprint(Symbol('Eta')) == '<mi>Η</mi>'
|
||
|
assert mpp.doprint(Symbol('Theta')) == '<mi>Θ</mi>'
|
||
|
assert mpp.doprint(Symbol('Iota')) == '<mi>Ι</mi>'
|
||
|
assert mpp.doprint(Symbol('Kappa')) == '<mi>Κ</mi>'
|
||
|
assert mpp.doprint(Symbol('Lambda')) == '<mi>Λ</mi>'
|
||
|
assert mpp.doprint(Symbol('Mu')) == '<mi>Μ</mi>'
|
||
|
assert mpp.doprint(Symbol('Nu')) == '<mi>Ν</mi>'
|
||
|
assert mpp.doprint(Symbol('Xi')) == '<mi>Ξ</mi>'
|
||
|
assert mpp.doprint(Symbol('Omicron')) == '<mi>Ο</mi>'
|
||
|
assert mpp.doprint(Symbol('Pi')) == '<mi>Π</mi>'
|
||
|
assert mpp.doprint(Symbol('Rho')) == '<mi>Ρ</mi>'
|
||
|
assert mpp.doprint(Symbol('Sigma')) == '<mi>Σ</mi>'
|
||
|
assert mpp.doprint(Symbol('Tau')) == '<mi>Τ</mi>'
|
||
|
assert mpp.doprint(Symbol('Upsilon')) == '<mi>Υ</mi>'
|
||
|
assert mpp.doprint(Symbol('Phi')) == '<mi>Φ</mi>'
|
||
|
assert mpp.doprint(Symbol('Chi')) == '<mi>Χ</mi>'
|
||
|
assert mpp.doprint(Symbol('Psi')) == '<mi>Ψ</mi>'
|
||
|
assert mpp.doprint(Symbol('Omega')) == '<mi>Ω</mi>'
|
||
|
|
||
|
|
||
|
def test_presentation_mathml_order():
|
||
|
expr = x**3 + x**2*y + 3*x*y**3 + y**4
|
||
|
|
||
|
mp = MathMLPresentationPrinter({'order': 'lex'})
|
||
|
mml = mp._print(expr)
|
||
|
assert mml.childNodes[0].nodeName == 'msup'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '3'
|
||
|
|
||
|
assert mml.childNodes[6].nodeName == 'msup'
|
||
|
assert mml.childNodes[6].childNodes[0].childNodes[0].nodeValue == 'y'
|
||
|
assert mml.childNodes[6].childNodes[1].childNodes[0].nodeValue == '4'
|
||
|
|
||
|
mp = MathMLPresentationPrinter({'order': 'rev-lex'})
|
||
|
mml = mp._print(expr)
|
||
|
|
||
|
assert mml.childNodes[0].nodeName == 'msup'
|
||
|
assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'y'
|
||
|
assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '4'
|
||
|
|
||
|
assert mml.childNodes[6].nodeName == 'msup'
|
||
|
assert mml.childNodes[6].childNodes[0].childNodes[0].nodeValue == 'x'
|
||
|
assert mml.childNodes[6].childNodes[1].childNodes[0].nodeValue == '3'
|
||
|
|
||
|
|
||
|
def test_print_intervals():
|
||
|
a = Symbol('a', real=True)
|
||
|
assert mpp.doprint(Interval(0, a)) == \
|
||
|
'<mrow><mfenced close="]" open="["><mn>0</mn><mi>a</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Interval(0, a, False, False)) == \
|
||
|
'<mrow><mfenced close="]" open="["><mn>0</mn><mi>a</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Interval(0, a, True, False)) == \
|
||
|
'<mrow><mfenced close="]" open="("><mn>0</mn><mi>a</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Interval(0, a, False, True)) == \
|
||
|
'<mrow><mfenced close=")" open="["><mn>0</mn><mi>a</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Interval(0, a, True, True)) == \
|
||
|
'<mrow><mfenced close=")" open="("><mn>0</mn><mi>a</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_tuples():
|
||
|
assert mpp.doprint(Tuple(0,)) == \
|
||
|
'<mrow><mfenced><mn>0</mn></mfenced></mrow>'
|
||
|
assert mpp.doprint(Tuple(0, a)) == \
|
||
|
'<mrow><mfenced><mn>0</mn><mi>a</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Tuple(0, a, a)) == \
|
||
|
'<mrow><mfenced><mn>0</mn><mi>a</mi><mi>a</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Tuple(0, 1, 2, 3, 4)) == \
|
||
|
'<mrow><mfenced><mn>0</mn><mn>1</mn><mn>2</mn><mn>3</mn><mn>4</mn></mfenced></mrow>'
|
||
|
assert mpp.doprint(Tuple(0, 1, Tuple(2, 3, 4))) == \
|
||
|
'<mrow><mfenced><mn>0</mn><mn>1</mn><mrow><mfenced><mn>2</mn><mn>3'\
|
||
|
'</mn><mn>4</mn></mfenced></mrow></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_re_im():
|
||
|
assert mpp.doprint(re(x)) == \
|
||
|
'<mrow><mi mathvariant="fraktur">R</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(im(x)) == \
|
||
|
'<mrow><mi mathvariant="fraktur">I</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(re(x + 1)) == \
|
||
|
'<mrow><mrow><mi mathvariant="fraktur">R</mi><mfenced><mi>x</mi>'\
|
||
|
'</mfenced></mrow><mo>+</mo><mn>1</mn></mrow>'
|
||
|
assert mpp.doprint(im(x + 1)) == \
|
||
|
'<mrow><mi mathvariant="fraktur">I</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_Abs():
|
||
|
assert mpp.doprint(Abs(x)) == \
|
||
|
'<mrow><mfenced close="|" open="|"><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Abs(x + 1)) == \
|
||
|
'<mrow><mfenced close="|" open="|"><mrow><mi>x</mi><mo>+</mo><mn>1</mn></mrow></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_Determinant():
|
||
|
assert mpp.doprint(Determinant(Matrix([[1, 2], [3, 4]]))) == \
|
||
|
'<mrow><mfenced close="|" open="|"><mfenced close="]" open="["><mtable><mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd></mtr><mtr><mtd><mn>3</mn></mtd><mtd><mn>4</mn></mtd></mtr></mtable></mfenced></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_presentation_settings():
|
||
|
raises(TypeError, lambda: mathml(x, printer='presentation',
|
||
|
method="garbage"))
|
||
|
|
||
|
|
||
|
def test_toprettyxml_hooking():
|
||
|
# test that the patch doesn't influence the behavior of the standard
|
||
|
# library
|
||
|
import xml.dom.minidom
|
||
|
doc1 = xml.dom.minidom.parseString(
|
||
|
"<apply><plus/><ci>x</ci><cn>1</cn></apply>")
|
||
|
doc2 = xml.dom.minidom.parseString(
|
||
|
"<mrow><mi>x</mi><mo>+</mo><mn>1</mn></mrow>")
|
||
|
prettyxml_old1 = doc1.toprettyxml()
|
||
|
prettyxml_old2 = doc2.toprettyxml()
|
||
|
|
||
|
mp.apply_patch()
|
||
|
mp.restore_patch()
|
||
|
|
||
|
assert prettyxml_old1 == doc1.toprettyxml()
|
||
|
assert prettyxml_old2 == doc2.toprettyxml()
|
||
|
|
||
|
|
||
|
def test_print_domains():
|
||
|
from sympy.sets import Integers, Naturals, Naturals0, Reals, Complexes
|
||
|
|
||
|
assert mpp.doprint(Complexes) == '<mi mathvariant="normal">ℂ</mi>'
|
||
|
assert mpp.doprint(Integers) == '<mi mathvariant="normal">ℤ</mi>'
|
||
|
assert mpp.doprint(Naturals) == '<mi mathvariant="normal">ℕ</mi>'
|
||
|
assert mpp.doprint(Naturals0) == \
|
||
|
'<msub><mi mathvariant="normal">ℕ</mi><mn>0</mn></msub>'
|
||
|
assert mpp.doprint(Reals) == '<mi mathvariant="normal">ℝ</mi>'
|
||
|
|
||
|
|
||
|
def test_print_expression_with_minus():
|
||
|
assert mpp.doprint(-x) == '<mrow><mo>-</mo><mi>x</mi></mrow>'
|
||
|
assert mpp.doprint(-x/y) == \
|
||
|
'<mrow><mo>-</mo><mfrac><mi>x</mi><mi>y</mi></mfrac></mrow>'
|
||
|
assert mpp.doprint(-Rational(1, 2)) == \
|
||
|
'<mrow><mo>-</mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_AssocOp():
|
||
|
from sympy.core.operations import AssocOp
|
||
|
|
||
|
class TestAssocOp(AssocOp):
|
||
|
identity = 0
|
||
|
|
||
|
expr = TestAssocOp(1, 2)
|
||
|
assert mpp.doprint(expr) == \
|
||
|
'<mrow><mi>testassocop</mi><mn>1</mn><mn>2</mn></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_basic():
|
||
|
expr = Basic(S(1), S(2))
|
||
|
assert mpp.doprint(expr) == \
|
||
|
'<mrow><mi>basic</mi><mfenced><mn>1</mn><mn>2</mn></mfenced></mrow>'
|
||
|
assert mp.doprint(expr) == '<basic><cn>1</cn><cn>2</cn></basic>'
|
||
|
|
||
|
|
||
|
def test_mat_delim_print():
|
||
|
expr = Matrix([[1, 2], [3, 4]])
|
||
|
assert mathml(expr, printer='presentation', mat_delim='[') == \
|
||
|
'<mfenced close="]" open="["><mtable><mtr><mtd><mn>1</mn></mtd><mtd>'\
|
||
|
'<mn>2</mn></mtd></mtr><mtr><mtd><mn>3</mn></mtd><mtd><mn>4</mn>'\
|
||
|
'</mtd></mtr></mtable></mfenced>'
|
||
|
assert mathml(expr, printer='presentation', mat_delim='(') == \
|
||
|
'<mfenced><mtable><mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd>'\
|
||
|
'</mtr><mtr><mtd><mn>3</mn></mtd><mtd><mn>4</mn></mtd></mtr></mtable></mfenced>'
|
||
|
assert mathml(expr, printer='presentation', mat_delim='') == \
|
||
|
'<mtable><mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd></mtr><mtr>'\
|
||
|
'<mtd><mn>3</mn></mtd><mtd><mn>4</mn></mtd></mtr></mtable>'
|
||
|
|
||
|
|
||
|
def test_ln_notation_print():
|
||
|
expr = log(x)
|
||
|
assert mathml(expr, printer='presentation') == \
|
||
|
'<mrow><mi>log</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mathml(expr, printer='presentation', ln_notation=False) == \
|
||
|
'<mrow><mi>log</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mathml(expr, printer='presentation', ln_notation=True) == \
|
||
|
'<mrow><mi>ln</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_mul_symbol_print():
|
||
|
expr = x * y
|
||
|
assert mathml(expr, printer='presentation') == \
|
||
|
'<mrow><mi>x</mi><mo>⁢</mo><mi>y</mi></mrow>'
|
||
|
assert mathml(expr, printer='presentation', mul_symbol=None) == \
|
||
|
'<mrow><mi>x</mi><mo>⁢</mo><mi>y</mi></mrow>'
|
||
|
assert mathml(expr, printer='presentation', mul_symbol='dot') == \
|
||
|
'<mrow><mi>x</mi><mo>·</mo><mi>y</mi></mrow>'
|
||
|
assert mathml(expr, printer='presentation', mul_symbol='ldot') == \
|
||
|
'<mrow><mi>x</mi><mo>․</mo><mi>y</mi></mrow>'
|
||
|
assert mathml(expr, printer='presentation', mul_symbol='times') == \
|
||
|
'<mrow><mi>x</mi><mo>×</mo><mi>y</mi></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_lerchphi():
|
||
|
assert mpp.doprint(lerchphi(1, 2, 3)) == \
|
||
|
'<mrow><mi>Φ</mi><mfenced><mn>1</mn><mn>2</mn><mn>3</mn></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_polylog():
|
||
|
assert mp.doprint(polylog(x, y)) == \
|
||
|
'<apply><polylog/><ci>x</ci><ci>y</ci></apply>'
|
||
|
assert mpp.doprint(polylog(x, y)) == \
|
||
|
'<mrow><msub><mi>Li</mi><mi>x</mi></msub><mfenced><mi>y</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_set_frozenset():
|
||
|
f = frozenset({1, 5, 3})
|
||
|
assert mpp.doprint(f) == \
|
||
|
'<mfenced close="}" open="{"><mn>1</mn><mn>3</mn><mn>5</mn></mfenced>'
|
||
|
s = set({1, 2, 3})
|
||
|
assert mpp.doprint(s) == \
|
||
|
'<mfenced close="}" open="{"><mn>1</mn><mn>2</mn><mn>3</mn></mfenced>'
|
||
|
|
||
|
|
||
|
def test_print_FiniteSet():
|
||
|
f1 = FiniteSet(x, 1, 3)
|
||
|
assert mpp.doprint(f1) == \
|
||
|
'<mfenced close="}" open="{"><mn>1</mn><mn>3</mn><mi>x</mi></mfenced>'
|
||
|
|
||
|
|
||
|
def test_print_LambertW():
|
||
|
assert mpp.doprint(LambertW(x)) == '<mrow><mi>W</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(LambertW(x, y)) == '<mrow><mi>W</mi><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_EmptySet():
|
||
|
assert mpp.doprint(S.EmptySet) == '<mo>∅</mo>'
|
||
|
|
||
|
|
||
|
def test_print_UniversalSet():
|
||
|
assert mpp.doprint(S.UniversalSet) == '<mo>𝕌</mo>'
|
||
|
|
||
|
|
||
|
def test_print_spaces():
|
||
|
assert mpp.doprint(HilbertSpace()) == '<mi>ℋ</mi>'
|
||
|
assert mpp.doprint(ComplexSpace(2)) == '<msup>𝒞<mn>2</mn></msup>'
|
||
|
assert mpp.doprint(FockSpace()) == '<mi>ℱ</mi>'
|
||
|
|
||
|
|
||
|
def test_print_constants():
|
||
|
assert mpp.doprint(hbar) == '<mi>ℏ</mi>'
|
||
|
assert mpp.doprint(S.TribonacciConstant) == '<mi>TribonacciConstant</mi>'
|
||
|
assert mpp.doprint(S.GoldenRatio) == '<mi>Φ</mi>'
|
||
|
assert mpp.doprint(S.EulerGamma) == '<mi>γ</mi>'
|
||
|
|
||
|
|
||
|
def test_print_Contains():
|
||
|
assert mpp.doprint(Contains(x, S.Naturals)) == \
|
||
|
'<mrow><mi>x</mi><mo>∈</mo><mi mathvariant="normal">ℕ</mi></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_Dagger():
|
||
|
assert mpp.doprint(Dagger(x)) == '<msup><mi>x</mi>†</msup>'
|
||
|
|
||
|
|
||
|
def test_print_SetOp():
|
||
|
f1 = FiniteSet(x, 1, 3)
|
||
|
f2 = FiniteSet(y, 2, 4)
|
||
|
|
||
|
prntr = lambda x: mathml(x, printer='presentation')
|
||
|
|
||
|
assert prntr(Union(f1, f2, evaluate=False)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mn>1</mn><mn>3</mn><mi>x</mi>'\
|
||
|
'</mfenced><mo>∪</mo><mfenced close="}" open="{"><mn>2</mn>'\
|
||
|
'<mn>4</mn><mi>y</mi></mfenced></mrow>'
|
||
|
assert prntr(Intersection(f1, f2, evaluate=False)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mn>1</mn><mn>3</mn><mi>x</mi>'\
|
||
|
'</mfenced><mo>∩</mo><mfenced close="}" open="{"><mn>2</mn>'\
|
||
|
'<mn>4</mn><mi>y</mi></mfenced></mrow>'
|
||
|
assert prntr(Complement(f1, f2, evaluate=False)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mn>1</mn><mn>3</mn><mi>x</mi>'\
|
||
|
'</mfenced><mo>∖</mo><mfenced close="}" open="{"><mn>2</mn>'\
|
||
|
'<mn>4</mn><mi>y</mi></mfenced></mrow>'
|
||
|
assert prntr(SymmetricDifference(f1, f2, evaluate=False)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mn>1</mn><mn>3</mn><mi>x</mi>'\
|
||
|
'</mfenced><mo>∆</mo><mfenced close="}" open="{"><mn>2</mn>'\
|
||
|
'<mn>4</mn><mi>y</mi></mfenced></mrow>'
|
||
|
|
||
|
A = FiniteSet(a)
|
||
|
C = FiniteSet(c)
|
||
|
D = FiniteSet(d)
|
||
|
|
||
|
U1 = Union(C, D, evaluate=False)
|
||
|
I1 = Intersection(C, D, evaluate=False)
|
||
|
C1 = Complement(C, D, evaluate=False)
|
||
|
D1 = SymmetricDifference(C, D, evaluate=False)
|
||
|
# XXX ProductSet does not support evaluate keyword
|
||
|
P1 = ProductSet(C, D)
|
||
|
|
||
|
assert prntr(Union(A, I1, evaluate=False)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mi>a</mi></mfenced>' \
|
||
|
'<mo>∪</mo><mfenced><mrow><mfenced close="}" open="{">' \
|
||
|
'<mi>c</mi></mfenced><mo>∩</mo><mfenced close="}" open="{">' \
|
||
|
'<mi>d</mi></mfenced></mrow></mfenced></mrow>'
|
||
|
assert prntr(Intersection(A, C1, evaluate=False)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mi>a</mi></mfenced>' \
|
||
|
'<mo>∩</mo><mfenced><mrow><mfenced close="}" open="{">' \
|
||
|
'<mi>c</mi></mfenced><mo>∖</mo><mfenced close="}" open="{">' \
|
||
|
'<mi>d</mi></mfenced></mrow></mfenced></mrow>'
|
||
|
assert prntr(Complement(A, D1, evaluate=False)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mi>a</mi></mfenced>' \
|
||
|
'<mo>∖</mo><mfenced><mrow><mfenced close="}" open="{">' \
|
||
|
'<mi>c</mi></mfenced><mo>∆</mo><mfenced close="}" open="{">' \
|
||
|
'<mi>d</mi></mfenced></mrow></mfenced></mrow>'
|
||
|
assert prntr(SymmetricDifference(A, P1, evaluate=False)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mi>a</mi></mfenced>' \
|
||
|
'<mo>∆</mo><mfenced><mrow><mfenced close="}" open="{">' \
|
||
|
'<mi>c</mi></mfenced><mo>×</mo><mfenced close="}" open="{">' \
|
||
|
'<mi>d</mi></mfenced></mrow></mfenced></mrow>'
|
||
|
assert prntr(ProductSet(A, U1)) == \
|
||
|
'<mrow><mfenced close="}" open="{"><mi>a</mi></mfenced>' \
|
||
|
'<mo>×</mo><mfenced><mrow><mfenced close="}" open="{">' \
|
||
|
'<mi>c</mi></mfenced><mo>∪</mo><mfenced close="}" open="{">' \
|
||
|
'<mi>d</mi></mfenced></mrow></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_logic():
|
||
|
assert mpp.doprint(And(x, y)) == \
|
||
|
'<mrow><mi>x</mi><mo>∧</mo><mi>y</mi></mrow>'
|
||
|
assert mpp.doprint(Or(x, y)) == \
|
||
|
'<mrow><mi>x</mi><mo>∨</mo><mi>y</mi></mrow>'
|
||
|
assert mpp.doprint(Xor(x, y)) == \
|
||
|
'<mrow><mi>x</mi><mo>⊻</mo><mi>y</mi></mrow>'
|
||
|
assert mpp.doprint(Implies(x, y)) == \
|
||
|
'<mrow><mi>x</mi><mo>⇒</mo><mi>y</mi></mrow>'
|
||
|
assert mpp.doprint(Equivalent(x, y)) == \
|
||
|
'<mrow><mi>x</mi><mo>⇔</mo><mi>y</mi></mrow>'
|
||
|
|
||
|
assert mpp.doprint(And(Eq(x, y), x > 4)) == \
|
||
|
'<mrow><mrow><mi>x</mi><mo>=</mo><mi>y</mi></mrow><mo>∧</mo>'\
|
||
|
'<mrow><mi>x</mi><mo>></mo><mn>4</mn></mrow></mrow>'
|
||
|
assert mpp.doprint(And(Eq(x, 3), y < 3, x > y + 1)) == \
|
||
|
'<mrow><mrow><mi>x</mi><mo>=</mo><mn>3</mn></mrow><mo>∧</mo>'\
|
||
|
'<mrow><mi>x</mi><mo>></mo><mrow><mi>y</mi><mo>+</mo><mn>1</mn></mrow>'\
|
||
|
'</mrow><mo>∧</mo><mrow><mi>y</mi><mo><</mo><mn>3</mn></mrow></mrow>'
|
||
|
assert mpp.doprint(Or(Eq(x, y), x > 4)) == \
|
||
|
'<mrow><mrow><mi>x</mi><mo>=</mo><mi>y</mi></mrow><mo>∨</mo>'\
|
||
|
'<mrow><mi>x</mi><mo>></mo><mn>4</mn></mrow></mrow>'
|
||
|
assert mpp.doprint(And(Eq(x, 3), Or(y < 3, x > y + 1))) == \
|
||
|
'<mrow><mrow><mi>x</mi><mo>=</mo><mn>3</mn></mrow><mo>∧</mo>'\
|
||
|
'<mfenced><mrow><mrow><mi>x</mi><mo>></mo><mrow><mi>y</mi><mo>+</mo>'\
|
||
|
'<mn>1</mn></mrow></mrow><mo>∨</mo><mrow><mi>y</mi><mo><</mo>'\
|
||
|
'<mn>3</mn></mrow></mrow></mfenced></mrow>'
|
||
|
|
||
|
assert mpp.doprint(Not(x)) == '<mrow><mo>¬</mo><mi>x</mi></mrow>'
|
||
|
assert mpp.doprint(Not(And(x, y))) == \
|
||
|
'<mrow><mo>¬</mo><mfenced><mrow><mi>x</mi><mo>∧</mo>'\
|
||
|
'<mi>y</mi></mrow></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_root_notation_print():
|
||
|
assert mathml(x**(S.One/3), printer='presentation') == \
|
||
|
'<mroot><mi>x</mi><mn>3</mn></mroot>'
|
||
|
assert mathml(x**(S.One/3), printer='presentation', root_notation=False) ==\
|
||
|
'<msup><mi>x</mi><mfrac><mn>1</mn><mn>3</mn></mfrac></msup>'
|
||
|
assert mathml(x**(S.One/3), printer='content') == \
|
||
|
'<apply><root/><degree><cn>3</cn></degree><ci>x</ci></apply>'
|
||
|
assert mathml(x**(S.One/3), printer='content', root_notation=False) == \
|
||
|
'<apply><power/><ci>x</ci><apply><divide/><cn>1</cn><cn>3</cn></apply></apply>'
|
||
|
assert mathml(x**(Rational(-1, 3)), printer='presentation') == \
|
||
|
'<mfrac><mn>1</mn><mroot><mi>x</mi><mn>3</mn></mroot></mfrac>'
|
||
|
assert mathml(x**(Rational(-1, 3)), printer='presentation', root_notation=False) \
|
||
|
== '<mfrac><mn>1</mn><msup><mi>x</mi><mfrac><mn>1</mn><mn>3</mn></mfrac></msup></mfrac>'
|
||
|
|
||
|
|
||
|
def test_fold_frac_powers_print():
|
||
|
expr = x ** Rational(5, 2)
|
||
|
assert mathml(expr, printer='presentation') == \
|
||
|
'<msup><mi>x</mi><mfrac><mn>5</mn><mn>2</mn></mfrac></msup>'
|
||
|
assert mathml(expr, printer='presentation', fold_frac_powers=True) == \
|
||
|
'<msup><mi>x</mi><mfrac bevelled="true"><mn>5</mn><mn>2</mn></mfrac></msup>'
|
||
|
assert mathml(expr, printer='presentation', fold_frac_powers=False) == \
|
||
|
'<msup><mi>x</mi><mfrac><mn>5</mn><mn>2</mn></mfrac></msup>'
|
||
|
|
||
|
|
||
|
def test_fold_short_frac_print():
|
||
|
expr = Rational(2, 5)
|
||
|
assert mathml(expr, printer='presentation') == \
|
||
|
'<mfrac><mn>2</mn><mn>5</mn></mfrac>'
|
||
|
assert mathml(expr, printer='presentation', fold_short_frac=True) == \
|
||
|
'<mfrac bevelled="true"><mn>2</mn><mn>5</mn></mfrac>'
|
||
|
assert mathml(expr, printer='presentation', fold_short_frac=False) == \
|
||
|
'<mfrac><mn>2</mn><mn>5</mn></mfrac>'
|
||
|
|
||
|
|
||
|
def test_print_factorials():
|
||
|
assert mpp.doprint(factorial(x)) == '<mrow><mi>x</mi><mo>!</mo></mrow>'
|
||
|
assert mpp.doprint(factorial(x + 1)) == \
|
||
|
'<mrow><mfenced><mrow><mi>x</mi><mo>+</mo><mn>1</mn></mrow></mfenced><mo>!</mo></mrow>'
|
||
|
assert mpp.doprint(factorial2(x)) == '<mrow><mi>x</mi><mo>!!</mo></mrow>'
|
||
|
assert mpp.doprint(factorial2(x + 1)) == \
|
||
|
'<mrow><mfenced><mrow><mi>x</mi><mo>+</mo><mn>1</mn></mrow></mfenced><mo>!!</mo></mrow>'
|
||
|
assert mpp.doprint(binomial(x, y)) == \
|
||
|
'<mfenced><mfrac linethickness="0"><mi>x</mi><mi>y</mi></mfrac></mfenced>'
|
||
|
assert mpp.doprint(binomial(4, x + y)) == \
|
||
|
'<mfenced><mfrac linethickness="0"><mn>4</mn><mrow><mi>x</mi>'\
|
||
|
'<mo>+</mo><mi>y</mi></mrow></mfrac></mfenced>'
|
||
|
|
||
|
|
||
|
def test_print_floor():
|
||
|
expr = floor(x)
|
||
|
assert mathml(expr, printer='presentation') == \
|
||
|
'<mrow><mfenced close="⌋" open="⌊"><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_ceiling():
|
||
|
expr = ceiling(x)
|
||
|
assert mathml(expr, printer='presentation') == \
|
||
|
'<mrow><mfenced close="⌉" open="⌈"><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_Lambda():
|
||
|
expr = Lambda(x, x+1)
|
||
|
assert mathml(expr, printer='presentation') == \
|
||
|
'<mfenced><mrow><mi>x</mi><mo>↦</mo><mrow><mi>x</mi><mo>+</mo>'\
|
||
|
'<mn>1</mn></mrow></mrow></mfenced>'
|
||
|
expr = Lambda((x, y), x + y)
|
||
|
assert mathml(expr, printer='presentation') == \
|
||
|
'<mfenced><mrow><mrow><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'\
|
||
|
'<mo>↦</mo><mrow><mi>x</mi><mo>+</mo><mi>y</mi></mrow></mrow></mfenced>'
|
||
|
|
||
|
|
||
|
def test_print_conjugate():
|
||
|
assert mpp.doprint(conjugate(x)) == \
|
||
|
'<menclose notation="top"><mi>x</mi></menclose>'
|
||
|
assert mpp.doprint(conjugate(x + 1)) == \
|
||
|
'<mrow><menclose notation="top"><mi>x</mi></menclose><mo>+</mo><mn>1</mn></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_AccumBounds():
|
||
|
a = Symbol('a', real=True)
|
||
|
assert mpp.doprint(AccumBounds(0, 1)) == '<mfenced close="⟩" open="⟨"><mn>0</mn><mn>1</mn></mfenced>'
|
||
|
assert mpp.doprint(AccumBounds(0, a)) == '<mfenced close="⟩" open="⟨"><mn>0</mn><mi>a</mi></mfenced>'
|
||
|
assert mpp.doprint(AccumBounds(a + 1, a + 2)) == '<mfenced close="⟩" open="⟨"><mrow><mi>a</mi><mo>+</mo><mn>1</mn></mrow><mrow><mi>a</mi><mo>+</mo><mn>2</mn></mrow></mfenced>'
|
||
|
|
||
|
|
||
|
def test_print_Float():
|
||
|
assert mpp.doprint(Float(1e100)) == '<mrow><mn>1.0</mn><mo>·</mo><msup><mn>10</mn><mn>100</mn></msup></mrow>'
|
||
|
assert mpp.doprint(Float(1e-100)) == '<mrow><mn>1.0</mn><mo>·</mo><msup><mn>10</mn><mn>-100</mn></msup></mrow>'
|
||
|
assert mpp.doprint(Float(-1e100)) == '<mrow><mn>-1.0</mn><mo>·</mo><msup><mn>10</mn><mn>100</mn></msup></mrow>'
|
||
|
assert mpp.doprint(Float(1.0*oo)) == '<mi>∞</mi>'
|
||
|
assert mpp.doprint(Float(-1.0*oo)) == '<mrow><mo>-</mo><mi>∞</mi></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_different_functions():
|
||
|
assert mpp.doprint(gamma(x)) == '<mrow><mi>Γ</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(lowergamma(x, y)) == '<mrow><mi>γ</mi><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(uppergamma(x, y)) == '<mrow><mi>Γ</mi><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(zeta(x)) == '<mrow><mi>ζ</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(zeta(x, y)) == '<mrow><mi>ζ</mi><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(dirichlet_eta(x)) == '<mrow><mi>η</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(elliptic_k(x)) == '<mrow><mi>Κ</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(totient(x)) == '<mrow><mi>ϕ</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(reduced_totient(x)) == '<mrow><mi>λ</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(primenu(x)) == '<mrow><mi>ν</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(primeomega(x)) == '<mrow><mi>Ω</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(fresnels(x)) == '<mrow><mi>S</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(fresnelc(x)) == '<mrow><mi>C</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Heaviside(x)) == '<mrow><mi>Θ</mi><mfenced><mi>x</mi><mfrac><mn>1</mn><mn>2</mn></mfrac></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_mathml_builtins():
|
||
|
assert mpp.doprint(None) == '<mi>None</mi>'
|
||
|
assert mpp.doprint(true) == '<mi>True</mi>'
|
||
|
assert mpp.doprint(false) == '<mi>False</mi>'
|
||
|
|
||
|
|
||
|
def test_mathml_Range():
|
||
|
assert mpp.doprint(Range(1, 51)) == \
|
||
|
'<mfenced close="}" open="{"><mn>1</mn><mn>2</mn><mi>…</mi><mn>50</mn></mfenced>'
|
||
|
assert mpp.doprint(Range(1, 4)) == \
|
||
|
'<mfenced close="}" open="{"><mn>1</mn><mn>2</mn><mn>3</mn></mfenced>'
|
||
|
assert mpp.doprint(Range(0, 3, 1)) == \
|
||
|
'<mfenced close="}" open="{"><mn>0</mn><mn>1</mn><mn>2</mn></mfenced>'
|
||
|
assert mpp.doprint(Range(0, 30, 1)) == \
|
||
|
'<mfenced close="}" open="{"><mn>0</mn><mn>1</mn><mi>…</mi><mn>29</mn></mfenced>'
|
||
|
assert mpp.doprint(Range(30, 1, -1)) == \
|
||
|
'<mfenced close="}" open="{"><mn>30</mn><mn>29</mn><mi>…</mi>'\
|
||
|
'<mn>2</mn></mfenced>'
|
||
|
assert mpp.doprint(Range(0, oo, 2)) == \
|
||
|
'<mfenced close="}" open="{"><mn>0</mn><mn>2</mn><mi>…</mi></mfenced>'
|
||
|
assert mpp.doprint(Range(oo, -2, -2)) == \
|
||
|
'<mfenced close="}" open="{"><mi>…</mi><mn>2</mn><mn>0</mn></mfenced>'
|
||
|
assert mpp.doprint(Range(-2, -oo, -1)) == \
|
||
|
'<mfenced close="}" open="{"><mn>-2</mn><mn>-3</mn><mi>…</mi></mfenced>'
|
||
|
|
||
|
|
||
|
def test_print_exp():
|
||
|
assert mpp.doprint(exp(x)) == \
|
||
|
'<msup><mi>ⅇ</mi><mi>x</mi></msup>'
|
||
|
assert mpp.doprint(exp(1) + exp(2)) == \
|
||
|
'<mrow><mi>ⅇ</mi><mo>+</mo><msup><mi>ⅇ</mi><mn>2</mn></msup></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_MinMax():
|
||
|
assert mpp.doprint(Min(x, y)) == \
|
||
|
'<mrow><mo>min</mo><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Min(x, 2, x**3)) == \
|
||
|
'<mrow><mo>min</mo><mfenced><mn>2</mn><mi>x</mi><msup><mi>x</mi>'\
|
||
|
'<mn>3</mn></msup></mfenced></mrow>'
|
||
|
assert mpp.doprint(Max(x, y)) == \
|
||
|
'<mrow><mo>max</mo><mfenced><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
assert mpp.doprint(Max(x, 2, x**3)) == \
|
||
|
'<mrow><mo>max</mo><mfenced><mn>2</mn><mi>x</mi><msup><mi>x</mi>'\
|
||
|
'<mn>3</mn></msup></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_mathml_presentation_numbers():
|
||
|
n = Symbol('n')
|
||
|
assert mathml(catalan(n), printer='presentation') == \
|
||
|
'<msub><mi>C</mi><mi>n</mi></msub>'
|
||
|
assert mathml(bernoulli(n), printer='presentation') == \
|
||
|
'<msub><mi>B</mi><mi>n</mi></msub>'
|
||
|
assert mathml(bell(n), printer='presentation') == \
|
||
|
'<msub><mi>B</mi><mi>n</mi></msub>'
|
||
|
assert mathml(euler(n), printer='presentation') == \
|
||
|
'<msub><mi>E</mi><mi>n</mi></msub>'
|
||
|
assert mathml(fibonacci(n), printer='presentation') == \
|
||
|
'<msub><mi>F</mi><mi>n</mi></msub>'
|
||
|
assert mathml(lucas(n), printer='presentation') == \
|
||
|
'<msub><mi>L</mi><mi>n</mi></msub>'
|
||
|
assert mathml(tribonacci(n), printer='presentation') == \
|
||
|
'<msub><mi>T</mi><mi>n</mi></msub>'
|
||
|
assert mathml(bernoulli(n, x), printer='presentation') == \
|
||
|
'<mrow><msub><mi>B</mi><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mathml(bell(n, x), printer='presentation') == \
|
||
|
'<mrow><msub><mi>B</mi><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mathml(euler(n, x), printer='presentation') == \
|
||
|
'<mrow><msub><mi>E</mi><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mathml(fibonacci(n, x), printer='presentation') == \
|
||
|
'<mrow><msub><mi>F</mi><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mathml(tribonacci(n, x), printer='presentation') == \
|
||
|
'<mrow><msub><mi>T</mi><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_mathml_presentation_mathieu():
|
||
|
assert mathml(mathieuc(x, y, z), printer='presentation') == \
|
||
|
'<mrow><mi>C</mi><mfenced><mi>x</mi><mi>y</mi><mi>z</mi></mfenced></mrow>'
|
||
|
assert mathml(mathieus(x, y, z), printer='presentation') == \
|
||
|
'<mrow><mi>S</mi><mfenced><mi>x</mi><mi>y</mi><mi>z</mi></mfenced></mrow>'
|
||
|
assert mathml(mathieucprime(x, y, z), printer='presentation') == \
|
||
|
'<mrow><mi>C′</mi><mfenced><mi>x</mi><mi>y</mi><mi>z</mi></mfenced></mrow>'
|
||
|
assert mathml(mathieusprime(x, y, z), printer='presentation') == \
|
||
|
'<mrow><mi>S′</mi><mfenced><mi>x</mi><mi>y</mi><mi>z</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_mathml_presentation_stieltjes():
|
||
|
assert mathml(stieltjes(n), printer='presentation') == \
|
||
|
'<msub><mi>γ</mi><mi>n</mi></msub>'
|
||
|
assert mathml(stieltjes(n, x), printer='presentation') == \
|
||
|
'<mrow><msub><mi>γ</mi><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_matrix_symbol():
|
||
|
A = MatrixSymbol('A', 1, 2)
|
||
|
assert mpp.doprint(A) == '<mi>A</mi>'
|
||
|
assert mp.doprint(A) == '<ci>A</ci>'
|
||
|
assert mathml(A, printer='presentation', mat_symbol_style="bold") == \
|
||
|
'<mi mathvariant="bold">A</mi>'
|
||
|
# No effect in content printer
|
||
|
assert mathml(A, mat_symbol_style="bold") == '<ci>A</ci>'
|
||
|
|
||
|
|
||
|
def test_print_hadamard():
|
||
|
from sympy.matrices.expressions import HadamardProduct
|
||
|
from sympy.matrices.expressions import Transpose
|
||
|
|
||
|
X = MatrixSymbol('X', 2, 2)
|
||
|
Y = MatrixSymbol('Y', 2, 2)
|
||
|
|
||
|
assert mathml(HadamardProduct(X, Y*Y), printer="presentation") == \
|
||
|
'<mrow>' \
|
||
|
'<mi>X</mi>' \
|
||
|
'<mo>∘</mo>' \
|
||
|
'<msup><mi>Y</mi><mn>2</mn></msup>' \
|
||
|
'</mrow>'
|
||
|
|
||
|
assert mathml(HadamardProduct(X, Y)*Y, printer="presentation") == \
|
||
|
'<mrow>' \
|
||
|
'<mfenced>' \
|
||
|
'<mrow><mi>X</mi><mo>∘</mo><mi>Y</mi></mrow>' \
|
||
|
'</mfenced>' \
|
||
|
'<mo>⁢</mo><mi>Y</mi>' \
|
||
|
'</mrow>'
|
||
|
|
||
|
assert mathml(HadamardProduct(X, Y, Y), printer="presentation") == \
|
||
|
'<mrow>' \
|
||
|
'<mi>X</mi><mo>∘</mo>' \
|
||
|
'<mi>Y</mi><mo>∘</mo>' \
|
||
|
'<mi>Y</mi>' \
|
||
|
'</mrow>'
|
||
|
|
||
|
assert mathml(
|
||
|
Transpose(HadamardProduct(X, Y)), printer="presentation") == \
|
||
|
'<msup>' \
|
||
|
'<mfenced>' \
|
||
|
'<mrow><mi>X</mi><mo>∘</mo><mi>Y</mi></mrow>' \
|
||
|
'</mfenced>' \
|
||
|
'<mo>T</mo>' \
|
||
|
'</msup>'
|
||
|
|
||
|
|
||
|
def test_print_random_symbol():
|
||
|
R = RandomSymbol(Symbol('R'))
|
||
|
assert mpp.doprint(R) == '<mi>R</mi>'
|
||
|
assert mp.doprint(R) == '<ci>R</ci>'
|
||
|
|
||
|
|
||
|
def test_print_IndexedBase():
|
||
|
assert mathml(IndexedBase(a)[b], printer='presentation') == \
|
||
|
'<msub><mi>a</mi><mi>b</mi></msub>'
|
||
|
assert mathml(IndexedBase(a)[b, c, d], printer='presentation') == \
|
||
|
'<msub><mi>a</mi><mfenced><mi>b</mi><mi>c</mi><mi>d</mi></mfenced></msub>'
|
||
|
assert mathml(IndexedBase(a)[b]*IndexedBase(c)[d]*IndexedBase(e),
|
||
|
printer='presentation') == \
|
||
|
'<mrow><msub><mi>a</mi><mi>b</mi></msub><mo>⁢'\
|
||
|
'</mo><msub><mi>c</mi><mi>d</mi></msub><mo>⁢</mo><mi>e</mi></mrow>'
|
||
|
|
||
|
|
||
|
def test_print_Indexed():
|
||
|
assert mathml(IndexedBase(a), printer='presentation') == '<mi>a</mi>'
|
||
|
assert mathml(IndexedBase(a/b), printer='presentation') == \
|
||
|
'<mrow><mfrac><mi>a</mi><mi>b</mi></mfrac></mrow>'
|
||
|
assert mathml(IndexedBase((a, b)), printer='presentation') == \
|
||
|
'<mrow><mfenced><mi>a</mi><mi>b</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_MatrixElement():
|
||
|
i, j = symbols('i j')
|
||
|
A = MatrixSymbol('A', i, j)
|
||
|
assert mathml(A[0,0],printer = 'presentation') == \
|
||
|
'<msub><mi>A</mi><mfenced close="" open=""><mn>0</mn><mn>0</mn></mfenced></msub>'
|
||
|
assert mathml(A[i,j], printer = 'presentation') == \
|
||
|
'<msub><mi>A</mi><mfenced close="" open=""><mi>i</mi><mi>j</mi></mfenced></msub>'
|
||
|
assert mathml(A[i*j,0], printer = 'presentation') == \
|
||
|
'<msub><mi>A</mi><mfenced close="" open=""><mrow><mi>i</mi><mo>⁢</mo><mi>j</mi></mrow><mn>0</mn></mfenced></msub>'
|
||
|
|
||
|
|
||
|
def test_print_Vector():
|
||
|
ACS = CoordSys3D('A')
|
||
|
assert mathml(Cross(ACS.i, ACS.j*ACS.x*3 + ACS.k), printer='presentation') == \
|
||
|
'<mrow><msub><mover><mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>×</mo><mfenced><mrow>'\
|
||
|
'<mfenced><mrow><mn>3</mn><mo>⁢</mo><msub>'\
|
||
|
'<mi mathvariant="bold">x</mi><mi mathvariant="bold">A</mi></msub>'\
|
||
|
'</mrow></mfenced><mo>⁢</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>+</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">k</mi><mo>^</mo></mover><mi mathvariant="bold">'\
|
||
|
'A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Cross(ACS.i, ACS.j), printer='presentation') == \
|
||
|
'<mrow><msub><mover><mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>×</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow>'
|
||
|
assert mathml(x*Cross(ACS.i, ACS.j), printer='presentation') == \
|
||
|
'<mrow><mi>x</mi><mo>⁢</mo><mfenced><mrow><msub><mover>'\
|
||
|
'<mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>×</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Cross(x*ACS.i, ACS.j), printer='presentation') == \
|
||
|
'<mrow><mo>-</mo><mrow><msub><mover><mi mathvariant="bold">j</mi>'\
|
||
|
'<mo>^</mo></mover><mi mathvariant="bold">A</mi></msub>'\
|
||
|
'<mo>×</mo><mfenced><mrow><mfenced><mi>x</mi></mfenced>'\
|
||
|
'<mo>⁢</mo><msub><mover><mi mathvariant="bold">i</mi>'\
|
||
|
'<mo>^</mo></mover><mi mathvariant="bold">A</mi></msub></mrow>'\
|
||
|
'</mfenced></mrow></mrow>'
|
||
|
assert mathml(Curl(3*ACS.x*ACS.j), printer='presentation') == \
|
||
|
'<mrow><mo>∇</mo><mo>×</mo><mfenced><mrow><mfenced><mrow>'\
|
||
|
'<mn>3</mn><mo>⁢</mo><msub>'\
|
||
|
'<mi mathvariant="bold">x</mi><mi mathvariant="bold">A</mi></msub>'\
|
||
|
'</mrow></mfenced><mo>⁢</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Curl(3*x*ACS.x*ACS.j), printer='presentation') == \
|
||
|
'<mrow><mo>∇</mo><mo>×</mo><mfenced><mrow><mfenced><mrow>'\
|
||
|
'<mn>3</mn><mo>⁢</mo><msub><mi mathvariant="bold">x'\
|
||
|
'</mi><mi mathvariant="bold">A</mi></msub><mo>⁢</mo>'\
|
||
|
'<mi>x</mi></mrow></mfenced><mo>⁢</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(x*Curl(3*ACS.x*ACS.j), printer='presentation') == \
|
||
|
'<mrow><mi>x</mi><mo>⁢</mo><mfenced><mrow><mo>∇</mo>'\
|
||
|
'<mo>×</mo><mfenced><mrow><mfenced><mrow><mn>3</mn>'\
|
||
|
'<mo>⁢</mo><msub><mi mathvariant="bold">x</mi>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced>'\
|
||
|
'<mo>⁢</mo><msub><mover><mi mathvariant="bold">j</mi>'\
|
||
|
'<mo>^</mo></mover><mi mathvariant="bold">A</mi></msub></mrow>'\
|
||
|
'</mfenced></mrow></mfenced></mrow>'
|
||
|
assert mathml(Curl(3*x*ACS.x*ACS.j + ACS.i), printer='presentation') == \
|
||
|
'<mrow><mo>∇</mo><mo>×</mo><mfenced><mrow><msub><mover>'\
|
||
|
'<mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>+</mo><mfenced><mrow>'\
|
||
|
'<mn>3</mn><mo>⁢</mo><msub><mi mathvariant="bold">x'\
|
||
|
'</mi><mi mathvariant="bold">A</mi></msub><mo>⁢</mo>'\
|
||
|
'<mi>x</mi></mrow></mfenced><mo>⁢</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Divergence(3*ACS.x*ACS.j), printer='presentation') == \
|
||
|
'<mrow><mo>∇</mo><mo>·</mo><mfenced><mrow><mfenced><mrow>'\
|
||
|
'<mn>3</mn><mo>⁢</mo><msub><mi mathvariant="bold">x'\
|
||
|
'</mi><mi mathvariant="bold">A</mi></msub></mrow></mfenced>'\
|
||
|
'<mo>⁢</mo><msub><mover><mi mathvariant="bold">j</mi>'\
|
||
|
'<mo>^</mo></mover><mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(x*Divergence(3*ACS.x*ACS.j), printer='presentation') == \
|
||
|
'<mrow><mi>x</mi><mo>⁢</mo><mfenced><mrow><mo>∇</mo>'\
|
||
|
'<mo>·</mo><mfenced><mrow><mfenced><mrow><mn>3</mn>'\
|
||
|
'<mo>⁢</mo><msub><mi mathvariant="bold">x</mi>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced>'\
|
||
|
'<mo>⁢</mo><msub><mover><mi mathvariant="bold">j</mi>'\
|
||
|
'<mo>^</mo></mover><mi mathvariant="bold">A</mi></msub></mrow>'\
|
||
|
'</mfenced></mrow></mfenced></mrow>'
|
||
|
assert mathml(Divergence(3*x*ACS.x*ACS.j + ACS.i), printer='presentation') == \
|
||
|
'<mrow><mo>∇</mo><mo>·</mo><mfenced><mrow><msub><mover>'\
|
||
|
'<mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>+</mo><mfenced><mrow>'\
|
||
|
'<mn>3</mn><mo>⁢</mo><msub>'\
|
||
|
'<mi mathvariant="bold">x</mi><mi mathvariant="bold">A</mi></msub>'\
|
||
|
'<mo>⁢</mo><mi>x</mi></mrow></mfenced>'\
|
||
|
'<mo>⁢</mo><msub><mover><mi mathvariant="bold">j</mi>'\
|
||
|
'<mo>^</mo></mover><mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Dot(ACS.i, ACS.j*ACS.x*3+ACS.k), printer='presentation') == \
|
||
|
'<mrow><msub><mover><mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>·</mo><mfenced><mrow>'\
|
||
|
'<mfenced><mrow><mn>3</mn><mo>⁢</mo><msub>'\
|
||
|
'<mi mathvariant="bold">x</mi><mi mathvariant="bold">A</mi></msub>'\
|
||
|
'</mrow></mfenced><mo>⁢</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>+</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">k</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Dot(ACS.i, ACS.j), printer='presentation') == \
|
||
|
'<mrow><msub><mover><mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>·</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow>'
|
||
|
assert mathml(Dot(x*ACS.i, ACS.j), printer='presentation') == \
|
||
|
'<mrow><msub><mover><mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>·</mo><mfenced><mrow>'\
|
||
|
'<mfenced><mi>x</mi></mfenced><mo>⁢</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(x*Dot(ACS.i, ACS.j), printer='presentation') == \
|
||
|
'<mrow><mi>x</mi><mo>⁢</mo><mfenced><mrow><msub><mover>'\
|
||
|
'<mi mathvariant="bold">i</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>·</mo><msub><mover>'\
|
||
|
'<mi mathvariant="bold">j</mi><mo>^</mo></mover>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Gradient(ACS.x), printer='presentation') == \
|
||
|
'<mrow><mo>∇</mo><msub><mi mathvariant="bold">x</mi>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow>'
|
||
|
assert mathml(Gradient(ACS.x + 3*ACS.y), printer='presentation') == \
|
||
|
'<mrow><mo>∇</mo><mfenced><mrow><msub><mi mathvariant="bold">'\
|
||
|
'x</mi><mi mathvariant="bold">A</mi></msub><mo>+</mo><mrow><mn>3</mn>'\
|
||
|
'<mo>⁢</mo><msub><mi mathvariant="bold">y</mi>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mrow></mfenced></mrow>'
|
||
|
assert mathml(x*Gradient(ACS.x), printer='presentation') == \
|
||
|
'<mrow><mi>x</mi><mo>⁢</mo><mfenced><mrow><mo>∇</mo>'\
|
||
|
'<msub><mi mathvariant="bold">x</mi><mi mathvariant="bold">A</mi>'\
|
||
|
'</msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Gradient(x*ACS.x), printer='presentation') == \
|
||
|
'<mrow><mo>∇</mo><mfenced><mrow><msub><mi mathvariant="bold">'\
|
||
|
'x</mi><mi mathvariant="bold">A</mi></msub><mo>⁢</mo>'\
|
||
|
'<mi>x</mi></mrow></mfenced></mrow>'
|
||
|
assert mathml(Cross(ACS.x, ACS.z) + Cross(ACS.z, ACS.x), printer='presentation') == \
|
||
|
'<mover><mi mathvariant="bold">0</mi><mo>^</mo></mover>'
|
||
|
assert mathml(Cross(ACS.z, ACS.x), printer='presentation') == \
|
||
|
'<mrow><mo>-</mo><mrow><msub><mi mathvariant="bold">x</mi>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub><mo>×</mo><msub>'\
|
||
|
'<mi mathvariant="bold">z</mi><mi mathvariant="bold">A</mi></msub></mrow></mrow>'
|
||
|
assert mathml(Laplacian(ACS.x), printer='presentation') == \
|
||
|
'<mrow><mo>∆</mo><msub><mi mathvariant="bold">x</mi>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow>'
|
||
|
assert mathml(Laplacian(ACS.x + 3*ACS.y), printer='presentation') == \
|
||
|
'<mrow><mo>∆</mo><mfenced><mrow><msub><mi mathvariant="bold">'\
|
||
|
'x</mi><mi mathvariant="bold">A</mi></msub><mo>+</mo><mrow><mn>3</mn>'\
|
||
|
'<mo>⁢</mo><msub><mi mathvariant="bold">y</mi>'\
|
||
|
'<mi mathvariant="bold">A</mi></msub></mrow></mrow></mfenced></mrow>'
|
||
|
assert mathml(x*Laplacian(ACS.x), printer='presentation') == \
|
||
|
'<mrow><mi>x</mi><mo>⁢</mo><mfenced><mrow><mo>∆</mo>'\
|
||
|
'<msub><mi mathvariant="bold">x</mi><mi mathvariant="bold">A</mi>'\
|
||
|
'</msub></mrow></mfenced></mrow>'
|
||
|
assert mathml(Laplacian(x*ACS.x), printer='presentation') == \
|
||
|
'<mrow><mo>∆</mo><mfenced><mrow><msub><mi mathvariant="bold">'\
|
||
|
'x</mi><mi mathvariant="bold">A</mi></msub><mo>⁢</mo>'\
|
||
|
'<mi>x</mi></mrow></mfenced></mrow>'
|
||
|
|
||
|
def test_print_elliptic_f():
|
||
|
assert mathml(elliptic_f(x, y), printer = 'presentation') == \
|
||
|
'<mrow><mi>𝖥</mi><mfenced separators="|"><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
assert mathml(elliptic_f(x/y, y), printer = 'presentation') == \
|
||
|
'<mrow><mi>𝖥</mi><mfenced separators="|"><mrow><mfrac><mi>x</mi><mi>y</mi></mfrac></mrow><mi>y</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_elliptic_e():
|
||
|
assert mathml(elliptic_e(x), printer = 'presentation') == \
|
||
|
'<mrow><mi>𝖤</mi><mfenced separators="|"><mi>x</mi></mfenced></mrow>'
|
||
|
assert mathml(elliptic_e(x, y), printer = 'presentation') == \
|
||
|
'<mrow><mi>𝖤</mi><mfenced separators="|"><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_elliptic_pi():
|
||
|
assert mathml(elliptic_pi(x, y), printer = 'presentation') == \
|
||
|
'<mrow><mi>𝛱</mi><mfenced separators="|"><mi>x</mi><mi>y</mi></mfenced></mrow>'
|
||
|
assert mathml(elliptic_pi(x, y, z), printer = 'presentation') == \
|
||
|
'<mrow><mi>𝛱</mi><mfenced separators=";|"><mi>x</mi><mi>y</mi><mi>z</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_Ei():
|
||
|
assert mathml(Ei(x), printer = 'presentation') == \
|
||
|
'<mrow><mi>Ei</mi><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
assert mathml(Ei(x**y), printer = 'presentation') == \
|
||
|
'<mrow><mi>Ei</mi><mfenced><msup><mi>x</mi><mi>y</mi></msup></mfenced></mrow>'
|
||
|
|
||
|
def test_print_expint():
|
||
|
assert mathml(expint(x, y), printer = 'presentation') == \
|
||
|
'<mrow><msub><mo>E</mo><mi>x</mi></msub><mfenced><mi>y</mi></mfenced></mrow>'
|
||
|
assert mathml(expint(IndexedBase(x)[1], IndexedBase(x)[2]), printer = 'presentation') == \
|
||
|
'<mrow><msub><mo>E</mo><msub><mi>x</mi><mn>1</mn></msub></msub><mfenced><msub><mi>x</mi><mn>2</mn></msub></mfenced></mrow>'
|
||
|
|
||
|
def test_print_jacobi():
|
||
|
assert mathml(jacobi(n, a, b, x), printer = 'presentation') == \
|
||
|
'<mrow><msubsup><mo>P</mo><mi>n</mi><mfenced><mi>a</mi><mi>b</mi></mfenced></msubsup><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_gegenbauer():
|
||
|
assert mathml(gegenbauer(n, a, x), printer = 'presentation') == \
|
||
|
'<mrow><msubsup><mo>C</mo><mi>n</mi><mfenced><mi>a</mi></mfenced></msubsup><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_chebyshevt():
|
||
|
assert mathml(chebyshevt(n, x), printer = 'presentation') == \
|
||
|
'<mrow><msub><mo>T</mo><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_chebyshevu():
|
||
|
assert mathml(chebyshevu(n, x), printer = 'presentation') == \
|
||
|
'<mrow><msub><mo>U</mo><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_legendre():
|
||
|
assert mathml(legendre(n, x), printer = 'presentation') == \
|
||
|
'<mrow><msub><mo>P</mo><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_assoc_legendre():
|
||
|
assert mathml(assoc_legendre(n, a, x), printer = 'presentation') == \
|
||
|
'<mrow><msubsup><mo>P</mo><mi>n</mi><mfenced><mi>a</mi></mfenced></msubsup><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_laguerre():
|
||
|
assert mathml(laguerre(n, x), printer = 'presentation') == \
|
||
|
'<mrow><msub><mo>L</mo><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_assoc_laguerre():
|
||
|
assert mathml(assoc_laguerre(n, a, x), printer = 'presentation') == \
|
||
|
'<mrow><msubsup><mo>L</mo><mi>n</mi><mfenced><mi>a</mi></mfenced></msubsup><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_print_hermite():
|
||
|
assert mathml(hermite(n, x), printer = 'presentation') == \
|
||
|
'<mrow><msub><mo>H</mo><mi>n</mi></msub><mfenced><mi>x</mi></mfenced></mrow>'
|
||
|
|
||
|
def test_mathml_SingularityFunction():
|
||
|
assert mathml(SingularityFunction(x, 4, 5), printer='presentation') == \
|
||
|
'<msup><mfenced close="⟩" open="⟨"><mrow><mi>x</mi>' \
|
||
|
'<mo>-</mo><mn>4</mn></mrow></mfenced><mn>5</mn></msup>'
|
||
|
assert mathml(SingularityFunction(x, -3, 4), printer='presentation') == \
|
||
|
'<msup><mfenced close="⟩" open="⟨"><mrow><mi>x</mi>' \
|
||
|
'<mo>+</mo><mn>3</mn></mrow></mfenced><mn>4</mn></msup>'
|
||
|
assert mathml(SingularityFunction(x, 0, 4), printer='presentation') == \
|
||
|
'<msup><mfenced close="⟩" open="⟨"><mi>x</mi></mfenced>' \
|
||
|
'<mn>4</mn></msup>'
|
||
|
assert mathml(SingularityFunction(x, a, n), printer='presentation') == \
|
||
|
'<msup><mfenced close="⟩" open="⟨"><mrow><mrow>' \
|
||
|
'<mo>-</mo><mi>a</mi></mrow><mo>+</mo><mi>x</mi></mrow></mfenced>' \
|
||
|
'<mi>n</mi></msup>'
|
||
|
assert mathml(SingularityFunction(x, 4, -2), printer='presentation') == \
|
||
|
'<msup><mfenced close="⟩" open="⟨"><mrow><mi>x</mi>' \
|
||
|
'<mo>-</mo><mn>4</mn></mrow></mfenced><mn>-2</mn></msup>'
|
||
|
assert mathml(SingularityFunction(x, 4, -1), printer='presentation') == \
|
||
|
'<msup><mfenced close="⟩" open="⟨"><mrow><mi>x</mi>' \
|
||
|
'<mo>-</mo><mn>4</mn></mrow></mfenced><mn>-1</mn></msup>'
|
||
|
|
||
|
|
||
|
def test_mathml_matrix_functions():
|
||
|
from sympy.matrices import Adjoint, Inverse, Transpose
|
||
|
X = MatrixSymbol('X', 2, 2)
|
||
|
Y = MatrixSymbol('Y', 2, 2)
|
||
|
assert mathml(Adjoint(X), printer='presentation') == \
|
||
|
'<msup><mi>X</mi><mo>†</mo></msup>'
|
||
|
assert mathml(Adjoint(X + Y), printer='presentation') == \
|
||
|
'<msup><mfenced><mrow><mi>X</mi><mo>+</mo><mi>Y</mi></mrow></mfenced><mo>†</mo></msup>'
|
||
|
assert mathml(Adjoint(X) + Adjoint(Y), printer='presentation') == \
|
||
|
'<mrow><msup><mi>X</mi><mo>†</mo></msup><mo>+</mo><msup>' \
|
||
|
'<mi>Y</mi><mo>†</mo></msup></mrow>'
|
||
|
assert mathml(Adjoint(X*Y), printer='presentation') == \
|
||
|
'<msup><mfenced><mrow><mi>X</mi><mo>⁢</mo>' \
|
||
|
'<mi>Y</mi></mrow></mfenced><mo>†</mo></msup>'
|
||
|
assert mathml(Adjoint(Y)*Adjoint(X), printer='presentation') == \
|
||
|
'<mrow><msup><mi>Y</mi><mo>†</mo></msup><mo>⁢' \
|
||
|
'</mo><msup><mi>X</mi><mo>†</mo></msup></mrow>'
|
||
|
assert mathml(Adjoint(X**2), printer='presentation') == \
|
||
|
'<msup><mfenced><msup><mi>X</mi><mn>2</mn></msup></mfenced><mo>†</mo></msup>'
|
||
|
assert mathml(Adjoint(X)**2, printer='presentation') == \
|
||
|
'<msup><mfenced><msup><mi>X</mi><mo>†</mo></msup></mfenced><mn>2</mn></msup>'
|
||
|
assert mathml(Adjoint(Inverse(X)), printer='presentation') == \
|
||
|
'<msup><mfenced><msup><mi>X</mi><mn>-1</mn></msup></mfenced><mo>†</mo></msup>'
|
||
|
assert mathml(Inverse(Adjoint(X)), printer='presentation') == \
|
||
|
'<msup><mfenced><msup><mi>X</mi><mo>†</mo></msup></mfenced><mn>-1</mn></msup>'
|
||
|
assert mathml(Adjoint(Transpose(X)), printer='presentation') == \
|
||
|
'<msup><mfenced><msup><mi>X</mi><mo>T</mo></msup></mfenced><mo>†</mo></msup>'
|
||
|
assert mathml(Transpose(Adjoint(X)), printer='presentation') == \
|
||
|
'<msup><mfenced><msup><mi>X</mi><mo>†</mo></msup></mfenced><mo>T</mo></msup>'
|
||
|
assert mathml(Transpose(Adjoint(X) + Y), printer='presentation') == \
|
||
|
'<msup><mfenced><mrow><msup><mi>X</mi><mo>†</mo></msup>' \
|
||
|
'<mo>+</mo><mi>Y</mi></mrow></mfenced><mo>T</mo></msup>'
|
||
|
assert mathml(Transpose(X), printer='presentation') == \
|
||
|
'<msup><mi>X</mi><mo>T</mo></msup>'
|
||
|
assert mathml(Transpose(X + Y), printer='presentation') == \
|
||
|
'<msup><mfenced><mrow><mi>X</mi><mo>+</mo><mi>Y</mi></mrow></mfenced><mo>T</mo></msup>'
|
||
|
|
||
|
|
||
|
def test_mathml_special_matrices():
|
||
|
from sympy.matrices import Identity, ZeroMatrix, OneMatrix
|
||
|
assert mathml(Identity(4), printer='presentation') == '<mi>𝕀</mi>'
|
||
|
assert mathml(ZeroMatrix(2, 2), printer='presentation') == '<mn>𝟘</mn>'
|
||
|
assert mathml(OneMatrix(2, 2), printer='presentation') == '<mn>𝟙</mn>'
|
||
|
|
||
|
def test_mathml_piecewise():
|
||
|
from sympy.functions.elementary.piecewise import Piecewise
|
||
|
# Content MathML
|
||
|
assert mathml(Piecewise((x, x <= 1), (x**2, True))) == \
|
||
|
'<piecewise><piece><ci>x</ci><apply><leq/><ci>x</ci><cn>1</cn></apply></piece><otherwise><apply><power/><ci>x</ci><cn>2</cn></apply></otherwise></piecewise>'
|
||
|
|
||
|
raises(ValueError, lambda: mathml(Piecewise((x, x <= 1))))
|
||
|
|
||
|
|
||
|
def test_issue_17857():
|
||
|
assert mathml(Range(-oo, oo), printer='presentation') == \
|
||
|
'<mfenced close="}" open="{"><mi>…</mi><mn>-1</mn><mn>0</mn><mn>1</mn><mi>…</mi></mfenced>'
|
||
|
assert mathml(Range(oo, -oo, -1), printer='presentation') == \
|
||
|
'<mfenced close="}" open="{"><mi>…</mi><mn>1</mn><mn>0</mn><mn>-1</mn><mi>…</mi></mfenced>'
|
||
|
|
||
|
|
||
|
def test_float_roundtrip():
|
||
|
x = sympify(0.8975979010256552)
|
||
|
y = float(mp.doprint(x).strip('</cn>'))
|
||
|
assert x == y
|