-
Notifications
You must be signed in to change notification settings - Fork 85
/
optPlannerProofsScript.sml
889 lines (853 loc) · 35.8 KB
/
optPlannerProofsScript.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
(**
Correctness proof for optimization planner
**)
open semanticPrimitivesTheory evaluateTheory
icing_rewriterTheory icing_optimisationsTheory
icing_optimisationProofsTheory fpOptTheory fpValTreeTheory
optPlannerTheory source_to_source2Theory source_to_source2ProofsTheory
floatToRealProofsTheory icing_realIdProofsTheory;
open preamble;
val _ = new_theory "optPlannerProofs";
fun rnCases_on t = rename1 t >> Cases_on t
(** The phase repeater can only repeat rewrites **)
Theorem phase_repeater_mem:
∀ n path rws r cfg e e2.
MEM (Apply (path, rws)) r ∧
phase_repeater n apply_distributivity cfg e = (e2, r) ⇒
∃ ei. MEM (Apply (path, rws)) (SND (apply_distributivity cfg ei))
Proof
Induct_on ‘n’ >> gs[phase_repeater_def] >> rpt strip_tac
>- (qexists_tac ‘e’ >> gs[])
>> Cases_on ‘apply_distributivity cfg e’ >> gs[]
>> Cases_on ‘q ≠ e’ >> gs[]
>> rnCases_on ‘phase_repeater n apply_distributivity cfg e3’ >> gs[]
>> rveq >> gs[MEM_APPEND]
>- (qexists_tac ‘e’ >> gs[])
>> first_x_assum irule >> asm_exists_tac >> gs[]
QED
(** Side-lemmas to ease proofs later **)
fun path_tac index_def =
Induct_on ‘r’ >> simp[MAP_plan_to_path_def]
>> rpt strip_tac
>- (
Cases_on ‘h’ >> gs[]
>> Cases_on ‘p’ >> gs[index_def])
>> last_x_assum mp_tac >> impl_tac >> gs[MAP_plan_to_path_def]
>> strip_tac >> asm_exists_tac >> gs[];
Theorem MEM_MAP_plan_to_path_index:
MEM (Apply (path, rws)) (MAP_plan_to_path (listIndex n) r) ⇒
∃ spath. path = ListIndex (n, spath) ∧
MEM (Apply (spath, rws)) r
Proof
path_tac listIndex_def
QED
Theorem MEM_MAP_plan_to_path_right:
MEM (Apply (path, rws)) (MAP_plan_to_path right r) ⇒
∃ spath. path = Right spath ∧
MEM (Apply (spath, rws)) r
Proof
path_tac right_def
QED
Theorem MEM_MAP_plan_to_path_center:
MEM (Apply (path, rws)) (MAP_plan_to_path center r) ⇒
∃ spath. path = Center spath ∧
MEM (Apply (spath, rws)) r
Proof
path_tac center_def
QED
Theorem MEM_MAP_plan_to_path_left:
MEM (Apply (path, rws)) (MAP_plan_to_path left r) ⇒
∃ spath. path = Left spath ∧
MEM (Apply (spath, rws)) r
Proof
path_tac left_def
QED
Theorem MAP_plan_to_path_SUC_prod:
(λ i (_, plani). MAP_plan_to_path (listIndex (i+n)) plani) o SUC =
λ i (_, plani). MAP_plan_to_path (listIndex (i + SUC n)) plani
Proof
gs[FUN_EQ_THM] >> rpt strip_tac >> gs[SUC_ONE_ADD]
QED
Theorem MAP_plan_to_path_SUC_trip:
(λ i (_, _, plani). MAP_plan_to_path (listIndex (i+n)) plani) o SUC =
λ i (_, _, plani). MAP_plan_to_path (listIndex (i + SUC n)) plani
Proof
gs[FUN_EQ_THM] >> rpt strip_tac >> gs[SUC_ONE_ADD]
QED
Theorem MAPi_plan_to_path_prod:
MAPi ((λ i (_, plani). MAP_plan_to_path (listIndex (i + n)) plani) o SUC) =
MAPi (λ i (_, plani). MAP_plan_to_path (listIndex (i+ SUC n)) plani)
Proof
gs[MAP_plan_to_path_SUC_prod]
QED
Theorem MAPi_plan_to_path_trip:
MAPi ((λ i (_, _, plani). MAP_plan_to_path (listIndex (i + n)) plani) o SUC) =
MAPi (λ i (_, _, plani). MAP_plan_to_path (listIndex (i+ SUC n)) plani)
Proof
gs[MAP_plan_to_path_SUC_trip]
QED
Theorem MEM_list_flat_sub_exp_general:
∀ l n f path rws cfg.
MEM (Apply (path, rws))
(FLAT (MAPi (λi (_, plani).
MAP_plan_to_path (listIndex (i+n)) plani)
(MAP (λ a. f a) l))) ⇒
∃ e path. exp_size e < exp6_size l ∧
MEM (Apply (path, rws)) (SND (f e)) ∧
MEM e l
Proof
Induct_on ‘l’ >> gs[]
>> rpt strip_tac >> gs[]
>- (
qexists_tac ‘h’ >> gs[astTheory.exp_size_def]
>> Cases_on ‘f h’ >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_index >> asm_exists_tac >> gs[])
>> gs[MAPi_plan_to_path_prod]
>> res_tac >> qexists_tac ‘e’ >> gs[astTheory.exp_size_def]
>> asm_exists_tac >> gs[]
QED
Theorem MEM_list_flat_sub_exp =
Q.SPECL [‘l’, ‘0’, ‘f’] MEM_list_flat_sub_exp_general
|> GEN “l:exp list”
|> GEN “f:exp -> 'a # opt_step list”
|> REWRITE_RULE [ADD_CLAUSES];
Theorem MEM_list_flat_sub_patexp_general:
∀ l n f path rws cfg.
MEM (Apply (path, rws))
(FLAT (MAPi (λi (_, _, plani).
MAP_plan_to_path (listIndex (i+n)) plani)
(MAP (λ (p,e). (p, f e)) l))) ⇒
∃ e p path. exp_size e < exp3_size l ∧
MEM (Apply (path, rws)) (SND (f e)) ∧
MEM (p, e) l
Proof
Induct_on ‘l’ >> gs[]
>> rpt strip_tac >> gs[]
>- (
Cases_on ‘h’ >> gs[]
>> qexists_tac ‘r’ >> qexists_tac ‘q’ >> gs[astTheory.exp_size_def]
>> Cases_on ‘f r’ >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_index >> asm_exists_tac >> gs[])
>> gs[MAPi_plan_to_path_trip]
>> res_tac >> qexists_tac ‘e’ >> gs[astTheory.exp_size_def]
>> asm_exists_tac >> qexists_tac ‘p’ >> gs[]
QED
Theorem MEM_list_flat_sub_patexp =
Q.SPECL [‘l’, ‘0’] MEM_list_flat_sub_patexp_general
|> GEN “l:(pat # exp) list”
|> GEN “f:exp -> 'a # opt_step list”
|> REWRITE_RULE [ADD_CLAUSES];
(** Now prove that generate_plan_exp can only produce rewrites from its
components **)
Theorem generate_plan_upper_bound_rws:
MEM (Apply (path,rws)) (generate_plan_exp cfg e) ⇒
(∃ e. MEM (Apply (path,rws)) (SND (canonicalize cfg e))) ∨
(∃ e. MEM (Apply (path,rws)) (SND (apply_distributivity cfg e))) ∨
(∃ e. MEM (Apply (path,rws)) (SND (peephole_optimise cfg e))) ∨
(∃ e. MEM (Apply (path,rws)) (SND (balance_expression_tree cfg e)))
Proof
gs[generate_plan_exp_def, compose_plan_generation_def]
>> rnCases_on ‘canonicalize cfg e’ >> gs[]
>> rnCases_on ‘phase_repeater 100 apply_distributivity cfg e2’ >> gs[]
>> rnCases_on ‘canonicalize cfg e3’ >> gs[]
>> rnCases_on ‘canonicalize cfg e4’ >> gs[]
>> rnCases_on ‘peephole_optimise cfg e5’ >> gs[]
>> rnCases_on ‘balance_expression_tree cfg e6’ >> gs[]
>> rename1 ‘balance_expression_tree cfg e6 = (e7, r7)’
>> rpt (TOP_CASE_TAC >> gs[]) >> rveq >> strip_tac
>> imp_res_tac phase_repeater_mem
(* canonicalize cases *)
>> TRY (DISJ1_TAC >> qexists_tac ‘e’ >> gs[] >> NO_TAC)
>> TRY (DISJ1_TAC >> qexists_tac ‘e2’ >> gs[] >> NO_TAC)
>> TRY (DISJ1_TAC >> qexists_tac ‘e3’ >> gs[] >> NO_TAC)
>> TRY (DISJ1_TAC >> qexists_tac ‘e4’ >> gs[] >> NO_TAC)
(* phase repeater cases *)
>> TRY (DISJ2_TAC >> DISJ1_TAC >> qexists_tac ‘ei’ >> gs[] >> NO_TAC)
(* peephole optimise cases *)
>> TRY (ntac 2 DISJ2_TAC >> DISJ1_TAC >> qexists_tac ‘e’ >> gs[] >> NO_TAC)
>> TRY (ntac 2 DISJ2_TAC >> DISJ1_TAC >> qexists_tac ‘e2’ >> gs[] >> NO_TAC)
>> TRY (ntac 2 DISJ2_TAC >> DISJ1_TAC >> qexists_tac ‘e3’ >> gs[] >> NO_TAC)
>> TRY (ntac 2 DISJ2_TAC >> DISJ1_TAC >> qexists_tac ‘e4’ >> gs[] >> NO_TAC)
>> TRY (ntac 2 DISJ2_TAC >> DISJ1_TAC >> qexists_tac ‘e5’ >> gs[] >> NO_TAC)
(* balance expression tree cases *)
>> TRY (ntac 3 DISJ2_TAC >> qexists_tac ‘e’ >> gs[] >> NO_TAC)
>> TRY (ntac 3 DISJ2_TAC >> qexists_tac ‘e2’ >> gs[] >> NO_TAC)
>> TRY (ntac 3 DISJ2_TAC >> qexists_tac ‘e3’ >> gs[] >> NO_TAC)
>> TRY (ntac 3 DISJ2_TAC >> qexists_tac ‘e4’ >> gs[] >> NO_TAC)
>> TRY (ntac 3 DISJ2_TAC >> qexists_tac ‘e5’ >> gs[] >> NO_TAC)
>> TRY (ntac 3 DISJ2_TAC >> qexists_tac ‘e6’ >> gs[] >> NO_TAC)
QED
(** Bound for canonicalize **)
Theorem canonicalize_app_upper_bound:
∀ e op eNew r path rws rw r.
canonicalize_app e = (eNew, r) ∧
MEM (Apply (path, rws)) r ∧
MEM rw rws ⇒
MEM rw [fp_neg_times_minus_one; fp_sub_add;
fp_comm_gen FP_Add; fp_comm_gen FP_Mul;
fp_assoc_gen FP_Add; fp_assoc_gen FP_Mul]
Proof
measureInduct_on ‘exp_size e’
>> simp[Once canonicalize_app_def, CaseEq"op", CaseEq"list"]
>> rpt strip_tac >> gs[CaseEq "exp", CaseEq "fp_bop", CaseEq"list", CaseEq"op"]
>> rveq >> gs[canonicalize_sub_def]
>> qpat_x_assum ‘_ = (_, _)’ mp_tac
>> COND_CASES_TAC >> gs[] >> rpt strip_tac >> rveq >> gs[]
>- (
Cases_on ‘canonicalize_app (App (FP_bop FP_Add) [v315; v153])’
>> gs[] >> rveq >> gs[MEM]
>> imp_res_tac MEM_MAP_plan_to_path_index
>> first_x_assum $ qspec_then ‘App (FP_bop FP_Add) [v315; v153]’ mp_tac
>> gs[astTheory.exp_size_def]
>> rpt $ disch_then drule >> gs[])
>> Cases_on ‘canonicalize_app (App (FP_bop FP_Mul) [v453; v153])’
>> gs[] >> rveq >> gs[MEM]
>> imp_res_tac MEM_MAP_plan_to_path_index
>> first_x_assum $ qspec_then ‘App (FP_bop FP_Mul) [v453; v153]’ mp_tac
>> gs[astTheory.exp_size_def]
>> rpt $ disch_then drule >> gs[]
QED
fun trivial_case_tac t =
first_x_assum $ qspec_then t mp_tac >> gs[]
>> disch_then $ qspecl_then [‘spath’, ‘rws’, ‘cfg’] mp_tac >> gs[];
(** Prove upper bound on rewrites for canonicalize **)
Theorem canonicalize_upper_bound:
∀ e path rws cfg.
MEM (Apply (path, rws)) (SND (canonicalize cfg e)) ⇒
∀ rw. MEM rw rws ⇒
MEM rw [fp_neg_times_minus_one; fp_sub_add;
fp_comm_gen FP_Add; fp_comm_gen FP_Mul;
fp_assoc_gen FP_Add; fp_assoc_gen FP_Mul]
Proof
measureInduct_on ‘exp_size e’
>> Cases_on ‘e’ >> gs[canonicalize_def] >> rpt strip_tac
>> gs[astTheory.exp_size_def]
>- (
imp_res_tac MEM_list_flat_sub_exp
>> first_x_assum $ qspec_then ‘e’ mp_tac >> gs[]
>> disch_then (fn ith => first_x_assum (fn th => mp_then Any drule ith th))
>> gs[])
>- (
Cases_on ‘cfg.canOpt’ >> gs[]
>- (
Cases_on ‘canonicalize_app (App o' (MAP FST (MAP (λ a. canonicalize cfg a) l)))’ >> gs[]
>- (
imp_res_tac MEM_list_flat_sub_exp
>> first_x_assum $ qspec_then ‘e’ mp_tac >> gs[]
>> disch_then (fn ith => first_x_assum (fn th => mp_then Any drule ith th))
>> gs[])
>> imp_res_tac canonicalize_app_upper_bound >> gs[])
>> imp_res_tac MEM_list_flat_sub_exp
>> first_x_assum $ qspec_then ‘e’ mp_tac >> gs[]
>> disch_then (fn ith => first_x_assum (fn th => mp_then Any drule ith th))
>> gs[])
>- (
Cases_on ‘canonicalize cfg e0’ >> Cases_on ‘canonicalize cfg e'’
>> gs[MEM_APPEND]
>> imp_res_tac MEM_MAP_plan_to_path_left
>> imp_res_tac MEM_MAP_plan_to_path_right
>- trivial_case_tac ‘e'’
>> trivial_case_tac ‘e0’)
>- (
Cases_on ‘canonicalize cfg e1’
>> Cases_on ‘canonicalize cfg e0’
>> Cases_on ‘canonicalize cfg e'’
>> gs[MEM_APPEND]
>> imp_res_tac MEM_MAP_plan_to_path_left
>> imp_res_tac MEM_MAP_plan_to_path_center
>> imp_res_tac MEM_MAP_plan_to_path_right
>- trivial_case_tac ‘e'’
>- trivial_case_tac ‘e0’
>> trivial_case_tac ‘e1’)
>- (
Cases_on ‘canonicalize cfg e'’ >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_left
>- trivial_case_tac ‘e'’
>> imp_res_tac MEM_list_flat_sub_patexp
>> first_x_assum $ qspec_then ‘e’ mp_tac >> gs[]
>> disch_then (fn ith => first_x_assum (fn th => mp_then Any drule ith th))
>> gs[])
>- (
Cases_on ‘canonicalize cfg e0’ >> Cases_on ‘canonicalize cfg e'’
>> gs[MEM_APPEND]
>> imp_res_tac MEM_MAP_plan_to_path_left
>> imp_res_tac MEM_MAP_plan_to_path_right
>- trivial_case_tac ‘e'’
>> trivial_case_tac ‘e0’)
>- (
Cases_on ‘canonicalize cfg e'’ >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_center
>> trivial_case_tac ‘e'’)
>- (
Cases_on ‘canonicalize cfg e'’ >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_center
>> trivial_case_tac ‘e'’)
>- (
Cases_on ‘canonicalize cfg e'’ >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_center
>> trivial_case_tac ‘e'’)
>> Cases_on ‘canonicalize (cfg with canOpt := (f = Opt)) e'’ >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_center
>> first_x_assum $ qspec_then ‘e'’ mp_tac >> gs[]
>> disch_then $ qspecl_then [‘spath’, ‘rws’, ‘cfg with canOpt := (f = Opt)’] mp_tac
>> gs[]
QED
(** Intermediate theorem for postorder-traversal of expressions **)
Theorem postorder_upper_bound:
∀ f cfg e P.
(∀ e cfg eOpt plan.
f cfg e = SOME (eOpt, plan) ⇒
∀ path rws.
MEM (Apply (path, rws)) plan ⇒
P rws) ⇒
∀ eOpt plan path rws.
(post_order_dfs_for_plan f cfg e) = (eOpt, plan) ⇒
(MEM (Apply (path, rws)) plan ⇒
P rws)
Proof
ho_match_mp_tac post_order_dfs_for_plan_ind >> rw[]
>> gs[post_order_dfs_for_plan_def]
>- (
Cases_on ‘post_order_dfs_for_plan f (cfg with canOpt := (sc = Opt)) e’
>> gs[] >> rveq
>> imp_res_tac MEM_MAP_plan_to_path_center
>> first_x_assum drule >> disch_then drule >> gs[])
>- (
qpat_x_assum `_ = (_,_)` mp_tac
>> COND_CASES_TAC >> gs[]
>- (
TOP_CASE_TAC >> gs[]
>- (
rpt strip_tac >> rveq
>> imp_res_tac MEM_list_flat_sub_exp
>> res_tac
>> Cases_on ‘post_order_dfs_for_plan f cfg e’ >> gs[]
>> first_x_assum drule >> gs[])
>> TOP_CASE_TAC >> gs[]
>> rpt strip_tac >> rveq >> gs[]
>> imp_res_tac MEM_list_flat_sub_exp
>> res_tac
>> Cases_on ‘post_order_dfs_for_plan f cfg e’ >> gs[]
>> first_x_assum drule >> gs[])
>> rpt strip_tac >> rveq
>> imp_res_tac MEM_list_flat_sub_exp
>> res_tac
>> Cases_on ‘post_order_dfs_for_plan f cfg e’ >> gs[]
>> first_x_assum drule >> gs[])
>- (
Cases_on ‘post_order_dfs_for_plan f cfg e'’
>> Cases_on ‘post_order_dfs_for_plan f cfg e’
>> gs[] >> rveq >> gs[MEM_APPEND]
>> imp_res_tac MEM_MAP_plan_to_path_left
>> imp_res_tac MEM_MAP_plan_to_path_right
>> res_tac)
>- (
rveq
>> imp_res_tac MEM_list_flat_sub_exp
>> res_tac
>> Cases_on ‘post_order_dfs_for_plan f cfg e’ >> gs[]
>> first_x_assum drule >> gs[])
>- (
Cases_on ‘post_order_dfs_for_plan f cfg e'’
>> Cases_on ‘post_order_dfs_for_plan f cfg e’
>> gs[] >> rveq >> gs[MEM_APPEND]
>> imp_res_tac MEM_MAP_plan_to_path_left
>> imp_res_tac MEM_MAP_plan_to_path_right
>> res_tac)
>- (
Cases_on ‘post_order_dfs_for_plan f cfg e''’
>> Cases_on ‘post_order_dfs_for_plan f cfg e'’
>> Cases_on ‘post_order_dfs_for_plan f cfg e’
>> ntac 5 $ pop_assum mp_tac
>> disch_then (fn th => mp_tac (SIMP_RULE std_ss [] th))
>> rpt strip_tac >> rveq
>> qpat_x_assum `MEM _ _` mp_tac
>> rewrite_tac[MEM_APPEND] >> strip_tac
>> imp_res_tac MEM_MAP_plan_to_path_left
>> imp_res_tac MEM_MAP_plan_to_path_center
>> imp_res_tac MEM_MAP_plan_to_path_right
>- (
res_tac >> first_x_assum drule >> rveq
>> metis_tac[])
>- (
res_tac >> first_x_assum drule >> rveq
>> metis_tac[])
>> last_x_assum $ qspecl_then [‘q''’, ‘r''’, ‘q'’, ‘r'’] mp_tac
>> impl_tac >- rewrite_tac[]
>> disch_then $ qspec_then ‘P’ mp_tac
>> impl_tac >- first_x_assum MATCH_ACCEPT_TAC
>> disch_then $ qspecl_then [‘q’, ‘r’, ‘spath’, ‘rws’] mp_tac
>> impl_tac >- asm_rewrite_tac[]
>> metis_tac[])
>- (
Cases_on ‘post_order_dfs_for_plan f cfg e’
>> gs[] >> rveq
>> imp_res_tac MEM_MAP_plan_to_path_center
>> first_x_assum drule >> disch_then drule >> gs[])
>- (
Cases_on ‘post_order_dfs_for_plan f cfg e’
>> gs[] >> rveq
>> imp_res_tac MEM_MAP_plan_to_path_center
>> first_x_assum drule >> disch_then drule >> gs[])
>- (
Cases_on ‘post_order_dfs_for_plan f cfg e’
>> gs[] >> rveq
>> imp_res_tac MEM_MAP_plan_to_path_center
>> first_x_assum drule >> disch_then drule >> gs[])
>- (
Cases_on ‘post_order_dfs_for_plan f cfg e’
>> gs[] >> rveq >> gs[MEM_APPEND]
>- (
imp_res_tac MEM_MAP_plan_to_path_left
>> first_x_assum drule >> disch_then drule >> gs[])
>> imp_res_tac MEM_list_flat_sub_patexp
>> res_tac
>> Cases_on ‘post_order_dfs_for_plan f cfg e'’ >> gs[]
>> first_x_assum drule >> gs[])
QED
Theorem plan_app_rewrite_with_each_alt:
∀ xs e eOpt plan path rws rw.
(λ (rewritten, plan).
if plan = [] then NONE
else SOME (rewritten, MAP (λ x. Apply x) plan))
(try_rewrite_with_each xs e) = SOME (eOpt, plan) ∧
MEM (Apply (path, rws)) plan ∧
MEM rw rws ⇒
MEM rw xs
Proof
Induct_on ‘xs’ >> simp[Once try_rewrite_with_each_def]
>> rpt strip_tac >> qpat_x_assum `_ = SOME _` mp_tac
>> PairCases_on ‘h’ >> gs[try_rewrite_with_each_def]
>> TOP_CASE_TAC >> gs[]
>- (rpt strip_tac >> res_tac >> metis_tac[])
>> rpt strip_tac >> rveq >> gs[]
>> ‘∃subplan. plan = (Apply (Here, [(h0,h1)]))::subplan’
by (
Cases_on ‘try_rewrite_with_each xs (rewriteFPexp [(h0, h1)] e)’
>> gs[] >> rveq >> gs[])
>> rveq >> gs[]
>> DISJ2_TAC >> first_x_assum irule
>> qexists_tac ‘rewriteFPexp [(h0,h1)] e’ >> qexists_tac ‘eOpt’
>> qexists_tac ‘path’ >> qexists_tac ‘subplan’ >> qexists_tac ‘rws’
>> gs[]
>> Cases_on ‘try_rewrite_with_each xs (rewriteFPexp [(h0, h1)] e)’
>> gs[] >> rveq >> Cases_on ‘r’ >> gs[]
QED
Theorem peephole_optimise_upper_bound:
∀ e path rws cfg.
MEM (Apply (path, rws)) (SND (peephole_optimise cfg e)) ⇒
∀ rw. MEM rw rws ⇒
MEM rw [fp_neg_push_mul_r; fp_times_minus_one_neg; fp_add_sub;
fp_times_two_to_add; fp_times_three_to_add; fp_times_zero;
fp_plus_zero; fp_times_one; fp_same_sub; fp_fma_intro]
Proof
simp[Once peephole_optimise_def]
>> rpt gen_tac
>> qmatch_goalsub_abbrev_tac ‘MEM _ (SND (post_order_dfs_for_plan peephole_app cfg e))’
>> rpt strip_tac
>> qspecl_then [‘peephole_app’, ‘cfg’, ‘e’,
‘λ rws. ∀ rw. MEM rw rws ⇒
rw = fp_neg_push_mul_r ∨ rw = fp_times_minus_one_neg ∨
rw = fp_add_sub ∨ rw = fp_times_two_to_add ∨
rw = fp_times_three_to_add ∨ rw = fp_times_zero ∨
rw = fp_plus_zero ∨ rw = fp_times_one ∨ rw = fp_same_sub ∨
rw = fp_fma_intro’]
mp_tac postorder_upper_bound
>> gs[]
>> impl_tac
>- (
unabbrev_all_tac
>> rpt $ pop_assum kall_tac
>> gs[] >> rpt strip_tac
>> drule plan_app_rewrite_with_each_alt
>> rpt $ disch_then drule >> gs[] >> metis_tac[])
>> Cases_on ‘post_order_dfs_for_plan peephole_app cfg e’ >> gs[]
>> rpt $ disch_then drule >> gs[]
QED
Theorem move_multiplicants_to_right_upper_bound:
∀ cfg intersect e eOpt plan path rws rw.
move_multiplicants_to_right cfg intersect e = (eOpt, plan) ∧
MEM (Apply (path, rws)) plan ∧
MEM rw rws ⇒
MEM rw [fp_comm_gen FP_Mul; fp_assoc_gen FP_Mul; fp_assoc2_gen FP_Mul]
Proof
ho_match_mp_tac move_multiplicants_to_right_ind
>> rw[]
>- gs[move_multiplicants_to_right_def]
>- (
qpat_x_assum `move_multiplicants_to_right _ _ _ = _` mp_tac
>> simp[Once move_multiplicants_to_right_def,
CaseEq "exp", CaseEq"list", CaseEq"op", CaseEq"fp_bop"]
>> rpt strip_tac >> gs[] >> rveq
>> Cases_on ‘move_multiplicants_to_right cfg [m] e2’ >> gs[]
>> qpat_x_assum `(if _ then _ else _) = _` mp_tac
>> rpt (COND_CASES_TAC >> gs[])
>> rpt strip_tac >> rveq >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_index
>> first_x_assum drule >> rpt $ disch_then drule >> gs[])
>> qpat_x_assum `move_multiplicants_to_right _ _ _ = _` mp_tac
>> simp[Once move_multiplicants_to_right_def]
>> Cases_on ‘move_multiplicants_to_right cfg [m1] e’ >> gs[]
>> simp[CaseEq "exp", CaseEq"list", CaseEq"op", CaseEq"fp_bop"]
>> rpt strip_tac >> gs[] >> rveq
>> TRY (
first_x_assum $ drule
>> rpt $ disch_then drule >> gs[] >> NO_TAC)
>> Cases_on ‘move_multiplicants_to_right cfg (m2::rest) e1’ >> gs[]
>> qpat_x_assum `(if _ then _ else _) = _` mp_tac
>> rpt (COND_CASES_TAC >> gs[])
>> rpt strip_tac >> rveq >> gs[]
>> imp_res_tac MEM_MAP_plan_to_path_index
>> first_x_assum $ drule
>> rpt $ disch_then drule >> gs[]
QED
Theorem canonicalize_for_distributivity_upper_bound:
MEM (Apply (path, rws)) (SND (canonicalize_for_distributivity cfg e)) ∧
MEM rw rws ⇒
MEM rw [fp_comm_gen FP_Mul; fp_assoc_gen FP_Mul; fp_assoc2_gen FP_Mul]
Proof
rpt strip_tac
>> qmatch_goalsub_abbrev_tac ‘MEM rw canon_rws’
>> Cases_on `canonicalize_for_distributivity cfg e` >> gs[]
>> gs[canonicalize_for_distributivity_def]
>> qpat_x_assum ‘_ = (_, _)’ mp_tac
>> qmatch_goalsub_abbrev_tac ‘post_order_dfs_for_plan canonicalize_app_fun _ _’
>> rpt strip_tac
>> qspecl_then [‘canonicalize_app_fun’, ‘cfg’, ‘e’, ‘λ rws. ∀ rw. MEM rw rws ⇒ MEM rw canon_rws’]
mp_tac postorder_upper_bound
>> gs[]
>> reverse impl_tac
>- (rpt $ disch_then drule >> gs[])
>> unabbrev_all_tac
>> rpt $ pop_assum kall_tac
>> rpt strip_tac >> gs[CaseEq"exp", CaseEq"op", CaseEq"list"]
>> rveq
>> qpat_x_assum ‘_ = SOME _’ mp_tac
>> qmatch_goalsub_abbrev_tac ‘move_multiplicants_to_right _ intersect_e1_e2 _’
>> Cases_on ‘move_multiplicants_to_right cfg' intersect_e1_e2 e1’ >> gs[]
>> Cases_on ‘move_multiplicants_to_right cfg' intersect_e1_e2 e2’ >> gs[]
>> rpt strip_tac >> rveq >> gs[MEM_APPEND]
>> imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac move_multiplicants_to_right_upper_bound >> gs[]
QED
Theorem canonicalize_for_distributivity_upper_bound_alt:
canonicalize_for_distributivity cfg e = (eOpt, plan) ∧
MEM (Apply (path, rws)) plan ∧
MEM rw rws ⇒
MEM rw [fp_comm_gen FP_Mul; fp_assoc_gen FP_Mul; fp_assoc2_gen FP_Mul]
Proof
rpt strip_tac >> irule canonicalize_for_distributivity_upper_bound
>> qexists_tac ‘cfg’ >> qexists_tac ‘e’ >> gs[]
>> asm_exists_tac >> gs[]
QED
Theorem apply_distributivity_local_plan:
apply_distributivity_local cfg e = SOME ((eOpt, res), plan) ∧
MEM (Apply (path, rws)) plan ∧
MEM rw rws ⇒
MEM (Apply (path, rws)) (SND (canonicalize_for_distributivity cfg e))∨
MEM rw [fp_comm_gen FP_Mul;
fp_distribute_gen FP_Mul FP_Add; fp_distribute_gen FP_Mul FP_Sub;
fp_distribute_gen FP_Div FP_Add; fp_distribute_gen FP_Div FP_Sub]
Proof
gs[apply_distributivity_local_def]
>> Cases_on ‘canonicalize_for_distributivity cfg e’ >> gs[CaseEq"exp", CaseEq"list", CaseEq"op"]
>> rpt strip_tac >> rveq >> gs[MEM_APPEND]
>> qpat_x_assum `_ = SOME _` mp_tac
>> COND_CASES_TAC >> gs[]
>> rpt strip_tac >> rveq >> gs[MEM_APPEND]
QED
val simple_case_tac =
last_x_assum $ mp_then Any mp_tac apply_distributivity_local_plan
>> rpt $ disch_then drule >> rpt strip_tac >> gs[]
>> first_x_assum $ mp_then Any mp_tac canonicalize_for_distributivity_upper_bound
>> disch_then drule >> gs[];
Theorem apply_distributivity_upper_bound:
∀ e path rws cfg.
MEM (Apply (path, rws)) (SND (apply_distributivity cfg e)) ⇒
∀ rw. MEM rw rws ⇒
MEM rw [fp_comm_gen FP_Mul;
fp_distribute_gen FP_Mul FP_Add; fp_distribute_gen FP_Mul FP_Sub;
fp_distribute_gen FP_Div FP_Add; fp_distribute_gen FP_Div FP_Sub;
fp_assoc2_gen FP_Add; fp_comm_gen FP_Mul; fp_assoc_gen FP_Mul;
fp_assoc2_gen FP_Mul]
Proof
qmatch_goalsub_abbrev_tac ‘MEM _ distrib_rws’
>> simp[Once apply_distributivity_def]
>> rpt gen_tac
>> qmatch_goalsub_abbrev_tac ‘MEM _ (SND (post_order_dfs_for_plan distributivity_app cfg e))’
>> rpt strip_tac
>> qspecl_then [‘distributivity_app’, ‘cfg’, ‘e’,
‘λ rws. ∀ rw. MEM rw rws ⇒ MEM rw distrib_rws’]
mp_tac postorder_upper_bound
>> gs[]
>> reverse impl_tac
>- (
Cases_on ‘post_order_dfs_for_plan distributivity_app cfg e’ >> gs[]
>> rpt $ disch_then drule >> gs[])
>> unabbrev_all_tac
>> rpt $ pop_assum kall_tac
>> rpt strip_tac
>> gs[CaseEq"exp", CaseEq"option", CaseEq"prod"] >> rveq
>~ [‘App op es’]
>- (
gs[CaseEq"op", CaseEq"option", CaseEq"prod", CaseEq"fp_bop", CaseEq"list",
CaseEq"exp"]
>> rveq >> gs[]
>> TRY (simple_case_tac >> NO_TAC)
>> Cases_on ‘canonicalize_for_distributivity cfg' e2_2’
>> Cases_on ‘canonicalize_for_distributivity cfg' (App (FP_bop FP_Add) [e1; e2_1])’
>> gs[CaseEq"option", CaseEq"prod"] >> rveq >> gs[]
>- simple_case_tac
>- (
Cases_on ‘canonicalize_for_distributivity cfg' (App (FP_bop FP_Add) [e1_can_dist; q])’
>> gs[CaseEq"option", CaseEq"prod"] >> rveq >> gs[]
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac canonicalize_for_distributivity_upper_bound_alt
>> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac canonicalize_for_distributivity_upper_bound_alt
>> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> simple_case_tac)
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac canonicalize_for_distributivity_upper_bound_alt
>> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac canonicalize_for_distributivity_upper_bound_alt
>> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> first_x_assum $ mp_then Any mp_tac apply_distributivity_local_plan
>> rpt $ disch_then drule >> rpt strip_tac >> gs[]
>> first_x_assum $ mp_then Any mp_tac canonicalize_for_distributivity_upper_bound
>> disch_then drule >> gs[])
>- (imp_res_tac canonicalize_for_distributivity_upper_bound_alt >> gs[])
>> qpat_x_assum ‘apply_distributivity_local _ (App _ _) = SOME _’
$ mp_then Any mp_tac apply_distributivity_local_plan
>> rpt $ disch_then drule >> rpt strip_tac >> gs[]
>> first_x_assum $ mp_then Any mp_tac canonicalize_for_distributivity_upper_bound_alt
>> rpt $ disch_then drule >> gs[])
>> Cases_on ‘canonicalize_for_distributivity cfg' (App (FP_bop FP_Add) [e1_can_dist; e2_can_dist])’
>> gs[CaseEq"option", CaseEq"prod"] >> rveq >> gs[]
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac canonicalize_for_distributivity_upper_bound_alt
>> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac canonicalize_for_distributivity_upper_bound_alt
>> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> first_x_assum $ mp_then Any mp_tac apply_distributivity_local_plan
>> rpt $ disch_then drule >> rpt strip_tac >> gs[]
>> first_x_assum $ mp_then Any mp_tac canonicalize_for_distributivity_upper_bound
>> disch_then drule >> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> first_x_assum $ mp_then Any mp_tac apply_distributivity_local_plan
>> rpt $ disch_then drule >> rpt strip_tac >> gs[]
>> first_x_assum $ mp_then Any mp_tac canonicalize_for_distributivity_upper_bound
>> disch_then drule >> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac canonicalize_for_distributivity_upper_bound_alt
>> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> qpat_x_assum `canonicalize_for_distributivity _ _ = (_, r)` $
mp_then Any mp_tac canonicalize_for_distributivity_upper_bound_alt
>> rpt $ disch_then drule >> rpt strip_tac >> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> first_x_assum $ mp_then Any mp_tac apply_distributivity_local_plan
>> rpt $ disch_then drule >> rpt strip_tac >> gs[]
>> first_x_assum $ mp_then Any mp_tac canonicalize_for_distributivity_upper_bound
>> disch_then drule >> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> last_x_assum $ mp_then Any mp_tac apply_distributivity_local_plan
>> disch_then kall_tac
>> last_x_assum $ mp_then Any mp_tac apply_distributivity_local_plan
>> rpt $ disch_then drule >> rpt strip_tac >> gs[]
>> first_x_assum $ mp_then Any mp_tac canonicalize_for_distributivity_upper_bound
>> disch_then drule >> gs[])
>- (
imp_res_tac MEM_MAP_plan_to_path_index
>> imp_res_tac canonicalize_for_distributivity_upper_bound_alt
>> gs[])
>> qpat_x_assum ‘apply_distributivity_local _ (App _ _) = SOME _’
$ mp_then Any mp_tac apply_distributivity_local_plan
>> rpt $ disch_then drule >> rpt strip_tac >> gs[]
>> first_x_assum $ mp_then Any mp_tac canonicalize_for_distributivity_upper_bound_alt
>> disch_then drule >> gs[])
>> simple_case_tac
QED
Theorem balance_expression_tree_upper_bound:
MEM (Apply (path, rws)) (SND(balance_expression_tree cfg e)) ⇒
∀ rw.
MEM rw rws ⇒
MEM rw [fp_assoc2_gen FP_Add ; fp_assoc2_gen FP_Mul]
Proof
simp[Once balance_expression_tree_def]
>> rpt gen_tac
>> qmatch_goalsub_abbrev_tac ‘MEM _ (SND (post_order_dfs_for_plan balance_app cfg e))’
>> rpt strip_tac
>> qspecl_then [‘balance_app’, ‘cfg’, ‘e’,
‘λ rws. ∀ rw. MEM rw rws ⇒ MEM rw [fp_assoc2_gen FP_Add; fp_assoc2_gen FP_Mul]’]
mp_tac postorder_upper_bound
>> gs[]
>> reverse impl_tac
>- (
Cases_on ‘post_order_dfs_for_plan balance_app cfg e’ >> gs[]
>> rpt $ disch_then drule >> gs[])
>> unabbrev_all_tac >> rpt $ pop_assum kall_tac
>> gs[CaseEq"exp", CaseEq"op", CaseEq"fp_bop", CaseEq"list"]
>> rpt strip_tac >> gs[]
QED
Theorem rewriteFPexp_weakening:
(∀ rw. MEM rw rws2 ⇒
∀ (st1:'a semanticPrimitives$state) st2 env e r.
is_rewriteFPexp_correct [rw] st1 st2 env e r) ∧
(∀ rw. MEM rw rws1 ⇒ MEM rw rws2) ⇒
∀ (st1:'a semanticPrimitives$state) st2 env e r.
is_rewriteFPexp_correct rws1 st1 st2 env e r
Proof
Induct_on ‘rws1’ >> gs[empty_rw_correct]
>> rpt strip_tac
>> ‘h :: rws1 = [h] ++ rws1’ by gs[]
>> pop_assum $ rewrite_tac o single
>> irule rewriteExp_compositional >> reverse conj_tac
>- (
first_x_assum $ qspec_then ‘h’ mp_tac >> gs[] >> strip_tac
>> first_x_assum drule >> gs[])
>> last_x_assum irule
>> conj_tac >> gs[]
QED
Theorem is_real_id_exp_weakening:
(∀ rw. MEM rw rws2 ⇒
∀ (st1:'a semanticPrimitives$state) st2 env e r.
is_real_id_exp [rw] st1 st2 env e r) ∧
(∀ rw. MEM rw rws1 ⇒ MEM rw rws2) ⇒
∀ (st1:'a semanticPrimitives$state) st2 env e r.
is_real_id_exp rws1 st1 st2 env e r
Proof
Induct_on ‘rws1’ >> gs[empty_rw_real_id]
>> rpt strip_tac
>> ‘h :: rws1 = [h] ++ rws1’ by gs[]
>> pop_assum $ rewrite_tac o single
>> irule real_valued_id_compositional >> reverse conj_tac
>- (
first_x_assum $ qspec_then ‘h’ mp_tac >> gs[] >> strip_tac
>> first_x_assum drule >> gs[])
>> last_x_assum irule
>> conj_tac >> gs[]
QED
Theorem optPlanner_correct_float_single:
∀ e st1 st2 env cfg exps r.
is_optimise_with_plan_correct (generate_plan_exp cfg e) st1 st2 env cfg exps r
Proof
rpt strip_tac
>> irule is_optimise_with_plan_correct_lift
>> rpt gen_tac >> strip_tac
>> irule is_rewriteFPexp_correct_lift_perform_rewrites
>> irule lift_rewriteFPexp_correct_list
>> first_x_assum $ mp_then Any assume_tac generate_plan_upper_bound_rws
>> gs[]
>> imp_res_tac balance_expression_tree_upper_bound
>> imp_res_tac canonicalize_upper_bound
>> imp_res_tac apply_distributivity_upper_bound
>> imp_res_tac peephole_optimise_upper_bound
>> irule rewriteFPexp_weakening >> asm_exists_tac >> gs[]
>> rpt strip_tac >> rveq
>> gs[fp_times_two_to_add_correct_unfold, fp_times_two_to_add_correct,
fp_times_three_to_add_correct_unfold, fp_times_three_to_add_correct,
fp_times_one_correct_unfold, fp_times_one_correct,
fp_times_minus_one_neg_correct_unfold,
fp_times_minus_one_neg_correct, fp_sub_add_correct_unfold,
fp_sub_add_correct, fp_plus_zero_correct_unfold,
fp_plus_zero_correct, fp_neg_times_minus_one_correct_unfold,
fp_neg_times_minus_one_correct, fp_neg_push_mul_r_correct_unfold,
fp_neg_push_mul_r_correct, fp_fma_intro_correct_unfold,
fp_fma_intro_correct, fp_distribute_gen_correct_unfold_add,
fp_distribute_gen_correct_unfold, fp_distribute_gen_correct,
fp_comm_gen_correct_unfold_mul, fp_comm_gen_correct_unfold_add,
fp_comm_gen_correct_unfold, fp_comm_gen_correct,
fp_assoc_gen_correct_unfold_mul, fp_assoc_gen_correct_unfold_add,
fp_assoc_gen_correct_unfold, fp_assoc_gen_correct,
fp_assoc2_gen_correct_unfold_mul, fp_assoc2_gen_correct_unfold_add,
fp_assoc2_gen_correct_unfold, fp_assoc2_gen_correct,
fp_add_sub_correct_unfold, fp_add_sub_correct,
reverse_tuple_def, fp_undistribute_gen_def, fp_times_zero_def,
fp_times_two_to_add_def, fp_times_three_to_add_def,
fp_times_one_def,
fp_times_minus_one_neg_def, fp_times_into_div_def, fp_sub_add_def,
fp_same_sub_def, fp_plus_zero_def,
fp_neg_times_minus_one_def, fp_neg_push_mul_r_def,
fp_mul_sub_undistribute_def, fp_mul_sub_distribute_def,
fp_mul_comm_def, fp_mul_assoc_def, fp_mul_assoc2_def,
fp_mul_add_undistribute_def, fp_mul_add_distribute_def,
fp_fma_intro_def, fp_div_sub_undistribute_def,
fp_div_sub_distribute_def, fp_div_add_undistribute_def,
fp_div_add_distribute_def, fp_distribute_gen_def, fp_comm_gen_def,
fp_assoc_gen_def, fp_assoc2_gen_def, fp_add_sub_def,
fp_add_comm_def, fp_add_assoc_def, fp_add_assoc2_def,
fp_times_zero_correct, fp_same_sub_correct]
QED
Theorem optPlanner_correct_real_single:
∀ e st1 st2 env cfg exps r.
is_real_id_optimise_with_plan (generate_plan_exp cfg e) st1 st2 env cfg exps r
Proof
rpt gen_tac
>> irule is_real_id_perform_rewrites_optimise_with_plan_lift
>> rpt gen_tac >> strip_tac
>> irule is_real_id_list_perform_rewrites_lift
>> irule lift_real_id_exp_list_strong
>> first_x_assum $ mp_then Any assume_tac generate_plan_upper_bound_rws
>> gs[]
>> imp_res_tac balance_expression_tree_upper_bound
>> imp_res_tac canonicalize_upper_bound
>> imp_res_tac apply_distributivity_upper_bound
>> imp_res_tac peephole_optimise_upper_bound
>> irule is_real_id_exp_weakening >> asm_exists_tac >> gs[]
>> rpt strip_tac >> rveq
>> gs[fp_times_two_to_add_real_id_unfold, fp_times_two_to_add_real_id,
fp_times_three_to_add_real_id_unfold, fp_times_three_to_add_real_id,
fp_times_one_real_id_unfold, fp_times_one_real_id,
fp_times_minus_one_neg_real_id_unfold,
fp_times_minus_one_neg_real_id, fp_sub_add_real_id_unfold,
fp_sub_add_real_id, fp_plus_zero_real_id_unfold,
fp_plus_zero_real_id, fp_neg_times_minus_one_real_id_unfold,
fp_neg_times_minus_one_real_id, fp_neg_push_mul_r_real_id_unfold,
fp_neg_push_mul_r_real_id, fma_intro_real_id,
fma_intro_real_id, fp_distribute_gen_real_id_unfold,
Q.SPECL [‘FP_Sub’, ‘FP_Mul’] fp_distribute_gen_real_id,
Q.SPECL [‘FP_Add’, ‘FP_Div’] fp_distribute_gen_real_id,
Q.SPECL [‘FP_Sub’, ‘FP_Div’] fp_distribute_gen_real_id,
fp_comm_gen_real_id_unfold_mul, fp_comm_gen_real_id_unfold_add,
Q.SPEC ‘FP_Sub’ fp_comm_gen_real_id, fp_assoc_gen_real_id_unfold_mul,
fp_assoc_gen_real_id_unfold_add, fp_assoc_gen_real_id,
fp_assoc2_gen_real_id_unfold_mul, fp_assoc2_gen_real_id_unfold_add,
fp_assoc2_gen_real_id, fp_add_sub_real_id_unfold, fp_add_sub_real_id,
reverse_tuple_def, fp_undistribute_gen_def, fp_times_zero_def,
fp_times_two_to_add_def, fp_times_three_to_add_def,
fp_times_one_def,
fp_times_minus_one_neg_def, fp_times_into_div_def, fp_sub_add_def,
fp_same_sub_def, fp_plus_zero_def,
fp_neg_times_minus_one_def, fp_neg_push_mul_r_def,
fp_mul_sub_undistribute_def, fp_mul_sub_distribute_def,
fp_mul_comm_def, fp_mul_assoc_def, fp_mul_assoc2_def,
fp_mul_add_undistribute_def, fp_mul_add_distribute_def,
fp_fma_intro_def, fp_div_sub_undistribute_def,
fp_div_sub_distribute_def, fp_div_add_undistribute_def,
fp_div_add_distribute_def, fp_distribute_gen_def, fp_comm_gen_def,
fp_assoc_gen_def, fp_assoc2_gen_def, fp_add_sub_def,
fp_add_comm_def, fp_add_assoc_def, fp_add_assoc2_def,
fp_times_zero_real_id, fp_same_sub_real_id]
QED
val _ = export_theory();