Cartesian Closed Categories and Typed Lambda Calculus/Fixed Points in Cartesian Closed Categories

Lesson 8.31,770 words

Fixed Points in Cartesian Closed Categories

The untyped lambda calculus has a fixed-point combinator; the typed calculus cannot, and Lawvere's fixed-point theorem explains why: any point-surjection onto an exponential forces every endomap to have a fixed point, which is the abstract form of Cantor's diagonal argument. Recursion is recovered instead by restricting to omega-complete partially ordered objects, where every continuous endomap has a least fixed point built by iterating from bottom.

╌╌╌╌

The untyped lambda calculus owes much of its interest to the fixed-point combinator , a term satisfying : for every term , the term is a fixed point of . No such combinator can exist in the typed calculus. If there is a type of natural numbers, the successor function is a term of type , and successor has no fixed point.1

Yet recursion needs fixed points. A recursive program

(read: if then else , in Backus's notation) defines as a fixed point of the operator . Without some fixed-point principle, a typed language cannot interpret its own While loops. Two results bound the situation. Lawvere's theorem shows that too many fixed points collapse the category; a construction on the -complete partially ordered objects supplies enough.

Lawvere's fixed-point theorem

The obstruction to a typed is a theorem about cartesian closed categories, not a defect of syntax. Call an arrow point-surjective if every arrow is named by some point of : there exists with

Lawvere's diagonal composite: duplicate the argument, let name a function, evaluate it on the copy, and apply ; point-surjectivity of then forces to have a fixed point.

The theorem reads in both directions:

  • Forward. If a model of the typed lambda calculus contains a type with a point-surjection — a type that can enumerate its own endofunctions, as the untyped calculus does — then every endomap of has a fixed point. This is how models of the untyped calculus must look.
  • Contrapositive. If some endomap of has no fixed point, then no arrow is point-surjective, for any . One fixed-point-free map rules out every enumeration.

The diagonal arguments

The contrapositive is the abstract form of the classical diagonal arguments. Take and . Negation has no fixed point, so no function is surjective. Since functions are exactly subsets of , this is Cantor's theorem: no set surjects onto its own power set. The proof extracted from Lawvere's composite is precisely Cantor's: the set is the transpose of , and it differs from every at the point .

Cantor's diagonal as the contrapositive of Lawvere: list the functions as rows, flip the diagonal, and the flipped row differs from every listed row, so misses it.

The same skeleton yields Russell's paradox (take the universe of sets), Gödel-style self-reference (take an enumeration of definable predicates), and Tarski's undefinability theorem. In each case a diagonal composite plus one fixed-point-free endomap contradicts surjectivity.

For semantics this is a no-go theorem. A model of a programming language would ideally provide three things: cartesian closure, a fixed point for every endomap of every type (general recursion), and non-degenerate data types (some type with two distinct points, such as booleans). Lawvere's theorem shows these are inconsistent: if booleans exist, negation has no fixed point. Requiring fixed points for all endomaps of all objects collapses the category to triviality, and Barr & Wells note the sharpened forms of this inconsistency due to Huwig and Poigné.1 Fixed points must therefore be demanded only for some endomaps of some objects: enough to interpret loops, few enough to avoid collapse.

Ordered objects in a cartesian closed category

The objects that carry fixed points are those with enough order structure to support a limiting process. The definitions internalize the -CPOs of domain theory into an arbitrary cartesian closed category, by ordering hom-sets rather than elements.

Continuity implies monotonicity: exactly when the chain has supremum , and a continuous arrow preserves that supremum. In these definitions recover the ordinary -CPOs, and the category of -CPOs with continuous maps is itself cartesian closed.

The least fixed point

On strict -CPO objects, continuous endomaps do have fixed points, and the construction is iteration from the bottom.

The least fixed point is the supremum of the chain of iterates from bottom; here , each arrow applies , and the limit satisfies .

The chain climbs by successive approximation and the fixed point is its limit. The loop on records the defining equation . This is the same construction as the initial algebra built by iterating an endofunctor, one level down: there the chain lives in a category of objects, here in a poset of approximants.

Semantics of recursive programs

The fixed points needed for programming are not on the base data types. On with its usual order, squaring is not even monotone, and successor has no fixed point at all; nothing in the theory applies to them, and nothing should. The objects that need fixed points are the arrow types: the operator is an endomap of a function object, and it is there that the order structure lives.4

The order is by definedness. Given any object of data (no order assumed), adjoin a fresh bottom element:

A flat order is trivially -complete: an increasing chain is either constantly or eventually a single constant. An arrow is a partial arrow : it sends the arguments outside its domain of definition to . Under mild assumptions on the category (true in ), the exponential is again an -CPO object, because a chain of arrows transposes to a chain , which has a supremum by assumption. The induced order on is extension of domain:

Every continuous endomap of therefore has a least fixed point, and this is all a recursive definition requires. For the Backus form , the operator is an endomap of ; when is continuous, so is , and interprets the program. The iterates from are the finite unrollings of the loop. With :

Algorithm:Unroll(p,q,g,h,x)\textsc{Unroll}(p, q, g, h, x) — the iterates of Φ\Phi from \bot as nested conditionals
  1. 1
    if p(x)p(x) then
  2. 2
    output q(x)q(x)
  3. 3
    else if p(h(x))p(h(x)) then
  4. 4
    output g(q(h(x)))g(q(h(x)))
  5. 5
    else if p(h(h(x)))p(h(h(x))) then
  6. 6
    output g(g(q(h(h(x)))))g(g(q(h(h(x)))))
  7. 7
    \vdots
  8. 8
    else if p(hn(x))p(h^n(x)) then
  9. 9
    output gn(q(hn(x)))g^n(q(h^n(x)))
  10. 10
    \vdots

The -th iterate is the partial function defined on precisely those inputs that exit the loop within tests; each iterate extends the domain of the last and never revises a value already produced, which is monotonicity in the extension order; and the supremum — the program's meaning — is defined on exactly the inputs for which the loop terminates. If the guard never succeeds on , every iterate is at and so is the fixed point: nontermination is denoted by , not by an error. The fixed point is syntactic existence, not a termination guarantee — the least fixed point of the identity operator is the everywhere-undefined function, the denotation of the canonical infinite loop.

Continuity of must be checked, once, for the constructors of the language: constants, projection onto a component of a tuple of functions, and composition with fixed functions ( for simpler continuous forms ) all yield continuous operators, so every loop built from them has a semantics.4

SettingFixed points availableCost
untyped lambda calculusevery term, via no types; is the nonterminating loop
typed lambda calculus / bare CCCnone guaranteed; all endomaps only if degenerateno general recursion
CCC with strict -CPO objectsevery continuous endomap of an ordered objectrecursion only at ordered (arrow) types; enters the semantics

Concept dependencies

A cartesian closed category and the typed lambda calculus present the same theory, with recursion supplied by order-theoretic fixed points and bounded by Lawvere's diagonal theorem.

The course's concept dependencies: each result stands on the ones below it, and the three readings of a CCC — functions, logic, programs — meet in this module.

Read bottom to top, a category is objects and arrows under composition; universal properties characterize constructions up to unique isomorphism; functors and natural transformations compare categories and functors; the Yoneda lemma says an object is determined by its arrows in; limits and colimits build objects from diagrams; adjunctions pair the building with the forgetting, and right adjoints preserve limits. From adjunctions two roads lead into computing: monads and their Kleisli categories model effects, while the product-exponential adjunction of a cartesian closed category models functions themselves — and, by this module's equivalence, is the typed lambda calculus. Lawvere's theorem bounds this world by a diagonal argument, and domain-theoretic order structure supplies the recursion a programming language needs.

Footnotes

  1. Barr & Wells, Category Theory for Computing Science, §6.6.1 — the untyped fixed-point combinator , the impossibility of typing it (successor has no fixed point), the Backus form , and the inconsistency of all-objects fixed points with other desirable assumptions (citing Huwig and Poigné). 2
  2. F. W. Lawvere, Diagonal arguments and cartesian closed categories (1969), reprinted as TAC Reprints no. 15 — http://www.tac.mta.ca/tac/reprints/articles/15/tr15abs.html. The theorem, its proof by the diagonal composite, and the derivation of Cantor, Russell, and Gödel-style arguments as contrapositives.
  3. Barr & Wells, §6.6.2–6.6.3 — partially ordered objects, -CPO objects, strictness, -continuous arrows, and the least-fixed-point proposition with the iteration-from-bottom proof.
  4. Barr & Wells, §6.6.4 — application to programs: fixed points at arrow types rather than data types, the flat CPO , the extension-of-domain order on , the infinite unrolling of , and the continuity of Backus's functional forms. 2

╌╌ END ╌╌