edits
[lambda.git] / hints / assignment_7_hint_5.mdwn
1 <!--
2 I would like to propose one pedegogical suggestion (due to Ken), which
3 is to separate peg addition from non-determinacy by explicitly adding
4 a "Let" construction to GSV's logic, i.e., "Let of var * term *
5 clause", whose interpretation adds a peg, assigns var to it, sets the
6 value to the value computed by term, and evaluates the clause with the
7 new peg in place.  This can be added easily, especially since you have
8 supplied a procedure that handles the main essence of the
9 construction.  Once the Let is in place, adding the existential is
10 purely dealing with nondeterminism.
11 -->
12
13 *       How shall we handle \[[&exist;x]]? As we said, GS&V really tell us how to interpret \[[&exist;xPx]], but for our purposes, what they say about this can be broken naturally into two pieces, such that we represent the update of our starting set `u` with \[[&exist;xPx]] as:
14
15         <pre><code>u >>= \[[&exist;x]] >>= \[[Px]]
16         </code></pre>
17
18         (Extra credit: how does the discussion on pp. 25-29 of GS&V bear on the possibility of this simplification?)
19
20         What does \[[&exist;x]] need to be here? Here's what they say, on the top of p. 13:
21
22         >       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.
23
24         We can defer that to a later step, where we do `... >>= \[[Px]]`. GS&V continue:
25  
26         >       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.
27
28         Deferring the "property P" part, this corresponds to:
29
30         <pre><code>u updated with \[[&exist;x]] &equiv;
31                 let extend one_dpm (d : entity) =
32                         bind_dpm one_dpm (new_peg_and_assign 'x' d)
33                 in bind_set u (fun one_dpm -> List.map (fun d -> extend one_dpm d) domain)
34         </code></pre>
35
36         where `new_peg_and_assign` is the operation we defined in [hint 3](/hints/assignment_7_hint_3):
37
38                 let new_peg_and_assign (var_to_bind : char) (d : entity) : bool -> bool dpm =
39                         fun truth_value ->
40                                 fun (r, h) ->
41                                         (* first we calculate an unused index *)
42                                         let new_index = List.length h
43                                         (* next we store d at h[new_index], which is at the very end of h *)
44                                         (* the following line achieves that in a simple but inefficient way *)
45                                         in let h' = List.append h [d]
46                                         (* next we assign 'x' to location new_index *)
47                                         in let r' = fun var ->
48                                                 if var = var_to_bind then new_index else r var
49                                         (* we pass through the same truth_value that we started with *)
50                                         in (truth_value, r', h');;
51         
52         What's going on in this proposed representation of \[[&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. A later step can then filter out all the `dpm`s where the entity `d` we did that with doesn't have property P. (Again, consult GS&V pp. 25-9 for extra credit.)
53
54         If we call the function `(fun one_dom -> List.map ...)` defined above \[[&exist;x]], then `u` updated with \[[&exist;x]] updated with \[[Px]] is just:
55
56         <pre><code>u >>= \[[&exist;x]] >>= \[[Px]]
57         </code></pre>
58
59         or, being explicit about which "bind" operation we're representing here with `>>=`, that is:
60
61         <pre><code>bind_set (bind_set u \[[&exist;x]]) \[[Px]]
62         </code></pre>
63
64 *       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 [week7](
65 /reader_monad_for_variable_binding).)
66  
67                 type assignment = char -> entity;;
68                 type 'a reader = assignment -> 'a;;
69
70                 let unit_reader (value : 'a) : 'a reader = fun r -> value;;
71
72                 let bind_reader (u : 'a reader) (f : 'a -> 'b reader) : 'b reader =
73                         fun r ->
74                                 let a = u r
75                                 in let u' = f a
76                                 in u' r;;
77
78         Here the type of a sentential clause is:
79
80                 type clause = bool reader;;
81
82         Here are meanings for singular terms and predicates:
83
84                 let getx : entity reader = fun r -> r 'x';;
85
86                 type lifted_unary = entity reader -> bool reader;;
87
88                 let lift (predicate : entity -> bool) : lifted_unary =
89                         fun entity_reader ->
90                                 fun r ->
91                                         let obj = entity_reader r
92                                         in unit_reader (predicate obj)
93
94         The meaning of \[[Qx]] would then be:
95
96         <pre><code>\[[Q]] &equiv; lift q
97         \[[x]] &equiv; getx
98         \[[Qx]] &equiv; \[[Q]] \[[x]] &equiv;
99                 fun r ->
100                         let obj = getx r
101                         in unit_reader (q obj)
102         </code></pre>
103
104         Recall also how we defined \[[lambda x]], or as [we called it before](/reader_monad_for_variable_binding), \\[[who(x)]]:
105
106                 let shift (var_to_bind : char) (clause : clause) : lifted_unary =
107                         fun entity_reader ->
108                                 fun r ->
109                                         let new_value = entity_reader r
110                                         (* remember here we're implementing assignments as functions rather than as lists of pairs *)
111                                         in let r' = fun var -> if var = var_to_bind then new_value else r var
112                                         in clause r'
113
114         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:
115
116                 fun (lifted_predicate : lifted_unary) ->
117                         fun r -> exists (fun (obj : entity) ->
118                                 lifted_predicate (unit_reader obj) r)
119                         
120         That would be the meaning of \[[&exist;]], which we'd use like this:
121
122         <pre><code>\[[&exist;]] ( \[[Q]] )
123         </code></pre>
124
125         or this:
126
127         <pre><code>\[[&exist;]] ( \[[lambda x]] \[[Qx]] )
128         </code></pre>
129
130         If we wanted to compose \[[&exist;]] with \[[lambda x]], we'd get:
131
132                 let shift var_to_bind clause =
133                         fun entity_reader r ->
134                                 let new_value = entity_reader r
135                                 in let r' = fun var -> if var = var_to_bind then new_value else r var
136                                 in clause r'
137                 in let lifted_exists =
138                         fun lifted_predicate ->
139                                 fun r -> exists (fun obj -> lifted_predicate (unit_reader obj) r)
140                 in fun bool_reader -> lifted_exists (shift 'x' bool_reader)
141
142         which we can simplify to:
143
144         <!--
145                 let shifted clause =
146                         fun entity_reader r ->
147                                 let new_value = entity_reader r
148                                 in let r' = fun var -> if var = 'x' then new_value else r var
149                                 in clause r'
150                 in let lifted_exists =
151                         fun lifted_predicate ->
152                                 fun r -> exists (fun obj -> lifted_predicate (unit_reader obj) r)
153                 in fun bool_reader -> lifted_exists (shifted bool_reader)
154
155                 fun bool_reader ->
156                         let shifted' =
157                                 fun entity_reader r ->
158                                         let new_value = entity_reader r
159                                         in let r' = fun var -> if var = 'x' then new_value else r var
160                                         in bool_reader r'
161                         in fun r -> exists (fun obj -> shifted' (unit_reader obj) r)
162
163                 fun bool_reader ->
164                         let shifted'' r obj =
165                                         let new_value = (unit_reader obj) r
166                                         in let r' = fun var -> if var = 'x' then new_value else r var
167                                         in bool_reader r'
168                         in fun r -> exists (fun obj -> shifted'' r obj)
169
170                 fun bool_reader ->
171                         let shifted'' r obj =
172                                         let new_value = obj
173                                         in let r' = fun var -> if var = 'x' then new_value else r var
174                                         in bool_reader r'
175                         in fun r -> exists (shifted'' r)
176         -->
177
178                 fun bool_reader ->
179                         let shifted r new_value =
180                                         let r' = fun var -> if var = 'x' then new_value else r var
181                                         in bool_reader r'
182                         in fun r -> exists (shifted r)
183
184         This gives us a value for \[[&exist;x]], which we use like this:
185
186         <pre><code>\[[&exist;x]] ( \[[Qx]] )
187         </code></pre>
188
189         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:
190
191         <pre><code>u >>= \[[&exist;x]] >>= \[[Qx]]
192         </code></pre>
193
194         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 some 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:
195
196         >       If &exist;x (man x and &exist;y y is wife of x) then (x kisses y).
197
198         See the discussion on pp. 24-5 of GS&V.
199
200
201 *       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.
202