module plfa.part3.Denotational where


The lambda calculus is a language about functions, that is, mappings from input to output. In computing we often think of such mappings as being carried out by a sequence of operations that transform an input into an output. But functions can also be represented as data. For example, one can tabulate a function, that is, create a table where each row has two entries, an input and the corresponding output for the function. Function application is then the process of looking up the row for a given input and reading off the output.

We shall create a semantics for the untyped lambda calculus based on this idea of functions-as-tables. However, there are two difficulties that arise. First, functions often have an infinite domain, so it would seem that we would need infinitely long tables to represent functions. Second, in the lambda calculus, functions can be applied to functions. They can even be applied to themselves! So it would seem that the tables would contain cycles. One might start to worry that advanced techniques are necessary to address these issues, but fortunately this is not the case!

The first problem, of functions with infinite domains, is solved by observing that in the execution of a terminating program, each lambda abstraction will only be applied to a finite number of distinct arguments. (We come back later to discuss diverging programs.) This observation is another way of looking at Dana Scottβs insight that only continuous functions are needed to model the lambda calculus.

The second problem, that of self-application, is solved by relaxing the way in which we lookup an argument in a functionβs table. Naively, one would look in the table for a row in which the input entry exactly matches the argument. In the case of self-application, this would require the table to contain a copy of itself. Impossible! (At least, it is impossible if we want to build tables using inductive data type definitions, which indeed we do.) Instead it is sufficient to find an input such that every row of the input appears as a row of the argument (that is, the input is a subset of the argument). In the case of self-application, the table only needs to contain a smaller copy of itself, which is fine.

With these two observations in hand, it is straightforward to write down a denotational semantics of the lambda calculus.

## Imports

open import Agda.Primitive using (lzero; lsuc)
open import Data.Empty using (β₯-elim)
open import Data.Nat using (β; zero; suc)
open import Data.Product using (_Γ_; Ξ£; Ξ£-syntax; β; β-syntax; projβ; projβ)
open import Data.Sum
open import Data.Vec using (Vec; []; _β·_)
open import Relation.Binary.PropositionalEquality
using (_β‘_; _β’_; refl; sym; cong; congβ; cong-app)
open import Relation.Nullary using (Β¬_)
open import Function using (_β_)
open import plfa.part2.Untyped
using (Context; β; _β_; β; _,_; Z; S_; _β’_; _; _Β·_; Ζ_;
#_; twoαΆ; ext; rename; exts; subst; subst-zero; _[_])
open import plfa.part2.Substitution using (Rename; extensionality; rename-id)


## Values

The Value data type represents a finite portion of a function. We think of a value as a finite set of pairs that represent input-output mappings. The Value data type represents the set as a binary tree whose internal nodes are the union operator and whose leaves represent either a single mapping or the empty set.

• The β₯ value provides no information about the computation.

• A value of the form v β¦ w is a single input-output mapping, from input v to output w.

• A value of the form v β w is a function that maps inputs to outputs according to both v and w. Think of it as taking the union of the two sets.

infixr 7 _β¦_
infixl 5 _β_

data Value : Set where
β₯ : Value
_β¦_ : Value β Value β Value
_β_ : Value β Value β Value


The β relation adapts the familiar notion of subset to the Value data type. This relation plays the key role in enabling self-application. There are two rules that are specific to functions, β-fun and β-dist, which we discuss below.

infix 4 _β_

data _β_ : Value β Value β Set where

β-bot : β {v} β β₯ β v

β-conj-L : β {u v w}
β v β u
β w β u
-----------
β (v β w) β u

β-conj-R1 : β {u v w}
β u β v
-----------
β u β (v β w)

β-conj-R2 : β {u v w}
β u β w
-----------
β u β (v β w)

β-trans : β {u v w}
β u β v
β v β w
-----
β u β w

β-fun : β {v w vβ² wβ²}
β vβ² β v
β w β wβ²
-------------------
β (v β¦ w) β (vβ² β¦ wβ²)

β-dist : β{v w wβ²}
---------------------------------
β v β¦ (w β wβ²) β (v β¦ w) β (v β¦ wβ²)


The first five rules are straightforward. The rule β-fun captures when it is OK to match a higher-order argument vβ² β¦ wβ² to a table entry whose input is v β¦ w. Considering a call to the higher-order argument. It is OK to pass a larger argument than expected, so v can be larger than vβ². Also, it is OK to disregard some of the output, so w can be smaller than wβ². The rule β-dist says that if you have two entries for the same input, then you can combine them into a single entry and joins the two outputs.

The β relation is reflexive.

β-refl : β {v} β v β v
β-refl {β₯} = β-bot
β-refl {v β¦ vβ²} = β-fun β-refl β-refl
β-refl {vβ β vβ} = β-conj-L (β-conj-R1 β-refl) (β-conj-R2 β-refl)


The β operation is monotonic with respect to β, that is, given two larger values it produces a larger value.

βββ : β {v w vβ² wβ²}
β v β vβ²  β  w β wβ²
-----------------------
β (v β w) β (vβ² β wβ²)
βββ dβ dβ = β-conj-L (β-conj-R1 dβ) (β-conj-R2 dβ)


The β-dist rule can be used to combine two entries even when the input values are not identical. One can first combine the two inputs using β and then apply the β-dist rule to obtain the following property.

ββ¦β-dist : β{v vβ² w wβ² : Value}
β (v β vβ²) β¦ (w β wβ²) β (v β¦ w) β (vβ² β¦ wβ²)
ββ¦β-dist = β-trans β-dist (βββ (β-fun (β-conj-R1 β-refl) β-refl)
(β-fun (β-conj-R2 β-refl) β-refl))


If the join u β v is less than another value w, then both u and v are less than w.

ββ-invL : β{u v w : Value}
β u β v β w
---------
β u β w
ββ-invL (β-conj-L lt1 lt2) = lt1
ββ-invL (β-conj-R1 lt) = β-conj-R1 (ββ-invL lt)
ββ-invL (β-conj-R2 lt) = β-conj-R2 (ββ-invL lt)
ββ-invL (β-trans lt1 lt2) = β-trans (ββ-invL lt1) lt2

ββ-invR : β{u v w : Value}
β u β v β w
---------
β v β w
ββ-invR (β-conj-L lt1 lt2) = lt2
ββ-invR (β-conj-R1 lt) = β-conj-R1 (ββ-invR lt)
ββ-invR (β-conj-R2 lt) = β-conj-R2 (ββ-invR lt)
ββ-invR (β-trans lt1 lt2) = β-trans (ββ-invR lt1) lt2


## Environments

An environment gives meaning to the free variables in a term by mapping variables to values.

Env : Context β Set
Env Ξ = β (x : Ξ β β) β Value


We have the empty environment, and we can extend an environment.

β : Env β
β ()

infixl 5 _,_

_,_ : β {Ξ} β Env Ξ β Value β Env (Ξ , β)
(Ξ³ , v) Z = v
(Ξ³ , v) (S x) = Ξ³ x


We can recover the previous environment from an extended environment, and the last value. Putting them together again takes us back to where we started.

init : β {Ξ} β Env (Ξ , β) β Env Ξ
init Ξ³ x = Ξ³ (S x)

last : β {Ξ} β Env (Ξ , β) β Value
last Ξ³ = Ξ³ Z

init-last : β {Ξ} β (Ξ³ : Env (Ξ , β)) β Ξ³ β‘ (init Ξ³ , last Ξ³)
init-last {Ξ} Ξ³ = extensionality lemma
where lemma : β (x : Ξ , β β β) β Ξ³ x β‘ (init Ξ³ , last Ξ³) x
lemma Z      =  refl
lemma (S x)  =  refl


We extend the β relation point-wise to environments with the following definition.

_β_ : β {Ξ} β Env Ξ β Env Ξ β Set
_β_ {Ξ} Ξ³ Ξ΄ = β (x : Ξ β β) β Ξ³ x β Ξ΄ x


We define a bottom environment and a join operator on environments, which takes the point-wise join of their values.

β₯ : β {Ξ} β Env Ξ
β₯ x = β₯

_β_ : β {Ξ} β Env Ξ β Env Ξ β Env Ξ
(Ξ³ β Ξ΄) x = Ξ³ x β Ξ΄ x


The β-refl, β-conj-R1, and β-conj-R2 rules lift to environments. So the join of two environments Ξ³ and Ξ΄ is greater than the first environment Ξ³ or the second environment Ξ΄.

β-refl : β {Ξ} {Ξ³ : Env Ξ} β Ξ³ β Ξ³
β-refl {Ξ} {Ξ³} x = β-refl {Ξ³ x}

β-env-conj-R1 : β {Ξ} β (Ξ³ : Env Ξ) β (Ξ΄ : Env Ξ) β Ξ³ β (Ξ³ β Ξ΄)
β-env-conj-R1 Ξ³ Ξ΄ x = β-conj-R1 β-refl

β-env-conj-R2 : β {Ξ} β (Ξ³ : Env Ξ) β (Ξ΄ : Env Ξ) β Ξ΄ β (Ξ³ β Ξ΄)
β-env-conj-R2 Ξ³ Ξ΄ x = β-conj-R2 β-refl


## Denotational Semantics

We define the semantics with a judgment of the form Ο β’ M β v, where Ο is the environment, M the program, and v is a result value. For readers familiar with big-step semantics, this notation will feel quite natural, but donβt let the similarity fool you. There are subtle but important differences! So here is the definition of the semantics, which we discuss in detail in the following paragraphs.

infix 3 _β’_β_

data _β’_β_ : β{Ξ} β Env Ξ β (Ξ β’ β) β Value β Set where

var : β {Ξ} {Ξ³ : Env Ξ} {x}
---------------
β Ξ³ β’ ( x) β Ξ³ x

β¦-elim : β {Ξ} {Ξ³ : Env Ξ} {L M v w}
β Ξ³ β’ L β (v β¦ w)
β Ξ³ β’ M β v
---------------
β Ξ³ β’ (L Β· M) β w

β¦-intro : β {Ξ} {Ξ³ : Env Ξ} {N v w}
β Ξ³ , v β’ N β w
-------------------
β Ξ³ β’ (Ζ N) β (v β¦ w)

β₯-intro : β {Ξ} {Ξ³ : Env Ξ} {M}
---------
β Ξ³ β’ M β β₯

β-intro : β {Ξ} {Ξ³ : Env Ξ} {M v w}
β Ξ³ β’ M β v
β Ξ³ β’ M β w
---------------
β Ξ³ β’ M β (v β w)

sub : β {Ξ} {Ξ³ : Env Ξ} {M v w}
β Ξ³ β’ M β v
β w β v
---------
β Ξ³ β’ M β w


Consider the rule for lambda abstractions, β¦-intro. It says that a lambda abstraction results in a single-entry table that maps the input v to the output w, provided that evaluating the body in an environment with v bound to its parameter produces the output w. As a simple example of this rule, we can see that the identity function maps β₯ to β₯ and also that it maps β₯ β¦ β₯ to β₯ β¦ β₯.

id : β β’ β
id = Ζ # 0

denot-id1 : β {Ξ³} β Ξ³ β’ id β β₯ β¦ β₯
denot-id1 = β¦-intro var

denot-id2 : β {Ξ³} β Ξ³ β’ id β (β₯ β¦ β₯) β¦ (β₯ β¦ β₯)
denot-id2 = β¦-intro var


Of course, we will need tables with many rows to capture the meaning of lambda abstractions. These can be constructed using the β-intro rule. If term M (typically a lambda abstraction) can produce both tables v and w, then it produces the combined table v β w. One can take an operational view of the rules β¦-intro and β-intro by imagining that when an interpreter first comes to a lambda abstraction, it pre-evaluates the function on a bunch of randomly chosen arguments, using many instances of the rule β¦-intro, and then joins them into a big table using many instances of the rule β-intro. In the following we show that the identity function produces a table containing both of the previous results, β₯ β¦ β₯ and (β₯ β¦ β₯) β¦ (β₯ β¦ β₯).

denot-id3 : β β’ id β (β₯ β¦ β₯) β (β₯ β¦ β₯) β¦ (β₯ β¦ β₯)
denot-id3 = β-intro denot-id1 denot-id2


We most often think of the judgment Ξ³ β’ M β v as taking the environment Ξ³ and term M as input, producing the result v. However, it is worth emphasizing that the semantics is a relation. The above results for the identity function show that the same environment and term can be mapped to different results. However, the results for a given Ξ³ and M are not too different, they are all finite approximations of the same function. Perhaps a better way of thinking about the judgment Ξ³ β’ M β v is that the Ξ³, M, and v are all inputs and the semantics either confirms or denies whether v is an accurate partial description of the result of M in environment Ξ³.

Next we consider the meaning of function application as given by the β¦-elim rule. In the premise of the rule we have that L maps v to w. So if M produces v, then the application of L to M produces w.

As an example of function application and the β¦-elim rule, we apply the identity function to itself. Indeed, we have both that β β’ id β (u β¦ u) β¦ (u β¦ u) and also β β’ id β (u β¦ u), so we can apply the rule β¦-elim.

id-app-id : β {u : Value} β β β’ id Β· id β (u β¦ u)
id-app-id {u} = β¦-elim (β¦-intro var) (β¦-intro var)


Next we revisit the Church numeral two: Ξ» f. Ξ» u. (f (f u)). This function has two parameters: a function f and an arbitrary value u, and it applies f twice. So f must map u to some value, which weβll name v. Then for the second application, f must map v to some value. Letβs name it w. So the functionβs table must include two entries, both u β¦ v and v β¦ w. For each application of the table, we extract the appropriate entry from it using the sub rule. In particular, we use the β-conj-R1 and β-conj-R2 to select u β¦ v and v β¦ w, respectively, from the table u β¦ v β v β¦ w. So the meaning of twoαΆ is that it takes this table and parameter u, and it returns w. Indeed we derive this as follows.

denot-twoαΆ : β{u v w : Value} β β β’ twoαΆ β ((u β¦ v β v β¦ w) β¦ u β¦ w)
denot-twoαΆ {u}{v}{w} =
β¦-intro (β¦-intro (β¦-elim (sub var lt1) (β¦-elim (sub var lt2) var)))
where lt1 : v β¦ w β u β¦ v β v β¦ w
lt1 = β-conj-R2 (β-fun β-refl β-refl)

lt2 : u β¦ v β u β¦ v β v β¦ w
lt2 = (β-conj-R1 (β-fun β-refl β-refl))


Next we have a classic example of self application: Ξ = Ξ»x. (x x). The input value for x needs to be a table, and it needs to have an entry that maps a smaller version of itself, call it v, to some value w. So the input value looks like v β¦ w β v. Of course, then the output of Ξ is w. The derivation is given below. The first occurrences of x evaluates to v β¦ w, the second occurrence of x evaluates to v, and then the result of the application is w.

Ξ : β β’ β
Ξ = (Ζ (# 0) Β· (# 0))

denot-Ξ : β {v w} β β β’ Ξ β ((v β¦ w β v) β¦ w)
denot-Ξ = β¦-intro (β¦-elim (sub var (β-conj-R1 β-refl))
(sub var (β-conj-R2 β-refl)))


One might worry whether this semantics can deal with diverging programs. The β₯ value and the β₯-intro rule provide a way to handle them. (The β₯-intro rule is also what enables Ξ² reduction on non-terminating arguments.) The classic Ξ© program is a particularly simple program that diverges. It applies Ξ to itself. The semantics assigns to Ξ© the meaning β₯. There are several ways to derive this, we shall start with one that makes use of the β-intro rule. First, denot-Ξ tells us that Ξ evaluates to ((β₯ β¦ β₯) β β₯) β¦ β₯ (choose vβ = vβ = β₯). Next, Ξ also evaluates to β₯ β¦ β₯ by use of β¦-intro and β₯-intro and to β₯ by β₯-intro. As we saw previously, whenever we can show that a program evaluates to two values, we can apply β-intro to join them together, so Ξ evaluates to (β₯ β¦ β₯) β β₯. This matches the input of the first occurrence of Ξ, so we can conclude that the result of the application is β₯.

Ξ© : β β’ β

denot-Ξ© = β¦-elim denot-Ξ (β-intro (β¦-intro β₯-intro) β₯-intro)


A shorter derivation of the same result is by just one use of the β₯-intro rule.

denot-Ξ©' : β β’ Ξ© β β₯


Just because one can derive β β’ M β β₯ for some closed term M doesnβt mean that M necessarily diverges. There may be other derivations that conclude with M producing some more informative value. However, if the only thing that a term evaluates to is β₯, then it indeed diverges.

An attentive reader may have noticed a disconnect earlier in the way we planned to solve the self-application problem and the actual β¦-elim rule for application. We said at the beginning that we would relax the notion of table lookup, allowing an argument to match an input entry if the argument is equal or greater than the input entry. Instead, the β¦-elim rule seems to require an exact match. However, because of the sub rule, application really does allow larger arguments.

β¦-elim2 : β {Ξ} {Ξ³ : Env Ξ} {Mβ Mβ vβ vβ vβ}
β Ξ³ β’ Mβ β (vβ β¦ vβ)
β Ξ³ β’ Mβ β vβ
β vβ β vβ
------------------
β Ξ³ β’ (Mβ Β· Mβ) β vβ
β¦-elim2 dβ dβ lt = β¦-elim dβ (sub dβ lt)


#### Exercise denot-plusαΆ (practice)

What is a denotation for plusαΆ? That is, find a value v (other than β₯) such that β β’ plusαΆ β v. Also, give the proof of β β’ plusαΆ β v for your choice of v.

-- Your code goes here


## Denotations and denotational equality

Next we define a notion of denotational equality based on the above semantics. Its statement makes use of an if-and-only-if, which we define as follows.

_iff_ : Set β Set β Set
P iff Q = (P β Q) Γ (Q β P)


Another way to view the denotational semantics is as a function that maps a term to a relation from environments to values. That is, the denotation of a term is a relation from environments to values.

Denotation : Context β Setβ
Denotation Ξ = (Env Ξ β Value β Set)


The following function β° gives this alternative view of the semantics, which really just amounts to changing the order of the parameters.

β° : β{Ξ} β (M : Ξ β’ β) β Denotation Ξ
β° M = Ξ» Ξ³ v β Ξ³ β’ M β v


In general, two denotations are equal when they produce the same values in the same environment.

infix 3 _β_

_β_ : β {Ξ} β (Denotation Ξ) β (Denotation Ξ) β Set
(_β_ {Ξ} Dβ Dβ) = (Ξ³ : Env Ξ) β (v : Value) β Dβ Ξ³ v iff Dβ Ξ³ v


Denotational equality is an equivalence relation.

β-refl : β {Ξ : Context} β {M : Denotation Ξ}
β M β M
β-refl Ξ³ v = β¨ (Ξ» x β x) , (Ξ» x β x) β©

β-sym : β {Ξ : Context} β {M N : Denotation Ξ}
β M β N
-----
β N β M
β-sym eq Ξ³ v = β¨ (projβ (eq Ξ³ v)) , (projβ (eq Ξ³ v)) β©

β-trans : β {Ξ : Context} β {Mβ Mβ Mβ : Denotation Ξ}
β Mβ β Mβ
β Mβ β Mβ
-------
β Mβ β Mβ
β-trans eq1 eq2 Ξ³ v = β¨ (Ξ» z β projβ (eq2 Ξ³ v) (projβ (eq1 Ξ³ v) z)) ,
(Ξ» z β projβ (eq1 Ξ³ v) (projβ (eq2 Ξ³ v) z)) β©


Two terms M and N are denotational equal when their denotations are equal, that is, β° M β β° N.

The following submodule introduces equational reasoning for the β relation.

module β-Reasoning {Ξ : Context} where

infix  1 start_
infix  3 _β

start_ : β {x y : Denotation Ξ}
β x β y
-----
β x β y
start xβy  =  xβy

_ββ¨_β©_ : β (x : Denotation Ξ) {y z : Denotation Ξ}
β x β y
β y β z
-----
β x β z
(x ββ¨ xβy β© yβz) =  β-trans xβy yβz

_ββ¨β©_ : β (x : Denotation Ξ) {y : Denotation Ξ}
β x β y
-----
β x β y

_β : β (x : Denotation Ξ)
-----
β x β x
(x β)  =  β-refl


## Road map for the following chapters

The subsequent chapters prove that the denotational semantics has several desirable properties. First, we prove that the semantics is compositional, i.e., that the denotation of a term is a function of the denotations of its subterms. To do this we shall prove equations of the following shape.

β° ( x) β ...
β° (Ζ M) β ... β° M ...
β° (M Β· N) β ... β° M ... β° N ...


The compositionality property is not trivial because the semantics we have defined includes three rules that are not syntax directed: β₯-intro, β-intro, and sub. The above equations suggest that the dentoational semantics can be defined as a recursive function, and indeed, we give such a definition and prove that it is equivalent to β°.

Next we investigate whether the denotational semantics and the reduction semantics are equivalent. Recall that the job of a language semantics is to describe the observable behavior of a given program M. For the lambda calculus there are several choices that one can make, but they usually boil down to a single bit of information:

• divergence: the program M executes forever.
• termination: the program M halts.

We can characterize divergence and termination in terms of reduction.

• divergence: Β¬ (M ββ  Ζ N) for any term N.
• termination: M ββ  Ζ N for some term N.

We can also characterize divergence and termination using denotations.

• divergence: Β¬ (β β’ M β v β¦ w) for any v and w.
• termination: β β’ M β v β¦ w for some v and w.

Alternatively, we can use the denotation function β°.

• divergence: Β¬ (β° M β β° (Ζ N)) for any term N.
• termination: β° M β β° (Ζ N) for some term N.

So the question is whether the reduction semantics and denotational semantics are equivalent.

(β N. M ββ  Ζ N)  iff  (β N. β° M β β° (Ζ N))


We address each direction of the equivalence in the second and third chapters. In the second chapter we prove that reduction to a lambda abstraction implies denotational equality to a lambda abstraction. This property is called the soundness in the literature.

M ββ  Ζ N  implies  β° M β β° (Ζ N)


In the third chapter we prove that denotational equality to a lambda abstraction implies reduction to a lambda abstraction. This property is called adequacy in the literature.

β° M β β° (Ζ N)  implies M ββ  Ζ Nβ² for some Nβ²


The fourth chapter applies the results of the three preceeding chapters (compositionality, soundness, and adequacy) to prove that denotational equality implies a property called contextual equivalence. This property is important because it justifies the use of denotational equality in proving the correctness of program transformations such as performance optimizations.

The proofs of all of these properties rely on some basic results about the denotational semantics, which we establish in the rest of this chapter. We start with some lemmas about renaming, which are quite similar to the renaming lemmas that we have seen in previous chapters. We conclude with a proof of an important inversion lemma for the less-than relation regarding function values.

## Renaming preserves denotations

We shall prove that renaming variables, and changing the environment accordingly, preserves the meaning of a term. We generalize the renaming lemma to allow the values in the new environment to be the same or larger than the original values. This generalization is useful in proving that reduction implies denotational equality.

As before, we need an extension lemma to handle the case where we proceed underneath a lambda abstraction. Suppose that Ο is a renaming that maps variables in Ξ³ into variables with equal or larger values in Ξ΄. This lemmas says that extending the renaming producing a renaming ext r that maps Ξ³ , v to Ξ΄ , v.

ext-β : β {Ξ Ξ v} {Ξ³ : Env Ξ} {Ξ΄ : Env Ξ}
β (Ο : Rename Ξ Ξ)
β Ξ³ β (Ξ΄ β Ο)
------------------------------
β (Ξ³ , v) β ((Ξ΄ , v) β ext Ο)
ext-β Ο lt Z = β-refl
ext-β Ο lt (S nβ²) = lt nβ²


We proceed by cases on the de Bruijn index n.

• If it is Z, then we just need to show that v β‘ v, which we have by refl.

• If it is S nβ², then the goal simplifies to Ξ³ nβ² β‘ Ξ΄ (Ο nβ²), which is an instance of the premise.

Now for the renaming lemma. Suppose we have a renaming that maps variables in Ξ³ into variables with the same values in Ξ΄. If M results in v when evaluated in environment Ξ³, then applying the renaming to M produces a program that results in the same value v when evaluated in Ξ΄.

rename-pres : β {Ξ Ξ v} {Ξ³ : Env Ξ} {Ξ΄ : Env Ξ} {M : Ξ β’ β}
β (Ο : Rename Ξ Ξ)
β Ξ³ β (Ξ΄ β Ο)
β Ξ³ β’ M β v
---------------------
β Ξ΄ β’ (rename Ο M) β v
rename-pres Ο lt (var {x = x}) = sub var (lt x)
rename-pres Ο lt (β¦-elim d dβ) =
β¦-elim (rename-pres Ο lt d) (rename-pres Ο lt dβ)
rename-pres Ο lt (β¦-intro d) =
β¦-intro (rename-pres (ext Ο) (ext-β Ο lt) d)
rename-pres Ο lt β₯-intro = β₯-intro
rename-pres Ο lt (β-intro d dβ) =
β-intro (rename-pres Ο lt d) (rename-pres Ο lt dβ)
rename-pres Ο lt (sub d ltβ²) =
sub (rename-pres Ο lt d) ltβ²


The proof is by induction on the semantics of M. As you can see, all of the cases are trivial except the cases for variables and lambda.

• For a variable x, we make use of the premise to show that Ξ³ x β‘ Ξ΄ (Ο x).

• For a lambda abstraction, the induction hypothesis requires us to extend the renaming. We do so, and use the ext-β lemma to show that the extended renaming maps variables to ones with equivalent values.

## Environment strengthening and identity renaming

We shall need a corollary of the renaming lemma that says that replacing the environment with a larger one (a stronger one) does not change whether a term M results in particular value v. In particular, if Ξ³ β’ M β v and Ξ³ β Ξ΄, then Ξ΄ β’ M β v. What does this have to do with renaming? Itβs renaming with the identity function. We apply the renaming lemma with the identity renaming, which gives us Ξ΄ β’ rename (Ξ» {A} x β x) M β v, and then we apply the rename-id lemma to obtain Ξ΄ β’ M β v.

β-env : β {Ξ} {Ξ³ : Env Ξ} {Ξ΄ : Env Ξ} {M v}
β Ξ³ β’ M β v
β Ξ³ β Ξ΄
----------
β Ξ΄ β’ M β v
β-env{Ξ}{Ξ³}{Ξ΄}{M}{v} d lt
with rename-pres{Ξ}{Ξ}{v}{Ξ³}{Ξ΄}{M} (Ξ» {A} x β x) lt d
... | Ξ΄β’id[M]βv rewrite rename-id {Ξ}{β}{M} =
Ξ΄β’id[M]βv


In the proof that substitution reflects denotations, in the case for lambda abstraction, we use a minor variation of β-env, in which just the last element of the environment gets larger.

up-env : β {Ξ} {Ξ³ : Env Ξ} {M v uβ uβ}
β (Ξ³ , uβ) β’ M β v
β uβ β uβ
-----------------
β (Ξ³ , uβ) β’ M β v
up-env d lt = β-env d (ext-le lt)
where
ext-le : β {Ξ³ uβ uβ} β uβ β uβ β (Ξ³ , uβ) β (Ξ³ , uβ)
ext-le lt Z = lt
ext-le lt (S n) = β-refl


Church numerals are more general than natural numbers in that they represent paths. A path consists of n edges and n + 1 vertices. We store the vertices in a vector of length n + 1 in reverse order. The edges in the path map the ith vertex to the i + 1 vertex. The following function D^suc (for denotation of successor) constructs a table whose entries are all the edges in the path.

D^suc : (n : β) β Vec Value (suc n) β Value
D^suc zero (a[0] β· []) = β₯
D^suc (suc i) (a[i+1] β· a[i] β· ls) =  a[i] β¦ a[i+1]  β  D^suc i (a[i] β· ls)


We use the following auxilliary function to obtain the last element of a non-empty vector. (This formulation is more convenient for our purposes than the one in the Agda standard library.)

vec-last : β{n : β} β Vec Value (suc n) β Value
vec-last {0} (a β· []) = a
vec-last {suc n} (a β· b β· ls) = vec-last (b β· ls)


The function DαΆ computes the denotation of the nth Church numeral for a given path.

DαΆ : (n : β) β Vec Value (suc n) β Value
DαΆ n (a[n] β· ls) = (D^suc n (a[n] β· ls)) β¦ (vec-last (a[n] β· ls)) β¦ a[n]

• The Church numeral for 0 ignores its first argument and returns its second argument, so for the singleton path consisting of just a[0], its denotation is

  β₯ β¦ a[0] β¦ a[0]

• The Church numeral for suc n takes two arguments: a successor function whose denotation is given by D^suc, and the start of the path (last of the vector). It returns the n + 1 vertex in the path.

  (D^suc (suc n) (a[n+1] β· a[n] β· ls)) β¦ (vec-last (a[n] β· ls)) β¦ a[n+1]


The exercise is to prove that for any path ls, the meaning of the Church numeral n is DαΆ n ls.

To fascilitate talking about arbitrary Church numerals, the following church function builds the term for the nth Church numeral, using the auxilliary function apply-n.

apply-n : (n : β) β β , β , β β’ β
apply-n zero = # 0
apply-n (suc n) = # 1 Β· apply-n n

church : (n : β) β β β’ β
church n = Ζ Ζ apply-n n


Prove the following theorem.

denot-church : β{n : β}{ls : Vec Value (suc n)}
β β β’ church n β DαΆ n ls

-- Your code goes here


## Inversion of the less-than relation for functions

What can we deduce from knowing that a function v β¦ w is less than some value u? What can we deduce about u? The answer to this question is called the inversion property of less-than for functions. This question is not easy to answer because of the β-dist rule, which relates a function on the left to a pair of functions on the right. So u may include several functions that, as a group, relate to v β¦ w. Furthermore, because of the rules β-conj-R1 and β-conj-R2, there may be other values inside u, such as β₯, that have nothing to do with v β¦ w. But in general, we can deduce that u includes a collection of functions where the join of their domains is less than v and the join of their codomains is greater than w.

To precisely state and prove this inversion property, we need to define what it means for a value to include a collection of values. We also need to define how to compute the join of their domains and codomains.

### Value membership and inclusion

Recall that we think of a value as a set of entries with the join operator v β w acting like set union. The function value v β¦ w and bottom value β₯ constitute the two kinds of elements of the set. (In other contexts one can instead think of β₯ as the empty set, but here we must think of it as an element.) We write u β v to say that u is an element of v, as defined below.

infix 5 _β_

_β_ : Value β Value β Set
u β β₯ = u β‘ β₯
u β v β¦ w = u β‘ v β¦ w
u β (v β w) = u β v β u β w


So we can represent a collection of values simply as a value. We write v β w to say that all the elements of v are also in w.

infix 5 _β_

_β_ : Value β Value β Set
v β w = β{u} β u β v β u β w


The notions of membership and inclusion for values are closely related to the less-than relation. They are narrower relations in that they imply the less-than relation but not the other way around.

βββ : β{u v : Value}
β u β v
-----
β u β v
βββ {.β₯} {β₯} refl = β-bot
βββ {v β¦ w} {v β¦ w} refl = β-refl
βββ {u} {v β w} (injβ x) = β-conj-R1 (βββ x)
βββ {u} {v β w} (injβ y) = β-conj-R2 (βββ y)

βββ : β{u v : Value}
β u β v
-----
β u β v
βββ {β₯} s with s {β₯} refl
... | x = β-bot
βββ {u β¦ uβ²} s with s {u β¦ uβ²} refl
... | x = βββ x
βββ {u β uβ²} s = β-conj-L (βββ (Ξ» z β s (injβ z))) (βββ (Ξ» z β s (injβ z)))


We shall also need some inversion principles for value inclusion. If the union of u and v is included in w, then of course both u and v are each included in w.

ββ-inv : β{u v w : Value}
β (u β v) β w
---------------
β u β w  Γ  v β w
ββ-inv uvw = β¨ (Ξ» x β uvw (injβ x)) , (Ξ» x β uvw (injβ x)) β©


In our value representation, the function value v β¦ w is both an element and also a singleton set. So if v β¦ w is a subset of u, then v β¦ w must be a member of u.

β¦βββ : β{v w u : Value}
β v β¦ w β u
---------
β v β¦ w β u
β¦βββ incl = incl refl


### Function values

To identify collections of functions, we define the following two predicates. We write Fun u if u is a function value, that is, if u β‘ v β¦ w for some values v and w. We write all-funs v if all the elements of v are functions.

data Fun : Value β Set where
fun : β{u v w} β u β‘ (v β¦ w) β Fun u

all-funs : Value β Set
all-funs v = β{u} β u β v β Fun u


The value β₯ is not a function.

Β¬Funβ₯ : Β¬ (Fun β₯)
Β¬Funβ₯ (fun ())


In our values-as-sets representation, our sets always include at least one element. Thus, if all the elements are functions, there is at least one that is a function.

all-funsβ : β{u}
β all-funs u
β Ξ£[ v β Value ] Ξ£[ w β Value ] v β¦ w β u
all-funsβ {β₯} f with f {β₯} refl
... | fun ()
all-funsβ {v β¦ w} f = β¨ v , β¨ w , refl β© β©
all-funsβ {u β uβ²} f
with all-funsβ Ξ» z β f (injβ z)


### Domains and codomains

Returning to our goal, the inversion principle for less-than a function, we want to show that v β¦ w β u implies that u includes a set of function values such that the join of their domains is less than v and the join of their codomains is greater than w.

To this end we define the following β¨dom and β¨cod functions. Given some value u (that represents a set of entries), β¨dom u returns the join of their domains and β¨cod u returns the join of their codomains.

β¨dom : (u : Value) β Value
β¨dom β₯  = β₯
β¨dom (v β¦ w) = v
β¨dom (u β uβ²) = β¨dom u β β¨dom uβ²

β¨cod : (u : Value) β Value
β¨cod β₯  = β₯
β¨cod (v β¦ w) = w
β¨cod (u β uβ²) = β¨cod u β β¨cod uβ²


We need just one property each for β¨dom and β¨cod. Given a collection of functions represented by value u, and an entry v β¦ w β u, we know that v is included in the domain of v.

β¦ββββ¨dom : β{u v w : Value}
β all-funs u  β  (v β¦ w) β u
----------------------
β v β β¨dom u
β¦ββββ¨dom {β₯} fg () uβv
β¦ββββ¨dom {v β¦ w} fg refl uβv = uβv
β¦ββββ¨dom {u β uβ²} fg (injβ vβ¦wβu) uβv =
let ih = β¦ββββ¨dom (Ξ» z β fg (injβ z)) vβ¦wβu in
injβ (ih uβv)
β¦ββββ¨dom {u β uβ²} fg (injβ vβ¦wβuβ²) uβv =
let ih = β¦ββββ¨dom (Ξ» z β fg (injβ z)) vβ¦wβuβ² in
injβ (ih uβv)


Regarding β¨cod, suppose we have a collection of functions represented by u, but all of them are just copies of v β¦ w. Then the β¨cod u is included in w.

ββ¦ββ¨codβ : β{u v w : Value}
β u β v β¦ w
---------
β β¨cod u β w
ββ¦ββ¨codβ {β₯} s refl with s {β₯} refl
... | ()
ββ¦ββ¨codβ {C β¦ Cβ²} s m with s {C β¦ Cβ²} refl
... | refl = m
ββ¦ββ¨codβ {u β uβ²} s (injβ x) = ββ¦ββ¨codβ (Ξ» {C} z β s (injβ z)) x
ββ¦ββ¨codβ {u β uβ²} s (injβ y) = ββ¦ββ¨codβ (Ξ» {C} z β s (injβ z)) y


With the β¨dom and β¨cod functions in hand, we can make precise the conclusion of the inversion principle for functions, which we package into the following predicate named factor. We say that v β¦ w factors u into uβ² if uβ² is a included in u, if uβ² contains only functions, its domain is less than v, and its codomain is greater than w.

factor : (u : Value) β (uβ² : Value) β (v : Value) β (w : Value) β Set
factor u uβ² v w = all-funs uβ²  Γ  uβ² β u  Γ  β¨dom uβ² β v  Γ  w β β¨cod uβ²


So the inversion principle for functions can be stated as

  v β¦ w β u
---------------
β factor u uβ² v w


We prove the inversion principle for functions by induction on the derivation of the less-than relation. To make the induction hypothesis stronger, we broaden the premise v β¦ w β u to uβ β uβ, and strengthen the conclusion to say that for every function value v β¦ w β uβ, we have that v β¦ w factors uβ into some value uβ.

β uβ β uβ
------------------------------------------------------
β β{v w} β v β¦ w β uβ β Ξ£[ uβ β Value ] factor uβ uβ v w


### Inversion of less-than for functions, the case for β-trans

The crux of the proof is the case for β-trans.

uβ β u   u β uβ
--------------- (β-trans)
uβ β uβ


By the induction hypothesis for uβ β u, we know that v β¦ w factors u into uβ², for some value uβ², so we have all-funs uβ² and uβ² β u. By the induction hypothesis for u β uβ, we know that for any vβ² β¦ wβ² β u, vβ² β¦ wβ² factors uβ into uβ. With these facts in hand, we proceed by induction on uβ² to prove that (β¨dom uβ²) β¦ (β¨cod uβ²) factors uβ into uβ. We discuss each case of the proof in the text below.

sub-inv-trans : β{uβ² uβ u : Value}
β all-funs uβ²  β  uβ² β u
β (β{vβ² wβ²} β vβ² β¦ wβ² β u β Ξ£[ uβ β Value ] factor uβ uβ vβ² wβ²)
---------------------------------------------------------------
β Ξ£[ uβ β Value ] factor uβ uβ (β¨dom uβ²) (β¨cod uβ²)
sub-inv-trans {β₯} {uβ} {u} fuβ² uβ²βu IH =
sub-inv-trans {uββ² β¦ uββ²} {uβ} {u} fg uβ²βu IH = IH (β¦βββ uβ²βu)
sub-inv-trans {uββ² β uββ²} {uβ} {u} fg uβ²βu IH
with ββ-inv uβ²βu
... | β¨ uββ²βu , uββ²βu β©
with sub-inv-trans {uββ²} {uβ} {u} (Ξ» {vβ²} z β fg (injβ z)) uββ²βu IH
| sub-inv-trans {uββ²} {uβ} {u} (Ξ» {vβ²} z β fg (injβ z)) uββ²βu IH
β¨ (uββ β uββ) , β¨ fuββ² , β¨ uββ²βuβ ,
β¨ βββ duβββduββ² duβββduββ² ,
where fuββ² : {vβ² : Value} β vβ² β uββ β vβ² β uββ β Fun vβ²
fuββ² {vβ²} (injβ x) = fu21' x
fuββ² {vβ²} (injβ y) = fu22' y
uββ²βuβ : {C : Value} β C β uββ β C β uββ β C β uβ
uββ²βuβ {C} (injβ x) = uβββuβ x
uββ²βuβ {C} (injβ y) = uβββuβ y

• Suppose uβ² β‘ β₯. Then we have a contradiction because it is not the case that Fun β₯.

• Suppose uβ² β‘ uββ² β¦ uββ². Then uββ² β¦ uββ² β u and we can apply the premise (the induction hypothesis from u β uβ) to obtain that uββ² β¦ uββ² factors of uβ into uββ². This case is complete because β¨dom uβ² β‘ uββ² and β¨cod uβ² β‘ uββ².

• Suppose uβ² β‘ uββ² β uββ². Then we have uββ² β u and uββ² β u. We also have all-funs uββ² and all-funs uββ², so we can apply the induction hypothesis for both uββ² and uββ². So there exists values uββ and uββ such that (β¨dom uββ²) β¦ (β¨cod uββ²) factors u into uββ and (β¨dom uββ²) β¦ (β¨cod uββ²) factors u into uββ. We will show that (β¨dom u) β¦ (β¨cod u) factors u into uββ β uββ. So we need to show that

  β¨dom (uββ β uββ) β β¨dom (uββ² β uββ²)
β¨cod (uββ² β uββ²) β β¨cod (uββ β uββ)


But those both follow directly from the factoring of u into uββ and uββ, using the monotonicity of β with respect to β.

### Inversion of less-than for functions

We come to the proof of the main lemma concerning the inversion of less-than for functions. We show that if uβ β uβ, then for any v β¦ w β uβ, we can factor uβ into uβ according to v β¦ w. We proceed by induction on the derivation of uβ β uβ, and describe each case in the text after the Agda proof.

sub-inv : β{uβ uβ : Value}
β uβ β uβ
β β{v w} β v β¦ w β uβ
-------------------------------------
β Ξ£[ uβ β Value ] factor uβ uβ v w
sub-inv {β₯} {uβ} β-bot {v} {w} ()
sub-inv {uββ β uββ} {uβ} (β-conj-L lt1 lt2) {v} {w} (injβ x) = sub-inv lt1 x
sub-inv {uββ β uββ} {uβ} (β-conj-L lt1 lt2) {v} {w} (injβ y) = sub-inv lt2 y
sub-inv {uβ} {uββ β uββ} (β-conj-R1 lt) {v} {w} m
with sub-inv lt m
β¨ uββ , β¨ fuββ , β¨ (Ξ» {w} z β injβ (uβββuββ z)) ,
sub-inv {uβ} {uββ β uββ} (β-conj-R2 lt) {v} {w} m
with sub-inv lt m
β¨ uββ , β¨ fuββ , β¨ (Ξ» {C} z β injβ (uβββuββ z)) ,
sub-inv {uβ} {uβ} (β-trans{v = u} uββu uβuβ) {v} {w} vβ¦wβuβ
with sub-inv uββu vβ¦wβuβ
with sub-inv-trans {uβ²} fuβ² uβ²βu (sub-inv uβuβ)
β¨ uβ , β¨ fuβ , β¨ uββuβ , β¨ β-trans domuββdomuβ² domuβ²βv ,
sub-inv {uββ β¦ uββ} {uββ β¦ uββ} (β-fun lt1 lt2) refl =
β¨ uββ β¦ uββ , β¨ (Ξ» {w} β fun) , β¨ (Ξ» {C} z β z) , β¨ lt1 , lt2 β© β© β© β©
sub-inv {uββ β¦ (uββ β uββ)} {uββ β¦ uββ β uββ β¦ uββ} β-dist
{.uββ} {.(uββ β uββ)} refl =
β¨ uββ β¦ uββ β uββ β¦ uββ , β¨ f , β¨ g , β¨ β-conj-L β-refl β-refl , β-refl β© β© β© β©
where f : all-funs (uββ β¦ uββ β uββ β¦ uββ)
f (injβ x) = fun x
f (injβ y) = fun y
g : (uββ β¦ uββ β uββ β¦ uββ) β (uββ β¦ uββ β uββ β¦ uββ)
g (injβ x) = injβ x
g (injβ y) = injβ y


Let v and w be arbitrary values.

• Case β-bot. So uβ β‘ β₯. We have v β¦ w β β₯, but that is impossible.

• Case β-conj-L.

  uββ β uβ   uββ β uβ
-------------------
uββ β uββ β uβ


Given that v β¦ w β uββ β uββ, there are two subcases to consider.

• Subcase v β¦ w β uββ. We conclude by the induction hypothesis for uββ β uβ.

• Subcase v β¦ w β uββ. We conclude by the induction hypothesis for uββ β uβ.

• Case β-conj-R1.

  uβ β uββ
--------------
uβ β uββ β uββ


Given that v β¦ w β uβ, the induction hypothesis for uβ β uββ gives us that v β¦ w factors uββ into uββ for some uββ. To show that v β¦ w also factors uββ β uββ into uββ, we just need to show that uββ β uββ β uββ, but that follows directly from uββ β uββ.

• Case β-conj-R2. This case follows by reasoning similar to the case for β-conj-R1.

• Case β-trans.

  uβ β u   u β uβ
---------------
uβ β uβ


By the induction hypothesis for uβ β u, we know that v β¦ w factors u into uβ², for some value uβ², so we have all-funs uβ² and uβ² β u. By the induction hypothesis for u β uβ, we know that for any vβ² β¦ wβ² β u, vβ² β¦ wβ² factors uβ. Now we apply the lemma sub-inv-trans, which gives us some uβ such that (β¨dom uβ²) β¦ (β¨cod uβ²) factors uβ into uβ. We show that v β¦ w also factors uβ into uβ. From β¨dom uβ β β¨dom uβ² and β¨dom uβ² β v, we have β¨dom uβ β v. From w β β¨cod uβ² and β¨cod uβ² β β¨cod uβ, we have w β β¨cod uβ, and this case is complete.

• Case β-fun.

  uββ β uββ  uββ β uββ
---------------------
uββ β¦ uββ β uββ β¦ uββ


Given that v β¦ w β uββ β¦ uββ, we have v β‘ uββ and w β‘ uββ. We show that uββ β¦ uββ factors uββ β¦ uββ into itself. We need to show that β¨dom (uββ β¦ uββ) β uββ and uββ β β¨cod (uββ β¦ uββ), but that is equivalent to our premises uββ β uββ and uββ β uββ.

• Case β-dist.

  ---------------------------------------------
uββ β¦ (uββ β uββ) β (uββ β¦ uββ) β (uββ β¦ uββ)


Given that v β¦ w β uββ β¦ (uββ β uββ), we have v β‘ uββ and w β‘ uββ β uββ. We show that uββ β¦ (uββ β uββ) factors (uββ β¦ uββ) β (uββ β¦ uββ) into itself. We have uββ β uββ β uββ, and also uββ β uββ β uββ β uββ, so the proof is complete.

We conclude this section with two corollaries of the sub-inv lemma. First, we have the following property that is convenient to use in later proofs. We specialize the premise to just v β¦ w β uβ and we modify the conclusion to say that for every vβ² β¦ wβ² β uβ, we have vβ² β v.

sub-inv-fun : β{v w uβ : Value}
β (v β¦ w) β uβ
-----------------------------------------------------
β Ξ£[ uβ β Value ] all-funs uβ Γ uβ β uβ
Γ (β{vβ² wβ²} β (vβ² β¦ wβ²) β uβ β vβ² β v) Γ w β β¨cod uβ
sub-inv-fun{v}{w}{uβ} abc
with sub-inv abc {v}{w} refl
where G : β{D E} β (D β¦ E) β uβ β D β v
G{D}{E} m = β-trans (βββ (β¦ββββ¨dom f m)) db


The second corollary is the inversion rule that one would expect for less-than with functions on the left and right-hand sides.

β¦ββ¦-inv : β{v w vβ² wβ²}
β v β¦ w β vβ² β¦ wβ²
-----------------
β vβ² β v Γ w β wβ²
β¦ββ¦-inv{v}{w}{vβ²}{wβ²} lt
with sub-inv-fun lt
with all-funsβ f
with Ξβv34 uβ¦uβ²βΞ
... | refl =
let β¨codΞβwβ² = ββ¦ββ¨codβ Ξβv34 in
β¨ lt1 uβ¦uβ²βΞ , β-trans lt2 (βββ β¨codΞβwβ²) β©


## Notes

The denotational semantics presented in this chapter is an example of a filter model (Barendregt, Coppo, Dezani-Ciancaglini, 1983). Filter models use type systems with intersection types to precisely characterize runtime behavior (Coppo, Dezani-Ciancaglini, and Salle, 1979). The notation that we use in this chapter is not that of type systems and intersection types, but the Value data type is isomorphic to types (β¦ is β, β is β§, β₯ is β€), the β relation is the inverse of subtyping <:, and the evaluation relation Ο β’ M β v is isomorphic to a type system. Write Ξ instead of Ο, A instead of v, and replace β with : and one has a typing judgement Ξ β’ M : A. By varying the definition of subtyping and using different choices of type atoms, intersection type systems provide semantics for many different untyped Ξ» calculi, from full beta to the lazy and call-by-value calculi (Alessi, Barbanera, and Dezani-Ciancaglini, 2006) (Rocca and Paolini, 2004). The denotational semantics in this chapter corresponds to the BCD system (Barendregt, Coppo, Dezani-Ciancaglini, 1983). Part 3 of the book Lambda Calculus with Types describes a framework for intersection type systems that enables results similar to the ones in this chapter, but for the entire family of intersection type systems (Barendregt, Dekkers, and Statman, 2013).

The two ideas of using finite tables to represent functions and of relaxing table lookup to enable self application first appeared in a technical report by Gordon Plotkin (1972) and are later described in an article in Theoretical Computer Science (Plotkin 1993). In that work, the inductive definition of Value is a bit different than the one we use:

Value = C + βf(Value) Γ βf(Value)


where C is a set of constants and βf means finite powerset. The pairs in βf(Value) Γ βf(Value) represent input-output mappings, just as in this chapter. The finite powersets are used to enable a function table to appear in the input and in the output. These differences amount to changing where the recursion appears in the definition of Value. Plotkinβs model is an example of a graph model of the untyped lambda calculus (Barendregt, 1984). In a graph model, the semantics is presented as a function from programs and environments to (possibly infinite) sets of values. The semantics in this chapter is instead defined as a relation, but set-valued functions are isomorphic to relations. Indeed, we present the semantics as a function in the next chapter and prove that it is equivalent to the relational version.

Dana Scottβs β(Ο) (1976) and Engelerβs B(A) (1981) are two more examples of graph models. Both use the following inductive definition of Value.

Value = C + βf(Value) Γ Value


The use of Value instead of βf(Value) in the output does not restrict expressiveness compared to Plotkinβs model because the semantics use sets of values and a pair of sets (V, Vβ²) can be represented as a set of pairs { (V, vβ²) | vβ² β Vβ² }. In Scottβs β(Ο), the above values are mapped to and from the natural numbers using a kind of Godel encoding.

## References

• Intersection Types and Lambda Models. Fabio Alessi, Franco Barbanera, and Mariangiola Dezani-Ciancaglini, Theoretical Compututer Science, vol. 355, pages 108-126, 2006.

• The Lambda Calculus. H.P. Barendregt, 1984.

• A filter lambda model and the completeness of type assignment. Henk Barendregt, Mario Coppo, and Mariangiola Dezani-Ciancaglini, Journal of Symbolic Logic, vol. 48, pages 931-940, 1983.

• Lambda Calculus with Types. Henk Barendregt, Wil Dekkers, and Richard Statman, Cambridge University Press, Perspectives in Logic, 2013.

• Functional characterization of some semantic equalities inside Ξ»-calculus. Mario Coppo, Mariangiola Dezani-Ciancaglini, and Patrick Salle, in Sixth Colloquium on Automata, Languages and Programming. Springer, pages 133β146, 1979.

• Algebras and combinators. Erwin Engeler, Algebra Universalis, vol. 13, pages 389-392, 1981.

• A Set-Theoretical Definition of Application. Gordon D. Plotkin, University of Edinburgh, Technical Report MIP-R-95, 1972.

• Set-theoretical and other elementary models of the Ξ»-calculus. Gordon D. Plotkin, Theoretical Computer Science, vol. 121, pages 351-409, 1993.

• The Parametric Lambda Calculus. Simona Ronchi Della Rocca and Luca Paolini, Springer, 2004.

• Data Types as Lattices. Dana Scott, SIAM Journal on Computing, vol. 5, pages 522-587, 1976.

## Unicode

This chapter uses the following unicode:

β₯  U+22A5  UP TACK (\bot)
β¦  U+21A6  RIGHTWARDS ARROW FROM BAR (\mapsto)
β  U+2294  SQUARE CUP (\lub)
β  U+2291  SQUARE IMAGE OF OR EQUAL TO (\sqsubseteq)
β¨ U+2A06  N-ARY SQUARE UNION OPERATOR (\Lub)
β’  U+22A2  RIGHT TACK (\|- or \vdash)
β  U+2193  DOWNWARDS ARROW (\d)
αΆ  U+1D9C  MODIFIER LETTER SMALL C (\^c)
β°  U+2130  SCRIPT CAPITAL E (\McE)
β  U+2243  ASYMPTOTICALLY EQUAL TO (\~- or \simeq)
β  U+2208  ELEMENT OF (\in)
β  U+2286  SUBSET OF OR EQUAL TO (\sub= or \subseteq)
`