Documentation

LeanPool.PartialCombinatoryAlgebras.PartialCombinatoryAlgebra

Partial combinatory algebras #

A partial combinatory algebra is a set equipped with a partial binary operation, which has the so-called combinators K and S. We formalize it in two stages.

We first define the class PartialApplication which equips a given set A with a partial binary operation. One might expect such an operation to have type A → A → Part A, but this leads to complications because it is not composable. So instead we specify that a partial operation is a map of type Part A → Part A → Part A. In other words, we always work with partial elements, and separately state that they are total as necessary.

(It would be natural to require that the applications be strict, i.e., if the result is defined so are its arguments. An early version did so, but the assumption of strictness was never used.)

We then define the class PCA (partial combinatory algebra) to be an extension of PartialApplication. It prescribed combinators K and S satisfying the usual properties. Following our strategy, K and S are again partial elements on the carrier set, with a separate claim that they are total.

The partial combinatory structure on a set A.

  • app : Part APart APart A
  • K : Part A

    The K combinator as a partial element.

  • S : Part A

    The S combinator as a partial element.

  • df_K₀ : K

    The K combinator is total.

  • df_K₁ {u : Part A} : u → (K u)

    Applying K to a total argument is total.

  • df_S₀ : S

    The S combinator is total.

  • df_S₁ {u : Part A} : u → (S u)

    Applying S to one total argument is total.

  • df_S₂ {u v : Part A} : u v → (S u v)

    Applying S to two total arguments is total.

  • eq_K (u v : Part A) : u v K u v = u

    The defining equation of K.

  • eq_S (u v w : Part A) : u v w S u v w = u w (v w)

    The defining equation of S.

Instances
    @[implicit_reducible]

    Every PCA is inhabited. We pick K as its default element.

    Equations

    Expr Γ A is the type of expressions built inductively from constants K and S, variables in Γ (the variable context), the elements of a carrier set A, and formal binary application.

    The usual accounts of PCAs typically do not introduce `K` and `S`
    as separate constants, because a PCA `A` already contains such combinators.
    However, as we defined the combinators to be partial elements, it is more
    convenient to have separate primitive constants denoting them.
    Also, this way `A` need not be an applicative structure.
    
    inductive LeanPool.PartialCombinatoryAlgebras.PCA.Expr (Γ : Type u_1) (A : Type u_2) :
    Type (max u_1 u_2)

    Expressions with variables from context Γ and elements from A.

    • K {Γ : Type u_1} {A : Type u_2} : Expr Γ A

      Formal expression denoting the K combinator

    • S {Γ : Type u_1} {A : Type u_2} : Expr Γ A

      Formal expression denoting the S combinator

    • elm {Γ : Type u_1} {A : Type u_2} : AExpr Γ A

      An element as a formal expression

    • var {Γ : Type u_1} {A : Type u_2} : ΓExpr Γ A

      A variable as a formal expression

    • app {Γ : Type u_1} {A : Type u_2} : Expr Γ AExpr Γ AExpr Γ A

      Formal expression application

    Instances For
      @[implicit_reducible]

      Formal application as a binary operation ·

      Equations
      @[reducible]
      def LeanPool.PartialCombinatoryAlgebras.PCA.override {Γ : Type u} [DecidableEq Γ] {A : Type v} (x : Γ) (a : A) (η : ΓA) (y : Γ) :
      A

      A valuation η : Γ → A assigning elements to variables, with the value of x overridden to be a.

      Equations
      Instances For

        An expression is said to be defined when it is defined at every valuation.

        Equations
        Instances For
          def LeanPool.PartialCombinatoryAlgebras.PCA.abstr {Γ : Type u} [DecidableEq Γ] {A : Type v} (x : Γ) :
          Expr Γ AExpr Γ A

          abstr e is an expression with one fewer variables than the expression e, which works similarly to function abastraction in the λ-calculus. It is at the heart of combinatory completeness.

          Equations
          Instances For
            @[simp]
            theorem LeanPool.PartialCombinatoryAlgebras.PCA.df_abstr {Γ : Type u} [DecidableEq Γ] {A : Type v} [PCA A] (x : Γ) (e : Expr Γ A) :

            An abstraction is defined.

            theorem LeanPool.PartialCombinatoryAlgebras.PCA.eval_abstr {Γ : Type u} [DecidableEq Γ] {A : Type v} [PCA A] (x : Γ) (e : Expr Γ A) (a : A) (η : ΓA) :
            eval η (abstr x e Expr.elm a) = eval (override x a η) e

            eval_abstr e behaves like abstraction in the extra variable. This is known as combinatory completeness.

            theorem LeanPool.PartialCombinatoryAlgebras.PCA.eval_abstr_app {Γ : Type u} [DecidableEq Γ] {A : Type v} [PCA A] (η : ΓA) (x : Γ) (e : Expr Γ A) (u : Part A) (hu : u ) :
            eval η (abstr x e) u = eval (override x (u.get hu) η) e

            Like eval_abstr but with the application on the outside of eval.

            @[simp]
            theorem LeanPool.PartialCombinatoryAlgebras.PCA.eval_override {Γ : Type u} [DecidableEq Γ] {A : Type v} [PCA A] (η : ΓA) (x : Γ) (a : A) (e : Expr Γ A) :
            eval (override x a η) e = eval η (subst x a e)
            def LeanPool.PartialCombinatoryAlgebras.PCA.compile {Γ : Type u} {A : Type v} [PCA A] (e : Expr Γ A) :

            Compile an expression to a partial element, substituting the default value for any variables occurring in e.

            Equations
            Instances For

              Notation for combinatory abstraction in an expression.

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

                Notation for compiling a closed PCA expression to a partial element.

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