Documentation

CslibFrontier.Foundations.Data.BitString.FunctionTables

Truth tables read from a random string #

A family of Boolean functions f v : BooleanFunction (ℓ v), one for each v : Fin n, can be read from a string of bits laid out in blocks of width B: the table of f v occupies the bits v * B + equivFin y for the inputs y of f v, numbered by BitString.equivFin (BitString.decodeTables). Positions past the end of the string read false, so every list decodes to some family.

When every table fits in its block (2 ^ ℓ v ≤ B) and the blocks fit in the string (n * B ≤ p), decoding a uniformly random string of p bits gives a uniformly random family: each family is decoded from exactly 2 ^ p / 2 ^ (∑ v, 2 ^ ℓ v) strings. In counting form, a set S of families is hit by #S * 2 ^ p / 2 ^ (∑ v, 2 ^ ℓ v) strings (BitString.card_filter_decodeTables_mem_mul). This turns a count of bad families into a count of bad random strings, which is what a randomized reduction that samples functions from its random bits needs.

The proof is the library's count of functions by a property of their restriction along an injection (Nat.card_subtype_comp_injective_mul), applied to the positions of the tables (BitString.tablePos).

Main definitions #

Main results #

def Cslib.BitString.decodeTables {n : ℕ} (B : ℕ) (ℓ : Fin n → ℕ) (r : List Bool) (v : Fin n) :

Truth tables read from a list of bits, in blocks of width B: the table of v is read from the bits v * B + equivFin y, for the inputs y of v's function in the order BitString.equivFin. Missing bits read false, so every list decodes.

@[simp]
theorem Cslib.BitString.decodeTables_apply {n : ℕ} (B : ℕ) (ℓ : Fin n → ℕ) (r : List Bool) (v : Fin n) (y : BitString (ℓ v)) :
decodeTables B ℓ r v y = r.getD (↑v * B + ↑((equivFin (ℓ v)) y)) false

Entry y of the table of v is bit v * B + equivFin y of the list, or false past its end.

def Cslib.BitString.tablePos {n B p : ℕ} {ℓ : Fin n → ℕ} (hℓ : ∀ (v : Fin n), 2 ^ ℓ v ≤ B) (hp : n * B ≤ p) :
(v : Fin n) × BitString (ℓ v) ↪ Fin p

The position of a table entry in the block layout of decodeTables: entry y of the table of v is bit v * B + equivFin y of a string of p bits.

@[simp]
theorem Cslib.BitString.tablePos_apply {n B p : ℕ} {ℓ : Fin n → ℕ} (hℓ : ∀ (v : Fin n), 2 ^ ℓ v ≤ B) (hp : n * B ≤ p) (x : (v : Fin n) × BitString (ℓ v)) :
↑((tablePos hℓ hp) x) = ↑x.fst * B + ↑((equivFin (ℓ x.fst)) x.snd)

Entry y of the table of v sits at position v * B + equivFin y.

theorem Cslib.BitString.decodeTables_ofFn {n B p : ℕ} {ℓ : Fin n → ℕ} (hℓ : ∀ (v : Fin n), 2 ^ ℓ v ≤ B) (hp : n * B ≤ p) (r : Fin p → Bool) :
decodeTables B ℓ (List.ofFn r) = (Equiv.piCurry fun (v : Fin n) (x : BitString (ℓ v)) => Bool) (r ∘ ⇑(tablePos hℓ hp))

Decoding the bits of a string of length p reads them at the positions tablePos.

theorem Cslib.BitString.card_functionTables {n : ℕ} (ℓ : Fin n → ℕ) :
Fintype.card ((v : Fin n) → BooleanFunction (ℓ v)) = 2 ^ ∑ v : Fin n, 2 ^ ℓ v

There are 2 ^ (∑ v, 2 ^ ℓ v) families of truth tables.

theorem Cslib.BitString.card_filter_decodeTables_mem_mul {n B p : ℕ} {ℓ : Fin n → ℕ} (hℓ : ∀ (v : Fin n), 2 ^ ℓ v ≤ B) (hp : n * B ≤ p) (S : Finset ((v : Fin n) → BooleanFunction (ℓ v))) :
{r : Fin p → Bool | decodeTables B ℓ (List.ofFn r) ∈ S}.card * 2 ^ ∑ v : Fin n, 2 ^ ℓ v = S.card * 2 ^ p

Decoding a random string hits a set of families in proportion to its size. If every table fits in a block of width B and the n blocks fit in p bits, the strings r of p bits whose decoding lies in S are a #S / 2 ^ (∑ v, 2 ^ ℓ v) fraction of all 2 ^ p strings.

theorem Cslib.BitString.mul_card_filter_decodeTables_mem_le {n B p a b : ℕ} {ℓ : Fin n → ℕ} (hℓ : ∀ (v : Fin n), 2 ^ ℓ v ≤ B) (hp : n * B ≤ p) {S : Finset ((v : Fin n) → BooleanFunction (ℓ v))} (hS : a * S.card ≤ b * Fintype.card ((v : Fin n) → BooleanFunction (ℓ v))) :
a * {r : Fin p → Bool | decodeTables B ℓ (List.ofFn r) ∈ S}.card ≤ b * 2 ^ p

Rare families are decoded from rare strings. If at most a b / a fraction of the families lie in S, then at most a b / a fraction of the strings of p bits decode into S.