a0ac32a3e8066a71968a56684027591a2eff228c
[lambda.git] / hints / assignment_7_hint_5.mdwn
1
2 *       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 our starting set `u` with \[[∃xPx]] as:
3
4         <pre><code>u >>=<sub>set</sub> \[[&exist;x]] >>=<sub>set</sub> \[[Px]]
5         </code></pre>
6
7         What does \[[&exist;x]] need to be here? Here's what they say, on the top of p. 13:
8
9         >       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.
10
11         We can defer that to a later step, where we do `... >>= \[[Px]]`. GS&V continue:
12  
13         >       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'` as there are entities `d` which in the possible world of `i` have the property P.
14
15         Deferring the "property P" part, this corresponds to:
16
17         <pre><code>u updated with \[[&exist;x]] &equiv;
18                 let extend_one = fun (one_dpm : bool dpm) ->
19                         List.map (fun d -> bind_dpm one_dpm (new_peg_and_assign 'x' d)) domain
20                 in bind_set u extend_one
21         </code></pre>
22
23         where `new_peg_and_assign` is the operation we defined in [hint 3](/hints/assignment_7_hint_3):
24
25                 let new_peg_and_assign (var_to_bind : char) (d : entity) =
26                         (* we want to return a function that we can bind to a bool dpm *)
27                         fun (truth_value : bool) ->
28                                 fun ((r, h) : assignment * store) ->
29                                         (* first we calculate an unused index *)
30                                         let new_index = List.length h
31                                         (* next we store d at h[new_index], which is at the very end of h *)
32                                         (* the following line achieves that in a simple but inefficient way *)
33                                         in let h' = List.append h [d]
34                                         (* next we assign 'x' to location new_index *)
35                                         in let r' = fun var ->
36                                                 if var = var_to_bind then new_index else r var
37                                         (* we pass through the same truth_value that we started with *)
38                                         in (truth_value, r', h')
39         
40         What's going on in this representation of `u` updated with \[[&exist;x]]? For each `bool dpm` in `u`, we collect `dpm`s that are the result of passing through their `bool`, but extending their input `(r, h)` by allocating a new peg for entity `d`, for each `d` in our whole domain of entities, and binding the variable `x` to the index of that peg.
41
42         A later step can then filter out all the `dpm`s where the entity `d` we did that with doesn't have property P.
43
44         So if we just call the function `extend_one` defined above \[[&exist;x]], then `u` updated with \[[&exist;x]] updated with \[[Px]] is just:
45
46         <pre><code>u >>= \[[&exist;x]] >>= \[[Px]]
47         </code></pre>
48
49         or, being explicit about which "bind" operation we're representing here with `>>=`, that is:
50
51         <pre><code>bind_set (bind_set u \[[&exist;x]]) \[[Px]]
52         </code></pre>
53
54 *       Let's compare this to what \[[&exist;xPx]] would look like on a non-dynamic semantics, for example, where we use a simple reader monad to implement variable binding. Reminding ourselves, we'd be working in a framework like this. (Here we implement environments or assignments as functions from variables to entities, instead of as lists of pairs of variables and entities. An assignment `r` here is what `fun c -> List.assoc c r` would have been in [week6](
55 /reader_monad_for_variable_binding).)
56  
57                 type assignment = char -> entity;;
58                 type 'a reader = assignment -> 'a;;
59
60                 let unit_reader (x : 'a) = fun r -> x;;
61
62                 let bind_reader (u : 'a reader) (f : 'a -> 'b reader) =
63                         fun r ->
64                                 let a = u r
65                                 in let u' = f a
66                                 in u' r;;
67
68                 let getx = fun r -> r 'x';;
69
70                 let lift (predicate : entity -> bool) =
71                         fun entity_reader ->
72                                 fun r ->
73                                         let obj = entity_reader r
74                                         in unit_reader (predicate obj)
75
76         `lift predicate` converts a function of type `entity -> bool` into one of type `entity reader -> bool reader`. The meaning of \[[Qx]] would then be:
77
78         <pre><code>\[[Q]] &equiv; lift q
79         \[[x]] &equiv; getx
80         \[[Qx]] &equiv; \[[Q]] \[[x]] &equiv;
81                 fun r ->
82                         let obj = getx r
83                         in unit_reader (q obj)
84         </code></pre>
85
86         Recall also how we defined \[[lambda x]], or as [we called it before](/reader_monad_for_variable_binding), \\[[who(x)]]:
87
88                 let shift (var_to_bind : char) (clause : bool reader) =
89                         (* we return a lifted predicate, that is a entity reader -> bool reader *)
90                         fun entity_reader ->
91                                 fun (r : assignment) ->
92                                         let new_value = entity_reader r
93                                         (* remember here we're implementing assignments as functions rather than as lists of pairs *)
94                                         in let r' = fun var -> if var = var_to_bind then new_value else r var
95                                         in clause r'
96
97         Now, how would we implement quantifiers in this setting? I'll assume we have a function `exists` of type `(entity -> bool) -> bool`. That is, it accepts a predicate as argument and returns `true` if any element in the domain satisfies that predicate. We could implement the reader-monad version of that like this:
98
99                 fun (lifted_predicate : entity reader -> bool reader) ->
100                         fun r -> exists (fun (obj : entity) ->
101                                 lifted_predicate (unit_reader obj) r)
102                         
103         That would be the meaning of \[[&exist;]], which we'd use like this:
104
105         <pre><code>\[[&exist;]] \[[Q]]
106         </code></pre>
107
108         or this:
109
110         <pre><code>\[[&exist;]] ( \[[lambda x]] \[[Qx]] )
111         </code></pre>
112
113         If we wanted to compose \[[&exist;]] with \[[lambda x]], we'd get:
114
115                 let shift var_to_bind clause =
116                         fun entity_reader r ->
117                                 let new_value = entity_reader r
118                                 in let r' = fun var -> if var = var_to_bind then new_value else r var
119                                 in clause r'
120                 in let lifted_exists =
121                         fun lifted_predicate ->
122                                 fun r -> exists (fun obj -> lifted_predicate (unit_reader obj) r)
123                 in fun bool_reader -> lifted_exists (shift 'x' bool_reader)
124
125         which we can simplify as:
126
127                 let shifted clause =
128                         fun entity_reader r ->
129                                 let new_value = entity_reader r
130                                 in let r' = fun var -> if var = 'x' then new_value else r var
131                                 in clause r'
132                 in let lifted_exists =
133                         fun lifted_predicate ->
134                                 fun r -> exists (fun obj -> lifted_predicate (unit_reader obj) r)
135                 in fun bool_reader -> lifted_exists (shifted bool_reader)
136
137                 fun bool_reader ->
138                         let shifted' =
139                                 fun entity_reader r ->
140                                         let new_value = entity_reader r
141                                         in let r' = fun var -> if var = 'x' then new_value else r var
142                                         in bool_reader r'
143                         in fun r -> exists (fun obj -> shifted' (unit_reader obj) r)
144
145                 fun bool_reader ->
146                         let shifted'' r obj =
147                                         let new_value = (unit_reader obj) r
148                                         in let r' = fun var -> if var = 'x' then new_value else r var
149                                         in bool_reader r'
150                         in fun r -> exists (fun obj -> shifted'' r obj)
151
152                 fun bool_reader ->
153                         let shifted'' r obj =
154                                         let new_value = obj
155                                         in let r' = fun var -> if var = 'x' then new_value else r var
156                                         in bool_reader r'
157                         in fun r -> exists (shifted'' r)
158
159                 fun bool_reader ->
160                         let shifted'' r new_value =
161                                         let r' = fun var -> if var = 'x' then new_value else r var
162                                         in bool_reader r'
163                         in fun r -> exists (shifted'' r)
164
165         This gives us a value for \[[&exist;x]], which we use like this:
166
167         <pre><code>\[[&exist;x]] ( \[[Qx]] )
168         </code></pre>
169
170         Contrast the way we use \[[&exist;x]] in GS&V's system. Here we don't have a function that takes \[[Qx]] as an argument. Instead we have a operation that gets bound in a discourse chain:
171
172         <pre><code>u >>= \[[&exist;x]] >>= \[[Qx]]
173         </code></pre>
174
175         The crucial difference in GS&V's system is that the distinctive effect of the \[[&exist;x]]---to allocate new pegs in the store and associate variable `x` with the objects stored there---doesn't last only while interpreting clauses supplied as arguments to \[[&exist;x]]. Instead, it persists through the discourse, possibly affecting the interpretation of claims outside the logical scope of the quantifier. This is how we'll able to interpret claims like:
176
177         >       If &exist;x (man x and &exist;y y is wife of x) then (x kisses y).
178
179
180 *       Can you figure out how to handle \[[not &phi;]] and the other connectives? If not, here are some [more hints](/hints/assignment_7_hint_6). But try to get as far as you can on your own.
181