tweak calc improvements
[lambda.git] / hints / assignment_7_hint_5.mdwn
1 *       How shall we handle \[[∃x]]? As we said, GS&V really tell us how to interpret \[[∃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 \[[∃xPx]] as:
2
3         <pre><code>u >>= \[[&exist;x]] >>= \[[Px]]
4         </code></pre>
5
6         (Extra credit: how does the discussion on pp. 25-29 of GS&V bear on the possibility of this simplification?)
7
8         What does \[[&exist;x]] need to be here? Here's what they say, on the top of p. 13:
9
10         >       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.
11
12         We can defer that to a later step, where we do `... >>= \[[Px]]`. GS&V continue:
13  
14         >       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.
15
16         Deferring the "property P" part, this corresponds to:
17
18         <pre><code>u updated with \[[&exist;x]] &equiv;
19                 let extend one_dpm (d : entity) =
20                         bind_dpm one_dpm (new_peg_and_assign 'x' d)
21                 in bind_set u (fun one_dpm -> List.map (fun d -> extend one_dpm d) domain)
22         </code></pre>
23
24         where `new_peg_and_assign` is the operation we defined in [hint 3](/hints/assignment_7_hint_3):
25
26                 let new_peg_and_assign (var_to_bind : char) (d : entity) : bool -> bool dpm =
27                         fun truth_value ->
28                                 fun (r, h) ->
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 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.)
41
42         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:
43
44         <pre><code>u >>= \[[&exist;x]] >>= \[[Px]]
45         </code></pre>
46
47         or, being explicit about which "bind" operation we're representing here with `>>=`, that is:
48
49         <pre><code>bind_set (bind_set u \[[&exist;x]]) \[[Px]]
50         </code></pre>
51
52 *       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](
53 /reader_monad_for_variable_binding).)
54  
55                 type assignment = char -> entity;;
56                 type 'a reader = assignment -> 'a;;
57
58                 let unit_reader (value : 'a) : 'a reader = fun r -> value;;
59
60                 let bind_reader (u : 'a reader) (f : 'a -> 'b reader) : 'b reader =
61                         fun r ->
62                                 let a = u r
63                                 in let u' = f a
64                                 in u' r;;
65
66         Here the type of a sentential clause is:
67
68                 type clause = bool reader;;
69
70         Here are meanings for singular terms and predicates:
71
72                 let getx : entity reader = fun r -> r 'x';;
73
74                 type lifted_unary = entity reader -> bool reader;;
75
76                 let lift (predicate : entity -> bool) : lifted_unary =
77                         fun entity_reader ->
78                                 fun r ->
79                                         let obj = entity_reader r
80                                         in unit_reader (predicate obj)
81
82         The meaning of \[[Qx]] would then be:
83
84         <pre><code>\[[Q]] &equiv; lift q
85         \[[x]] &equiv; getx
86         \[[Qx]] &equiv; \[[Q]] \[[x]] &equiv;
87                 fun r ->
88                         let obj = getx r
89                         in unit_reader (q obj)
90         </code></pre>
91
92         Recall also how we defined \[[lambda x]], or as [we called it before](/reader_monad_for_variable_binding), \\[[who(x)]]:
93
94                 let shift (var_to_bind : char) (clause : clause) : lifted_unary =
95                         fun entity_reader ->
96                                 fun r ->
97                                         let new_value = entity_reader r
98                                         (* remember here we're implementing assignments as functions rather than as lists of pairs *)
99                                         in let r' = fun var -> if var = var_to_bind then new_value else r var
100                                         in clause r'
101
102         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:
103
104                 fun (lifted_predicate : lifted_unary) ->
105                         fun r -> exists (fun (obj : entity) ->
106                                 lifted_predicate (unit_reader obj) r)
107                         
108         That would be the meaning of \[[&exist;]], which we'd use like this:
109
110         <pre><code>\[[&exist;]] ( \[[Q]] )
111         </code></pre>
112
113         or this:
114
115         <pre><code>\[[&exist;]] ( \[[lambda x]] \[[Qx]] )
116         </code></pre>
117
118         If we wanted to compose \[[&exist;]] with \[[lambda x]], we'd get:
119
120                 let shift var_to_bind clause =
121                         fun entity_reader r ->
122                                 let new_value = entity_reader r
123                                 in let r' = fun var -> if var = var_to_bind then new_value else r var
124                                 in clause r'
125                 in let lifted_exists =
126                         fun lifted_predicate ->
127                                 fun r -> exists (fun obj -> lifted_predicate (unit_reader obj) r)
128                 in fun bool_reader -> lifted_exists (shift 'x' bool_reader)
129
130         which we can simplify to:
131
132         <!--
133                 let shifted clause =
134                         fun entity_reader r ->
135                                 let new_value = entity_reader r
136                                 in let r' = fun var -> if var = 'x' then new_value else r var
137                                 in clause r'
138                 in let lifted_exists =
139                         fun lifted_predicate ->
140                                 fun r -> exists (fun obj -> lifted_predicate (unit_reader obj) r)
141                 in fun bool_reader -> lifted_exists (shifted bool_reader)
142
143                 fun bool_reader ->
144                         let shifted' =
145                                 fun entity_reader r ->
146                                         let new_value = entity_reader r
147                                         in let r' = fun var -> if var = 'x' then new_value else r var
148                                         in bool_reader r'
149                         in fun r -> exists (fun obj -> shifted' (unit_reader obj) r)
150
151                 fun bool_reader ->
152                         let shifted'' r obj =
153                                         let new_value = (unit_reader obj) r
154                                         in let r' = fun var -> if var = 'x' then new_value else r var
155                                         in bool_reader r'
156                         in fun r -> exists (fun obj -> shifted'' r obj)
157
158                 fun bool_reader ->
159                         let shifted'' r obj =
160                                         let new_value = obj
161                                         in 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
166                 fun bool_reader ->
167                         let shifted r new_value =
168                                         let r' = fun var -> if var = 'x' then new_value else r var
169                                         in bool_reader r'
170                         in fun r -> exists (shifted r)
171
172         This gives us a value for \[[&exist;x]], which we use like this:
173
174         <pre><code>\[[&exist;x]] ( \[[Qx]] )
175         </code></pre>
176
177         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:
178
179         <pre><code>u >>= \[[&exist;x]] >>= \[[Qx]]
180         </code></pre>
181
182         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:
183
184         >       If &exist;x (man x and &exist;y y is wife of x) then (x kisses y).
185
186         See the discussion on pp. 24-5 of GS&V.
187
188
189 *       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.
190