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

Satisfiability decided by counting models

Lax175070.SelectedSat · concepts/Lax175070/SelectedSat.lean · lax-175070

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

    ⊕SAT asks whether a CNF instance of the NP core has an odd number of models, and Modk_k-SAT whether that number is not a multiple of kk.

    An instance with a selected variable is a CNF instance together with a mark on its variables. #SelSATb_b counts the models in which every selected variable has the value bb. SelMajSAT asks whether the selected variable is true in more models than it is false, and SelEqSAT whether it is true in exactly as many models as it is false.

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

    Lean source view on GitHub

    1import Mathlib.Data.Fintype.Lattice
    2import Mathlib.ModelTheory.Order
    3import Mathlib.ModelTheory.Semantics
    4import Mathlib.ModelTheory.Complexity
    5import Mathlib.Tactic.FinCases
    6import Mathlib.SetTheory.Cardinal.Finite
    7import Mathlib.Order.PiLex
    8import Mathlib.Data.Prod.Lex
    9import Mathlib.Data.Fintype.EquivFin
    10import Mathlib.Logic.Equiv.Fin.Basic
    11import Mathlib.Data.Finite.Sigma
    12import Mathlib.Order.Lattice.Nat
    13import Mathlib.Data.Set.Card
    14import Mathlib.Data.Fintype.Pigeonhole
    15import Mathlib.Dynamics.FixedPoints.Basic
    16import Mathlib.ModelTheory.Syntax
    17import Mathlib.Algebra.Order.BigOperators.Group.Finset
    18import Mathlib.Data.Fintype.Card
    19import Mathlib.Data.Set.Finite.Lemmas
    20import Mathlib.Algebra.BigOperators.Finprod
    21import Mathlib.Logic.Equiv.Prod
    22import Lax366625.CountingSat
    23import Lax904597.Sat
    24import Lax485149.Problems
    25import Lax366625.CountingProblems
    26import Lax175070.CountDefinability
    27
    28/-!
    29---
    30title: Satisfiability decided by counting models
    31type: definition
    32---
    33⊕SAT asks whether a CNF instance of the NP core has an odd number of models,
    34and Modk_k-SAT whether that number is not a multiple of kk.
    35
    36An instance with a selected variable is a CNF instance together with a mark
    37on its variables. #SelSATb_b counts the models in which every selected
    38variable has the value bb. SelMajSAT asks whether the selected variable is
    39true in more models than it is false, and SelEqSAT whether it is true in
    40exactly as many models as it is false.
    41-/
    42
    43namespace Lax175070.SelectedSat
    44
    45open Lax366625.CountingSat Lax904597.Sat
    46
    47open FirstOrder
    48
    49open FirstOrder.Language
    50
    51/-- The relation symbols of the language. -/
    52inductive selMarkRel : ℕ → Type where
    53/-- `sel x`: the variable `x` is selected. -/
    54 | sel : selMarkRel 1
    55 deriving DecidableEq
    56
    57/-- The symbol selecting a variable. -/
    58def selMark : FirstOrder.Language :=
    59 ⟨fun _ => Empty, selMarkRel⟩
    60
    61instance instIsRelationalSelMark : FirstOrder.Language.IsRelational selMark := fun _ =>
    62 (inferInstance : IsEmpty Empty)
    63
    64/-- `sel x`: the variable `x` is selected. -/
    65abbrev smSel : selMark.Relations 1 :=
    66 .sel
    67
    68/-- The relational language of CNF formulas with a selected variable. -/
    69abbrev satSel : Language.{0, 0} := sat.sum selMark
    70
    71open FirstOrder
    72
    73open Language Structure
    74
    75/-- “Is selected”, in the vocabulary of CNF formulas with a selected
    76variable. -/
    77abbrev ssSel : satSel.Relations 1 := Sum.inr smSel
    78
    79/-- A CNF formula with a selected variable is a CNF formula. -/
    80instance satSelStructure (A : Type) [satSel.Structure A] :
    81 sat.Structure A :=
    82 (LHom.sumInl : sat →ᴸ satSel).reduct A
    83
    84section Counts
    85
    86variable (A : Type) [satSel.Structure A]
    87
    88/-- A model of the formula in which every selected variable has the value
    89`b`. -/
    90def SelModel (b : Bool) (ν : A → Prop) : Prop :=
    91 SatModel A ν ∧ ∀ x : A, RelMap ssSel ![x] → (ν x ↔ b = true)
    92
    93end Counts
    94
    95open Lax904597.Problems Lax485149.Problems Lax366625.CountingProblems Lax175070.CountDefinability
    96
    97/-- **⊕SAT**: the number of models of a CNF formula is odd. -/
    98noncomputable def ParitySAT : DecisionProblem sat :=
    99 decide Odd SharpSAT
    100
    101/-- **Mod_k-SAT**: the number of models of a CNF formula is not a multiple of
    102`k`. -/
    103noncomputable def ModSAT (k : ℕ) : DecisionProblem sat :=
    104 decide (fun c => ¬ k ∣ c) SharpSAT
    105
    106/-- **#SelSAT**: the number of models in which every selected variable has the
    107value `b`. -/
    108noncomputable def SharpSelSAT (b : Bool) : CountingProblem satSel :=
    109 CountingProblem.ofFun fun A _ => Nat.card {ν : A → Prop // SelModel A b ν}
    110
    111/-- **SelMajSAT**: the selected variable is true in more models than it is
    112false. -/
    113noncomputable def SelMajSAT : DecisionProblem satSel :=
    114 DecisionProblem.ofPred fun A _ => SharpSelSAT false A < SharpSelSAT true A
    115
    116/-- **SelEqSAT**: the selected variable is true in exactly as many models as it
    117is false. -/
    118noncomputable def SelEqSAT : DecisionProblem satSel :=
    119 DecisionProblem.ofPred fun A _ => SharpSelSAT true A = SharpSelSAT false A
    120
    121end Lax175070.SelectedSat
    122

    Discussion

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

    Loading discussion…