Skip to content

Commit 80e6915

Browse files
committed
Times should have always at least 2 elements
Rework arithmetic format
1 parent 2aa00f0 commit 80e6915

File tree

16 files changed

+357
-140
lines changed

16 files changed

+357
-140
lines changed

mathics/builtin/arithfns/basic.py

Lines changed: 252 additions & 100 deletions
Large diffs are not rendered by default.

mathics/builtin/arithmetic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ class DirectedInfinity(SympyFunction):
524524

525525
formats = {
526526
"DirectedInfinity[1]": "HoldForm[Infinity]",
527-
"DirectedInfinity[-1]": "HoldForm[-Infinity]",
527+
"DirectedInfinity[-1]": "HoldForm[Minus[Infinity]]",
528+
"DirectedInfinity[-I]": "HoldForm[Minus[Infinity] I]",
528529
"DirectedInfinity[]": "HoldForm[ComplexInfinity]",
529530
"DirectedInfinity[DirectedInfinity[z_]]": "DirectedInfinity[z]",
530531
"DirectedInfinity[z_?NumericQ]": "HoldForm[z Infinity]",

mathics/builtin/forms/output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,9 +1060,9 @@ class MatrixForm(TableForm):
10601060
10611061
## Issue #182
10621062
#> {{2*a, 0},{0,0}}//MatrixForm
1063-
= 2 a 0
1063+
= 2 a 0
10641064
.
1065-
. 0 0
1065+
. 0 0
10661066
"""
10671067

10681068
in_outputforms = True

mathics/builtin/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ class Superscript(Builtin):
500500

501501
summary_text = "format an expression with a superscript"
502502
rules = {
503-
"MakeBoxes[Superscript[x_, y_], f:StandardForm|TraditionalForm]": (
503+
"MakeBoxes[Superscript[x_, y_], f:OutputForm|StandardForm|TraditionalForm]": (
504504
"SuperscriptBox[MakeBoxes[x, f], MakeBoxes[y, f]]"
505505
)
506506
}

mathics/builtin/numbers/calculus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ class Series(Builtin):
17141714
>> Clear[s];
17151715
We can also expand over multiple variables
17161716
>> Series[Exp[x-y], {x, 0, 2}, {y, 0, 2}]
1717-
= (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
1717+
= 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
17181718
17191719
"""
17201720

@@ -2097,7 +2097,7 @@ def pre_makeboxes(self, x, x0, data, nmin, nmax, den, form, evaluation: Evaluati
20972097
Expression(SymbolPlus, *expansion),
20982098
Expression(SymbolPower, Expression(SymbolO, variable), powers[-1]),
20992099
)
2100-
return Expression(SymbolInfix, expansion, String("+"), Integer(300), SymbolLeft)
2100+
return Expression(SymbolInfix, expansion, String("+"), Integer(299), SymbolLeft)
21012101

21022102
def eval_makeboxes(
21032103
self,

mathics/builtin/quantum_mechanics/angular.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class PauliMatrix(SympyFunction):
107107
= True
108108
109109
>> MatrixExp[I \[Phi]/2 PauliMatrix[3]]
110-
= {{E ^ (I / 2 ϕ), 0}, {0, E ^ ((-I / 2) ϕ)}}
110+
= {{E ^ (I / 2 ϕ), 0}, {0, E ^ (-I / 2 ϕ)}}
111111
112112
>> % /. \[Phi] -> 2 Pi
113113
= {{-1, 0}, {0, -1}}

mathics/builtin/statistics/orderstats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class Sort(Builtin):
263263
Sort uses 'OrderedQ' to determine ordering by default.
264264
You can sort patterns according to their precedence using 'PatternsOrderedQ':
265265
>> Sort[{items___, item_, OptionsPattern[], item_symbol, item_?test}, PatternsOrderedQ]
266-
= {item_symbol, item_ ? test, item_, items___, OptionsPattern[]}
266+
= {item_symbol, (item_) ? test, item_, items___, OptionsPattern[]}
267267
268268
When sorting patterns, values of atoms do not matter:
269269
>> Sort[{a, b/;t}, PatternsOrderedQ]

mathics/core/convert/sympy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,10 @@ def old_from_sympy(expr) -> BaseElement:
463463
else:
464464
factors.append(Expression(SymbolPower, slot, from_sympy(exp)))
465465
if factors:
466-
result.append(Expression(SymbolTimes, *factors))
466+
if len(factors) == 1:
467+
result.append(factors[0])
468+
else:
469+
result.append(Expression(SymbolTimes, *factors))
467470
else:
468471
result.append(Integer1)
469472
return Expression(SymbolFunction, Expression(SymbolPlus, *result))

mathics/core/systemsymbols.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
SymbolPolygon = Symbol("System`Polygon")
191191
SymbolPossibleZeroQ = Symbol("System`PossibleZeroQ")
192192
SymbolPrecision = Symbol("System`Precision")
193+
SymbolPrecedenceForm = Symbol("System`PrecedenceForm")
193194
SymbolQuantity = Symbol("System`Quantity")
194195
SymbolQuiet = Symbol("System`Quiet")
195196
SymbolQuotient = Symbol("System`Quotient")

mathics/doc/documentation/1-Manual.mdoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,15 +1186,15 @@ A dice object shall be displayed as a rectangle with the given number of points
11861186
#> Definition[Dice]
11871187
= Attributes[Dice] = {Orderless}
11881188
.
1189-
. 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]]
1189+
. 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]]
11901190
.
1191-
. 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]]
1191+
. 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]]
11921192
.
1193-
. 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]]
1193+
. 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]]
11941194
.
1195-
. 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]]
1195+
. 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]]
11961196
.
1197-
. 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]]
1197+
. 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]]
11981198

11991199
The empty series of dice shall be displayed as an empty dice:
12001200
>> Format[Dice[]] := Graphics[{EdgeForm[Black], White, Rectangle[]}, ImageSize -> Tiny]

0 commit comments

Comments
 (0)