AngouriMath

Navigation

CostModel


← Back to list of classes

Description

Summary

What "simpler" means, as a named value rather than as an anonymous function.

Remarks

ComplexityCriteria has always accepted any
Func`2, so the cost of an expression was already the caller's
to choose. What it could not do is be named: two callers wanting "the smallest tree"
each wrote the same lambda, neither could say which one they used, and nothing could list
what the alternatives are. #746 v2.0 asks for a cost model that is data for exactly that reason, and names the examples —
smallest tree, fewest radicals — that All now holds.
A model counts one of two things, and which one decides what it may read.SmallestTree and Default count how the expression is
written
: y ^ (1 * (-1)) * x really is a bigger tree than x / y, so
reading the node as written is not an approximation, it is the question. The others count a
mathematical feature — is there a division here, is there a radical — which is a
property of the value and not of the spelling, so they ask what an exponent
Evaled to rather than what it was typed as.
The distinction is worth stating because getting it wrong is silent and backwards:
FewestDivisions used to test the exponent's node, so
y ^ (1 * (-1)) * x — a division written where the test could not see it — scored
cheaper than x / y, under the one criterion whose whole job is to remove
divisions. That is
#950. A caller
writing their own model wants to decide which of the two kinds it is
, because nothing
here can decide it for them: an expression handed to a cost model has not necessarily been
evaluated, and on an e-graph — where every writing of a value is a member of one class at
once — it certainly has not.
Every model here counts nodes a little, even the ones that are about something else. A criterion that counts only its own feature ties constantly, and a tie is settled by
whichever candidate the search happened to generate first — which is an accident rather
than a preference. The node term is small enough not to overturn the feature it is added to
and large enough to decide between candidates the feature cannot separate.

Example

using var _ = MathS.Settings.ComplexityCriteria.Set(CostModel.FewestDivisions.Cost);
Console.WriteLine("a / b + b / c".ToEntity().Simplify());   // (a * c + b ^ 2) / (b * c)

Parameter "Name"

A short name, so a report can say which model produced an answer.

Parameter "Description"

What this model prefers, in a sentence.

Parameter "Cost"

The cost of an expression; lower is simpler. Pass this to
ComplexityCriteria.

Members

























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