Skip to content

Ask the e-graph whether two expressions are equal: MathS.AreEqual - #2447

Merged
Rafael-SOWNet merged 3 commits into
masterfrom
feature/ask-the-egraph-for-equality
Nov 15, 2026
Merged

Rafael-SOWNet merged 3 commits into
masterfrom
feature/ask-the-egraph-for-equality

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Closes #1251, in the shape agreed on the issue.

API

EqualityAnswer MathS.AreEqual(Entity left, Entity right, WorkBudget budget,
    Soundness weakest = Soundness.Sound, Domain domain = Domain.Complex);

The answer is three-valued: Equal, NotEqual or Unknown, with the BudgetOutcome, so a spent budget is never read as a negative.

  • Equal carries the weakest soundness it relied on, and for a conditional proof the steps that merged a class.
  • NotEqual carries a witness point.

How it decides, in one budget ledger:

  1. Refute. Up to 12 points, some off the real line for Complex. Two sides differ at a point when both are defined there and their interval enclosures are disjoint.
  2. Prove. Both sides go into one e-graph, which saturates under the safe rules, and the answer is whether they share a class. With weakest = Sound only the rules declaring Sound run.
  3. Otherwise Unknown.

Commutativity is Sound. For the query only, two steps reorder the operands of a sum and of a product. They don't group or fold anything, and they are not in any rule set, so Simplify is unchanged. They decline when an operand involves a matrix, a transpose, a set, a statement or a lambda. They also decline for the whole question when it writes a matrix operation (#2147). Names are read as numbers of domain, which the docs say.

Catalogue and MCP. The catalogue entry is are_equal, and the MCP tool is am_are_equal. Unlike am_verify_equal, it never answers from sampling. Its not_equal comes with a point you can check, and unknown is never reported as false. The terminal lists it in notOffered.

Measured

The corpus is 83 true pairs from the simplification regression tests. Mean cost per query is from the prototype, against Simplify(a - b) == 0.

arm proved cost per query
AreEqual, Sound 18 Equal (15 before the reordering steps), 65 Unknown about 3–4× the time, 8–9× the allocation
AreEqual, SoundUnderAssumptions 71 Equal, 12 Unknown same order
the same 83 pairs made false 83 NotEqual, each with a witness —

There was no NotEqual on a true pair and no Equal on a false one. All 12 Unknowns saturated inside the budget, so what limits them is the rules, which cannot expand or factorise. Simplify proves more of these pairs, but it has no NotEqual and no Unknown.

Checks.

  • Unit tests: 19856 passed. MCP 431, Terminal 69, F# 134 and Interactive passed. AOT smoke: 78 of 78.
  • Harnesses:
    • boundcheck: 0 disagreements
    • rootcheck: 596/596
    • casbench: 0 wrong
    • propcheck: 0 failures
    • simpsweep: 10463/10463
    • rulecheck: 0
    • canoncheck and confluence: on baseline
  • New public API is recorded in PublicApi.txt. There is no BREAKING-CHANGES entry, since no answer changes.

Left open

  • The assumptions are rule names, not conditions as entities, and they are a superset.
  • "Equal where both sides are defined" is not transitive through an intermediate with a smaller domain. Refuting first is the mitigation; a proof-producing union-find would close it.
  • A witness is found only where the interval evaluator reads both sides. A side with provided, piecewise, a binder or a set can only come out Equal or Unknown.

🤖 Generated with Claude Code

Rafael-SOWNet and others added 3 commits November 15, 2026 00:31
MathS.AreEqual(left, right, budget, weakest = Sound, domain = Complex)
answers Equal, NotEqual or Unknown.

- NotEqual only with a witness: a point where the library's evaluation
  and an enclosure of every subexpression say both sides are defined,
  and enclosures of the two values are disjoint (doubles, then fifty
  digits). The point is looked for first, so no proof is reported over
  a point that refutes it.
- Equal only when both sides land in one e-class. Under weakest =
  Sound only rules declaring Sound fire; under SoundUnderAssumptions
  the conditional rules and the canonical-form pass join, the answer
  names those that merged a class, and a proof the sound rules also
  make is reported as Sound.
- Bounded in steps: a point tried, a match attempt, a node grown.

Saturation.Run reports each rule whose application merged two classes.

Part of #1251.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The e-graph neither sorts a commutative pair nor flattens a nested chain,
and the pass that does, CanonicalOrderExact, also groups like terms and
so declares SoundUnderAssumptions. x + y = y + x was therefore Unknown
to a caller asking for an unconditional proof.

Two oracle-only steps, declared Sound, flatten a Sumf chain or a Mulf
chain (differences and quotients stay operands) and rebuild it in
EntityOrder.Canonical order, grouping nothing. Commutativity and
associativity hold for numbers with no side condition, and a name is a
number of the domain asked. A chain is left alone where an operand holds
a matrix, a transpose, a set, a statement, a lambda or an application,
or where a link is read over a narrower codomain; a question with any
matrix or matrix operation in it gets neither step, since a name beside
a transpose may be a matrix (#2147). Simplify and every rule set are
untouched.

Records the public surface #1251 adds in PublicApi.txt, and points
CanonicalForm.md's "not a decision procedure for equality" at
MathS.AreEqual.

Part of #1251.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
are_equal joins Core/Operations/Catalogue.cs: an operation offered by
name is an entry there.

The MCP server offers it as am_are_equal: left and right as strings, a
step budget (default 20000), domain (complex or real) and the weakest
soundness (sound or sound_under_assumptions). The answer states the
verdict, the justification, the assumptions, the witness and what the
budget did; unknown is "inconclusive" with equal null, never false. The
description sets it apart from am_verify_equal, which may answer from
sampling and believes a simplification.

The terminal lists it in OneShot.notOffered: its one-shot commands are
AngouriMathCLI's, and adding commands is #1019 item 16's question.

Part of #1251.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.00524% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.95%. Comparing base (5ec47ae) to head (4ff08e9).

Files with missing lines Patch % Lines
...AngouriMath/Core/Transformations/EqualityOracle.cs 92.15% 4 Missing and 8 partials ⚠️
...AngouriMath/Core/Transformations/EqualityAnswer.cs 60.86% 9 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2447      +/-   ##
==========================================
+ Coverage   86.92%   86.95%   +0.03%     
==========================================
  Files         316      319       +3     
  Lines       70574    70760     +186     
  Branches    20613    20666      +53     
==========================================
+ Hits        61345    61528     +183     
+ Misses       4956     4953       -3     
- Partials     4273     4279       +6     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.48% <88.94%> (+0.02%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 39.81% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/AngouriMath/Convenience/MathS.Equality.cs 100.00% <100.00%> (ø)
Sources/AngouriMath/Core/Operations/Catalogue.cs 100.00% <100.00%> (ø)
...ces/AngouriMath/Core/Transformations/Saturation.cs 93.54% <100.00%> (+0.21%) ⬆️
...urces/Terminal/AngouriMath.Terminal.Lib/OneShot.fs 69.48% <100.00%> (ø)
...AngouriMath/Core/Transformations/EqualityAnswer.cs 60.86% <60.86%> (ø)
...AngouriMath/Core/Transformations/EqualityOracle.cs 92.15% <92.15%> (ø)

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit f439c0e into master Nov 15, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 15, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the feature/ask-the-egraph-for-equality branch November 15, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

The e-graph is a congruence closure and nothing can ask it whether two expressions are equal

1 participant