Answers to Self-Study Questions

Test Yourself #1

We want to know the value of:

By the definition of P, this is:

Note that

is the store that maps A to n, and maps all other Ids to zero. Let's call this store s1 in what follows.

So we have:

Using the definition of C for a sequence of statements we get:

Now using the definition of C for an assignment we get:

Using the definition of E for an identifier, we have:

which simplifies to: which (since s1 maps A to n) evaluates to n.

Therefore, we have the (sub)expression

which evaluates to the store that maps A and Z to n, and all other identifiers to zero. We'll call that store s2. Now we have: Using the definition of C for an if-then statement we get: Using the definition of B for an equality test, and the fact that s2 maps Z to n, we have: By the definition of C for an assignment, we have: which using the definition of E for a number literal becomes: Note that is a store that maps Z to one. Call this store s3: The Evaluates to whatever value the store s' maps Z to. Observe that for s3, this value is one, and for s2 it is n. We now have for the entire program:

Test Yourself #2

The store represents the state of the program, and once it becomes ⊥, all states produced after that point must also be ⊥. C is the only valuation function that produces a new state for the program, which is why it must be strict. B and E do not produce a new state, so they do not need to be strict.

Test Yourself #3

E [[E1/E2]] = λk.λs.E [[E1]] (λn1.λs2.E [[E2]] (λn2.λs3.if n2 equals zero thenelse k (n1 divided-by n2) s3) s2) s1

Test Yourself #4

Note that s1 is a store that maps A to n, and all other Ids to zero. We have: Applying C [[C1;C2]] we get: Applying C for assignment, we get: Let's just focus on the E portion for now: This is: Applying E [[N]], we get: If we apply the zero, we get: Using E[[I]], we get: Recall that this was originally E [[A/0]]. If we now plug that back into the program, we get: Of course, this was originally a program, wrapped in a λn which we've omitted for convenience above. Adding everything back in, we get the final solution: As it turns out, the result of this program does not depend on its input.