-
Notifications
You must be signed in to change notification settings - Fork 0
/
botworld_propsScript.sml
2794 lines (2604 loc) · 101 KB
/
botworld_propsScript.sml
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
open preamble indexedListsTheory match_goal simpleSexpTheory
botworldTheory
botworld_dataTheory
botworld_serialiseTheory
botworld_svTheory
local open realSimps ffiExtTheory in end
val _ = new_theory"botworld_props";
(* TODO: move *)
val CHOICE_IMAGE_SING = Q.store_thm("CHOICE_IMAGE_SING",
`f (CHOICE {x}) = CHOICE (IMAGE f {x})`,
rw[]);
val ALL_DISTINCT_MAP_MEM = Q.store_thm("ALL_DISTINCT_MAP_MEM",
`∀ls x1 x2. ALL_DISTINCT (MAP f ls) ∧
MEM x1 ls ∧ MEM x2 ls ∧ f x1 = f x2 ⇒ x1 = x2`,
Induct \\ rw[MEM_MAP] \\ metis_tac[]);
val ALL_DISTINCT_MAP_FST =
ALL_DISTINCT_MAP_MEM |> Q.GEN`f` |> Q.ISPEC`FST`
|> SIMP_RULE(srw_ss())[FORALL_PROD]
val ALL_DISTINCT_MAP_FILTER = Q.store_thm("ALL_DISTINCT_MAP_FILTER",
`∀ls. ALL_DISTINCT (MAP f ls) ⇒ ALL_DISTINCT (MAP f (FILTER P ls))`,
Induct \\ rw[] \\ fs[MEM_MAP,MEM_FILTER] \\ metis_tac[]);
val ALL_DISTINCT_FILTER_GENLIST = Q.store_thm("ALL_DISTINCT_FILTER_GENLIST",
`ALL_DISTINCT (FILTER P (GENLIST f n)) ⇔
∀m1 m2. m1 < n ∧ m2 < n ∧ f m1 = f m2 ∧ P (f m1) ⇒ m1 = m2`,
Induct_on`n` \\ rw[GENLIST,FILTER_SNOC,ALL_DISTINCT_SNOC,MEM_FILTER,MEM_GENLIST]
\\ metis_tac[LESS_ANTISYM,LESS_CASES,LESS_OR_EQ,NOT_LESS,prim_recTheory.LESS_THM]);
val MAP2_MAP = Q.store_thm("MAP2_MAP",
`(∀l1 l2. LENGTH l1 = LENGTH l2 ⇒
MAP2 f (MAP g l1) l2 = MAP2 (CURRY (UNCURRY f o (g ## I))) l1 l2) ∧
(∀l1 l2. LENGTH l1 = LENGTH l2 ⇒
MAP2 f l1 (MAP h l2) = MAP2 (CURRY (UNCURRY f o (I ## h))) l1 l2)`,
conj_tac
\\ Induct \\ simp[]
\\ Cases_on`l2` \\ simp[]);
val MAP2_same = Q.store_thm("MAP2_same",
`∀l. MAP2 f l l = MAP (W f) l`,
Induct \\ simp[]);
val PAIR_MAP_COMPOSE = Q.store_thm("PAIR_MAP_COMPOSE",
`(a ## b) o (c ## d) = (a o c ## b o d)`,
rw[FUN_EQ_THM,FORALL_PROD]);
val MAP_FILTER_remove = Q.store_thm("MAP_FILTER_remove",
`∀l1 l2. MAP f l1 = MAP f l2 ∧ (∀n. n < LENGTH l1 ⇒ (P (EL n l1) ⇔ P (EL n l2)))
⇒ MAP f (FILTER P l1) = MAP f (FILTER P l2)`,
Induct \\ rw[]
\\ Cases_on`l2` \\ fs[]
\\ first_assum(qspec_then`0`mp_tac)
\\ simp_tac(srw_ss())[] \\ strip_tac \\ fs[]
\\ first_x_assum match_mp_tac \\ rw[]
\\ first_x_assum(qspec_then`SUC n`mp_tac)
\\ simp[]);
val PERM_FLAT = Q.store_thm("PERM_FLAT",
`∀l1 l2. PERM l1 l2 ⇒ PERM (FLAT l1) (FLAT l2)`,
ho_match_mp_tac PERM_IND
\\ simp[]
\\ conj_tac >- ( simp[PERM_APPEND_IFF] )
\\ conj_tac >- ( simp[PERM_SWAP_L_AT_FRONT] )
\\ metis_tac[PERM_TRANS]);
val PERM_SNOC = Q.store_thm("PERM_SNOC",
`∀l1 x l2. PERM (SNOC x l1) l2 ⇔ PERM (x::l1) l2`,
Induct \\ rw[]
\\ rw[PERM_FUN_SWAP_AT_FRONT]
\\ metis_tac[PERM_CONS_IFF,PERM_TRANS,PERM_SYM]);
val ALL_DISTINCT_FLAT = Q.store_thm("ALL_DISTINCT_FLAT",
`∀lss. ALL_DISTINCT (FLAT lss) ⇔
ALL_DISTINCT (FILTER ($<> []) lss) ∧
(∀ls. MEM ls lss ⇒ ALL_DISTINCT ls) ∧
(∀l1 l2. MEM l1 lss ∧ MEM l2 lss ∧ l1 ≠ l2 ⇒ DISJOINT (set l1) (set l2))`,
Induct \\ rw[]
\\ rw[ALL_DISTINCT_APPEND]
\\ rw[EQ_IMP_THM] \\ fs[]
>- (
fs[MEM_FILTER,MEM_FLAT]
\\ Cases_on`h`\\fs[]
\\ metis_tac[MEM] )
>- (
fs[IN_DISJOINT,MEM_FLAT]
\\ metis_tac[] )
>- (
fs[IN_DISJOINT,MEM_FLAT]
\\ metis_tac[] )
\\ fs[MEM_FILTER] \\ rw[] \\ fs[]
\\ fs[IN_DISJOINT,MEM_FLAT]
\\ metis_tac[]);
val PERM_FILTER_SPLIT = Q.store_thm("PERM_FILTER_SPLIT",
`∀P ls. PERM ls (FILTER P ls ++ FILTER ($~ o P) ls)`,
gen_tac \\ Induct \\ simp[] \\ rw[]
\\ rw[PERM_CONS_EQ_APPEND]
\\ ONCE_REWRITE_TAC[CONJ_COMM]
\\ asm_exists_tac \\ rw[]);
(*
val QSORT_any_pivot = Q.store_thm("QSORT_any_pivot",
`∀R ls x. MEM x ls ⇒
(QSORT R ls =
QSORT R (FILTER (λy. y ≠ x ∧ R x y) ls) ++ (FILTER ($= x) ls) ++
QSORT R (FILTER (λy. y ≠ x ∧ R y x) ls))`,
ho_match_mp_tac QSORT_IND
\\ simp[]
\\ rpt gen_tac
\\ strip_tac
\\ gen_tac
\\ strip_tac
>- (
rveq \\ fs[]
\\ simp[Once QSORT_DEF]
\\ pairarg_tac \\ fs[]
val QSORT_SET_TO_LIST_INSERT = Q.store_thm("QSORT_SET_TO_LIST_INSERT",
`∀s. FINITE s ⇒
∀x. x ∈ s ⇒
QSORT R (SET_TO_LIST s) =
QSORT R (SET_TO_LIST { y | y ∈ s ∧ y ≠ x ∧ R y x } ) ++ [x] ++
QSORT R (SET_TO_LIST { y | y ∈ s ∧ y ≠ x ∧ R x y } )`,
\\ ho_match_mp_tac SET_TO_LIST_IND
\\ rw[] \\ fs[]
\\ Cases_on`s = ∅` \\ fs[]
\\ simp[Once SET_TO_LIST_THM]
\\ simp[Once QSORT_DEF]
\\ pairarg_tac \\ fs[]
*)
val ALL_DISTINCT_QSORT = Q.store_thm("ALL_DISTINCT_QSORT",
`ALL_DISTINCT (QSORT R ls) ⇔ ALL_DISTINCT ls`,
metis_tac[QSORT_PERM,ALL_DISTINCT_PERM])
val FLOOKUP_FMAP_MAP2 = Q.store_thm("FLOOKUP_FMAP_MAP2",
`FLOOKUP (FMAP_MAP2 f m) x =
OPTION_MAP (CURRY f x) (FLOOKUP m x) `,
rw[FLOOKUP_DEF,FMAP_MAP2_THM])
val FMAP_MAP2_o_f = Q.store_thm("FMAP_MAP2_o_f",
`FMAP_MAP2 f (g o_f h) = FMAP_MAP2 (f o (I ## g)) h`,
rw[fmap_eq_flookup,FLOOKUP_FMAP_MAP2,FLOOKUP_o_f]
\\ CASE_TAC \\ fs[]);
val o_f_FMAP_MAP2 = Q.store_thm("o_f_FMAP_MAP2",
`f o_f (FMAP_MAP2 g h) = FMAP_MAP2 (f o g) h`,
rw[fmap_eq_flookup,FLOOKUP_FMAP_MAP2,FLOOKUP_o_f]
\\ CASE_TAC \\ fs[]);
val FMAP_MAP2_SND_compose = Q.store_thm("FMAP_MAP2_SND_compose",
`FMAP_MAP2 (f o SND) (FMAP_MAP2 (g o SND) x) = FMAP_MAP2 (f o g o SND) x`,
rw[fmap_eq_flookup,FLOOKUP_FMAP_MAP2]
\\ rename1`FLOOKUP x k`
\\ Cases_on`FLOOKUP x k` \\ simp[])
val FILTER_INDICES = Q.store_thm("FILTER_INDICES",
`∃f.
(∀i. i < LENGTH (FILTER P ls) ⇒ EL i (FILTER P ls) = EL (f i) ls) ∧
(INJ f (count (LENGTH (FILTER P ls))) (count (LENGTH ls))) ∧
(∀x y. x < LENGTH (FILTER P ls) ∧ y < LENGTH (FILTER P ls) ∧ x < y ⇒ f x < f y)`,
Induct_on`ls` >> simp[] >>
gen_tac >>
IF_CASES_TAC >> fs[] >- (
qexists_tac`λi. if i = 0 then 0 else SUC (f (PRE i))` >>
simp[] >>
conj_tac >- ( Cases >> simp[EL_CONS] ) >>
conj_tac >- (
fs[INJ_DEF] >>
conj_tac >> Cases >> simp[] >>
Cases >> simp[] ) >>
Cases >> simp[] ) >>
qexists_tac`SUC o f` >> simp[] >> fs[INJ_DEF]);
fun Abbrev_intro th =
EQ_MP (SYM(SPEC(concl th)markerTheory.Abbrev_def)) th
val ZIP_MAP_PAIR = Q.store_thm("ZIP_MAP_PAIR",
`LENGTH l1 = LENGTH l2 ⇒
ZIP (MAP f1 l1,MAP f2 l2) = MAP (f1 ## f2) (ZIP(l1,l2))`,
rw[ZIP_MAP,MAP_MAP_o] >> simp[o_DEF] >>
rpt(AP_TERM_TAC ORELSE AP_THM_TAC) >>
simp[FUN_EQ_THM,FORALL_PROD]);
val MEM_EL_P = Q.store_thm("MEM_EL_P",
`∀l. (∃n. n < LENGTH l ∧ P (EL n l)) ⇔ (∃x. MEM x l ∧ P x)`,
rw[MEM_EL] >> metis_tac[]);
val unique_index_filter = Q.store_thm("unique_index_filter",
`∀ls i. i < LENGTH ls ∧
(∀j. j < LENGTH ls ⇒ (R (EL j ls) ⇔ j = i)) ∧
P (EL i ls) ⇒
∃k. k < LENGTH (FILTER P ls) ∧ (∀j. j < LENGTH (FILTER P ls) ⇒ (R (EL j (FILTER P ls)) ⇔ j = k))`,
Induct >> simp[] >> rpt gen_tac >> strip_tac >>
IF_CASES_TAC >> fs[] >- (
Cases_on`i`>>fs[]>-(
qexists_tac`0`>>simp[]>>rw[]>>
Cases_on`j`>>fs[]>-(
first_x_assum(qspec_then`0`mp_tac)>>simp[])>>
`MEM (EL n (FILTER P ls)) ls` by (
metis_tac[MEM_FILTER,MEM_EL] ) >>
fs[MEM_EL] >>
first_x_assum(qspec_then`SUC n'`mp_tac)>>simp[]) >>
last_x_assum(qspec_then`n`mp_tac)>>simp[]>>
impl_tac >- (
rw[] >>
first_x_assum(qspec_then`SUC j`mp_tac)>>simp[])>>
rw[] >>
qexists_tac`SUC k`>>simp[]>>rw[]>>
Cases_on`j`>>fs[]>>
last_x_assum(qspec_then`0`mp_tac)>>simp[]) >>
Cases_on`i`>>fs[]>>
last_x_assum drule >>
impl_tac >- (
rw[] >>
first_x_assum(qspec_then`SUC j`mp_tac)>>simp[])>>
rw[]);
val LENGTH_FILTER_EQ = Q.store_thm("LENGTH_FILTER_EQ",
`∀l1 l2.
LENGTH l1 = LENGTH l2 ∧ (∀i. i < LENGTH l1 ⇒ (P (EL i l1) ⇔ P (EL i l2)))
⇒ LENGTH (FILTER P l1) = LENGTH (FILTER P l2)`,
Induct \\ simp[LENGTH_NIL_SYM]
\\ gen_tac \\ Cases \\ simp[]
\\ metis_tac[LESS_MONO_EQ,EL_restricted,HD,prim_recTheory.LESS_0,LENGTH]);
val APPEND_EQ_suff =
DISCH_ALL(#2(EQ_IMP_RULE(UNDISCH(SPEC_ALL(CONJUNCT1 (SPEC_ALL APPEND_11_LENGTH))))))
|> SIMP_RULE(pure_ss)[AND_IMP_INTRO,CONJ_ASSOC]
|> SIMP_RULE(pure_ss)[PROVE[]``LENGTH a = LENGTH b ∧ a = b ⇔ a = b``]
(* -- *)
val grid_injective = Q.store_thm("grid_injective",
`wf_state s ⇒
∀c1 c2 sq.
(FLOOKUP s.grid c1 = SOME sq) ∧
(FLOOKUP s.grid c2 = SOME sq) ∧
¬ NULL sq.robots
⇒
(c1 = c2)`,
rw[wf_state_def,listTheory.NULL_EQ,pred_setTheory.IN_DISJOINT,listTheory.MEM_MAP]
\\ metis_tac[listTheory.MEM,listTheory.list_CASES])
val same_name_same_square = Q.store_thm("same_name_same_square",
`wf_state s ⇒
∀s1 s2 nm.
s1 ∈ FRANGE s.grid ∧
s2 ∈ FRANGE s.grid ∧
MEM nm (MAP FST s1.robots) ∧
MEM nm (MAP FST s2.robots)
⇒ s1 = s2`,
rw[wf_state_def,finite_mapTheory.IN_FRANGE_FLOOKUP,pred_setTheory.IN_DISJOINT]
\\ metis_tac[optionTheory.SOME_11]);
val focal_robot_unique = Q.store_thm("focal_robot_unique",
`wf_state_with_hole s ⇒
∀s1 s2.
s1 ∈ FRANGE s.state.grid ∧ s2 ∈ FRANGE s.state.grid ∧
MEM s.focal_name (MAP FST s1.robots) ∧
MEM s.focal_name (MAP FST s2.robots)
⇒
s1 = s2`,
metis_tac[wf_state_with_hole_def,same_name_same_square]);
val FST_updateInventory = Q.store_thm("FST_updateInventory[simp]",
`FST (updateInventory sq x y) = x`,
Cases_on`y`\\rw[updateInventory_def]);
val SND_updateInventory_const = Q.store_thm("SND_updateInventory_const[simp]",
`(SND (updateInventory sq nm y)).memory = (FST y).memory ∧
(SND (updateInventory sq nm y)).processor = (FST y).processor ∧
(SND (updateInventory sq nm y)).frame = (FST y).frame`,
Cases_on`y` \\ rw[updateInventory_def]
\\ BasicProvers.TOP_CASE_TAC \\ fs[]);
val FST_runMachine = Q.store_thm("FST_runMachine[simp]",
`FST (runMachine ev nmra) = FST nmra`,
PairCases_on`nmra`\\rw[runMachine_def,UNCURRY]);
val FST_o_if_focal = Q.store_thm("FST_o_if_focal[simp]",
`FST o if_focal x y = FST`,
rw[if_focal_def,FUN_EQ_THM,FORALL_PROD]);
val NOT_isMovedIn_act = Q.store_thm("NOT_isMovedIn_act[simp]",
`¬isMovedIn (act sq nb a)`,
rw[act_def]
\\ CASE_TAC \\ rw[]
\\ CASE_TAC \\ rw[]);
val less8 = Q.prove(
`x < 8n ⇔ (x = 0 ∨ x = 1 ∨ x = 2 ∨ x = 3 ∨ x = 4 ∨ x = 5 ∨ x = 6 ∨ x = 7)`,
rw[EQ_IMP_THM] >> simp[])
val LENGTH_neighbour_coords = Q.store_thm("LENGTH_neighbour_coords",
`LENGTH (neighbour_coords x) = 8`,
Cases_on`x`>>simp[neighbour_coords_def]);
val LENGTH_neighbours = Q.store_thm("LENGTH_neighbours",
`LENGTH (neighbours x y) = 8`,
simp[neighbours_def,LENGTH_neighbour_coords]);
val opposite_less8 = Q.store_thm("opposite_less8[simp]",
`opposite dir < 8`, rw[opposite_def])
val opposite_inj = Q.store_thm("opposite_inj",
`i < 8 ∧ j < 8 ∧ opposite i = opposite j ⇒ i = j`,
EVAL_TAC \\ rw[less8] \\ fs[]);
val opposite_opposite = Q.store_thm("opposite_opposite[simp]",
`dir < 8 ⇒ opposite (opposite dir) = dir`,
EVAL_TAC >> rw[less8] >> simp[]);
val neighbours_EL_neighbour_coords = Q.store_thm("neighbours_EL_neighbour_coords",
`dir < 8 ∧ FLOOKUP s i = SOME sq ⇒
EL (opposite dir) (neighbours s (EL dir (neighbour_coords i))) = SOME sq`,
simp[neighbours_def] >>
Cases_on`EL dir (neighbour_coords i)` >>
Cases_on`i` >>
fs[neighbour_coords_def] >>
simp[less8] >>
strip_tac >> fs[opposite_def] >> rveq
\\ pop_assum (SUBST1_TAC o SYM)
\\ rpt AP_TERM_TAC
\\ simp[]
\\ intLib.COOPER_TAC);
val ALL_DISTINCT_neighbour_coords = Q.store_thm("ALL_DISTINCT_neighbour_coords[simp]",
`ALL_DISTINCT (neighbour_coords k)`,
Cases_on`k` \\ rw[neighbour_coords_def]
\\ intLib.COOPER_TAC)
val NOT_MEM_neighbour_coords = Q.store_thm("NOT_MEM_neighbour_coords",
`¬MEM k (neighbour_coords k)`,
Cases_on`k`\\rw[neighbour_coords_def]
\\ intLib.COOPER_TAC);
val neighbour_coords_opposite_imp = Q.store_thm("neighbour_coords_opposite_imp",
`d < 8 ⇒
EL (opposite d) (neighbour_coords (EL d (neighbour_coords c))) = c`,
Cases_on`c`>>
rw[less8] >> simp[neighbour_coords_def,opposite_def] >>
intLib.COOPER_TAC);
val event_name_in_grid = Q.store_thm("event_name_in_grid",
`FLOOKUP g c = SOME sq ∧
MEM nra (event sq (neighbours g c)).robotActions ⇒
if ¬isMovedIn (SND(SND nra)) then
MEM (FST nra) (MAP FST sq.robots)
else
∃c' sq'.
FLOOKUP g c' = SOME sq' ∧ c ≠ c' ∧
MEM (FST nra) (MAP FST sq'.robots)`,
simp[event_def]
\\ strip_tac
>- (
fs[MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,MEM_MAP,UNCURRY]
\\ fs[localActions_def,MEM_MAP,UNCURRY]
\\ metis_tac[] )
\\ fs[MEM_FLAT,MEM_GENLIST]
\\ rveq
\\ Cases_on`EL dir (neighbours g c)` \\ fs[incomingFrom_def]
\\ fs[MEM_MAP,MEM_FILTER]
\\ pairarg_tac \\ fs[]
\\ rw[]
\\ fs[neighbours_def]
\\ rfs[EL_MAP]
\\ asm_exists_tac
\\ simp[EXISTS_PROD]
\\ reverse conj_tac >- metis_tac[]
\\ Cases_on`c` \\ fs[neighbour_coords_def]
\\ fs[less8] \\ rw[]
\\ intLib.COOPER_TAC);
val incomingFrom_MovedIn = Q.store_thm("incomingFrom_MovedIn",
`MEM x (incomingFrom y z) ⇒ ∃i. SND (SND x) = MovedIn i`,
Cases_on`z`>>rw[incomingFrom_def]>>
fs[MEM_FLAT,MEM_MAP,MEM_FILTER,EXISTS_PROD]);
val wf_state_event_same_name = Q.store_thm("wf_state_event_same_name",
`wf_state s ∧
MEM (nm,ra1) ev1.robotActions ∧
MEM (nm,ra2) ev2.robotActions ∧
FLOOKUP (computeEvents s.grid) c1 = SOME ev1 ∧
FLOOKUP (computeEvents s.grid) c2 = SOME ev2 ∧
c1 ≠ c2
⇒
∃dir. dir < 8 ∧ {SND ra1; SND ra2} = {MovedIn dir; MovedOut (opposite dir)}`,
rw[computeEvents_def,FLOOKUP_FMAP_MAP2,wf_state_def]
\\ fs[event_def,MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,MEM_MAP,UNCURRY,MEM_FLAT,MEM_GENLIST]
\\ rw[]
\\ rpt (
qmatch_asmsub_abbrev_tac`incomingFrom _ nb`
\\ Cases_on`nb`
\\ qpat_x_assum`Abbrev _`(strip_assume_tac o SYM o SIMP_RULE std_ss [markerTheory.Abbrev_def])
\\ fs[incomingFrom_def])
\\ fs[MEM_MAP,MEM_FILTER]
\\ fs[localActions_def,MEM_MAP] \\ rw[]
\\ TRY pairarg_tac \\ fs[] \\ rw[]
\\ TRY pairarg_tac \\ fs[] \\ rw[]
\\ fs[IN_DISJOINT,MEM_MAP,EXISTS_PROD]
>- metis_tac[]
>- (
rfs[neighbours_def,EL_MAP]
\\ reverse(Cases_on`EL dir (neighbour_coords c2) = c1`)
>- metis_tac[]
\\ rw[] \\ fs[] \\ rw[]
\\ fs[IN_FRANGE_FLOOKUP,PULL_EXISTS]
\\ `r = r'` by metis_tac[ALL_DISTINCT_MAP_FST]
\\ simp[act_def]
\\ fs[LENGTH_neighbour_coords,GSYM neighbours_def]
\\ imp_res_tac neighbours_EL_neighbour_coords \\ fs[]
\\ qexists_tac`dir` \\ rw[EXTENSION,EQ_IMP_THM] )
>- (
rfs[neighbours_def,EL_MAP]
\\ reverse(Cases_on`EL dir (neighbour_coords c1) = c2`)
>- metis_tac[]
\\ rw[] \\ fs[] \\ rw[]
\\ fs[IN_FRANGE_FLOOKUP,PULL_EXISTS]
\\ `r = r'` by metis_tac[ALL_DISTINCT_MAP_FST]
\\ simp[act_def]
\\ fs[LENGTH_neighbour_coords,GSYM neighbours_def]
\\ imp_res_tac neighbours_EL_neighbour_coords \\ fs[]
\\ qexists_tac`dir` \\ rw[EXTENSION,EQ_IMP_THM] )
\\ rfs[neighbours_def,EL_MAP]
\\ qmatch_assum_rename_tac`d1 < LENGTH (_ c1)`
\\ qmatch_assum_rename_tac`d2 < LENGTH (_ c2)`
\\ reverse(Cases_on`EL d1 (neighbour_coords c1) = EL d2 (neighbour_coords c2)`)
>- metis_tac[]
\\ fs[IN_FRANGE_FLOOKUP,PULL_EXISTS]
\\ `r = r'` by metis_tac[ALL_DISTINCT_MAP_FST]
\\ rw[] \\ fs[] \\ rw[]
\\ fs[LENGTH_neighbour_coords]
\\ `d1 = d2` by metis_tac[opposite_inj]
\\ fs[] \\ rw[]
\\ Cases_on`c1` \\ Cases_on`c2`
\\ `F` suffices_by rw[]
\\ pop_assum mp_tac
\\ simp[neighbour_coords_def]
\\ fs[less8]
\\ intLib.COOPER_TAC);
val MEM_MovedOut_localActions = Q.store_thm("MEM_MovedOut_localActions",
`MEM nra (localActions sq nb) ∧
SND(SND nra) = MovedOut dir
⇒
dir < LENGTH nb ∧
((FST(SND nra)).command) = Move dir ∧
IS_SOME (EL dir nb)`,
simp[localActions_def,MEM_MAP]
\\ strip_tac
\\ pairarg_tac \\ fs[]
\\ rveq \\ fs[]
\\ pop_assum mp_tac
\\ simp[act_def]
\\ BasicProvers.TOP_CASE_TAC \\ fs[] \\ rw[] \\ fs[]
\\ BasicProvers.TOP_CASE_TAC \\ fs[] \\ rw[] \\ fs[]);
val NOT_MEM_MovedIn_localActions = Q.store_thm("NOT_MEM_MovedIn_localActions",
`MEM nra (localActions sq nb) ⇒ ¬isMovedIn(SND(SND nra))`,
simp[localActions_def,MEM_MAP] \\ strip_tac
\\ pairarg_tac \\ fs[]);
val same_name_same_action = Q.store_thm("same_name_same_action",
`wf_state s ∧
FLOOKUP (computeEvents s.grid) c1 = SOME ev1 ∧
FLOOKUP (computeEvents s.grid) c2 = SOME ev2 ∧
MEM (nm,ra1) ev1.robotActions ∧
MEM (nm,ra2) ev2.robotActions ⇒
((c1 = c2 ∧ ra1 = ra2) ∨
∃dir. dir < 8 ∧ {SND ra1; SND ra2} = {MovedIn dir; MovedOut (opposite dir)})`,
rw[IN_FRANGE_FLOOKUP,computeEvents_def,FLOOKUP_FMAP_MAP2]
\\ reverse(Cases_on`c1=c2`\\fs[])
>- (
drule (GEN_ALL wf_state_event_same_name)
\\ simp[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS]
\\ metis_tac[] )
\\ fs[] \\ rveq \\ fs[]
\\ disj1_tac
\\ drule (GEN_ALL event_name_in_grid)
\\ disch_then drule
\\ drule (GEN_ALL event_name_in_grid)
\\ qpat_x_assum`MEM (nm,ra1) _`assume_tac
\\ disch_then drule
\\ rw[]
>- (
rpt(qpat_x_assum`MEM _ _.robotActions`mp_tac)
\\ simp[event_def,MEM_FLAT,MEM_GENLIST,PULL_EXISTS,MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,UNCURRY,o_DEF,MEM_MAP,EXISTS_PROD]
\\ reverse strip_tac
>- ( imp_res_tac incomingFrom_MovedIn \\ fs[] )
\\ reverse strip_tac
>- ( imp_res_tac incomingFrom_MovedIn \\ fs[] )
\\ rveq \\ simp[]
\\ `ALL_DISTINCT (MAP FST (localActions sq (neighbours s.grid c1)))`
by (
simp[localActions_def,MAP_MAP_o,o_DEF,UNCURRY,ETA_AX]
\\ fs[wf_state_def,IN_FRANGE_FLOOKUP,PULL_EXISTS]
\\ metis_tac[] )
\\ metis_tac[PAIR_EQ,ALL_DISTINCT_MAP_FST] )
>- ( fs[wf_state_def,IN_DISJOINT] \\ metis_tac[] )
>- ( fs[wf_state_def,IN_DISJOINT] \\ metis_tac[] )
\\ rpt(qpat_x_assum`MEM _ _.robotActions`mp_tac)
\\ simp[event_def,MEM_FLAT,MEM_GENLIST,PULL_EXISTS,MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,UNCURRY,o_DEF,MEM_MAP,EXISTS_PROD]
\\ strip_tac
>- ( metis_tac[NOT_MEM_MovedIn_localActions,SND] )
\\ strip_tac
>- ( metis_tac[NOT_MEM_MovedIn_localActions,SND] )
\\ Cases_on`EL dir (neighbours s.grid c1)`\\fs[incomingFrom_def]
\\ Cases_on`EL dir' (neighbours s.grid c1)`\\fs[incomingFrom_def]
\\ rfs[neighbours_def,EL_MAP]
\\ fs[MEM_MAP,MEM_FILTER,UNCURRY]
\\ rveq
\\ reverse conj_asm2_tac
>- (
fs[wf_state_def,IN_DISJOINT,MEM_MAP,PULL_EXISTS]
\\ metis_tac[ALL_DISTINCT_neighbour_coords,EL_ALL_DISTINCT_EL_EQ] )
\\ rveq \\ fs[] \\ rw[]
\\ fs[wf_state_def,IN_FRANGE_FLOOKUP,PULL_EXISTS]
\\ metis_tac[ALL_DISTINCT_MAP_FST,PAIR,SND]);
val event_MovedOut_MovedIn = Q.store_thm("event_MovedOut_MovedIn",
`FLOOKUP (computeEvents g) c = SOME ev ∧
MEM (nm,r,MovedOut dir) ev.robotActions
⇒
∃ev' r0.
dir < LENGTH (neighbour_coords c) ∧
FLOOKUP (computeEvents g) (EL dir (neighbour_coords c)) = SOME ev' ∧
MEM (nm,r0,MovedIn (opposite dir)) ev'.robotActions`,
rw[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS]
\\ reverse(fs[event_def])
>- (
fs[MEM_FLAT,MEM_GENLIST] \\ rw[]
\\ Cases_on`EL dir' (neighbours g c)` \\ fs[incomingFrom_def]
\\ fs[MEM_MAP,MEM_FILTER,UNCURRY] )
\\ fs[MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,MEM_MAP,UNCURRY]
\\ drule MEM_MovedOut_localActions
\\ simp[] \\ strip_tac
\\ fs[Once neighbours_def]
\\ rfs[EL_MAP,IS_SOME_EXISTS]
\\ simp[EXISTS_OR_THM]
\\ disj2_tac
\\ simp[MEM_FLAT,MEM_GENLIST,PULL_EXISTS]
\\ CONV_TAC SWAP_EXISTS_CONV
\\ qexists_tac`opposite dir`
\\ simp[Once LENGTH_neighbours]
\\ simp[Once neighbours_def,EL_MAP,Once LENGTH_neighbour_coords]
\\ fs[Once LENGTH_neighbour_coords]
\\ simp[neighbour_coords_opposite_imp]
\\ simp[incomingFrom_def,MEM_MAP,MEM_FILTER,EXISTS_PROD]
\\ rveq
\\ fs[localActions_def,MEM_MAP,UNCURRY]
\\ rw[]
\\ qexists_tac`SND y'` \\ fs[]);
val event_MovedIn_MovedOut = Q.store_thm("event_MovedIn_MovedOut",
`MEM (nm,r,MovedIn dir) ev.robotActions ∧
FLOOKUP (computeEvents g) c = SOME ev
⇒
∃ev'.
dir < LENGTH (neighbour_coords c) ∧
FLOOKUP (computeEvents g) (EL dir (neighbour_coords c)) = SOME ev' ∧
MEM (nm,r,MovedOut (opposite dir)) ev'.robotActions`,
rw[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS]
\\ fs[event_def]
>- (
fs[MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,MEM_MAP,UNCURRY]
\\ imp_res_tac NOT_MEM_MovedIn_localActions
\\ qpat_x_assum`MovedIn _ = _`(assume_tac o SYM)
\\ fs[] )
\\ fs[MEM_FLAT,MEM_GENLIST] \\ rw[]
\\ simp[MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,MEM_MAP,UNCURRY]
\\ Cases_on`EL dir' (neighbours g c)` \\ fs[incomingFrom_def]
\\ fs[MEM_MAP,MEM_FILTER,UNCURRY] \\ rw[]
\\ fs[Once neighbours_def]
\\ rfs[EL_MAP]
\\ simp[EXISTS_OR_THM]
\\ disj1_tac
\\ simp[localActions_def,MEM_MAP,PULL_EXISTS,UNCURRY]
\\ qexists_tac`y`
\\ simp[act_def,EL_MAP]
\\ fs[Once LENGTH_neighbour_coords,neighbour_coords_opposite_imp]
\\ simp[LENGTH_neighbour_coords]
\\ simp[updateInventory_def]);
val wf_state_step = Q.store_thm("wf_state_step",
`wf_state s ⇒ wf_state (step s)`,
strip_tac
\\ first_assum mp_tac
\\ simp_tac(srw_ss())[wf_state_def]
\\ reverse(rpt strip_tac)
>- (
fs[step_def,IN_FRANGE_FLOOKUP,FLOOKUP_FMAP_MAP2]
\\ rw[]
\\ pop_assum mp_tac
\\ simp[computeSquare_def,MEM_MAPi,PULL_EXISTS,MEM_GENLIST,MEM_FILTER,MEM_MAP]
\\ reverse(rw[])
\\ TRY pairarg_tac \\ fs[]
\\ rw[]
\\ fs[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS]
\\ simp[GSYM ADD1]
\\ match_mp_tac prim_recTheory.LESS_SUC
\\ first_x_assum match_mp_tac
\\ rw[]
\\ fs[event_def]
>- (
asm_exists_tac
\\ fs[MAP2_MAP,MAP2_same,ZIP_MAP]
\\ fs[MEM_MAP,UNCURRY,EXISTS_PROD]
\\ fs[localActions_def,MEM_MAP,UNCURRY] \\ rw[]
\\ metis_tac[PAIR,FST,FST_updateInventory])
\\ fs[MEM_FLAT,MEM_GENLIST]
\\ rw[]
\\ Cases_on`EL dir (neighbours s.grid k)` \\ fs[incomingFrom_def]
\\ fs[MEM_MAP,MEM_FILTER,UNCURRY]
\\ rw[]
\\ fs[neighbours_def]
\\ rfs[EL_MAP]
\\ asm_exists_tac \\ rw[]
\\ metis_tac[] )
>- (
fs[IN_FRANGE_FLOOKUP,step_def,FLOOKUP_FMAP_MAP2]
\\ simp[computeSquare_def,MAP_MAP_o,MAP_GENLIST]
\\ simp[ALL_DISTINCT_APPEND,MEM_GENLIST,ALL_DISTINCT_GENLIST,MEM_MAP,MEM_FILTER,PULL_EXISTS,MEM_MAPi]
\\ simp[combinTheory.o_DEF,ETA_AX]
\\ conj_tac
>- (
match_mp_tac ALL_DISTINCT_MAP_FILTER
\\ fs[computeEvents_def,FLOOKUP_FMAP_MAP2]
\\ simp[event_def,MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,MAP_MAP_o,o_DEF,UNCURRY,ETA_AX,ZIP_MAP]
\\ simp[localActions_def,MAP_MAP_o,o_DEF,UNCURRY,ETA_AX]
\\ fs[PULL_EXISTS]
\\ simp[ALL_DISTINCT_APPEND]
\\ conj_tac >- metis_tac[]
\\ simp[MEM_MAP,MEM_FLAT,MEM_GENLIST,PULL_EXISTS]
\\ simp[MAP_FLAT,MAP_GENLIST,o_DEF]
\\ conj_tac
>- (
simp[ALL_DISTINCT_FLAT,MEM_GENLIST,PULL_EXISTS,ALL_DISTINCT_FILTER_GENLIST]
\\ conj_tac
>- (
simp[ALL_DISTINCT_FILTER_GENLIST]
\\ qx_genl_tac[`d1`,`d2`]
\\ qmatch_goalsub_abbrev_tac`incomingFrom _ n1`
\\ qmatch_goalsub_abbrev_tac`_ = _ _ (incomingFrom _ n2)`
\\ Cases_on`n1` \\ simp[incomingFrom_def,MAP_MAP_o,o_DEF,UNCURRY,ETA_AX]
\\ Cases_on`n2` \\ simp[incomingFrom_def,MAP_MAP_o,o_DEF,UNCURRY,ETA_AX]
\\ rw[]
\\ fs[markerTheory.Abbrev_def]
\\ rpt(qpat_x_assum`SOME _ = _`(assume_tac o SYM))
\\ rfs[neighbours_def,EL_MAP]
\\ Q.ISPEC_THEN`neighbour_coords k`match_mp_tac
(Q.GEN`l` (MP_CANON (DISCH_ALL (#1 (EQ_IMP_RULE (UNDISCH_ALL (SPEC_ALL ALL_DISTINCT_EL_IMP)))))))
\\ simp[]
\\ spose_not_then strip_assume_tac
\\ last_x_assum drule
\\ qhdtm_x_assum`FLOOKUP`kall_tac
\\ disch_then drule
\\ disch_then drule
\\ simp[IN_DISJOINT]
\\ fs[GSYM NULL_EQ,NOT_NULL_MEM]
\\ fs[MEM_FILTER]
\\ qmatch_assum_abbrev_tac`(l1:'a list) = l2`
\\ `MEM (FST e) l1` by (simp[Abbr`l1`,MEM_MAP,MEM_FILTER] \\ metis_tac[])
\\ `MEM (FST e) l2` by metis_tac[]
\\ fs[Abbr`l1`,Abbr`l2`,MEM_MAP,MEM_FILTER]
\\ metis_tac[] )
\\ conj_tac
>- (
rw[]
\\ qmatch_goalsub_abbrev_tac`incomingFrom _ nb`
\\ Cases_on`nb` \\ simp[incomingFrom_def,MAP_MAP_o,o_DEF,UNCURRY,ETA_AX]
\\ match_mp_tac ALL_DISTINCT_MAP_FILTER
\\ fs[markerTheory.Abbrev_def]
\\ rpt(qpat_x_assum`SOME _ = _`(assume_tac o SYM))
\\ rfs[neighbours_def,EL_MAP]
\\ metis_tac[] )
\\ qx_genl_tac[`d1`,`d2`]
\\ qpat_abbrev_tac`nb = neighbours _ _`
\\ Cases_on`EL d1 nb` \\ simp[incomingFrom_def]
\\ Cases_on`EL d2 nb` \\ simp[incomingFrom_def]
\\ simp[MAP_MAP_o,o_DEF,UNCURRY,ETA_AX]
\\ rw[]
\\ fs[Abbr`nb`,neighbours_def,EL_MAP]
\\ simp[IN_DISJOINT,MEM_MAP,MEM_FILTER,UNCURRY]
\\ spose_not_then strip_assume_tac
\\ drule same_name_same_square
\\ simp[IN_FRANGE_FLOOKUP,PULL_EXISTS,MEM_MAP]
\\ asm_exists_tac \\ simp[]
\\ qpat_x_assum`FLOOKUP _ (EL d1 _) = _`assume_tac
\\ asm_exists_tac \\ simp[]
\\ asm_exists_tac \\ simp[]
\\ rveq \\ fs[MEM_MAP,MEM_FILTER]
\\ first_assum(part_match_exists_tac(el 2 o strip_conj) o concl)
\\ fs[]
\\ spose_not_then strip_assume_tac \\ rveq
\\ last_x_assum drule
\\ qpat_x_assum`FLOOKUP _ (EL d2 _) = _`assume_tac
\\ disch_then drule
\\ simp[GSYM NULL_EQ, NOT_NULL_MEM]
\\ reverse conj_tac >- metis_tac[]
\\ `d1 ≠ d2` suffices_by metis_tac[ALL_DISTINCT_neighbour_coords,EL_ALL_DISTINCT_EL_EQ,LESS_TRANS]
\\ spose_not_then strip_assume_tac \\ fs[])
\\ rw[]
\\ spose_not_then strip_assume_tac
\\ Cases_on`EL dir (neighbours s.grid k)`\\fs[incomingFrom_def]
\\ rfs[neighbours_def,EL_MAP]
\\ fs[MEM_MAP,MEM_FILTER,UNCURRY]
\\ rveq \\ fs[]
\\ last_x_assum drule
\\ qpat_x_assum`FLOOKUP _ k = _`assume_tac
\\ disch_then drule
\\ simp[IN_DISJOINT,MEM_MAP,PULL_EXISTS]
\\ metis_tac[NOT_MEM_neighbour_coords,MEM_EL])
\\ conj_tac >- ( simp[EL_ALL_DISTINCT_EL_EQ] )
\\ rw[]
\\ spose_not_then strip_assume_tac
\\ fs[computeEvents_def,FLOOKUP_FMAP_MAP2]
\\ rw[]
\\ drule (GEN_ALL event_name_in_grid)
\\ disch_then drule
\\ simp[]
\\ fs[PULL_EXISTS]
\\ rw[]
\\ spose_not_then strip_assume_tac
\\ first_x_assum drule \\ simp[]
\\ pairarg_tac \\ fs[]
\\ asm_exists_tac \\ fs[MEM_MAPi])
\\ fs[step_def,FLOOKUP_FMAP_MAP2]
\\ simp[computeSquare_def,MAP_MAP_o,MAP_GENLIST,o_DEF,ETA_AX]
\\ REWRITE_TAC[CONJ_ASSOC]
\\ reverse conj_tac
>- (
simp[IN_DISJOINT,MEM_MAPi]
\\ spose_not_then strip_assume_tac
\\ rw[] \\ fs[name_component_equality] )
\\ fs[computeEvents_def,FLOOKUP_FMAP_MAP2]
\\ rveq
\\ simp[IN_DISJOINT,MEM_GENLIST,MEM_MAP,MEM_FILTER,UNCURRY,PULL_EXISTS]
\\ fs[IN_DISJOINT]
\\ rw[]
\\ spose_not_then strip_assume_tac
>- (
rw[]
\\ drule (GEN_ALL event_name_in_grid)
\\ disch_then drule
\\ qhdtm_x_assum`FLOOKUP`mp_tac
\\ drule (GEN_ALL event_name_in_grid)
\\ disch_then drule
\\ rw[]
>- metis_tac[]
>- (
spose_not_then strip_assume_tac
\\ qmatch_assum_rename_tac`c2 ≠ c3`
\\ reverse(Cases_on`c3=c1`) >- metis_tac[]
\\ rveq \\ fs[] \\ rveq
\\ qmatch_assum_rename_tac`FST ra1 = FST ra2`
\\ Cases_on`ra1` \\ Cases_on`ra2` \\ fs[] \\ rveq
\\ qmatch_assum_rename_tac`MEM (nm,a1) _`
\\ qpat_x_assum`MEM (nm,a1) _`mp_tac
\\ qmatch_assum_rename_tac`MEM (nm,a2) _`
\\ strip_tac
\\ drule (GEN_ALL wf_state_event_same_name)
\\ disch_then drule
\\ qpat_x_assum`MEM (nm,a2) _`assume_tac
\\ disch_then drule
\\ CONV_TAC(LAND_CONV(SIMP_CONV(srw_ss())[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS,GSYM CONJ_ASSOC]))
\\ disch_then drule
\\ simp[]
\\ qpat_x_assum`FLOOKUP _ c2 = _`assume_tac
\\ asm_exists_tac
\\ rw[EXTENSION]
\\ disj2_tac
\\ qexists_tac`SND a1`
\\ simp[]
\\ CCONTR_TAC \\ fs[]
\\ fs[])
>- (
spose_not_then strip_assume_tac
\\ qmatch_assum_rename_tac`c1 ≠ c3`
\\ reverse(Cases_on`c3=c2`) >- metis_tac[]
\\ rveq \\ fs[] \\ rveq
\\ qmatch_assum_rename_tac`FST ra1 = FST ra2`
\\ Cases_on`ra1` \\ Cases_on`ra2` \\ fs[] \\ rveq
\\ qmatch_assum_rename_tac`MEM (nm,a1) _`
\\ qpat_x_assum`MEM (nm,a1) _`mp_tac
\\ qmatch_assum_rename_tac`MEM (nm,a2) _`
\\ strip_tac
\\ drule (GEN_ALL wf_state_event_same_name)
\\ disch_then drule
\\ qpat_x_assum`MEM (nm,a2) _`assume_tac
\\ disch_then drule
\\ CONV_TAC(LAND_CONV(SIMP_CONV(srw_ss())[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS,GSYM CONJ_ASSOC]))
\\ qpat_x_assum`FLOOKUP _ c1 = _`assume_tac
\\ disch_then drule
\\ simp[]
\\ qpat_x_assum`FLOOKUP _ c2 = _`assume_tac
\\ asm_exists_tac
\\ rw[EXTENSION]
\\ disj2_tac
\\ qexists_tac`SND a2`
\\ simp[]
\\ CCONTR_TAC \\ fs[]
\\ fs[])
>- (
spose_not_then strip_assume_tac
\\ qmatch_assum_rename_tac`c2 ≠ c3`
\\ qmatch_assum_rename_tac`c1 ≠ c4`
\\ reverse(Cases_on`c3=c4`) >- metis_tac[]
\\ rveq \\ fs[] \\ rveq
\\ qmatch_assum_rename_tac`FST ra1 = FST ra2`
\\ Cases_on`ra1` \\ Cases_on`ra2` \\ fs[] \\ rveq
\\ qmatch_assum_rename_tac`MEM (nm,a1) _`
\\ qpat_x_assum`MEM (nm,a1) _`mp_tac
\\ qmatch_assum_rename_tac`MEM (nm,a2) _`
\\ strip_tac
\\ drule (GEN_ALL wf_state_event_same_name)
\\ disch_then drule
\\ qpat_x_assum`MEM (nm,a2) _`assume_tac
\\ disch_then drule
\\ CONV_TAC(LAND_CONV(SIMP_CONV(srw_ss())[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS,GSYM CONJ_ASSOC]))
\\ qpat_x_assum`FLOOKUP _ c1 = _`assume_tac
\\ disch_then drule
\\ simp[]
\\ qpat_x_assum`FLOOKUP _ c2 = _`assume_tac
\\ asm_exists_tac
\\ rw[EXTENSION]
\\ disj2_tac
\\ qexists_tac`MovedOut (opposite dir)`
\\ simp[]
\\ CCONTR_TAC \\ fs[]
\\ pop_assum(assume_tac o SYM)
\\ fs[]))
>- (
rw[]
\\ qpat_x_assum`FLOOKUP _ c1 = _`assume_tac
\\ drule (GEN_ALL event_name_in_grid)
\\ disch_then drule
\\ rw[]
>- (
rw[MEM_MAP,MEM_MAPi]
\\ spose_not_then strip_assume_tac
\\ fs[IN_FRANGE_FLOOKUP,PULL_EXISTS,MEM_MAP,MEM_MAPi]
\\ first_x_assum drule
\\ disch_then drule \\ simp[])
>- (
rw[MEM_MAP]
\\ spose_not_then strip_assume_tac
\\ fs[IN_FRANGE_FLOOKUP,PULL_EXISTS,MEM_MAPi,MEM_MAP]
\\ first_x_assum drule
\\ disch_then drule
\\ simp[]))
\\ rw[]
\\ drule (GEN_ALL event_name_in_grid)
\\ disch_then drule
\\ fs[MEM_MAPi]
\\ rw[MEM_MAP]
\\ spose_not_then strip_assume_tac \\ fs[]
\\ fs[IN_FRANGE_FLOOKUP,MEM_MAP,PULL_EXISTS]
\\ first_x_assum drule
\\ disch_then drule
\\ qpat_assum`name _ _ _ = _`(assume_tac o SYM)
\\ fs[]);
val wf_state_fill = Q.store_thm("wf_state_fill",
`wf_state s.state ⇒ wf_state (fill f s)`,
simp[wf_state_def,fill_def,FLOOKUP_o_f,IN_FRANGE_FLOOKUP,PULL_EXISTS]
\\ strip_tac
\\ conj_tac
>- (
rpt gen_tac
\\ BasicProvers.TOP_CASE_TAC
\\ BasicProvers.TOP_CASE_TAC
\\ strip_tac \\ rveq
\\ simp[MAP_MAP_o]
\\ metis_tac[] )
\\ conj_tac
>- (
rpt gen_tac
\\ BasicProvers.TOP_CASE_TAC
\\ strip_tac \\ rveq
\\ simp[MAP_MAP_o]
\\ metis_tac[] )
\\ rpt gen_tac
\\ BasicProvers.TOP_CASE_TAC
\\ strip_tac \\ rveq
\\ fs[MAP_MAP_o]
\\ metis_tac[]);
val focal_event_sing = Q.store_thm("focal_event_sing",
`wf_state s ∧
sq ∈ FRANGE s.grid ∧
MEM nm (MAP FST sq.robots)
⇒
∃x.
{(ev,a) | ∃r. MEM (nm,r,a) ev.robotActions ∧
¬isMovedOut a ∧
ev ∈ FRANGE (computeEvents s.grid) }
= {x}`,
rw[computeEvents_def,IN_FRANGE_FLOOKUP,FLOOKUP_FMAP_MAP2,EXTENSION,PULL_EXISTS]
\\ `MEM nm (MAP FST (event sq (neighbours s.grid k)).robotActions)`
by (
rw[event_def,MAP2_MAP,MAP2_same,PAIR_MAP_COMPOSE,MAP_MAP_o,o_DEF,UNCURRY,ETA_AX,ZIP_MAP]
\\ rw[localActions_def,MAP_MAP_o,o_DEF,UNCURRY,ETA_AX] )
\\ qmatch_asmsub_abbrev_tac`MEM nm (MAP FST ev.robotActions)`
\\ `FLOOKUP (computeEvents s.grid) k = SOME ev`
by simp[computeEvents_def,FLOOKUP_FMAP_MAP2]
\\ fs[MEM_MAP] \\ rw[]
\\ qmatch_assum_rename_tac`MEM nra ev.robotActions`
\\ Cases_on`isMovedIn (SND(SND nra))`
>- (
qexists_tac`(ev,SND(SND nra))`
\\ rw[EQ_IMP_THM,Abbr`ev`]
\\ PairCases_on`nra` \\ fs[]
\\ rveq
>- (
drule (GEN_ALL same_name_same_action)
\\ disch_then drule
\\ simp[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS]
\\ disch_then drule
\\ disch_then drule
\\ disch_then drule
\\ strip_tac \\ rveq \\ fs[]
\\ Cases_on`nra2` \\ fs[]
\\ fs[EXTENSION]
\\ first_assum(qspec_then`a`mp_tac)
\\ simp_tac(srw_ss())[]
\\ strip_tac \\ fs[]
\\ first_x_assum(qspec_then`MovedOut(opposite dir)`mp_tac)
\\ simp[] )
\\ first_assum(part_match_exists_tac (el 2 o strip_conj) o concl) \\ simp[]
\\ Cases_on`nra2` \\ fs[])
\\ Cases_on`isMovedOut (SND(SND nra))`
>- (
PairCases_on`nra`\\fs[]
\\ Cases_on`nra2`\\fs[]
\\ rw[]
\\ drule (GEN_ALL event_MovedOut_MovedIn)
\\ disch_then drule
\\ rw[]
\\ qexists_tac`(ev', MovedIn(opposite n))`
\\ rw[EQ_IMP_THM]
>- (
fs[computeEvents_def,FLOOKUP_FMAP_MAP2,Abbr`ev`]
\\ rveq \\ fs[] \\ rveq
\\ qmatch_assum_rename_tac`FLOOKUP _ c = SOME _`
\\ `c = EL n (neighbour_coords k) ∧ (r,a) = (r0,MovedIn (opposite n))`
by (
drule (GEN_ALL same_name_same_action)
\\ simp[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS]
\\ disch_then drule
\\ qpat_x_assum`FLOOKUP _ (_ _) = _`assume_tac
\\ disch_then drule
\\ disch_then drule
\\ disch_then drule
\\ strip_tac \\ fs[]
\\ fs[EXTENSION]
\\ first_assum(qspec_then`a`mp_tac)
\\ simp_tac(srw_ss())[]
\\ strip_tac \\ fs[]
\\ first_x_assum(qspec_then`MovedOut(opposite dir)`mp_tac)
\\ simp[] )
\\ fs[] )
\\ fs[computeEvents_def,FLOOKUP_FMAP_MAP2]
\\ rw[]
\\ metis_tac[] )
\\ qexists_tac`(ev,SND(SND nra))`
\\ rw[EQ_IMP_THM]
>- (
fs[computeEvents_def,FLOOKUP_FMAP_MAP2,Abbr`ev`]
\\ PairCases_on`nra` \\ rfs[] \\ rveq
\\ drule (GEN_ALL same_name_same_action)
\\ simp[computeEvents_def,FLOOKUP_FMAP_MAP2,PULL_EXISTS]
\\ disch_then drule
\\ qpat_x_assum`FLOOKUP _ k = _`assume_tac
\\ disch_then drule
\\ disch_then drule
\\ disch_then drule
\\ strip_tac \\ fs[]
\\ fs[EXTENSION]
\\ first_x_assum(qspec_then`nra2`mp_tac)
\\ rw[] \\ fs[] )
\\ fs[computeEvents_def,FLOOKUP_FMAP_MAP2,Abbr`ev`]
\\ PairCases_on`nra` \\ rfs[] \\ rveq
\\ metis_tac[]);
val FRANGE_fill = Q.store_thm("FRANGE_fill",
`FRANGE (fill f s).grid =
IMAGE (square_robots_fupd (MAP (if_focal s.focal_name f)))
(FRANGE s.state.grid)`,
rw[EXTENSION,IN_FRANGE_FLOOKUP,EQ_IMP_THM,fill_def,FLOOKUP_o_f]
\\ pop_assum mp_tac
\\ BasicProvers.TOP_CASE_TAC \\ fs[] \\ rw[]
\\ TRY(qexists_tac`k`\\simp[])
\\ metis_tac[]);