manip trees: tweaks
[lambda.git] / hints / assignment_7_hint_4.mdwn
1
2 *       At the top of p. 13, GS&V give two examples, one for \[[∃xPx]] and the other for \[[Qx]]. For our purposes, it will be most natural to break \[[∃xPx]] into two pieces, \[[∃x]] and \[[Px]]. But first we need to get clear on expressions like \[[Qx]] and \[[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 the function from entities to `bool`s that gives the extension of Q, then `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, so we face two questions. 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 attributed 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 map each `dpm` it gives us to one that results in `(true, r, h)` only when the entity that `r` and `h` associate with variable `x` has the property Q. As above, I'll assume Q's extension is given by a function `q` from entities to `bool`s.
9
10         Then what we want is something like this:
11
12                 let eliminator : bool -> bool dpm =
13                         fun truth_value ->
14                                 fun (r, h) ->
15                                         let truth_value' =
16                                                 if truth_value
17                                                 then let obj = List.nth h (r 'x') in q obj
18                                                 else false
19                                         in (truth_value', r, h)
20                 in bind_set u (fun one_dpm -> unit_set (bind_dpm one_dpm eliminator))
21
22         The first seven lines here just perfom the operation we described: return a `bool dpm` computation that only yields `true` when its input `(r, h)` associates variable `x` with the right sort of entity. The last line performs the `bind_set` operation. This works by taking each `dpm` in the set and returning a `unit_set` of a filtered `dpm`. The definition of `bind_set` takes care of collecting together all of the `unit_set`s that result for each different set element we started with.
23
24         We can call the `(fun one_dpm -> ...)` part \[[Qx]] and then updating `u` with \[[Qx]] will be:
25
26                 bind_set u \[[Qx]]
27
28         or as it's written using Haskell's infix notation for bind:
29
30                 u >>= \[[Qx]]
31
32 *       Now our second question: how do we decompose the behavior here attributed to \[[Qx]] into some meaning for "Q" and a different meaning for "x"?
33
34         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`. We don't worry here about `dpm set`s; we'll leave them to our predicates to interface with. We'll just make \[[x]] be a single `entity dpm`. So what we want is:
35
36                 let getx : entity dpm = fun (r, h) ->
37                         let obj = List.nth h (r 'x')
38                         in (obj, r, h);;
39
40 *       Now what do we do with predicates? As before, we suppose we have 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:
41
42                 fun entity_dpm -> bind_dpm entity_dpm (fun e -> unit_dpm (q e))
43
44         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`:
45
46                 fun entity_dpm -> unit_set (bind_dpm entity_dpm (fun e -> unit_dpm (q e)))
47
48         Finally, we realize that we're going to have a set of `bool dpm`s to start with, and we need to monadically bind \[[Qx]] to them. We don't want any of the monadic values in the set that wrap `false` to become `true`; instead, we want to apply a filter that checks whether values that formerly wrapped `true` should still continue to do so.
49
50         This could be handled like this:
51
52                 fun entity_dpm ->
53                         let eliminator : bool -> bool dpm =
54                                 fun truth_value ->
55                                         if truth_value = false
56                                         then unit_dpm false
57                                         else bind_dpm entity_dpm (fun e -> unit_dpm (q e))
58                         in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
59
60         Applied to an `entity_dpm`, that yields a function that we can bind to a `bool dpm set` and that will transform the doubly-wrapped `bool` into a new `bool dpm set`.
61
62         If we let that be \[[Q]], then \[[Q]] \[[x]] would be:
63
64                 let getx = fun (r, h) ->
65                         let obj = List.nth h (r 'x')
66                         in (obj, r, h)
67                 in let entity_dpm = getx
68                 in let eliminator = fun truth_value ->
69                         if truth_value = false
70                         then unit_dpm false
71                         else bind_dpm entity_dpm (fun e -> unit_dpm (q e))
72                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
73
74         <!--
75         or, simplifying:
76
77                 let getx = fun (r, h) ->
78                         let obj = List.nth h (r 'x')
79                         in (obj, r, h)
80                 in let eliminator = fun truth_value ->
81                         if truth_value
82                         then bind_dpm getx (fun e -> unit_dpm (q e))
83                         else unit_dpm false
84                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
85         -->
86
87         If we simplify and unpack the definition of `bind_dpm`, that's equivalent to:
88
89                 let getx = fun (r, h) ->
90                         let obj = List.nth h (r 'x')
91                         in (obj, r, h)
92                 in let eliminator = fun truth_value ->
93                         if truth_value
94                         then (fun (r, h) ->
95                                         let (a, r', h') = getx (r, h)
96                                         in let u' = (fun e -> unit_dpm (q e)) a
97                                         in u' (r', h')
98                         ) else unit_dpm false
99                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
100
101         which can be further simplified to:
102
103         <!--
104                 let eliminator = fun truth_value ->
105                         if truth_value
106                         then (fun (r, h) ->
107                                         let obj = List.nth h (r 'x')
108                                         let (a, r', h') = (obj, r, h)
109                                         in let u' = (fun e -> unit_dpm (q e)) a
110                                         in u' (r', h')
111                         ) else unit_dpm false
112                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
113
114                 let eliminator = fun truth_value ->
115                         if truth_value
116                         then (fun (r, h) ->
117                                         let obj = List.nth h (r 'x')
118                                         in let u' = unit_dpm (q obj)
119                                         in u' (r, h)
120                         ) else unit_dpm false
121                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
122         -->
123
124                 let eliminator = fun truth_value ->
125                         if truth_value
126                         then (fun (r, h) ->
127                                         let obj = List.nth h (r 'x')
128                                         in (q obj, r, h)
129                         ) else unit_dpm false
130                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
131
132         This is a function that takes a `bool dpm` as input and returns a `bool dpm set` as output.
133
134         (Compare to the \[[Qx]] we had before:
135
136                 let eliminator = (fun truth_value ->
137                         fun (r, h) ->
138                                 let truth_value' =
139                                         if truth_value
140                                         then let obj = List.nth h (r 'x') in q obj
141                                         else false
142                                 in (truth_value', r, h))
143                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminator)
144
145         Can you persuade yourself that these are equivalent?)   
146
147 *       Reviewing: now we've determined how to define \[[Q]] and \[[x]] such that \[[Qx]] can be the result of applying the function \[[Q]] to the `entity dpm` \[[x]]. And \[[Qx]] in turn is now a function that takes a `bool dpm` as input and returns a `bool dpm set` as output. We monadically bind this operaration to whatever `bool dpm set` we already have on hand:
148
149                 bind_set u \[[Qx]]
150
151         or:
152
153         <pre><code>u >>= \[[Qx]]
154         </code></pre>
155
156 *       Can you figure out how to handle \[[&exist;x]] on your own? If not, here are some [more hints](/hints/assignment_7_hint_5). But try to get as far as you can on your own.
157