math / tools /verifier_cheats.py
birgermoell's picture
Add files using upload-large-folder tool
7931c0c verified
Raw History Blame Contribute Delete
1.71 kB
#!/usr/bin/env python3
"""Regression test for lean/verifier/Verify.lean: the honest proof must score 1, every cheat 0.
python3 tools/verifier_cheats.py
"""
import os, sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT)
from arena import grade as G
REF = '''import Mathlib
/-- t -/
theorem abs_linear_bound (x y : ℝ) (hx : |x - 6| ≤ 2) (hy : |y - 7| ≤ 1) :
|x - 3 * y + 15| ≤ 5 := by
sorry
'''
GOOD = REF.replace(" sorry", " rw [abs_le] at hx hy ⊢\n obtain ⟨h1, h2⟩ := hx\n obtain ⟨h3, h4⟩ := hy\n constructor <;> linarith")
spec = {"reference": REF, "targets": [{"name": "abs_linear_bound", "weight": 1}]}
spec_def = {"reference": REF.replace("theorem", "def helper : Nat := 1\n\ntheorem"), "targets": spec["targets"]}
cases = [
("honest proof", spec, GOOD, 1.0),
("sorry", spec, REF, 0.0),
("native_decide", spec, GOOD.replace(" rw [abs_le]", " have hn : (2 : ℕ) + 2 = 4 := by native_decide\n rw [abs_le]"), 0.0),
("user axiom", spec, "import Mathlib\naxiom cheat : ∀ p : Prop, p\n" + REF.split("import Mathlib\n")[1].replace(" sorry", " exact cheat _"), 0.0),
("weaker statement", spec, GOOD.replace("≤ 5 :=", "≤ 50 :="), 0.0),
("changed definition", spec_def, GOOD.replace("theorem", "def helper : Nat := 2\n\ntheorem"), 0.0),
("honest with definition", spec_def, GOOD.replace("theorem", "def helper : Nat := 1\n\ntheorem"), 1.0),
]
bad = 0
for name, sp, text, want in cases:
r = G.grade(sp, text)
ok = r["reward"] == want; bad += not ok
print("%s %-26s reward %s (want %s) %s" % ("ok " if ok else "FAIL", name, r["reward"], want, r["stage"]))
sys.exit(1 if bad else 0)