Polynomial-time probabilistic Turing machines
Lax115662.ProbabilisticMachines · concepts/Lax115662/ProbabilisticMachines.lean · lax-115662
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
A probabilistic Turing machine has finite control and a finite tape alphabet. At each step an independent fair bit selects one of two transition tables. Each transition moves the tape head one square or writes one symbol. Both tables agree on which configurations are terminal. The input is an ordinary binary word, using the type .
A polynomial-time procedure consists of one such machine, a polynomial , and an output attached to each control state. Every computation on must halt within steps. Halted configurations are left fixed, so we may use exactly random bits, including unused bits after termination. For an output event , its probability is the number of bit strings producing an output in , divided by . All machines and bounds are chosen uniformly, before the input.
Concept map
Lean source view on GitHub
| 1 | import Lax434930.PolynomialTime |
| 2 | import Mathlib.Computability.TuringMachine.PostTuringMachine |
| 3 | import Mathlib.Data.Fintype.Pi |
| 4 | import Mathlib.Data.Rat.Defs |
| 5 | |
| 6 | /-! |
| 7 | --- |
| 8 | title: Polynomial-time probabilistic Turing machines |
| 9 | type: definition |
| 10 | --- |
| 11 | A probabilistic Turing machine has finite control and a finite tape alphabet. |
| 12 | At each step an independent fair bit selects one of two transition tables. |
| 13 | Each transition moves the tape head one square or writes one symbol. Both |
| 14 | tables agree on which configurations are terminal. The input is an ordinary |
| 15 | binary word, using the type `Lax434930.PolynomialTime.Word`. |
| 16 | |
| 17 | A polynomial-time procedure consists of one such machine, a polynomial |
| 18 | , and an output attached to each control state. Every |
| 19 | computation on must halt within steps. Halted configurations are |
| 20 | left fixed, so we may use exactly random bits, including unused bits |
| 21 | after termination. For an output event , its probability is the number |
| 22 | of bit strings producing an output in , divided by . |
| 23 | All machines and bounds are chosen uniformly, before the input. |
| 24 | -/ |
| 25 | |
| 26 | namespace Lax115662.ProbabilisticMachines |
| 27 | |
| 28 | open scoped Classical |
| 29 | |
| 30 | open Lax434930.PolynomialTime Turing |
| 31 | |
| 32 | /-- Two finite local transition tables, with common halting configurations. -/ |
| 33 | structure Machine where |
| 34 | /-- The finite tape alphabet. -/ |
| 35 | Γ : Type |
| 36 | /-- The finite set of control states. -/ |
| 37 | Q : Type |
| 38 | /-- There are finitely many tape symbols. -/ |
| 39 | [alphabet : Fintype Γ] |
| 40 | /-- There are finitely many control states. -/ |
| 41 | [control : Fintype Q] |
| 42 | /-- The distinguished blank tape symbol. -/ |
| 43 | [blank : Inhabited Γ] |
| 44 | /-- The initial control state. -/ |
| 45 | [initial : Inhabited Q] |
| 46 | /-- Represent each binary input symbol as a tape symbol. -/ |
| 47 | input : Bool ↪ Γ |
| 48 | /-- Input symbols are distinct from the blank symbol. -/ |
| 49 | input_ne_blank : ∀ b, input b ≠ default |
| 50 | /-- One transition table for each possible coin outcome. -/ |
| 51 | transition : Bool → TM0.Machine Γ Q |
| 52 | /-- Whether a configuration halts is independent of the next coin. -/ |
| 53 | same_halts : ∀ q a, transition false q a = none ↔ transition true q a = none |
| 54 | |
| 55 | attribute [instance] Machine.alphabet Machine.control Machine.blank Machine.initial |
| 56 | |
| 57 | /-- Perform one coin-selected transition, keeping terminal configurations fixed. -/ |
| 58 | def Machine.advance (M : Machine) (c : TM0.Cfg M.Γ M.Q) (b : Bool) : |
| 59 | TM0.Cfg M.Γ M.Q := |
| 60 | (TM0.step (M.transition b) c).getD c |
| 61 | |
| 62 | /-- Execute a finite sequence of fair coin choices. -/ |
| 63 | def Machine.run (M : Machine) (x coins : Word) : TM0.Cfg M.Γ M.Q := |
| 64 | coins.foldl M.advance (TM0.init (x.map M.input)) |
| 65 | |
| 66 | /-- A uniform procedure with a worst-case polynomial bound on every branch. -/ |
| 67 | structure Procedure (α : Type) where |
| 68 | /-- The machine executing the procedure. -/ |
| 69 | machine : Machine |
| 70 | /-- A polynomial bound on the number of steps on every computation branch. -/ |
| 71 | time : Polynomial ℕ |
| 72 | /-- The answer associated with each terminal control state. -/ |
| 73 | output : machine.Q → α |
| 74 | /-- Every coin sequence of the allowed length reaches a halting configuration. -/ |
| 75 | halts : ∀ (x : Word) (r : Fin (time.eval x.length) → Bool), |
| 76 | TM0.step (machine.transition false) (machine.run x (List.ofFn r)) = none |
| 77 | |
| 78 | /-- The finite sample space of coin sequences on a particular input. -/ |
| 79 | abbrev Procedure.Coins {α : Type} (A : Procedure α) (x : Word) := |
| 80 | Fin (A.time.eval x.length) → Bool |
| 81 | |
| 82 | /-- Read the output from the terminal control state. -/ |
| 83 | def Procedure.eval {α : Type} (A : Procedure α) (x : Word) (r : A.Coins x) : α := |
| 84 | A.output (A.machine.run x (List.ofFn r)).q |
| 85 | |
| 86 | /-- Exact probability under independent uniform bits. -/ |
| 87 | noncomputable def Procedure.probability {α : Type} (A : Procedure α) |
| 88 | (x : Word) (E : α → Prop) : ℚ := |
| 89 | ((Finset.univ.filter (fun r : A.Coins x => E (A.eval x r))).card : ℚ) / |
| 90 | Fintype.card (A.Coins x) |
| 91 | |
| 92 | /-- A Boolean answer correctly decides membership of the given input. -/ |
| 93 | def Correct (L : Language) (x : Word) (b : Bool) : Prop := |
| 94 | (b = true ↔ x ∈ L) |
| 95 | |
| 96 | end Lax115662.ProbabilisticMachines |
| 97 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments