Documentation

CslibFrontier.Computability.Circuit.Boolean.Lookup

Lookup tables and local maps #

Two size bounds for multi-output Boolean functions, used when a circuit reads a hard-wired table.

A lookup table is an arbitrary map D from a index bits to r output bits. One shared decoder computes the 2 ^ a minterms of the index, with 2 a + 1 gates each, and every output bit is the disjunction of the minterms of the indices where it is set. So D costs at most 2 ^ a * (2 a + 1) + r * (2 ^ a + 1) gates (complexity_le_lookup): linear in the number of table entries times the index and output widths, instead of r separate truth tables.

A local map is one where every output bit depends on at most t inputs. Each output then costs at most the truth-table bound on t inputs, so the whole map costs at most r * (2 ^ t * (2 t + 3) + 1) gates (complexity_le_mul_of_forall_dependsOn); for constant t this is linear in the number of outputs.

A selected answer reads one of q answer bits z, chosen by the inputs in a set s. Disjoining one minterm conjoined with its selected answer wire for each assignment of s costs at most 2 ^ #s * (2 #s + 3) + 1 gates whatever q is (complexity_select_le). Learners use this to read the answers to their queries from input wires.

Main results #

theorem Cslib.Circuits.Boolean.complexity_le_lookup {a r : ℕ} (D : (Fin a → Bool) → Fin r → Bool) :
complexity interpretation D ≤ 2 ^ a * (2 * a + 1) + r * (2 ^ a + 1)

Lookup tables. Any map from a index bits to r output bits costs at most 2 ^ a * (2 * a + 1) + r * (2 ^ a + 1) gates: a shared decoder computes every minterm of the index, and each output bit is the disjunction of the minterms of the indices where it is set.

theorem Cslib.Circuits.Boolean.complexity_le_mul_of_forall_dependsOn {n r t : ℕ} (f : (Fin n → Bool) → Fin r → Bool) (hf : ∀ (j : Fin r), ∃ (s : Finset (Fin n)), s.card ≤ t ∧ DependsOn (fun (x : Fin n → Bool) => f x j) ↑s) :
complexity interpretation f ≤ r * (2 ^ t * (2 * t + 3) + 1)

Local maps. A map whose r outputs each depend on at most t of its inputs costs at most r * (2 ^ t * (2 * t + 3) + 1) gates: compute each output from its truth table on those inputs.

theorem Cslib.Circuits.Boolean.complexity_select_le {n q : ℕ} (s : Finset (Fin n)) (sel : (↥s → Bool) → Fin q) :
complexity interpretation (single fun (zx : Fin (q + n) → Bool) => zx (Fin.castAdd n (sel fun (i : ↥s) => zx (Fin.natAdd q ↑i)))) ≤ 2 ^ s.card * (2 * s.card + 3) + 1

Reading a selected answer. On inputs z ++ x, returning the answer bit z (sel (x restricted to s)) costs at most 2 ^ #s * (2 * #s + 3) + 1 gates, the bound of complexity_le_of_dependsOn for a function of s alone: one minterm and two gates for each assignment of s. The answer bits z are not part of that count, whereas treating the map as a function of s and all of z would cost 2 ^ (#s + q).