Summary
Provide a non-mutating (copy-on-write) Simplify for the function tree: one that returns a new, simplified tree and leaves its input untouched.
Motivation
Today's Simplify mutates the tree in place. Because nodes are shared (shared_ptr subtrees), an in-place simplify on a shared subtree lets one System observe another's tree change. That hazard is exactly why DefaultAutoSimplify() had to be set to false (see ADR-0011) — auto-simplification could not be left on safely.
A simplify that produces a new tree (sharing untouched subtrees, copying only what changes) would let auto-simplification be re-enabled and keep shared subtrees immutable.
Scope
- A non-mutating
Simplify returning a fresh tree; original unchanged.
- Expose the
EliminateZeros / EliminateOnes building blocks (currently internal).
- This is the read-path counterpart to the simplified-by-construction differentiation already in place: the
SimplifiedMult/SimplifiedSum factories from ADR-0011 flatten, fold exact constants, and never emit Floats — a non-mutating Simplify should reuse the same rules.
References
- ADR-0011 (simplified-by-construction differentiation; the
DefaultAutoSimplify()=false watch note explains the in-place mutation hazard this issue removes).
Summary
Provide a non-mutating (copy-on-write)
Simplifyfor the function tree: one that returns a new, simplified tree and leaves its input untouched.Motivation
Today's
Simplifymutates the tree in place. Because nodes are shared (shared_ptrsubtrees), an in-place simplify on a shared subtree lets oneSystemobserve another's tree change. That hazard is exactly whyDefaultAutoSimplify()had to be set tofalse(see ADR-0011) — auto-simplification could not be left on safely.A simplify that produces a new tree (sharing untouched subtrees, copying only what changes) would let auto-simplification be re-enabled and keep shared subtrees immutable.
Scope
Simplifyreturning a fresh tree; original unchanged.EliminateZeros/EliminateOnesbuilding blocks (currently internal).SimplifiedMult/SimplifiedSumfactories from ADR-0011 flatten, fold exact constants, and never emitFloats — a non-mutatingSimplifyshould reuse the same rules.References
DefaultAutoSimplify()=falsewatch note explains the in-place mutation hazard this issue removes).