Documentation

CslibFrontier.Computability.WordRAM.Notation

Notation for structured word-RAM programs #

ram[ s₁; s₂; … ] writes a structured program (Cslib.WordRAM.Code) as a sequence of statements, one per data instruction, in the style of word-RAM pseudocode. Registers are named by identifiers, for instance local abbreviations of elements of Fin r. The statements are:

The notation unfolds to the constructors of Cslib.WordRAM.Code, so it adds nothing to the semantics. The binary operations and width% are instructions of the standard basis (Cslib.WordRAM.Op.bin, Cslib.WordRAM.Op.width); the other statements work over every basis. It is scoped: open Cslib.WordRAM enables it, with its statement forms, their expansions and the tactic ram_eval. Only the category wramStmt and the syntax abbreviation wramBlock are global, since Lean cannot scope them; without the open, wramStmt has no rules, so they parse nothing. The statement forms follow the word-RAM notation of Algolean. Its only new tokens are ram[, width% and the internal ram_stmt% and ram_block%, so it reserves no identifiers: ram and width remain ordinary names.

Main definitions #

Tactics #

References #

A statement of a structured word-RAM program.

Instances For

    A block of statements, separated by semicolons.

    Instances For

      A structured word-RAM program, written as a block of statements.

      Instances For

        Internal: a nested block of statements, as a structured program.

        Instances For

          Internal: a single statement, as a structured program.

          Instances For

            Set a register to a constant.

            Instances For

              Truncated subtraction.

              Instances For

                Bitwise exclusive or.

                Instances For

                  Load from the memory cell whose address is in a register.

                  Instances For

                    Store to the memory cell whose address is in a register.

                    Instances For

                      Sample uniformly from [0, regs s] into a register.

                      Instances For

                        A conditional on the equality of two registers.

                        Instances For

                          A conditional on the comparison of two registers.

                          Instances For

                            A loop while two registers are equal.

                            Instances For

                              A loop while one register is smaller than another.

                              Instances For

                                A structured program given as a term.

                                Instances For

                                  Symbolically execute structured code on a goal ExecWithin w c x y T or Exec w c x y T, allowing each loop the given number of iterations (default 0). Whether a written number fits a word is decided by omega from the Fits hypotheses in context (Cslib.WordRAM.reduceFits), or by the given simp lemmas.

                                  On failure the error names the step that failed: the goal has neither form, a given simp lemma does not elaborate, simp cannot evaluate the program (pass its definition, as in ram_eval [myProgram]), the interpreter returns none (a fault, or too few loop iterations), a branch or Fits condition remains (shown), or omega cannot prove the instruction bound (shown). Under try or first, which discard the message, it fails without working out which step.

                                  Instances For

                                    Internal: the symbolic execution behind ram_eval and ram_exact_eval. The string names the calling tactic in error messages and the number is the loop fuel; the identifier names the simp set that evaluates the program, ram_eval_simps or ram_exact_eval_simps, and the list holds the caller's simp lemmas.

                                    Instances For

                                      Internal: simp +decide only with the simp set set (ram_eval_simps or ram_exact_eval_simps), the simplification procedures of ram_eval (Cslib.WordRAM.RamEval.simprocs), and the given simp lemmas. It is simp +decide only [l₁, …, lₙ, args] for the lemmas l₁, …, lₙ with which ram_eval_simp_set filled set, but it does not index them again.

                                      Instances For

                                        Internal: fill the empty simp set set with the entries that simp only [names] builds from the simp lemmas and definitions names, in their order, so that ram_eval_simp set [args] is simp +decide only [names, args]. Simplification procedures belong in Cslib.WordRAM.RamEval.simprocs.

                                        Instances For

                                          The simplification procedures of ram_eval and ram_exact_eval, in the order in which they are added, with true for those that rewrite after visiting the subterms (post). They are added by name on each call, since the builtin ones cannot be tagged into a simp set in a module.

                                          Instances For

                                            The simp context of ram_eval_simp set [args], given stx := simp +decide only [args]: the context that mkSimpContext builds for simp +decide only [l₁, …, lₙ, args], where ram_eval_simp_set filled set with l₁, …, lₙ, and simprocs come among the lᵢ. The theorems of set are taken as indexed, and args are elaborated into the same tree, so simp searches one tree, as it does for the literal list.

                                            Instances For

                                              Internal: fill the simp set set of ram_eval (ram_eval_simps) or ram_exact_eval (ram_exact_eval_simps), given the simp lemmas basis that evaluate the instructions of the basis. The simplification procedures among the lemmas are Cslib.WordRAM.RamEval.simprocs.

                                              Instances For