Polynomial-time probabilistic Turing machines
Lax666725.ProbabilisticMachines · concepts/Lax666725/ProbabilisticMachines.lean · lax-666725
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 Lax666725.ProbabilisticMachines |
| 27 | |
| 28 | open Lax434930.PolynomialTime Turing |
| 29 | |
| 30 | /-- Two finite local transition tables, with common halting configurations. -/ |
| 31 | structure Machine where |
| 32 | Γ : Type |
| 33 | Q : Type |
| 34 | [alphabet : Fintype Γ] |
| 35 | [control : Fintype Q] |
| 36 | [blank : Inhabited Γ] |
| 37 | [initial : Inhabited Q] |
| 38 | input : Bool ↪ Γ |
| 39 | input_ne_blank : ∀ b, input b ≠ default |
| 40 | transition : Bool → TM0.Machine Γ Q |
| 41 | same_halts : ∀ q a, transition false q a = none ↔ transition true q a = none |
| 42 | |
| 43 | attribute [instance] Machine.alphabet Machine.control Machine.blank Machine.initial |
| 44 | |
| 45 | /-- Perform one coin-selected transition, keeping terminal configurations fixed. -/ |
| 46 | def Machine.advance (M : Machine) (c : TM0.Cfg M.Γ M.Q) (b : Bool) : |
| 47 | TM0.Cfg M.Γ M.Q := |
| 48 | (TM0.step (M.transition b) c).getD c |
| 49 | |
| 50 | /-- Execute a finite sequence of fair coin choices. -/ |
| 51 | def Machine.run (M : Machine) (x coins : Word) : TM0.Cfg M.Γ M.Q := |
| 52 | coins.foldl M.advance (TM0.init (x.map M.input)) |
| 53 | |
| 54 | /-- A uniform procedure with a worst-case polynomial bound on every branch. -/ |
| 55 | structure Procedure (α : Type) where |
| 56 | machine : Machine |
| 57 | time : Polynomial ℕ |
| 58 | output : machine.Q → α |
| 59 | halts : ∀ (x : Word) (r : Fin (time.eval x.length) → Bool), |
| 60 | TM0.step (machine.transition false) (machine.run x (List.ofFn r)) = none |
| 61 | |
| 62 | /-- The finite sample space of coin sequences on a particular input. -/ |
| 63 | abbrev Procedure.Coins {α : Type} (A : Procedure α) (x : Word) := |
| 64 | Fin (A.time.eval x.length) → Bool |
| 65 | |
| 66 | /-- Read the output from the terminal control state. -/ |
| 67 | def Procedure.eval {α : Type} (A : Procedure α) (x : Word) (r : A.Coins x) : α := |
| 68 | A.output (A.machine.run x (List.ofFn r)).q |
| 69 | |
| 70 | /-- Exact probability under independent uniform bits. -/ |
| 71 | noncomputable def Procedure.probability {α : Type} (A : Procedure α) |
| 72 | (x : Word) (E : α → Prop) : ℚ := by |
| 73 | classical |
| 74 | exact ((Finset.univ.filter (fun r : A.Coins x => E (A.eval x r))).card : ℚ) / |
| 75 | Fintype.card (A.Coins x) |
| 76 | |
| 77 | /-- A Boolean answer correctly decides membership of the given input. -/ |
| 78 | def Correct (L : Language) (x : Word) (b : Bool) : Prop := |
| 79 | (b = true ↔ x ∈ L) |
| 80 | |
| 81 | end Lax666725.ProbabilisticMachines |
| 82 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments