assignment7 tweaks
[lambda.git] / hints / assignment_7_hint_3.mdwn
1
2 *       In def 2.5, they say the denotation of an e-type constant <code>&alpha;</code> wrt a discourse possibility `(r, g, w)` is whatever object the world `w` associates with <code>&alpha;</code>. Since we don't have worlds, this will just be an object.
3
4 *       They say the denotation of a predicate is whatever extension the world `w` associates with the predicate. Since we don't have worlds, this will just be an extension.
5
6 *       They say the denotation of a variable is the object which the store `g` assigns to the index that the assignment function `r` assigns to the variable. In other words, if the variable is `'x'`, its denotation wrt `(r, g, w)` is `g[r['x']]`.
7
8 We're going to keep all of that, except dropping the worlds. And instead of talking about
9
10 >       \[[expression]] in possibility `(r, g, w)`
11
12 we'll just talk about \[[expression]] and let that be a monadic object, implemented in part by a function that takes `(r, g)` as an argument.
13
14 More specifically, \[[expression]] will be a set of `'a discourse_possibility` monads, where `'a` is the appropriate type for *expression*, and the discourse possibility monads are themselves state monads where `(r, g)` is the state that gets updated. Those are implemented as functions from `(r, g)` to `(a, r', g')`, where `a` is a value of type `'a`, and `r', g'` are possibly altered assignment functions and stores.
15
16 *       In def 2.7, GS&V talk about an operation that takes an existing set of discourse possibilities, and extends each member in the set by allocating a new location in the store, and assigning a variable `'x'` to that location, which holds some object `d` from the domain. It will be useful to have a shorthand way of referring to this operation:
17
18                 let newpeg_and_bind (bound_variable : char) (d : entity) =
19                         fun ((r, g) : assignment * store) ->
20                                 let newindex = List.length g
21                                 (* first we store d at index newindex in g, which is at the very end *)
22                                 (* the following line achieves that in a simple but very inefficient way *)
23                                 in let g' = List.append g [d]
24                                 (* next we assign 'x' to location newindex *)
25                                 in let r' = fun v ->
26                                         if v = bound_variable then newindex else r v
27                                 in (r',g')
28
29 *       At the top of p. 13 (this is in between defs 2.8 and 2.9), GS&V give two examples, one for \[[&exist;xPx]] and the other for \[[Qx]]. In fact it will be easiest for us to break \[[&exist;xPx]] into two pieces, \[[&exist;x]] and \[[Px]]. Let's consider expressions like \[[Px]]  first.
30
31         They say that the effect of updating an information state `s` with the meaning of "Qx" should be to eliminate possibilities in which the object associated with the peg associated with the variable `x` does not have the property Q. In other words, if we let `Q` be a function from objects to `bool`s, `s` updated with \[[Qx]] should be `s` filtered by the function `fun (r, g) -> let obj = List.nth g (r 'x') in Q obj`. When `...Q obj` evaluates to `true`, that `(r, g)` pair is retained, else it is discarded.
32
33         Recall that [we said before](/hints/assignment_7_hint_2) that `List.filter (test : 'a -> bool) (u : 'a set) : 'a set` is the same as:
34
35                 bind_set u (fun a -> if test a then unit_set a else empty_set)
36
37         Hence, updating `s` with \[[Qx]] should be:
38
39                 bind_set s (fun (r, g) -> if (let obj = List.nth g (r 'x') in Q obj) then unit_set (r, g) else empty_set)
40
41         We can call the `(fun (r, g) -> ...)` part \[[Qx]] and then updating `s` with \[[Qx]] will be:
42
43                 bind_set s \[[Qx]]
44
45         or as it's written using Haskell's infix notation for bind:
46
47                 s >>= \[[Qx]]
48
49 *       Now how shall we handle \[[&exist;x]]. As we said, GS&V really tell us how to interpret \[[&exist;xPx]], but what they say about this breaks naturally into two pieces, such that we can represent the update of `s` with \[[&exist;xPx]] as:
50
51         <pre><code>s >>= \[[&exist;x]] >>= \[[Px]]
52         </code></pre>
53
54         What does \[[&exist;x]] need to be here? Here's what they say, on the top of p. 13:
55
56         >       Suppose an information state `s` is updated with the sentence &exist;xPx. Possibilities in `s` in which no object has the property P will be eliminated.
57
58         We can defer that to a later step, where we do `... >>= \[[Px]]`.
59  
60         >       The referent system of the remaining possibilities will be extended with a new peg, which is associated with `x`. And for each old possibility `i` in `s`, there will be just as many extensions `i[x/d]` in the new state `s'` and there are objects `d` which in the possible world of `i` have the property P.
61
62         Deferring the "property P" part, this says:
63
64         <pre><code>s updated with \[[&exist;x]] &equiv;
65                 s >>= (fun (r, g) -> List.map (fun d -> newpeg_and_bind 'x' d) domain)
66         </code></pre>
67         
68         That is, for each pair `(r, g)` in `s`, we collect the result of extending `(r, g)` by allocating a new peg for object `d`, for each `d` in our whole domain of objects (here designated `domain`), and binding the variable `x` to the index of that peg.
69
70         A later step can then filter out all the possibilities in which the object `d` we did that with doesn't have property P.
71
72         So if we just call the function `(fun (r, g) -> ...)` above \[[&exist;x]], then `s` updated with \[[&exist;x]] updated with \[[Px]] is just:
73
74         <pre><code>s >>= \[[&exist;x]] >>= \[[Px]]
75         </code></pre>
76
77         or, being explicit about which "bind" operation we're representing here with `>>=`, that is:
78
79         <pre><code>bind_set (bind_set s \[[&exist;x]]) \[[Px]]
80         </code></pre>
81
82 *       In def 3.1 on p. 14, GS&V define `s` updated with \[[not &phi;]] as:
83
84         >       { i &elem; s | i does not subsist in s[&phi;] }
85
86         where `i` *subsists* in <code>s[&phi;]</code> if there are any `i'` that *extend* `i` in <code>s[&phi;]</code>.
87
88         Here's how we can represent that:
89
90                 <pre><code>bind_set s (fun (r, g) ->
91                         let u = unit_set (r, g)
92                         in let descendents = u >>= \[[&phi;]]
93                         in if descendents = empty_set then u else empty_set
94                 </code></pre>
95
96