Documentation

CslibFrontier.Computability.Circuit.Boolean.Substitution

Substituting variables and constants for inputs #

A substitution ρ : Fin N → Fin n ⊕ Bool feeds every input of a Boolean function of N variables from one of n new variables or from a constant; several inputs may receive the same variable, so this is a projection in Valiant's sense rather than a restriction, which would leave the remaining inputs free. A substitution does not make a function harder to compute: a circuit for f with its inputs rewired, and two gates for the constants, computes f ∘ ρ.

The substitution appendInputs r fixes the last p inputs of a function of n + p variables to the bits r: substituting it computes x ↦ f (Fin.append x r); prependInputs r fixes the first p inputs instead. A restriction (partial assignment) is the substitution that replaces each bit by itself or by a constant (BitString.PartialAssignment.substitute_toSubstitution).

Fixing inputs that a target function ignores keeps the agreement on average: if g agrees with a function of its first n inputs on a δ fraction of all inputs, then for some fixing of the other inputs the resulting function, two gates larger, agrees with it on a δ fraction of the inputs (Cslib.Circuits.Boolean.exists_complexity_le_of_agree_prefix).

Fixing a prefix u of the input of a language L, and reading only the first P of Q new inputs, gives a function r ↦ [u ++ (first P bits of r) ∈ L] at most two gates larger than the slice of L at length |u| + P (Cslib.Circuits.Boolean.complexity_le_of_append_take). This is the circuit of a verifier with its instance hardwired, used in derandomization. When the slices of L have circuits of size C (N + 1) ^ d and the prefix is polynomially long, so do the hardwired slices (Cslib.Circuits.Boolean.complexity_slice_le_of_prefix_of_le).

The substitution padInputs m n feeds the first m of n inputs from m variables and the others with false; it shows that extending a function by ignored inputs does not make it easier (Cslib.Circuits.Boolean.complexity_le_extend).

Main definitions #

Main results #

def Cslib.Circuits.Boolean.substitute {n N : ℕ} (ρ : Fin N → Fin n ⊕ Bool) (x : Fin n → Bool) :
Fin N → Bool

The inputs of a function of N variables fed by ρ from the variables x: input j is x i when ρ j = .inl i, and the constant b when ρ j = .inr b.

@[simp]
theorem Cslib.Circuits.Boolean.substitute_inl {n N : ℕ} {ρ : Fin N → Fin n ⊕ Bool} {x : Fin n → Bool} {j : Fin N} {i : Fin n} (h : ρ j = Sum.inl i) :
substitute ρ x j = x i

At an input mapped by ρ to variable .inl i, substitute ρ x evaluates to x i.

@[simp]
theorem Cslib.Circuits.Boolean.substitute_inr {n N : ℕ} {ρ : Fin N → Fin n ⊕ Bool} {x : Fin n → Bool} {j : Fin N} {b : Bool} (h : ρ j = Sum.inr b) :
substitute ρ x j = b

At an input mapped by ρ to constant .inr b, substitute ρ x evaluates to b.

theorem Cslib.Circuits.Boolean.substitute_bind {n N M : ℕ} (σ : Fin N → Fin M ⊕ Bool) (τ : Fin M → Fin n ⊕ Bool) (x : Fin n → Bool) :
substitute (fun (j : Fin N) => Sum.elim τ Sum.inr (σ j)) x = substitute σ (substitute τ x)

Substituting along a composite of substitutions: first τ, then σ.

The output of a two-output constant circuit that carries the constant b: false is output 0 and true is output 1.

def Cslib.Circuits.Boolean.projectionCircuit {σ : Signature} {n N : ℕ} (K : Circuit σ n 2) (ρ : Fin N → Fin n ⊕ Bool) :
Circuit σ n N

A projection from a bank of two constants. Over any basis, K is a circuit whose outputs 0 and 1 are the constants false and true; the projection circuit appends the outputs of K to the live inputs and wires output j from input i when ρ j = .inl i, and from the output of K carrying b when ρ j = .inr b. Gates exist only in K: it costs exactly what K costs, and adds no depth beyond that of K.

theorem Cslib.Circuits.Boolean.eval_projectionCircuit {σ : Signature} {n N : ℕ} (K : Circuit σ n 2) (ρ : Fin N → Fin n ⊕ Bool) {I : Interpretation σ Bool} (hK : ∀ (x : BitString n) (b : Bool), K.eval I x (constIndex b) = b) (x : BitString n) :

If K carries the constants, the projection circuit evaluates substitute ρ.

theorem Cslib.Circuits.Boolean.cost_program_projectionCircuit {σ : Signature} {n N : ℕ} (K : Circuit σ n 2) (ρ : Fin N → Fin n ⊕ Bool) (cost : σ.Op → ℕ) :

A projection circuit costs what its constant bank costs.

theorem Cslib.Circuits.Boolean.size_projectionCircuit {σ : Signature} {n N : ℕ} (K : Circuit σ n 2) (ρ : Fin N → Fin n ⊕ Bool) :

A projection circuit has as many gates as its constant bank.

A projection circuit is no deeper than its constant bank.

Implement a substitution using one shared gate for each Boolean constant. Both gates are included even when unused or when the output is empty.

@[simp]

The shared-constant circuit implements its input substitution.

Substitution charges each of the two shared constant gates once.

@[simp]

The substitution circuit has exactly two gates, regardless of the output width.

The shared-constant substitution circuit has depth at most one.

A substitution costs at most two gates, one for each constant.

Substitutions do not make functions harder. Feeding the inputs of f from variables and constants costs at most two more gates than f.

def Cslib.Circuits.Boolean.appendInputs {n p : ℕ} (r : Fin p → Bool) :
Fin (n + p) → Fin n ⊕ Bool

The substitution fixing the last p inputs of a function of n + p variables to r.

@[simp]

Substituting appendInputs r on x appends r after x.

def Cslib.Circuits.Boolean.prependInputs {n p : ℕ} (r : Fin p → Bool) :
Fin (p + n) → Fin n ⊕ Bool

The substitution fixing the first p inputs of a function of p + n variables to r.

@[simp]

Substituting prependInputs r on x prepends r before x.

Hardwiring a prefix. Let f on Q inputs test whether u followed by the first P ≤ Q bits of its input lies in L. Then f costs at most two gates more than the slice of L at length u.length + P.

theorem Cslib.Circuits.Boolean.complexity_slice_le_of_prefix_of_le {L M : Language Bool} (pre : List Bool) {n C d a K : ℕ} (h : ∀ (x : List Bool), x.length = n → (x ∈ L ↔ pre ++ x ∈ M)) (hM : ∀ (N : ℕ), complexity interpretation (single (M.slice N)) ≤ C * (N + 1) ^ d) (hpre : pre.length + n + 1 ≤ a * (n + 1) ^ K) :
complexity interpretation (single (L.slice n)) ≤ (C * a ^ d + 2) * (n + 1) ^ (K * d)

Hardwiring a polynomially long prefix. If x ∈ L exactly when pre ++ x ∈ M for the words of length n, the slices of M have circuits of size C (N + 1) ^ d, and |pre| + n + 1 ≤ a (n + 1) ^ K, then the slice of L at length n has circuits of size (C a ^ d + 2) (n + 1) ^ (K d).

The substitution feeding the first m of n inputs from m variables and the others with false.

For m ≤ n, the first m substituted inputs of padInputs m n are the variables.

theorem Cslib.Circuits.Boolean.complexity_le_extend {n N : ℕ} (hle : n ≤ N) (f : BooleanFunction n) :
complexity interpretation (single f) ≤ complexity interpretation (single fun (y : Fin N → Bool) => f fun (i : Fin n) => y (Fin.castLE hle i)) + 2

Ignored inputs do not make a function easier. A function f of n ≤ N variables costs at most two gates more than its extension to N inputs that reads the first n.

theorem Cslib.Circuits.Boolean.exists_complexity_le_of_agree_prefix {n N : ℕ} (hle : n ≤ N) (E : BooleanFunction n) (g : BooleanFunction N) {δ : ℝ} (hagree : δ * 2 ^ N < ↑{y : BitString N | g y = E fun (i : Fin n) => y (Fin.castLE hle i)}.card) :
∃ (C : BooleanFunction n), complexity interpretation (single C) ≤ complexity interpretation (single g) + 2 ∧ δ * 2 ^ n < ↑{x : BitString n | C x = E x}.card

Fixing ignored inputs. If g on N inputs agrees with a function E of its first n inputs on more than δ * 2 ^ N inputs, then fixing the other N - n inputs suitably (appendInputs) gives a function on n inputs, of complexity at most two more, that agrees with E on more than δ * 2 ^ n inputs: some fixing does at least as well as the average.

The substitution replacing each fixed bit by its value and each free bit by itself.

Restricting is substituting constants for the fixed bits.