AngouriMath

Navigation

RewriteRecording


← Back to list of classes

Description

Summary

Collects the rewrites that fire while it is open, so that an answer can be asked how
it was reached rather than only what it is.

Remarks

Off unless asked for, and off is free: with no recording open, applying a rule set
costs one ambient read more than it did before — per rule set, not per node — and
allocates nothing. That is the condition
#746 puts on
every layer above the tree, and it is why this is a scope rather than a setting that
something might leave on.
Per flow, like Settings: the recording belongs to the call rather
than to the thread running it. It survives an await, and work
started under it — including on another thread — reports to it. A recording opened
inside a task is invisible to that task's siblings and to whatever started it.
Order is not guaranteed once work is parallel. Steps from one flow keep the
order they fired in, but two flows recording into the same open recording interleave
however they happen to run. The single-threaded case — which is what
Simplify(System.Int32) is — is unaffected.
Three views, and they answer different questions.Steps is every
rewrite that fired, on the subexpression it matched, across every candidate
Simplify(System.Int32) generated including the ones that lost.
Derivation is the same list with the normalisation and the repeats taken
out — 270 rewrites down to 5 on x^(-1)/(y/z) — and it is still a *set* of
rewrites, so reading it in order does not walk from the input to the answer.
PathFrom(AngouriMath.Entity,AngouriMath.Entity) is the one that does: whole expressions, in
order, from the input to the value that was returned, with the losing candidates left
out. Ask the first what fired, the second which identities were used, the third how it
got there.

Example

using AngouriMath;
using AngouriMath.Core.Transformations;
            
using var recording = RewriteRecording.Start();
var simplified = ((Entity)"a / (b / c)").Simplify();
foreach (var step in recording.Steps)
    Console.WriteLine(step);

Members

























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