Finite stack subroutines and their interfaces

Lax218471.Subroutine · concepts/Lax218471/Subroutine.lean · lax-218471

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 subroutine has access to the caller's stacks and finite control, together with a private finite collection of working stacks and private finite control. At entry and return its private stacks are empty and its private control is reset. Execution counts actual TM2 transitions. This interface makes repeated calls and preservation of unrelated caller data explicit.

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

    Lean source view on GitHub

    1import Mathlib.Computability.TuringMachine.Computable
    2import Mathlib.Data.Fintype.Sum
    3import Mathlib.Data.Fintype.Prod
    4
    5/-!
    6---
    7title: Finite stack subroutines and their interfaces
    8type: definition
    9---
    10A subroutine has access to the caller's stacks and finite control, together
    11with a private finite collection of working stacks and private finite control.
    12At entry and return its private stacks are empty and its private control is
    13reset. Execution counts actual TM2 transitions. This interface makes repeated
    14calls and preservation of unrelated caller data explicit.
    15-/
    16
    17namespace Lax218471.Subroutine
    18
    19open Turing
    20
    21/-- The data visible to a caller between subroutine calls. -/
    22structure Store {K : Type} (Γ : K → Type) (σ : Type) where
    23 state : σ
    24 stk : ∀ k, List (Γ k)
    25
    26/-- An ordinary finite TM2 program with a private working region. -/
    27structure Routine {K : Type} (Γ : K → Type) (σ : Type) where
    28 W : Type
    29 [workEq : DecidableEq W]
    30 [workFin : Fintype W]
    31 Δ : W → Type
    32 τ : Type
    33 [stateFin : Fintype τ]
    34 initial : τ
    35 Label : Type
    36 [labelFin : Fintype Label]
    37 entry : Label
    38 code : Label → TM2.Stmt (Sum.elim Γ Δ) Label (σ × τ)
    39
    40namespace Routine
    41
    42variable {K σ : Type} {Γ : K → Type} (p : Routine Γ σ)
    43
    44instance : DecidableEq p.W := p.workEq
    45instance : Fintype p.W := p.workFin
    46instance : Fintype p.τ := p.stateFin
    47instance : Fintype p.Label := p.labelFin
    48
    49/-- A boundary configuration contains no private working data. -/
    50def boundary (l : Option p.Label) (s : Store Γ σ) :
    51 TM2.Cfg (Sum.elim Γ p.Δ) p.Label (σ × p.τ) where
    52 l := l
    53 var := (s.state, p.initial)
    54 stk := fun | .inl k => s.stk k | .inr _ => []
    55
    56/-- Exact execution from a clean entry to a clean return. -/
    57def Executes [DecidableEq K] (s t : Store Γ σ) (n : ℕ) : Prop :=
    58 (fun c => c.bind (TM2.step p.code))^[n] (some (p.boundary (some p.entry) s)) =
    59 some (p.boundary none t)
    60
    61end Routine
    62end Lax218471.Subroutine
    63

    Discussion

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

    Loading discussion…