Polynomial-time probabilistic Turing machines

Lax666725.ProbabilisticMachines · concepts/Lax666725/ProbabilisticMachines.lean · lax-666725

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 Lax666725.ProbabilisticMachines
    27
    28open Lax434930.PolynomialTime Turing
    29
    30/-- Two finite local transition tables, with common halting configurations. -/
    31structure 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
    43attribute [instance] Machine.alphabet Machine.control Machine.blank Machine.initial
    44
    45/-- Perform one coin-selected transition, keeping terminal configurations fixed. -/
    46def 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. -/
    51def 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. -/
    55structure 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. -/
    63abbrev 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. -/
    67def 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. -/
    71noncomputable 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. -/
    78def Correct (L : Language) (x : Word) (b : Bool) : Prop :=
    79 (b = true ↔ x ∈ L)
    80
    81end Lax666725.ProbabilisticMachines
    82

    Discussion

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

    Loading discussion…