-
Notifications
You must be signed in to change notification settings - Fork 0
/
continuity1b.lagda
1277 lines (1027 loc) · 70.1 KB
/
continuity1b.lagda
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\begin{code}
{-# OPTIONS --rewriting #-}
{-# OPTIONS --guardedness #-}
--{-# OPTIONS --auto-inline #-}
open import Level using (Level ; 0ℓ ; Lift ; lift ; lower) renaming (suc to lsuc)
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
open import Agda.Builtin.Sigma
open import Relation.Nullary
open import Relation.Unary using (Pred; Decidable)
open import Relation.Binary.PropositionalEquality using (sym ; trans ; subst)
open import Data.Product
open import Data.Product.Properties
open import Data.Sum
open import Data.Empty
open import Data.Maybe
open import Data.Unit using (⊤ ; tt)
open import Data.Nat using (ℕ ; _<_ ; _≤_ ; _≥_ ; _≤?_ ; suc ; _+_ ; pred)
open import Data.Nat.Properties
open import Data.Bool using (Bool ; _∧_ ; _∨_)
open import Agda.Builtin.String
open import Agda.Builtin.String.Properties
open import Data.List
open import Data.List.Properties
open import Data.List.Relation.Unary.Any
open import Data.List.Relation.Binary.Subset.Propositional
open import Data.List.Relation.Binary.Subset.Propositional.Properties
open import Data.List.Membership.Propositional
open import Data.List.Membership.Propositional.Properties
open import Function.Bundles
open import Induction.WellFounded
open import util
open import name
open import calculus
open import terms
open import world
open import choice
open import choiceExt
open import choiceVal
open import compatible
open import getChoice
open import progress
open import freeze
open import newChoice
open import mod
open import choiceBar
open import encode
module continuity1b {L : Level} (W : PossibleWorlds {L}) (M : Mod W)
(C : Choice)
(K : Compatible {L} W C)
(G : GetChoice {L} W C K)
(X : ChoiceExt W C)
(N : NewChoice {L} W C K G)
(EC : Encode)
where
open import worldDef(W)
open import computation(W)(C)(K)(G)(X)(N)(EC)
open import terms2(W)(C)(K)(G)(X)(N)(EC)
open import terms3(W)(C)(K)(G)(X)(N)(EC)
open import terms4(W)(C)(K)(G)(X)(N)(EC)
--open import terms5(W)(C)(K)(G)(X)(N)(EC)
open import terms6(W)(C)(K)(G)(X)(N)(EC)
open import terms8(W)(C)(K)(G)(X)(N)(EC)
open import terms9 --(W)(C)(K)(G)(X)(N)(EC)
open import bar(W)
open import barI(W)(M)--(C)(K)(P)
open import forcing(W)(M)(C)(K)(G)(X)(N)(EC)
open import props0(W)(M)(C)(K)(G)(X)(N)(EC)
open import ind2(W)(M)(C)(K)(G)(X)(N)(EC)
open import choiceDef{L}(C)
open import compatibleDef{L}(W)(C)(K)
open import getChoiceDef(W)(C)(K)(G)
open import newChoiceDef(W)(C)(K)(G)(N)
open import choiceExtDef(W)(C)(K)(G)(X)
open import props1(W)(M)(C)(K)(G)(X)(N)(EC)
open import props2(W)(M)(C)(K)(G)(X)(N)(EC)
open import props3(W)(M)(C)(K)(G)(X)(N)(EC)
open import props4(W)(M)(C)(K)(G)(X)(N)(EC)
open import continuity-conds(W)(C)(K)(G)(X)(N)(EC)
open import continuity1(W)(M)(C)(K)(G)(X)(N)(EC)
open import continuity2(W)(M)(C)(K)(G)(X)(N)(EC)
→≡sucIf≤ : {v : Var} {a b : Var}
→ a ≡ b
→ sucIf≤ v a ≡ sucIf≤ v b
→≡sucIf≤ {v} {a} {b} e rewrite e = refl
NAMEinj : {n m : Name} → NAME n ≡ NAME m → n ≡ m
NAMEinj refl = refl
#⇓sameℕ : (w : 𝕎·) (t1 t2 : CTerm) → Set
#⇓sameℕ w t1 t2 = Σ ℕ (λ n → t1 #⇓ (#NUM n) at w × t2 #⇓ (#NUM n) at w)
testMup : (name : Name) (F f : Term) → Term
testMup name F f = testM name (shiftNameUp 0 F) (shiftNameUp 0 f)
#testMup : (name : Name) (F f : CTerm) → CTerm
#testMup name F f = #testM name (#shiftNameUp 0 F) (#shiftNameUp 0 f)
νtestMup : (F f : Term) → Term
νtestMup F f = νtestM (shiftNameUp 0 F) (shiftNameUp 0 f)
#νtestMup : (F f : CTerm) → CTerm
#νtestMup F f = #νtestM (#shiftNameUp 0 F) (#shiftNameUp 0 f)
testML : (name : Name) (F f : Term) → Term
testML name F f = SEQ (LOAD F) (testM name F f)
testMLup : (name : Name) (F f : Term) → Term
testMLup name F f = SEQ (LOAD F) (testMup name F f)
νtestML : (F f : Term) → Term
νtestML F f = FRESH (testML 0 F f)
νtestMLup : (F f : Term) → Term
νtestMLup F f = FRESH (testMLup 0 F f)
#LOAD : CTerm → CTerm
#LOAD a = ct (LOAD ⌜ a ⌝) c
where
c : # LOAD ⌜ a ⌝
c rewrite CTerm.closed a = refl
#testML : (name : Name) (F f : CTerm) → CTerm
#testML name F f = ct (testML name ⌜ F ⌝ ⌜ f ⌝) c
where
c : # testML name ⌜ F ⌝ ⌜ f ⌝
c rewrite fvars-SEQ0 (LOAD ⌜ F ⌝) (testM name ⌜ F ⌝ ⌜ f ⌝)
| CTerm.closed (#testM name F f)
| CTerm.closed F = refl --refl
#testMLup : (name : Name) (F f : CTerm) → CTerm
#testMLup name F f = ct (testMLup name ⌜ F ⌝ ⌜ f ⌝) c
where
c : # testMLup name ⌜ F ⌝ ⌜ f ⌝
c rewrite fvars-SEQ0 (LOAD ⌜ F ⌝) (testMup name ⌜ F ⌝ ⌜ f ⌝)
| CTerm.closed (#testMup name F f)
| CTerm.closed F = refl --refl
#νtestML : (F f : CTerm) → CTerm
#νtestML F f = ct (νtestML ⌜ F ⌝ ⌜ f ⌝) c
where
c : # νtestML ⌜ F ⌝ ⌜ f ⌝
c = CTerm.closed (#testML 0 F f)
#νtestMLup : (F f : CTerm) → CTerm
#νtestMLup F f = ct (νtestMLup ⌜ F ⌝ ⌜ f ⌝) c
where
c : # νtestMLup ⌜ F ⌝ ⌜ f ⌝
c = CTerm.closed (#testMLup 0 F f)
testM-QNAT-shift : (cn : comp→∀ℕ) (kb : K□) (gc : get-choose-ℕ) (i : ℕ) (w : 𝕎·) (F f : CTerm) (name : Name)
→ compatible· name w Res⊤
→ ∈Type i w #BAIRE→NAT F
→ ∈Type i w #BAIRE f
→ #⇓sameℕ w (#testM name F f) (#testM name F f)
testM-QNAT-shift cn kb gc i w1 F f name comp1 ∈F ∈f =
suc k , ack , ack
where
w2 : 𝕎·
w2 = chooseT name w1 (NUM 0)
cs : set0 name ⇓ AX from w1 to w2
cs = 1 , refl
e2 : w1 ⊑· w2
e2 = ⇓from-to→⊑ {w1} {w2} cs
-- we prove that in w2 name's value is 0
gc0 : getT 0 name w2 ≡ just (NUM 0)
gc0 = gc name w1 0 comp1
g0 : ∀𝕎 w2 (λ w' e → Lift {0ℓ} (lsuc(L)) (Σ ℕ (λ j → getT 0 name w' ≡ just (NUM j))))
g0 = cn name w1 0 comp1
eqa : ∈Type i w2 #NAT (#APPLY F (#upd name f))
eqa = equalInType-FUN→
(≡CTerm→equalInType #BAIRE→NAT≡ (equalInType-mon ∈F w2 e2))
w2 (⊑-refl· _) (#upd name f) (#upd name f)
(upd∈ i w2 name f g0 (equalInType-mon ∈f w2 e2))
eqn : NATeq w2 (#APPLY F (#upd name f)) (#APPLY F (#upd name f))
eqn = kb (equalInType-NAT→ i w2 (#APPLY F (#upd name f)) (#APPLY F (#upd name f)) eqa) w2 (⊑-refl· _)
cak : Σ ℕ (λ k → appUpd name ⌜ F ⌝ ⌜ f ⌝ ⇛ NUM k at w2)
cak = fst eqn , fst (snd eqn)
m : ℕ
m = fst cak
ca : Σ 𝕎· (λ w' → appUpd name ⌜ F ⌝ ⌜ f ⌝ ⇓ NUM m from w2 to w')
ca = ⇛→⇓from-to (snd cak)
w3 : 𝕎·
w3 = fst ca
e3 : w2 ⊑· w3
e3 = ⇓from-to→⊑ {w2} {w3} (snd ca)
gt0 : Σ ℕ (λ k → getT 0 name w3 ≡ just (NUM k))
gt0 = lower (g0 w3 e3)
k : ℕ
k = fst gt0
gk : get0 name ⇓ NUM k from w3 to w3
gk = 1 , step-APPLY-CS (NUM k) w3 0 name (snd gt0)
pbk : probeM name ⌜ F ⌝ ⌜ f ⌝ ⇓ NUM (suc k) from w2 to w3
pbk = ⇓-trans₂ (SEQ⇓₁ (snd ca)) (⇓-trans₂ (SEQ-val⇓ w3 (NUM m) (SUC (get0 name)) tt) (⇓NUM→SUC⇓NUM gk))
ack : testM name ⌜ F ⌝ ⌜ f ⌝ ⇓ NUM (suc k) at w1
ack = ⇓-from-to→⇓ {w1} {w3} {testM name ⌜ F ⌝ ⌜ f ⌝} {NUM (suc k)}
(⇓-trans₂ {w1} {w2} {w3} {testM name ⌜ F ⌝ ⌜ f ⌝} {SEQ AX (probeM name ⌜ F ⌝ ⌜ f ⌝)} {NUM (suc k)}
(SEQ⇓₁ {w1} {w2} {set0 name} {AX} {probeM name ⌜ F ⌝ ⌜ f ⌝} cs)
(⇓-trans₂ (SEQ-val⇓ w2 AX (probeM name ⌜ F ⌝ ⌜ f ⌝) tt) pbk))
νtestM-QNAT-shift : (cn : comp→∀ℕ) (kb : K□) (gc : get-choose-ℕ) (i : ℕ) (w : 𝕎·) (F f : CTerm)
→ ∈Type i w #BAIRE→NAT F
→ ∈Type i w #BAIRE f
→ #⇓sameℕ w (#νtestMup F f) (#νtestMup F f)
νtestM-QNAT-shift cn kb gc i w F f ∈F ∈f =
fst smn , ack , ack
where
tM : Term
tM = testMup 0 ⌜ F ⌝ ⌜ f ⌝
name : Name
name = newChoiceT w tM
w1 : 𝕎·
w1 = startNewChoiceT Res⊤ w tM
e1 : w ⊑· w1
e1 = startNewChoiceT⊏ Res⊤ w tM
comp1 : compatible· name w1 Res⊤
comp1 = startChoiceCompatible· Res⊤ w name (¬newChoiceT∈dom𝕎 w tM)
s1 : νtestMup ⌜ F ⌝ ⌜ f ⌝ ⇓ testM name ⌜ F ⌝ ⌜ f ⌝ from w to w1
s1 = 1 , ≡pair (shiftNameDown-renn-shiftNameUp name ⌜ F ⌝ ⌜ f ⌝ (CTerm.closed F) (CTerm.closed f)) refl
smn : #⇓sameℕ w1 (#testM name F f) (#testM name F f)
smn = testM-QNAT-shift cn kb gc i w1 F f name comp1 (equalInType-mon ∈F w1 e1) (equalInType-mon ∈f w1 e1)
ack : νtestMup ⌜ F ⌝ ⌜ f ⌝ ⇓ NUM (fst smn) at w
ack = ⇓-trans₁ {w} {w1} {νtestMup ⌜ F ⌝ ⌜ f ⌝} {testM name ⌜ F ⌝ ⌜ f ⌝} {NUM (proj₁ smn)} s1 (fst (snd smn))
≡SEQ : {a b c d : Term} → a ≡ b → c ≡ d → SEQ a c ≡ SEQ b d
≡SEQ {a} {b} {c} {d} e f rewrite e | f = refl
shiftNameDown-renn-shiftNameUp-LOAD :
(name : Name) (F f : Term)
→ # F
→ # f
→ shiftNameDown 0 (renn 0 (suc name) (testMLup 0 F f))
≡ testML name F f
shiftNameDown-renn-shiftNameUp-LOAD name F f cF cf
rewrite shiftUp-shiftNameUp 0 0 F
| shiftUp-shiftNameUp 0 0 f
| #shiftUp 0 (ct F cF)
| #shiftUp 0 (ct f cf)
| shiftUp-shiftNameUp 3 0 f
| #shiftUp 3 (ct f cf)
| renn-shiftNameUp 0 (suc name) F
| renn-shiftNameUp 0 (suc name) f
| shiftNameDownUp 0 F
| shiftNameDownUp 0 f
| shiftUp-shiftNameUp 1 0 F
| shiftUp-shiftNameUp 4 0 f
| #shiftUp 1 (ct F cF)
| #shiftUp 4 (ct f cf)
| renn-shiftNameUp 0 (suc name) F
| renn-shiftNameUp 0 (suc name) f
| shiftNameDownUp 0 F
| shiftNameDownUp 0 f = refl
testML-QNAT-shift : (cn : comp→∀ℕ) (kb : K□) (gc : get-choose-ℕ) (i : ℕ) (w : 𝕎·) (F f : CTerm) (name : Name)
→ compatible· name w Res⊤
→ ∈Type i w #BAIRE→NAT F
→ ∈Type i w #BAIRE f
→ #⇓sameℕ w (#testML name F f) (#testML name F f)
testML-QNAT-shift cn kb gc i w F f name compat ∈F ∈f =
fst smn , ack , ack
where
w1 : 𝕎·
w1 = startNewChoices Res⊤ w ⌜ F ⌝
e1 : w ⊑· w1
e1 = startNewChoices⊑ Res⊤ w ⌜ F ⌝
s1 : testML name ⌜ F ⌝ ⌜ f ⌝ ⇓ SEQ AX (testM name ⌜ F ⌝ ⌜ f ⌝) from w to w1
s1 = 1 , refl
smn : #⇓sameℕ w1 (#testM name F f) (#testM name F f)
smn = testM-QNAT-shift cn kb gc i w1 F f name (⊑-compatible· e1 compat) (equalInType-mon ∈F w1 e1) (equalInType-mon ∈f w1 e1)
ack : testML name ⌜ F ⌝ ⌜ f ⌝ ⇓ NUM (fst smn) at w
ack = ⇓-trans₁ {w} {w1} {testML name ⌜ F ⌝ ⌜ f ⌝} {SEQ AX (testM name ⌜ F ⌝ ⌜ f ⌝)} {NUM (proj₁ smn)}
s1
(⇓-trans₁ {w1} {w1} {SEQ AX (testM name ⌜ F ⌝ ⌜ f ⌝)} {testM name ⌜ F ⌝ ⌜ f ⌝} {NUM (proj₁ smn)}
(SEQ-AX⇓₁from-to {w1} {testM name ⌜ F ⌝ ⌜ f ⌝} (CTerm.closed (#testM name F f)))
(fst (snd smn)))
νtestMLup-QNAT-shift : (cn : comp→∀ℕ) (kb : K□) (gc : get-choose-ℕ) (i : ℕ) (w : 𝕎·) (F f : CTerm)
→ ∈Type i w #BAIRE→NAT F
→ ∈Type i w #BAIRE f
→ #⇓sameℕ w (#νtestMLup F f) (#νtestMLup F f)
νtestMLup-QNAT-shift cn kb gc i w F f ∈F ∈f =
fst smn , ack , ack
where
tM : Term
tM = testMLup 0 ⌜ F ⌝ ⌜ f ⌝
name : Name
name = newChoiceT w tM
w1 : 𝕎·
w1 = startNewChoiceT Res⊤ w tM
e1 : w ⊑· w1
e1 = startNewChoiceT⊏ Res⊤ w tM
comp1 : compatible· name w1 Res⊤
comp1 = startChoiceCompatible· Res⊤ w name (¬newChoiceT∈dom𝕎 w tM)
s1 : νtestMLup ⌜ F ⌝ ⌜ f ⌝ ⇓ testML name ⌜ F ⌝ ⌜ f ⌝ from w to w1
s1 = 1 , ≡pair (shiftNameDown-renn-shiftNameUp-LOAD name ⌜ F ⌝ ⌜ f ⌝ (CTerm.closed F) (CTerm.closed f)) refl
smn : #⇓sameℕ w1 (#testML name F f) (#testML name F f)
smn = testML-QNAT-shift cn kb gc i w1 F f name comp1 (equalInType-mon ∈F w1 e1) (equalInType-mon ∈f w1 e1)
ack : νtestMLup ⌜ F ⌝ ⌜ f ⌝ ⇓ NUM (fst smn) at w
ack = ⇓-trans₁ {w} {w1} {νtestMLup ⌜ F ⌝ ⌜ f ⌝} {testML name ⌜ F ⌝ ⌜ f ⌝} {NUM (proj₁ smn)} s1 (fst (snd smn))
testM-QNAT : (cn : comp→∀ℕ) (kb : K□) (gc : get-choose-ℕ)
(i : ℕ) (w : 𝕎·) (F f : CTerm)
→ ∈Type i w #BAIRE→NAT F
→ ∈Type i w #BAIRE f
→ ∈Type i w #QNAT (#νtestMup F f)
testM-QNAT cn kb gc i w F f ∈F ∈f =
→equalInType-QNAT i w (#νtestMup F f) (#νtestMup F f) (Mod.∀𝕎-□ M aw)
where
aw : ∀𝕎 w (λ w' _ → #weakMonEq w' (#νtestMup F f) (#νtestMup F f))
aw w1 e1 w2 e2 = lift (νtestM-QNAT-shift cn kb gc i w2 F f (equalInType-mon ∈F w2 (⊑-trans· e1 e2)) (equalInType-mon ∈f w2 (⊑-trans· e1 e2)))
contQBody : (F f : Term) → Term
contQBody F f =
SUM QNAT
(PI BAIRE
(FUN (EQ f (VAR 0) (QBAIREn! (VAR 1)))
(EQ (APPLY F f) (APPLY F (VAR 0)) NAT)))
#contQBody : (F f : CTerm) → CTerm
#contQBody F f = ct (contQBody ⌜ F ⌝ ⌜ f ⌝) c
where
c : # contQBody ⌜ F ⌝ ⌜ f ⌝
c rewrite CTerm.closed f
| #shiftUp 0 f
| #shiftUp 0 F
| CTerm.closed F
| CTerm.closed f
| #shiftUp 1 f
| #shiftUp 1 F
| CTerm.closed F
| CTerm.closed f = refl
#contQBody≡ : (F f : CTerm)
→ #contQBody F f
≡ #SUM #QNAT
(#[0]PI #[0]BAIRE
(#[1]FUN (#[1]EQ ⌞ f ⌟ #[1]VAR0 (#[1]QBAIREn! #[1]VAR1))
(#[1]EQ (#[1]APPLY ⌞ F ⌟ ⌞ f ⌟) (#[1]APPLY ⌞ F ⌟ #[1]VAR0) #[1]NAT)))
#contQBody≡ F f = CTerm≡ refl
→equalTypesQLT : {i : ℕ} {w : 𝕎·} {a₁ a₂ b₁ b₂ : CTerm}
→ equalInType i w #QNAT a₁ a₂
→ equalInType i w #QNAT b₁ b₂
→ equalTypes i w (#QLT a₁ b₁) (#QLT a₂ b₂)
→equalTypesQLT {i} {w} {a₁} {a₂} {b₁} {b₂} ea eb =
eqTypes-local (∀𝕎-□Func2 aw ea1 eb1)
where
ea1 : □· w (λ w' _ → #weakMonEq w' a₁ a₂)
ea1 = equalInType-QNAT→ i w a₁ a₂ ea
eb1 : □· w (λ w' _ → #weakMonEq w' b₁ b₂)
eb1 = equalInType-QNAT→ i w b₁ b₂ eb
aw : ∀𝕎 w (λ w' e' → #weakMonEq w' a₁ a₂ → #weakMonEq w' b₁ b₂ → equalTypes i w' (#QLT a₁ b₁) (#QLT a₂ b₂))
aw w1 e1 ha hb =
EQTQLT a₁ a₂ b₁ b₂ (#compAllRefl (#QLT a₁ b₁) w1) (#compAllRefl (#QLT a₂ b₂) w1) ha hb
sub0-QNATn-body : (a n : CTerm) → sub0 a (#[0]QLT #[0]VAR ⌞ n ⌟) ≡ #QLT a n
sub0-QNATn-body a n rewrite CTerm→CTerm0→Term n = CTerm≡ e
where
e : QLT (shiftDown 0 (shiftUp 0 ⌜ a ⌝)) (shiftDown 0 (subv 0 (shiftUp 0 ⌜ a ⌝) ⌜ n ⌝))
≡ QLT (CTerm.cTerm a) ⌜ n ⌝
e rewrite #shiftUp 0 a
| #subv 0 ⌜ a ⌝ ⌜ n ⌝ (CTerm.closed n)
| #shiftDown 0 n | #shiftDown 0 a = refl
≡QNATn : (n : CTerm) → #QNATn n ≡ #SET #NAT (#[0]QLT #[0]VAR ⌞ n ⌟)
≡QNATn n rewrite CTerm→CTerm0→Term n = CTerm≡ (≡SET refl e)
where
e : QLT (VAR 0) (shiftUp 0 ⌜ n ⌝) ≡ QLT (VAR 0) ⌜ n ⌝
e rewrite #shiftUp 0 n = refl
∈NAT→∈QNAT : {i : ℕ} {w : 𝕎·} {a b : CTerm}
→ equalInType i w #NAT a b
→ equalInType i w #QNAT a b
∈NAT→∈QNAT {i} {w} {a} {b} ea =
→equalInType-QNAT i w a b (Mod.∀𝕎-□Func M aw ea2)
where
ea2 : □· w (λ w' _ → NATeq w' a b)
ea2 = equalInType-NAT→ i w a b ea
aw : ∀𝕎 w (λ w' e' → NATeq w' a b → #weakMonEq w' a b)
aw w1 e1 (k , c₁ , c₂) w2 e2 = lift (k , lower (c₁ w2 e2) , lower (c₂ w2 e2))
→equalTypesQNATn : (i : ℕ) (w : 𝕎·) (a₁ a₂ : CTerm)
→ equalInType i w #QNAT a₁ a₂
→ equalTypes i w (#QNATn a₁) (#QNATn a₂)
→equalTypesQNATn i w a₁ a₂ ea =
≡CTerm→eqTypes
(sym (≡QNATn a₁))
(sym (≡QNATn a₂))
(eqTypesSET← {B = #[0]QLT #[0]VAR ⌞ a₁ ⌟} {D = #[0]QLT #[0]VAR ⌞ a₂ ⌟} (λ w' e' → eqTypesNAT) aw1)
where
aw2 : ∀𝕎 w (λ w' _ → (b₁ b₂ : CTerm) → equalInType i w' #NAT b₁ b₂
→ equalTypes i w' (#QLT b₁ a₁) (#QLT b₂ a₂))
aw2 w1 e1 b₁ b₂ eb = →equalTypesQLT (∈NAT→∈QNAT eb) (equalInType-mon ea w1 e1)
aw1 : ∀𝕎 w (λ w' _ → (b₁ b₂ : CTerm) → equalInType i w' #NAT b₁ b₂
→ equalTypes i w' (sub0 b₁ (#[0]QLT #[0]VAR ⌞ a₁ ⌟)) (sub0 b₂ (#[0]QLT #[0]VAR ⌞ a₂ ⌟)))
aw1 w1 e1 b₁ b₂ eb = ≡CTerm→eqTypes (sym (sub0-QNATn-body b₁ a₁)) (sym (sub0-QNATn-body b₂ a₂)) (aw2 w1 e1 b₁ b₂ eb)
→equalTypesQBAIREn : (i : ℕ) (w : 𝕎·) (a₁ a₂ : CTerm)
→ equalInType i w #QNAT a₁ a₂
→ equalTypes i w (#QBAIREn a₁) (#QBAIREn a₂)
→equalTypesQBAIREn i w a₁ a₂ ea =
≡CTerm→eqTypes
(sym (≡QBAIREn a₁))
(sym (≡QBAIREn a₂))
(eqTypesFUN← (→equalTypesQNATn i w a₁ a₂ ea) eqTypesNAT)
→equalTypesQBAIREn! : (i : ℕ) (w : 𝕎·) (a₁ a₂ : CTerm)
→ equalInType i w #QNAT a₁ a₂
→ equalTypes i w (#QBAIREn! a₁) (#QBAIREn! a₂)
→equalTypesQBAIREn! i w a₁ a₂ ea =
≡CTerm→eqTypes
(sym (≡QBAIREn! a₁))
(sym (≡QBAIREn! a₂))
(eqTypesFUN← (→equalTypesQNATn i w a₁ a₂ ea) isTypeNAT!)
∈QNATn→∈NAT : {i : ℕ} {w : 𝕎·} {a b n : CTerm}
→ equalInType i w #QNAT n n
→ equalInType i w (#QNATn n) a b
→ equalInType i w #NAT a b
∈QNATn→∈NAT {i} {w} {a} {b} {n} en ea =
→equalInType-NAT i w a b (Mod.□-idem M (Mod.∀𝕎-□Func M aw1 eb2))
where
eb1 : equalInType i w (#SET #NAT (#[0]QLT #[0]VAR ⌞ n ⌟)) a b
eb1 = ≡CTerm→equalInType (≡QNATn n) ea
eb2 : □· w (λ w' _ → SETeq (equalInType i w' #NAT) (λ x y ea → equalInType i w' (sub0 x (#[0]QLT #[0]VAR ⌞ n ⌟))) a b)
eb2 = equalInType-SET→ {B = #[0]QLT #[0]VAR ⌞ n ⌟} eb1
aw1 : ∀𝕎 w (λ w' e' → SETeq (equalInType i w' #NAT) (λ x y ea₁ → equalInType i w' (sub0 x (#[0]QLT #[0]VAR (CTerm→CTerm0 n)))) a b
→ □· w' (↑wPred' (λ w'' _ → NATeq w'' a b) e'))
aw1 w1 e1 (x , ex , ey) = Mod.∀𝕎-□Func M (λ w2 e2 s z → s) (equalInType-NAT→ i w1 a b ex)
∈BAIRE→∈QBAIREn : {i : ℕ} {w : 𝕎·} {f g n : CTerm}
→ equalInType i w #QNAT n n
→ equalInType i w #BAIRE f g
→ equalInType i w (#QBAIREn n) f g
∈BAIRE→∈QBAIREn {i} {w} {f} {g} {n} en ef =
≡CTerm→equalInType
(sym (≡QBAIREn n))
(equalInType-FUN (→equalTypesQNATn i w n n en)
eqTypesNAT
aw)
where
ef1 : equalInType i w (#FUN #NAT #NAT) f g
ef1 = ≡CTerm→equalInType #BAIRE≡ ef
ef2 : ∀𝕎 w (λ w' _ → (a₁ a₂ : CTerm) → equalInType i w' #NAT a₁ a₂ → equalInType i w' #NAT (#APPLY f a₁) (#APPLY g a₂))
ef2 = equalInType-FUN→ ef1
aw : ∀𝕎 w (λ w' _ → (a₁ a₂ : CTerm) → equalInType i w' (#QNATn n) a₁ a₂
→ equalInType i w' #NAT (#APPLY f a₁) (#APPLY g a₂))
aw w1 e1 a₁ a₂ ea = ef2 w1 e1 a₁ a₂ (∈QNATn→∈NAT (equalInType-mon en w1 e1) ea)
sub0-contQBodyPI : (F f a : CTerm)
→ sub0 a (#[0]PI #[0]BAIRE
(#[1]FUN (#[1]EQ ⌞ f ⌟ #[1]VAR0 (#[1]QBAIREn! #[1]VAR1))
(#[1]EQ (#[1]APPLY ⌞ F ⌟ ⌞ f ⌟) (#[1]APPLY ⌞ F ⌟ #[1]VAR0) #[1]NAT)))
≡ #PI #BAIRE
(#[0]FUN (#[0]EQ ⌞ f ⌟ #[0]VAR (#[0]QBAIREn! ⌞ a ⌟))
(#[0]EQ (#[0]APPLY ⌞ F ⌟ ⌞ f ⌟) (#[0]APPLY ⌞ F ⌟ #[0]VAR) #[0]NAT))
sub0-contQBodyPI F f a
rewrite CTerm→CTerm1→Term f
= CTerm≡ (≡PI refl (≡PI e1 e2)) --e1 e2))
where
e1 : EQ (shiftDown 1 (subv 1 (shiftUp 0 (shiftUp 0 ⌜ a ⌝)) ⌜ f ⌝))
(VAR 0)
(PI (SET NAT (QLT (VAR 0) (shiftDown 2 (shiftUp 0 (shiftUp 0 (shiftUp 0 ⌜ a ⌝)))))) NAT!)
≡ EQ ⌜ f ⌝ (VAR 0) (PI (SET NAT (QLT (VAR 0) (shiftUp 0 ⌜ a ⌝))) NAT!)
e1 rewrite #shiftUp 0 a | #shiftUp 0 a | #shiftUp 0 a
| #subv 1 ⌜ a ⌝ ⌜ f ⌝ (CTerm.closed f)
| #shiftDown 1 a | #shiftDown 2 a | #shiftDown 1 f = refl
e2 : EQ (APPLY (shiftDown 2 (subv 2 (shiftUp 0 (shiftUp 0 (shiftUp 0 ⌜ a ⌝))) (shiftUp 0 ⌜ F ⌝)))
(shiftDown 2 (subv 2 (shiftUp 0 (shiftUp 0 (shiftUp 0 ⌜ a ⌝))) (shiftUp 0 ⌜ f ⌝))))
(APPLY (shiftDown 2 (subv 2 (shiftUp 0 (shiftUp 0 (shiftUp 0 ⌜ a ⌝))) (shiftUp 0 ⌜ F ⌝)))
(VAR 1))
NAT
≡ EQ (APPLY (shiftUp 0 ⌜ F ⌝) (shiftUp 0 ⌜ f ⌝)) (APPLY (shiftUp 0 ⌜ F ⌝) (VAR 1)) NAT
e2 rewrite #shiftUp 0 a | #shiftUp 0 a | #shiftUp 0 a | #shiftUp 0 F | #shiftUp 0 f
| #subv 2 ⌜ a ⌝ ⌜ F ⌝ (CTerm.closed F)
| #subv 2 ⌜ a ⌝ ⌜ f ⌝ (CTerm.closed f)
| #shiftDown 2 F | #shiftDown 2 f = refl
sub0-contQBodyPI-PI : (F f a g : CTerm)
→ sub0 g (#[0]FUN (#[0]EQ ⌞ f ⌟ #[0]VAR (#[0]QBAIREn! ⌞ a ⌟))
(#[0]EQ (#[0]APPLY ⌞ F ⌟ ⌞ f ⌟) (#[0]APPLY ⌞ F ⌟ #[0]VAR) #[0]NAT))
≡ #FUN (#EQ f g (#QBAIREn! a)) (#EQ (#APPLY F f) (#APPLY F g) #NAT)
sub0-contQBodyPI-PI F f a g
rewrite CTerm→CTerm1→Term f =
CTerm≡ (≡PI e1 e2)
where
e1 : EQ (shiftDown 0 (subv 0 (shiftUp 0 ⌜ g ⌝) ⌜ f ⌝))
(shiftDown 0 (shiftUp 0 ⌜ g ⌝))
(PI (SET NAT (QLT (VAR 0) (shiftDown 1 (subv 1 (shiftUp 0 (shiftUp 0 ⌜ g ⌝)) (shiftUp 0 ⌜ a ⌝))))) NAT!)
≡ EQ ⌜ f ⌝ ⌜ g ⌝ (PI (SET NAT (QLT (VAR 0) (shiftUp 0 ⌜ a ⌝))) NAT!)
e1 rewrite #shiftUp 0 g | #shiftUp 0 g | #shiftUp 0 a
| #subv 0 ⌜ g ⌝ ⌜ f ⌝ (CTerm.closed f)
| #subv 1 ⌜ g ⌝ ⌜ a ⌝ (CTerm.closed a)
| #shiftDown 0 f | #shiftDown 1 a | #shiftDown 0 g = refl --refl
e2 : EQ (APPLY (shiftDown 1 (subv 1 (shiftUp 0 (shiftUp 0 ⌜ g ⌝)) (shiftUp 0 ⌜ F ⌝)))
(shiftDown 1 (subv 1 (shiftUp 0 (shiftUp 0 ⌜ g ⌝)) (shiftUp 0 ⌜ f ⌝))))
(APPLY (shiftDown 1 (subv 1 (shiftUp 0 (shiftUp 0 ⌜ g ⌝)) (shiftUp 0 ⌜ F ⌝)))
(shiftDown 1 (shiftUp 0 (shiftUp 0 ⌜ g ⌝))))
NAT
≡ EQ (APPLY (shiftUp 0 ⌜ F ⌝) (shiftUp 0 ⌜ f ⌝)) (APPLY (shiftUp 0 ⌜ F ⌝) (shiftUp 0 ⌜ g ⌝)) NAT
e2 rewrite #shiftUp 0 g | #shiftUp 0 g | #shiftUp 0 F | #shiftUp 0 f
| #subv 1 ⌜ g ⌝ ⌜ F ⌝ (CTerm.closed F)
| #subv 1 ⌜ g ⌝ ⌜ f ⌝ (CTerm.closed f)
| #shiftDown 1 F | #shiftDown 1 f | #shiftDown 1 g = refl
equalInType-QBAIREn-BAIRE-trans : {i : ℕ} {w : 𝕎·} {a b c n : CTerm}
→ equalInType i w #BAIRE b c
→ equalInType i w (#QBAIREn n) a b
→ equalInType i w #QNAT n n
→ equalInType i w (#QBAIREn n) a c
equalInType-QBAIREn-BAIRE-trans {i} {w} {a} {b} {c} {n} h1 h2 h3 =
equalInType-trans h2 h4
where
h4 : equalInType i w (#QBAIREn n) b c
h4 = ∈BAIRE→∈QBAIREn h3 h1
#lift-<NUM-pair→#weakMonEqₗ : {w : 𝕎·} {a b : CTerm}
→ ∀𝕎 w (λ w' _ → #lift-<NUM-pair w' a b)
→ #weakMonEq w a a
#lift-<NUM-pair→#weakMonEqₗ {w} {a} {b} h w1 e1 =
lift (fst (lower (h w1 e1)) , fst (snd (snd (lower (h w1 e1)))) , fst (snd (snd (lower (h w1 e1)))))
#lift-<NUM-pair→#weakMonEqᵣ : {w : 𝕎·} {a b : CTerm}
→ ∀𝕎 w (λ w' _ → #lift-<NUM-pair w' a b)
→ #weakMonEq w b b
#lift-<NUM-pair→#weakMonEqᵣ {w} {a} {b} h w1 e1 =
lift (fst (snd (lower (h w1 e1))) , fst (snd (snd (snd (lower (h w1 e1))))) , fst (snd (snd (snd (lower (h w1 e1))))))
→equalInTypeQLT : {i : ℕ} {w : 𝕎·} {a b u v : CTerm}
→ ∀𝕎 w (λ w' _ → #lift-<NUM-pair w' a b)
→ equalInType i w (#QLT a b) u v
→equalInTypeQLT {i} {w} {a} {b} {u} {v} h =
(EQTQLT a a b b (#compAllRefl (#QLT a b) w) (#compAllRefl (#QLT a b) w) (#lift-<NUM-pair→#weakMonEqₗ {w} {a} {b} h) (#lift-<NUM-pair→#weakMonEqᵣ {w} {a} {b} h)) ,
Mod.∀𝕎-□ M (λ w1 e1 → lift (lower (h w1 e1)))
→equalInType-QNATn : {i : ℕ} {w : 𝕎·} {t a b : CTerm}
→ equalInType i w #QNAT t t
→ □· w (λ w' _ → Σ ℕ (λ n → Σ ℕ (λ k → t #⇓ #NUM n at w' × a #⇛ #NUM k at w' × b #⇛ #NUM k at w' × k < n)))
→ equalInType i w (#QNATn t) a b
→equalInType-QNATn {i} {w} {t} {a} {b} eqt eqi =
≡CTerm→equalInType
(sym (≡QNATn t))
(equalInType-SET
{B = #[0]QLT #[0]VAR ⌞ t ⌟}
(λ w' _ → eqTypesNAT)
(λ w' e' a₁ a₂ eqa → ≡CTerm→eqTypes (sym (sub0-QNATn-body a₁ t)) (sym (sub0-QNATn-body a₂ t)) (→equalTypesQLT (∈NAT→∈QNAT eqa) (equalInType-mon eqt w' e')))
(λ w' e' → →equalInType-NAT i w' a b (Mod.∀𝕎-□Func M (λ w'' e'' (n , k , c , c1 , c2 , ltn) → k , c1 , c2) (Mod.↑□ M eqi e')))
(Mod.∀𝕎-□Func M aw (Mod.→□∀𝕎 M eqi)))
where
aw : ∀𝕎 w (λ w' _ → ∀𝕎 w' (λ w'' _ → Σ ℕ (λ n → Σ ℕ (λ k → t #⇓ #NUM n at w'' × a #⇛ #NUM k at w'' × b #⇛ #NUM k at w'' × k < n)))
→ Σ CTerm (∈Type i w' (sub0 a (#[0]QLT #[0]VAR ⌞ t ⌟))))
aw w1 e1 h =
#AX ,
≡CTerm→equalInType
(sym (sub0-QNATn-body a t))
(→equalInTypeQLT {i} {w1} {a} {t}
(λ w2 e2 → lift (fst (snd (h w2 e2)) ,
fst (h w2 e2) ,
lower (fst (snd (snd (snd (h w2 e2)))) w2 (⊑-refl· _)) ,
fst (snd (snd (h w2 e2))) ,
snd (snd (snd (snd (snd (h w2 e2))))))))
→∀𝕎-NATeq-NATeq : (w : 𝕎·) (a b : CTerm)
→ ∀𝕎 w (λ w' _ → Lift {0ℓ} (lsuc(L)) ((k : ℕ) → a #⇓ #NUM k at w' → b #⇓ #NUM k at w'))
→ ∀𝕎 w (λ w' _ → NATeq w' a a → NATeq w' a b)
→∀𝕎-NATeq-NATeq w a b h w1 e1 (n , c₁ , c₂) = n , c₁ , c
where
c : b #⇛ #NUM n at w1
c w2 e2 = lift (lower (h w2 (⊑-trans· e1 e2)) n (lower (c₁ w2 e2)))
abstract
νtestMup⇓ℕ : (cn : comp→∀ℕ) (kb : K□) (gc : get-choose-ℕ) (i : ℕ) (w : 𝕎·) (F f : CTerm)
→ ∈Type i w #BAIRE→NAT F
→ ∈Type i w #BAIRE f
→ Σ ℕ (λ n → Σ 𝕎· (λ w' → #νtestMup F f #⇓ #NUM n from w to w'))
νtestMup⇓ℕ cn kb gc i w F f ∈F ∈f = n , c
where
h : #⇓sameℕ w (#νtestMup F f) (#νtestMup F f)
h = νtestM-QNAT-shift cn kb gc i w F f ∈F ∈f
n : ℕ
n = fst h
c : Σ 𝕎· (λ w' → #νtestMup F f #⇓ #NUM n from w to w')
c = #⇓→from-to {w} {#νtestMup F f} {#NUM n} (fst (snd h))
abstract
νtestMLup⇓ℕ : (cn : comp→∀ℕ) (kb : K□) (gc : get-choose-ℕ) (i : ℕ) (w : 𝕎·) (F f : CTerm)
→ ∈Type i w #BAIRE→NAT F
→ ∈Type i w #BAIRE f
→ Σ ℕ (λ n → Σ 𝕎· (λ w' → #νtestMLup F f #⇓ #NUM n from w to w'))
νtestMLup⇓ℕ cn kb gc i w F f ∈F ∈f = n , c
where
h : #⇓sameℕ w (#νtestMLup F f) (#νtestMLup F f)
h = νtestMLup-QNAT-shift cn kb gc i w F f ∈F ∈f
n : ℕ
n = fst h
c : Σ 𝕎· (λ w' → #νtestMLup F f #⇓ #NUM n from w to w')
c = #⇓→from-to {w} {#νtestMLup F f} {#NUM n} (fst (snd h))
testM⇓→ : (cn : comp→∀ℕ) {w1 w2 : 𝕎·} {F f : Term} {n : ℕ} {name : Name}
→ # F
→ # f
→ compatible· name w1 Res⊤
→ testM name F f ⇓ NUM n from w1 to w2
→ Σ Term (λ v → Σ ℕ (λ k →
APPLY F (upd name f) ⇓ v from (chooseT name w1 (NUM 0)) to w2
× isValue v
× getT 0 name w2 ≡ just (NUM k)
× n ≡ suc k))
testM⇓→ cn {w1} {w2} {F} {f} {n} {name} cF cf compat comp =
fst comp2 ,
fst (snd comp2) ,
fst (snd (snd comp2)) ,
fst (snd (snd (snd comp2))) ,
fst (snd (snd (snd (snd (snd comp2))))) ,
NUMinj (snd (snd (snd (snd (snd (snd comp2))))))
where
w1' : 𝕎·
w1' = chooseT name w1 (NUM 0)
comp1 : probeM name F f ⇓ NUM n from w1' to w2
comp1 = testM⇓→step tt comp
comp2 : Σ Term (λ u → Σ ℕ (λ k →
appUpd name F f ⇓ u from w1' to w2
× isValue u
× get0 name ⇓ NUM k from w2 to w2
× getT 0 name w2 ≡ just (NUM k)
× NUM n ≡ NUM (suc k)))
comp2 = probeM⇓-decomp name F f (NUM n) w1' w2 comp1 tt (cn name w1 0 compat)
≡→steps : {k : ℕ} {a b c : Term} {w1 w2 : 𝕎·}
→ a ≡ b
→ steps k (a , w1) ≡ (c , w2)
→ steps k (b , w1) ≡ (c , w2)
≡→steps {k} {a} {b} {c} {w1} {w2} e h rewrite e = h
testML⇓→ : (cn : comp→∀ℕ) {w1 w2 : 𝕎·} {F f : Term} {n : ℕ} {name : Name}
→ # F
→ # f
→ compatible· name w1 Res⊤
→ testML name F f ⇓ NUM n from w1 to w2
→ Σ Term (λ v → Σ ℕ (λ k →
APPLY F (upd name f) ⇓ v from (chooseT name (startNewChoices Res⊤ w1 F) (NUM 0)) to w2
× isValue v
× getT 0 name w2 ≡ just (NUM k)
× n ≡ suc k))
testML⇓→ cn {w1} {w2} {F} {f} {n} {name} cF cf compat (0 , ())
testML⇓→ cn {w1} {w2} {F} {f} {n} {name} cF cf compat (1 , ())
testML⇓→ cn {w1} {w2} {F} {f} {n} {name} cF cf compat (suc (suc k) , comp) =
testM⇓→
cn {startNewChoices Res⊤ w1 F} {w2} {F} {f} {n} {name} cF cf
(⊑-compatible· (startNewChoices⊑ Res⊤ w1 F) compat)
(k , ≡→steps {k} {sub AX (shiftUp 0 (testM name F f))} {testM name F f} {NUM n} {startNewChoices Res⊤ w1 F} {w2} c comp)
where
c : sub AX (shiftUp 0 (testM name F f)) ≡ testM name F f
c rewrite #shiftUp 0 (#testM name (ct F cF) (ct f cf))
| subNotIn AX (testM name F f) (CTerm.closed (#testM name (ct F cF) (ct f cf)))
| #shiftUp 0 (ct F cF)
| #shiftUp 1 (ct F cF)
| #shiftUp 0 (ct f cf)
| #shiftUp 3 (ct f cf)
| #shiftUp 4 (ct f cf)
| #subv 1 AX F cF
| #shiftDown 1 (ct F cF)
| #subv 4 AX f cf
| #shiftDown 4 (ct f cf) = refl
νtestM⇓→step' : {F f v : Term} {w1 w2 : 𝕎·}
→ # F
→ # f
→ isValue v
→ νtestMup F f ⇓ v from w1 to w2
→ testM (newChoiceT w1 (testMup 0 F f)) F f ⇓ v from startNewChoiceT Res⊤ w1 (testMup 0 F f) to w2
νtestM⇓→step' {F} {f} {v} {w1} {w2} cF cf isv (0 , comp) rewrite pair-inj₁ (sym comp) = ⊥-elim isv
νtestM⇓→step' {F} {f} {v} {w1} {w2} cF cf isv (suc k , comp)
rewrite shiftNameDown-renn-shiftNameUp (newChoiceT w1 (testMup 0 F f)) F f cF cf
= k , comp
abstract
νtestM⇓→ : (cn : comp→∀ℕ) {w1 w2 : 𝕎·} {F f : Term} {n : ℕ}
→ # F
→ # f
→ νtestMup F f ⇓ NUM n from w1 to w2
→ Σ Term (λ v → Σ ℕ (λ k →
APPLY F (upd (newChoiceT w1 (testMup 0 F f)) f) ⇓ v from (chooseT (newChoiceT w1 (testMup 0 F f)) (startNewChoiceT Res⊤ w1 (testMup 0 F f)) (NUM 0)) to w2
× isValue v
× getT 0 (newChoiceT w1 (testMup 0 F f)) w2 ≡ just (NUM k)
× n ≡ suc k
× compatible· (newChoiceT w1 (testMup 0 F f)) (startNewChoiceT Res⊤ w1 (testMup 0 F f)) Res⊤))
νtestM⇓→ cn {w1} {w2} {F} {f} {n} cF cf comp =
--newChoiceT w1 (testMup 0 F f) ,
fst comp3 ,
fst (snd comp3) ,
fst (snd (snd comp3)) ,
fst (snd (snd (snd comp3))) ,
fst (snd (snd (snd (snd (snd comp3))))) ,
NUMinj (snd (snd (snd (snd (snd (snd comp3)))))) ,
compat1
where
name : Name
name = newChoiceT w1 (testMup 0 F f)
w1' : 𝕎·
w1' = startNewChoiceT Res⊤ w1 (testMup 0 F f)
comp1 : testM name F f ⇓ NUM n from w1' to w2
comp1 = νtestM⇓→step' cF cf tt comp
w1'' : 𝕎·
w1'' = chooseT name w1' (NUM 0)
comp2 : probeM name F f ⇓ NUM n from w1'' to w2
comp2 = testM⇓→step tt comp1
compat1 : compatible· name w1' Res⊤
compat1 = startChoiceCompatible· Res⊤ w1 name (¬newChoiceT∈dom𝕎 w1 (testMup 0 F f))
comp3 : Σ Term (λ u → Σ ℕ (λ k →
appUpd name F f ⇓ u from w1'' to w2
× isValue u
× get0 name ⇓ NUM k from w2 to w2
× getT 0 name w2 ≡ just (NUM k)
× NUM n ≡ NUM (suc k)))
comp3 = probeM⇓-decomp name F f (NUM n) w1'' w2 comp2 tt (cn name w1' 0 compat1)
abstract
shiftNameUp-inj : {n : Name} {a b : Term} → shiftNameUp n a ≡ shiftNameUp n b → a ≡ b
shiftNameUp-inj {n} {VAR x} {VAR x} refl = refl
-- shiftNameUp-inj {n} {NAT} {NAT} e = refl
shiftNameUp-inj {n} {QNAT} {QNAT} e = refl
-- shiftNameUp-inj {n} {TNAT} {TNAT} e = refl
shiftNameUp-inj {n} {LT a a₁} {LT b b₁} e rewrite shiftNameUp-inj (LTinj1 e) | shiftNameUp-inj (LTinj2 e) = refl
shiftNameUp-inj {n} {QLT a a₁} {QLT b b₁} e rewrite shiftNameUp-inj (QLTinj1 e) | shiftNameUp-inj (QLTinj2 e) = refl
shiftNameUp-inj {n} {NUM x} {NUM .x} refl = refl
shiftNameUp-inj {n} {IFLT a a₁ a₂ a₃} {IFLT b b₁ b₂ b₃} e rewrite shiftNameUp-inj (IFLTinj1 e) | shiftNameUp-inj (IFLTinj2 e) | shiftNameUp-inj (IFLTinj3 e) | shiftNameUp-inj (IFLTinj4 e) = refl
shiftNameUp-inj {n} {IFEQ a a₁ a₂ a₃} {IFEQ b b₁ b₂ b₃} e rewrite shiftNameUp-inj (IFEQinj1 e) | shiftNameUp-inj (IFEQinj2 e) | shiftNameUp-inj (IFEQinj3 e) | shiftNameUp-inj (IFEQinj4 e) = refl
shiftNameUp-inj {n} {SUC a} {SUC b} e rewrite shiftNameUp-inj (SUCinj e) = refl
shiftNameUp-inj {n} {NATREC a a₁ a₂} {NATREC b b₁ b₂} e rewrite shiftNameUp-inj (NATRECinj1 e) | shiftNameUp-inj (NATRECinj2 e) | shiftNameUp-inj (NATRECinj3 e) = refl
shiftNameUp-inj {n} {PI a a₁} {PI b b₁} e rewrite shiftNameUp-inj (PIinj1 e) | shiftNameUp-inj (PIinj2 e) = refl
shiftNameUp-inj {n} {LAMBDA a} {LAMBDA b} e rewrite shiftNameUp-inj (LAMinj e) = refl
shiftNameUp-inj {n} {APPLY a a₁} {APPLY b b₁} e rewrite shiftNameUp-inj (APPLYinj1 e) | shiftNameUp-inj (APPLYinj2 e) = refl
shiftNameUp-inj {n} {MSEQ s₁} {MSEQ s₂} e = e
shiftNameUp-inj {n} {MAPP s₁ a₁} {MAPP s₂ a₂} e rewrite MAPPinj1 e | shiftNameUp-inj (MAPPinj2 e) = refl
shiftNameUp-inj {n} {FIX a} {FIX b} e rewrite shiftNameUp-inj (FIXinj e) = refl
shiftNameUp-inj {n} {LET a a₁} {LET b b₁} e rewrite shiftNameUp-inj (LETinj1 e) | shiftNameUp-inj (LETinj2 e) = refl
shiftNameUp-inj {n} {SUM a a₁} {SUM b b₁} e rewrite shiftNameUp-inj (SUMinj1 e) | shiftNameUp-inj (SUMinj2 e) = refl
shiftNameUp-inj {n} {PAIR a a₁} {PAIR b b₁} e rewrite shiftNameUp-inj (PAIRinj1 e) | shiftNameUp-inj (PAIRinj2 e) = refl
shiftNameUp-inj {n} {SPREAD a a₁} {SPREAD b b₁} e rewrite shiftNameUp-inj (SPREADinj1 e) | shiftNameUp-inj (SPREADinj2 e) = refl
shiftNameUp-inj {n} {WT a a₁ a₂} {WT b b₁ b₂} e rewrite shiftNameUp-inj (Winj1 e) | shiftNameUp-inj (Winj2 e) | shiftNameUp-inj (Winj3 e) = refl
shiftNameUp-inj {n} {SUP a a₁} {SUP b b₁} e rewrite shiftNameUp-inj (SUPinj1 e) | shiftNameUp-inj (SUPinj2 e) = refl
shiftNameUp-inj {n} {WREC a a₁} {WREC b b₁} e rewrite shiftNameUp-inj (WRECinj1 e) | shiftNameUp-inj (WRECinj2 e) = refl
shiftNameUp-inj {n} {MT a a₁ a₂} {MT b b₁ b₂} e rewrite shiftNameUp-inj (Minj1 e) | shiftNameUp-inj (Minj2 e) | shiftNameUp-inj (Minj3 e) = refl
shiftNameUp-inj {n} {SET a a₁} {SET b b₁} e rewrite shiftNameUp-inj (SETinj1 e) | shiftNameUp-inj (SETinj2 e) = refl
shiftNameUp-inj {n} {ISECT a a₁} {ISECT b b₁} e rewrite shiftNameUp-inj (ISECTinj1 e) | shiftNameUp-inj (ISECTinj2 e) = refl
shiftNameUp-inj {n} {TUNION a a₁} {TUNION b b₁} e rewrite shiftNameUp-inj (TUNIONinj1 e) | shiftNameUp-inj (TUNIONinj2 e) = refl
shiftNameUp-inj {n} {UNION a a₁} {UNION b b₁} e rewrite shiftNameUp-inj (UNIONinj1 e) | shiftNameUp-inj (UNIONinj2 e) = refl
-- shiftNameUp-inj {n} {QTUNION a a₁} {QTUNION b b₁} e rewrite shiftNameUp-inj (QTUNIONinj1 e) | shiftNameUp-inj (QTUNIONinj2 e) = refl
shiftNameUp-inj {n} {INL a} {INL b} e rewrite shiftNameUp-inj (INLinj e) = refl
shiftNameUp-inj {n} {INR a} {INR b} e rewrite shiftNameUp-inj (INRinj e) = refl
shiftNameUp-inj {n} {DECIDE a a₁ a₂} {DECIDE b b₁ b₂} e rewrite shiftNameUp-inj (DECIDEinj1 e) | shiftNameUp-inj (DECIDEinj2 e) | shiftNameUp-inj (DECIDEinj3 e) = refl
shiftNameUp-inj {n} {EQ a a₁ a₂} {EQ b b₁ b₂} e rewrite shiftNameUp-inj (EQinj1 e) | shiftNameUp-inj (EQinj2 e) | shiftNameUp-inj (EQinj3 e) = refl
-- shiftNameUp-inj {n} {EQB a a₁ a₂ a₃} {EQB b b₁ b₂ b₃} e rewrite shiftNameUp-inj (EQBinj1 e) | shiftNameUp-inj (EQBinj2 e) | shiftNameUp-inj (EQBinj3 e) | shiftNameUp-inj (EQBinj4 e) = refl
shiftNameUp-inj {n} {AX} {AX} e = refl
shiftNameUp-inj {n} {FREE} {FREE} e = refl
shiftNameUp-inj {n} {CS x} {CS x₁} e = ≡CS (sucIf≤-inj {n} {x} {x₁} (CSinj e))
shiftNameUp-inj {n} {NAME x} {NAME x₁} e = ≡NAME (sucIf≤-inj {n} {x} {x₁} (NAMEinj e))
shiftNameUp-inj {n} {FRESH a} {FRESH b} e rewrite shiftNameUp-inj (FRESHinj e) = refl
shiftNameUp-inj {n} {LOAD a} {LOAD b} e = e --rewrite shiftNameUp-inj (LOADinj e) = refl
shiftNameUp-inj {n} {CHOOSE a a₁} {CHOOSE b b₁} e rewrite shiftNameUp-inj (CHOOSEinj1 e) | shiftNameUp-inj (CHOOSEinj2 e) = refl
--shiftNameUp-inj {n} {IFC0 a a₁ a₂} {IFC0 b b₁ b₂} e rewrite shiftNameUp-inj (IFC0inj1 e) | shiftNameUp-inj (IFC0inj2 e) | shiftNameUp-inj (IFC0inj3 e) = refl
-- shiftNameUp-inj {n} {TSQUASH a} {TSQUASH b} e rewrite shiftNameUp-inj (TSQUASHinj e) = refl
-- shiftNameUp-inj {n} {TTRUNC a} {TTRUNC b} e rewrite shiftNameUp-inj (TTRUNCinj e) = refl
shiftNameUp-inj {n} {NOWRITE} {NOWRITE} refl = refl
shiftNameUp-inj {n} {NOREAD} {NOREAD} refl = refl
shiftNameUp-inj {n} {SUBSING a} {SUBSING b} e rewrite shiftNameUp-inj (SUBSINGinj e) = refl
shiftNameUp-inj {n} {PARTIAL a} {PARTIAL b} e rewrite shiftNameUp-inj (PARTIALinj e) = refl
shiftNameUp-inj {n} {FFDEFS a a₁} {FFDEFS b b₁} e rewrite shiftNameUp-inj (FFDEFSinj1 e) | shiftNameUp-inj (FFDEFSinj2 e) = refl
shiftNameUp-inj {n} {PURE} {PURE} refl = refl
shiftNameUp-inj {n} {NOSEQ} {NOSEQ} refl = refl
shiftNameUp-inj {n} {NOENC} {NOENC} refl = refl
shiftNameUp-inj {n} {TERM a} {TERM b} e rewrite shiftNameUp-inj (TERMinj e) = refl
shiftNameUp-inj {n} {ENC a} {ENC b} e rewrite shiftNameUp-inj (ENCinj e) = refl
shiftNameUp-inj {n} {UNIV x} {UNIV .x} refl = refl
shiftNameUp-inj {n} {LIFT a} {LIFT b} e rewrite shiftNameUp-inj (LIFTinj e) = refl
shiftNameUp-inj {n} {LOWER a} {LOWER b} e rewrite shiftNameUp-inj (LOWERinj e) = refl
shiftNameUp-inj {n} {SHRINK a} {SHRINK b} e rewrite shiftNameUp-inj (SHRINKinj e) = refl
shiftUp-ShiftNameUp≡ShiftNameUp→ : (v : Name) (f a : Term)
→ shiftUp 0 (shiftNameUp v f) ≡ shiftNameUp v a
→ a ≡ shiftUp 0 f
shiftUp-ShiftNameUp≡ShiftNameUp→ v f a e
rewrite shiftUp-shiftNameUp 0 v f = sym (shiftNameUp-inj e)
updBody≡shiftNameUp→ : (v : Var) (name : Name) (f : Term) (a : Term)
→ updBody (sucIf≤ v name) (shiftNameUp v f) ≡ shiftNameUp v a
→ a ≡ updBody name f
updBody≡shiftNameUp→ v name f (LET (VAR 0) (LET (IFLT (APPLY (CS x₁) (NUM 0)) (VAR 0) (CHOOSE (NAME x₂) (VAR 0)) AX) (APPLY a (VAR 1)))) e
rewrite sym (sucIf≤-inj {v} {name} {x₁} (CSinj (APPLYinj1 (IFLTinj1 (LETinj1 (LETinj2 e))))))
| sym (sucIf≤-inj {v} {name} {x₂} (NAMEinj (CHOOSEinj1 (IFLTinj3 (LETinj1 (LETinj2 e))))))
| shiftUp-ShiftNameUp≡ShiftNameUp→ v f a (APPLYinj1 (LETinj2 (LETinj2 e))) = refl
{--
predIf≤-inj : {n : ℕ} {x y : Var} → predIf≤ n x ≡ predIf≤ n y → x ≡ y
predIf≤-inj {n} {0} {0} e = refl
predIf≤-inj {n} {0} {suc y} e with suc y ≤? n
... | yes q = e
... | no q = {!!}
predIf≤-inj {n} {suc x} {0} e with suc x ≤? n
... | yes p = e
... | no p = {!!}
predIf≤-inj {n} {suc x} {suc y} e with suc x ≤? n | suc y ≤? n
... | yes p | yes q = e
... | yes p | no q rewrite e = ⊥-elim {!!}
... | no p | yes q rewrite e = {!!}
... | no p | no q rewrite e = refl
--}
abstract
fvars-shiftNameDown : (n : ℕ) (a : Term) → fvars (shiftNameDown n a) ≡ fvars a
fvars-shiftNameDown n (VAR x) = refl
-- fvars-shiftNameDown n NAT = refl
fvars-shiftNameDown n QNAT = refl
-- fvars-shiftNameDown n TNAT = refl
fvars-shiftNameDown n (LT a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (QLT a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (NUM x) = refl
fvars-shiftNameDown n (IFLT a a₁ a₂ a₃) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ | fvars-shiftNameDown n a₂ | fvars-shiftNameDown n a₃ = refl
fvars-shiftNameDown n (IFEQ a a₁ a₂ a₃) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ | fvars-shiftNameDown n a₂ | fvars-shiftNameDown n a₃ = refl
fvars-shiftNameDown n (SUC a) rewrite fvars-shiftNameDown n a = refl
fvars-shiftNameDown n (NATREC a a₁ a₂) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ | fvars-shiftNameDown n a₂ = refl
fvars-shiftNameDown n (PI a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (LAMBDA a) rewrite fvars-shiftNameDown n a = refl
fvars-shiftNameDown n (APPLY a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (MSEQ s) = refl
fvars-shiftNameDown n (MAPP s a) rewrite fvars-shiftNameDown n a = refl
fvars-shiftNameDown n (FIX a) rewrite fvars-shiftNameDown n a = refl
fvars-shiftNameDown n (LET a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (SUM a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (PAIR a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (SPREAD a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (WT a a₁ a₂) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ | fvars-shiftNameDown n a₂ = refl
fvars-shiftNameDown n (SUP a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (WREC a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (MT a a₁ a₂) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ | fvars-shiftNameDown n a₂ = refl
fvars-shiftNameDown n (SET a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (ISECT a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (TUNION a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (UNION a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
-- fvars-shiftNameDown n (QTUNION a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl
fvars-shiftNameDown n (INL a) rewrite fvars-shiftNameDown n a = refl
fvars-shiftNameDown n (INR a) rewrite fvars-shiftNameDown n a = refl
fvars-shiftNameDown n (DECIDE a a₁ a₂) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ | fvars-shiftNameDown n a₂ = refl
fvars-shiftNameDown n (EQ a a₁ a₂) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ | fvars-shiftNameDown n a₂ = refl
-- fvars-shiftNameDown n (EQB a a₁ a₂ a₃) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ | fvars-shiftNameDown n a₂ | fvars-shiftNameDown n a₃ = refl
fvars-shiftNameDown n AX = refl
fvars-shiftNameDown n FREE = refl
fvars-shiftNameDown n (CS x) = refl
fvars-shiftNameDown n (NAME x) = refl
fvars-shiftNameDown n (FRESH a) rewrite fvars-shiftNameDown (suc n) a = refl
fvars-shiftNameDown n (LOAD a) rewrite fvars-shiftNameDown n a = refl
fvars-shiftNameDown n (CHOOSE a a₁) rewrite fvars-shiftNameDown n a | fvars-shiftNameDown n a₁ = refl