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 #
Turing.TM2.Cfg.mapLabel: rename the label of a configuration.Turing.TM2.restrict: the program on a finite set of labels.Turing.PartrecToTM2.finProgram,Turing.PartrecToTM2.finInit: the compiled program of a code on its finite support, and its initial configuration on an input list.
Main results #
Turing.TM2.eval_restrict: a supported program and its restriction have the same runs.Turing.PartrecToTM2.eval_finProgram: the restricted program evaluates the code, with the output list on the main stack.Turing.PartrecToTM2.trNat_eq_map_bits: the stack encoding of a number lists its binary digits, least significant first.Turing.PartrecToTM2.primrec_trNat,Turing.PartrecToTM2.primrec_bits: the stack encoding of numbers and their binary digitsNat.bitsare primitive recursive.
The program on the labels in S. A jump to a label outside S goes to d.
Restriction preserves runs: from a configuration in S, the program halts exactly when
its restriction does, in the corresponding configuration.
The four stacks of PartrecToTM2 form a finite type.
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.
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.