Documentation

CslibFrontier.Computability.Complexity.Classes.LogSpace.Randomized

Randomized logarithmic space #

A fair-coin machine (Turing.MultiTapePTM) reads each coin once, in order, so its randomness is read-once. Its nondeterministic view (Turing.MultiTapePTM.toNTM) takes either coin at every step; space is measured there, exactly as for Cslib.Complexity.NL. Every branch must halt: on every encoded instance some number of steps t bounds every computation path. No clock is part of the definition.

The acceptance probability on input is acceptCoins input t / 2 ^ t, where Turing.MultiTapePTM.acceptCoins counts the coin strings of length t whose replay ends halted with output [true]. Once every branch halts within t steps, this fraction no longer depends on t (Turing.MultiTapePTM.acceptCoins_succ), so the classes quantify over one such t per instance.

The threshold 1/2 for RL can be raised to 1 - 2 ^ (-r) for any fixed r by repetition (Cslib.Complexity.mem_RL_iff_error_le), which also gives Cslib.Complexity.RL_subset_BPL. The acceptance probability is an entry of a power or inverse of a polynomial-size configuration matrix (Cslib.Complexity.exists_configMatrix_of_mem_BPL).

The model follows the decision recorded in issue #474: one-way coins, halting on every branch with the polynomial clock a derived lemma, acceptance by counting coin strings, and space as for NL Arora and Barak, Section 7.7.

Main definitions #

Main results #

References #

noncomputable def Turing.MultiTapePTM.acceptCoins {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (t : ℕ) :

The number of coin strings of length t whose replay from the initial configuration on input ends halted with output [true].

theorem Turing.MultiTapePTM.acceptCoins_le {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (t : ℕ) :
machine.acceptCoins input t ≤ 2 ^ t

At most all coin strings are accepted.

theorem Turing.MultiTapePTM.halted_stepCoins {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {input : List Bool} {t : ℕ} (ht : machine.toNTM.RunsInTime input t) {coins : List Bool} (hlen : t ≤ coins.length) :
(machine.stepCoins coins (machine.toNTM.initCfg input)).Halted

Under a time bound t, every replay of t or more coins ends halted.

theorem Turing.MultiTapePTM.acceptCoins_succ {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {input : List Bool} {t : ℕ} (ht : machine.toNTM.RunsInTime input t) :
machine.acceptCoins input (t + 1) = 2 * machine.acceptCoins input t

One more coin doubles the count once every branch halts within t steps: the last coin of a string of length t + 1 is read by a halted configuration and ignored.

theorem Turing.MultiTapePTM.acceptCoins_add {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {input : List Bool} {t : ℕ} (ht : machine.toNTM.RunsInTime input t) (m : ℕ) :
machine.acceptCoins input (t + m) = 2 ^ m * machine.acceptCoins input t

Once every branch halts within t steps, the count scales with the number of extra coins.

theorem Turing.MultiTapePTM.acceptCoins_mul_two_pow {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {input : List Bool} {t t' : ℕ} (ht : machine.toNTM.RunsInTime input t) (ht' : machine.toNTM.RunsInTime input t') :
machine.acceptCoins input t' * 2 ^ t = machine.acceptCoins input t * 2 ^ t'

The acceptance probability does not depend on the clock: for two halting times t and t', acceptCoins input t / 2 ^ t = acceptCoins input t' / 2 ^ t'.

theorem Turing.MultiTapePTM.two_pow_mul_le_iff {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {input : List Bool} {t t' : ℕ} (ht : machine.toNTM.RunsInTime input t) (ht' : machine.toNTM.RunsInTime input t') (x y : ℕ) :
x * 2 ^ t ≤ y * machine.acceptCoins input t ↔ x * 2 ^ t' ≤ y * machine.acceptCoins input t'

A lower bound x / y on the acceptance probability holds at one halting time exactly when it holds at another.

theorem Turing.MultiTapePTM.mul_le_two_pow_iff {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {input : List Bool} {t t' : ℕ} (ht : machine.toNTM.RunsInTime input t) (ht' : machine.toNTM.RunsInTime input t') (x y : ℕ) :
y * machine.acceptCoins input t ≤ x * 2 ^ t ↔ y * machine.acceptCoins input t' ≤ x * 2 ^ t'

An upper bound x / y on the acceptance probability holds at one halting time exactly when it holds at another.

theorem Turing.MultiTapePTM.accepts_toNTM_iff {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {input : List Bool} {t : ℕ} (ht : machine.toNTM.RunsInTime input t) :
machine.toNTM.Accepts input ↔ 0 < machine.acceptCoins input t

Acceptance of the nondeterministic view is acceptance by some coin string of a halting length.

Deterministic machines #

The nondeterministic view of a deterministic machine run as a fair-coin machine is the deterministic machine itself.

theorem Turing.MultiTapePTM.stepCoins_ofDeterministic {k : ℕ} {State : Type} (tm : MultiTapeTM k Bool State) (input coins : List Bool) :

A deterministic machine ignores its coins: every replay of n coins is its run of n steps.

theorem Turing.MultiTapePTM.acceptCoins_ofDeterministic {k : ℕ} {State : Type} (tm : MultiTapeTM k Bool State) (input : List Bool) (t : ℕ) :

A deterministic machine accepts all coin strings of length t or none.

The polynomial clock #

structure Turing.MultiTapePTM.RunsInLogSpace {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {α : Type} (enc : α ↪ List Bool) (c d : ℕ) :

A logarithmic-space fair-coin machine with a polynomial clock: on every encoded instance enc a of length n, every branch visits at most c * (Nat.log2 n + 1) work-tape cells and halts within Turing.polyClock d n steps.

theorem Turing.MultiTapePTM.exists_runsInLogSpace {k : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) [Finite State] {α : Type} {enc : α ↪ List Bool} {c : ℕ} (hs : ∀ (a : α), machine.toNTM.RunsInSpace (enc a) (c * ((enc a).length.log2 + 1))) (ht : ∀ (a : α), ∃ (t : ℕ), machine.toNTM.RunsInTime (enc a) t) :
∃ (d : ℕ), machine.RunsInLogSpace enc c d

Halting on every branch gives the polynomial clock: a machine that stays within logarithmic space and halts on every branch of every encoded instance halts within Turing.polyClock d n steps, for one exponent d.

def Cslib.Complexity.RL {α : Type} (enc : α ↪ List Bool) :
Set (Set α)

Randomized logarithmic space with one-sided error Arora and Barak, Section 7.7: some fair-coin machine with finitely many states, on every encoded instance enc a of length n, visits at most c * (Nat.log2 n + 1) work-tape cells on every branch, halts on every branch within some number of steps t, accepts members on at least half of the coin strings of length t, and accepts non-members on none.

def Cslib.Complexity.BPL {α : Type} (enc : α ↪ List Bool) :
Set (Set α)

Randomized logarithmic space with bounded two-sided error Arora and Barak, Section 7.7: as for Cslib.Complexity.RL, but members are accepted on at least two thirds of the coin strings and non-members on at most one third.

theorem Cslib.Complexity.RL_subset_NL {α : Type} {enc : α ↪ List Bool} :
RL enc ⊆ NL enc

Randomized logspace with one-sided error is within NL: the nondeterministic view of an RL machine accepts exactly the members, since members have an accepting coin string and non-members none.

theorem Cslib.Complexity.exists_polyClock_of_mem_RL {α : Type} {enc : α ↪ List Bool} {A : Set α} (h : A ∈ RL enc) :
∃ (k : ℕ) (State : Type) (_ : Finite State) (M : Turing.MultiTapePTM k Bool State) (c : ℕ) (d : ℕ), M.RunsInLogSpace enc c d ∧ ∀ (a : α), (a ∈ A → 2 ^ Turing.polyClock d (enc a).length ≤ 2 * M.acceptCoins (enc a) (Turing.polyClock d (enc a).length)) ∧ (a ∉ A → M.acceptCoins (enc a) (Turing.polyClock d (enc a).length) = 0)

RL has a polynomial clock: an RL machine, which only promises to halt on every branch, halts within polyClock d n steps (Turing.MultiTapePTM.RunsInLogSpace), and the acceptance bounds hold at that clock.

theorem Cslib.Complexity.exists_polyClock_of_mem_BPL {α : Type} {enc : α ↪ List Bool} {A : Set α} (h : A ∈ BPL enc) :
∃ (k : ℕ) (State : Type) (_ : Finite State) (M : Turing.MultiTapePTM k Bool State) (c : ℕ) (d : ℕ), M.RunsInLogSpace enc c d ∧ ∀ (a : α), (a ∈ A → 2 * 2 ^ Turing.polyClock d (enc a).length ≤ 3 * M.acceptCoins (enc a) (Turing.polyClock d (enc a).length)) ∧ (a ∉ A → 3 * M.acceptCoins (enc a) (Turing.polyClock d (enc a).length) ≤ 2 ^ Turing.polyClock d (enc a).length)

BPL has a polynomial clock: a BPL machine, which only promises to halt on every branch, halts within polyClock d n steps (Turing.MultiTapePTM.RunsInLogSpace), and the acceptance bounds hold at that clock.

theorem Cslib.Complexity.L_subset_RL {α : Type} {enc : α ↪ List Bool} :
L enc ⊆ RL enc

Deterministic logarithmic space is within RL: a logspace decider ignores its coins.

theorem Cslib.Complexity.L_subset_BPL {α : Type} {enc : α ↪ List Bool} :
L enc ⊆ BPL enc

Deterministic logarithmic space is within BPL: a logspace decider ignores its coins.