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) == 'x1' 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 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 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) == '' assert mathml(S.TribonacciConstant) == '' assert mathml(S.GoldenRatio) == 'φ' mml = mathml(S.EulerGamma) assert mml == '' mml = mathml(S.EmptySet) assert mml == '' mml = mathml(S.true) assert mml == '' mml = mathml(S.false) assert mml == '' mml = mathml(S.NaN) assert mml == '' 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')) == 'α' assert mp.doprint(Symbol('beta')) == 'β' assert mp.doprint(Symbol('gamma')) == 'γ' assert mp.doprint(Symbol('delta')) == 'δ' assert mp.doprint(Symbol('epsilon')) == 'ε' assert mp.doprint(Symbol('zeta')) == 'ζ' assert mp.doprint(Symbol('eta')) == 'η' assert mp.doprint(Symbol('theta')) == 'θ' assert mp.doprint(Symbol('iota')) == 'ι' assert mp.doprint(Symbol('kappa')) == 'κ' assert mp.doprint(Symbol('lambda')) == 'λ' assert mp.doprint(Symbol('mu')) == 'μ' assert mp.doprint(Symbol('nu')) == 'ν' assert mp.doprint(Symbol('xi')) == 'ξ' assert mp.doprint(Symbol('omicron')) == 'ο' assert mp.doprint(Symbol('pi')) == 'π' assert mp.doprint(Symbol('rho')) == 'ρ' assert mp.doprint(Symbol('varsigma')) == 'ς' assert mp.doprint(Symbol('sigma')) == 'σ' assert mp.doprint(Symbol('tau')) == 'τ' assert mp.doprint(Symbol('upsilon')) == 'υ' assert mp.doprint(Symbol('phi')) == 'φ' assert mp.doprint(Symbol('chi')) == 'χ' assert mp.doprint(Symbol('psi')) == 'ψ' assert mp.doprint(Symbol('omega')) == 'ω' assert mp.doprint(Symbol('Alpha')) == 'Α' assert mp.doprint(Symbol('Beta')) == 'Β' assert mp.doprint(Symbol('Gamma')) == 'Γ' assert mp.doprint(Symbol('Delta')) == 'Δ' assert mp.doprint(Symbol('Epsilon')) == 'Ε' assert mp.doprint(Symbol('Zeta')) == 'Ζ' assert mp.doprint(Symbol('Eta')) == 'Η' assert mp.doprint(Symbol('Theta')) == 'Θ' assert mp.doprint(Symbol('Iota')) == 'Ι' assert mp.doprint(Symbol('Kappa')) == 'Κ' assert mp.doprint(Symbol('Lambda')) == 'Λ' assert mp.doprint(Symbol('Mu')) == 'Μ' assert mp.doprint(Symbol('Nu')) == 'Ν' assert mp.doprint(Symbol('Xi')) == 'Ξ' assert mp.doprint(Symbol('Omicron')) == 'Ο' assert mp.doprint(Symbol('Pi')) == 'Π' assert mp.doprint(Symbol('Rho')) == 'Ρ' assert mp.doprint(Symbol('Sigma')) == 'Σ' assert mp.doprint(Symbol('Tau')) == 'Τ' assert mp.doprint(Symbol('Upsilon')) == 'Υ' assert mp.doprint(Symbol('Phi')) == 'Φ' assert mp.doprint(Symbol('Chi')) == 'Χ' assert mp.doprint(Symbol('Psi')) == 'Ψ' assert mp.doprint(Symbol('Omega')) == 'Ω' 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)) == 'xy' assert mathml(Or(x, y)) == 'xy' assert mathml(Xor(x, y)) == 'xy' assert mathml(Implies(x, y)) == 'xy' assert mathml(Not(x)) == 'x' def test_content_finite_sets(): assert mathml(FiniteSet(a)) == 'a' assert mathml(FiniteSet(a, b)) == 'ab' assert mathml(FiniteSet(FiniteSet(a, b), c)) == \ 'cab' 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) == \ 'ab' assert mathml(I1) == \ 'ab' \ '' assert mathml(C1) == \ 'ab' assert mathml(P1) == \ 'ab' \ '' assert mathml(Intersection(A, U2, evaluate=False)) == \ 'a' \ 'cd' assert mathml(Intersection(U1, U2, evaluate=False)) == \ 'a' \ 'bc' \ 'd' # XXX Does the parenthesis appear correctly for these examples in mathjax? assert mathml(Intersection(C1, C2, evaluate=False)) == \ 'a' \ 'bc' \ 'd' assert mathml(Intersection(P1, P2, evaluate=False)) == \ 'a' \ 'b' \ 'cd' assert mathml(Union(A, I2, evaluate=False)) == \ 'a' \ 'cd' assert mathml(Union(I1, I2, evaluate=False)) == \ 'a' \ 'bc' \ 'd' assert mathml(Union(C1, C2, evaluate=False)) == \ 'a' \ 'bc' \ 'd' assert mathml(Union(P1, P2, evaluate=False)) == \ 'a' \ 'b' \ 'cd' assert mathml(Complement(A, C2, evaluate=False)) == \ 'a' \ 'cd' assert mathml(Complement(U1, U2, evaluate=False)) == \ 'a' \ 'bc' \ 'd' assert mathml(Complement(I1, I2, evaluate=False)) == \ 'a' \ 'bc' \ 'd' assert mathml(Complement(P1, P2, evaluate=False)) == \ 'a' \ 'b' \ 'cd' assert mathml(ProductSet(A, P2)) == \ 'a' \ 'c' \ 'd' assert mathml(ProductSet(U1, U2)) == \ 'a' \ 'bc' \ 'd' assert mathml(ProductSet(I1, I2)) == \ 'a' \ 'b' \ 'cd' assert mathml(ProductSet(C1, C2)) == \ 'a' \ 'b' \ 'cd' def test_presentation_printmethod(): assert mpp.doprint(1 + x) == 'x+1' assert mpp.doprint(x**2) == 'x2' assert mpp.doprint(x**-1) == '1x' assert mpp.doprint(x**-2) == \ '1x2' assert mpp.doprint(2*x) == \ '2x' 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) == \ 'yz2xzxxyz' assert mathml(d, printer='presentation') == \ '6y2zxzxfxyz' 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))) == \ '01'\ 'xx' assert mpp.doprint(Integral(log(x), x)) == \ 'logx'\ 'x' assert mpp.doprint(Integral(x*y, x, y)) == \ 'x'\ 'yyx' z, w = symbols('z w') assert mpp.doprint(Integral(x*y*z, x, y, z)) == \ 'x'\ 'yz'\ 'zyx' assert mpp.doprint(Integral(x*y*z*w, x, y, z, w)) == \ ''\ 'w'\ 'xy'\ 'zw'\ 'zyx' assert mpp.doprint(Integral(x, x, y, (z, 0, 1))) == \ '01'\ 'xz'\ 'yx' assert mpp.doprint(Integral(x, (x, 0))) == \ '0x'\ 'x' 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') == '' assert mathml(S.TribonacciConstant, printer='presentation' ) == 'TribonacciConstant' assert mathml(S.EulerGamma, printer='presentation' ) == 'γ' assert mathml(S.GoldenRatio, printer='presentation' ) == 'Φ' assert mathml(zoo, printer='presentation') == \ '~' assert mathml(S.NaN, printer='presentation') == 'NaN' 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')) == 'α' assert mpp.doprint(Symbol('beta')) == 'β' assert mpp.doprint(Symbol('gamma')) == 'γ' assert mpp.doprint(Symbol('delta')) == 'δ' assert mpp.doprint(Symbol('epsilon')) == 'ε' assert mpp.doprint(Symbol('zeta')) == 'ζ' assert mpp.doprint(Symbol('eta')) == 'η' assert mpp.doprint(Symbol('theta')) == 'θ' assert mpp.doprint(Symbol('iota')) == 'ι' assert mpp.doprint(Symbol('kappa')) == 'κ' assert mpp.doprint(Symbol('lambda')) == 'λ' assert mpp.doprint(Symbol('mu')) == 'μ' assert mpp.doprint(Symbol('nu')) == 'ν' assert mpp.doprint(Symbol('xi')) == 'ξ' assert mpp.doprint(Symbol('omicron')) == 'ο' assert mpp.doprint(Symbol('pi')) == 'π' assert mpp.doprint(Symbol('rho')) == 'ρ' assert mpp.doprint(Symbol('varsigma')) == 'ς' assert mpp.doprint(Symbol('sigma')) == 'σ' assert mpp.doprint(Symbol('tau')) == 'τ' assert mpp.doprint(Symbol('upsilon')) == 'υ' assert mpp.doprint(Symbol('phi')) == 'φ' assert mpp.doprint(Symbol('chi')) == 'χ' assert mpp.doprint(Symbol('psi')) == 'ψ' assert mpp.doprint(Symbol('omega')) == 'ω' assert mpp.doprint(Symbol('Alpha')) == 'Α' assert mpp.doprint(Symbol('Beta')) == 'Β' assert mpp.doprint(Symbol('Gamma')) == 'Γ' assert mpp.doprint(Symbol('Delta')) == 'Δ' assert mpp.doprint(Symbol('Epsilon')) == 'Ε' assert mpp.doprint(Symbol('Zeta')) == 'Ζ' assert mpp.doprint(Symbol('Eta')) == 'Η' assert mpp.doprint(Symbol('Theta')) == 'Θ' assert mpp.doprint(Symbol('Iota')) == 'Ι' assert mpp.doprint(Symbol('Kappa')) == 'Κ' assert mpp.doprint(Symbol('Lambda')) == 'Λ' assert mpp.doprint(Symbol('Mu')) == 'Μ' assert mpp.doprint(Symbol('Nu')) == 'Ν' assert mpp.doprint(Symbol('Xi')) == 'Ξ' assert mpp.doprint(Symbol('Omicron')) == 'Ο' assert mpp.doprint(Symbol('Pi')) == 'Π' assert mpp.doprint(Symbol('Rho')) == 'Ρ' assert mpp.doprint(Symbol('Sigma')) == 'Σ' assert mpp.doprint(Symbol('Tau')) == 'Τ' assert mpp.doprint(Symbol('Upsilon')) == 'Υ' assert mpp.doprint(Symbol('Phi')) == 'Φ' assert mpp.doprint(Symbol('Chi')) == 'Χ' assert mpp.doprint(Symbol('Psi')) == 'Ψ' assert mpp.doprint(Symbol('Omega')) == 'Ω' 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)) == \ '0a' assert mpp.doprint(Interval(0, a, False, False)) == \ '0a' assert mpp.doprint(Interval(0, a, True, False)) == \ '0a' assert mpp.doprint(Interval(0, a, False, True)) == \ '0a' assert mpp.doprint(Interval(0, a, True, True)) == \ '0a' def test_print_tuples(): assert mpp.doprint(Tuple(0,)) == \ '0' assert mpp.doprint(Tuple(0, a)) == \ '0a' assert mpp.doprint(Tuple(0, a, a)) == \ '0aa' assert mpp.doprint(Tuple(0, 1, 2, 3, 4)) == \ '01234' assert mpp.doprint(Tuple(0, 1, Tuple(2, 3, 4))) == \ '0123'\ '4' def test_print_re_im(): assert mpp.doprint(re(x)) == \ 'Rx' assert mpp.doprint(im(x)) == \ 'Ix' assert mpp.doprint(re(x + 1)) == \ 'Rx'\ '+1' assert mpp.doprint(im(x + 1)) == \ 'Ix' def test_print_Abs(): assert mpp.doprint(Abs(x)) == \ 'x' assert mpp.doprint(Abs(x + 1)) == \ 'x+1' def test_print_Determinant(): assert mpp.doprint(Determinant(Matrix([[1, 2], [3, 4]]))) == \ '1234' 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( "x1") doc2 = xml.dom.minidom.parseString( "x+1") 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) == '' assert mpp.doprint(Integers) == '' assert mpp.doprint(Naturals) == '' assert mpp.doprint(Naturals0) == \ '0' assert mpp.doprint(Reals) == '' def test_print_expression_with_minus(): assert mpp.doprint(-x) == '-x' assert mpp.doprint(-x/y) == \ '-xy' assert mpp.doprint(-Rational(1, 2)) == \ '-12' def test_print_AssocOp(): from sympy.core.operations import AssocOp class TestAssocOp(AssocOp): identity = 0 expr = TestAssocOp(1, 2) assert mpp.doprint(expr) == \ 'testassocop12' def test_print_basic(): expr = Basic(S(1), S(2)) assert mpp.doprint(expr) == \ 'basic12' assert mp.doprint(expr) == '12' def test_mat_delim_print(): expr = Matrix([[1, 2], [3, 4]]) assert mathml(expr, printer='presentation', mat_delim='[') == \ '1'\ '234'\ '' assert mathml(expr, printer='presentation', mat_delim='(') == \ '12'\ '34' assert mathml(expr, printer='presentation', mat_delim='') == \ '12'\ '34' def test_ln_notation_print(): expr = log(x) assert mathml(expr, printer='presentation') == \ 'logx' assert mathml(expr, printer='presentation', ln_notation=False) == \ 'logx' assert mathml(expr, printer='presentation', ln_notation=True) == \ 'lnx' def test_mul_symbol_print(): expr = x * y assert mathml(expr, printer='presentation') == \ 'xy' assert mathml(expr, printer='presentation', mul_symbol=None) == \ 'xy' assert mathml(expr, printer='presentation', mul_symbol='dot') == \ 'x·y' assert mathml(expr, printer='presentation', mul_symbol='ldot') == \ 'xy' assert mathml(expr, printer='presentation', mul_symbol='times') == \ 'x×y' def test_print_lerchphi(): assert mpp.doprint(lerchphi(1, 2, 3)) == \ 'Φ123' def test_print_polylog(): assert mp.doprint(polylog(x, y)) == \ 'xy' assert mpp.doprint(polylog(x, y)) == \ 'Lixy' def test_print_set_frozenset(): f = frozenset({1, 5, 3}) assert mpp.doprint(f) == \ '135' s = set({1, 2, 3}) assert mpp.doprint(s) == \ '123' def test_print_FiniteSet(): f1 = FiniteSet(x, 1, 3) assert mpp.doprint(f1) == \ '13x' def test_print_LambertW(): assert mpp.doprint(LambertW(x)) == 'Wx' assert mpp.doprint(LambertW(x, y)) == 'Wxy' def test_print_EmptySet(): assert mpp.doprint(S.EmptySet) == '' def test_print_UniversalSet(): assert mpp.doprint(S.UniversalSet) == '𝕌' def test_print_spaces(): assert mpp.doprint(HilbertSpace()) == '' assert mpp.doprint(ComplexSpace(2)) == '𝒞2' assert mpp.doprint(FockSpace()) == '' def test_print_constants(): assert mpp.doprint(hbar) == '' assert mpp.doprint(S.TribonacciConstant) == 'TribonacciConstant' assert mpp.doprint(S.GoldenRatio) == 'Φ' assert mpp.doprint(S.EulerGamma) == 'γ' def test_print_Contains(): assert mpp.doprint(Contains(x, S.Naturals)) == \ 'x' def test_print_Dagger(): assert mpp.doprint(Dagger(x)) == 'x' 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)) == \ '13x'\ '2'\ '4y' assert prntr(Intersection(f1, f2, evaluate=False)) == \ '13x'\ '2'\ '4y' assert prntr(Complement(f1, f2, evaluate=False)) == \ '13x'\ '2'\ '4y' assert prntr(SymmetricDifference(f1, f2, evaluate=False)) == \ '13x'\ '2'\ '4y' 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)) == \ 'a' \ '' \ 'c' \ 'd' assert prntr(Intersection(A, C1, evaluate=False)) == \ 'a' \ '' \ 'c' \ 'd' assert prntr(Complement(A, D1, evaluate=False)) == \ 'a' \ '' \ 'c' \ 'd' assert prntr(SymmetricDifference(A, P1, evaluate=False)) == \ 'a' \ '' \ 'c×' \ 'd' assert prntr(ProductSet(A, U1)) == \ 'a' \ '×' \ 'c' \ 'd' def test_print_logic(): assert mpp.doprint(And(x, y)) == \ 'xy' assert mpp.doprint(Or(x, y)) == \ 'xy' assert mpp.doprint(Xor(x, y)) == \ 'xy' assert mpp.doprint(Implies(x, y)) == \ 'xy' assert mpp.doprint(Equivalent(x, y)) == \ 'xy' assert mpp.doprint(And(Eq(x, y), x > 4)) == \ 'x=y'\ 'x>4' assert mpp.doprint(And(Eq(x, 3), y < 3, x > y + 1)) == \ 'x=3'\ 'x>y+1'\ 'y<3' assert mpp.doprint(Or(Eq(x, y), x > 4)) == \ 'x=y'\ 'x>4' assert mpp.doprint(And(Eq(x, 3), Or(y < 3, x > y + 1))) == \ 'x=3'\ 'x>y+'\ '1y<'\ '3' assert mpp.doprint(Not(x)) == '¬x' assert mpp.doprint(Not(And(x, y))) == \ '¬x'\ 'y' def test_root_notation_print(): assert mathml(x**(S.One/3), printer='presentation') == \ 'x3' assert mathml(x**(S.One/3), printer='presentation', root_notation=False) ==\ 'x13' assert mathml(x**(S.One/3), printer='content') == \ '3x' assert mathml(x**(S.One/3), printer='content', root_notation=False) == \ 'x13' assert mathml(x**(Rational(-1, 3)), printer='presentation') == \ '1x3' assert mathml(x**(Rational(-1, 3)), printer='presentation', root_notation=False) \ == '1x13' def test_fold_frac_powers_print(): expr = x ** Rational(5, 2) assert mathml(expr, printer='presentation') == \ 'x52' assert mathml(expr, printer='presentation', fold_frac_powers=True) == \ 'x52' assert mathml(expr, printer='presentation', fold_frac_powers=False) == \ 'x52' def test_fold_short_frac_print(): expr = Rational(2, 5) assert mathml(expr, printer='presentation') == \ '25' assert mathml(expr, printer='presentation', fold_short_frac=True) == \ '25' assert mathml(expr, printer='presentation', fold_short_frac=False) == \ '25' def test_print_factorials(): assert mpp.doprint(factorial(x)) == 'x!' assert mpp.doprint(factorial(x + 1)) == \ 'x+1!' assert mpp.doprint(factorial2(x)) == 'x!!' assert mpp.doprint(factorial2(x + 1)) == \ 'x+1!!' assert mpp.doprint(binomial(x, y)) == \ 'xy' assert mpp.doprint(binomial(4, x + y)) == \ '4x'\ '+y' def test_print_floor(): expr = floor(x) assert mathml(expr, printer='presentation') == \ 'x' def test_print_ceiling(): expr = ceiling(x) assert mathml(expr, printer='presentation') == \ 'x' def test_print_Lambda(): expr = Lambda(x, x+1) assert mathml(expr, printer='presentation') == \ 'xx+'\ '1' expr = Lambda((x, y), x + y) assert mathml(expr, printer='presentation') == \ 'xy'\ 'x+y' def test_print_conjugate(): assert mpp.doprint(conjugate(x)) == \ 'x' assert mpp.doprint(conjugate(x + 1)) == \ 'x+1' def test_print_AccumBounds(): a = Symbol('a', real=True) assert mpp.doprint(AccumBounds(0, 1)) == '01' assert mpp.doprint(AccumBounds(0, a)) == '0a' assert mpp.doprint(AccumBounds(a + 1, a + 2)) == 'a+1a+2' def test_print_Float(): assert mpp.doprint(Float(1e100)) == '1.0·10100' assert mpp.doprint(Float(1e-100)) == '1.0·10-100' assert mpp.doprint(Float(-1e100)) == '-1.0·10100' assert mpp.doprint(Float(1.0*oo)) == '' assert mpp.doprint(Float(-1.0*oo)) == '-' def test_print_different_functions(): assert mpp.doprint(gamma(x)) == 'Γx' assert mpp.doprint(lowergamma(x, y)) == 'γxy' assert mpp.doprint(uppergamma(x, y)) == 'Γxy' assert mpp.doprint(zeta(x)) == 'ζx' assert mpp.doprint(zeta(x, y)) == 'ζxy' assert mpp.doprint(dirichlet_eta(x)) == 'ηx' assert mpp.doprint(elliptic_k(x)) == 'Κx' assert mpp.doprint(totient(x)) == 'ϕx' assert mpp.doprint(reduced_totient(x)) == 'λx' assert mpp.doprint(primenu(x)) == 'νx' assert mpp.doprint(primeomega(x)) == 'Ωx' assert mpp.doprint(fresnels(x)) == 'Sx' assert mpp.doprint(fresnelc(x)) == 'Cx' assert mpp.doprint(Heaviside(x)) == 'Θx12' def test_mathml_builtins(): assert mpp.doprint(None) == 'None' assert mpp.doprint(true) == 'True' assert mpp.doprint(false) == 'False' def test_mathml_Range(): assert mpp.doprint(Range(1, 51)) == \ '1250' assert mpp.doprint(Range(1, 4)) == \ '123' assert mpp.doprint(Range(0, 3, 1)) == \ '012' assert mpp.doprint(Range(0, 30, 1)) == \ '0129' assert mpp.doprint(Range(30, 1, -1)) == \ '3029'\ '2' assert mpp.doprint(Range(0, oo, 2)) == \ '02' assert mpp.doprint(Range(oo, -2, -2)) == \ '20' assert mpp.doprint(Range(-2, -oo, -1)) == \ '-2-3' def test_print_exp(): assert mpp.doprint(exp(x)) == \ 'x' assert mpp.doprint(exp(1) + exp(2)) == \ '+2' def test_print_MinMax(): assert mpp.doprint(Min(x, y)) == \ 'minxy' assert mpp.doprint(Min(x, 2, x**3)) == \ 'min2xx'\ '3' assert mpp.doprint(Max(x, y)) == \ 'maxxy' assert mpp.doprint(Max(x, 2, x**3)) == \ 'max2xx'\ '3' def test_mathml_presentation_numbers(): n = Symbol('n') assert mathml(catalan(n), printer='presentation') == \ 'Cn' assert mathml(bernoulli(n), printer='presentation') == \ 'Bn' assert mathml(bell(n), printer='presentation') == \ 'Bn' assert mathml(euler(n), printer='presentation') == \ 'En' assert mathml(fibonacci(n), printer='presentation') == \ 'Fn' assert mathml(lucas(n), printer='presentation') == \ 'Ln' assert mathml(tribonacci(n), printer='presentation') == \ 'Tn' assert mathml(bernoulli(n, x), printer='presentation') == \ 'Bnx' assert mathml(bell(n, x), printer='presentation') == \ 'Bnx' assert mathml(euler(n, x), printer='presentation') == \ 'Enx' assert mathml(fibonacci(n, x), printer='presentation') == \ 'Fnx' assert mathml(tribonacci(n, x), printer='presentation') == \ 'Tnx' def test_mathml_presentation_mathieu(): assert mathml(mathieuc(x, y, z), printer='presentation') == \ 'Cxyz' assert mathml(mathieus(x, y, z), printer='presentation') == \ 'Sxyz' assert mathml(mathieucprime(x, y, z), printer='presentation') == \ 'C′xyz' assert mathml(mathieusprime(x, y, z), printer='presentation') == \ 'S′xyz' def test_mathml_presentation_stieltjes(): assert mathml(stieltjes(n), printer='presentation') == \ 'γn' assert mathml(stieltjes(n, x), printer='presentation') == \ 'γnx' def test_print_matrix_symbol(): A = MatrixSymbol('A', 1, 2) assert mpp.doprint(A) == 'A' assert mp.doprint(A) == 'A' assert mathml(A, printer='presentation', mat_symbol_style="bold") == \ 'A' # No effect in content printer assert mathml(A, mat_symbol_style="bold") == 'A' 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") == \ '' \ 'X' \ '' \ 'Y2' \ '' assert mathml(HadamardProduct(X, Y)*Y, printer="presentation") == \ '' \ '' \ 'XY' \ '' \ 'Y' \ '' assert mathml(HadamardProduct(X, Y, Y), printer="presentation") == \ '' \ 'X' \ 'Y' \ 'Y' \ '' assert mathml( Transpose(HadamardProduct(X, Y)), printer="presentation") == \ '' \ '' \ 'XY' \ '' \ 'T' \ '' def test_print_random_symbol(): R = RandomSymbol(Symbol('R')) assert mpp.doprint(R) == 'R' assert mp.doprint(R) == 'R' def test_print_IndexedBase(): assert mathml(IndexedBase(a)[b], printer='presentation') == \ 'ab' assert mathml(IndexedBase(a)[b, c, d], printer='presentation') == \ 'abcd' assert mathml(IndexedBase(a)[b]*IndexedBase(c)[d]*IndexedBase(e), printer='presentation') == \ 'ab⁢'\ 'cde' def test_print_Indexed(): assert mathml(IndexedBase(a), printer='presentation') == 'a' assert mathml(IndexedBase(a/b), printer='presentation') == \ 'ab' assert mathml(IndexedBase((a, b)), printer='presentation') == \ 'ab' def test_print_MatrixElement(): i, j = symbols('i j') A = MatrixSymbol('A', i, j) assert mathml(A[0,0],printer = 'presentation') == \ 'A00' assert mathml(A[i,j], printer = 'presentation') == \ 'Aij' assert mathml(A[i*j,0], printer = 'presentation') == \ 'Aij0' def test_print_Vector(): ACS = CoordSys3D('A') assert mathml(Cross(ACS.i, ACS.j*ACS.x*3 + ACS.k), printer='presentation') == \ 'i^'\ 'A×'\ '3'\ 'xA'\ ''\ 'j^'\ 'A+'\ 'k^'\ 'A' assert mathml(Cross(ACS.i, ACS.j), printer='presentation') == \ 'i^'\ 'A×'\ 'j^'\ 'A' assert mathml(x*Cross(ACS.i, ACS.j), printer='presentation') == \ 'x'\ 'i^'\ 'A×'\ 'j^'\ 'A' assert mathml(Cross(x*ACS.i, ACS.j), printer='presentation') == \ '-j'\ '^A'\ '×x'\ 'i'\ '^A'\ '' assert mathml(Curl(3*ACS.x*ACS.j), printer='presentation') == \ '×'\ '3'\ 'xA'\ ''\ 'j^'\ 'A' assert mathml(Curl(3*x*ACS.x*ACS.j), printer='presentation') == \ '×'\ '3x'\ 'A'\ 'x'\ 'j^'\ 'A' assert mathml(x*Curl(3*ACS.x*ACS.j), printer='presentation') == \ 'x'\ '×3'\ 'x'\ 'A'\ 'j'\ '^A'\ '' assert mathml(Curl(3*x*ACS.x*ACS.j + ACS.i), printer='presentation') == \ '×'\ 'i^'\ 'A+'\ '3x'\ 'A'\ 'x'\ 'j^'\ 'A' assert mathml(Divergence(3*ACS.x*ACS.j), printer='presentation') == \ '·'\ '3x'\ 'A'\ 'j'\ '^A' assert mathml(x*Divergence(3*ACS.x*ACS.j), printer='presentation') == \ 'x'\ '·3'\ 'x'\ 'A'\ 'j'\ '^A'\ '' assert mathml(Divergence(3*x*ACS.x*ACS.j + ACS.i), printer='presentation') == \ '·'\ 'i^'\ 'A+'\ '3'\ 'xA'\ 'x'\ 'j'\ '^A' assert mathml(Dot(ACS.i, ACS.j*ACS.x*3+ACS.k), printer='presentation') == \ 'i^'\ 'A·'\ '3'\ 'xA'\ ''\ 'j^'\ 'A+'\ 'k^'\ 'A' assert mathml(Dot(ACS.i, ACS.j), printer='presentation') == \ 'i^'\ 'A·'\ 'j^'\ 'A' assert mathml(Dot(x*ACS.i, ACS.j), printer='presentation') == \ 'j^'\ 'A·'\ 'x'\ 'i^'\ 'A' assert mathml(x*Dot(ACS.i, ACS.j), printer='presentation') == \ 'x'\ 'i^'\ 'A·'\ 'j^'\ 'A' assert mathml(Gradient(ACS.x), printer='presentation') == \ 'x'\ 'A' assert mathml(Gradient(ACS.x + 3*ACS.y), printer='presentation') == \ ''\ 'xA+3'\ 'y'\ 'A' assert mathml(x*Gradient(ACS.x), printer='presentation') == \ 'x'\ 'xA'\ '' assert mathml(Gradient(x*ACS.x), printer='presentation') == \ ''\ 'xA'\ 'x' assert mathml(Cross(ACS.x, ACS.z) + Cross(ACS.z, ACS.x), printer='presentation') == \ '0^' assert mathml(Cross(ACS.z, ACS.x), printer='presentation') == \ '-x'\ 'A×'\ 'zA' assert mathml(Laplacian(ACS.x), printer='presentation') == \ 'x'\ 'A' assert mathml(Laplacian(ACS.x + 3*ACS.y), printer='presentation') == \ ''\ 'xA+3'\ 'y'\ 'A' assert mathml(x*Laplacian(ACS.x), printer='presentation') == \ 'x'\ 'xA'\ '' assert mathml(Laplacian(x*ACS.x), printer='presentation') == \ ''\ 'xA'\ 'x' def test_print_elliptic_f(): assert mathml(elliptic_f(x, y), printer = 'presentation') == \ '𝖥xy' assert mathml(elliptic_f(x/y, y), printer = 'presentation') == \ '𝖥xyy' def test_print_elliptic_e(): assert mathml(elliptic_e(x), printer = 'presentation') == \ '𝖤x' assert mathml(elliptic_e(x, y), printer = 'presentation') == \ '𝖤xy' def test_print_elliptic_pi(): assert mathml(elliptic_pi(x, y), printer = 'presentation') == \ '𝛱xy' assert mathml(elliptic_pi(x, y, z), printer = 'presentation') == \ '𝛱xyz' def test_print_Ei(): assert mathml(Ei(x), printer = 'presentation') == \ 'Eix' assert mathml(Ei(x**y), printer = 'presentation') == \ 'Eixy' def test_print_expint(): assert mathml(expint(x, y), printer = 'presentation') == \ 'Exy' assert mathml(expint(IndexedBase(x)[1], IndexedBase(x)[2]), printer = 'presentation') == \ 'Ex1x2' def test_print_jacobi(): assert mathml(jacobi(n, a, b, x), printer = 'presentation') == \ 'Pnabx' def test_print_gegenbauer(): assert mathml(gegenbauer(n, a, x), printer = 'presentation') == \ 'Cnax' def test_print_chebyshevt(): assert mathml(chebyshevt(n, x), printer = 'presentation') == \ 'Tnx' def test_print_chebyshevu(): assert mathml(chebyshevu(n, x), printer = 'presentation') == \ 'Unx' def test_print_legendre(): assert mathml(legendre(n, x), printer = 'presentation') == \ 'Pnx' def test_print_assoc_legendre(): assert mathml(assoc_legendre(n, a, x), printer = 'presentation') == \ 'Pnax' def test_print_laguerre(): assert mathml(laguerre(n, x), printer = 'presentation') == \ 'Lnx' def test_print_assoc_laguerre(): assert mathml(assoc_laguerre(n, a, x), printer = 'presentation') == \ 'Lnax' def test_print_hermite(): assert mathml(hermite(n, x), printer = 'presentation') == \ 'Hnx' def test_mathml_SingularityFunction(): assert mathml(SingularityFunction(x, 4, 5), printer='presentation') == \ 'x' \ '-45' assert mathml(SingularityFunction(x, -3, 4), printer='presentation') == \ 'x' \ '+34' assert mathml(SingularityFunction(x, 0, 4), printer='presentation') == \ 'x' \ '4' assert mathml(SingularityFunction(x, a, n), printer='presentation') == \ '' \ '-a+x' \ 'n' assert mathml(SingularityFunction(x, 4, -2), printer='presentation') == \ 'x' \ '-4-2' assert mathml(SingularityFunction(x, 4, -1), printer='presentation') == \ 'x' \ '-4-1' 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') == \ 'X' assert mathml(Adjoint(X + Y), printer='presentation') == \ 'X+Y' assert mathml(Adjoint(X) + Adjoint(Y), printer='presentation') == \ 'X+' \ 'Y' assert mathml(Adjoint(X*Y), printer='presentation') == \ 'X' \ 'Y' assert mathml(Adjoint(Y)*Adjoint(X), printer='presentation') == \ 'Y⁢' \ 'X' assert mathml(Adjoint(X**2), printer='presentation') == \ 'X2' assert mathml(Adjoint(X)**2, printer='presentation') == \ 'X2' assert mathml(Adjoint(Inverse(X)), printer='presentation') == \ 'X-1' assert mathml(Inverse(Adjoint(X)), printer='presentation') == \ 'X-1' assert mathml(Adjoint(Transpose(X)), printer='presentation') == \ 'XT' assert mathml(Transpose(Adjoint(X)), printer='presentation') == \ 'XT' assert mathml(Transpose(Adjoint(X) + Y), printer='presentation') == \ 'X' \ '+YT' assert mathml(Transpose(X), printer='presentation') == \ 'XT' assert mathml(Transpose(X + Y), printer='presentation') == \ 'X+YT' def test_mathml_special_matrices(): from sympy.matrices import Identity, ZeroMatrix, OneMatrix assert mathml(Identity(4), printer='presentation') == '𝕀' assert mathml(ZeroMatrix(2, 2), printer='presentation') == '𝟘' assert mathml(OneMatrix(2, 2), printer='presentation') == '𝟙' def test_mathml_piecewise(): from sympy.functions.elementary.piecewise import Piecewise # Content MathML assert mathml(Piecewise((x, x <= 1), (x**2, True))) == \ 'xx1x2' raises(ValueError, lambda: mathml(Piecewise((x, x <= 1)))) def test_issue_17857(): assert mathml(Range(-oo, oo), printer='presentation') == \ '-101' assert mathml(Range(oo, -oo, -1), printer='presentation') == \ '10-1' def test_float_roundtrip(): x = sympify(0.8975979010256552) y = float(mp.doprint(x).strip('')) assert x == y