nLab
partial combinatory algebra

Contents

Idea

A partial combinatory algebra is a generalization of a model of the untyped lambda calculus allowing for application to be only partially defined.

Definition

The following definitions are taken from Hofstra.

A partial applicative structure is a set equipped with a partial binary operation

m:A×AAm \colon A \times A \to A

An application of m is indicated by juxtaposition: ab denotes m(a,b) if (and only if) m(a,b) is defined, i.e., if (a,b) belongs to the domain of m. Homomorphisms between partial applicative structures A,B are defined to be total functions f:AB such that f(ab)=f(a)f(b), meaning the right side is defined whenever the left side is. In other words, in the locally posetal bicategory of sets and relations, we have a 2-cell

A×A f×f B×B m m A f B\array{ A \times A & \stackrel{f \times f}{\to} & B \times B \\ m \downarrow & \leq & \downarrow m \\ A & \underset{f}{\to} & B }

By convention, unbracketed juxtapositions are associated to the left, so that for example xyz means (xy)z.

If A is a partial applicative structure and Magma(A) is the free magma on the underlying set of A, then we have an evident partial function

α:Magma(A)A\alpha \colon \mathbf{Magma}(A) \to A

which evaluates binary words in A as elements in A, whenever possible, using the partial applicative structure and induction on the structure of the word.

Definition

A partial applicative structure A is a partial combinatory algebra (a PCA) if there are elements k,sA such that

  • For all a,bA, ka and kab are defined and kab=a.
  • For all a,bA, sa and sab are defined and for all c, (ac)(bc) is defined if and only if sabc is defined, and sabc=(ac)(bc).

A homomorphism of PCA’s is a homomorphism of the underlying partial applicative structures.

A total combinatory algebra is a PCA A whose application m:A×AA is a total function.

Note that appropriate elements k, s are not considered part of the structure (to be preserved under homomorphism) – here one is interested only in the property that such elements exist. Indeed, they need not be uniquely determined within the PCA.

Functional completeness

The definition of PCA given above is traditional but somewhat opaque at first glance. The real point of the definition is that a PCA is the same thing as a partial applicative structure A that enjoys a functional completeness property, in the following sense.

Let X be a countably infinite set of “variables”, and let A[X] denote the magma freely generated from the disjoint sum A+X. Each term t, i.e., each element tA[X], has finitely many x iX occurring inside it; these are called the free variables of t, and we write FV(t) for the set of free variables. If FV(t){x 0,x 1,,x n}, then we can think of t as giving a partially defined function in n+1 variables. That is, we may consider t as a term of Magma(A+{x 0,,x n}), and (partially) define the substitution t[a 0/x 0,,a n/x n] where a 0,,a n are elements of A, by evaluating at t of the composite

Magma(A+{x 0,,x n})Magma(ϕ)Magma(A)αA\mathbf{Magma}(A + \{x_0, \ldots, x_n\}) \stackrel{\mathbf{Magma}(\phi)}{\to} \mathbf{Magma}(A) \stackrel{\alpha}{\to} A

where ϕ(x i)=a i and is elsewhere the identity.

Then, we say A is functionally complete if every term tA[X], viewed as a partial operation on A, is represented by some element in A. To be precise: for each term t with FV(t){x 0,,x n}, there exists an element aA such that

  • For all a 0,,a n1A, aa 0a n1 is defined;

  • For all a 0,,a nA, t[a 0/x 0,,a n/x n] is defined precisely when aa 0a n is defined, and these two elements are equal.

For example, if k, s are elements which realize A as a PCA, then k represents the term t=x 0 viewed as belonging to Magma(A+{x 0,x 1}), and s represents the term (x 0x 2)(x 1x 2) viewed as belonging to Magma(A+{x 0,x 1,x 2)}.

Theorem

A partial combinatory algebra is functionally complete.

Proof

The idea is to simulate λ-abstraction λx.t, where xX is a variable and t is a term, by induction on t. Indeed, given elements k,s that realize A as a PCA, put

λx.x skk λx.t kt ifxFV(t) λx.tt s(λx.t)(λx.t)\array{ \lambda x. x & \coloneqq & s k k & \\ \lambda x. t & \coloneqq & k t & if x \notin FV(t) \\ \lambda x. t t' & \coloneqq & s(\lambda x. t)(\lambda x. t') }

One then proves equality of partial functions (λx.t)(a)=t[a/x], by induction on t.

Hofstra defines a PCA to be a functionally complete partial applicative structure. This is an unbiased definition, in the sense that it does not privilege certain elements k, s (or, for that matter, any other system of combinators that provide functional completeness).

Examples of combinators

  1. Let us check that skk indeed represents the identity function I. This is trivial: we have, for any aA, equalities between defined terms

    skka=(ka)(ka)=a.s k k a = (k a)(k a) = a.
  2. Consider the second projection function, corresponding to x 1Magma(A+{x 0,x 1}). Thinking in terms of λ-terms, this is represented by λx.λy.y=λx.skk=k(skk), or kI. In other words, we calculate

    kIab=((kI)a)b=Ib=b.k I a b = ((k I) a) b = I b = b.
  3. Following the proof of functional completeness, we have

    λx.xx=s(λx.x)(λx.x)=sII\lambda x. x x = s(\lambda x. x)(\lambda x. x) = s I I
  4. Finally, consider the classical construction of the fixed-point combinator, Y=λy.(λx.y(xx))(λx.y(xx)). We have firstly

    λx.y(xx)=s(λx.y)(λx.xx)=s(ky)(sII)\lambda x. y(x x) = s(\lambda x. y)(\lambda x. x x) = s(k y)(s I I)

    which means

    Y = λy.(sII)(s(ky)(sII)) = s(λy.sII)(λy.s(ky)(sII)) = s(k(sII))(s(λy.s(ky))(λy.sII) = s(k(sII))(s(s(ks)(λy.ky)))(k(sII)) = s(k(sII))(s(s(ks)(s(kk)I)))(k(sII))\array{ Y & = & \lambda y. (s I I)(s(k y)(s I I)) \\ & = & s(\lambda y. s I I)(\lambda y. s(k y)(s I I)) \\ & = & s(k (s I I))(s(\lambda y. s(k y))(\lambda y. s I I) \\ & = & s(k (s I I))(s(s (k s)(\lambda y. k y)))(k (s I I)) \\ & = & s(k (s I I))(s(s (k s)(s(k k)I)))(k (s I I)) }

Examples of PCA’s

  1. (Kleene’s first algebra.) Suppose given a coding of all partial recursive functions of the form

    k\mathbb{N}^k \to \mathbb{N}

    (ranging over k=0,1,2,) by elements of , and a coding of elements of k over all k by elements of . Define a partial applicative structure

    ×\mathbb{N} \times \mathbb{N} \to \mathbb{N}

    where pq={p}([q]) whenever the right side is defined, where {p} is the p th partial recursive function and [q] is the q th tuple. It may be checked that k and s, defined extensionally in the obvious way, are partial recursive functions, so we get in this way a PCA.

  2. Suppose we have a cartesian closed category generated by an object X such that X×X and X X are retracts of X. Then elements 1X form a PCA, in fact a total combinatory algebra, where the applicative structure is

    X×Xr×1 XX X×XevalXX \times X \stackrel{r \times 1_X}{\to} X^X \times X \stackrel{eval}{\to} X

    for some chosen retraction r. In other words, models of the untyped lambda calculus give PCA’s.

  3. Kleene's second algebra.

Realizability toposes

From any PCA, a corresponding “realizability tripos” can be constructed, from which, in turn, a corresponding “realizability topos” can be constructed, as outlined in the article on triposes.

A preliminary technical task is to encode pairing and unpairing functions by elements of A. By this we mean functions p:A×AA, l:AA, r:AA such that for all (a,a)A×A, we have (a,a)=(l(p(a,a)),r(p(a,a))). One way of doing this is to put

  • p=λx.λy.λz.zxy

  • l=λp.p(λx.λy.x)

  • r=λp.p(λx.λy.y)

whereupon we may calculate

paa = λz.zaa l(paa) = (λz.zaa)(λx.λy.x) = (λx.λy.x)aa = (λy.a)a=a\array{ p a a' & = & \lambda z. z a a' \\ l(p a a') & = & (\lambda z. z a a')(\lambda x. \lambda y. x) \\ & = & (\lambda x. \lambda y. x) a a' \\ & = & (\lambda y. a) a' = a }
r(paa) = (λz.zaa)(λx.λy.y) = (λx.λy.y)aa = (λy.y)a=a\array{ r(p a a') & = & (\lambda z. z a a')(\lambda x. \lambda y. y) \\ & = & (\lambda x. \lambda y. y) a a' \\ & = & (\lambda y. y) a' = a' }

That out of the way, let P(A) be the power set of A and let X be a set. Put a preorder structure on P(A) X as follows: given f,gP(A) X, let Hom(f,g) be the set of a in A such that for all x in X and a in f(x), a applied to a is defined and an element of g(x). We will of course take fg just in case Hom(f,g) is inhabited.

Theorem

The preorder P(A) X has finite products, finite coproducts, and is cartesian closed. In other words, the preorder P(A) X is a Heyting prealgebra.

Proof

An initial object is given by the constant function taking each x to the empty subset A, and a terminal object is given by the constant function taking each x to the full subset AA.

Take f,g:XP(A). For binary products, define

(fg)(x)={paaaf(x)ag(x)}(f \wedge g)(x) = \{p a a' | a \in f(x) \wedge a' \in g(x)\}

Notice that l realizes fgf (since l(paa)=a), and similarly r realizes fgg. Furthermore, suppose given h:XP(A), and that tA realizes hf and uA realizes hg. Then

v=λb.p(tb)(ub)v = \lambda b. p (t b)(u b)

realizes hfg. Thus fg is a product in the preorder.

For binary coproducts, define

(fg)(x)={plaaf(x)}{praag(x)}(f \vee g)(x) = \{p l a | a \in f(x)\} \cup \{p r a' | a' \in g(x)\}

Then pl realizes ffg and pr realizes gfg. Furthermore, suppose t realizes fh and u realizes gh. Then

v=λb.l(b)(p(t(rb))(u(rb)))v = \lambda b. l(b)(p(t(r b))(u(r b)))

realizes fgh. Indeed, we have

v(pla) = l(pla)(p(t(r(pla)))(u(r(pla)))) = l(p(ta)(ua)) = ta\array{ v(p l a) & = & l(p l a)(p(t(r(p l a)))(u(r(p l a)))) \\ & = & l(p(t a)(u a)) \\ & = & t a }

and similarly v(pra)=ua. In either case, we see v(b) lives in h(x) for any b(fg)(x).

For cartesian closure, define

(fg)(x)={aaf(x)aaaag(x)}(f \Rightarrow g)(x) = \{a' | \forall a \in f(x) a' a \downarrow \wedge a' a \in g(x)\}

where aa is standard shorthand for ”aa is defined”. Then for any f and g, the combinator λb.l(b)r(b) realizes (fg)fg, and the combinator λb.λa.pab realizes gf(fg).

For any function f:XY, it is immediate that

P(A) f:P(A) YP(A) XP(A)^f \colon P(A)^Y \to P(A)^X

is a functor preorder map that preserves Heyting prealgebra structure.

Furthermore, in the case of a projection map f:Z×YY, there will be left and right adjoints to P(A) f:P(A) YP(A) Z×Y((P(A) Z) Y), as induced by the union and intersection maps from P(A) Z to P(A).

References

Pieter J.W. Hofstra, Partial Combinatory Algebras and Realizability Toposes, (web) (pdf)

Revised on September 8, 2012 00:48:59 by Todd Trimble (67.81.93.25)