AngouriMath

Navigation

← Back to list of members

Canonicalize

 Method (no overloads)

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

This is not Simplify(System.Int32) and is not trying to be. It makes an
expression comparable, not shorter, and it may well make it longer. What it
buys is that a.Canonicalize() == b.Canonicalize() is a real test of whether
the two are the same expression, where comparing simplified forms is not.
Equal trees mean the expressions are equal; different trees mean nothing at
all.
There is no canonical form for the whole language — deciding whether an
expression is zero is undecidable once pi, the exponential, the trigonometric
functions and abs are in play — so this canonicalises the part that can be:
the arrangement of commutative operators. For rational functions over Q, where
a complete canonical form does exist, use
CanonicalizeAsRationalFunction.
Docs/Contributing/CanonicalForm.md states the boundary and how far off the
library is from it.

Example

using AngouriMath;
using static System.Console;
            
WriteLine("x + y".ToEntity().Canonicalize() == "y + x".ToEntity().Canonicalize());
WriteLine("(x + y) + a".ToEntity().Canonicalize() == "x + (y + a)".ToEntity().Canonicalize());

Prints
True
True

























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