Documentation

MIPRE.Foundations.SAT.FmlLib

Formulas on bit vectors #

The vocabulary in which the describer of the succinct Cook–Levin theorem is written (planning/succinct-cook-levin.md, S3): a field is a list of formulas read as a binary number, least significant bit first (Fml.val); the fields of an index are slices of the input bits (Fml.field); and the tests on fields are conjunctions and disjunctions (andList, orList), equality with a constant or another field (eqConst, eqFields), comparison (ltConst, ltFields), addition of a constant with its carry (addBits, addConstRel), subtraction of a constant by the two's complement (subConstBits), padding (padTo) and a multiplexer (mux). Every test is defined by a fold or a structural recursion whose program is the same fold (FmlProg.lean), and every semantics lemma is an equation on val.

Values of bit strings #

theorem MIPRE.SAT.bitsVal_injective {l₁ l₂ : Cost.BitStr} :
List.length l₁ = List.length l₂ → Cost.bitsVal l₁ = Cost.bitsVal l₂ → l₁ = l₂

Equal-length bit strings with equal values are equal.

The bits of a number, padded to W bits with zeros (least significant bit first).

Equations
Instances For

    The two's complement of a W-bit string: 2^W - v modulo 2^W.

    Equations
    Instances For

      Basic connectives #

      Equivalence.

      Equations
      Instances For
        theorem MIPRE.SAT.Fml.eval_xnor (f g : Fml) (x : ℕ → Bool) :
        eval x (f.xnor g) = (eval x f == eval x g)

        Exclusive or.

        Equations
        Instances For
          theorem MIPRE.SAT.Fml.eval_xor (f g : Fml) (x : ℕ → Bool) :
          eval x (f.xor g) = (eval x f != eval x g)
          def MIPRE.SAT.Fml.mux (s a b : Fml) :

          The multiplexer if s then a else b.

          Equations
          Instances For
            theorem MIPRE.SAT.Fml.eval_mux (s a b : Fml) (x : ℕ → Bool) :
            eval x (s.mux a b) = if eval x s = true then eval x a else eval x b

            Conjunction of a list, as a fold.

            Equations
            Instances For
              theorem MIPRE.SAT.Fml.eval_foldl_and (l : List Fml) (init : Fml) (x : ℕ → Bool) :
              eval x (List.foldl and init l) = (eval x init && l.all fun (x_1 : Fml) => eval x x_1)
              theorem MIPRE.SAT.Fml.eval_andList (l : List Fml) (x : ℕ → Bool) :
              eval x (andList l) = l.all fun (x_1 : Fml) => eval x x_1
              theorem MIPRE.SAT.Fml.eval_andList_eq_true (l : List Fml) (x : ℕ → Bool) :
              eval x (andList l) = true ↔ ∀ f ∈ l, eval x f = true

              Disjunction of a list, as a fold.

              Equations
              Instances For
                theorem MIPRE.SAT.Fml.eval_foldl_or (l : List Fml) (init : Fml) (x : ℕ → Bool) :
                eval x (List.foldl or init l) = (eval x init || l.any fun (x_1 : Fml) => eval x x_1)
                theorem MIPRE.SAT.Fml.eval_orList (l : List Fml) (x : ℕ → Bool) :
                eval x (orList l) = l.any fun (x_1 : Fml) => eval x x_1
                theorem MIPRE.SAT.Fml.eval_orList_eq_true (l : List Fml) (x : ℕ → Bool) :
                eval x (orList l) = true ↔ ∃ f ∈ l, eval x f = true

                Fields #

                The bits of a field: the values of its formulas, least significant first.

                Equations
                Instances For
                  def MIPRE.SAT.Fml.val (fs : List Fml) (x : ℕ → Bool) :

                  The value of a field.

                  Equations
                  Instances For
                    @[simp]
                    @[simp]
                    theorem MIPRE.SAT.Fml.bitsOf_cons (f : Fml) (fs : List Fml) (x : ℕ → Bool) :
                    bitsOf (f :: fs) x = eval x f :: bitsOf fs x
                    @[simp]
                    theorem MIPRE.SAT.Fml.length_bitsOf (fs : List Fml) (x : ℕ → Bool) :
                    theorem MIPRE.SAT.Fml.val_cons (f : Fml) (fs : List Fml) (x : ℕ → Bool) :
                    val (f :: fs) x = 2 * val fs x + (eval x f).toNat
                    theorem MIPRE.SAT.Fml.val_lt (fs : List Fml) (x : ℕ → Bool) :
                    val fs x < 2 ^ fs.length

                    The field of W input bits starting at bit a.

                    Equations
                    Instances For
                      @[simp]
                      theorem MIPRE.SAT.Fml.length_field (a W : ℕ) :
                      (field a W).length = W
                      theorem MIPRE.SAT.Fml.bitsOf_field (a W : ℕ) (x : ℕ → Bool) :

                      Constant bits as formulas.

                      Equations
                      Instances For

                        Padding a field to W bits with zeros.

                        Equations
                        Instances For
                          theorem MIPRE.SAT.Fml.length_padTo (W : ℕ) (fs : List Fml) (h : fs.length ≤ W) :
                          (padTo W fs).length = W
                          theorem MIPRE.SAT.Fml.bitsOf_padTo (W : ℕ) (fs : List Fml) (x : ℕ → Bool) :
                          bitsOf (padTo W fs) x = padBits W (bitsOf fs x)
                          theorem MIPRE.SAT.Fml.val_padTo (W : ℕ) (fs : List Fml) (x : ℕ → Bool) :
                          val (padTo W fs) x = val fs x

                          Equality #

                          def MIPRE.SAT.Fml.eqStep (acc : Fml) (p : Fml × Bool) :

                          The step of the equality test with a constant.

                          Equations
                          Instances For

                            The field fs equals the constant c (of the same length).

                            Equations
                            Instances For
                              theorem MIPRE.SAT.Fml.eval_foldl_eqStep (fs : List Fml) (c : Cost.BitStr) :
                              fs.length = List.length c → ∀ (init : Fml) (x : ℕ → Bool), eval x (List.foldl eqStep init (fs.zip c)) = (eval x init && decide (bitsOf fs x = c))
                              theorem MIPRE.SAT.Fml.eval_eqConst (fs : List Fml) (c : Cost.BitStr) (h : fs.length = List.length c) (x : ℕ → Bool) :
                              eval x (eqConst fs c) = decide (bitsOf fs x = c)
                              def MIPRE.SAT.Fml.eqFStep (acc : Fml) (p : Fml × Fml) :

                              The step of the equality test of two fields.

                              Equations
                              Instances For

                                The fields fs and gs (of the same length) are equal.

                                Equations
                                Instances For
                                  theorem MIPRE.SAT.Fml.eval_foldl_eqFStep (fs gs : List Fml) :
                                  fs.length = gs.length → ∀ (init : Fml) (x : ℕ → Bool), eval x (List.foldl eqFStep init (fs.zip gs)) = (eval x init && decide (bitsOf fs x = bitsOf gs x))
                                  theorem MIPRE.SAT.Fml.eval_eqFields (fs gs : List Fml) (h : fs.length = gs.length) (x : ℕ → Bool) :
                                  eval x (eqFields fs gs) = decide (bitsOf fs x = bitsOf gs x)
                                  theorem MIPRE.SAT.Fml.eval_eqFields_iff (fs gs : List Fml) (h : fs.length = gs.length) (x : ℕ → Bool) :
                                  eval x (eqFields fs gs) = true ↔ val fs x = val gs x

                                  Comparison #

                                  The step of the comparison with a constant, least significant bit first: the prefix is below the constant's prefix iff this bit is below, or equal with the lower bits below.

                                  Equations
                                  Instances For

                                    The field fs is below the constant c (of the same length).

                                    Equations
                                    Instances For
                                      theorem MIPRE.SAT.Fml.eval_foldl_ltStep (fs : List Fml) (c : Cost.BitStr) :
                                      fs.length = List.length c → ∀ (init : Fml) (x : ℕ → Bool), eval x (List.foldl ltStep init (fs.zip c)) = true ↔ val fs x < Cost.bitsVal c ∨ val fs x = Cost.bitsVal c ∧ eval x init = true

                                      The step of the comparison of two fields.

                                      Equations
                                      Instances For

                                        The field fs is below the field gs (of the same length).

                                        Equations
                                        Instances For
                                          theorem MIPRE.SAT.Fml.eval_foldl_ltFStep (fs gs : List Fml) :
                                          fs.length = gs.length → ∀ (init : Fml) (x : ℕ → Bool), eval x (List.foldl ltFStep init (fs.zip gs)) = true ↔ val fs x < val gs x ∨ val fs x = val gs x ∧ eval x init = true
                                          theorem MIPRE.SAT.Fml.eval_ltFields_iff (fs gs : List Fml) (h : fs.length = gs.length) (x : ℕ → Bool) :
                                          eval x (ltFields fs gs) = true ↔ val fs x < val gs x

                                          Addition of a constant #

                                          def MIPRE.SAT.Fml.sum3 (f b c : Fml) :

                                          The sum bit of a full adder.

                                          Equations
                                          Instances For
                                            def MIPRE.SAT.Fml.maj3 (f b c : Fml) :

                                            The carry bit of a full adder.

                                            Equations
                                            Instances For
                                              theorem MIPRE.SAT.Fml.eval_sum3_maj3 (f b c : Fml) (x : ℕ → Bool) :
                                              (eval x (f.sum3 b c)).toNat + 2 * (eval x (f.maj3 b c)).toNat = (eval x f).toNat + (eval x b).toNat + (eval x c).toNat

                                              The sum of a field and a constant (of the same length) with a carry in: the sum bits and the carry out.

                                              Equations
                                              Instances For
                                                theorem MIPRE.SAT.Fml.length_addBits (fs : List Fml) (c : Cost.BitStr) :
                                                fs.length = List.length c → ∀ (cin : Fml), (addBits fs c cin).1.length = fs.length
                                                theorem MIPRE.SAT.Fml.val_addBits (fs : List Fml) (c : Cost.BitStr) :
                                                fs.length = List.length c → ∀ (cin : Fml) (x : ℕ → Bool), val (addBits fs c cin).1 x + 2 ^ fs.length * (eval x (addBits fs c cin).2).toNat = val fs x + Cost.bitsVal c + (eval x cin).toNat

                                                The adder identity: sum + 2^W · carry = fs + c + cin.

                                                The sum bits of a field and a constant.

                                                Equations
                                                Instances For

                                                  The carry out of the sum of a field and a constant.

                                                  Equations
                                                  Instances For
                                                    theorem MIPRE.SAT.Fml.val_addConstBits (fs : List Fml) (c : Cost.BitStr) (h : fs.length = List.length c) (x : ℕ → Bool) :
                                                    val (addConstBits fs c) x + 2 ^ fs.length * (eval x (addConstCarry fs c)).toNat = val fs x + Cost.bitsVal c
                                                    theorem MIPRE.SAT.Fml.val_addConstBits_mod (fs : List Fml) (c : Cost.BitStr) (h : fs.length = List.length c) (x : ℕ → Bool) :
                                                    val (addConstBits fs c) x = (val fs x + Cost.bitsVal c) % 2 ^ fs.length

                                                    gs = fs + c, exactly: the sum bits agree and there is no carry out.

                                                    Equations
                                                    Instances For
                                                      theorem MIPRE.SAT.Fml.eval_addConstRel_iff (fs gs : List Fml) (c : Cost.BitStr) (h : fs.length = List.length c) (hg : gs.length = fs.length) (x : ℕ → Bool) :
                                                      eval x (addConstRel fs gs c) = true ↔ val gs x = val fs x + Cost.bitsVal c

                                                      Subtraction of a constant #

                                                      The difference fs - c by the two's complement, correct when c ≤ fs.

                                                      Equations
                                                      Instances For
                                                        theorem MIPRE.SAT.Fml.val_subConstBits (fs : List Fml) (c : Cost.BitStr) (h : fs.length = List.length c) (x : ℕ → Bool) (hc : Cost.bitsVal c ≤ val fs x) :

                                                        Input bounds #

                                                        theorem MIPRE.SAT.Fml.InputsLt.xnor {n : ℕ} {f g : Fml} (hf : InputsLt n f) (hg : InputsLt n g) :
                                                        InputsLt n (f.xnor g)
                                                        theorem MIPRE.SAT.Fml.InputsLt.xor {n : ℕ} {f g : Fml} (hf : InputsLt n f) (hg : InputsLt n g) :
                                                        InputsLt n (f.xor g)
                                                        theorem MIPRE.SAT.Fml.InputsLt.mux {n : ℕ} {s a b : Fml} (hs : InputsLt n s) (ha : InputsLt n a) (hb : InputsLt n b) :
                                                        InputsLt n (s.mux a b)
                                                        theorem MIPRE.SAT.Fml.InputsLt.foldl_and {n : ℕ} (l : List Fml) (init : Fml) (hi : InputsLt n init) (hl : ∀ f ∈ l, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.andList {n : ℕ} (l : List Fml) (hl : ∀ f ∈ l, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.foldl_or {n : ℕ} (l : List Fml) (init : Fml) (hi : InputsLt n init) (hl : ∀ f ∈ l, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.orList {n : ℕ} (l : List Fml) (hl : ∀ f ∈ l, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.field {n a W : ℕ} (h : a + W ≤ n) (f : Fml) :
                                                        f ∈ Fml.field a W → InputsLt n f
                                                        theorem MIPRE.SAT.Fml.InputsLt.padTo {n W : ℕ} {fs : List Fml} (h : ∀ f ∈ fs, InputsLt n f) (f : Fml) :
                                                        f ∈ Fml.padTo W fs → InputsLt n f
                                                        theorem MIPRE.SAT.Fml.InputsLt.foldl_zip {n : ℕ} {γ : Type u_1} (step : Fml → Fml × γ → Fml) (hstep : ∀ (acc : Fml) (p : Fml × γ), InputsLt n acc → InputsLt n p.1 → InputsLt n (step acc p)) (fs : List Fml) (c : List γ) (init : Fml) (hi : InputsLt n init) (hl : ∀ f ∈ fs, InputsLt n f) :
                                                        InputsLt n (List.foldl step init (fs.zip c))
                                                        theorem MIPRE.SAT.Fml.InputsLt.eqConst {n : ℕ} {fs : List Fml} (c : Cost.BitStr) (h : ∀ f ∈ fs, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.foldl_zip₂ {n : ℕ} (step : Fml → Fml × Fml → Fml) (hstep : ∀ (acc : Fml) (p : Fml × Fml), InputsLt n acc → InputsLt n p.1 → InputsLt n p.2 → InputsLt n (step acc p)) (fs gs : List Fml) (init : Fml) (hi : InputsLt n init) (hf : ∀ f ∈ fs, InputsLt n f) (hg : ∀ f ∈ gs, InputsLt n f) :
                                                        InputsLt n (List.foldl step init (fs.zip gs))
                                                        theorem MIPRE.SAT.Fml.InputsLt.eqFields {n : ℕ} {fs gs : List Fml} (h : ∀ f ∈ fs, InputsLt n f) (hg : ∀ f ∈ gs, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.ltConst {n : ℕ} {fs : List Fml} (c : Cost.BitStr) (h : ∀ f ∈ fs, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.ltFields {n : ℕ} {fs gs : List Fml} (h : ∀ f ∈ fs, InputsLt n f) (hg : ∀ f ∈ gs, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.sum3 {n : ℕ} {f b c : Fml} (hf : InputsLt n f) (hb : InputsLt n b) (hc : InputsLt n c) :
                                                        InputsLt n (f.sum3 b c)
                                                        theorem MIPRE.SAT.Fml.InputsLt.maj3 {n : ℕ} {f b c : Fml} (hf : InputsLt n f) (hb : InputsLt n b) (hc : InputsLt n c) :
                                                        InputsLt n (f.maj3 b c)
                                                        theorem MIPRE.SAT.Fml.InputsLt.addBits {n : ℕ} (fs : List Fml) (c : Cost.BitStr) (cin : Fml) :
                                                        (∀ f ∈ fs, InputsLt n f) → InputsLt n cin → (∀ f ∈ (Fml.addBits fs c cin).1, InputsLt n f) ∧ InputsLt n (Fml.addBits fs c cin).2
                                                        theorem MIPRE.SAT.Fml.InputsLt.addConstBits {n : ℕ} {fs : List Fml} (c : Cost.BitStr) (h : ∀ f ∈ fs, InputsLt n f) (f : Fml) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.addConstCarry {n : ℕ} {fs : List Fml} (c : Cost.BitStr) (h : ∀ f ∈ fs, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.addConstRel {n : ℕ} {fs gs : List Fml} (c : Cost.BitStr) (h : ∀ f ∈ fs, InputsLt n f) (hg : ∀ f ∈ gs, InputsLt n f) :
                                                        theorem MIPRE.SAT.Fml.InputsLt.subConstBits {n : ℕ} {fs : List Fml} (c : Cost.BitStr) (h : ∀ f ∈ fs, InputsLt n f) (f : Fml) :