Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax251941.Acceptance

The acceptance problem for machines

concepts/Lax251941/Acceptance.lean · lax-251941

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.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Definition

    Following Sipser's Introduction to the Theory of Computation, Section 4.2, a machine MM run on an input ww either accepts, rejects, or loops; MM recognises the language AA if it accepts exactly the words of AA, and decides AA if moreover it halts on every input, accepting or rejecting. A language is Turing-recognisable if some machine recognises it and decidable if some machine decides it. The acceptance problem is the language

    ATM={M,wM is a machine and M accepts w},A_{TM} = \{\langle M, w\rangle \mid M \text{ is a machine and } M \text{ accepts } w\},

    where M,w\langle M, w \rangle encodes a machine together with an input word.

    Lean source view on GitHub

    1import Mathlib.Computability.PartrecCode
    2
    3/-!
    4---
    5title: The acceptance problem for machines
    6type: definition
    7---
    8Following Sipser's *Introduction to the Theory of Computation*, Section 4.2, a
    9*machine* MM run on an input ww either accepts, rejects, or loops; MM
    10*recognises* the language AA if it accepts exactly the words of AA, and
    11*decides* AA if moreover it halts on every input, accepting or rejecting. A
    12language is *Turing-recognisable* if some machine recognises it and *decidable*
    13if some machine decides it. The *acceptance problem* is the language
    14ATM={M,wM is a machine and M accepts w},A_{TM} = \{\langle M, w\rangle \mid M \text{ is a machine and } M \text{ accepts } w\},
    15where M,w\langle M, w \rangle encodes a machine together with an input word.
    16
    17# Formalization notes
    18
    19Sipser's argument is about an arbitrary universal model of computation; the
    20machines here are mathlib's partial recursive programs `Nat.Partrec.Code`, which
    21supply exactly the two ingredients his proof needs — a universal machine
    22(`Nat.Partrec.Code.eval_part`: evaluation is itself computable) and the ability
    23to program every partial recursive function as a machine
    24(`Nat.Partrec.Code.exists_code`). Inputs and outputs are natural numbers, which
    25play the role of strings; a machine *accepts* by halting with output `1` and
    26*rejects* by halting with output `0`, so that accepting, rejecting and looping
    27are the three mutually exclusive outcomes of Sipser's definition. The pair
    28M,w\langle M, w\rangle is the Cantor pairing of the code of `M` (mathlib's
    29`Encodable.encode`, under which the programs are `Denumerable`) with `w`.
    30Turing machines in the literal sense, with a tape, appear in `TuringMachines`;
    31they are where the reduction to the Post correspondence problem lives.
    32-/
    33
    34namespace Lax251941.Acceptance
    35
    36/-- A machine: a partial recursive program. -/
    37abbrev Machine := Nat.Partrec.Code
    38
    39/-- `M` accepts `w` if it halts on `w` with output `1`. -/
    40def Accepts (M : Machine) (w : ℕ) : Prop := M.eval w = Part.some 1
    41
    42/-- `M` rejects `w` if it halts on `w` with output `0`. -/
    43def Rejects (M : Machine) (w : ℕ) : Prop := M.eval w = Part.some 0
    44
    45/-- A machine is a decider if it accepts or rejects every input, i.e. never loops.
    46-/
    47def IsDecider (M : Machine) : Prop := ∀ w, Accepts M w ∨ Rejects M w
    48
    49/-- `M` recognises the language `A` if it accepts exactly the words of `A`. -/
    50def Recognizes (M : Machine) (A : Set ℕ) : Prop := ∀ w, w ∈ A ↔ Accepts M w
    51
    52/-- `M` decides `A` if it is a decider that recognises `A`. -/
    53def Decides (M : Machine) (A : Set ℕ) : Prop := IsDecider M ∧ Recognizes M A
    54
    55/-- A language is Turing-recognisable if some machine recognises it. -/
    56def TuringRecognizable (A : Set ℕ) : Prop := ∃ M, Recognizes M A
    57
    58/-- A language is decidable if some machine decides it. -/
    59def TuringDecidable (A : Set ℕ) : Prop := ∃ M, Decides M A
    60
    61/-- The acceptance problem `A_TM`: the pairs `⟨M, w⟩`, encoded by Cantor pairing
    62of the code of `M` with `w`, such that `M` accepts `w`. -/
    63def ATM : Set ℕ := {n | Accepts (Denumerable.ofNat Machine n.unpair.1) n.unpair.2}
    64
    65end Lax251941.Acceptance
    66

    Formalization notes

    Sipser's argument is about an arbitrary universal model of computation; the machines here are mathlib's partial recursive programs Nat.Partrec.CodeNat.Partrec.Code, which supply exactly the two ingredients his proof needs — a universal machine (Nat.Partrec.Code.evalpartNat.Partrec.Code.eval_part: evaluation is itself computable) and the ability to program every partial recursive function as a machine (Nat.Partrec.Code.existscodeNat.Partrec.Code.exists_code). Inputs and outputs are natural numbers, which play the role of strings; a machine accepts by halting with output 11 and rejects by halting with output 00, so that accepting, rejecting and looping are the three mutually exclusive outcomes of Sipser's definition. The pair M,w\langle M, w\rangle is the Cantor pairing of the code of MM (mathlib's Encodable.encodeEncodable.encode, under which the programs are DenumerableDenumerable) with ww. Turing machines in the literal sense, with a tape, appear in TuringMachinesTuringMachines; they are where the reduction to the Post correspondence problem lives.

    Community review

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.

    0 comments

    Loading discussion…