assignment7 tweaks
[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 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. I'll assume we have some function q to start with that maps entities to `bool`s. 
9
10         Then what we want is something like this:
11
12                 let eliminate_non_Qxs = (fun truth_value ->
13                         fun (r, h) ->
14                                 let truth_value' =
15                                         if truth_value
16                                         then let obj = List.nth h (r 'x') in q obj
17                                         else false
18                                 in (truth_value', r, h))
19                 in bind_set u (fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs))
20
21         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.
22
23         We can call the `(fun one_dpm -> ...)` part \[[Qx]] and then updating `u` with \[[Qx]] will be:
24
25                 bind_set u \[[Qx]]
26
27         or as it's written using Haskell's infix notation for bind:
28
29                 u >>= \[[Qx]]
30
31 *       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"?
32
33         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 sets of `dpm`s; we'll leave that to our predicates to interface with. We'll just make \[[x]] be a single `entity dpm`. Then what we want is:
34
35                 let getx = fun (r, h) ->
36                         let obj = List.nth h (r 'x')
37                         in (obj, r, h);;
38
39 *       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:
40
41                 fun entity_dpm -> bind_dpm entity_dpm (fun e -> unit_dpm (q e))
42
43         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`:
44
45                 fun entity_dpm -> unit_set (bind_dpm entity_dpm (fun e -> unit_dpm (q e)))
46
47         Finally, we realize that we're going to have a set of `bool dpm`s to start with, and we need to compose \[[Qx]] with 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.
48
49         This could be handled like this:
50
51                 fun entity_dpm ->
52                         let eliminate_non_Qxs = fun truth_value ->
53                                 if truth_value = false
54                                 then unit_dpm false
55                                 else bind_dpm entity_dpm (fun e -> unit_dpm (q e))
56                         in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs)
57
58         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`.
59
60         If we let that be \[[Q]], then \[[Q]] \[[x]] would be:
61
62                 let getx = fun (r, h) ->
63                         let obj = List.nth h (r 'x')
64                         in (obj, r, h)
65                 in let entity_dpm = getx
66                 in let eliminate_non_Qxs = fun truth_value ->
67                         if truth_value = false
68                         then unit_dpm false
69                         else bind_dpm entity_dpm (fun e -> unit_dpm (q e))
70                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs)
71
72         or, simplifying:
73
74                 let getx = fun (r, h) ->
75                         let obj = List.nth h (r 'x')
76                         in (obj, r, h)
77                 in let eliminate_non_Qxs = fun truth_value ->
78                         if truth_value
79                         then bind_dpm getx (fun e -> unit_dpm (q e))
80                         else unit_dpm false
81                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs)
82
83         unpacking the definition of `bind_dpm`, that is:
84
85                 let getx = fun (r, h) ->
86                         let obj = List.nth h (r 'x')
87                         in (obj, r, h)
88                 in let eliminate_non_Qxs = fun truth_value ->
89                         if truth_value
90                         then (fun (r, h) ->
91                                         let (a, r', h') = getx (r, h)
92                                         in let u' = (fun e -> unit_dpm (q e)) a
93                                         in u' (r', h')
94                         ) else unit_dpm false
95                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs)
96
97         continuing to simplify:
98
99                 let eliminate_non_Qxs = fun truth_value ->
100                         if truth_value
101                         then (fun (r, h) ->
102                                         let obj = List.nth h (r 'x')
103                                         let (a, r', h') = (obj, r, h)
104                                         in let u' = (fun e -> unit_dpm (q e)) a
105                                         in u' (r', h')
106                         ) else unit_dpm false
107                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs)
108
109                 let eliminate_non_Qxs = fun truth_value ->
110                         if truth_value
111                         then (fun (r, h) ->
112                                         let obj = List.nth h (r 'x')
113                                         in let u' = unit_dpm (q obj)
114                                         in u' (r, h)
115                         ) else unit_dpm false
116                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs)
117
118                 let eliminate_non_Qxs = fun truth_value ->
119                         if truth_value
120                         then (fun (r, h) ->
121                                         let obj = List.nth h (r 'x')
122                                         in (q obj, r, h)
123                         ) else unit_dpm false
124                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs)
125
126         This is a function that takes a `bool dpm` as input and returns a `bool dpm set` as output.
127
128         (Compare to the \[[Qx]] we had before:
129
130                 let eliminate_non_Qxs = (fun truth_value ->
131                         fun (r, h) ->
132                                 let truth_value' =
133                                         if truth_value
134                                         then let obj = List.nth h (r 'x') in q obj
135                                         else false
136                                 in (truth_value', r, h))
137                 in fun one_dpm -> unit_set (bind_dpm one_dpm eliminate_non_Qxs)
138
139         Can you persuade yourself that these are equivalent?)   
140
141 *       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 compose this with a `bool dpm set` we already have on hand:
142
143                 bind_set u \[[Qx]]
144
145         or:
146
147         <pre><code>u >>=<sub>set</sub> \[[Qx]]
148         </code></pre>
149
150 *       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.
151