Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arithmetic format #892

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
352 changes: 252 additions & 100 deletions mathics/builtin/arithfns/basic.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ class DirectedInfinity(SympyFunction):

formats = {
"DirectedInfinity[1]": "HoldForm[Infinity]",
"DirectedInfinity[-1]": "HoldForm[-Infinity]",
"DirectedInfinity[-1]": "HoldForm[Minus[Infinity]]",
"DirectedInfinity[-I]": "HoldForm[Minus[Infinity] I]",
"DirectedInfinity[]": "HoldForm[ComplexInfinity]",
"DirectedInfinity[DirectedInfinity[z_]]": "DirectedInfinity[z]",
"DirectedInfinity[z_?NumericQ]": "HoldForm[z Infinity]",
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/forms/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,9 @@ class MatrixForm(TableForm):

## Issue #182
#> {{2*a, 0},{0,0}}//MatrixForm
= 2 a 0
= 2 a 0
.
. 0 0
. 0 0
"""

in_outputforms = True
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class Superscript(Builtin):

summary_text = "format an expression with a superscript"
rules = {
"MakeBoxes[Superscript[x_, y_], f:StandardForm|TraditionalForm]": (
"MakeBoxes[Superscript[x_, y_], f:OutputForm|StandardForm|TraditionalForm]": (
"SuperscriptBox[MakeBoxes[x, f], MakeBoxes[y, f]]"
)
}
6 changes: 4 additions & 2 deletions mathics/builtin/numbers/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,8 +1712,10 @@ class Series(Builtin):
= 17
>> Clear[s];
We can also expand over multiple variables
## TODO: In WMA, the first term is also sorounded by parenthesis. This is
## to fix in another round, after complete the refactor of Infix.
>> Series[Exp[x-y], {x, 0, 2}, {y, 0, 2}]
= (1 - y + 1 / 2 y ^ 2 + O[y] ^ 3) + (1 - y + 1 / 2 y ^ 2 + O[y] ^ 3) x + (1 / 2 + (-1 / 2) y + 1 / 4 y ^ 2 + O[y] ^ 3) x ^ 2 + O[x] ^ 3
= 1 - y + 1 / 2 y ^ 2 + O[y] ^ 3 + (1 - y + 1 / 2 y ^ 2 + O[y] ^ 3) x + (1 / 2 - 1 / 2 y + 1 / 4 y ^ 2 + O[y] ^ 3) x ^ 2 + O[x] ^ 3

"""

Expand Down Expand Up @@ -2096,7 +2098,7 @@ def pre_makeboxes(self, x, x0, data, nmin, nmax, den, form, evaluation: Evaluati
Expression(SymbolPlus, *expansion),
Expression(SymbolPower, Expression(SymbolO, variable), powers[-1]),
)
return Expression(SymbolInfix, expansion, String("+"), Integer(300), SymbolLeft)
return Expression(SymbolInfix, expansion, String("+"), Integer(299), SymbolLeft)

def eval_makeboxes(
self,
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/quantum_mechanics/angular.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class PauliMatrix(SympyFunction):
= True

>> MatrixExp[I \[Phi]/2 PauliMatrix[3]]
= {{E ^ (I / 2 ϕ), 0}, {0, E ^ ((-I / 2) ϕ)}}
= {{E ^ (I / 2 ϕ), 0}, {0, E ^ (-I / 2 ϕ)}}

>> % /. \[Phi] -> 2 Pi
= {{-1, 0}, {0, -1}}
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/statistics/orderstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class Sort(Builtin):
Sort uses 'OrderedQ' to determine ordering by default.
You can sort patterns according to their precedence using 'PatternsOrderedQ':
>> Sort[{items___, item_, OptionsPattern[], item_symbol, item_?test}, PatternsOrderedQ]
= {item_symbol, item_ ? test, item_, items___, OptionsPattern[]}
= {item_symbol, (item_) ? test, item_, items___, OptionsPattern[]}

When sorting patterns, values of atoms do not matter:
>> Sort[{a, b/;t}, PatternsOrderedQ]
Expand Down
5 changes: 4 additions & 1 deletion mathics/core/convert/sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ def old_from_sympy(expr) -> BaseElement:
else:
factors.append(Expression(SymbolPower, slot, from_sympy(exp)))
if factors:
result.append(Expression(SymbolTimes, *factors))
if len(factors) == 1:
result.append(factors[0])
else:
result.append(Expression(SymbolTimes, *factors))
else:
result.append(Integer1)
return Expression(SymbolFunction, Expression(SymbolPlus, *result))
Expand Down
1 change: 1 addition & 0 deletions mathics/core/systemsymbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
SymbolPolygon = Symbol("System`Polygon")
SymbolPossibleZeroQ = Symbol("System`PossibleZeroQ")
SymbolPrecision = Symbol("System`Precision")
SymbolPrecedenceForm = Symbol("System`PrecedenceForm")
SymbolQuantity = Symbol("System`Quantity")
SymbolQuiet = Symbol("System`Quiet")
SymbolQuotient = Symbol("System`Quotient")
Expand Down
10 changes: 5 additions & 5 deletions mathics/doc/documentation/1-Manual.mdoc
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,15 @@ A dice object shall be displayed as a rectangle with the given number of points
#> Definition[Dice]
= Attributes[Dice] = {Orderless}
.
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], MathMLForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{Plus[1, Times[-1, p]], 0.5}, r]}]}, ImageSize -> Tiny]]
. Format[Dice[(n_Integer) ? (1 <= #1 <= 6&)], MathMLForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - 1*p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - 1*p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - 1*p, 0.5}, r]}]}, ImageSize -> Tiny]]
.
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], OutputForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{Plus[1, Times[-1, p]], 0.5}, r]}]}, ImageSize -> Tiny]]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not perfect, but at least I got something less weird than what we have in master.

. Format[Dice[(n_Integer) ? (1 <= #1 <= 6&)], OutputForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - 1*p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - 1*p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - 1*p, 0.5}, r]}]}, ImageSize -> Tiny]]
.
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], StandardForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{Plus[1, Times[-1, p]], 0.5}, r]}]}, ImageSize -> Tiny]]
. Format[Dice[(n_Integer) ? (1 <= #1 <= 6&)], StandardForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - 1*p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - 1*p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - 1*p, 0.5}, r]}]}, ImageSize -> Tiny]]
.
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], TeXForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{Plus[1, Times[-1, p]], 0.5}, r]}]}, ImageSize -> Tiny]]
. Format[Dice[(n_Integer) ? (1 <= #1 <= 6&)], TeXForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - 1*p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - 1*p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - 1*p, 0.5}, r]}]}, ImageSize -> Tiny]]
.
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], TraditionalForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, Plus[1, Times[-1, p]]}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{Plus[1, Times[-1, p]], p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{Plus[1, Times[-1, p]], 0.5}, r]}]}, ImageSize -> Tiny]]
. Format[Dice[(n_Integer) ? (1 <= #1 <= 6&)], TraditionalForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - 1*p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - 1*p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - 1*p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - 1*p, 0.5}, r]}]}, ImageSize -> Tiny]]

The empty series of dice shall be displayed as an empty dice:
>> Format[Dice[]] := Graphics[{EdgeForm[Black], White, Rectangle[]}, ImageSize -> Tiny]
Expand Down
24 changes: 15 additions & 9 deletions mathics/eval/makeboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def eval_fullform_makeboxes(
return Expression(SymbolMakeBoxes, expr, form).evaluate(evaluation)


def eval_makeboxes(
self, expr, evaluation: Evaluation, form=SymbolStandardForm
) -> Expression:
def eval_makeboxes(expr, evaluation: Evaluation, form=SymbolStandardForm) -> Expression:
"""
This function takes the definitions provided by the evaluation
object, and produces a boxed fullform for expr.
Expand Down Expand Up @@ -334,13 +332,21 @@ def parenthesize(
elif element.has_form("PrecedenceForm", 2):
element_prec = element.elements[1].value
# If "element" is a negative number, we need to parenthesize the number. (Fixes #332)
elif isinstance(element, (Integer, Real)) and element.value < 0:
# Force parenthesis by adjusting the surrounding context's precedence value,
# We can't change the precedence for the number since it, doesn't
# have a precedence value.
element_prec = precedence
elif isinstance(element, (Integer, Real)):
if element.value < 0:
# Force parenthesis by adjusting the surrounding context's precedence value,
# We can't change the precedence for the number since it, doesn't
# have a precedence value.
element_prec = 480
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure this is not the right way to fix this. There is always a precedence for all atoms.

else:
element_prec = 999
when_equal = False
elif isinstance(element, Symbol):
precedence = precedence
element_prec = 999
when_equal = False
else:
element_prec = builtins_precedence.get(element.get_head())
element_prec = builtins_precedence.get(element.get_head(), 670)
if precedence is not None and element_prec is not None:
if precedence > element_prec or (precedence == element_prec and when_equal):
return Expression(
Expand Down
26 changes: 24 additions & 2 deletions mathics/format/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,31 @@ def fractionbox(self, **options) -> str:
_options = self.box_options.copy()
_options.update(options)
options = _options

# This removes the auxiliar parentheses in
# numerator and denominator if they are not
# needed. See comment in `mathics.builtin.arithfns.basic.Divide`

def remove_trivial_parentheses(x):
if not isinstance(x, RowBox):
return x
elements = x.elements
if len(elements) != 3:
return x
left, center, right = elements
if not (isinstance(left, String) and isinstance(right, String)):
return x
open_p, close_p = elements[0].value, elements[-1].value
if open_p == "(" and close_p == ")":
return center
return x

num = remove_trivial_parentheses(self.num)
den = remove_trivial_parentheses(self.den)

return "\\frac{%s}{%s}" % (
lookup_conversion_method(self.num, "latex")(self.num, **options),
lookup_conversion_method(self.den, "latex")(self.den, **options),
lookup_conversion_method(num, "latex")(num, **options),
lookup_conversion_method(den, "latex")(den, **options),
)


Expand Down
25 changes: 23 additions & 2 deletions mathics/format/mathml.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,30 @@ def fractionbox(self, **options) -> str:
_options = self.box_options.copy()
_options.update(options)
options = _options

# This removes the auxiliar parentheses in
# numerator and denominator if they are not
# needed. See comment in `mathics.builtin.arithfns.basic.Divide`
def remove_trivial_parentheses(x):
if not isinstance(x, RowBox):
return x
elements = x.elements
if len(elements) != 3:
return x
left, center, right = elements
if not (isinstance(left, String) and isinstance(right, String)):
return x
open_p, close_p = elements[0].value, elements[-1].value
if open_p == "(" and close_p == ")":
return center
return x

num = remove_trivial_parentheses(self.num)
den = remove_trivial_parentheses(self.den)

return "<mfrac>%s %s</mfrac>" % (
lookup_conversion_method(self.num, "mathml")(self.num, **options),
lookup_conversion_method(self.den, "mathml")(self.den, **options),
lookup_conversion_method(num, "mathml")(num, **options),
lookup_conversion_method(den, "mathml")(den, **options),
)


Expand Down
4 changes: 2 additions & 2 deletions mathics/format/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def fractionbox(self, **options) -> str:
num_text = boxes_to_text(self.num, **options)
den_text = boxes_to_text(self.den, **options)
if isinstance(self.num, RowBox):
num_text = f"({num_text})"
num_text = f"{num_text}"
if isinstance(self.den, RowBox):
den_text = f"({den_text})"
den_text = f"{den_text}"

return " / ".join([num_text, den_text])

Expand Down
12 changes: 7 additions & 5 deletions test/builtin/arithmetic/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,25 @@ def test_multiply(str_expr, str_expected, msg):
("DirectedInfinity[Sqrt[3]]", "Infinity", None),
(
"a b DirectedInfinity[1. + 2. I]",
"a b ((0.447214 + 0.894427 I) Infinity)",
"a b (0.447214 + 0.894427 I) Infinity",
"symbols times floating point complex directed infinity",
),
("a b DirectedInfinity[I]", "a b (I Infinity)", ""),
("a b DirectedInfinity[I]", "a b I Infinity", ""),
(
"a b (-1 + 2 I) Infinity",
"a b ((-1 / 5 + 2 I / 5) Sqrt[5] Infinity)",
"a b (-1 / 5 + 2 I / 5) Sqrt[5] Infinity",
"symbols times algebraic exact factor times infinity",
),
(
"a b (-1 + 2 Pi I) Infinity",
"a b (Infinity (-1 + 2 I Pi) / Sqrt[1 + 4 Pi ^ 2])",
"a b (-0.157177 + 0.98757 I) Infinity",
# TODO: Improve handling irrational directions
# "a b Infinity (-1 + 2 I Pi) / Sqrt[1 + 4 Pi ^ 2]",
"complex irrational exact",
),
(
"a b DirectedInfinity[(1 + 2 I)/ Sqrt[5]]",
"a b ((1 / 5 + 2 I / 5) Sqrt[5] Infinity)",
"a b (1 / 5 + 2 I / 5) Sqrt[5] Infinity",
"symbols times algebraic complex directed infinity",
),
("a b DirectedInfinity[q]", "a b (q Infinity)", ""),
Expand Down
21 changes: 15 additions & 6 deletions test/format/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,13 @@
"System`StandardForm": "<msup><mi>a</mi> <mfrac><mi>b</mi> <mi>c</mi></mfrac></msup>",
"System`TraditionalForm": "<msup><mi>a</mi> <mfrac><mi>b</mi> <mi>c</mi></mfrac></msup>",
"System`InputForm": "<mrow><mi>a</mi> <mo>^</mo> <mrow><mo>(</mo> <mrow><mi>b</mi> <mtext>&nbsp;/&nbsp;</mtext> <mi>c</mi></mrow> <mo>)</mo></mrow></mrow>",
"System`OutputForm": "<mrow><mi>a</mi> <mtext>&nbsp;^&nbsp;</mtext> <mrow><mo>(</mo> <mrow><mi>b</mi> <mtext>&nbsp;/&nbsp;</mtext> <mi>c</mi></mrow> <mo>)</mo></mrow></mrow>",
"System`OutputForm": r"<mrow><mi>a</mi> <mtext>&nbsp;^&nbsp;</mtext> <mrow><mo>(</mo> <mfrac><mi>b</mi> <mi>c</mi></mfrac> <mo>)</mo></mrow></mrow>",
},
"latex": {
"System`StandardForm": "a^{\\frac{b}{c}}",
"System`TraditionalForm": "a^{\\frac{b}{c}}",
"System`InputForm": "a{}^{\\wedge}\\left(b\\text{ / }c\\right)",
"System`OutputForm": "a\\text{ ${}^{\\wedge}$ }\\left(b\\text{ / }c\\right)",
"System`OutputForm": "a\\text{ ${}^{\\wedge}$ }\\left(\\frac{b}{c}\\right)",
},
},
"1/(1+1/(1+1/a))": {
Expand All @@ -559,15 +559,20 @@
"Fragile!",
),
"System`OutputForm": (
"<mrow><mn>1</mn> <mtext>&nbsp;/&nbsp;</mtext> <mrow><mo>(</mo> <mrow><mn>1</mn> <mtext>&nbsp;+&nbsp;</mtext> <mrow><mn>1</mn> <mtext>&nbsp;/&nbsp;</mtext> <mrow><mo>(</mo> <mrow><mn>1</mn> <mtext>&nbsp;+&nbsp;</mtext> <mrow><mn>1</mn> <mtext>&nbsp;/&nbsp;</mtext> <mi>a</mi></mrow></mrow> <mo>)</mo></mrow></mrow></mrow> <mo>)</mo></mrow></mrow>",
(
r"<mfrac><mn>1</mn> <mrow><mn>1</mn> <mtext>&nbsp;+&nbsp;</mtext> "
r"<mfrac><mn>1</mn> <mrow><mn>1</mn> <mtext>&nbsp;+&nbsp;</mtext> "
r"<mfrac><mn>1</mn> <mi>a</mi></mfrac></mrow></mfrac></mrow>"
r"</mfrac>"
),
"Fragile!",
),
},
"latex": {
"System`StandardForm": "\\frac{1}{1+\\frac{1}{1+\\frac{1}{a}}}",
"System`TraditionalForm": "\\frac{1}{1+\\frac{1}{1+\\frac{1}{a}}}",
"System`InputForm": "1\\text{ / }\\left(1\\text{ + }1\\text{ / }\\left(1\\text{ + }1\\text{ / }a\\right)\\right)",
"System`OutputForm": "1\\text{ / }\\left(1\\text{ + }1\\text{ / }\\left(1\\text{ + }1\\text{ / }a\\right)\\right)",
"System`OutputForm": r"\frac{1}{1\text{ + }\frac{1}{1\text{ + }\frac{1}{a}}}",
},
},
"Sqrt[1/(1+1/(1+1/a))]": {
Expand All @@ -592,15 +597,19 @@
"Fragile!",
),
"System`OutputForm": (
"<mrow><mi>Sqrt</mi> <mo>[</mo> <mrow><mn>1</mn> <mtext>&nbsp;/&nbsp;</mtext> <mrow><mo>(</mo> <mrow><mn>1</mn> <mtext>&nbsp;+&nbsp;</mtext> <mrow><mn>1</mn> <mtext>&nbsp;/&nbsp;</mtext> <mrow><mo>(</mo> <mrow><mn>1</mn> <mtext>&nbsp;+&nbsp;</mtext> <mrow><mn>1</mn> <mtext>&nbsp;/&nbsp;</mtext> <mi>a</mi></mrow></mrow> <mo>)</mo></mrow></mrow></mrow> <mo>)</mo></mrow></mrow> <mo>]</mo></mrow>",
(
r"<mrow><mi>Sqrt</mi> <mo>[</mo> <mfrac><mn>1</mn> <mrow><mn>1</mn> <mtext>&nbsp;+&nbsp;</mtext> "
r"<mfrac><mn>1</mn> <mrow><mn>1</mn> <mtext>&nbsp;+&nbsp;</mtext> <mfrac><mn>1</mn> <mi>a</mi>"
r"</mfrac></mrow></mfrac></mrow></mfrac> <mo>]</mo></mrow>"
),
"Fragile!",
),
},
"latex": {
"System`StandardForm": "\\sqrt{\\frac{1}{1+\\frac{1}{1+\\frac{1}{a}}}}",
"System`TraditionalForm": "\\sqrt{\\frac{1}{1+\\frac{1}{1+\\frac{1}{a}}}}",
"System`InputForm": "\\text{Sqrt}\\left[1\\text{ / }\\left(1\\text{ + }1\\text{ / }\\left(1\\text{ + }1\\text{ / }a\\right)\\right)\\right]",
"System`OutputForm": "\\text{Sqrt}\\left[1\\text{ / }\\left(1\\text{ + }1\\text{ / }\\left(1\\text{ + }1\\text{ / }a\\right)\\right)\\right]",
"System`OutputForm": r"\text{Sqrt}\left[\frac{1}{1\text{ + }\frac{1}{1\text{ + }\frac{1}{a}}}\right]",
},
},
# Grids, arrays and matrices
Expand Down