Documentation

MIPRE.Foundations.SAT.Formula

Boolean formulas and their circuits #

A formula (Fml) is a tree of and, or, not over input bits and constants. Its post-order flattening (Fml.flattenAt) is a circuit in which every gate is read at most once (input bits are read through fresh input gates, which Circuit.WellFormed does not count), so a formula's circuit is well-formed whatever the formula (Fml.toCircuit_wellFormed), and computes the formula (Fml.eval_toCircuit). The describer of the succinct Cook–Levin theorem is built as a formula, which confines the circuit bookkeeping to this file (planning/succinct-cook-levin.md, S3).

inductive MIPRE.SAT.Fml :

Boolean formulas over input bits.

Instances For
    def MIPRE.SAT.instDecidableEqFml.decEq (x✝ x✝¹ : Fml) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For
      @[instance_reducible]
      Equations
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        The number of nodes: the number of gates of the circuit.

        Equations
        Instances For
          theorem MIPRE.SAT.Fml.InputsLt.mono {n m : ℕ} (h : n ≤ m) {f : Fml} (hf : InputsLt n f) :

          Formulas as data: the post-order serialization #

          The nodes of the post-order (reverse Polish) serialization of a formula.

          Instances For
            def MIPRE.SAT.Fml.instDecidableEqNode.decEq (x✝ x✝¹ : Node) :
            Decidable (x✝ = x✝¹)
            Equations
            Instances For
              Equations
              Instances For
                @[simp]

                Parsing a post-order serialization.

                Equations
                Instances For
                  @[instance_reducible]

                  Formulas encode as their post-order serializations, so that a program builds a formula by appending lists.

                  Equations
                  • One or more equations did not get rendered due to their size.

                  The serialization, as a polynomial-time function (the encoding is the same).

                  Equations
                  Instances For
                    @[simp]

                    The constructors as polynomial-time functions.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              @[simp]
                              @[simp]
                              theorem MIPRE.SAT.Fml.andF_apply (p : Fml × Fml) :
                              andF.toFun p = p.1.and p.2
                              @[simp]
                              theorem MIPRE.SAT.Fml.orF_apply (p : Fml × Fml) :
                              orF.toFun p = p.1.or p.2
                              @[simp]

                              Flattening to a circuit #

                              The post-order gate list of a formula whose first gate is at position base: the output gate is the last one, at base + size - 1.

                              Equations
                              Instances For
                                @[simp]
                                theorem MIPRE.SAT.Fml.length_flattenAt (base : ℕ) (f : Fml) :
                                (flattenAt base f).length = f.size

                                The circuit of a formula on n inputs.

                                Equations
                                Instances For
                                  @[simp]
                                  @[simp]
                                  theorem MIPRE.SAT.Fml.toCircuit_size (n : ℕ) (f : Fml) :
                                  theorem MIPRE.SAT.Fml.refs_flattenAt (base : ℕ) (f : Fml) (k : ℕ) (hk : k < (flattenAt base f).length) (u : ℕ) :
                                  u ∈ (flattenAt base f)[k].refs → base ≤ u ∧ u < base + k

                                  Every reference of the gate at position k of flattenAt base f lies in [base, base + k).

                                  The number of references to u in a gate list.

                                  Equations
                                  Instances For
                                    @[simp]
                                    @[simp]
                                    theorem MIPRE.SAT.Fml.refCount_append (gs hs : List Gate) (u : ℕ) :
                                    refCount (gs ++ hs) u = refCount gs u + refCount hs u
                                    theorem MIPRE.SAT.Fml.refCount_eq_zero_of_forall (gs : List Gate) (u : ℕ) (h : ∀ (k : ℕ) (hk : k < gs.length), u ∉ gs[k].refs) :
                                    refCount gs u = 0

                                    A gate list whose references at position k are in [base, base + k) references no u outside [base, base + length - 1).

                                    theorem MIPRE.SAT.Fml.refCount_flattenAt_eq_zero (base : ℕ) (f : Fml) (u : ℕ) (hu : u < base ∨ base + f.size - 1 ≤ u) :
                                    refCount (flattenAt base f) u = 0
                                    theorem MIPRE.SAT.Fml.refCount_flattenAt_le (base : ℕ) (f : Fml) (u : ℕ) :
                                    refCount (flattenAt base f) u ≤ 1

                                    Every gate of the circuit of a formula is read at most once, and the output gate is read by no gate.

                                    theorem MIPRE.SAT.Fml.inputsLt_of_mem_flattenAt {n : ℕ} (base : ℕ) (f : Fml) :
                                    InputsLt n f → ∀ (i : ℕ), Gate.input i ∈ flattenAt base f → i < n

                                    The circuit of a formula is well-formed.

                                    Evaluation #

                                    theorem MIPRE.SAT.Fml.Circuit.valueAt_append (n : ℕ) (gs post : List Gate) (x : ℕ → Bool) (k : ℕ) (hk : k < gs.length) :
                                    { inputs := n, gates := gs ++ post }.valueAt x k = { inputs := n, gates := gs }.valueAt x k

                                    The value of a gate depends only on the gates up to it: appending gates changes nothing.

                                    theorem MIPRE.SAT.Fml.Circuit.getD_ofFn_valueAt (C : Circuit) (x : ℕ → Bool) (k u : ℕ) (hu : u < k) :
                                    (List.ofFn fun (i : Fin k) => C.valueAt x ↑i).getD u false = C.valueAt x u

                                    The values of the earlier gates, as read by a gate.

                                    theorem MIPRE.SAT.Fml.valueAt_flattenAt (n : ℕ) (x : ℕ → Bool) (f : Fml) (pre post : List Gate) :
                                    { inputs := n, gates := pre ++ flattenAt pre.length f ++ post }.valueAt x (pre.length + f.size - 1) = eval x f

                                    The output gate of flattenAt placed after pre computes the formula, whatever follows.

                                    theorem MIPRE.SAT.Fml.eval_toCircuit (n : ℕ) (f : Fml) (x : ℕ → Bool) :
                                    (toCircuit n f).eval x = eval x f

                                    The circuit of a formula computes it.

                                    theorem MIPRE.SAT.Fml.evalBits_toCircuit (n : ℕ) (f : Fml) (l : List Bool) :
                                    (toCircuit n f).evalBits l = eval (fun (i : ℕ) => l.getD i false) f