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.
- K : Part A
The
Kcombinator as a partial element. - S : Part A
The
Scombinator as a partial element. The
Kcombinator is total.Applying
Kto a total argument is total.The
Scombinator is total.Applying
Sto one total argument is total.Applying
Sto two total arguments is total.The defining equation of
K.The defining equation of
S.
Instances
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.
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}
: A → Expr Γ 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 Γ A → Expr Γ A → Expr Γ A
Formal expression application
Instances For
Formal application as a binary operation ·
A valuation η : Γ → A assigning elements to variables,
with the value of x overridden to be a.
Instances For
Evaluate an expression with respect to a given valuation η.
Equations
- LeanPool.PartialCombinatoryAlgebras.PCA.eval η LeanPool.PartialCombinatoryAlgebras.PCA.Expr.K = LeanPool.PartialCombinatoryAlgebras.PCA.K
- LeanPool.PartialCombinatoryAlgebras.PCA.eval η LeanPool.PartialCombinatoryAlgebras.PCA.Expr.S = LeanPool.PartialCombinatoryAlgebras.PCA.S
- LeanPool.PartialCombinatoryAlgebras.PCA.eval η (LeanPool.PartialCombinatoryAlgebras.PCA.Expr.elm a) = Part.some a
- LeanPool.PartialCombinatoryAlgebras.PCA.eval η (LeanPool.PartialCombinatoryAlgebras.PCA.Expr.var x_1) = Part.some (η x_1)
- LeanPool.PartialCombinatoryAlgebras.PCA.eval η (e₁.app e₂) = LeanPool.PartialCombinatoryAlgebras.PCA.eval η e₁ ⬝ LeanPool.PartialCombinatoryAlgebras.PCA.eval η e₂
Instances For
An expression is said to be defined when it is defined at every valuation.
Equations
- LeanPool.PartialCombinatoryAlgebras.PCA.defined e = ∀ (η : Γ → A), (LeanPool.PartialCombinatoryAlgebras.PCA.eval η e) ⇓
Instances For
The substitution of an element for the extra variable.
Equations
- One or more equations did not get rendered due to their size.
- LeanPool.PartialCombinatoryAlgebras.PCA.subst x a LeanPool.PartialCombinatoryAlgebras.PCA.Expr.K = LeanPool.PartialCombinatoryAlgebras.PCA.Expr.K
- LeanPool.PartialCombinatoryAlgebras.PCA.subst x a LeanPool.PartialCombinatoryAlgebras.PCA.Expr.S = LeanPool.PartialCombinatoryAlgebras.PCA.Expr.S
- LeanPool.PartialCombinatoryAlgebras.PCA.subst x a (LeanPool.PartialCombinatoryAlgebras.PCA.Expr.elm a_1) = LeanPool.PartialCombinatoryAlgebras.PCA.Expr.elm a_1
- LeanPool.PartialCombinatoryAlgebras.PCA.subst x a (e₁.app e₂) = LeanPool.PartialCombinatoryAlgebras.PCA.subst x a e₁ ⬝ LeanPool.PartialCombinatoryAlgebras.PCA.subst x a e₂
Instances For
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
- One or more equations did not get rendered due to their size.
- LeanPool.PartialCombinatoryAlgebras.PCA.abstr x LeanPool.PartialCombinatoryAlgebras.PCA.Expr.K = LeanPool.PartialCombinatoryAlgebras.PCA.Expr.K ⬝ LeanPool.PartialCombinatoryAlgebras.PCA.Expr.K
- LeanPool.PartialCombinatoryAlgebras.PCA.abstr x LeanPool.PartialCombinatoryAlgebras.PCA.Expr.S = LeanPool.PartialCombinatoryAlgebras.PCA.Expr.K ⬝ LeanPool.PartialCombinatoryAlgebras.PCA.Expr.S
Instances For
An abstraction is defined.
eval_abstr e behaves like abstraction in the extra variable.
This is known as combinatory completeness.
Like eval_abstr but with the application on the outside of eval.
Evaluate an expression under the assumption that it is closed.
Return inl x if variable x is encountered, otherwise inr u
where u is the partial element so obtained.
Equations
- One or more equations did not get rendered due to their size.
- LeanPool.PartialCombinatoryAlgebras.PCA.evalClosed LeanPool.PartialCombinatoryAlgebras.PCA.Expr.K = Sum.inr LeanPool.PartialCombinatoryAlgebras.PCA.K
- LeanPool.PartialCombinatoryAlgebras.PCA.evalClosed LeanPool.PartialCombinatoryAlgebras.PCA.Expr.S = Sum.inr LeanPool.PartialCombinatoryAlgebras.PCA.S
- LeanPool.PartialCombinatoryAlgebras.PCA.evalClosed (LeanPool.PartialCombinatoryAlgebras.PCA.Expr.elm a) = Sum.inr (Part.some a)
- LeanPool.PartialCombinatoryAlgebras.PCA.evalClosed (LeanPool.PartialCombinatoryAlgebras.PCA.Expr.var x_1) = Sum.inl x_1
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.