AngouriMath

Navigation

MatchedRules


← Back to list of classes

Description

Summary

Rule sets written as data, a few at a time and deliberately so: the value of this file is
that a set expressed here can be checked against the switch that already expresses
it, so the migration is proven one set at a time rather than asserted wholesale.

Remarks

MatchedRulesAgreeWithTheSwitchTest is that check. It runs both forms over
generated expressions and requires them to agree on every one, which is what makes
replacing the switch a mechanical step rather than a leap.
PythagoreanIdentity is the exception, and is here for the opposite reason:
there is nothing for it to agree with. It uses n-ary matching to say something the
switch has no way of saying, so it is checked against the mathematics rather than
against the code it would replace.
Both sides of every rule here are patterns, so thirteen of the fourteen can be read
backwards — Reversed, and
Docs/Contributing/ReversibleRules.md for what that requires and what it does not
claim. The fourteenth is the Pythagorean identity, which cannot, for a reason that is about
the mathematics rather than about the encoding.
What it costs to use one of these has been measured end to end, and the first answer
was wrong about the reason.
The first exchange cost about 5% of
Simplify's time
for one set, which was recorded here as the price of the idea
and as the argument against doing it wholesale. It was not the idea: NodePattern recomputed IsDeterministic on every attempt, walking the
whole pattern tree behind a delegate before any matching began, so the case that does the
least work — a rule that does not fire — paid the most for it. Settled once instead, a
miss goes 29.99 ns → 13.48 ns and a whole pass 1182.9 ns → 659.9 ns at identical
allocation.
Re-measured against Simplify itself, three arms in one process with the third a
second copy of the first, the exchange is inside the noise floor on time — six
samples each, medians +0.12% apart where the same binary spreads 1.90% — and
+0.14% on allocation, which is the one figure that reproduces: two copies of the
same assembly agree to 5 bytes in 45.6 MB. So a set is exchanged when its rules want to
be data, and the cost is no longer the reason not to.

Members

























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