Documentation

MIPRE.Foundations.SAT.Flatten

Flattening a formula to a circuit, in polynomial time #

A formula is encoded as its post-order serialization (Fml.rpn), and the circuit of a formula (Fml.flattenAt 0) is computed from that serialization by a single left-to-right scan with a stack of gate indices (flStep, flatten): an input or constant node emits its gate and pushes the gate's index; a connective pops the indices of its arguments, emits the gate and pushes the new index. The scan is a fold, so the program is a PolyTimeFun.foldl of the step (PolyTimeFun.casesNode dispatches on the node), and Fml.toCircuitF is the circuit of a formula on a given number of inputs as a polynomial-time function (planning/succinct-cook-levin.md, S3).

The scan #

@[reducible, inline]

The state of the scan: the stack of gate indices, the gates so far (reversed), and the number of gates so far.

Equations
Instances For

    One step of the scan.

    Equations
    Instances For
      theorem MIPRE.SAT.foldl_flStep_rpn (f : Fml) (rest : List Fml.Node) (vs : List ℕ) (out : List Gate) (cnt : ℕ) :
      List.foldl flStep (vs, out, cnt) (f.rpn ++ rest) = List.foldl flStep ((cnt + f.size - 1) :: vs, (Fml.flattenAt cnt f).reverse ++ out, cnt + f.size) rest

      The scan of the serialization of f from a state pushes the output index of f and emits its gates.

      The gates of a serialization.

      Equations
      Instances For

        The size of the state along the scan #

        The payload of a gate: the input index of an input gate.

        Equations
        Instances For
          theorem MIPRE.SAT.flStep_bounded (l : List Fml.Node) (E : ℕ) (hE : ∀ nd ∈ l, Cost.esize nd ≤ E) (vs : List ℕ) (out : List Gate) (cnt D : ℕ) :
          (∀ v ∈ vs, Cost.esize v ≤ D) → Cost.esize cnt ≤ D → have s := List.foldl flStep (vs, out, cnt) l; (∀ v ∈ s.1, Cost.esize v ≤ D + 4 * l.length) ∧ Cost.esize s.2.2 ≤ D + 4 * l.length ∧ Cost.esize s.1 ≤ Cost.esize vs + l.length * (D + 4 * l.length + 1) ∧ Cost.esize s.2.1 ≤ Cost.esize out + l.length * (2 * (D + 4 * l.length) + E + 13)

          Along the scan, every index on the stack is bounded, and so is the state.

          Dispatch on a node #

          The branches of casesNodeProg, in the environments described there.

          Equations
          Instances For

            Dispatch on the node of an input (a, nd): the environment after the two elims is [tag, payload, a, nd, input], and the unary tag is inspected one nil at a time.

            Equations
            Instances For
              theorem MIPRE.SAT.FlProg.casesNodeProg_inp {Fi Fc Fa Fo Fn : Cost.Prog} (hi : Cost.Prog.WellScoped 1 Fi) (ea : Cost.Data) (i : ℕ) {r : Cost.Data} {t : ℕ} (h : Cost.Eval [ea.cons (Cost.encode i)] Fi r t) :
              Cost.Eval [ea.cons (Cost.encode (Fml.Node.inp i))] (casesNodeProg Fi Fc Fa Fo Fn) r (ea.size + Cost.esize i + t + 7)
              theorem MIPRE.SAT.FlProg.casesNodeProg_const {Fi Fc Fa Fo Fn : Cost.Prog} (hc : Cost.Prog.WellScoped 1 Fc) (ea : Cost.Data) (b : Bool) {r : Cost.Data} {t : ℕ} (h : Cost.Eval [ea.cons (Cost.encode b)] Fc r t) :
              Cost.Eval [ea.cons (Cost.encode (Fml.Node.const b))] (casesNodeProg Fi Fc Fa Fo Fn) r (ea.size + Cost.esize b + t + 8)
              theorem MIPRE.SAT.FlProg.casesNodeProg_and {Fi Fc Fa Fo Fn : Cost.Prog} (ha : Cost.Prog.WellScoped 1 Fa) (ea : Cost.Data) {r : Cost.Data} {t : ℕ} (h : Cost.Eval [ea] Fa r t) :
              Cost.Eval [ea.cons (Cost.encode Fml.Node.and)] (casesNodeProg Fi Fc Fa Fo Fn) r (ea.size + t + 7)
              theorem MIPRE.SAT.FlProg.casesNodeProg_or {Fi Fc Fa Fo Fn : Cost.Prog} (ho : Cost.Prog.WellScoped 1 Fo) (ea : Cost.Data) {r : Cost.Data} {t : ℕ} (h : Cost.Eval [ea] Fo r t) :
              Cost.Eval [ea.cons (Cost.encode Fml.Node.or)] (casesNodeProg Fi Fc Fa Fo Fn) r (ea.size + t + 8)
              theorem MIPRE.SAT.FlProg.casesNodeProg_not {Fi Fc Fa Fo Fn : Cost.Prog} (hn : Cost.Prog.WellScoped 1 Fn) (ea : Cost.Data) {r : Cost.Data} {t : ℕ} (h : Cost.Eval [ea] Fn r t) :
              Cost.Eval [ea.cons (Cost.encode Fml.Node.not)] (casesNodeProg Fi Fc Fa Fo Fn) r (ea.size + t + 8)
              def MIPRE.SAT.PolyTimeFun.casesNodeFun {α : Type u_1} {β : Type u_2} (Fi : α × ℕ → β) (Fc : α × Bool → β) (Fa Fo Fn : α → β) :
              α × Fml.Node → β

              The function of casesNode.

              Equations
              Instances For
                noncomputable def MIPRE.SAT.PolyTimeFun.casesNode {α : Type u_1} {β : Type u_2} [Cost.SizedEncoding α] [Cost.SizedEncoding β] (Fi : Cost.PolyTimeFun (α × ℕ) β) (Fc : Cost.PolyTimeFun (α × Bool) β) (Fa Fo Fn : Cost.PolyTimeFun α β) :

                Case analysis on a node component.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  @[simp]
                  theorem MIPRE.SAT.PolyTimeFun.casesNode_inp {α : Type u_1} {β : Type u_2} [Cost.SizedEncoding α] [Cost.SizedEncoding β] (Fi : Cost.PolyTimeFun (α × ℕ) β) (Fc : Cost.PolyTimeFun (α × Bool) β) (Fa Fo Fn : Cost.PolyTimeFun α β) (a : α) (i : ℕ) :
                  (casesNode Fi Fc Fa Fo Fn).toFun (a, Fml.Node.inp i) = Fi.toFun (a, i)
                  @[simp]
                  theorem MIPRE.SAT.PolyTimeFun.casesNode_const {α : Type u_1} {β : Type u_2} [Cost.SizedEncoding α] [Cost.SizedEncoding β] (Fi : Cost.PolyTimeFun (α × ℕ) β) (Fc : Cost.PolyTimeFun (α × Bool) β) (Fa Fo Fn : Cost.PolyTimeFun α β) (a : α) (b : Bool) :
                  (casesNode Fi Fc Fa Fo Fn).toFun (a, Fml.Node.const b) = Fc.toFun (a, b)
                  @[simp]
                  theorem MIPRE.SAT.PolyTimeFun.casesNode_and {α : Type u_1} {β : Type u_2} [Cost.SizedEncoding α] [Cost.SizedEncoding β] (Fi : Cost.PolyTimeFun (α × ℕ) β) (Fc : Cost.PolyTimeFun (α × Bool) β) (Fa Fo Fn : Cost.PolyTimeFun α β) (a : α) :
                  (casesNode Fi Fc Fa Fo Fn).toFun (a, Fml.Node.and) = Fa.toFun a
                  @[simp]
                  theorem MIPRE.SAT.PolyTimeFun.casesNode_or {α : Type u_1} {β : Type u_2} [Cost.SizedEncoding α] [Cost.SizedEncoding β] (Fi : Cost.PolyTimeFun (α × ℕ) β) (Fc : Cost.PolyTimeFun (α × Bool) β) (Fa Fo Fn : Cost.PolyTimeFun α β) (a : α) :
                  (casesNode Fi Fc Fa Fo Fn).toFun (a, Fml.Node.or) = Fo.toFun a
                  @[simp]
                  theorem MIPRE.SAT.PolyTimeFun.casesNode_not {α : Type u_1} {β : Type u_2} [Cost.SizedEncoding α] [Cost.SizedEncoding β] (Fi : Cost.PolyTimeFun (α × ℕ) β) (Fc : Cost.PolyTimeFun (α × Bool) β) (Fa Fo Fn : Cost.PolyTimeFun α β) (a : α) :
                  (casesNode Fi Fc Fa Fo Fn).toFun (a, Fml.Node.not) = Fn.toFun a

                  The scan as a polynomial-time function #

                  The gate constructors as polynomial-time functions.

                  Equations
                  Instances For

                    The step of the scan on a leaf: push the counter, emit the gate, increment.

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

                      The step of the scan on a binary connective: pop two indices, emit the gate, push. The state is presented as ((out, cnt), vs) to casesList.

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

                        The step of the scan on a negation.

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

                          The step of the scan, as a polynomial-time function.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            theorem MIPRE.SAT.esize_flState (vs : List ℕ) (out : List Gate) (cnt : ℕ) :
                            Cost.esize (vs, out, cnt) = Cost.esize vs + (Cost.esize out + Cost.esize cnt + 1) + 1

                            The Cobham condition of the scan.

                            The gates of a serialization, in polynomial time.

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

                              The circuit of a formula on n inputs, in polynomial time.

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