Documentation

Complexitylib.Algebraic.Basis.DeMorgan.Residual

Residual values for De Morgan circuits #

Partial evaluation represents a Boolean value by a constant or a possibly negated wire. This module contains the local Boolean simplifier and the small proof-carrying constructions that realize such values inside a De Morgan program. Whole-program restriction is deliberately kept in a separate module.

A Boolean constant or a signed wire in a residual program.

Instances For
    def Algebraic.DeMorgan.ResidualValue.eval {n g : ℕ} (program : Program signature n g) (input : Fin n → Bool) :

    Evaluate a residual value in a residual program.

    Equations
    Instances For
      @[simp]
      def Algebraic.DeMorgan.ResidualValue.bindWires {n g k h : ℕ} (value : ResidualValue n g) (values : Wire n g → ResidualValue k h) :

      Replace every wire in a residual value by another residual value. This is the small substitution operation used to state that partial evaluation follows zero-cost origin chains.

      Equations
      Instances For
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.bindWires_constant {n g k h : ℕ} (values : Wire n g → ResidualValue k h) (value : Bool) :
        (constant value).bindWires values = constant value
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.bindWires_wire_false {n g k h : ℕ} (values : Wire n g → ResidualValue k h) (wire : Wire n g) :
        (ResidualValue.wire false wire).bindWires values = values wire
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.bindWires_wire_true {n g k h : ℕ} (values : Wire n g → ResidualValue k h) (wire : Wire n g) :
        (ResidualValue.wire true wire).bindWires values = (values wire).negate
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.mapWires_negate {n g h : ℕ} (value : ResidualValue n g) (wireMap : Wire n g → Wire n h) :
        mapWires wireMap value.negate = (mapWires wireMap value).negate
        theorem Algebraic.DeMorgan.ResidualValue.mapWires_injective {n g h : ℕ} {wireMap : Wire n g → Wire n h} (injective : Function.Injective wireMap) :
        Function.Injective fun (value : ResidualValue n g) => mapWires wireMap value
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.bindWires_negate {n g k h : ℕ} (value : ResidualValue n g) (values : Wire n g → ResidualValue k h) :
        value.negate.bindWires values = (value.bindWires values).negate
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.mapWires_bindWires {n g k h l : ℕ} (value : ResidualValue n g) (values : Wire n g → ResidualValue k h) (wireMap : Wire k h → Wire k l) :
        mapWires wireMap (value.bindWires values) = value.bindWires fun (wire : Wire n g) => mapWires wireMap (values wire)
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.bindWires_mapWires {n g h k l : ℕ} (value : ResidualValue n g) (wireMap : Wire n g → Wire n h) (values : Wire n h → ResidualValue k l) :
        (mapWires wireMap value).bindWires values = value.bindWires fun (wire : Wire n g) => values (wireMap wire)
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.eval_constant {n g : ℕ} (program : Program signature n g) (input : Fin n → Bool) (value : Bool) :
        eval program input (constant value) = value
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.eval_wire_false {n g : ℕ} (program : Program signature n g) (input : Fin n → Bool) (residualWire : Wire n g) :
        eval program input (wire false residualWire) = program.trace interpretation input residualWire
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.eval_wire_true {n g : ℕ} (program : Program signature n g) (input : Fin n → Bool) (residualWire : Wire n g) :
        eval program input (wire true residualWire) = !program.trace interpretation input residualWire
        @[simp]
        theorem Algebraic.DeMorgan.ResidualValue.eval_negate {n g : ℕ} (value : ResidualValue n g) (program : Program signature n g) (input : Fin n → Bool) :
        eval program input value.negate = !eval program input value

        The two charged De Morgan connectives.

        Instances For
          @[instance_reducible]
          Equations

          Boolean semantics of a charged connective.

          Equations
          Instances For

            The value which makes a binary operation independent of its other input.

            Equations
            Instances For

              Source-input value making a possibly-negated literal absorbing.

              Equations
              Instances For

                Simplify a binary De Morgan gate. none means both signed inputs are genuinely needed and the charged gate must be retained.

                Equations
                Instances For
                  theorem Algebraic.DeMorgan.simplifyBinary_and_of_argument_false {n g : ℕ} (values : Fin 2 → ResidualValue n g) (argument : Fin 2) (constant : values argument = ResidualValue.constant false) :

                  A false argument annihilates an AND gate, in either input position.

                  theorem Algebraic.DeMorgan.simplifyBinary_or_of_argument_true {n g : ℕ} (values : Fin 2 → ResidualValue n g) (argument : Fin 2) (constant : values argument = ResidualValue.constant true) :

                  A true argument annihilates an OR gate, in either input position.

                  theorem Algebraic.DeMorgan.simplifyBinary_of_argument_constant {n g : ℕ} (op : BinaryOp) (values : Fin 2 → ResidualValue n g) (argument : Fin 2) (value : Bool) (constant : values argument = ResidualValue.constant value) :
                  ∃ (result : ResidualValue n g), simplifyBinary op (values 0) (values 1) = some result

                  Any constant argument makes a binary De Morgan gate simplifiable.

                  theorem Algebraic.DeMorgan.simplifyBinary_of_common_value {n g : ℕ} (op : BinaryOp) (value : ResidualValue n g) (leftNegated rightNegated : Bool) :
                  ∃ (result : ResidualValue n g), simplifyBinary op (if leftNegated = true then value.negate else value) (if rightNegated = true then value.negate else value) = some result

                  Two signed forms of one residual value always make a binary gate simplify.

                  theorem Algebraic.DeMorgan.simplifyBinary_sound {n g : ℕ} {op : BinaryOp} {left right result : ResidualValue n g} (simplifies : simplifyBinary op left right = some result) (program : Program signature n g) (input : Fin n → Bool) :
                  ResidualValue.eval program input result = op.eval (ResidualValue.eval program input left) (ResidualValue.eval program input right)

                  simplifyBinary preserves the value of a gate whenever it succeeds.

                  Materialization #

                  def Algebraic.DeMorgan.identityLine {n g : ℕ} (sourceWire : Wire n g) :

                  A free identity line.

                  Equations
                  Instances For
                    def Algebraic.DeMorgan.notLine {n g : ℕ} (sourceWire : Wire n g) :

                    A free negation line.

                    Equations
                    Instances For
                      def Algebraic.DeMorgan.binaryLine {n g : ℕ} (op : BinaryOp) (left right : Wire n g) :

                      A charged binary line.

                      Equations
                      Instances For
                        theorem Algebraic.DeMorgan.binaryLine_mapWires {n g h : ℕ} (op : BinaryOp) (left right : Wire n g) (wireMap : Wire n g → Wire n h) :
                        (binaryLine op left right).mapWires wireMap = binaryLine op (wireMap left) (wireMap right)

                        Mapping the wires of a binary line maps its two named arguments.

                        theorem Algebraic.DeMorgan.binaryLine_wire_eq_left_or_right {n g : ℕ} (op : BinaryOp) (left right : Wire n g) (argument : Fin (signature.Arity (binaryLine op left right).op)) :
                        (binaryLine op left right).wires argument = left ∨ (binaryLine op left right).wires argument = right

                        Every argument wire of a binary line is one of its two named inputs.

                        theorem Algebraic.DeMorgan.andLine_eq_binaryLine {n g : ℕ} (wires : Fin 2 → Wire n g) :
                        { op := Op.and, wires := wires } = binaryLine BinaryOp.and (wires 0) (wires 1)

                        Every binary AND line is determined by its two arguments.

                        theorem Algebraic.DeMorgan.orLine_eq_binaryLine {n g : ℕ} (wires : Fin 2 → Wire n g) :
                        { op := Op.or, wires := wires } = binaryLine BinaryOp.or (wires 0) (wires 1)

                        Every binary OR line is determined by its two arguments.

                        @[simp]
                        @[simp]
                        theorem Algebraic.DeMorgan.identityLine_cost {n g : ℕ} (sourceWire : Wire n g) :
                        binaryCost (identityLine sourceWire).op = 0
                        @[simp]
                        theorem Algebraic.DeMorgan.notLine_cost {n g : ℕ} (sourceWire : Wire n g) :
                        binaryCost (notLine sourceWire).op = 0
                        @[simp]
                        theorem Algebraic.DeMorgan.binaryLine_cost {n g : ℕ} (op : BinaryOp) (left right : Wire n g) :
                        binaryCost (binaryLine op left right).op = 1
                        @[simp]
                        theorem Algebraic.DeMorgan.binaryLine_eval {n g : ℕ} (op : BinaryOp) (left right : Wire n g) (program : Program signature n g) (input : Fin n → Bool) :
                        (binaryLine op left right).eval interpretation input (program.eval interpretation input) = op.eval (program.trace interpretation input left) (program.trace interpretation input right)
                        @[simp]
                        theorem Algebraic.DeMorgan.binaryLine_interpretation {n g : ℕ} (op : BinaryOp) (left right : Wire n g) (values : Wire n g → Bool) :
                        (interpretation (binaryLine op left right).op fun (argument : Fin (arity (binaryLine op left right).op)) => values ((binaryLine op left right).wires argument)) = op.eval (values left) (values right)

                        Applying a binary line to an arbitrary wire valuation reads its two inputs.

                        theorem Algebraic.DeMorgan.ResidualValue.eval_mapWires {n g h : ℕ} (value : ResidualValue n g) (wireMap : Wire.Renaming n g h) (source : Program signature n g) (result : Program signature n h) (input : Fin n → Bool) (preserves : ∀ (sourceWire : Wire n g), result.trace interpretation input (wireMap.apply sourceWire) = source.trace interpretation input sourceWire) :
                        eval result input (mapWires wireMap.apply value) = eval source input value
                        structure Algebraic.DeMorgan.Materialization {n g : ℕ} (program : Program signature n g) (value : ResidualValue n g) :

                        Materialize a residual value as a wire, adding only zero-cost gates and embedding every old wire into the extended program.

                        Instances For
                          def Algebraic.DeMorgan.materialize {n g : ℕ} (program : Program signature n g) (value : ResidualValue n g) :
                          Materialization program value

                          Materialize a constant or signed wire using at most one free gate.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            structure Algebraic.DeMorgan.RetainedGate {n g : ℕ} (program : Program signature n g) (op : BinaryOp) (left right : ResidualValue n g) :

                            Retain a genuinely binary gate after materializing its signed arguments. The extension adds exactly one unit of charged cost.

                            Instances For
                              def Algebraic.DeMorgan.retainGate {n g : ℕ} (program : Program signature n g) (op : BinaryOp) (left right : ResidualValue n g) :
                              RetainedGate program op left right

                              Materialize two signed arguments and append their charged gate.

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