In this article, we consider the domain-theoretic semantics of PCF. This provides some insight into the properties of CPOs, and also provides the basis for semantic reasoning about PCF.
We show soundness of the PCF equational axioms system, and therefore the reduction rules, for our CPO model, called . It is impossible for the PCF equational proof system to be complete for proving all equations between PCF terms that hold in PCF. The reason is that, as shown in Easy Foundations for Programming Languages V — PCF Iteration and Recursion, every partial recursive function is definable in PCF.
By soundness, and the fact that all the numerals denote distinct elements of the model, two expressions of type will be equal in PCF iff they operationally define the same partial recursive function. Since equality between partial recursive functions is not recursively enumerable, no recursive axiom system could be complete for .
CPO Model for PCF
The model is the full continuous hierarchy over and , with constants of PCF interpreted as described below.
Since the type constants of PCF are interpreted as pointed CPOs, and cartesian product and continuous function constractors preserve pointedness, all of the type of PCF are interpreted as pointed CPOs. This gives us least-fixed-point operators at all types, allowing us to interpret the fixed-point constants of PCF according to Lemma 1 in the last article.
We interpret constants and as the standard natural numbers and boolean elements of the lifted set and . If we choose continuous functions for basic PCF operations , and conditional, then every term of PCF will have a meaning in . It follows that every term in PCF has a fixed point.
We interpret and in as the lifted versions, and , of the standard functions. In other words, we interpret as the extension of addition that is strict in both arguments, so that for every ,
We treat the PCF equality test similarly, so that the PCF expression has value if and denote the same element of different from , value if and denote different non- elements of , and value if either and denotes .
The interpretation of conditional in is a little subtle. You may guess that we could also interpret conditional as a strict function, with value of the appropriate type whenever any of its arguments is of some type. However, this does not work, since in the case that denotes but does not, we would have
which contradicts an equational axiom of PCF.
Recall that we have the following equational axioms for conditional discussed in Easy Foundations for Programming Languages III — The Language PCF & Its Syntax.
An interpretation of conditional that satisfies the equational axioms of PCF is the following.
Since the equational axioms of PCF only mention conditional expressions when the first argument is or , it is easy to see that the axioms are satisfied. This completes the definition of .
Now we have the following immediate consequences of the general soundness theorem for Henkin models.
(Theorem 1.) Let and be expressions of PCF over typed variables from . If is provable from the axioms for PCF, then the CPO model satisfies the equation .
(Corollary 1.) If is a well-typed term of PCF, and , then the CPO model satisfies the equation .
These soundness results show that the denotational semantics given by has the minimal properties required of any denotational semantics. Specifically, if we can prove , or reduce one term to the other, then these two terms will have the same meaning in . It follows that if two terms have different meanings, then we cannot prove them equal or reduce one to the other. Therefore, we can use to reason about unprovability or the non-existence of reductions.
Examples
In this section, we will use two examples to illustrate how to work out the meaning of some expressions in and make some comments about the difference between the least fixed point of a function and other fixed points.
Ex.1 Factorial Function
Recall that the factorial function may be written , where is the expression
We will work out the meaning of this closed term assuming that and denote multiplication and subtraction functions which are strict extensions of the standard ones. In other words, we assume that multiplication and subtraction have their standard meaning on non-least elements of , but have value if either of their arguments is .
Following the definition of in a CPO, we can see that the meaning of factorial is the least upper bound of a directed set. Specifically, is the least upper bound , where . We will work out the first few cases of to understand what this means.
Since all of the lambda terms involved are closed, we will dispense with the formality of writing and use lambda terms as names for elements of the appropriate domains.
Continuing in this way, we can see that is the function which computes whenever and has value otherwise. Since represents “undefined,” this means that is defined for and undefined otherwise.
A property of this collection of functions is that for a particular argument , there are two possible values for — if , then the value is , while if , the value is .
As spelled out in the statement of Lemma 4 in the CPO article, the least upper bound of is the function mapping any to the least upper bound of the set . The set contains only , if , and has two elements and otherwise. Therefore is the function from to which maps to , and any other to .
Such strictness of factorial agrees with our computational intuition and experience, since we do not expect any computation of to terminate if the expression cannot be simplified to a numeral. But in the case reduces to a numeral for , we can reduce to the numeral for .
In general, the least fixed point of a function is the fixed point that is “computed in practice.” Later we will formally show that the PCF operational and denotational semantics coincide. Simply put, the least fixed point of a function has all the properties of that we can determine by applying -reduction some number of times.
Ex.2 Function with Many Fixed Points
This example illustrates the difference between the least fixed point of a function and other fixed points.
Consider the function defined by
where subtraction yields if .
In contrast to the function used to define factorial, we will see that has many fixed points. The reason is that is a function mapping even arguments to . This allows us to find greater fixed points (in the point-wise order) which map even arguments to natural numbers other than .
Before discussing alternate fixed points further, we will work out the meaning of .
As in factorial, we let . The least fixed point of is the least upper bound of the set . The simplest way to understand this set is to begin by working out the first few functions.
Continuing in this way, we can see that is the function which maps any odd to and has value otherwise. The least upper bound of all such functions is the function mapping all odd to , and any other natural number to .
This corresponds to the fact that if we try to compute the value of by reduction, we will succeed after a finite number of reduction steps iff is odd. If is even, we can reduce the expression indefinitely, but will never produce a numeral.
It is not hard to see that the fixed points of above are precisely the functions satisfying the two conditions:
Since these two equations do not determine a value for even , any function mapping all even (and ) to some number will be a fixed point of . All of these alternatives are greater than since any natural number is greater than in the ordering on the lifted CPO of natural numbers. However, none of these alternative fixed points is the function computed by reduction.
Fixed-Point Induction
The equational proof system for PCF is sound for the CPO model and other semantic models of PCF. It is adequate to specify the result of any program — if is closed, and denotes a number in the CPO model , then we can prove .
However, the equational proof system is not very powerful when it comes to proving equations between parts of programs, such as terms defining functions. This is illustrated in the example below.
In this section, we study an extension to the equational proof system that has been found, in practice, to be sufficient for proving many equations between PCF terms.
Ex. 3 Equation of Function Terms
If and are continuous functions on some CPO , then it is not hard to see that . The reason is that
by monotonicity, general facts about least upper bound, and the associativity of composition.
In the rest of this example, we show that there is no equational proof of , treating and as variables of type , for any type , using only the equational proof system of PCF.
There are two facts about PCF:
- The reduction rules of PCF are confluent;
- The reduction rules of PCF are exactly directed versions of the equational axioms, plus symmetry, transitivity and congruence rules.
Based on these, we know that the equation is provable iff both terms reduce to a common term. However, an easy induction shows that any term obtained by reducing will have an equal number of ’s and ’s, while terms obtained from will have more than . Therefore, we cannot prove using the equational proof system.
Extended Proof System
The extended proof system is based on the CPO interpretation of terms. In addition to equations, we will use formulas which assert that the meaning of one term is an approximation of another. More specifically, we use assertions of the form or, written out with type assignments, . To be precise, an approximation is satisfied at environment for CPO model if .
The proof system given in this section is sound for deriving assertions that hold in all CPO models. A common way of reading is, “ is an approximation of .”
One obvious inference rule is
which allows us to derive approximations from equations. This rule may be used to derive versions of the and axioms using approximation in place of equality.
A “converse” to this rule is
which is sound since a partial order is anti-symmetric. This rule lets us derive equations from approximations.
Since is transitive, we also have the rule
If we add a constant to the language, for each type , then we write the axiom scheme
since is the least element of type . The tag “bot” stands for the “bottom” element.
We also know that the least element of a function type is the function mapping each argument to . This gives us the equational axiom scheme
We also have a congruence rule for each syntactic form. For application, the rule
tells us that every continuous function is monotonic. The congruence rule for lambda abstraction
is sound since we order functions point-wise.
The final rule is an induction rule for fixed points. From the equational axiom for fixed points, we can prove that , and similar properties that follow from being a fixed point of . However, in the standard equational proof system, there is no obvious way to make use of the fact that is the least fixed point of . With approximations instead of equations, we could write a rule
saying that is an approximation to any fixed point of . This follows from the more powerful rule of “fixed point induction”, also called Scott induction after Dana Scott.
In stating the rule of fixed point induction, we write to mean that the equation or approximation is provable from the set of equations and approximations using the axioms and inference rules given here, combined with the equational axioms and inference rules of typed lambda calculus with fixed points and any additional equational hypotheses (such as axioms for algebraic datatypes).
If has the form , then we write for the result of removing variable from the type assignment and substituting for in both terms, assuming . If is an equation, we define similarly.
Using this notation, the rule to find the fixed point is written as follows.
If we think of as a way of saying that the variable has some property, then says that this property holds for . The second hypothesis, , is a way of saying that if this property holds for some arbitrary . then it holds for . If follows that this property holds for every element of , by induction on . Using the fact that the value of any term depends continuously on each of its free variables, we can easily verify that the property holds for the least upper bound of this set, namely . This gives us the conclusion of the fixed point induction rule.
A feature of fixed-point induction is that we reason implicitly about sets of form without introducing natural numbers into the formal system. While the soundness proof for fixed-point induction uses induction on the integers, the proof system only uses formulas such as approximation or equality.
Ex 4. Fixed-Point Induction Example
To illustrate the use of fixed-point induction, we will show that if is a fixed point of , then .
We assume (according to the definition of fixed point), which gives us
since equality implies approximation. This will be useful at a later step of the proof.
Let us now think about how we can use the fixed point induction rule. The conclusion of the rule has the form , which matches the statement we wish to prove if we take
with not free in , and let be . Reading the fixed point induction rule from the bottom up, we can see that it suffices to prove
which is an axiom, and to show that we can prove
if we take as an additional hypothesis.
If we begin with , then by monotonicity (the “congruence rule” for application), we have
But since we have already proved above, this gives us
which is exactly what we need in order to finish the proof by fixed point induction.