Documentation

Complexitylib.Algebraic.Basis.DeMorgan.Expression

De Morgan expressions compiled to circuits #

This is a small tree language for Boolean formulas over the manuscript's actual basis. Unlike the Boolean-ring compiler, it emits NOT, AND, and OR directly, which is useful for zero tests, comparisons, selectors, and sorting-network records. Constants are represented by nullary gates but are free under DeMorgan.standardCost.

Tree-shaped expressions over the De Morgan basis.

Instances For
    @[reducible]

    Number of program gates emitted by tree compilation.

    Equations
    Instances For
      @[reducible]

      Standard charged cost: constants and inputs are free, and each logical operation costs one.

      Equations
      Instances For
        @[simp]
        theorem Algebraic.DeMorgan.Expression.mapInputs_eval {sourceInputs targetInputs : ℕ} (inputMap : Fin sourceInputs → Fin targetInputs) (expression : Expression sourceInputs) (input : Fin targetInputs → Bool) :
        eval input (mapInputs inputMap expression) = eval (input ∘ inputMap) expression
        @[simp]
        theorem Algebraic.DeMorgan.Expression.mapInputs_gateCount {sourceInputs targetInputs : ℕ} (inputMap : Fin sourceInputs → Fin targetInputs) (expression : Expression sourceInputs) :
        (mapInputs inputMap expression).gateCount = expression.gateCount
        @[simp]
        theorem Algebraic.DeMorgan.Expression.mapInputs_standardCost {sourceInputs targetInputs : ℕ} (inputMap : Fin sourceInputs → Fin targetInputs) (expression : Expression sourceInputs) :
        (mapInputs inputMap expression).standardCost = expression.standardCost

        One free constant gate.

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

          constantCircuit is a single constant gate.

          One direct NOT gate.

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

            One direct AND gate.

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

              One direct OR gate.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[simp]
                theorem Algebraic.DeMorgan.Expression.circuit_size {n : ℕ} (expression : Expression n) :
                expression.circuit.size = expression.gateCount

                Compilation emits exactly gateCount program gates.

                @[simp]
                theorem Algebraic.DeMorgan.Expression.circuit_eval {n : ℕ} (expression : Expression n) (input : Fin n → Bool) :
                expression.circuit.eval interpretation input 0 = eval input expression

                Compilation preserves Boolean semantics.

                @[simp]

                Compilation realizes the expression's standard charged cost exactly.

                De Morgan implementation of Boolean XOR.

                Equations
                Instances For
                  @[simp]
                  theorem Algebraic.DeMorgan.Expression.xor_eval {n : ℕ} (left right : Expression n) (input : Fin n → Bool) :
                  eval input (left.xor right) = eval input left + eval input right
                  def Algebraic.DeMorgan.Expression.finXor {n : ℕ} (count : ℕ) :
                  (Fin count → Expression n) → Expression n

                  XOR a finite expression family, with false for the empty family.

                  Equations
                  Instances For
                    @[simp]
                    theorem Algebraic.DeMorgan.Expression.finXor_eval {n : ℕ} (count : ℕ) (terms : Fin count → Expression n) (input : Fin n → Bool) :
                    eval input (finXor count terms) = ∑ index : Fin count, eval input (terms index)
                    def Algebraic.DeMorgan.Expression.finAnd {n : ℕ} (count : ℕ) :
                    (Fin count → Expression n) → Expression n

                    Conjunction of a finite expression family, with true as the empty conjunction.

                    Equations
                    Instances For
                      def Algebraic.DeMorgan.Expression.finOr {n : ℕ} (count : ℕ) :
                      (Fin count → Expression n) → Expression n

                      Disjunction of a finite expression family, with false as the empty disjunction.

                      Equations
                      Instances For

                        Boolean fold matching finAnd's constructor order.

                        Equations
                        Instances For

                          Boolean fold matching finOr's constructor order.

                          Equations
                          Instances For
                            @[simp]
                            theorem Algebraic.DeMorgan.Expression.finAnd_eval {n : ℕ} (count : ℕ) (terms : Fin count → Expression n) (input : Fin n → Bool) :
                            eval input (finAnd count terms) = finAndValue count fun (index : Fin count) => eval input (terms index)
                            @[simp]
                            theorem Algebraic.DeMorgan.Expression.finOr_eval {n : ℕ} (count : ℕ) (terms : Fin count → Expression n) (input : Fin n → Bool) :
                            eval input (finOr count terms) = finOrValue count fun (index : Fin count) => eval input (terms index)
                            theorem Algebraic.DeMorgan.Expression.finAndValue_eq_true_iff (count : ℕ) (values : Fin count → Bool) :
                            finAndValue count values = true ↔ ∀ (index : Fin count), values index = true
                            theorem Algebraic.DeMorgan.Expression.finOrValue_eq_true_iff (count : ℕ) (values : Fin count → Bool) :
                            finOrValue count values = true ↔ ∃ (index : Fin count), values index = true
                            theorem Algebraic.DeMorgan.Expression.finOrValue_oneHot (count : ℕ) (selected : Fin count) (flags values : Fin count → Bool) (selectedTrue : flags selected = true) (unique : ∀ (index : Fin count), flags index = true → index = selected) :
                            (finOrValue count fun (index : Fin count) => flags index && values index) = values selected

                            A disjunction selected by a one-hot flag family returns the selected value.

                            theorem Algebraic.DeMorgan.Expression.finAnd_standardCost {n : ℕ} (count : ℕ) (terms : Fin count → Expression n) :
                            (finAnd count terms).standardCost = ∑ index : Fin count, (terms index).standardCost + count

                            Exact charged cost of a finite conjunction.

                            theorem Algebraic.DeMorgan.Expression.finOr_standardCost {n : ℕ} (count : ℕ) (terms : Fin count → Expression n) :
                            (finOr count terms).standardCost = ∑ index : Fin count, (terms index).standardCost + count

                            Exact charged cost of a finite disjunction.