Documentation

Cslib.Computability.Circuit.Synthesis

Simultaneous circuit synthesis #

Synthesis I sources targets cost bounds the number of additional gates needed to compute targets from sources under an interpretation I. Every function already available in the starting program remains available, so successive constructions can share intermediate results. The signature and its carrier are arbitrary; neither needs to be finite or decidable.

The core rules compose bounds, combine finite families, and apply operations of the signature. The fold rules accept a bound for combining two arguments, which may itself use several gates. Synthesis.exists_circuit_family selects any finite family of outputs without adding gates; Synthesis.exists_circuit specializes this to a single output.

def Cslib.Circuits.inputs {U : Type u} (n : ) :
Set ((Fin nU)U)

The coordinate projections supplied by the circuit's inputs.

Equations
Instances For
    def Cslib.Circuits.available {σ : Signature} {U : Type u} {n : } (I : Interpretation σ U) {g : } (p : Program σ n g) :
    Set ((Fin nU)U)

    The functions computed by the wires of p, whether input wires or internal gates.

    Equations
    Instances For
      theorem Cslib.Circuits.mem_available {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {g : } {p : Program σ n g} {f : (Fin nU)U} :
      f available I p ∃ (w : Fin (n + g)), ∀ (x : Fin nU), p.trace I x w = f x

      A function is available exactly when some wire computes it pointwise.

      theorem Cslib.Circuits.inputs_subset_available {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {g : } (p : Program σ n g) :
      inputs navailable I p

      The input projections are available in every program.

      def Cslib.Circuits.Synthesis {σ : Signature} {U : Type u} {n : } (I : Interpretation σ U) (sources targets : Set ((Fin nU)U)) (cost : ) :

      Synthesis I sources targets cost says that targets can be computed from sources using at most cost additional gates, without losing anything already computed.

      Precisely: for every program p₁ on whose wires every function in sources is available, there is a program p₂ such that

      • p₂ has at most cost more gates than p₁,
      • every function available in p₁ is still available in p₂, and
      • every function in targets is available in p₂.

      Quantifying over an arbitrary starting program, rather than the empty one, is what lets constructions share intermediate results: Synthesis.comp adds budgets because the second construction may reuse wires built by the first.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Cslib.Circuits.Synthesis.of_subset {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s t : Set ((Fin nU)U)} (h : ts) :
        Synthesis I s t 0

        Available functions require no additional gates.

        theorem Cslib.Circuits.Synthesis.mono {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s t : Set ((Fin nU)U)} {a b : } (h : Synthesis I s t a) {s' t' : Set ((Fin nU)U)} (hs : ss') (ht : t't) (hab : a b) :
        Synthesis I s' t' b

        Enlarge the source family, narrow the target family, or increase the budget.

        theorem Cslib.Circuits.Synthesis.comp {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s t t₁ : Set ((Fin nU)U)} {a b : } (h : Synthesis I s t a) (h' : Synthesis I (s t) t₁ b) :
        Synthesis I s t₁ (a + b)

        Successive constructions add their gate budgets.

        theorem Cslib.Circuits.Synthesis.union {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s t t₁ : Set ((Fin nU)U)} {a b : } (h : Synthesis I s t a) (h' : Synthesis I s t₁ b) :
        Synthesis I s (t t₁) (a + b)

        Combine two target families, preserving the first while constructing the second.

        theorem Cslib.Circuits.Synthesis.gate {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s : Set ((Fin nU)U)} (op : σ.Op) (args : Fin (σ.Arity op)(Fin nU)U) (hargs : ∀ (i : Fin (σ.Arity op)), args i s) :
        Synthesis I s {fun (x : Fin nU) => I op fun (i : Fin (σ.Arity op)) => args i x} 1

        Synthesize an operation whose arguments are already available.

        theorem Cslib.Circuits.Synthesis.biUnion {σ : Signature} {U : Type u} {n : } {ι : Type w} {I : Interpretation σ U} {s : Set ((Fin nU)U)} (indices : Finset ι) (targets : ιSet ((Fin nU)U)) (cost : ι) (h : iindices, Synthesis I s (targets i) (cost i)) :
        Synthesis I s (⋃ iindices, targets i) (∑ iindices, cost i)

        Combine a finite family of target sets, retaining all earlier results.

        theorem Cslib.Circuits.Synthesis.iUnion {σ : Signature} {U : Type u} {n : } {ι : Type w} {I : Interpretation σ U} {s : Set ((Fin nU)U)} [Fintype ι] (targets : ιSet ((Fin nU)U)) (cost : ι) (h : ∀ (i : ι), Synthesis I s (targets i) (cost i)) :
        Synthesis I s (⋃ (i : ι), targets i) (∑ i : ι, cost i)

        Combine target sets indexed by a finite type.

        theorem Cslib.Circuits.Synthesis.family {σ : Signature} {U : Type u} {n : } {ι : Type w} {I : Interpretation σ U} {s : Set ((Fin nU)U)} [Fintype ι] (f : ι(Fin nU)U) (cost : ι) (h : ∀ (i : ι), Synthesis I s {f i} (cost i)) :
        Synthesis I s (Set.range f) (∑ i : ι, cost i)

        Simultaneously synthesize an indexed finite family of functions.

        theorem Cslib.Circuits.Synthesis.gate_of_syntheses {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s : Set ((Fin nU)U)} (op : σ.Op) (args : Fin (σ.Arity op)(Fin nU)U) (cost : Fin (σ.Arity op)) (h : ∀ (i : Fin (σ.Arity op)), Synthesis I s {args i} (cost i)) :
        Synthesis I s {fun (x : Fin nU) => I op fun (i : Fin (σ.Arity op)) => args i x} (i : Fin (σ.Arity op), cost i + 1)

        Synthesize every argument, then apply an operation with one further gate.

        theorem Cslib.Circuits.Synthesis.nullary {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s : Set ((Fin nU)U)} (op : σ.Op) (arity : σ.Arity op = 0) :
        Synthesis I s {fun (x : Fin nU) => I op fun (i : Fin (σ.Arity op)) => (Fin.cast arity i).elim0} 1

        A nullary operation supplies its interpreted constant with one gate.

        theorem Cslib.Circuits.Synthesis.unary {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s : Set ((Fin nU)U)} {a : } {f : (Fin nU)U} (h : Synthesis I s {f} a) (op : σ.Op) :
        Synthesis I s {fun (x : Fin nU) => I op fun (x_1 : Fin (σ.Arity op)) => f x} (a + 1)

        Feed a synthesized function to every argument of an operation, using one further gate. In particular, this applies a unary operation.

        theorem Cslib.Circuits.Synthesis.binary {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s : Set ((Fin nU)U)} {a b : } {f g : (Fin nU)U} (hf : Synthesis I s {f} a) (hg : Synthesis I s {g} b) (op : σ.Op) :
        Synthesis I s {fun (x : Fin nU) => I op fun (i : Fin (σ.Arity op)) => if i = 0 then f x else g x} (a + b + 1)

        Feed f to argument zero and g to the remaining arguments, using one further gate. For a binary operation, these are its two arguments.

        theorem Cslib.Circuits.Synthesis.combine {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {s : Set ((Fin nU)U)} {a b : } {f g result : (Fin nU)U} {c : } (hf : Synthesis I s {f} a) (hg : Synthesis I s {g} b) (h : Synthesis I {f, g} {result} c) :
        Synthesis I s {result} (a + b + c)

        Apply a synthesis bound to two previously synthesized arguments. The combining construction can use several gates and can reuse either argument.

        theorem Cslib.Circuits.Synthesis.foldr {σ : Signature} {U : Type u} {n : } {ι : Type w} {I : Interpretation σ U} {s : Set ((Fin nU)U)} {a : } (op : UUU) (combineCost : ) (hop : ∀ (f g : (Fin nU)U), Synthesis I {f, g} {fun (x : Fin nU) => op (f x) (g x)} combineCost) (indices : List ι) (f : ι(Fin nU)U) (cost : ι) (seed : (Fin nU)U) (hseed : Synthesis I s {seed} a) (h : iindices, Synthesis I s {f i} (cost i)) :
        Synthesis I s {fun (x : Fin nU) => List.foldr (fun (i : ι) (acc : U) => op (f i x) acc) (seed x) indices} ((List.map (fun (i : ι) => cost i + combineCost) indices).sum + a)

        Fold an ordered list of synthesized functions. No algebraic laws are needed for the combining operation. The seed and the combining construction have their own gate budgets.

        theorem Cslib.Circuits.Synthesis.finset_fold {σ : Signature} {U : Type u} {n : } {ι : Type w} {I : Interpretation σ U} {s : Set ((Fin nU)U)} {a : } (op : UUU) [Std.Commutative op] [Std.Associative op] (combineCost : ) (hop : ∀ (f g : (Fin nU)U), Synthesis I {f, g} {fun (x : Fin nU) => op (f x) (g x)} combineCost) (indices : Finset ι) (f : ι(Fin nU)U) (cost : ι) (seed : (Fin nU)U) (hseed : Synthesis I s {seed} a) (h : iindices, Synthesis I s {f i} (cost i)) :
        Synthesis I s {fun (x : Fin nU) => Finset.fold op (seed x) (fun (i : ι) => f i x) indices} (iindices, (cost i + combineCost) + a)

        Fold a finite set of synthesized functions with a commutative associative operation. The seed need not be an identity or a constant, and the combining construction may use several gates.

        theorem Cslib.Circuits.Synthesis.exists_circuit_family {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {m cost : } {f : Fin m(Fin nU)U} (h : Synthesis I (inputs n) (Set.range f) cost) :
        gcost, ∃ (c : Circuit σ n g m), ∀ (x : Fin nU) (j : Fin m), c.eval I x j = f j x

        Select a finite family of outputs from a synthesis bound. Selecting outputs, including repeated outputs or an empty family, requires no additional gates.

        theorem Cslib.Circuits.Synthesis.exists_circuit {σ : Signature} {U : Type u} {n : } {I : Interpretation σ U} {f : (Fin nU)U} {cost : } (h : Synthesis I (inputs n) {f} cost) :
        gcost, ∃ (c : Circuit σ n g 1), c.Computes I f

        Extract a single-output circuit from a synthesis bound on the input projections.