Skip to content

Commit 9b8792a

Browse files
haasonsaasclaude
andcommitted
fix: Preserve informative result when both provers fail
When Lean fails and Coq fallback also fails (e.g. UNAVAILABLE), return the Lean result instead of discarding it. Symmetric logic applied to both _lean_then_coq and _coq_then_lean — the initial prover's result is preserved when the fallback doesn't prove either. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d155229 commit 9b8792a

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

formal_verification/hybrid_lean_coq_resolver.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,41 @@ def _lean_then_coq(self, spec: FormalSpec) -> ProofResult:
5454
"""Try Lean first, fall back to Coq."""
5555
lean_spec = self._ensure_lean_spec(spec)
5656
if lean_spec is not None:
57-
result = self.lean_prover.prove_specification(lean_spec)
58-
if result.proven:
59-
return result
57+
lean_result = self.lean_prover.prove_specification(lean_spec)
58+
if lean_result.proven:
59+
return lean_result
60+
else:
61+
lean_result = None
6062

6163
if not self.use_fallback:
62-
if lean_spec is not None:
63-
return result
64+
if lean_result is not None:
65+
return lean_result
6466
return self._untranslatable(spec, "lean")
6567

66-
return self.coq_prover.prove_specification(spec)
68+
coq_result = self.coq_prover.prove_specification(spec)
69+
if coq_result.proven:
70+
return coq_result
71+
# Prefer the more informative result from whichever prover ran.
72+
return lean_result if lean_result is not None else coq_result
6773

6874
def _coq_then_lean(self, spec: FormalSpec) -> ProofResult:
6975
"""Try Coq first, fall back to Lean."""
70-
result = self.coq_prover.prove_specification(spec)
71-
if result.proven:
72-
return result
76+
coq_result = self.coq_prover.prove_specification(spec)
77+
if coq_result.proven:
78+
return coq_result
7379

7480
if not self.use_fallback:
75-
return result
81+
return coq_result
7682

7783
lean_spec = self._ensure_lean_spec(spec)
7884
if lean_spec is None:
79-
return result
80-
return self.lean_prover.prove_specification(lean_spec)
85+
return coq_result
86+
87+
lean_result = self.lean_prover.prove_specification(lean_spec)
88+
if lean_result.proven:
89+
return lean_result
90+
# Both failed — prefer the initial result.
91+
return coq_result
8192

8293
def _ensure_lean_spec(self, spec: FormalSpec) -> FormalSpec | None:
8394
"""Translate the spec's claim to Lean if needed."""

0 commit comments

Comments
 (0)