Compiling structured word-RAM programs #
A structured program (Cslib.WordRAM.Code) assembles into a flat program
(Cslib.WordRAM.Code.assemble) whose conditionals and loops become branches and jumps to
absolute instruction indices:
branch c pos negatpcbecomes a branch onctopos, thenneg, then a jump pastpos;loop c bodyatpcbecomes a branch onctobody, a jump past the loop,body, and a jump back to the branch.
Every structured execution is a run of the assembled program with exactly the same number of
instructions (Cslib.WordRAM.Exec.runs). A complete program ends with a halt
(Cslib.WordRAM.Code.program), so a structured proof that a program answers a question
(Cslib.WordRAM.Code.Answers) gives a flat program that answers it with one more instruction
(Cslib.WordRAM.Code.Answers.program), and a uniform decision procedure
(Cslib.WordRAM.Code.decidesInTime_program, Cslib.WordRAM.UniformDecidableInTime.of_code).
Main definitions #
Cslib.WordRAM.Code.assemble,Cslib.WordRAM.Code.program: assembly at a given position, and the complete program halting with a given register.Cslib.WordRAM.Program.Contains: a program contains another at a given position.Cslib.WordRAM.Code.Answers: a structured program answers a question in a register.
Main results #
Cslib.WordRAM.Exec.runs: structured executions are runs of the assembled program with the same instruction count.Cslib.WordRAM.Exec.executes: a structured execution followed byhaltis a halting run.Cslib.WordRAM.Code.decidesInTime_program,Cslib.WordRAM.UniformDecidableInTime.of_code: structured decision procedures are uniform deciders. Width-indexed code with a uniform size bound givesCslib.WordRAM.DecidableInTime.of_code.Cslib.WordRAM.Code.not_readsWidth_program: a compiled program reads the word size only if the structured program does.
References #
- MIT–ULB CompGeom Group, Undecidability of tiling with a tromino; the assembly and its exact-cost correctness are adapted from its accompanying Lean formalization.
Assembly #
Correctness of assembly #
Assembly is correct. A structured execution is a run of any program containing the assembled structured program, from its first instruction to the instruction after it, with exactly the same number of instructions.
Answering questions with structured programs #
The structured program c, run at word size w from the initial data on input, leaves
the answer to b in register out within time instructions: 1 if b holds and 0
otherwise.
Instances For
A structured program that answers a question gives a flat program that answers it, with one
more instruction for the final halt.
Structured answers give a fixed-program decision certificate, charging the final halt.
Structured decision procedures are uniform deciders.
Structured families with bounded compiled code give nonuniform deciders.
Reading the word size #
An assembled program reads the word size only if the structured program does.
A compiled program reads the word size only if the structured program does.