Skip to content

Non-mutating (copy-on-write) Simplify for the function tree #251

Description

@ofloveandhate

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions