Skip to content

Range analysis: add symbolic constant folding for SymbExpr and cover identity simplification cases#14

Merged
Coursant merged 3 commits intoSymbexpr-Cfrom
copilot/summarize-symbolic-expressions
Apr 13, 2026
Merged

Range analysis: add symbolic constant folding for SymbExpr and cover identity simplification cases#14
Coursant merged 3 commits intoSymbexpr-Cfrom
copilot/summarize-symbolic-expressions

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 13, 2026

SymbExpr simplification was missing constant-identity folding, so symbolic bounds retained avoidable noise (x+0, x*1, x-0) and equivalent forms. This PR adds constant-aware simplification rules and extends symbolic range coverage to assert those expressions collapse as expected.

  • Symbolic simplification: constant-aware folding

    • Added constant helpers in SymbExpr (const_bits, zero/one checks).
    • Added try_simplify_constants() and integrated it into simplify() before linear flattening.
    • Implemented identity/annihilator rewrites for core ops:
      • x + 0, 0 + xx
      • x - 0x
      • x * 1, 1 * xx
      • x * 0, 0 * x0 (explicit zero-constant selection)
      • x / 1x
      • x & 0, 0 & x0
      • x | 0, 0 | xx
      • x ^ 0, 0 ^ xx
      • x << 0, x >> 0x
      • -(-x) / !(!x)x
  • Symbolic range fixture updates

    • Added const_identity_case in range_symbolic to exercise +0, *1, -0 paths.
    • Updated test_symbolic_interval expectations to validate simplified symbolic output and guard against unsimplified identity forms.
fn const_identity_case(x: i32) -> i32 {
    let y = x + 0;
    let z = y * 1;
    let w = z - 0;
    w
}

@Coursant Coursant marked this pull request as ready for review April 13, 2026 20:49
@Coursant Coursant merged commit 8d06352 into Symbexpr-C Apr 13, 2026
0 of 2 checks passed
@Coursant Coursant deleted the copilot/summarize-symbolic-expressions branch April 25, 2026 16:49
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.

2 participants