Documentation

Cslib.Computability.URM.Defs

URM Core Definitions #

This file contains the core definitions for Unlimited Register Machines (URMs): instructions, register state, programs, and machine configurations.

Main definitions #

References #

Instructions #

URM instructions.

  • Z n: Set register n to zero
  • S n: Increment register n by one
  • T m n: Transfer (copy) the contents of register m to register n
  • J m n q: If registers m and n have equal contents, jump to instruction q; otherwise proceed to the next instruction
  • Z : โ„• โ†’ Instr
  • S : โ„• โ†’ Instr
  • T : โ„• โ†’ โ„• โ†’ Instr
  • J : โ„• โ†’ โ„• โ†’ โ„• โ†’ Instr
Instances For
    def Cslib.URM.instDecidableEqInstr.decEq (xโœ xโœยน : Instr) :
    Decidable (xโœ = xโœยน)
    Equations
    Instances For
      def Cslib.URM.instReprInstr.repr :
      Instr โ†’ โ„• โ†’ Std.Format
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Cslib.URM.Instr.readsFrom :
        Instr โ†’ Finset โ„•

        The registers read by an instruction.

        Equations
        Instances For
          def Cslib.URM.Instr.writesTo :
          Instr โ†’ Option โ„•

          The register written to by an instruction, if any.

          Equations
          Instances For
            def Cslib.URM.Instr.maxRegister :
            Instr โ†’ โ„•

            The maximum register index referenced by an instruction.

            Equations
            Instances For
              def Cslib.URM.Instr.shiftJumps (offset : โ„•) :
              Instr โ†’ Instr

              Shift all jump targets in an instruction by offset. Used when concatenating programs to maintain correct jump destinations.

              Equations
              Instances For
                def Cslib.URM.Instr.shiftRegisters (offset : โ„•) :
                Instr โ†’ Instr

                Shift all register references in an instruction by offset. Used to isolate register usage when composing programs.

                Equations
                Instances For

                  Register Contents #

                  @[reducible, inline]

                  Register contents: maps register indices to natural number contents.

                  Uses the functional representation โ„• โ†’ โ„• for efficiency with rewrites, following the advice from the grind tactic documentation.

                  Equations
                  Instances For

                    The zero registers where all registers contain 0.

                    Equations
                    Instances For
                      def Cslib.URM.Regs.read (ฯƒ : Regs) (n : โ„•) :
                      โ„•

                      Read the contents of register n.

                      Equations
                      • ฯƒ.read n = ฯƒ n
                      Instances For
                        def Cslib.URM.Regs.write (ฯƒ : Regs) (n v : โ„•) :

                        Write value v to register n.

                        Equations
                        • ฯƒ.write n v = Function.update ฯƒ n v
                        Instances For
                          def Cslib.URM.Regs.ofInputs (inputs : List โ„•) :

                          Initialize registers with input values in registers 0, 1, ..., k-1. Registers beyond the inputs are initialized to 0.

                          Equations
                          Instances For
                            def Cslib.URM.Regs.output (ฯƒ : Regs) :
                            โ„•

                            Extract output from register 0.

                            Equations
                            Instances For

                              Programs #

                              @[reducible, inline]

                              A URM program is a list of instructions.

                              Equations
                              Instances For

                                The maximum register index referenced by any instruction in the program.

                                Equations
                                Instances For
                                  def Cslib.URM.Program.shiftJumps (p : Program) (offset : โ„•) :

                                  Shift all jump targets in a program by offset. Used when concatenating programs: the second program's jumps must be adjusted by the length of the first program.

                                  Equations
                                  Instances For
                                    def Cslib.URM.Program.shiftRegisters (p : Program) (offset : โ„•) :

                                    Shift all register references in a program by offset. Used to isolate register usage when composing programs.

                                    Equations
                                    Instances For

                                      Machine State #

                                      Machine state: program counter (0-indexed) and register contents.

                                      • pc : โ„•

                                        Program counter (0-indexed).

                                      • regs : Regs

                                        Register contents.

                                      Instances For
                                        def Cslib.URM.State.init (inputs : List โ„•) :

                                        Initial state for a program with given inputs. The program counter starts at 0, and inputs are loaded into registers 0, 1, ....

                                        Equations
                                        Instances For

                                          A state is halted if the program counter is at or beyond the program length.

                                          Equations
                                          Instances For
                                            @[implicit_reducible]
                                            Equations
                                            @[implicit_reducible]
                                            Equations