Documentation

CslibFrontier.Computability.Circuit.Boolean.Zhegalkin.Synthesis

Internal weighted circuit synthesis primitives #

Internal CostSynthesis engine and zero-weight binary addition combinators shared by AdditiveBound, BlockCols, Decomposition, Complexity, StageStep, and UpperBound; never re-exported through Zhegalkin.

Main definitions #

Main results #

def Cslib.Circuits.CostSynthesis {σ : Signature} {U : Type u} {n : ℕ} (I : Interpretation σ U) (w : σ.Op → ℕ) (sources targets : Set ((Fin n → U) → U)) (totalCost weightCost : ℕ) :

Simultaneous synthesis tracking both total gate count and an auxiliary per-gate weight w (such as andCost over {⊕, ∧, 1}).

theorem Cslib.Circuits.CostSynthesis.of_subset {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {s t : Set ((Fin n → U) → U)} (h : t ⊆ s) :
CostSynthesis I w s t 0 0
theorem Cslib.Circuits.CostSynthesis.of_mem {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {s : Set ((Fin n → U) → U)} {f : (Fin n → U) → U} (hf : f ∈ s) :
CostSynthesis I w s {f} 0 0
theorem Cslib.Circuits.CostSynthesis.mono {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {s t : Set ((Fin n → U) → U)} {a wa : ℕ} (h : CostSynthesis I w s t a wa) {s' t' : Set ((Fin n → U) → U)} {a' wa' : ℕ} (hs : s ⊆ s') (ht : t' ⊆ t) (ha : a ≤ a') (hwa : wa ≤ wa') :
CostSynthesis I w s' t' a' wa'
theorem Cslib.Circuits.CostSynthesis.comp {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {s t t₁ : Set ((Fin n → U) → U)} {a b wa wb : ℕ} (h : CostSynthesis I w s t a wa) (h' : CostSynthesis I w (s ∪ t) t₁ b wb) :
CostSynthesis I w s (t ∪ t₁) (a + b) (wa + wb)
theorem Cslib.Circuits.CostSynthesis.trans {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {s t t₁ : Set ((Fin n → U) → U)} {a b wa wb : ℕ} (h : CostSynthesis I w s t a wa) (h' : CostSynthesis I w (s ∪ t) t₁ b wb) :
CostSynthesis I w s t₁ (a + b) (wa + wb)
theorem Cslib.Circuits.CostSynthesis.union {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {s t t₁ : Set ((Fin n → U) → U)} {a b wa wb : ℕ} (h : CostSynthesis I w s t a wa) (h' : CostSynthesis I w s t₁ b wb) :
CostSynthesis I w s (t ∪ t₁) (a + b) (wa + wb)
theorem Cslib.Circuits.CostSynthesis.gate {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {s : Set ((Fin n → U) → U)} (op : σ.Op) (args : Fin (σ.Arity op) → (Fin n → U) → U) (hargs : ∀ (i : Fin (σ.Arity op)), args i ∈ s) :
CostSynthesis I w s {fun (x : Fin n → U) => I op fun (i : Fin (σ.Arity op)) => args i x} 1 (w op)
theorem Cslib.Circuits.CostSynthesis.biUnion {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {s : Set ((Fin n → U) → U)} {ι : Type u_1} (indices : Finset ι) (targets : ι → Set ((Fin n → U) → U)) (tc wc : ι → ℕ) (h : ∀ i ∈ indices, CostSynthesis I w s (targets i) (tc i) (wc i)) :
CostSynthesis I w s (⋃ i ∈ indices, targets i) (∑ i ∈ indices, tc i) (∑ i ∈ indices, wc i)
theorem Cslib.Circuits.CostSynthesis.exists_circuit_outputs {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {a wa m : ℕ} {f : Fin m → (Fin n → U) → U} (h : CostSynthesis I w (inputs n) (Set.range f) a wa) :
∃ (c : Circuit σ n m), (c.Computes I fun (x : Fin n → U) (j : Fin m) => f j x) ∧ c.size ≤ a ∧ c.program.cost w ≤ wa
theorem Cslib.Circuits.CostSynthesis.exists_circuit {σ : Signature} {U : Type u} {n : ℕ} {I : Interpretation σ U} {w : σ.Op → ℕ} {a wa : ℕ} {f : (Fin n → U) → U} (h : CostSynthesis I w (inputs n) {f} a wa) :
∃ (c : Circuit σ n 1), c.Computes I (single f) ∧ c.size ≤ a ∧ c.program.cost w ≤ wa

Zero-weight binary addition primitives #

theorem Cslib.Circuits.add_two_of_mem {σ : Signature} {n : ℕ} {G : Type u} [AddCommMonoid G] {I : Interpretation σ G} {w : σ.Op → ℕ} {addOp : σ.Op} (hArity : σ.Arity addOp = 2) (hEval : ∀ (args : Fin (σ.Arity addOp) → G), I addOp args = args ⟨0, ⋯⟩ + args ⟨1, ⋯⟩) (hZeroW : w addOp = 0) {s : Set ((Fin n → G) → G)} {f g : (Fin n → G) → G} (hf : f ∈ s) (hg : g ∈ s) :
CostSynthesis I w s {fun (x : Fin n → G) => f x + g x} 1 0
theorem Cslib.Circuits.nonempty_sum_of_mem {σ : Signature} {n : ℕ} {G : Type u} [AddCommMonoid G] {I : Interpretation σ G} {w : σ.Op → ℕ} {addOp : σ.Op} {ι : Type u_1} (hArity : σ.Arity addOp = 2) (hEval : ∀ (args : Fin (σ.Arity addOp) → G), I addOp args = args ⟨0, ⋯⟩ + args ⟨1, ⋯⟩) (hZeroW : w addOp = 0) {s : Set ((Fin n → G) → G)} (S : Finset ι) (hS : S.Nonempty) (F : ι → (Fin n → G) → G) (hF : ∀ i ∈ S, F i ∈ s) :
CostSynthesis I w s {fun (x : Fin n → G) => ∑ i ∈ S, F i x} (S.card - 1) 0

Summing a nonempty finite family of already-available wires uses #S - 1 binary addition gates and zero weight, with no constant or zero gate needed.

theorem Cslib.Circuits.sum_of_mem_of_zero {σ : Signature} {n : ℕ} {G : Type u} [AddCommMonoid G] {I : Interpretation σ G} {w : σ.Op → ℕ} {addOp : σ.Op} {ι : Type u_1} (hArity : σ.Arity addOp = 2) (hEval : ∀ (args : Fin (σ.Arity addOp) → G), I addOp args = args ⟨0, ⋯⟩ + args ⟨1, ⋯⟩) (hZeroW : w addOp = 0) {s : Set ((Fin n → G) → G)} (hzero : (fun (x : Fin n → G) => 0) ∈ s) (S : Finset ι) (F : ι → (Fin n → G) → G) (hF : ∀ i ∈ S, F i ∈ s) :
CostSynthesis I w s {fun (x : Fin n → G) => ∑ i ∈ S, F i x} (S.card - 1) 0

Summing a finite family when (fun _ => 0) is already available uses at most #S - 1 binary addition gates (in particular 0 gates when #S ≤ 1).

Nonempty subset sums of a block of b wires #

theorem Cslib.Circuits.mul_sub_two_pow_le {b s : ℕ} (hbs : b ≤ s) :
s * (2 ^ b - b - 1) ≤ b * 2 ^ s
theorem Cslib.Circuits.block_nonempty_subSums {σ : Signature} {n : ℕ} {G : Type u} [AddCommMonoid G] {I : Interpretation σ G} {w : σ.Op → ℕ} {addOp : σ.Op} (hArity : σ.Arity addOp = 2) (hEval : ∀ (args : Fin (σ.Arity addOp) → G), I addOp args = args ⟨0, ⋯⟩ + args ⟨1, ⋯⟩) (hZeroW : w addOp = 0) {s : Set ((Fin n → G) → G)} {b : ℕ} (v : Fin b → (Fin n → G) → G) :
(∀ (j : Fin b), v j ∈ s) → CostSynthesis I w s {f : (Fin n → G) → G | ∃ (T : Finset (Fin b)), T.Nonempty ∧ f = fun (x : Fin n → G) => ∑ j ∈ T, v j x} (2 ^ b - b - 1) 0

All 2 ^ b - 1 nonempty subset sums of b available functions cost 2 ^ b - b - 1 binary addition gates (since the b singletons are already available).