b17f83f36b0e0dce6335f3bddf3e092fd254c0a2
[lambda.git] / hints / assignment_7_hint_4.mdwn
1
2 *       At the top of p. 13 (this is in between defs 2.8 and 2.9), GS&V give two examples, one for \[[∃xPx]] and the other for \[[Qx]]. In fact it will be most natural to break \[[∃xPx]] into two pieces, \[[∃x]] and \[[Px]]. But first we need to get clear on expressions like \[[Px]]. 
3
4 *       GS&V say that the effect of updating an information state `s` with the meaning of "Qx" should be to eliminate possibilities in which the entity 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 entities to `bool`s, `s` updated with \[[Qx]] should be `s` filtered by the function `fun (r, h) -> let obj = List.nth h (r 'x') in Q obj`. When `... Q obj` evaluates to `true`, that `(r, h)` pair is retained, else it is discarded.
5
6         OK, we face two questions then. First, how do we carry this over to our present framework, where we're working with sets of `dpm`s instead of sets of discourse possibilities? And second, how do we decompose the behavior here ascribed to \[[Qx]] into some meaning for "Q" and a different meaning for "x"?
7
8 *       Answering the first question: we assume we've got some `(bool dpm) set` to start with. I won't call this `s` because that's what GS&V use for sets of discourse possibilities, and we don't want to confuse discourse possibilities with `dpm`s. Instead I'll call it `u`. Now what we want to do with `u` is to apply a filter that only lets through those `bool dpm`s whose outputs are `(true, r, h)`, where the entity that `r` and `h` associate with variable `x` has the property P. So what we want is:
9
10                 let test = (fun (truth_value, r, h) ->
11                         truth_value && (let obj = List.nth h (r 'x') in Q obj))
12                 in List.filter test u
13
14         Persuade yourself that in general:
15
16                 List.filter (test : 'a -> bool) (u : 'a set) : 'a set
17
18         is the same as:
19
20                 bind_set u (fun a -> if test a then unit_set a else empty_set)
21
22         Hence substituting in our above formula, we can derive:
23
24                 let test = (fun (truth_value, r, h) ->
25                         truth_value && (let obj = List.nth h (r 'x') in Q obj))
26                 in bind_set u (fun a -> if test a then unit_set a else empty_set)
27         
28         or simplifying:
29
30                 bind_set u (fun (truth_value, r, h) ->
31                         if truth_value && (let obj = List.nth h (r 'x') in Q obj)
32                         then unit_set (true, r, h) else empty_set)
33
34         We can call the `(fun (truth_value, r, h) -> ...)` part \[[Qx]] and then updating `u` with \[[Qx]] will be:
35
36                 bind_set u \[[Qx]]
37
38         or as it's written using Haskell's infix notation for bind:
39
40                 u >>= \[[Qx]]
41
42 *       Now our second question: how do we decompose the behavior here ascribed to \[[Qx]] into some meaning for "Q" and a different meaning for "x"?
43
44         Well, we already know that \[[x]] will be a kind of computation that takes an assignment function `r` and store `h` as input. It will look up the entity that those two together associate with the variable `x`. So we can treat \[[x]] as an `entity dpm`. Except that we don't have just one `dpm` to compose it with, but a set of them. However, we'll leave that to our predicates to deal with. We'll just make \[[x]] be an operation on a single `dpm`. Let's call the `dpm` we start with `v`. Then what we want to do is:
45
46                 let getx = fun (r, h) ->
47                         let obj = List.nth h (r 'x')
48                         in (obj, r, h)
49                 in bind_dpm v (fun _ -> getx)
50
51         What's going on here? Our starting `dpm` is a kind of monadic box. We don't care what value is inside that monadic box, which is why we're binding it to a function of the form `fun _ -> ...`. What we return is a new monadic box, which takes `(r, h)` as input and returns the entity they associate with variable `x` (together with unaltered versions of `r` and `h`).
52
53 *       Now what do we do with predicates? We suppose we're given a function Q that maps entities to `bool`s. We want to turn it into a function that maps `entity dpm`s to `bool dpm`s. Eventually we'll need to operate not just on single `dpm`s but on sets of them, but first things first. We'll begin by lifting Q into a function that takes `entity dpm`s as arguments and returns `bool dpm`s:
54
55                 fun entity_dpm -> bind_dpm entity_dpm (fun e -> unit_dpm (Q e))
56
57         Now we have to transform this into a function that again takes single `entity dpm`s as arguments, but now returns a `(bool dpm) set`. This is easily done with `unit_set`:
58
59                 fun entity_dpm -> unit_set (bind_dpm entity_dpm (fun e -> unit_dpm (Q e)))
60
61         If we let that be \[[Q]], then \[[Q]] \[[x]] would be:
62
63                 let getx = fun (r, h) ->
64                         let obj = List.nth h (r 'x')
65                         in (obj, r, h)
66                 in let entity_dpm = getx
67                 in unit_set (bind_dpm entity_dpm (fun e -> unit_dpm (Q e)))
68
69         or, simplifying:
70
71                 let getx = fun (r, h) ->
72                         let obj = List.nth h (r 'x')
73                         in (obj, r, h)
74                 in unit_set (bind_dpm getx (fun e -> unit_dpm (Q e)))
75
76         which is:
77
78                 let getx = fun (r, h) ->
79                         let obj = List.nth h (r 'x')
80                         in (obj, r, h)
81                 in fun (r, h) ->
82                         let (a, r', h') = getx (r, h)
83                         in let u' = (fun e -> unit_dpm (Q e)) a
84                         in unit_set (u' (r', h'))
85                 
86         which is:
87
88                 fun (r, h) ->
89                         let obj = List.nth h (r 'x')
90                         in let (a, r', h') = (obj, r, h)
91                         in let u' = (fun e -> unit_dpm (Q e)) a
92                         in unit_set (u' (r', h'))
93                 
94         which is:
95
96                 fun (r, h) ->
97                         let obj = List.nth h (r 'x')
98                         in let u' = unit_dpm (Q obj)
99                         in unit_set (u' (r, h))
100
101         which is:
102
103                 fun (r, h) ->
104                         let obj = List.nth h (r 'x')
105                         in unit_set (unit_dpm (Q obj) (r, h))
106
107         which is:
108
109                 fun (r, h) ->
110                         let obj = List.nth h (r 'x')
111                         in unit_set ((Q obj, r, h))
112
113
114
115
116
117
118
119
120 , so really \[[x]] will need to be a monadic operation on *a set of* `entity dpm`s. But one thing at a time. First, let's figure out what operation should be performed on each starting `dpm`. Let's call the `dpm` we start with `v`. Then what we want to do is:
121
122
123         So that's how \[[x]] should operate on a single `dpm`. How should it operate on a set of them? Well, we just have to take each member of the set and return a `unit_set` of the operation we perform on each of them. The `bind_set` operation takes care of joining all those `unit_set`s together. So, where `u` is the set of `dpm`s we start with, we have:
124
125                 let handle_each = fun v ->
126                         (* as above *)
127                         let getx = fun (r, h) ->
128                                 let obj = List.nth h (r 'x')
129                                 in (obj, r, h)
130                         in let result = bind_dpm v (fun _ -> getx)
131                         (* we return a unit_set of each result *)
132                         in unit_set result
133                 in bind_set u handle_each
134
135         This is a computation that takes a bunch of `_ dpm`s and returns `dpm`s that return their input discourse possibilities unaltered, together with the entity those discouse possibilities associate with variable 'x'. We can take \[[x]] to be the `handle_each` function defined above.
136
137
138 *       They say the denotation of a variable is the entity which the store `h` 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, h, w)` is `h[r['x']]`. In our OCaml implementation, that will be `List.nth h (r 'x')`.
139
140
141
142 *       Now how shall we handle \[[∃x]]. As we said, GS&V really tell us how to interpret \[[∃xPx]], but what they say about this breaks naturally into two pieces, such that we can represent the update of `s` with \[[∃xPx]] as:
143
144         <pre><code>s >>= \[[&exist;x]] >>= \[[Px]]
145         </code></pre>
146
147         What does \[[&exist;x]] need to be here? Here's what they say, on the top of p. 13:
148
149         >       Suppose an information state `s` is updated with the sentence &exist;xPx. Possibilities in `s` in which no entity has the property P will be eliminated.
150
151         We can defer that to a later step, where we do `... >>= \[[Px]]`.
152  
153         >       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 entities `d` which in the possible world of `i` have the property P.
154
155         Deferring the "property P" part, this says:
156
157         <pre><code>s updated with \[[&exist;x]] &equiv;
158                 s >>= (fun (r, h) -> List.map (fun d -> newpeg_and_bind 'x' d) domain)
159         </code></pre>
160         
161         That is, for each pair `(r, h)` in `s`, we collect the result of extending `(r, h)` by allocating a new peg for entity `d`, for each `d` in our whole domain of entities (here designated `domain`), and binding the variable `x` to the index of that peg.
162
163         A later step can then filter out all the possibilities in which the entity `d` we did that with doesn't have property P.
164
165         So if we just call the function `(fun (r, h) -> ...)` above \[[&exist;x]], then `s` updated with \[[&exist;x]] updated with \[[Px]] is just:
166
167         <pre><code>s >>= \[[&exist;x]] >>= \[[Px]]
168         </code></pre>
169
170         or, being explicit about which "bind" operation we're representing here with `>>=`, that is:
171
172         <pre><code>bind_set (bind_set s \[[&exist;x]]) \[[Px]]
173         </code></pre>
174
175 *       In def 3.1 on p. 14, GS&V define `s` updated with \[[not &phi;]] as:
176
177         >       { i &elem; s | i does not subsist in s[&phi;] }
178
179         where `i` *subsists* in <code>s[&phi;]</code> if there are any `i'` that *extend* `i` in <code>s[&phi;]</code>.
180
181         Here's how we can represent that:
182
183                 <pre><code>bind_set s (fun (r, h) ->
184                         let u = unit_set (r, h)
185                         in let descendents = u >>= \[[&phi;]]
186                         in if descendents = empty_set then u else empty_set
187                 </code></pre>
188
189