Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax489179.Satisfiability

Bounded-width CNF satisfiability and its encoding

concepts/Lax489179/Satisfiability.lean · lax-489179

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Definition

    A CNF formula has nn 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 kk means at most kk literals in each clause. The empty conjunction is true and an empty clause is false.

    The binary encoding gives nn, 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 nn and the usual explicit formula size. Polynomial factors in its full length are retained in the SAT running-time bounds; the exponential parameter is nn, not the number of clauses or encoded bits. Unused indexed variables, repeated literals and repeated clauses are allowed.

    Lean source view on GitHub

    1import Mathlib.Data.List.Basic
    2import Mathlib.Data.Fin.Basic
    3
    4/-!
    5---
    6title: Bounded-width CNF satisfiability and its encoding
    7type: definition
    8---
    9A CNF formula has nn indexed Boolean variables. A literal is a variable
    10and a polarity; a clause is a disjunction of literals and a formula is
    11a conjunction of clauses. Width at most kk means at most kk literals
    12in each clause. The empty conjunction is true and an empty clause is false.
    13
    14The binary encoding gives nn, the number of clauses, each clause length,
    15and each literal's index and sign, in that order. Natural numbers use
    16unary followed by a zero. This self-delimiting encoding has polynomial
    17length in nn and the usual explicit formula size. Polynomial factors
    18in its full length are retained in the SAT running-time bounds; the
    19exponential parameter is nn, not the number of clauses or encoded bits.
    20Unused indexed variables, repeated literals and repeated clauses are allowed.
    21-/
    22
    23namespace Lax489179.Satisfiability
    24
    25abbrev Literal (n : ℕ) := Fin n × Bool
    26abbrev Clause (n : ℕ) := List (Literal n)
    27
    28structure Formula where
    29 numVars : ℕ
    30 clauses : List (Clause numVars)
    31
    32def Satisfiable (F : Formula) : Prop :=
    33 ∃ assignment : Fin F.numVars → Bool,
    34 ∀ clause ∈ F.clauses, ∃ literal ∈ clause, assignment literal.1 = literal.2
    35
    36def WidthAtMost (k : ℕ) (F : Formula) : Prop :=
    37 ∀ clause ∈ F.clauses, clause.length ≤ k
    38
    39def encodeNat (n : ℕ) : List Bool := List.replicate n true ++ [false]
    40
    41def encodeLiteral {n : ℕ} (literal : Literal n) : List Bool :=
    42 encodeNat literal.1.val ++ [literal.2]
    43
    44def encodeClause {n : ℕ} (clause : Clause n) : List Bool :=
    45 encodeNat clause.length ++ clause.flatMap encodeLiteral
    46
    47def encode (F : Formula) : List Bool :=
    48 encodeNat F.numVars ++ encodeNat F.clauses.length ++ F.clauses.flatMap encodeClause
    49
    50end 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

    Loading discussion…