Documentation

Archive.Arithcc

A compiler for arithmetic expressions #

A formalization of the correctness of a compiler from arithmetic expressions to machine language described by McCarthy and Painter, which is considered the first proof of compiler correctness.

Main definitions #

Main results #

Notation #

References #

Tags #

compiler

Types #

@[reducible, inline]

Value type shared by both source and target languages.

Equations
Instances For
    @[reducible, inline]

    Variable identifier type in the source language.

    Equations
    Instances For
      @[reducible, inline]

      Register name type in the target language.

      Equations
      Instances For
        theorem Arithcc.Register.le_of_lt_succ {r₁ : Arithcc.Register} {r₂ : Arithcc.Register} :
        r₁ < r₂ + 1r₁ r₂

        Source language #

        inductive Arithcc.Expr :

        An expression in the source language is formed by constants, variables, and sums.

        Instances For

          The semantics of the source language (2.1).

          Equations
          Instances For

            Target language #

            Instructions of the target machine language (3.1--3.7).

            Instances For
              structure Arithcc.State :

              Machine state consists of the accumulator and a vector of registers.

              The paper uses two functions c and a for accessing both the accumulator and registers. For clarity, we make accessing the accumulator explicit and use read/write for registers.

              Instances For
                Equations

                This is similar to the c function (3.8), but for registers only.

                Equations
                Instances For

                  This is similar to the a function (3.9), but for registers only.

                  Equations
                  Instances For

                    The semantics of the target language (3.11).

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      The resulting machine state of running a target program from a given machine state (3.12).

                      Equations
                      Instances For
                        @[simp]

                        A lemma on the concatenation of two programs (3.13).

                        Compiler #

                        Map a variable in the source expression to a machine register.

                        Equations
                        Instances For

                          The implementation of the compiler (4.2).

                          This definition explicitly takes a map from variables to registers.

                          Equations
                          Instances For

                            Correctness #

                            Machine states ζ₁ and ζ₂ are equal except for the accumulator and registers {x | x ≥ t}.

                            Equations
                            Instances For
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                theorem Arithcc.StateEqRs.symm {t : Arithcc.Register} (ζ₁ : Arithcc.State) (ζ₂ : Arithcc.State) :
                                ζ₁ ≃[t]/ac ζ₂ζ₂ ≃[t]/ac ζ₁
                                theorem Arithcc.StateEqRs.trans {t : Arithcc.Register} (ζ₁ : Arithcc.State) (ζ₂ : Arithcc.State) (ζ₃ : Arithcc.State) :
                                ζ₁ ≃[t]/ac ζ₂ζ₂ ≃[t]/ac ζ₃ζ₁ ≃[t]/ac ζ₃

                                Machine states ζ₁ and ζ₂ are equal except for registers {x | x ≥ t}.

                                Equations
                                Instances For
                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    theorem Arithcc.StateEq.symm {t : Arithcc.Register} (ζ₁ : Arithcc.State) (ζ₂ : Arithcc.State) :
                                    ζ₁ ≃[t] ζ₂ζ₂ ≃[t] ζ₁
                                    theorem Arithcc.StateEq.trans {t : Arithcc.Register} (ζ₁ : Arithcc.State) (ζ₂ : Arithcc.State) (ζ₃ : Arithcc.State) :
                                    ζ₁ ≃[t] ζ₂ζ₂ ≃[t] ζ₃ζ₁ ≃[t] ζ₃
                                    theorem Arithcc.StateEqStateEqRs.trans (t : Arithcc.Register) (ζ₁ : Arithcc.State) (ζ₂ : Arithcc.State) (ζ₃ : Arithcc.State) :
                                    ζ₁ ≃[t] ζ₂ζ₂ ≃[t]/ac ζ₃ζ₁ ≃[t]/ac ζ₃

                                    Transitivity of chaining ≃[t] and ≃[t]/ac.

                                    theorem Arithcc.stateEq_implies_write_eq {t : Arithcc.Register} {ζ₁ : Arithcc.State} {ζ₂ : Arithcc.State} (h : ζ₁ ≃[t] ζ₂) (v : Arithcc.Word) :
                                    Arithcc.write t v ζ₁ ≃[t + 1] Arithcc.write t v ζ₂

                                    Writing the same value to register t gives ≃[t + 1] from ≃[t].

                                    Writing the same value to any register preserves ≃[t]/ac.

                                    theorem Arithcc.write_eq_implies_stateEq {t : Arithcc.Register} {v : Arithcc.Word} {ζ₁ : Arithcc.State} {ζ₂ : Arithcc.State} (h : ζ₁ ≃[t + 1] Arithcc.write t v ζ₂) :
                                    ζ₁ ≃[t] ζ₂

                                    ≃[t + 1] with writing to register t implies ≃[t].

                                    theorem Arithcc.compiler_correctness (map : Arithcc.IdentifierArithcc.Register) (e : Arithcc.Expr) (ξ : Arithcc.IdentifierArithcc.Word) (η : Arithcc.State) (t : Arithcc.Register) (hmap : ∀ (x : Arithcc.Identifier), Arithcc.read (Arithcc.loc x map) η = ξ x) (ht : ∀ (x : Arithcc.Identifier), Arithcc.loc x map < t) :
                                    Arithcc.outcome (Arithcc.compile map e t) η ≃[t] { ac := Arithcc.value e ξ, rs := η.rs }

                                    The main compiler correctness theorem.

                                    Unlike Theorem 1 in the paper, both map and the assumption on t are explicit.