Skip to content

Commit

Permalink
style: make some proofs happen and less imperative
Browse files Browse the repository at this point in the history
  • Loading branch information
hargoniX committed Dec 16, 2023
1 parent a3cfb19 commit d7f581d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions crup.lean
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ where
match cs with
| [] => (units, others)
| c :: cs =>
if c.size == 1 then
let lit := c[0]'sorry
if h : c.size == 1 then
let lit := c[0]'(by simp_all_arith)
go cs (lit :: units) others
else
go cs units (c :: others)
Expand All @@ -147,21 +147,23 @@ Propagate a single `unit` clause through a list of `Clauses`, outputting the rem
-/
def unitPropagate (unit : Int) (clauses : Clauses) : LogM (UnitClauses × Clauses) := do
log s!"Propagating {unit} into {clauses.toList}"
let mut newUnits := []
let mut remainder := []
for clause in clauses do
if clause.contains unit then
pure ()
else if clause.contains (-unit) then
let newClause := clause.erase (-unit)
if newClause.size == 1 then
let lit := newClause[0]'sorry
newUnits := lit :: newUnits
return go clauses [] []
where
go (clauses : Clauses) (newUnits : List Int) (remainder : Clauses) : UnitClauses × Clauses :=
match clauses with
| [] => (newUnits, remainder)
| clause :: clauses =>
if clause.contains unit then
go clauses newUnits remainder
else if clause.contains (-unit) then
let newClause := clause.erase (-unit)
if h : newClause.size == 1 then
let lit := newClause[0]'(by simp_all_arith)
go clauses (lit :: newUnits) remainder
else
go clauses newUnits (newClause :: remainder)
else
remainder := newClause :: remainder
else
remainder := clause :: remainder
return (newUnits, remainder)
go clauses newUnits (clause :: remainder)

/--
Derive False by running `unitPropagate` on a list of `Clauses`.
Expand Down

0 comments on commit d7f581d

Please sign in to comment.