Types and Programming Languages Exercises

Preface

2 Mathematical Preliminaries

2.2 Ordered Sets

2.2.6

Exercise [★★ ↛]: Suppose we are given a relation R on a set S. Define the relation R′ as follows:

R′ = R ∪ {(s, s) | sS}.

That is, R′ contains all the pairs in R plus all pairs of the form (s, s). Show that R′ is the reflexive closure of R.

We need to show that:

2.2.7

Exercise [★★, ↛]: Here is a more constructive definition of the transitive closure of a relation R. First, we define the following sequence of sets of pairs:

R0 = R Ri+1 = Ri { (s,u) for some t (s,t) Ri  and  (t,u) Ri }

That is, we construct each Ri + 1 by adding to Ri all the pairs that can be obtained by “one step of transitivity” from pairs already in Ri. Finally, define the relation R+ as the union of all the Ri:

R+ = i Ri

Show that this R+ is really the transitive closure of R—i.e., that it satisfies the conditions given in Definition 2.2.5.

We need to show that:

2.2.8

Exercise [★★, ↛]: Suppose R is a binary relation on a set S and P is a predicate on S that is preserved by R. Show that P is also preserved by R.

We need to show that: For any sS and tS: (s, t) ∈ R and sP implies tP.

Since P is preserved by R, we have: For any sS and tS: (s, t) ∈ R and sP implies tP.

First, we prove that for all i, P is preserved by Ri that is defined in exercise 2.2.7. This can be done by induction:

Since R is the union of all Ri, P is also preserved by R.

3 Untyped Arithmetic Expressions

3.2 Syntax

3.2.4

Exercise [★★]: How many elements does S3 have?

By definition:

So we have:

3.2.5

Exercise [★★]: Show that the sets Si are cumulative—that is, that for each i we have SiSi + 1.

Proof by induction:

3.3 Induction on Terms

3.3.4

Theorem [Principles of induction on terms]: Suppose P is a predicate on terms.

  • Induction on depth:
    • If, for each term s,
      • given P(r) for all r such that depth(r) < depth(s)
        we can show P(s),
    • then P(s) holds for all s.
  • Induction on size:
    • If, for each term s,
      • given P(r) for all r such that size(r) < size(s)
        we can show P(s),
    • then P(s) holds for all s.
  • Structural induction:
    • If, for each term s,
      • given P(r) for all immediate subterms r of s
        we can show P(s),
    • then P(s) holds for all s.

Proof: Exercise (★★).

3.5

3.5.5

Exercise [★]: Spell out the induction principle used in the preceding proof, in the style of Theorem 3.3.4.


List of common unicode characters:

Code PointNameAliasCharacter
U+2032PRIMEminutes, feet
U+219BRIGHTWARDS ARROW WITH STROKE
U+2205EMPTY SETnull set
U+2208ELEMENT OF
U+2209NOT AN ELEMENT OF
U+2217ASTERISK OPERATOR
U+2223DIVIDESsuch that, APL stile
U+222AUNIONcup
U+2286SUBSET OF OR EQUAL TO
U+22C3N-ARY UNIONz notation generalised union
U+2605BLACK STAR