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

#SAT, counting the models of a CNF formula

Lax366625.CountingSat · concepts/Lax366625/CountingSat.lean · lax-366625

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

    An instance is a CNF instance of the NP core. Its variables are the elements occurring in some clause, and a model is a set of variables such that every clause contains a true literal. #SAT counts the models: its value on an instance is the number of models, the elements that are not variables being always false.

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

    Lean source view on GitHub

    1import Mathlib.Tactic.FinCases
    2import Mathlib.Order.PiLex
    3import Mathlib.Data.Prod.Lex
    4import Mathlib.Data.Fintype.EquivFin
    5import Mathlib.ModelTheory.Order
    6import Mathlib.ModelTheory.Semantics
    7import Mathlib.ModelTheory.Complexity
    8import Mathlib.Logic.Equiv.Fin.Basic
    9import Mathlib.Data.Finite.Sigma
    10import Mathlib.Data.Fintype.Lattice
    11import Mathlib.ModelTheory.Syntax
    12import Mathlib.Order.Lattice.Nat
    13import Mathlib.Data.Set.Card
    14import Mathlib.Data.Fintype.Pigeonhole
    15import Mathlib.Dynamics.FixedPoints.Basic
    16import Mathlib.Algebra.Order.BigOperators.Group.Finset
    17import Mathlib.Data.Fintype.Card
    18import Mathlib.SetTheory.Cardinal.Finite
    19import Lax904597.Sat
    20import Lax366625.CountingProblems
    21
    22/-!
    23---
    24title: #SAT, counting the models of a CNF formula
    25type: definition
    26---
    27An instance is a CNF instance of the NP core. Its variables are the elements
    28occurring in some clause, and a model is a set of variables such that every
    29clause contains a true literal. #SAT counts the models: its value on an
    30instance is the number of models, the elements that are not variables being
    31always false.
    32-/
    33
    34namespace Lax366625.CountingSat
    35
    36open Lax904597.Sat
    37
    38open FirstOrder
    39
    40open Language Structure
    41
    42section Sat
    43
    44variable (A : Type) [sat.Structure A]
    45
    46/-- The element `x` is a variable of the CNF formula: it occurs, positively or
    47negatively, in some clause. The decision problem does not need the notion –
    48an element in no clause is harmless – but everything that *counts* assignments
    49does, and so does any reduction that must not give such an element a truth
    50value to choose. -/
    51def SatOccurs (x : A) : Prop :=
    52 ∃ c : A, RelMap satIsClause ![c] ∧ (RelMap satPosIn ![c, x] ∨ RelMap satNegIn ![c, x])
    53
    54end Sat
    55
    56open FirstOrder
    57
    58open Language Structure
    59
    60section Models
    61
    62variable (A : Type) [sat.Structure A]
    63
    64/-- The set `ν` of true variables is a model of the CNF formula: every clause
    65contains a true literal, and `ν` consists of variables of the formula. -/
    66def SatModel (ν : A → Prop) : Prop :=
    67 (∀ c : A, RelMap satIsClause ![c] →
    68 ∃ x : A, (RelMap satPosIn ![c, x] ∧ ν x) ∨ (RelMap satNegIn ![c, x] ∧ ¬ν x)) ∧
    69 ∀ x : A, ν x → SatOccurs A x
    70
    71end Models
    72
    73open Lax366625.CountingProblems
    74
    75/-- **#SAT**: the number of models of a CNF formula. -/
    76noncomputable def SharpSAT : CountingProblem sat :=
    77 CountingProblem.ofFun fun A _ => Nat.card {ν : A → Prop // SatModel A ν}
    78
    79end Lax366625.CountingSat
    80

    Discussion

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

    Loading discussion…