Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Probabilistic.ExpectedTime

Expected running time of fair-coin machines #

The running time T_{M,x} of a closed fair-coin machine M on an input x is the number of steps after which it first halts, a random variable over its coins Arora and Barak, Section 7.3. Its expectation is the tail sum E[T_{M,x}] = ∑ₜ Pr[T_{M,x} > t], and T_{M,x} > t exactly when the closed run with clock t has not halted. Turing.MultiTapePTM.expectedTime is this tail sum, valued in ℝ≥0∞, so it is total and equals ⊤ when the machine does not halt almost surely or its running time has infinite expectation. This is the convention of Cslib.WordRAM.expectedTime.

Halting is absorbing, so the probability of still running after t steps decreases with t, and the probability of having halted in any given set of halted configurations increases with t. Hence Markov's inequality takes the form (t + 1) * Pr[T_{M,x} > t] ≤ E[T_{M,x}]. A finite expectation also means that every finite coin prefix has an extension on which the machine halts: otherwise the run would keep running on a set of coin sequences of positive probability.

Main definitions #

Main results #

References #

noncomputable def Turing.MultiTapePTM.expectedTime {k : ℕ} {Symbol State : Type} (machine : MultiTapePTM k Symbol State) (input : List Symbol) :

The expected running time of machine on input under fair coins: the tail sum over t of the probability that the closed run has not halted after t steps Arora and Barak, Section 7.3. It is ⊤ when the expectation is infinite.

theorem Turing.MultiTapePTM.eval_runClosedConfigFrom_add {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (t m : ℕ) (cfg : MultiTapeMachine.Config k Symbol State Empty input) :
(machine.runClosedConfigFrom (t + m) cfg).eval = (machine.runClosedConfigFrom t cfg).eval.bind fun (mid : MultiTapeMachine.Config k Symbol State Empty input) => (machine.runClosedConfigFrom m mid).eval

Running t + m steps runs t steps and then m more.

theorem Turing.MultiTapePTM.eval_runClosedConfigFrom_of_halted {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (m : ℕ) (cfg : MultiTapeMachine.Config k Symbol State Empty input) (h : cfg.tapes.state = none) :
(machine.runClosedConfigFrom m cfg).eval = PMF.pure cfg

A halted configuration stays where it is.

theorem Turing.MultiTapePTM.toOuterMeasure_running_antitone {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (cfg : MultiTapeMachine.Config k Symbol State Empty input) :
Antitone fun (t : ℕ) => (machine.runClosedConfigFrom t cfg).eval.toOuterMeasure {final : MultiTapeMachine.Config k Symbol State Empty input | final.tapes.state.isSome = true}

The probability of still running decreases with the clock.

theorem Turing.MultiTapePTM.toOuterMeasure_halted_monotone {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (cfg : MultiTapeMachine.Config k Symbol State Empty input) {S : Set (MultiTapeMachine.Config k Symbol State Empty input)} (hS : ∀ final ∈ S, final.tapes.state = none) :
Monotone fun (t : ℕ) => (machine.runClosedConfigFrom t cfg).eval.toOuterMeasure S

The probability of having halted in a set of halted configurations increases with the clock: halted configurations stay.

theorem Turing.MultiTapePTM.toOuterMeasure_compl_antitone {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (cfg : MultiTapeMachine.Config k Symbol State Empty input) {good : Set (MultiTapeMachine.Config k Symbol State Empty input)} (hgood : ∀ c ∈ good, c.tapes.state = none) :
Antitone fun (t : ℕ) => (machine.runClosedConfigFrom t cfg).eval.toOuterMeasure goodᶜ

The miss probability decreases with the clock: the probability of not yet being in a set of halted configurations is the complement of an increasing probability.

theorem Turing.MultiTapePTM.expectedTime_le_tsum_toOuterMeasure_compl {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) {good : Set (MultiTapeMachine.Config k Symbol State Empty input)} (hgood : ∀ c ∈ good, c.tapes.state = none) :

The expected running time is at most the sum of the miss probabilities of any set of halted configurations.

theorem Turing.MultiTapePTM.mul_toOuterMeasure_running_le_expectedTime {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (t : ℕ) :
(↑t + 1) * (machine.runClosedConfigFrom t (MultiTapeMachine.initialConfig machine input)).eval.toOuterMeasure {final : MultiTapeMachine.Config k Symbol State Empty input | final.tapes.state.isSome = true} ≤ machine.expectedTime input

Markov's inequality for the running time: the run is still going after t steps with probability at most E[T] / (t + 1).

theorem Turing.MultiTapePTM.expectedTime_le_of_halted {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) {T : ℕ} (h : ∀ final ∈ (machine.runClosedConfigFrom T (MultiTapeMachine.initialConfig machine input)).eval.support, final.tapes.state = none) :
machine.expectedTime input ≤ ↑T

Halting within a clock bounds the expected running time: if every run has halted after T steps, the expected running time is at most T.

theorem Turing.MultiTapePTM.toOuterMeasure_running_eq_card {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (t : ℕ) :

The probability of still running as a count: the fraction of the 2 ^ t coin strings of length t whose replay has not halted.

theorem Turing.MultiTapePTM.tapes_runClosedConfigFromCoins_of_halted {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (coins : List Bool) (cfg : MultiTapeMachine.Config k Symbol State Empty input) (h : cfg.tapes.state = none) :
(machine.runClosedConfigFromCoins coins cfg).tapes = cfg.tapes

Replaying coins from a halted configuration leaves its tapes unchanged.

theorem Turing.MultiTapePTM.output_isPrefix_append {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (coins more : List Bool) (cfg : MultiTapeMachine.Config k Symbol State Empty input) :
(machine.runClosedConfigFromCoins coins cfg).tapes.output <+: (machine.runClosedConfigFromCoins (coins ++ more) cfg).tapes.output

Outputs only grow: replaying more coins extends the output of a replay.

theorem Turing.MultiTapePTM.exists_halted_append_of_expectedTime_ne_top {k : ℕ} {Symbol State : Type} {input : List Symbol} (machine : MultiTapePTM k Symbol State) (h : machine.expectedTime input ≠ ⊤) (coins : List Bool) :
∃ (more : List Bool), (machine.runClosedConfigFromCoins (coins ++ more) (MultiTapeMachine.initialConfig machine input)).tapes.state = none

With finite expected running time, every coin prefix extends to a halting run: some extension of the prefix is a coin string on which the replay has halted. Otherwise every run extending the prefix would keep running, with probability at least that of the prefix at every clock, and the tail sum would be infinite.