You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a1b0149
Browse filesBrowse the repository at this point in the historyBrowse files
Make det, transpose, trace and an entry nodes that apply to a matrix argument
det(A) of a symbol was refused at parsing, transpose(x) too, trace(A) was the product
trace * A, and A[i, j] did not parse. Each of the four is now a node over what it is
applied to, carried out once that is a matrix: by Substitute, Simplify, Evaled and a
compiled delegate taking T[,]. Of a matrix written out each is still computed as it is
parsed, as det and transpose were, so nothing #2180 answered moves but transpose(x).
- Determinantf, Transposef, Tracef and MatrixEntryf, with printing that parses back,
LaTeX (\det, ^{\mathrm{T}}, \operatorname{tr}, a subscript), SymPy, substitution,
sorting, serialization, and MathS.Matrices.Determinant, Transpose, Trace and Entry.
- An entry counts its row and column from 1, as a_ij does: [[1, 2], [3, 4]][2, 1] is 3.
The brackets follow an atom directly, which did not parse before.
- A non-square matrix has no determinant and no trace, and an index out of range or not
whole names no entry: the node is left as it is, never a number. Written out, each is
refused at parsing, as det of a non-square matrix was. A number, a statement or a set
is no matrix and is refused.
- det(transpose(A)) is det(A), trace(transpose(A)) is trace(A), transpose(transpose(A))
is A and transpose(A)[k, l] is A[l, k].
- The transpose, the trace and an entry are differentiated through the matrix; the
determinant keeps its derivative node, Jacobi's formula needing the adjugate.
- Compiled: the transpose, Bareiss' fraction-free determinant with the largest pivot
where the elements have a size (exact over long and int), the trace, and the entry
with its indices checked whole and in range when called. Shapes written into the
expression are checked at Compile.
- A product with a transpose in it is a product of matrices, and Simplify read it as
commutative: transpose(A) * A - A * transpose(A) simplified to 0, and transpose(A) * B
printed as B * transpose(A). Such a product is set aside as a name of its own while
the rest is simplified, and put back with each factor simplified in place; the
canonical sort and the print order leave it as written.
- A name beside a written matrix may stand for a matrix, and simplification reads it as
a number: det(A [[2, 0], [0, 3]]) was 6 A^2 at parsing, and a compiled delegate
computed that. Such an argument is not carried out, at parsing, in evaluation or by
Simplify, until the name is a matrix; det([[x, 1], [2, x]]), whose names are entries,
is x^2 - 2 as before.
Measured: the new MatrixOperationNodesTest compares every value with one computed from
the entries, at real, negative and non-real matrices, 2x2 and 3x3, and every compiled
value with evaluation, including a matrix argument beside a written matrix, which the
base commit's SimplifiedAroundMatrixArguments leaves to these nodes. The 2.6.0 values in BREAKING-CHANGES.md are measured on the
2.6.0 package.
Closes#2427.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: Sources/AngouriMath/Core/Antlr/AngouriMath.g
+23-11Lines changed: 23 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -80,14 +80,24 @@ options
80
80
// So we put UPPER_CASE lexer rules after lower_case parser rules.
81
81
82
82
// atom is defined later
83
+
/* An atom, then any entries taken of it, then a factorial mark.
84
+
85
+
An entry of a matrix is `A[i, j]`, its row and its column counted from 1 as a_ij is. The
86
+
brackets follow what they index directly, and a bracket after an atom was not a parse before,
87
+
so nothing that parsed reads differently. They are read here rather than in a rule of their
88
+
own, since a rule is a context allocated for every atom of every parse, and that cost ParseEasy
89
+
7% of its allocation. https://github.com/asc-community/AngouriMath/issues/2147
90
+
91
+
The double factorial, n (n - 2) (n - 4) ..., is not (n!)!: that keeps its parentheses. Three
92
+
marks are the triple factorial in the literature, which the library does not have, so they are
93
+
refused rather than read as (n!!)!. https://github.com/asc-community/AngouriMath/issues/2182 */
83
94
factorial_expression returns[Entity value]
84
-
: p = atom '!' { $value = MathS.Factorial($p.value); }
85
-
/* The double factorial, n (n - 2) (n - 4) ..., which is not (n!)!: that keeps its parentheses.
86
-
Three marks are the triple factorial in the literature, which the library does not have, so
87
-
they are refused rather than read as (n!!)!. https://github.com/asc-community/AngouriMath/issues/2182 */
88
-
| p = atom '!!' { $value = MathS.DoubleFactorial($p.value); }
89
-
| p = atom '!!!' { throw new UnrecognizedFunctionParseException("n!!! is the triple factorial, which AngouriMath does not have; write (n!!)! for the factorial of a double factorial"); }
| '!!!' { throw new UnrecognizedFunctionParseException("n!!! is the triple factorial, which AngouriMath does not have; write (n!!)! for the factorial of a double factorial"); }
0 commit comments