Skip to content

Introduce a shared exact symbolic expression core - #1127

Merged
isPANN merged 9 commits into
1075-growth-domainfrom
codex/symbolic-expr-core
Aug 9, 2026
Merged

Introduce a shared exact symbolic expression core#1127
isPANN merged 9 commits into
1075-growth-domainfrom
codex/symbolic-expr-core

Conversation

@isPANN

@isPANN isPANN commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #1083. This is the first reviewable implementation layer of #1126.

Outcome

This PR replaces the duplicated symbolic-expression implementations with one canonical exact DAG and carries those exact expressions through reduction-path composition. Asymptotic Growth is derived only when a terminal comparison or Big-O presentation needs it.

Canonical expression core

  • adds problemreductions-expr as the single parser and expression implementation used by the runtime library and proc macros
  • stores immutable nodes behind Arc, preserving shared subexpressions through substitution and node-table serde
  • uses arbitrary-precision BigRational constants and validated owned symbols
  • exposes only the semantic nodes Const, Var, n-ary Add/Mul, Pow, Exp, Log, and Factorial
  • lowers subtraction, division, unary negation, and square root immediately into canonical operations
  • normalizes operand order, coefficients, repeated powers, and neutral elements
  • memoizes DAG traversals and batch Growth analysis by node identity
  • deletes the duplicate proc-macro parser and legacy raw-overhead path

Exact path semantics

  • composes every reduction overhead as exact symbolic expressions across the whole path
  • does not greedily prune paths from intermediate Big-O projections
  • converts exact terminal fields to Growth in one shared analysis context
  • reports missing substitutions by output field and identifies the failing path edge
  • distinguishes a valid one-node identity path from an invalid empty path
  • uses one canonical identity-field syntax instead of repeated string field names

Explicit failure boundaries

  • statically invalid parsed expressions such as 0 / 0, 0^-1, and log(0) return parse errors
  • non-finite approximate results return ApproximationError; they never become successful infinities or O(1)
  • unsupported asymptotic forms return serialized, deduplicated GrowthFailure reasons
  • exact antichains are never truncated or silently widened
  • missing variables and invalid factorial arguments remain explicit errors

There is no compatibility AST, parser fallback, antichain cap, or silent approximation fallback.

External oracle fixture

A committed fixture generated by pinned SymPy 1.14.0 checks:

  • 50 exact cases: rational values, canonical free-variable sets, and polynomial classification
  • 12 numerical cases: finite f64 results and the explicit overflow boundary
  • 14 asymptotic-order cases from exact SymPy limits
  • 8 factorial-domain cases

Regenerate it with:

uv run --project scripts python scripts/generate_symbolic_expr_fixture.py

Stack boundary

This PR supplies the canonical expression core and integrates it with the existing overhead/path APIs. The named SizeMap/SizeBound types, complete registry field accounting, and separate exact-bound search APIs remain later stacked changes in #1126.

Risk and rollback

This intentionally replaces the old expression representation rather than preserving compatibility. The main risk is semantic drift in normalization or path composition; the SymPy corpus, property tests, deep shared-DAG regressions, and full repository test suite cover those boundaries. Before later stack layers depend on this commit, rollback is a normal revert of this PR; no persisted schema migration is required.

Verification

  • make check
  • cargo test --workspace --quiet
  • focused parser/domain/error tests
  • 5,000-case dominance property test (0.47 s locally)
  • independent fresh-context implementation review: approved with no remaining findings

All passed.

Coverage

  • full instrumented run: 6,090 tests passed
  • project line coverage: 95.81% (120,289 / 125,543)
  • PR patch coverage: 98.39% (2,261 / 2,298), up from 96.26%
  • changed-file coverage: expression DAG 99.37%, macro codegen 97.81%, pred-sym error boundary 100%

@isPANN
isPANN merged commit f7a8fbe into 1075-growth-domain Aug 9, 2026
@isPANN
isPANN deleted the codex/symbolic-expr-core branch August 9, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant