From De Morgan circuits to programs with shared gates #
The fan-out of a gate of a circuit is the number of argument slots of gates that read it plus
the number of designated outputs equal to it (gateFanOut), and sharedGateCount counts the
gates of fan-out at least two. Every single-output circuit over the De Morgan basis computing
f yields a SharedProgram computing f with at most sharedGateCount c shared gates and at
most as many AND and OR gates as the circuit (exists_sharedProgram_of_circuit); NOT,
identity, and constant gates are free, as in DeMorgan.binaryCost.
The program is built from the last gate down. Its variables are all wires of the circuit, so
the initial program outputs the literal of the output wire. A gate of fan-out at least two
becomes a shared gate computing its formula, and its wire is then exactly the new shared
variable (SharedProgram.share). Any other gate is substituted into the program
(SharedProgram.substVar); since its variable occurs at most once, this adds the gate's own
cost and keeps every earlier gate occurring at most as often as its fan-out.
Consequently Khrapchenko's bound with shared gates holds for the library's De Morgan circuits:
a circuit computing the parity of n ≥ 1 bits in which at most k gates have fan-out at least
two has n² ≤ (k + 1) · (cost + k + 1), where cost counts the AND and OR gates
(parity_sq_le_cost). It has at least C · n AND and OR gates when (k + 1) · (C + 1) ≤ n
(mul_le_cost_of_parity), and a family of such circuits with k(n) = o(n) gates of fan-out at
least two has superlinear cost (isLittleO_cost_of_parity). Analogous quadratic and superlinear
bounds hold for threshold and majority circuits (threshold_mul_le_cost, majority_mul_le_cost,
majority_sq_le_cost_of_odd, mul_le_cost_of_majority, isLittleO_cost_of_majority).
Fan-out of circuit gates #
The number of argument slots of the program's gates that read gate g. The last gate is
read by no gate of the program; an earlier gate is read by the gates before the last one and
by the arguments of the last gate that are equal to it.
Equations
- Algebraic.KW.slotUses Cslib.Circuits.Program.empty = Fin.elim0
- Algebraic.KW.slotUses (p.gate line) = fun (i : Fin (gateCount + 1)) => Fin.lastCases 0 (fun (g : Fin gateCount) => Algebraic.KW.slotUses p g + Algebraic.KW.argUses line g) i
Instances For
The fan-out of gate g of a circuit: the number of argument slots of gates that read g
plus the number of designated outputs equal to g.
Equations
- Algebraic.KW.gateFanOut c g = Algebraic.KW.slotUses c.program g + {o : Fin m | c.outputs o = Cslib.Circuits.Wire.gate g}.card
Instances For
Occurrences and substitution of a variable #
Insert the value b at position N of y, moving the later entries up by one.
Equations
Instances For
The number of literal leaves on the variable with index v.
Equations
- Algebraic.KW.Formula.occ v (Algebraic.KW.Formula.lit i positive) = if ↑i = v then 1 else 0
- Algebraic.KW.Formula.occ v (Algebraic.KW.Formula.const value) = 0
- Algebraic.KW.Formula.occ v (l.and r) = Algebraic.KW.Formula.occ v l + Algebraic.KW.Formula.occ v r
- Algebraic.KW.Formula.occ v (l.or r) = Algebraic.KW.Formula.occ v l + Algebraic.KW.Formula.occ v r
Instances For
The substitution behind SharedProgram.substVar: the variable N becomes φ, the
variables below N are kept, and those above N move down by one.
Equations
- φ.substVarMap d i = if h : ↑i < N then Algebraic.KW.Formula.lit ⟨↑i, ⋯⟩ true else if h' : ↑i = N then Algebraic.KW.Formula.mapIndex (Fin.castLE ⋯) φ else Algebraic.KW.Formula.lit ⟨↑i - 1, ⋯⟩ true
Instances For
De Morgan gates as formulas #
The formula of one De Morgan gate over the earlier wires, numbered by Wire.index.
Equations
- One or more equations did not get rendered due to their size.
- Algebraic.KW.lineFormula { op := Algebraic.DeMorgan.Op.false, wires := wires } = Algebraic.KW.Formula.const false
- Algebraic.KW.lineFormula { op := Algebraic.DeMorgan.Op.true, wires := wires } = Algebraic.KW.Formula.const true
- Algebraic.KW.lineFormula { op := Algebraic.DeMorgan.Op.id, wires := w } = Algebraic.KW.Formula.lit (w ⟨0, Algebraic.KW.lineFormula._proof_3⟩).index true
- Algebraic.KW.lineFormula { op := Algebraic.DeMorgan.Op.not, wires := w } = Algebraic.KW.Formula.lit (w ⟨0, Algebraic.KW.lineFormula._proof_4⟩).index false
Instances For
The values of the inputs and gates of a De Morgan program, numbered by Wire.index.
Equations
Instances For
From circuits to programs #
Parity #
Parity in De Morgan circuits with few shared gates. If a De Morgan circuit computes the
parity of n ≥ 1 bits and at most k of its gates have fan-out at least two, then
n² ≤ (k + 1) · (cost + k + 1), where cost counts its AND and OR gates; so it has at least
n² / (k + 1) - (k + 1) AND and OR gates.
Superlinear cost for parity with few shared gates. If (k + 1) · (C + 1) ≤ n, every
De Morgan circuit computing the parity of n bits in which at most k gates have fan-out at
least two has at least C · n AND and OR gates.
Parity needs superlinear De Morgan circuits when o(n) gates have fan-out at least
two. If k n = o(n) and, for every n, c n is a De Morgan circuit computing the parity of
n bits in which at most k n gates have fan-out at least two, then the number of AND and OR
gates of c n grows faster than n.
Threshold and majority #
Single-output circuit target for the t-threshold function on n bits.
Equations
- Algebraic.KW.thresholdTarget n t x x✝ = Algebraic.KW.threshold t x
Instances For
Single-output circuit target for the strict majority function on n bits.
Equations
Instances For
Threshold functions in De Morgan circuits with few shared gates. For 1 ≤ t ≤ n, every
De Morgan circuit computing threshold t in which at most k gates have fan-out at least two
satisfies (n + 1 - t) · t ≤ (k + 1) · (cost + k + 1), where cost counts its AND and OR
gates.
Majority in De Morgan circuits with few shared gates. Every De Morgan circuit computing
strict majority of n ≥ 1 bits in which at most k gates have fan-out at least two satisfies
(n - ⌊n/2⌋) · (⌊n/2⌋ + 1) ≤ (k + 1) · (cost + k + 1), where cost counts its AND and OR
gates.
Odd-input majority in De Morgan circuits with few shared gates. For odd n, every
De Morgan circuit computing strict majority of n bits in which at most k gates have fan-out
at least two satisfies (⌊n/2⌋ + 1)² ≤ (k + 1) · (cost + k + 1).
Superlinear cost for majority with few shared gates. If (k + 1) · (C + 1) ≤ m,
every De Morgan circuit computing the majority of 2 * m + 1 bits in which at most k gates have
fan-out at least two has at least C · m AND and OR gates.
Majority needs superlinear De Morgan circuits when o(m) gates have fan-out at least
two. If k m = o(m) and, for every m, c m is a De Morgan circuit computing the
majority of 2 * m + 1 bits in which at most k m gates have fan-out at least two, then the
number of AND and OR gates of c m grows faster than m.