Polynomial-time probabilistic Turing machines

Lax115662.ProbabilisticMachines · concepts/Lax115662/ProbabilisticMachines.lean · lax-115662

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural 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 Lax434930.PolynomialTime.WordLax434930.PolynomialTime.Word.

    A polynomial-time procedure consists of one such machine, a polynomial p∈N[X]p\in\mathbb N[X], and an output attached to each control state. Every computation on xx must halt within p(∣x∣)p(|x|) steps. Halted configurations are left fixed, so we may use exactly p(∣x∣)p(|x|) random bits, including unused bits after termination. For an output event EE, its probability is the number of bit strings producing an output in EE, divided by 2p(∣x∣)2^{p(|x|)}. All machines and bounds are chosen uniformly, before the input.

    Concept map
    2 concepts; 8 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Lax434930.PolynomialTime
    2import Mathlib.Computability.TuringMachine.PostTuringMachine
    3import Mathlib.Data.Fintype.Pi
    4import Mathlib.Data.Rat.Defs
    5
    6/-!
    7---
    8title: Polynomial-time probabilistic Turing machines
    9type: definition
    10---
    11A probabilistic Turing machine has finite control and a finite tape alphabet.
    12At each step an independent fair bit selects one of two transition tables.
    13Each transition moves the tape head one square or writes one symbol. Both
    14tables agree on which configurations are terminal. The input is an ordinary
    15binary word, using the type `Lax434930.PolynomialTime.Word`.
    16
    17A polynomial-time procedure consists of one such machine, a polynomial
    18p∈N[X]p\in\mathbb N[X], and an output attached to each control state. Every
    19computation on xx must halt within p(∣x∣)p(|x|) steps. Halted configurations are
    20left fixed, so we may use exactly p(∣x∣)p(|x|) random bits, including unused bits
    21after termination. For an output event EE, its probability is the number
    22of bit strings producing an output in EE, divided by 2p(∣x∣)2^{p(|x|)}.
    23All machines and bounds are chosen uniformly, before the input.
    24-/
    25
    26namespace Lax115662.ProbabilisticMachines
    27
    28open scoped Classical
    29
    30open Lax434930.PolynomialTime Turing
    31
    32/-- Two finite local transition tables, with common halting configurations. -/
    33structure 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
    55attribute [instance] Machine.alphabet Machine.control Machine.blank Machine.initial
    56
    57/-- Perform one coin-selected transition, keeping terminal configurations fixed. -/
    58def 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. -/
    63def 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. -/
    67structure 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. -/
    79abbrev 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. -/
    83def 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. -/
    87noncomputable 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. -/
    93def Correct (L : Language) (x : Word) (b : Bool) : Prop :=
    94 (b = true ↔ x ∈ L)
    95
    96end Lax115662.ProbabilisticMachines
    97

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…