AngouriMath

Navigation

← Back to list of members

Gathered​(System.​String,​AngouriMath.​Core.​Transformations.​Matching.​MatchPattern[])

 Method (no overloads)

Summary

Matches an associative-commutative chain of — a sum or a
product — by finding parts among its operands in any positions and binding whatever is left over to restName.

Remarks

This is the n-ary half of
#248, and it is
what lets a rule about two terms fire on an expression with five. A binary pattern
cannot: sin(x)^2 + cos(x)^2 inside a + sin(x)^2 + b + cos(x)^2 is not two
children of any one node. The library's present answer is to sort the operands with
CanonicalOrder before running the rules so that the pair lands adjacent — which
works, and is a workaround for the matcher rather than a property of the mathematics.
When nothing is left over, restName is bound to the operator's
identity
— 0 for a sum, 1 for a product. That is not a convenience:
the empty sum is zero and the empty product is one, so one rule covers
both sin(x)^2 + cos(x)^2 and the same pair buried in a longer sum, and the
right-hand side never has to ask which case it is in.
Operands come from LinearChildren, so subtraction and division are already
normalised: a - b offers a and (-1) * b, and a / b offers
a and b ^ (-1). A rule therefore does not need a second arm for the
subtractive spelling, which is one of the ways the switch sets multiplied.
Cost. Assigning k parts to n operands is n!/(n-k)! attempts, so this is bounded
by MaxAssignments measured work rather than by a reasoned size limit, as
#921 settled for
the resultant. Past the bound it stops yielding, so the rule does not apply rather than taking unbounded time — declining is a legitimate answer where a wrong one
or a hang is not.

























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