Documentation

CslibFrontier.Computability.Machines.Turing.TM2.PartrecToTM2

The stack machine of a partial recursive code on finitely many labels #

Mathlib compiles a code c : Turing.ToPartrec.Code to the stack machine Turing.PartrecToTM2.tr, whose labels Λ' form an infinite type, and shows that a run from PartrecToTM2.init c v only visits the finite set codeSupp c Cont'.halt (PartrecToTM2.tr_supports). This file turns the compiled program into a program on that finite set of labels, with the same runs.

Restriction renames the jump targets of each statement. A target outside the support goes to a fixed label of the support, so the restricted program is defined without proofs, and the support hypothesis is used only to show that a run is unchanged (Turing.TM2.eval_restrict).

Main definitions #

Main results #

def Turing.TM2.Cfg.mapLabel {K : Type u_1} {Γ : K → Type u_2} {Λ : Type u_3} {Λ₂ : Type u_4} {σ : Type u_5} (f : Λ → Λ₂) (c : Cfg Γ Λ σ) :
Cfg Γ Λ₂ σ

Rename the label of a configuration, keeping its state and stacks.

def Turing.TM2.restrict {K : Type u_1} {Γ : K → Type u_2} {Λ : Type u_3} {σ : Type u_5} [DecidableEq Λ] (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) (d : ↥S) :
↥S → Stmt Γ (↥S) σ

The program on the labels in S. A jump to a label outside S goes to d.

theorem Turing.TM2.eval_restrict {K : Type u_1} {Γ : K → Type u_2} {Λ : Type u_3} {σ : Type u_5} [DecidableEq K] [DecidableEq Λ] {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} (hS : ∀ q ∈ S, SupportsStmt S (M q)) (d : ↥S) (c : Cfg Γ (↥S) σ) :

Restriction preserves runs: from a configuration in S, the program halts exactly when its restriction does, in the corresponding configuration.

@[instance_reducible]

The four stacks of PartrecToTM2 form a finite type.

The stack encoding of a number lists its binary digits (Nat.bits), least significant first, as bit0 and bit1.

@[instance_reducible]

The stack alphabet of PartrecToTM2 is primcodable through an enumeration.

The stack encoding of numbers is primitive recursive.

The binary digits of a number are primitive recursive.

@[reducible, inline]

The labels that a run of the compiled program of c can visit.

The initial label of the compiled program of c.

The compiled program of c on the finitely many labels its runs visit.

The initial configuration of finProgram c on the input list v: Mathlib's init c v, at the start label.

The finite program evaluates the code: it halts on v exactly when c does, and then holds the encoded output list on the main stack and nothing on the others.