AngouriMath

Navigation

← Back to list of members

ByPriority​(AngouriMath.​Core.​Transformations.​Matching.​MatchedRule[])

 Method (no overloads)

Summary

declared ordered so that no rule is tried before a rule its pattern
subsumes — the more specific one first — keeping declaration order everywhere else.

Remarks

What this replaces is the position somebody typed a rule at. A set is
first-match-wins, so where two rules both fire at a node and disagree, whichever comes
first decides the answer. Where one pattern subsumes the other that decision is not a
preference: the general rule would swallow the special one and the special one would
never fire at all, so the specific rule has to be tried first. That was maintained by
hand and written in a comment on one set;
Subsumes(AngouriMath.Core.Transformations.Matching.MatchPattern) computes it, and this applies it.
It changes no answer today, and that is a measurement rather than an intention. Over the 5,480 within-set rule pairs in MatchedRules, subsumption has an
opinion about 28 of them — spread across eight sets, Boolean and
InequalityEquality carrying half — and in every one the specific rule is
already declared first. None is mutual. So this orders what was already ordered; what
it adds is that inserting a general rule above a specific one no longer silently
reverses an answer. RulePriorityTest holds the two orders equal, so the file
stays readable as well as correct.
A stable topological sort, taking the earliest-declared rule that has nothing left
which must precede it. Subsumption is conservative, so most pairs constrain nothing and
fall through to declaration order. It cannot cycle — a cycle would need each of two
rules to be strictly more general than the other — but a cycle is emitted in
declaration order rather than trusted not to happen, because a sort that silently drops
a rule would be a set quietly missing a rewrite.

























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