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

The number written by unit propagation

Lax366625.HornNumbers · concepts/Lax366625/HornNumbers.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 together with a mark on the output variables and a binary relation comparing them. A variable is forced when unit propagation derives it: when it is the positive literal of a clause all of whose negative literals are forced earlier. When the instance is a satisfiable Horn formula and the comparison is a linear order on the output variables, the number written is ∑2r(x)\sum 2^{r(x)} over the forced output variables xx, r(x)r(x) being the number of output variables below xx; otherwise it is 00.

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

    Lean source view on GitHub

    1import Mathlib.Order.Lattice.Nat
    2import Mathlib.Data.Fintype.Card
    3import Mathlib.Data.Fintype.Lattice
    4import Mathlib.Data.Set.Card
    5import Mathlib.Tactic.FinCases
    6import Mathlib.Order.PiLex
    7import Mathlib.Data.Prod.Lex
    8import Mathlib.Data.Fintype.EquivFin
    9import Mathlib.ModelTheory.Order
    10import Mathlib.ModelTheory.Semantics
    11import Mathlib.ModelTheory.Complexity
    12import Mathlib.Logic.Equiv.Fin.Basic
    13import Mathlib.Data.Finite.Sigma
    14import Mathlib.ModelTheory.Syntax
    15import Mathlib.Algebra.BigOperators.Finprod
    16import Mathlib.Data.Fintype.Pigeonhole
    17import Mathlib.Dynamics.FixedPoints.Basic
    18import Lax535992.HornSat
    19import Lax904597.Sat
    20import Lax904597.SecondOrder
    21import Lax366625.CountingProblems
    22
    23/-!
    24---
    25title: The number written by unit propagation
    26type: definition
    27---
    28An instance is a CNF instance of the NP core together with a mark on the
    29output variables and a binary relation comparing them. A variable is forced
    30when unit propagation derives it: when it is the positive literal of a
    31clause all of whose negative literals are forced earlier. When the instance
    32is a satisfiable Horn formula and the comparison is a linear order on the
    33output variables, the number written is ∑2r(x)\sum 2^{r(x)} over the forced
    34output variables xx, r(x)r(x) being the number of output variables below
    35xx; otherwise it is 00.
    36-/
    37
    38namespace Lax366625.HornNumbers
    39
    40open Lax535992.HornSat Lax904597.Sat
    41
    42open FirstOrder
    43
    44open Language Structure Lax904597.SecondOrder.SOBlock
    45
    46section LeastModel
    47
    48variable {A : Type} [sat.Structure A]
    49
    50/-- The stages of unit propagation: `ForcedIn n x` says that `x` is the
    51positive literal of a clause whose negative literals are all forced in fewer
    52than `n` rounds. -/
    53def ForcedIn : ℕ → A → Prop
    54 | 0, _ => False
    55 | n + 1, x => ∃ c : A, RelMap satIsClause ![c] ∧ RelMap satPosIn ![c, x] ∧
    56 ∀ y : A, RelMap satNegIn ![c, y] → ForcedIn n y
    57
    58/-- A variable is *forced* when some stage forces it. On a Horn formula this
    59is the least model of the implications. -/
    60def Forced (x : A) : Prop := ∃ n, ForcedIn n x
    61
    62end LeastModel
    63
    64open FirstOrder
    65
    66open FirstOrder.Language
    67
    68/-- The relation symbols of the language. -/
    69inductive digitOrderRel : ℕ → Type where
    70/-- `out x`: the element `x` holds one digit. -/
    71 | out : digitOrderRel 1
    72/-- `below y x`: the digit of `y` is at most as significant as the one of
    73 `x`. -/
    74 | below : digitOrderRel 2
    75 deriving DecidableEq
    76
    77/-- The symbols reading a number off a set of marked elements. -/
    78def digitOrder : FirstOrder.Language :=
    79 ⟨fun _ => Empty, digitOrderRel⟩
    80
    81instance instIsRelationalDigitOrder : FirstOrder.Language.IsRelational digitOrder := fun _ =>
    82 (inferInstance : IsEmpty Empty)
    83
    84/-- `out x`: the element `x` holds one digit. -/
    85abbrev dgoOut : digitOrder.Relations 1 :=
    86 .out
    87
    88/-- `below y x`: the digit of `y` is at most as significant as the one of
    89 `x`. -/
    90abbrev dgoBelow : digitOrder.Relations 2 :=
    91 .below
    92
    93/-- The relational language of Horn formulas writing a number. -/
    94abbrev satOut : Language.{0, 0} := sat.sum digitOrder
    95
    96open FirstOrder
    97
    98open Language Structure
    99
    100/-- “Is an output variable”. -/
    101abbrev hnOut : satOut.Relations 1 := Sum.inr dgoOut
    102
    103/-- The comparison of the output variables. -/
    104abbrev hnBelow : satOut.Relations 2 := Sum.inr dgoBelow
    105
    106/-- A Horn formula writing a number is a CNF instance. -/
    107instance satOutStructure (A : Type) [satOut.Structure A] :
    108 sat.Structure A :=
    109 (LHom.sumInl : sat →ᴸ satOut).reduct A
    110
    111section Semantics
    112
    113variable {A : Type} [satOut.Structure A]
    114
    115/-- The output variable `x` is forced. -/
    116def ForcedDigit (x : A) : Prop :=
    117 RelMap hnOut ![x] ∧ Forced x
    118
    119/-- `y` is an output variable strictly below `x`. -/
    120def LowerVar (x y : A) : Prop :=
    121 RelMap hnOut ![y] ∧ y ≠ x ∧ RelMap hnBelow ![y, x]
    122
    123/-- The rank of a variable among the outputs: the number of output variables
    124strictly below it. -/
    125noncomputable def varRank (x : A) : ℕ :=
    126 Nat.card {y : A // LowerVar x y}
    127
    128variable (A) in
    129/-- **The comparison of the outputs is a linear order on them**: reflexive,
    130transitive, antisymmetric and total among the output variables. -/
    131def VarOrder : Prop :=
    132 (∀ p : A, RelMap hnOut ![p] → RelMap hnBelow ![p, p]) ∧
    133 (∀ p q r : A, RelMap hnOut ![p] → RelMap hnOut ![q] → RelMap hnOut ![r] →
    134 RelMap hnBelow ![p, q] → RelMap hnBelow ![q, r] → RelMap hnBelow ![p, r]) ∧
    135 (∀ p q : A, RelMap hnOut ![p] → RelMap hnOut ![q] →
    136 RelMap hnBelow ![p, q] → RelMap hnBelow ![q, p] → p = q) ∧
    137 ∀ p q : A, RelMap hnOut ![p] → RelMap hnOut ![q] →
    138 RelMap hnBelow ![p, q] ∨ RelMap hnBelow ![q, p]
    139
    140variable (A) in
    141open Classical in
    142/-- **The number written by unit propagation**: each forced output variable
    143contributes two to the power of its rank among the outputs. Instances that are
    144not satisfiable Horn formulas, or whose outputs are not linearly ordered,
    145write `0`. -/
    146noncomputable def hornNumber : ℕ :=
    147 if HornSatisfiable A ∧ VarOrder A then ∑ᶠ x : A, if ForcedDigit x then 2 ^ varRank x else 0
    148 else 0
    149
    150end Semantics
    151
    152open Lax366625.CountingProblems
    153
    154/-- **The number written by unit propagation**, as a counting problem. -/
    155noncomputable def HornNumber : CountingProblem satOut :=
    156 CountingProblem.ofFun fun A _ => hornNumber A
    157
    158end Lax366625.HornNumbers
    159

    Discussion

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

    Loading discussion…