While this submission is a draft, it cannot be used by other submissions.

2-CNF Formulas and the Language 2-SAT

Lax117284.TwoSatCNF · concepts/Lax117284/TwoSatCNF.lean · lax-117284

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.

    Natural Language Statement

    Definition

    A CNF formula is in 2-CNF when every clause has at most two literals. The language 2-SAT consists of the binary encodings of the satisfiable 2-CNF formulas: it is the language SAT of lax−429075lax-429075, restricted to the encodings of formulas in 2-CNF.

    Concept map
    6 concepts; 6 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Lax429075.Satisfiability
    2import Mathlib.Data.Finset.Card
    3
    4/-!
    5---
    6title: 2-CNF Formulas and the Language 2-SAT
    7type: definition
    8---
    9A CNF formula is in *2-CNF* when every clause has at most two literals. The language 2-SAT
    10consists of the binary encodings of the satisfiable 2-CNF formulas: it is the language SAT of
    11`lax-429075`, restricted to the encodings of formulas in 2-CNF.
    12
    13# Formalization Notes
    14
    15Nothing about formulas, literals, satisfiability or encodings is defined here. A formula is a
    16formula of `lax-429075` — a list of clauses, a clause a list of literals, a literal a variable
    17index with a sign — its satisfiability is that submission's `Satisfiable`, and its binary word is
    18that submission's `encodeCNF`. The only new notion is the width condition, so that 2-SAT is
    19literally a subset of SAT, with membership in the two languages witnessed by the same formula.
    20
    21A clause is allowed to have fewer than two literals. A unit clause is a clause of one literal;
    22the empty clause is a clause no assignment satisfies, so a formula containing one is not
    23satisfiable. Both are handled by the algorithm, and the classical results hold for them: the
    24restriction to clauses of exactly two literals is a convenience that this development does not
    25need.
    26
    27The variables of a formula are the indices its literals mention, however large; a formula on
    28the single variable `1000` has one variable. The count of distinct variables is what the running
    29time of the algorithm is measured by, besides the length of the word.
    30-/
    31
    32namespace Lax117284.TwoSatCNF
    33
    34open Lax429075.CNF Lax429075.Encoding Lax429075.Satisfiability Lax434930.PolynomialTime
    35
    36/-- A CNF formula is in **2-CNF** when every clause has at most two literals. -/
    37def IsTwoCNF (F : Formula) : Prop := ∀ C ∈ F, C.length ≤ 2
    38
    39/-- The literals of a formula, in order of occurrence. -/
    40def literals (F : Formula) : List Literal := F.flatMap id
    41
    42/-- The variables a formula mentions. -/
    43def vars (F : Formula) : Finset ℕ := ((literals F).map Literal.index).toFinset
    44
    45/-- The number of distinct variables of a formula. -/
    46def varCount (F : Formula) : ℕ := (vars F).card
    47
    48/-- **2-SAT**: the encodings of the satisfiable formulas in 2-CNF. It is `SAT` restricted to
    49the encodings of 2-CNF formulas. -/
    50def TwoSAT : Language := {w | ∃ F : Formula, encodeCNF F = w ∧ IsTwoCNF F ∧ Satisfiable F}
    51
    52end Lax117284.TwoSatCNF
    53
    Formalization Notes

    Nothing about formulas, literals, satisfiability or encodings is defined here. A formula is a formula of lax−429075lax-429075 — a list of clauses, a clause a list of literals, a literal a variable index with a sign — its satisfiability is that submission's SatisfiableSatisfiable, and its binary word is that submission's encodeCNFencodeCNF. The only new notion is the width condition, so that 2-SAT is literally a subset of SAT, with membership in the two languages witnessed by the same formula.

    A clause is allowed to have fewer than two literals. A unit clause is a clause of one literal; the empty clause is a clause no assignment satisfies, so a formula containing one is not satisfiable. Both are handled by the algorithm, and the classical results hold for them: the restriction to clauses of exactly two literals is a convenience that this development does not need.

    The variables of a formula are the indices its literals mention, however large; a formula on the single variable 10001000 has one variable. The count of distinct variables is what the running time of the algorithm is measured by, besides the length of the word.

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…