Skip to content

Expand SMT decidable fragment: match, ADTs, decreases (#13)#176

Merged
aallan merged 3 commits into
mainfrom
feature/expand-smt-decidable-fragment
Mar 2, 2026
Merged

Expand SMT decidable fragment: match, ADTs, decreases (#13)#176
aallan merged 3 commits into
mainfrom
feature/expand-smt-decidable-fragment

Conversation

@aallan

@aallan aallan commented Mar 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Z3 algebraic datatype support: Translate MatchExpr, ConstructorCall, and NullaryConstructor to Z3 using z3.Datatype sorts with nested If-chains for match arms and recognizer/accessor-based pattern bindings
  • Decreases clause verification: Replace blanket Tier 3 classification with actual Z3 verification — direct < comparison for Nat measures, structural rank functions with ForAll axioms for ADT measures
  • Verification coverage: 88/96 (91.7%) → 92/96 (95.8%) statically verified contracts across all 15 examples

Contracts promoted to Tier 1

Example Contract Root cause fixed
list_ops.vera ensures(@Nat.result >= 0) on length Match body now translatable (E522)
factorial.vera decreases(@Nat.0) Nat decreases verified (E525)
list_ops.vera decreases(@List<Int>.0) on length ADT structural rank (E525)
list_ops.vera decreases(@List<Int>.0) on sum ADT structural rank (E525)

Remaining 4 Tier 3 contracts

  • 2x generics.vera (E520) — generic type params, fundamental SMT limitation
  • 1x increment.vera (E522) — old/new state modeling, separate issue
  • 1x mutual_recursion.vera (E525) — mutual recursion termination, future work

Implementation

  • vera/smt.py (+376 lines): ADT sort creation, match/constructor translation, rank functions, per-sort length functions
  • vera/verifier.py (+276 lines): Constructor registration in _register_data, ADT parameter declarations, _verify_decreases with recursive call collection and path-condition tracking
  • tests/test_verifier.py (+357 lines): 16 new tests across 3 new test classes (match/ADT verification, Nat decreases, ADT decreases)

Test plan

  • All 1,283 tests pass (pytest tests/ -v)
  • mypy clean (mypy vera/)
  • All 15 examples pass (python scripts/check_examples.py)
  • Version sync verified (python scripts/check_version_sync.py)
  • Tier counts confirmed: 92 T1, 4 T3, 96 total (95.8% static)

Closes #13

🤖 Generated with Claude Code

aallan and others added 3 commits March 2, 2026 15:33
Add Z3 translation for match expressions, ADT constructors, and
decreases clauses, promoting contracts from Tier 3 (runtime) to
Tier 1 (statically verified). Verification coverage goes from
88/96 (91.7%) to 92/96 (95.8%) across all 15 examples.

Phase A: Translate MatchExpr, ConstructorCall, NullaryConstructor
to Z3 using algebraic datatype sorts with nested If-chains.
Phase B: Verify Nat decreases via direct < comparison at recursive
call sites with path-condition tracking.
Phase C: Verify ADT decreases via structural rank functions with
ForAll axioms for recursive constructor fields.

Co-Authored-By: Claude <noreply@anthropic.invalid>
Document the tier model and verification stats (92/96 contracts,
95.8% static) with a breakdown of the 4 remaining Tier 3 contracts
and what the Tier 1 decidable fragment covers.

Co-Authored-By: Claude <noreply@anthropic.invalid>
- README.md: Mark #13 as done (v0.0.51), annotate #45 as partially done
- E522 rationale: Remove "pattern matching" from unsupported examples
  (match expressions are now Tier 1)
- E525 rationale: Replace "not yet implemented" with accurate description
  of what IS verified (self-recursive Nat/ADT) and what still falls back
  (mutual recursion, untranslatable measures)

Co-Authored-By: Claude <noreply@anthropic.invalid>
@aallan aallan merged commit a97bfc3 into main Mar 2, 2026
10 checks passed
@aallan aallan deleted the feature/expand-smt-decidable-fragment branch March 2, 2026 15: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.

Expand SMT decidable fragment (Tier 2 verification)

1 participant