-
Notifications
You must be signed in to change notification settings - Fork 0
/
lemmas-satisfy.agda
394 lines (365 loc) · 15.8 KB
/
lemmas-satisfy.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
open import Prelude
open import constraints-core
open import contexts
open import core
open import notintro-decidable
open import result-judgements
open import satisfy-decidable
open import statics-core
open import value-judgements
open import xrefutable-decidable
module lemmas-satisfy where
maysat-truth-not : ∀{e} →
(e ⊧̇? ·⊤ → ⊥)
maysat-truth-not (CMSNotIntro _ () _)
maysat-falsity-not : ∀{e} →
(e ⊧̇? ·⊥ → ⊥)
maysat-falsity-not (CMSNotIntro _ _ ())
satormay-falsity-not : ∀{e} →
(e ⊧̇†? ·⊥ → ⊥)
satormay-falsity-not (CSMSMay (CMSNotIntro _ _ ()))
notintro-sat-ref-not : ∀{e ξ} →
e notintro →
e ⊧̇ ξ →
ξ xrefutable →
⊥
notintro-sat-ref-not ni (CSNotIntroPair ni' sat1 sat2)
(RXPairL ref1) =
notintro-sat-ref-not NVFst sat1 ref1
notintro-sat-ref-not ni (CSNotIntroPair ni' sat1 sat2)
(RXPairR ref2) =
notintro-sat-ref-not NVSnd sat2 ref2
notintro-sat-ref-not ni (CSOrL sat1) (RXOr ref1 ref2) =
notintro-sat-ref-not ni sat1 ref1
notintro-sat-ref-not ni (CSOrR sat2) (RXOr ref1 ref2) =
notintro-sat-ref-not ni sat2 ref2
not-ref-not-pos-not : ∀{ξ} →
(ξ xrefutable → ⊥) →
(ξ possible → ⊥) →
⊥
not-ref-not-pos-not {·⊤} ¬ref ¬pos = ¬pos PTruth
not-ref-not-pos-not {·⊥} ¬ref ¬pos = ¬ref RXFalsity
not-ref-not-pos-not {·?} ¬ref ¬pos = ¬pos PUnknown
not-ref-not-pos-not {N n} ¬ref ¬pos = ¬pos PNum
not-ref-not-pos-not {inl ξ} ¬ref ¬pos = ¬ref RXInl
not-ref-not-pos-not {inr ξ} ¬ref ¬pos = ¬ref RXInr
not-ref-not-pos-not {⟨ ξ1 , ξ2 ⟩} ¬ref ¬pos =
not-ref-not-pos-not (λ ref1 → ¬ref (RXPairL ref1))
(λ pos1 →
not-ref-not-pos-not
(λ ref2 → ¬ref (RXPairR ref2))
(λ pos2 → ¬pos (PPair pos1 pos2)))
not-ref-not-pos-not {ξ1 ∨ ξ2} ¬ref ¬pos =
not-ref-not-pos-not (λ ref1 →
not-ref-not-pos-not
(λ ref2 → ¬ref (RXOr ref1 ref2))
(λ pos2 → ¬pos (POrR pos2)))
(λ pos1 → ¬pos (POrL pos1))
sat-pos : ∀{ξ e} →
e ⊧̇ ξ →
ξ possible
sat-pos CSTruth = PTruth
sat-pos CSNum = PNum
sat-pos (CSInl sat) = PInl (sat-pos sat)
sat-pos (CSInr sat) = PInr (sat-pos sat)
sat-pos (CSPair sat1 sat2) =
PPair (sat-pos sat1) (sat-pos sat2)
sat-pos (CSNotIntroPair ni sat1 sat2) =
PPair (sat-pos sat1) (sat-pos sat2)
sat-pos (CSOrL sat) = POrL (sat-pos sat)
sat-pos (CSOrR sat) = POrR (sat-pos sat)
maysat-pos : ∀{ξ e} →
e ⊧̇? ξ →
ξ possible
maysat-pos CMSUnknown = PUnknown
maysat-pos (CMSInl msat) = PInl (maysat-pos msat)
maysat-pos (CMSInr msat) = PInr (maysat-pos msat)
maysat-pos (CMSPairL msat1 sat2) =
PPair (maysat-pos msat1) (sat-pos sat2)
maysat-pos (CMSPairR sat1 msat2) =
PPair (sat-pos sat1) (maysat-pos msat2)
maysat-pos (CMSPair msat1 msat2) =
PPair (maysat-pos msat1) (maysat-pos msat2)
maysat-pos (CMSOrL msat1 ¬sat2) = POrL (maysat-pos msat1)
maysat-pos (CMSOrR ¬sat1 msat2) = POrR (maysat-pos msat2)
maysat-pos (CMSNotIntro ni ref pos) = pos
satormay-pos : ∀{ξ e} →
e ⊧̇†? ξ →
ξ possible
satormay-pos (CSMSSat sat) = sat-pos sat
satormay-pos (CSMSMay msat) = maysat-pos msat
not-ref-sat : ∀{ξ Γ Δ Δp e τ} →
ξ :c: τ →
Γ , Δ , Δp ⊢ e :: τ →
e final →
(ξ xrefutable → ⊥) →
e ⊧̇ ξ
not-ref-sat CTTruth wt fin ¬ref = CSTruth
not-ref-sat CTFalsity wt fin ¬ref = abort (¬ref RXFalsity)
not-ref-sat CTUnknown wt fin ¬ref = abort (¬ref RXUnknown)
not-ref-sat CTNum wt fin ¬ref = abort (¬ref RXNum)
not-ref-sat (CTInl ct) wt fin ¬ref = abort (¬ref RXInl)
not-ref-sat (CTInr ct) wt fin ¬ref = abort (¬ref RXInr)
not-ref-sat {ξ = ⟨ ξ1 , ξ2 ⟩} (CTPair ct1 ct2) wt fin ¬ref
with xrefutable-dec ξ1
... | Inl ref1 = abort (¬ref (RXPairL ref1))
... | Inr ¬ref1
with xrefutable-dec ξ2
... | Inl ref2 = abort (¬ref (RXPairR ref2))
... | Inr ¬ref2 with wt | fin
... | TVar x | FVal ()
... | TVar x | FIndet ()
... | TAp wt1 wt2 | FIndet ind =
CSNotIntroPair NVAp
(not-ref-sat ct1 (TFst wt)
(FIndet (IFst (λ e1 e2 ()) ind)) ¬ref1)
(not-ref-sat ct2 (TSnd wt)
(FIndet (ISnd (λ e1 e2 ()) ind)) ¬ref2)
... | TMatchZPre wt' x | FIndet ind =
CSNotIntroPair NVMatch
(not-ref-sat ct1 (TFst wt)
(FIndet (IFst (λ e1 e2 ()) ind)) ¬ref1)
(not-ref-sat ct2 (TSnd wt)
(FIndet (ISnd (λ e1 e2 ()) ind)) ¬ref2)
... | TMatchNZPre wt' x x₁ x₂ x₃ | FIndet ind =
CSNotIntroPair NVMatch
(not-ref-sat ct1 (TFst wt)
(FIndet (IFst (λ e1 e2 ()) ind)) ¬ref1)
(not-ref-sat ct2 (TSnd wt)
(FIndet (ISnd (λ e1 e2 ()) ind)) ¬ref2)
... | TFst wt' | FIndet ind =
CSNotIntroPair NVFst
(not-ref-sat ct1 (TFst wt)
(FIndet (IFst (λ e1 e2 ()) ind)) ¬ref1)
(not-ref-sat ct2 (TSnd wt)
(FIndet (ISnd (λ e1 e2 ()) ind)) ¬ref2)
... | TSnd wt' | FIndet ind =
CSNotIntroPair NVSnd
(not-ref-sat ct1 (TFst wt)
(FIndet (IFst (λ e1 e2 ()) ind)) ¬ref1)
(not-ref-sat ct2 (TSnd wt)
(FIndet (ISnd (λ e1 e2 ()) ind)) ¬ref2)
... | TEHole u∈Δ st | FIndet ind =
CSNotIntroPair NVEHole
(not-ref-sat ct1 (TFst wt)
(FIndet (IFst (λ e1 e2 ()) ind)) ¬ref1)
(not-ref-sat ct2 (TSnd wt)
(FIndet (ISnd (λ e1 e2 ()) ind)) ¬ref2)
... | THole u∈Δ st wt' | FIndet ind =
CSNotIntroPair NVHole
(not-ref-sat ct1 (TFst wt)
(FIndet (IFst (λ e1 e2 ()) ind)) ¬ref1)
(not-ref-sat ct2 (TSnd wt)
(FIndet (ISnd (λ e1 e2 ()) ind)) ¬ref2)
... | TPair wt1 wt2 | fin
with pair-final fin
... | fin1 , fin2 =
CSPair (not-ref-sat ct1 wt1 fin1 ¬ref1)
(not-ref-sat ct2 wt2 fin2 ¬ref2)
not-ref-sat {ξ = ξ1 ∨ ξ2} (CTOr ct1 ct2) wt fin ¬ref
with xrefutable-dec ξ1
... | Inr ¬ref1 = CSOrL (not-ref-sat ct1 wt fin ¬ref1)
... | Inl ref1
with xrefutable-dec ξ2
... | Inr ¬ref2 = CSOrR (not-ref-sat ct2 wt fin ¬ref2)
... | Inl ref2 = abort (¬ref (RXOr ref1 ref2))
notintro-not-sat-ref : ∀{ξ e} →
e notintro →
(e ⊧̇ ξ → ⊥) →
ξ xrefutable
notintro-not-sat-ref {·⊤} ni ¬sat = abort (¬sat CSTruth)
notintro-not-sat-ref {·⊥} ni ¬sat = RXFalsity
notintro-not-sat-ref {·?} ni ¬sat = RXUnknown
notintro-not-sat-ref {N n} ni ¬sat = RXNum
notintro-not-sat-ref {inl ξ} ni ¬sat = RXInl
notintro-not-sat-ref {inr ξ} ni ¬sat = RXInr
notintro-not-sat-ref {⟨ ξ1 , ξ2 ⟩} {e = e} ni ¬sat
with satisfy-dec (fst e) ξ1 | satisfy-dec (snd e) ξ2
... | Inl sat1 | Inl sat2 =
abort (¬sat (CSNotIntroPair ni sat1 sat2))
... | Inl sat1 | Inr ¬sat2 =
RXPairR (notintro-not-sat-ref NVSnd ¬sat2)
... | Inr ¬sat1 | Inl sat2 =
RXPairL (notintro-not-sat-ref NVFst ¬sat1)
... | Inr ¬sat1 | Inr ¬sat2 =
RXPairL (notintro-not-sat-ref NVFst ¬sat1)
notintro-not-sat-ref {ξ1 ∨ ξ2} ni ¬sat =
RXOr (notintro-not-sat-ref ni (λ sat1 → ¬sat (CSOrL sat1)))
(notintro-not-sat-ref ni (λ sat2 → ¬sat (CSOrR sat2)))
notintro-maysat-ref : ∀{ξ e} →
e notintro →
e ⊧̇? ξ →
ξ xrefutable
notintro-maysat-ref ni CMSUnknown = RXUnknown
notintro-maysat-ref ni (CMSInl msat) = RXInl
notintro-maysat-ref ni (CMSInr msat) = RXInr
notintro-maysat-ref () (CMSPairL _ _)
notintro-maysat-ref () (CMSPairR _ _)
notintro-maysat-ref () (CMSPair msat1 msat2)
notintro-maysat-ref ni (CMSOrL msat1 ¬sat2) =
RXOr (notintro-maysat-ref ni msat1)
(notintro-not-sat-ref ni ¬sat2)
notintro-maysat-ref ni (CMSOrR ¬sat1 msat2) =
RXOr (notintro-not-sat-ref ni ¬sat1)
(notintro-maysat-ref ni msat2)
notintro-maysat-ref ni (CMSNotIntro ni' ref pos) = ref
satormay-inl : ∀{e τ ξ} →
e ⊧̇†? ξ →
inl τ e ⊧̇†? inl ξ
satormay-inl (CSMSSat sat) = CSMSSat (CSInl sat)
satormay-inl (CSMSMay msat) = CSMSMay (CMSInl msat)
inl-satormay : ∀{e τ ξ} →
inl τ e ⊧̇†? inl ξ →
e ⊧̇†? ξ
inl-satormay (CSMSSat (CSInl sat)) = CSMSSat sat
inl-satormay (CSMSMay (CMSInl msat)) = CSMSMay msat
satormay-inr : ∀{e τ ξ} →
e ⊧̇†? ξ →
inr τ e ⊧̇†? inr ξ
satormay-inr (CSMSSat sat) = CSMSSat (CSInr sat)
satormay-inr (CSMSMay msat) = CSMSMay (CMSInr msat)
inr-satormay : ∀{e τ ξ} →
inr τ e ⊧̇†? inr ξ →
e ⊧̇†? ξ
inr-satormay (CSMSSat (CSInr sat)) = CSMSSat sat
inr-satormay (CSMSMay (CMSInr msat)) = CSMSMay msat
satormay-pair : ∀{e1 e2 ξ1 ξ2} →
e1 ⊧̇†? ξ1 →
e2 ⊧̇†? ξ2 →
⟨ e1 , e2 ⟩ ⊧̇†? ⟨ ξ1 , ξ2 ⟩
satormay-pair (CSMSSat sat1) (CSMSSat sat2) =
CSMSSat (CSPair sat1 sat2)
satormay-pair (CSMSSat sat1) (CSMSMay msat2) =
CSMSMay (CMSPairR sat1 msat2)
satormay-pair (CSMSMay msat1) (CSMSSat sat2) =
CSMSMay (CMSPairL msat1 sat2)
satormay-pair (CSMSMay msat1) (CSMSMay msat2) =
CSMSMay (CMSPair msat1 msat2)
pair-satormay : ∀{e1 e2 ξ1 ξ2} →
⟨ e1 , e2 ⟩ ⊧̇†? ⟨ ξ1 , ξ2 ⟩ →
(e1 ⊧̇†? ξ1) × (e2 ⊧̇†? ξ2)
pair-satormay (CSMSSat (CSPair sat1 sat2)) =
CSMSSat sat1 , CSMSSat sat2
pair-satormay (CSMSMay (CMSPairL msat1 sat2)) =
CSMSMay msat1 , CSMSSat sat2
pair-satormay (CSMSMay (CMSPairR sat1 msat2)) =
CSMSSat sat1 , CSMSMay msat2
pair-satormay (CSMSMay (CMSPair msat1 msat2)) =
CSMSMay msat1 , CSMSMay msat2
satormay-or-l : ∀{e ξ1 ξ2} →
e ⊧̇†? ξ1 →
e ⊧̇†? (ξ1 ∨ ξ2)
satormay-or-l (CSMSSat sat) = CSMSSat (CSOrL sat)
satormay-or-l {e = e} {ξ2 = ξ2} (CSMSMay msat)
with satisfy-dec e ξ2
... | Inl sat2 = CSMSSat (CSOrR sat2)
... | Inr ¬sat2 = CSMSMay (CMSOrL msat ¬sat2)
satormay-or-r : ∀{e ξ1 ξ2} →
e ⊧̇†? ξ2 →
e ⊧̇†? (ξ1 ∨ ξ2)
satormay-or-r (CSMSSat sat) = CSMSSat (CSOrR sat)
satormay-or-r {e = e} {ξ1 = ξ1} (CSMSMay msat)
with satisfy-dec e ξ1
... | Inl sat1 = CSMSSat (CSOrL sat1)
... | Inr ¬sat1 = CSMSMay (CMSOrR ¬sat1 msat)
or-satormay : ∀{e ξ1 ξ2} →
e ⊧̇†? (ξ1 ∨ ξ2) →
(e ⊧̇†? ξ1) + (e ⊧̇†? ξ2)
or-satormay (CSMSSat (CSOrL sat1)) = Inl (CSMSSat sat1)
or-satormay (CSMSSat (CSOrR sat2)) = Inr (CSMSSat sat2)
or-satormay (CSMSMay (CMSOrL msat1 ¬sat2)) = Inl (CSMSMay msat1)
or-satormay (CSMSMay (CMSOrR ¬sat1 msat2)) = Inr (CSMSMay msat2)
or-satormay (CSMSMay (CMSNotIntro ni (RXOr ref1 ref2)
(POrL pos1))) =
Inl (CSMSMay (CMSNotIntro ni ref1 pos1))
or-satormay (CSMSMay (CMSNotIntro ni (RXOr ref1 ref2)
(POrR pos2))) =
Inr (CSMSMay (CMSNotIntro ni ref2 pos2))
-- these two quick lemmas show that if à lambda
-- satisfies a constraint, then anything at all must
-- match that constraint
lam-sat-all-sat : ∀{x e τ ξ e'} →
(·λ x ·[ τ ] e) ⊧̇ ξ →
e' ⊧̇ ξ
lam-sat-all-sat CSTruth = CSTruth
lam-sat-all-sat (CSOrL sat) =
CSOrL (lam-sat-all-sat sat)
lam-sat-all-sat (CSOrR sat) =
CSOrR (lam-sat-all-sat sat)
all-lam-maysat : ∀{x τ e ξ x' τ' e'} →
(·λ x ·[ τ ] e) ⊧̇? ξ →
(·λ x' ·[ τ' ] e') ⊧̇? ξ
all-lam-maysat CMSUnknown = CMSUnknown
all-lam-maysat {ξ = ξ1 ∨ ξ2} {e' = e'}
(CMSOrL msat1 ¬sat2) =
CMSOrL (all-lam-maysat msat1)
(λ{sat2' → ¬sat2 (lam-sat-all-sat sat2')})
all-lam-maysat (CMSOrR ¬sat1 msat2) =
CMSOrR (λ{sat1' → ¬sat1 (lam-sat-all-sat sat1')})
(all-lam-maysat msat2)
-- the lemmas below show that constraints behave the
-- same for all notintro expressions w.r.t. satisfication
-- if some notintro expression satisfies a constraint,
-- then all notintro expressions satisfy a constraint
all-notintro-sat : ∀{e ξ e'} →
e notintro →
e ⊧̇ ξ →
e' notintro →
e' ⊧̇ ξ
all-notintro-sat ni CSTruth ni' = CSTruth
all-notintro-sat ni (CSNotIntroPair x sat1 sat2) ni' =
CSNotIntroPair ni' (all-notintro-sat NVFst sat1 NVFst)
(all-notintro-sat NVSnd sat2 NVSnd)
all-notintro-sat ni (CSOrL sat) ni' =
CSOrL (all-notintro-sat ni sat ni')
all-notintro-sat ni (CSOrR sat) ni' =
CSOrR (all-notintro-sat ni sat ni')
-- if some notintro expression does not
-- satisfy a constraint, then no notintro
-- expression can satisfy the constraint
all-notintro-not-sat : ∀{e ξ e'} →
e notintro →
(e ⊧̇ ξ → ⊥) →
e' notintro →
e' ⊧̇ ξ →
⊥
all-notintro-not-sat ni ¬sat ni' CSTruth = ¬sat CSTruth
all-notintro-not-sat ni ¬sat ni'
(CSNotIntroPair _ sat1' sat2') =
¬sat (CSNotIntroPair ni
(all-notintro-sat NVFst sat1' NVFst)
(all-notintro-sat NVSnd sat2' NVSnd))
all-notintro-not-sat ni ¬sat ni' (CSOrL sat') =
¬sat (CSOrL (all-notintro-sat ni' sat' ni))
all-notintro-not-sat ni ¬sat ni' (CSOrR sat') =
¬sat (CSOrR (all-notintro-sat ni' sat' ni))
-- if a constraint may be matched by some notintro
-- expression, then it may be matched by any notintro
-- expression
all-notintro-maysat : ∀{e ξ e'} →
e notintro →
e ⊧̇? ξ →
e' notintro →
e' ⊧̇? ξ
all-notintro-maysat ni CMSUnknown ni' = CMSUnknown
all-notintro-maysat ni (CMSOrL msat1 ¬sat2) ni' =
CMSOrL (all-notintro-maysat ni msat1 ni')
(all-notintro-not-sat ni ¬sat2 ni')
all-notintro-maysat ni (CMSOrR ¬sat1 msat2) ni' =
CMSOrR (all-notintro-not-sat ni ¬sat1 ni')
(all-notintro-maysat ni msat2 ni')
all-notintro-maysat ni (CMSNotIntro _ ref pos) ni' =
CMSNotIntro ni' ref pos
entails-trans : ∀{τ ξ1 ξ2 ξ3} →
ξ1 ·: τ c⊧̇ ξ2 →
ξ3 :c: τ →
(∀{Δ Δp e} →
∅ , Δ , Δp ⊢ e :: τ →
e val →
e ⊧̇ ξ2 →
e ⊧̇ ξ3) →
ξ1 ·: τ c⊧̇ ξ3
entails-trans (Entails ct1 ct2 ent12) ct3 ent23 =
Entails ct1 ct3
(λ wt val satm1 →
ent23 wt val (ent12 wt val satm1))