You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduction metadata currently uses one lossy Expr representation for exact structural size calculation, symbolic composition, and asymptotic growth. Constants become f64, missing variables evaluate as zero, and concrete results are rounded and cast to usize. It also lacks one exact canonical representation shared by contract-specific consumers. The audit in #1125 demonstrates that these semantics cannot support trustworthy Pareto ranking.
Complexity theory also separates exact construction facts from certified resource bounds:
kernelization bounds output size by a function of the parameter, and Turing kernelization may produce several instances (Witteveen–Bottesch–Torenvliet);
fine-grained Turing reductions control the sum of costs over multiple query sizes rather than one terminal size (Carmosino et al., Definition 1);
treewidth-dependent constructions may assume a supplied tree decomposition rather than computing exact treewidth (Kolman–Koutecký).
This issue is a complete replacement, not a compatibility migration. The existing formula text syntax may remain because it is adequate, but the old AST, old evaluator, ambiguous overhead contract, and all superseded call paths must be removed.
Objective
Build one exact canonical symbolic-expression core and three explicit consumers:
SizeMap: checked equalities for exact concrete target sizes.
SizeBound: certified monotone inequalities for conservative target bounds.
Growth: asymptotic simplification and display.
Migrate every registered reduction to the new contracts. Every registered target size field must be explicitly accounted for as exact, bound-only, or unavailable with a reason. No existing declaration is automatically reinterpreted as exact or certified merely to preserve behavior.
Canonical expression representation
Keep one formula parser and one public canonical semantic DAG shared by runtime and proc macros:
The expression domain is eventually-positive problem-size functions. The public representation is a mathematical IR, not a source-syntax tree. Parsing lowers equivalent syntax immediately:
a - b -> a + (-1) * b
a / b -> a * b^-1
-a -> (-1) * a
sqrt(a) -> a^(1/2)
Requirements:
Decimal literals are parsed exactly into arbitrary-precision rationals; 2.372 becomes 593/250 without passing through binary floating point.
Integer intermediates use arbitrary precision. Fixed-width overflow is checked only when converting an exact constructed size to the repository's concrete ProblemSize representation.
Add and Mul are flattened, constants are folded exactly, equal terms and powers are combined, and operands have deterministic structural order.
Canonicalization must preserve the value of eventually-positive size functions. Consumers validate the canonical semantic expression rather than the author's surface spelling.
Variable names are owned. Runtime parsing must not leak strings for 'static lifetimes.
The proc macro and runtime parser share the same grammar and AST semantics. Delete the current ParsedExpr/Expr semantic duplication.
Substitution, composition, equality, hashing where required, serialization, display, variable collection, and growth conversion are implemented once against the canonical DAG.
Immutable Arc sharing and traversal-local memoization keep repeated path composition proportional to the unique DAG rather than an expanded expression tree.
SizeMap
SizeMap is a validated mapping from target field names to canonical Expr values.
Construction accepts only integral constants, fields, addition, subtraction, multiplication, exact division, and non-negative integral powers. Validation compiles expressions into a private checked-integer form; invalid operators are rejected before evaluation. Runtime evaluation has no approximate branch.
Errors name the edge and target field and distinguish:
missing input field;
negative output;
non-integral division/result;
division by zero;
concrete target size outside the supported ProblemSize range.
Bound values use arbitrary-precision non-negative integers so a mathematically valid bound is not truncated to usize.
Registration rejects expressions that are not proven monotone in every referenced input field.
After canonicalization, negative coefficients, negative variable powers, and functions without a structural monotonicity rule cannot enter SizeBound. If canonicalization eliminates such syntax completely, validation uses the resulting semantic expression.
Certified-bound Big-O is derived from SizeBound. When requested, an exact terminal SizeMap expression may also be projected to Growth; neither projection may re-enter path composition or construct a concrete ProblemSize.
No choose2 or other special formula syntax is introduced.
Explicit field accounting
For every registered reduction and every registered target size field, metadata must say one of:
an exact formula is present in SizeMap;
a certified upper formula is present in SizeBound but exact propagation is unavailable;
propagation is unavailable, with a concise reason naming the missing statistic or hard parameter.
An exact field may also have a separate monotone bound. Absence is never interpreted as zero, identity, a same-named field, or permission to use the other contract.
Exact treewidth is not added as a required field. A width bound is admissible only when already present as cheap input metadata or when a decomposition/certificate is part of the model input.
Numeric targets such as ILP, QUBO, Knapsack, and Factoring must account for encoding/coefficient bit length where needed for a valid complexity bound; variable and constraint counts alone are not treated as total encoding size.
Search semantics
Expose two separate APIs and result types:
Exact search: every required field on every edge must have a SizeMap; compare exact terminal vectors only.
no shared Pareto frontier between exact and bound results;
no default mode that silently selects one based on availability;
retain distinct intermediate paths;
apply dominance only at the requested terminal problem;
exclude Turing/multi-query edges from single-target size ranking until they receive a separate query-cost model.
Implementation requirements
Replace the existing expression AST and both parsing/code-generation paths with the exact canonical immutable DAG described above.
Delete the floating concrete evaluator, missing-variable default, rounding, saturation, leaked variable names, and superseded parser/evaluator code.
Reimplement Growth on the canonical AST and confine floating approximation to an explicitly named complexity-estimation boundary.
Implement SizeMap, its validation, checked evaluation, errors, and constructed-target oracle.
Implement SizeBound, monotonicity validation, arbitrary-precision bound evaluation/composition, and errors.
Replace reduction registry metadata and macro syntax directly; do not accept legacy overhead as an alias.
Migrate all registered reductions. Do not automatically classify existing formulas; inspect their construction or proof and declare exact, bound, or unavailable deliberately.
Replace all library, CLI, MCP, export, documentation, and test callers; delete unused forwarding and compatibility code.
The implementation may be large. Architectural completeness takes priority over minimizing changed files or lines. If delivery is split for review, each change must follow an explicit dependency sequence on one integration branch; no intermediate compatibility layer may land on main, and the final merge removes every superseded path.
Verification
Provide one repository-wide behavioural suite:
cargo test symbolic_size_contracts --features example-db -- --nocapture
It must print counts and a final PASS, and prove:
Canonical DAG:n * (n - 1) / 2 - m deterministically normalizes to -1 * m + n * (-1 + n) * 2^-1, and that canonical form survives serialize/deserialize/display.
Exact literals:2.372 is exactly 593/250.
Owned variables: repeated runtime parsing of dynamic variable names does not leak allocations.
Known exact map: the canonical five-vertex, four-edge Maximum Independent Set → Clique case predicts and constructs (5, 6).
Known bound: the same constructed target satisfies its certified bound.
Repository accounting: every registered target size field is classified; the test prints total exact, bound-only, and unavailable field counts, and reports zero unclassified fields.
Exact oracle: every executable canonical example with declared exact fields matches the independently measured constructed target field-by-field; checked count equals eligible count and mismatch count is zero.
Bound oracle: every executable canonical example with declared bounds satisfies them field-by-field; checked count equals eligible measurable bound count and violation count is zero.
Exact negative controls: missing field, negative result, non-integral result, division by zero, and out-of-range concrete output are rejected.
Bound controls: canonical expressions with an irreducible negative coefficient (n - m) or negative variable power (n / m) are rejected during SizeBound construction; an expression such as n - n may normalize to the admissible constant zero.
Contract isolation: exact search on a path lacking a required map returns unavailable and never consults its bound; bound search never reports an exact result.
Growth isolation:exp(n) remains valid for complexity/growth handling but cannot enter SizeMap or produce ProblemSize.
No local pruning: the synthetic complement case retains both prefixes and compares only terminal results.
No legacy path: the old floating concrete evaluator and ambiguous legacy registry fields have been deleted while the behavioural suite and full repository checks pass.
Then run:
make check
cargo test --manifest-path problemreductions-cli/Cargo.toml
Background
Reduction metadata currently uses one lossy
Exprrepresentation for exact structural size calculation, symbolic composition, and asymptotic growth. Constants becomef64, missing variables evaluate as zero, and concrete results are rounded and cast tousize. It also lacks one exact canonical representation shared by contract-specific consumers. The audit in #1125 demonstrates that these semantics cannot support trustworthy Pareto ranking.Complexity theory also separates exact construction facts from certified resource bounds:
k' <= g(k), not equality (Marx, Parameterized Reduction);This issue is a complete replacement, not a compatibility migration. The existing formula text syntax may remain because it is adequate, but the old AST, old evaluator, ambiguous
overheadcontract, and all superseded call paths must be removed.Objective
Build one exact canonical symbolic-expression core and three explicit consumers:
SizeMap: checked equalities for exact concrete target sizes.SizeBound: certified monotone inequalities for conservative target bounds.Growth: asymptotic simplification and display.Migrate every registered reduction to the new contracts. Every registered target size field must be explicitly accounted for as exact, bound-only, or unavailable with a reason. No existing declaration is automatically reinterpreted as exact or certified merely to preserve behavior.
Canonical expression representation
Keep one formula parser and one public canonical semantic DAG shared by runtime and proc macros:
The expression domain is eventually-positive problem-size functions. The public representation is a mathematical IR, not a source-syntax tree. Parsing lowers equivalent syntax immediately:
Requirements:
2.372becomes593/250without passing through binary floating point.ProblemSizerepresentation.AddandMulare flattened, constants are folded exactly, equal terms and powers are combined, and operands have deterministic structural order.'staticlifetimes.ParsedExpr/Exprsemantic duplication.Arcsharing and traversal-local memoization keep repeated path composition proportional to the unique DAG rather than an expanded expression tree.SizeMap
SizeMapis a validated mapping from target field names to canonicalExprvalues.Construction accepts only integral constants, fields, addition, subtraction, multiplication, exact division, and non-negative integral powers. Validation compiles expressions into a private checked-integer form; invalid operators are rejected before evaluation. Runtime evaluation has no approximate branch.
Errors name the edge and target field and distinguish:
ProblemSizerange.Maximum Independent Set → Clique:
For
(num_vertices=5, num_edges=4), the exact result is(5, 6).SizeBound
SizeBoundis a separately validated mapping from target fields to conservative monotone expressions.usize.SizeBound. If canonicalization eliminates such syntax completely, validation uses the resulting semantic expression.SizeBound. When requested, an exact terminalSizeMapexpression may also be projected toGrowth; neither projection may re-enter path composition or construct a concreteProblemSize.Maximum Independent Set → Clique may use:
No
choose2or other special formula syntax is introduced.Explicit field accounting
For every registered reduction and every registered target size field, metadata must say one of:
SizeMap;SizeBoundbut exact propagation is unavailable;An exact field may also have a separate monotone bound. Absence is never interpreted as zero, identity, a same-named field, or permission to use the other contract.
Exact treewidth is not added as a required field. A width bound is admissible only when already present as cheap input metadata or when a decomposition/certificate is part of the model input.
Numeric targets such as ILP, QUBO, Knapsack, and Factoring must account for encoding/coefficient bit length where needed for a valid complexity bound; variable and constraint counts alone are not treated as total encoding size.
Search semantics
Expose two separate APIs and result types:
SizeMap; compare exact terminal vectors only.SizeBound; compare terminal guaranteed-bound vectors only.Rules:
Implementation requirements
Growthon the canonical AST and confine floating approximation to an explicitly named complexity-estimation boundary.SizeMap, its validation, checked evaluation, errors, and constructed-target oracle.SizeBound, monotonicity validation, arbitrary-precision bound evaluation/composition, and errors.overheadas an alias.The implementation may be large. Architectural completeness takes priority over minimizing changed files or lines. If delivery is split for review, each change must follow an explicit dependency sequence on one integration branch; no intermediate compatibility layer may land on
main, and the final merge removes every superseded path.Verification
Provide one repository-wide behavioural suite:
cargo test symbolic_size_contracts --features example-db -- --nocaptureIt must print counts and a final
PASS, and prove:n * (n - 1) / 2 - mdeterministically normalizes to-1 * m + n * (-1 + n) * 2^-1, and that canonical form survives serialize/deserialize/display.2.372is exactly593/250.(5, 6).n - m) or negative variable power (n / m) are rejected duringSizeBoundconstruction; an expression such asn - nmay normalize to the admissible constant zero.exp(n)remains valid for complexity/growth handling but cannot enterSizeMapor produceProblemSize.Then run:
make check cargo test --manifest-path problemreductions-cli/Cargo.tomlBoth commands must exit successfully.
Dependencies
Out of scope
choose2or other special syntax added only for this feature.