SE 500 Fall 2022
HW #6: Resolution; Types; Quantification; Formalizing Predicates
Due: 3pm, Friday, October 28

1. Use resolution to prove the validity of the following argument:

Spock is brilliant. If Vulcans are logical and Spock is brilliant, then Kirk is arrogant. If Vulcans are logical, and Scotty got drunk last night, and Kirk is arrogant, then Sulu is a good helmsman. If Scotty got drunk last night, then Vulcans are logical. If Spock is brilliant, then Scotty got drunk last night. Therefore, Sulu is a good helmsman.

2. Given are functions with types as follows:

a : A b : B f : A → A g : A → B h : A × B → A

(Note that a and b 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) f.a (b) g.a (c) g.b (d) f(g.a) (e) f(f.a)
(f) f(h(a,b)) (g) g(h(a,b)) (h) f(h(g.a,a)) (i) h(f.a,g.a) (j) h(h(f.a,g.a),g.a)

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


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 := v+2]
(b) (★x | 0 ≤ x < n-r : x+v)[x := 8]
(c) (★x | 0 ≤ x < n-r : x+v)[n := 2x]
(d) (★x | 0 ≤ x ≤ r : (★y | 1 ≤ y : x+y+n))[n := x-y]
(e) (★x | 0 ≤ x ≤ r : (★y | 0 ≤ y : x+y+n))[r := y]


4. Let s be the state

s : { i:1, j:2, k:3, b[0..4]:(5,0,-4,2,1), d:true}

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

Let E be the expression

(d ∨ i=j)  ≡  ((MAX j | 1≤j<k : i + (+i | 0≤i≤j : 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

(a) Indicate, for each occurrence of a variable in E, whether it is bound or free.
(b) Compute s.E (i.e., the value of E in state s)

Show your work.


5. Translate each of the following statements into an expression in predicate logic. Expect quantification to play a major role.

(a) The sum of the elements in array segment b[k..m) is positive.

(b) No element in array segment b[j..k) has a negative value.

(c) At least one element in array segment b[0..k) is odd, but no element in an even-numbered location in that segment is odd. (You may assume the existence of predicate isEven.)

(d) Every value that occurs in array b[] (the index range of which is [0..#b)) occurs among its first m elements. (In other words, the values occurring in location m and thereafter are duplicates of values that occur in b[0..m).)

(e) No value occurs more than once in array b[0..#b).

(f) The longest plateau in array b[] begins at location k. A plateau in an array is a segment in which all the elements are equal to each other. You may wish to define a predicate isPlateau(p,q) that indicates whether or not b[p..q) is a plateau and a function plateauLen(p) that maps each location p of the array to the maximum value r such that b[p..p+r) is a plateau.