Lax489179.Satisfiability
Bounded-width CNF satisfiability and its encoding
concepts/Lax489179/Satisfiability.lean · lax-489179
No public endorsements yet.
Loading review…
Sign in with ORCIDConcept map
Definition
A CNF formula has indexed Boolean variables. A literal is a variable and a polarity; a clause is a disjunction of literals and a formula is a conjunction of clauses. Width at most means at most literals in each clause. The empty conjunction is true and an empty clause is false.
The binary encoding gives , the number of clauses, each clause length, and each literal's index and sign, in that order. Natural numbers use unary followed by a zero. This self-delimiting encoding has polynomial length in and the usual explicit formula size. Polynomial factors in its full length are retained in the SAT running-time bounds; the exponential parameter is , not the number of clauses or encoded bits. Unused indexed variables, repeated literals and repeated clauses are allowed.
Lean source view on GitHub
| 1 | import Mathlib.Data.List.Basic |
| 2 | import Mathlib.Data.Fin.Basic |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: Bounded-width CNF satisfiability and its encoding |
| 7 | type: definition |
| 8 | --- |
| 9 | A CNF formula has indexed Boolean variables. A literal is a variable |
| 10 | and a polarity; a clause is a disjunction of literals and a formula is |
| 11 | a conjunction of clauses. Width at most means at most literals |
| 12 | in each clause. The empty conjunction is true and an empty clause is false. |
| 13 | |
| 14 | The binary encoding gives , the number of clauses, each clause length, |
| 15 | and each literal's index and sign, in that order. Natural numbers use |
| 16 | unary followed by a zero. This self-delimiting encoding has polynomial |
| 17 | length in and the usual explicit formula size. Polynomial factors |
| 18 | in its full length are retained in the SAT running-time bounds; the |
| 19 | exponential parameter is , not the number of clauses or encoded bits. |
| 20 | Unused indexed variables, repeated literals and repeated clauses are allowed. |
| 21 | -/ |
| 22 | |
| 23 | namespace Lax489179.Satisfiability |
| 24 | |
| 25 | abbrev Literal (n : ℕ) := Fin n × Bool |
| 26 | abbrev Clause (n : ℕ) := List (Literal n) |
| 27 | |
| 28 | structure Formula where |
| 29 | numVars : ℕ |
| 30 | clauses : List (Clause numVars) |
| 31 | |
| 32 | def Satisfiable (F : Formula) : Prop := |
| 33 | ∃ assignment : Fin F.numVars → Bool, |
| 34 | ∀ clause ∈ F.clauses, ∃ literal ∈ clause, assignment literal.1 = literal.2 |
| 35 | |
| 36 | def WidthAtMost (k : ℕ) (F : Formula) : Prop := |
| 37 | ∀ clause ∈ F.clauses, clause.length ≤ k |
| 38 | |
| 39 | def encodeNat (n : ℕ) : List Bool := List.replicate n true ++ [false] |
| 40 | |
| 41 | def encodeLiteral {n : ℕ} (literal : Literal n) : List Bool := |
| 42 | encodeNat literal.1.val ++ [literal.2] |
| 43 | |
| 44 | def encodeClause {n : ℕ} (clause : Clause n) : List Bool := |
| 45 | encodeNat clause.length ++ clause.flatMap encodeLiteral |
| 46 | |
| 47 | def encode (F : Formula) : List Bool := |
| 48 | encodeNat F.numVars ++ encodeNat F.clauses.length ++ F.clauses.flatMap encodeClause |
| 49 | |
| 50 | end Lax489179.Satisfiability |
| 51 |
Community review
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.
0 comments