AngouriMath

Navigation

← Back to list of members

Canonicalization

 Property

Summary

A canonical form for the commutative structure: two expressions differing only in
how their sums, products, conjunctions, disjunctions and set operations are
arranged or nested come out as the identical tree.

Remarks

Normalise, order, normalise, and the first of those is what makes it work.
The order's key depends on a node's class and the normalisation changes classes:
in 1/2 - x the constant reaches an unprepared sort as 1 * 2 ^ (-1),
a product, and is ordered against -x as one, but folds to the number
1/2 immediately afterwards — so the next pass orders it the other way and
the two alternate. Sorting a tree that has already settled sorts what the tree is
actually going to be.
Measured over 834 generated expressions and 2738 ordered pairs by
Sources/Tests/Harnesses/CanonCheck: idempotent, and independent of the order
the operands were written in
, where ordering without the leading normalisation
fails 18 of the first and InnerSimplification alone fails 2024 of the
second. Its canoncheck-baseline.tsv lists every one.
What it is not. It is not a canonical form for the language — no such thing
exists, since zero-equivalence is undecidable here — and it is not a
simplification, since it makes an expression comparable rather than shorter.
Equal trees mean the expressions are equal; different trees mean nothing at all.
Docs/Contributing/CanonicalForm.md states the boundary and what is still owed.
Nesting goes with order. The sort works over commutative chains rather than
over one node, so it flattens as it sorts: (x + y) + a and x + (y + a) both reach a + x + y, and reach it as the same tree. That is worth saying
because InnerSimplification alone leaves those two as different trees
which print identically — associativity being normalised on the way out
rather than in the expression — so a comparison of printed forms cannot tell the
two situations apart.
Nothing in the library runs this: it is offered, not applied. Putting it inside
InnerSimplification would move every commutative operand order in
every printed answer at once, which is a decision for a release rather than for a
transformation. #746 tier 1.

























Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 4378 pages online