SE 500 Fall 2023
HW #7: Types and Quantification
Due: 3:00pm, Friday, November 3

1. Given are functions with types (i.e., signatures) as follows:

x : A y : B f : A → A g : A → B h : B × A → A

(Note that x and y are zero-argument functions, which is to say that they are constants.)

For each of the following expressions, indicate its type (i.e., the type of the value obtained by evaluating the expression) or else indicate that it is not "type correct". In the latter case, identify a smallest subexpression that is a source of the incorrectness.

(a) g.x (b) f(g.x) (c) g(f.x) (d) f(h(g.x,x)) (e) h(y,g.x) (f) h(g.x, h(g.x,f.x))

Recall that Gries & Schneider denote function application by a period (or "full stop", if you prefer), as in f.x, when the argument is atomic, but they use the more traditional notation when the function's argument is non-atomic (e.g., f(f.x)).


2. Let s be the state

s : { i:1; j:2; k:5; b[0..7):(5,3,-4,2,-1,0,9); d:false }

To clarify, b[0..7):(5,3,-4,2,-1,0,9) means that b is an array with index range [0..7) and that b[0] has value 5, b[1] has value 3, ..., b[6] has value 9.

Each problem presents an expression E. You are to

(a) Indicate, for each occurrence of a variable in E, whether it is bound or free, and
(b) Evaluate E in state s. (Show your work.)

(i) (i-j) + (+i | j≤i≤k : b[i])

(ii) (∀j | i≤j≤k : (∃m | 0≤m<j : b[m] > b[j]))

(iii) (d ∨ i≠j)  ≡  ((MAX j | 1≤j<k : b[i+j]) > k)

Note: Even if you have not thought about it this way before (or seen it treated this way in a math book), the max operator is conveniently considered to be a binary infix operator, just like addition, multiplication, conjunction, and disjunction. And, like those operators, it is associative and symmetric and thus is suitable for use as a quantification operator. End of Note


3. Making use of this definition, show (in step-by-step fashion) the result of carrying out the following textual substitutions:

(a) (★x | 0 ≤ x < n+r : x+v)[v := 9w]
(b) (★x | 0 ≤ x < n+r : x+v)[x := 3]
(c) (★x | 0 ≤ x < n+r : x+v)[n := n-x]
(d) (★x | 0 ≤ x < r : (★y | 0 ≤ y ≤ x : x+y+n))[r := y+1]
(e) (★x | 0 ≤ x < r : (★y | 1 ≤ y < x: x+y+n))[n := x+y]



The remaining problems call for the use of the theorems in Chapter 8 of Gries and Schneider. In particular, Theorem (8.24) will be useful in several problems for the purpose of rewriting the range of a quantification. Essentially, what (8.24) says is that if b≤c≤d, then we can split up the range [b..d) into two ranges: [b..c) and [c..d). In other words, if b≤c≤d, the expression b≤i<d is equivalent to b≤i<c ∨ c≤i<d.

In Problems 4 and 5, assume that is an associative and symmetric binary operator having an identity element. In Problems 7 and 8, f is a function of type ℕ×ℕ→ℕ. In Problem 9, g is a function of type ℕ→ℕ.

4. Prove
(a) (★i | 0≤i<12 : P) = (★i | 0≤i<5 : P) ★ (★i | 5≤i<12 : P)
(b) (★i | 0≤i<12 : P) = (★i | 0≤i<5 : P) ★ P[i:=5] ★ (★i | 6≤i<12 : P)


5. Prove (★i | 0≤i<12 : P) ★ (★i | 0≤i<6 : Q) = (★i | 0≤i<6 : P★Q) ★ (★i | 6≤i<12 : P)


6. Prove (∧i | 0≤i<10 : P) = (∧i | 4≤i<10 : P) ∧ (∧i | 0≤i≤6 : P)

Hint: Make use of one of the properties of conjunction.


7. Prove   (+i | 0≤i<m : (+j | 0≤j<n : f.i.j))  =  (+k | 0≤k<n : (+i | 0≤i<m : f.i.k))


8. Prove   (+i,j | 0≤i≤j<n : f.i.j)  =  (+i | 0≤i<n : (+j | i≤j<n : f.i.j))

Keep in mind that the expression a≤b≤c is an abbreviation for the conjunction a≤b ∧ b≤c and that, by transitivity of , a≤c is a consequence of that conjunction, so that the original expression is (by Theorem (3.60)) equivalent to  a≤b ∧ b≤c ∧ a≤c.


9. Prove   (∀i,j | 0≤i≤j≤n : g.i ≤ g.j) = (∀i,j | 0≤i<j≤n : g.i ≤ g.j)

(Notice the subtle difference between the two ranges.)

Note: It is conventional to use ∀ as a quantification operator, even though it means the same thing as if ∧ had been used instead. (We call this a universal quantification.) Unlike ∧, we never use ∀ as a binary infix operator.

Hint #1: Starting with the LHS, rewrite the range R as R1 ∨ R2, where R1 (respectively, R2) covers all (i,j)-pairs in R's "truth set" in which i≤j (respectively, i=j). Then use Axiom (8.16).

Hint #2: Manipulate the quantification having R2 as its range so as to obtain one of the form (∀i | Q : (∀j | j=i : P)), to which (8.14) can be applied.

Hint #3: Recall that is reflexive, which is to say that x ≤ x is true for all x.

Hint #4: If the body of a universal quantification is true, the whole quantification is equivalent to true. (See Theorem (9.8).)