DEV Community

Bohdan Hordii
Bohdan Hordii

Posted on Originally published at bohdanhordii.dev

Architectural Deep-Dive: SemantEq: Faithful Bidirectional Equivalence of Formal Statements

Solving the Trivial Equivalence Trap in Formal Statement Autoformalization

Automated formalization bridges natural language specifications and interactive theorem provers like Lean 4. While Large Language Models can generate formal Lean statements at high velocity, confirming that an autoformalized statement $P$ faithfully matches a reference statement $Q$ remains a major engineering bottleneck.

In this article, we examine the fundamental flaws of legacy equivalence checking and how proof-term rewriting audits resolve them.

Canonical publication: https://bohdanhordii.dev


1. Problem Statement & Production Failure Modes

The standard naive approach to checking whether statement $P$ faithfully translates statement $Q$ is evaluating bidirectional logical equivalence: $P \leftrightarrow Q$.

In production-grade formal environments powered by extensive libraries (such as Lean 4's Mathlib), this approach fails fundamentally. If both $P$ and $Q$ represent provable facts or tautologies within the library, an automated prover effortlessly derives:

$$P \leftrightarrow \mathrm{True} \leftrightarrow Q$$

Consequently, completely unrelated propositions—such as Fermat's Little Theorem and the irrationality of $\sqrt{2}$—pass automated equivalence gates as identical. As LLMs and automated theorem provers become more capable, the false-positive rate of naive equivalence checks actually worsens, degrading the reliability of automated specification synthesis.

Previous attempts restricted provers or enforced syntactic naming heuristics (e.g., verifying that the proof of $P$ references the token $Q$). These heuristics are brittle, easy to hallucinate, and break across minor refactorings.


2. Architectural Breakdown: Proof-Term Auditing

The SemantEq framework solves this by enforcing that statement $P$ transforms into $Q$ exclusively through a sequence of verified, authorized rewrite steps (such as structural logical rearrangements and identity substitutions).

Core Design Tenet: Lean Proof Terms over Tactic Scripts

Tactic scripts (like by simp; aesop) are high-level meta-programs that obscure how a truth was reached. In contrast, Lean 4 compiles every proof down to a minimal, verifiable lambda-calculus proof term checked by the trusted kernel.

SemantEq inspects the compiled proof term directly:

+-------------------------------------------------------------+
|                      LLM Generator                          |
|  Generates bidirectional proof candidate: P <-> Q           |
+------------------------------+------------------------------+
                               |
                               v
+-------------------------------------------------------------+
|                   Lean 4 Kernel Check                       |
|  Type-checks proof term into core lambda-calculus           |
+------------------------------+------------------------------+
                               |
                               v
+-------------------------------------------------------------+
|                  SemantEq-ProofAudit Gate                   |
|  Validates that proof-term AST contains only:               |
|   - Logical symmetry & associativity rewrites               |
|   - Whitelisted library equalities                         |
|   - Zero shortcut traversals via P <-> True <-> Q           |
+-------------------------------------------------------------+
Enter fullscreen mode Exit fullscreen mode

By separating equivalence candidate generation from strict audit acceptance, we decouple prover capability from verification integrity. The LLM can be aggressively tuned for recall, while the deterministic policy auditor guarantees 100% precision.


3. Benchmarks & Production Takeaways

Benchmarked against the ProofNetVerif dataset:

  • Algorithmic Search (SemantEq-Eval): Reached 100% precision with 65.6% recall completely without an LLM in the loop.
  • Model-Assisted Audit (SemantEq-ProofAudit): Screened 104 non-equivalent statement pairs and accepted zero false positives (0% error rate), while elevating recall on genuine equivalent pairs from 65.4% to 81.1%.

Recommended Architectural Patterns for Autonomous Agents

  1. Zero-Trust Spec Ingestion: Never trust an LLM declaring two software specs or formal interfaces are identical based on text similarity or unconstrained test runs.
  2. Isolate Generation from Validation: Treat LLMs strictly as untrusted proposal engines. Use deterministic kernel validators to evaluate the AST of proof terms.
  3. Decouple Tactic Execution from Audit Policy: Do not rely on tactic success flags. Inspect the resulting term graph to ensure no vacuous proofs (shortcuts via trivial truths) bypassed your safety constraints.

Formal verification is rapidly transitioning from academic curiosity to a mission-critical safety layer for autonomous software engineering.


Author: Bohdan Hordii | Website: bohdanhordii.dev | Contact: @bohdan_hordii

Top comments (0)