-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompArith.thy
1960 lines (1629 loc) · 90.5 KB
/
CompArith.thy
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
theory CompArith
imports Main CompArithDefs
begin
(* Lemma 1.2 *)
lemma lemma_1_2 :
fixes x :: "bool list"
assumes "length x > 0" and "\<sigma> x = True"
shows "\<lparr> x \<rparr> < 0"
using assms proof (induct x)
case Nil
then show ?case by simp
next
case (Cons x xs)
then have subst: "x = True" unfolding sigma_def by simp
show ?case unfolding subst unfolding seval.simps
apply simp
apply (rule le_less_trans)
apply (rule ueval_upper_bound)
by simp
qed
(* Lemma 1.4 *)
lemma lemma_1_4_1 :
fixes k :: nat
assumes "length x = Suc k"
shows "length x = length y \<Longrightarrow> \<lbrakk> x \<rbrakk> = \<lbrakk> y \<rbrakk> \<Longrightarrow> x = y"
apply (induct x y rule: List.list_induct2)
apply simp
apply(case_tac x; case_tac y, simp_all)
by (metis not_add_less1 ueval_upper_bound3)+
lemma lemma_1_4_2 :
fixes k :: nat
assumes "length x = Suc k"
shows "length x = length y \<Longrightarrow> \<lparr> x \<rparr> = \<lparr> y \<rparr> \<Longrightarrow> x = y"
apply (induct x y rule: List.list_induct2)
apply simp
apply(case_tac x; case_tac y, simp_all)
using lemma_1_4_1 apply (metis Nitpick.size_list_simp(2))
apply (metis diff_gt_0_iff_gt less_imp_of_nat_less minus_diff_eq not_int_zless_negative of_nat_less_numeral_power_cancel_iff pos_int_cases ueval_upper_bound3)
apply (metis of_nat_less_0_iff less_iff_diff_less_0 numeral_power_eq_of_nat_cancel_iff of_nat_less_iff ueval_upper_bound3)
by (metis Nitpick.size_list_simp(2) lemma_1_4_1)
(* Lemma 2.1 *)
lemma lem_2_1 :
fixes a_i b_i c_i :: "bool"
defines c_suci_def: "c_suci \<equiv> \<lbrakk>(\<lbrakk>a_i\<rbrakk>\<^sub>N + \<lbrakk>b_i\<rbrakk>\<^sub>N + \<lbrakk>c_i\<rbrakk>\<^sub>N) div 2\<rbrakk>\<^sub>B"
and r_i_def: "r_i \<equiv> \<lbrakk>(\<lbrakk>a_i\<rbrakk>\<^sub>N + \<lbrakk>b_i\<rbrakk>\<^sub>N + \<lbrakk>c_i\<rbrakk>\<^sub>N) mod 2\<rbrakk>\<^sub>B"
shows "\<lbrakk>a_i\<rbrakk>\<^sub>N + \<lbrakk>b_i\<rbrakk>\<^sub>N + \<lbrakk>c_i\<rbrakk>\<^sub>N = 2 * (\<lbrakk>c_suci\<rbrakk>\<^sub>N) + \<lbrakk>r_i\<rbrakk>\<^sub>N"
unfolding c_suci_def r_i_def by (cases a_i; cases b_i; cases c_i, simp_all)
(* Theorem 3.1 *)
(* 1: done *)
(* 1 \<longleftrightarrow> 3 : done *)
(* 2 \<longleftrightarrow> 4 : done *)
(* 1 \<longleftrightarrow> 2 : done *)
lemma thm_3_1_1 :
fixes a b :: "bool list"
shows "length a = length b \<Longrightarrow> \<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk>a +\<^sub>Z\<^sub>A b\<rbrakk>"
unfolding uplus_def
apply (subst plus_DA , simp)
proof (induct a b rule: List.list_induct2)
case Nil
thus ?case by simp
next
case (Cons a as b bs)
have subst1: "\<And> a b as bs :: nat. a + as + (b + bs) = a + b + (as + bs)" by simp
show ?case unfolding ueval.simps Cons(1)
apply (subst DAplus_eq_len , simp add: Cons)
apply (subst subst1)
unfolding DAplus.simps prod.sel(1) prod.sel(2) to_from_div_id3 to_from_mod_id3 ueval.simps Cons(2)
apply (subst DAplus_eq_len , simp add: Cons)+
apply (induct a ; induct b ; induct "(snd (DAplus as bs))")
by simp+
qed
lemma thm_3_1_1_alt :
fixes a_k b_k :: "bool" and as bs :: "bool list"
defines a_def: "a \<equiv> a_k # as" and b_def: "b \<equiv> b_k # bs"
assumes len_eq: "length as = length bs"
shows "\<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk>a +\<^sub>Z\<^sub>A b\<rbrakk>"
unfolding a_def b_def
using len_eq
proof (induct as bs arbitrary: a_k b_k rule: List.list_induct2)
case Nil
thus ?case unfolding uplus_def DAplus.simps
by (cases a_k; cases b_k; simp_all)
next
case (Cons a_km1 as b_km1 bs)
define ak ("a\<^sup>k") where ak_def[simp]: "a\<^sup>k = a_km1 # as"
define bk ("b\<^sup>k") where bk_def[simp]: "b\<^sup>k = b_km1 # bs"
define a b where a_def: "a = a_k # a\<^sup>k" and b_def: "b = b_k # b\<^sup>k"
define b_km1' ("b\<^sup>k\<^sup>-\<^sup>1") where "b\<^sup>k\<^sup>-\<^sup>1 = b_km1"
define rk ("r\<^sup>k") where rk_def: "r\<^sup>k = fst (DA\<^sup>+ a\<^sup>k b\<^sup>k)"
define c_kp1 ("c\<^sub>k\<^sub>+\<^sub>1") where c_kp1_def: "c\<^sub>k\<^sub>+\<^sub>1 = snd (DA\<^sup>+ a\<^sup>k b\<^sup>k)"
define r_kp1 ("r\<^sub>k\<^sub>+\<^sub>1") where r_kp1_def: "r\<^sub>k\<^sub>+\<^sub>1 = \<lbrakk> (\<lbrakk> a_k \<rbrakk>\<^sub>N + \<lbrakk> b_k \<rbrakk>\<^sub>N + \<lbrakk> c\<^sub>k\<^sub>+\<^sub>1 \<rbrakk>\<^sub>N) mod 2 \<rbrakk>\<^sub>B"
define c_kp2 ("c\<^sub>k\<^sub>+\<^sub>2") where c_kp2_def: "c\<^sub>k\<^sub>+\<^sub>2 = \<lbrakk> (\<lbrakk> a_k \<rbrakk>\<^sub>N + \<lbrakk> b_k \<rbrakk>\<^sub>N + \<lbrakk> c\<^sub>k\<^sub>+\<^sub>1 \<rbrakk>\<^sub>N) div 2 \<rbrakk>\<^sub>B"
have len_ak_eq_bk: "length a\<^sup>k = length b\<^sup>k" unfolding ak_def bk_def using Cons(1) by simp
have len_bk: "length b\<^sup>k = length r\<^sup>k" unfolding rk_def ak_def bk_def by (subst DAplus_eq_len, simp_all add: Cons)
from Cons have ih: "\<lbrakk> a\<^sup>k \<rbrakk> + \<lbrakk> b\<^sup>k \<rbrakk> = \<lbrakk> a\<^sup>k +\<^sub>Z\<^sub>A b\<^sup>k \<rbrakk>" by simp
then have ih': "\<lbrakk> a\<^sup>k \<rbrakk> + \<lbrakk> b\<^sup>k \<rbrakk> = \<lbrakk> c\<^sub>k\<^sub>+\<^sub>1 # r\<^sup>k \<rbrakk>"
unfolding rk_def c_kp1_def uplus_def DAplus.simps bool2nat.simps add_0 fst_conv snd_conv to_from_mod_id by simp
show "\<lbrakk> a \<rbrakk> + \<lbrakk> b \<rbrakk> = \<lbrakk> a +\<^sub>Z\<^sub>A b \<rbrakk>"
unfolding a_def b_def uplus_def DAplus.simps fst_conv snd_conv rk_def[symmetric] c_kp1_def[symmetric] bool2nat.simps add_0
r_kp1_def[symmetric] c_kp2_def[symmetric] to_from_mod_id ueval.simps
apply(subst semiring_normalization_rules(20))
apply (subst ih')
unfolding ueval.simps len_ak_eq_bk len_bk apply simp
unfolding semiring_normalization_rules(1) semiring_normalization_rules(18) apply(rule mult_right_cancel[THEN iffD2], simp)
unfolding c_kp2_def r_kp1_def
by (cases a_k; cases b_k; cases "c\<^sub>k\<^sub>+\<^sub>1", simp_all)
qed
lemma thm_3_1_1_iff_3 : "(\<forall>a b. length a = length b \<longrightarrow> \<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk>a +\<^sub>Z\<^sub>A b\<rbrakk>) \<longleftrightarrow> (\<forall>a b. length a = length b \<longrightarrow> \<lparr>a\<rparr> + \<lparr>b\<rparr> = \<lparr>a +\<^sub>S\<^sub>A b\<rparr>)"
apply rule+
apply (case_tac a ; case_tac b)
unfolding splus.simps apply (simp , simp , simp)
defer
apply rule+
proof goal_cases
case (1 a b)
then have "length (False # a) = length (False # b)" by simp
with 1 have subst2: "\<lparr> False # a \<rparr> + \<lparr> False # b \<rparr> = \<lparr> (False # a) +\<^sub>S\<^sub>A (False # b) \<rparr>" by blast
show ?case
apply (rule int_int_eq[THEN subst])
apply simp
apply (subst eval_eq_seval , subst eval_eq_seval)
apply (subst subst2)
unfolding seval.simps splus.simps list.sel(1)
apply simp
apply (subst to_from_mod_id)+
apply (subst to_from_div_False)
unfolding uplus_def DAplus.simps bool2nat.simps
apply simp
apply (subst to_from_mod_id)
by simp
next
case (2 xs ys a as b bs)
then have subst2: "length as = length bs" by simp
have subst1: "\<And> a b as bs :: int. a + as + (b + bs) = a + b + (as + bs)" by simp
show ?case
unfolding 2 seval.simps
apply (subst subst1)
apply (subst nat_transfer(1))
apply (subst 2(1))
using 2 apply simp
unfolding uplus_def splus.simps list.sel(1) DAplus.simps prod.sel
apply simp
unfolding to_from_div_id3 to_from_mod_id3 subst2
apply(subst to_from_mod_id)+
apply(subst to_from_mod_id2)
apply(subst DAplus_eq_len , simp add:subst2)+
apply(cases a ; cases b ; cases "snd (DA\<^sup>+ as bs)")
by auto
qed
lemma thm_3_1_3: "length a = length b \<Longrightarrow> \<lparr>a\<rparr> + \<lparr>b\<rparr> = \<lparr>a +\<^sub>S\<^sub>A b\<rparr>" using thm_3_1_1_iff_3 thm_3_1_1 by simp
lemma thm_3_1_2_iff_4 : "(\<forall>a b. length a = length b \<longrightarrow> int \<lbrakk>a\<rbrakk> - int \<lbrakk>b\<rbrakk> = \<lparr>a -\<^sub>Z\<^sub>A b\<rparr>) \<longleftrightarrow>
(\<forall>a b. length a = length b \<longrightarrow> \<lparr>a\<rparr> - \<lparr>b\<rparr> = \<lparr>a -\<^sub>S\<^sub>A b\<rparr>)"
apply rule+
apply (case_tac a ; case_tac b)
unfolding sminus.simps apply (simp , simp , simp)
defer
apply rule+
proof goal_cases
case (1 a b)
then have "length (False # a) = length (False # b)" by simp
with 1 have subst1: "\<lparr> False # a \<rparr> - \<lparr> False # b \<rparr> = \<lparr> (False # a) -\<^sub>S\<^sub>A (False # b) \<rparr>" by blast
show ?case
apply (subst eval_eq_seval , subst eval_eq_seval)
apply (subst subst1)
unfolding seval.simps sminus.simps list.sel(1) uminus_def
apply simp
apply (cases "snd (DA\<^sup>- a b)")
by simp_all
next
case (2 xs ys a as b bs)
then have subst2: "length as = length bs" by simp
have subst1: "\<And> a b as bs :: int. - a + as - (- b + bs) = - a + b + (as - bs)" by simp
show ?case
unfolding 2 seval.simps
apply (subst subst1)
apply (subst 2(1))
using 2 apply simp
unfolding uminus_def sminus.simps list.sel(1) DAminus.simps prod.sel apply simp
apply(subst DAminus_eq_len , simp add:subst2)+
unfolding to_from_div_id3 to_from_mod_id3 subst2
apply(cases a ; cases b ; cases "snd (DA\<^sup>- as bs)")
by auto
qed
lemma thm_3_1_1_iff_2 : "(\<forall>a b. length a = length b \<longrightarrow> \<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk>a +\<^sub>Z\<^sub>A b\<rbrakk>) \<longleftrightarrow>
(\<forall>a b. length a = length b \<longrightarrow> int \<lbrakk>a\<rbrakk> - int \<lbrakk>b\<rbrakk> = \<lparr>a -\<^sub>Z\<^sub>A b\<rparr>)"
apply rule+
defer
apply rule+
proof goal_cases
case (2 a b)
have subst1: "\<And> a b c :: int. a = c + b \<Longrightarrow> a - b = c" by simp
have subst2: "\<And> a b c :: int. a + c + b = a + (c + b)" by simp
from 2(1) have subst3: "\<forall>a b. length a = length b \<longrightarrow> int \<lbrakk> a \<rbrakk> + int \<lbrakk> b \<rbrakk> = int \<lbrakk> a +\<^sub>Z\<^sub>A b \<rbrakk>"
by fastforce
have 4: "length a = length b \<Longrightarrow> fst (DA\<^sup>+ (fst (DA\<^sup>- a b)) b) = a"
apply (induct a b rule:List.list_induct2)
apply simp
apply (case_tac x ; case_tac y)
apply simp_all
by (subst DAplus_DAminus_compl, simp, case_tac "snd (DA\<^sup>- xs ys)", simp, simp)+
show ?case
apply (rule subst1)
unfolding uminus_def DAminus.simps prod.sel seval.simps
apply (subst subst2)
apply (subst subst3)
using DAminus_eq_len 2
apply simp
apply(subst DAminus_eq_len , simp add:2(2))+
apply simp
unfolding uplus_def DAplus.simps
apply simp
apply(subst DAplus_eq_len)
apply(subst DAminus_eq_len)
using 2 apply simp
apply simp
apply (subst DAplus_DAminus_compl)
using 2 apply simp
apply (cases "snd (DA\<^sup>- a b)")
apply simp_all
using 4 2 by simp+
next
case (1 a b)
have subst1: "\<And> a b c :: nat. int a + int b = int c \<Longrightarrow> a + b = c" by simp
have subst2: "\<And> a b c :: int. a = c - b \<Longrightarrow> a + b = c" by simp
have subst3: "\<And> a b. int \<lbrakk> b \<rbrakk> = int \<lbrakk> (False # b) \<rbrakk>" by simp
have 2: "length a = length b \<Longrightarrow> fst (DA\<^sup>- (fst (DA\<^sup>+ a b)) b) = a"
apply (induct a b rule:List.list_induct2)
apply simp
apply (case_tac x ; case_tac y)
apply simp_all
by (subst DAminus_DAplus_compl, simp, case_tac "snd (DA\<^sup>+ xs ys)", simp, simp)+
show ?case
apply (subst subst1, simp_all)
apply (subst subst2, simp_all)
apply (subst(3) subst3)
apply(subst 1(1))
unfolding uplus_def apply(rule DAplus_eq_len)
using 1 apply simp
unfolding uminus_def DAminus.simps prod.sel seval.simps
apply(subst DAminus_eq_len, subst DAplus_eq_len, simp add:1, simp)
unfolding not_False_eq_True bool2nat.simps DAplus.simps DAminus.simps prod.sel
apply simp
apply(subst DAminus_eq_len, subst DAplus_eq_len, simp add:1, simp)
apply(subst DAminus_DAplus_compl, simp add: 1)+
apply(cases "snd (DA\<^sup>+ a b)")
using 1 2 by simp+
qed
lemma thm_3_1_2: "length a = length b \<Longrightarrow> int \<lbrakk>a\<rbrakk> - int \<lbrakk>b\<rbrakk> = \<lparr>a -\<^sub>Z\<^sub>A b\<rparr>" using thm_3_1_1_iff_2 thm_3_1_1 by simp
lemma thm_3_1_4: "length a = length b \<Longrightarrow> \<lparr>a\<rparr> - \<lparr>b\<rparr> = \<lparr>a -\<^sub>S\<^sub>A b\<rparr>" using thm_3_1_1_iff_2 thm_3_1_2_iff_4 thm_3_1_1 by simp
(* Theorem 3.2 *)
(* 4 \<longleftrightarrow> 3 : done *)
(* 3 \<longleftrightarrow> 5 : done *)
(* 1 \<longleftrightarrow> 4 : done *)
(* 1 \<longleftrightarrow> 2 : done *)
lemma thm_3_2_4_iff_3 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) +\<^sub>A (b#bs))"
shows "snd (DA\<^sup>+ (a#as) (b#bs)) = \<bottom> \<longleftrightarrow>
(triple' \<bottom> \<bottom> \<bottom> \<or> triple' \<bottom> \<bottom> \<top> \<or> triple' \<bottom> \<top> \<top> \<or> triple' \<top> \<bottom> \<top>)"
apply rule
unfolding triple'_def triple_def tplus_def
by (cases a; cases b; cases "snd (DA\<^sup>+ as bs)", simp_all)+
lemma thm_3_2_3_iff_5 :
fixes ak bk :: bool and as bs :: "bool list"
assumes "length (ak # as) = length (bk # bs)"
defines "triple' x y z \<equiv> triple x y z (ak # as) (bk # bs) ((ak # as) +\<^sub>A (bk # bs))" and
"rk \<equiv> hd ((ak # as) +\<^sub>A (bk # bs))"
shows "\<lbrakk>ak\<rbrakk>\<^sub>Z + \<lbrakk>bk\<rbrakk>\<^sub>Z - \<lbrakk>rk\<rbrakk>\<^sub>Z = 0 \<or> \<lbrakk>ak\<rbrakk>\<^sub>Z + \<lbrakk>bk\<rbrakk>\<^sub>Z - \<lbrakk>rk\<rbrakk>\<^sub>Z = -1 \<longleftrightarrow>
(triple' \<bottom> \<bottom> \<bottom> \<or> triple' \<bottom> \<bottom> \<top> \<or> triple' \<bottom> \<top> \<top> \<or> triple' \<top> \<bottom> \<top>)"
apply rule
unfolding triple'_def triple_def rk_def[symmetric] list.sel(1)
by(cases ak; cases bk; cases rk, simp_all)+
lemma thm_3_2_1_iff_4 :
"length a = length b \<Longrightarrow>
\<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk>a +\<^sub>A b\<rbrakk> \<longleftrightarrow> snd (DA\<^sup>+ a b) = False"
apply rule
apply (rule ccontr)
proof goal_cases
case 1
then have 2: "snd (DA\<^sup>+ a b) = True" by simp
have "\<lbrakk> a \<rbrakk> + \<lbrakk> b \<rbrakk> = \<lbrakk> a +\<^sub>Z\<^sub>A b \<rbrakk>" using thm_3_1_1 1 by simp
with 1 have "\<lbrakk> a +\<^sub>A b \<rbrakk> = \<lbrakk> a +\<^sub>Z\<^sub>A b \<rbrakk>" by simp
with 1 have "\<lbrakk> fst (DA\<^sup>+ a b) \<rbrakk> = \<lbrakk> snd (DA\<^sup>+ a b) # fst (DA\<^sup>+ a b) \<rbrakk>"
unfolding uplus_def tplus_def using plus_DA by presburger
with 2 have "\<lbrakk> fst (DA\<^sup>+ a b) \<rbrakk> = \<lbrakk> True # fst (DA\<^sup>+ a b) \<rbrakk>" by simp
then show ?case by simp
next
case 2
have "\<lbrakk> a \<rbrakk> + \<lbrakk> b \<rbrakk> = \<lbrakk> a +\<^sub>Z\<^sub>A b \<rbrakk>" using thm_3_1_1 2 by simp
then have "\<lbrakk> a \<rbrakk> + \<lbrakk> b \<rbrakk> = \<lbrakk> snd (DA\<^sup>+ a b) # fst (DA\<^sup>+ a b) \<rbrakk>"
unfolding uplus_def using 2 plus_DA by presburger
with 2 have "\<lbrakk> a \<rbrakk> + \<lbrakk> b \<rbrakk> = \<lbrakk> False # fst (DA\<^sup>+ a b) \<rbrakk>" by simp
then show ?case unfolding tplus_def ueval.simps bool2nat.simps by simp
qed
lemma thm_3_2_1_iff_2 :
"length a = length b \<Longrightarrow>
\<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk>a +\<^sub>A b\<rbrakk> \<longleftrightarrow> (0 \<le> \<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> \<and> \<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> \<le> 2 ^ (length a) - 1)"
apply rule+
proof goal_cases
case 1
show ?case unfolding 1
apply(rule ueval_upper_bound2)
unfolding tplus_def apply (rule DAplus_eq_len)
using 1 by simp
next
case 2
then have 3: "\<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> \<le> 2 ^ length a - 1" by simp
have "\<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk> a +\<^sub>Z\<^sub>A b \<rbrakk>" using thm_3_1_1 2 by simp
with 3 have "\<lbrakk>a +\<^sub>Z\<^sub>A b\<rbrakk> \<le> 2 ^ length a - 1" by simp
then have "\<lbrakk> snd (DA\<^sup>+ a b) # fst (DA\<^sup>+ a b) \<rbrakk> \<le> 2 ^ length a - 1"
unfolding uplus_def tplus_def using plus_DA 2 by simp
then have "\<lbrakk> snd (DA\<^sup>+ a b) \<rbrakk>\<^sub>N * 2 ^ length a + \<lbrakk> fst (DA\<^sup>+ a b) \<rbrakk> \<le> 2 ^ length a - 1"
unfolding ueval.simps using DAplus_eq_len 2 by simp
then have "snd (DA\<^sup>+ a b) = False" by (rule_tac ccontr, simp)
then show ?case
apply (subst thm_3_2_1_iff_4)
using 2 by simp_all
qed
(* Theorem 3.2 Condition Set 2 *)
(* 4 \<longleftrightarrow> 3 : done *)
(* 3 \<longleftrightarrow> 5 : done *)
(* 1 \<longleftrightarrow> 4 : done *)
(* 1 \<longleftrightarrow> 2 : done *)
lemma thm_3_2_cs2_4_iff_3 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) +\<^sub>A (b#bs))"
shows "snd (DA\<^sup>+ (a#as) (b#bs)) = \<top> \<longleftrightarrow>
(triple' \<bottom> \<top> \<bottom> \<or> triple' \<top> \<bottom> \<bottom> \<or> triple' \<top> \<top> \<bottom> \<or> triple' \<top> \<top> \<top>)"
apply rule
unfolding triple'_def triple_def tplus_def
by (cases a; cases b; cases "snd (DA\<^sup>+ as bs)", simp_all)+
lemma thm_3_2_cs2_3_iff_5 :
fixes ak bk :: bool and as bs :: "bool list"
assumes "length (ak # as) = length (bk # bs)"
defines "triple' x y z \<equiv> triple x y z (ak # as) (bk # bs) ((ak # as) +\<^sub>A (bk # bs))" and
"rk \<equiv> hd ((ak # as) +\<^sub>A (bk # bs))"
shows "\<lbrakk>ak\<rbrakk>\<^sub>Z + \<lbrakk>bk\<rbrakk>\<^sub>Z - \<lbrakk>rk\<rbrakk>\<^sub>Z = 2 \<or> \<lbrakk>ak\<rbrakk>\<^sub>Z + \<lbrakk>bk\<rbrakk>\<^sub>Z - \<lbrakk>rk\<rbrakk>\<^sub>Z = 1 \<longleftrightarrow>
(triple' \<bottom> \<top> \<bottom> \<or> triple' \<top> \<bottom> \<bottom> \<or> triple' \<top> \<top> \<bottom> \<or> triple' \<top> \<top> \<top>)"
apply rule
unfolding triple'_def triple_def rk_def[symmetric] list.sel(1)
by(cases ak; cases bk; cases rk, simp_all)+
lemma thm_3_2_cs2_1_iff_4 :
"length a = length b \<Longrightarrow>
\<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk>\<top>#(a +\<^sub>A b)\<rbrakk> \<longleftrightarrow> snd (DA\<^sup>+ a b) = \<top>"
apply rule
using thm_3_2_1_iff_4 apply fastforce
by (simp add: thm_3_1_1 tplus_def uplus_def)
lemma thm_3_2_cs2_1_iff_2 :
"length a = length b \<Longrightarrow>
\<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> = \<lbrakk>\<top>#(a +\<^sub>A b)\<rbrakk> \<longleftrightarrow> 2 ^ (length a) \<le> \<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> \<and> \<lbrakk>a\<rbrakk> + \<lbrakk>b\<rbrakk> \<le> 2 * (2 ^ (length a) - 1)"
apply rule+
apply (simp add: DAplus_eq_len tplus_def)
apply (metis add_le_mono mult_2 ueval_upper_bound)
by (metis DAplus_eq_len not_less thm_3_2_1_iff_4 thm_3_2_cs2_1_iff_4 top_unfold tplus_def ueval_upper_bound3)
(* Theorem 3.3 *)
(* 3 \<longleftrightarrow> 5 : done *)
(* 4 \<longleftrightarrow> 3 : done *)
(* 2 \<longrightarrow> 4 : done *)
(* 4 \<longrightarrow> 1 : done *)
(* 1 \<longrightarrow> 2 : done *)
lemma thm_3_3_3_iff_5 :
fixes ak bk :: bool and as bs :: "bool list"
assumes "length (ak # as) = length (bk # bs)"
defines "triple' x y z \<equiv> triple x y z (ak # as) (bk # bs) ((ak # as) +\<^sub>A (bk # bs))" and
"rk \<equiv> hd ((ak # as) +\<^sub>A (bk # bs))"
shows "-(\<lbrakk>ak\<rbrakk>\<^sub>Z) + \<lbrakk>bk\<rbrakk>\<^sub>Z - \<lbrakk>rk\<rbrakk>\<^sub>Z = 0 \<or> -(\<lbrakk>ak\<rbrakk>\<^sub>Z) + \<lbrakk>bk\<rbrakk>\<^sub>Z - \<lbrakk>rk\<rbrakk>\<^sub>Z = -1 \<longleftrightarrow>
(triple' \<bottom> \<top> \<top> \<or> triple' \<top> \<bottom> \<bottom> \<or> triple' \<bottom> \<bottom> \<top> \<or> triple' \<bottom> \<bottom> \<bottom> \<or> triple' \<top> \<top> \<top> \<or> triple' \<top> \<top> \<bottom>)"
apply rule
unfolding triple'_def triple_def rk_def[symmetric] list.sel(1)
by(cases ak; cases bk; cases rk, simp_all)+
lemma thm_3_3_4_iff_3 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) -\<^sub>A (b#bs))"
shows "snd (DA\<^sup>- (a#as) (b#bs)) \<noteq> hd (fst (DA\<^sup>- (a#as) (b#bs))) \<longleftrightarrow>
(triple' \<bottom> \<top> \<top> \<or> triple' \<top> \<bottom> \<bottom> \<or> triple' \<bottom> \<bottom> \<top> \<or> triple' \<bottom> \<bottom> \<bottom> \<or> triple' \<top> \<top> \<top> \<or> triple' \<top> \<top> \<bottom>)"
apply rule
unfolding triple'_def triple_def tminus_def
by (cases a;cases b; cases "snd (DA\<^sup>- as bs)", simp_all)+
lemma thm_3_3_2_impl_4 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "k \<equiv> length as"
shows "(- (2 ^ k) \<le> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<and> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<le> 2 ^ k - 1) \<Longrightarrow> snd (DA\<^sup>- (a#as) (b#bs)) \<noteq> hd (fst (DA\<^sup>- (a#as) (b#bs)))"
apply rule
proof goal_cases
case 1
have 2: "- (2 ^ k) \<le> \<lparr> (a # as) -\<^sub>Z\<^sub>A (b # bs) \<rparr> \<and> \<lparr> (a # as) -\<^sub>Z\<^sub>A (b # bs) \<rparr> \<le> 2 ^ k - 1"
apply rule
apply(subst thm_3_1_2[symmetric])
using assms apply simp
using 1 apply simp
apply (subst thm_3_1_2[symmetric])
apply (simp add: assms)
using 1 by simp
have "\<lparr> fst (DA\<^sup>- (False # a # as) (False # b # bs)) \<rparr> = \<lparr> (\<not> snd (DA\<^sup>- (a # as) (b # bs))) # fst (DA\<^sup>- (a # as) (b # bs)) \<rparr>"
apply (subst DAminus.simps)
unfolding prod.sel bool2nat.simps
apply (cases "snd (DA\<^sup>- (a # as) (b # bs))")
by simp_all
with 2 have 3: "- (2 ^ k) \<le> \<lparr> (\<not> snd (DA\<^sup>- (a # as) (b # bs))) # hd (fst (DA\<^sup>- (a # as) (b # bs))) # tl (fst (DA\<^sup>- (a # as) (b # bs))) \<rparr> \<and>
\<lparr> (\<not> snd (DA\<^sup>- (a # as) (b # bs))) # hd (fst (DA\<^sup>- (a # as) (b # bs))) # tl (fst (DA\<^sup>- (a # as) (b # bs))) \<rparr> \<le> 2 ^ k - 1"
unfolding uminus_def DAminus.simps prod.sel list.sel by simp
show ?case
proof (cases "snd (DA\<^sup>- (a # as) (b # bs))")
case False
then have false: "snd (DA\<^sup>- (a # as) (b # bs)) = False" by simp
have "\<lparr> (\<not> snd (DA\<^sup>- (a # as) (b # bs))) # hd (fst (DA\<^sup>- (a # as) (b # bs))) # tl (fst (DA\<^sup>- (a # as) (b # bs))) \<rparr> \<le> - (2 ^ (k+1)) + (2 ^ k - 1)"
unfolding 1(2)[symmetric] seval.simps ueval.simps
apply(rule add_mono)
unfolding k_def list.size(4) length_tl
apply(subst DAminus_eq_len)
using assms apply simp
unfolding list.size(4) assms[symmetric] nat_transfer2[symmetric]
using False apply simp
apply(subst DAminus_eq_len)
using assms apply simp
unfolding false bool2nat.simps mult_zero_class.mult_zero_left add_0
apply simp
unfolding k_def using ueval_upper_bound3 DAminus_eq_len assms by metis
with 3 have contr1: "- (2 ^ k) \<le> - (2 ^ (k+1)) + (2 ^ k - (1 :: int))" by simp
have contr2: "- (2 ^ (k+1)) + (2 ^ k - (1 :: int)) < - (2 ^ k)" by simp
show ?thesis using contr1 contr2 by simp
next
case True
then have true: "snd (DA\<^sup>- (a # as) (b # bs)) = True" by simp
have "2 ^ k \<le> \<lparr> (\<not> snd (DA\<^sup>- (a # as) (b # bs))) # hd (fst (DA\<^sup>- (a # as) (b # bs))) # tl (fst (DA\<^sup>- (a # as) (b # bs))) \<rparr>"
unfolding 1(2)[symmetric] seval.simps ueval.simps true not_True_eq_False bool2nat.simps mult_zero_left
minus_zero add_0 length_tl
apply(subst DAminus_eq_len)
using assms apply simp
unfolding list.size(4) k_def assms by simp
with 3 have "2 ^ k \<le> 2 ^ k - (1 :: int)" by simp
then show ?thesis by simp
qed
qed
lemma thm_3_3_4_impl_1 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "k \<equiv> length as"
shows "snd (DA\<^sup>- (a#as) (b#bs)) \<noteq> hd (fst (DA\<^sup>- (a#as) (b#bs))) \<Longrightarrow> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> = \<lparr>(a#as) -\<^sub>A (b#bs)\<rparr>"
apply (subst thm_3_1_2)
using assms apply simp
unfolding uminus_def tminus_def seval.simps DAminus.simps prod.sel by auto
lemma thm_3_3_1_impl_2:
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "k \<equiv> length as"
shows "int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> = \<lparr>(a#as) -\<^sub>A (b#bs)\<rparr> \<Longrightarrow> (- (2 ^ k) \<le> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<and> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<le> 2 ^ k - 1)"
apply rule
unfolding k_def tminus_def DAminus.simps prod.sel
using assms DAminus_eq_len seval_lower_bound seval_upper_bound by metis+
(* Theorem 3.3 Condition Set 2 *)
(* 3 \<longleftrightarrow> 5 : done *)
(* 4 \<longleftrightarrow> 3 : done *)
(* 2 \<longrightarrow> 3 : done *)
(* 3 \<longrightarrow> 1 : done *)
(* 1 \<longrightarrow> 2 : done *)
lemma thm_3_3_cs2_3_iff_5 :
fixes ak bk :: bool and as bs :: "bool list"
assumes "length (ak # as) = length (bk # bs)"
defines "triple' x y z \<equiv> triple x y z (ak # as) (bk # bs) ((ak # as) -\<^sub>A (bk # bs))" and
"rk \<equiv> hd ((ak # as) -\<^sub>A (bk # bs))"
shows "-(\<lbrakk>ak\<rbrakk>\<^sub>Z) + \<lbrakk>bk\<rbrakk>\<^sub>Z - \<lbrakk>rk\<rbrakk>\<^sub>Z = 1 \<longleftrightarrow> triple' \<bottom> \<top> \<bottom>"
apply rule
unfolding triple'_def triple_def rk_def[symmetric] list.sel(1)
by(cases ak; cases bk; cases rk, simp_all)+
lemma thm_3_3_cs2_4_iff_3 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) -\<^sub>A (b#bs))"
shows "snd (DA\<^sup>- (a#as) (b#bs)) = \<bottom> \<and> hd (fst (DA\<^sup>- (a#as) (b#bs))) = \<bottom> \<longleftrightarrow> triple' \<bottom> \<top> \<bottom>"
apply rule
unfolding triple'_def triple_def tminus_def
by (cases a;cases b; cases "snd (DA\<^sup>- as bs)", simp_all)+
lemma thm_3_3_cs2_2_impl_3:
fixes k :: nat and a b :: bool and as bs :: "bool list"
assumes "length as = k"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) -\<^sub>A (b#bs))"
shows "length as = length bs \<Longrightarrow>
- (2 ^ Suc k) + 1 \<le> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<and> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<le> - (2 ^ k) - 1 \<Longrightarrow> triple' \<bottom> \<top> \<bottom>"
proof goal_cases
case 1
have "\<bottom> = a" "\<top> = b" "\<bottom> = hd ((a#as) -\<^sub>A (b#bs))"
apply (smt "1"(1) "1"(2) assms(1) bot_unfold eval_eq_seval of_nat_add of_nat_less_0_iff seval.simps(2) seval_upper_bound ueval.simps(2))
apply (smt "1"(1) "1"(2) assms(1) eval_eq_seval of_nat_add of_nat_less_0_iff seval.simps(2) seval_upper_bound top_unfold ueval.simps(2))
by (smt "1"(1) "1"(2) assms(1) bool2nat.simps(1) bot_unfold comm_monoid_mult_class.mult_1 less_imp_of_nat_less list.sel(1) of_nat_add seval.simps(2) seval_lower_bound thm_3_3_1_impl_2 thm_3_3_4_iff_3 thm_3_3_4_impl_1 top_unfold triple_def ueval.simps(2) ueval_upper_bound3)
then show ?case unfolding triple'_def triple_def by auto
qed
lemma thm_3_3_cs2_3_impl_1:
fixes k :: nat and a b :: bool and as bs :: "bool list"
assumes "length as = k"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) -\<^sub>A (b#bs))"
shows "length as = length bs \<Longrightarrow>
triple' \<bottom> \<top> \<bottom> \<Longrightarrow> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> = \<lparr>\<top>#((a#as) -\<^sub>A (b#bs))\<rparr> \<and> hd ((a#as) -\<^sub>A (b#bs)) = \<bottom>"
apply(subst thm_3_1_2)
using assms apply simp
unfolding sminus.simps uminus_def tminus_def seval.simps ueval.simps DAminus.simps prod.sel triple'_def triple_def list.sel(1)
using to_from_mod_id to_from_mod_id3 by auto
lemma thm_3_3_cs2_1_impl_2:
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "k \<equiv> length as"
shows "int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> = \<lparr>\<top>#((a#as) -\<^sub>A (b#bs))\<rparr> \<and> hd ((a#as) -\<^sub>A (b#bs)) = \<bottom> \<Longrightarrow>
- (2 ^ Suc k) + 1 \<le> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<and> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<le> - (2 ^ k) - 1"
apply rule
unfolding k_def tminus_def DAminus.simps prod.sel
using assms DAminus_eq_len seval_lower_bound seval_upper_bound
apply (smt eval_eq_seval length_Cons of_nat_less_0_iff)
by (smt DAminus_eq_len One_nat_def assms(1) bool2nat.simps(1) bool2nat.simps(2) bot_unfold comm_monoid_mult_class.mult_1 comm_semiring_class.distrib diff_Suc_1 int_nat_eq le_numeral_extra(4) length_Cons list.sel(1) mult_is_0 nat_2 numeral_2_eq_2 of_nat_add of_nat_diff of_nat_power semiring_normalization_rules(2) semiring_normalization_rules(27) seval.simps(2) seval_upper_bound top_unfold ueval.simps(2))
(* Theorem 3.3 Condition Set 3 *)
(* 3 \<longleftrightarrow> 5 : done *)
(* 4 \<longleftrightarrow> 3 : done *)
(* 2 \<longrightarrow> 3 : done *)
(* 3 \<longrightarrow> 1 : done *)
(* 1 \<longrightarrow> 2 : done *)
lemma thm_3_3_cs3_3_iff_5 :
fixes ak bk :: bool and as bs :: "bool list"
assumes "length (ak # as) = length (bk # bs)"
defines "triple' x y z \<equiv> triple x y z (ak # as) (bk # bs) ((ak # as) -\<^sub>A (bk # bs))" and
"rk \<equiv> hd ((ak # as) -\<^sub>A (bk # bs))"
shows "-(\<lbrakk>ak\<rbrakk>\<^sub>Z) + \<lbrakk>bk\<rbrakk>\<^sub>Z - \<lbrakk>rk\<rbrakk>\<^sub>Z = -2 \<longleftrightarrow> triple' \<top> \<bottom> \<top>"
apply rule
unfolding triple'_def triple_def rk_def[symmetric] list.sel(1)
by(cases ak; cases bk; cases rk, simp_all)+
lemma thm_3_3_cs3_4_iff_3 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) -\<^sub>A (b#bs))"
shows "snd (DA\<^sup>- (a#as) (b#bs)) = \<top> \<and> hd (fst (DA\<^sup>- (a#as) (b#bs))) = \<top> \<longleftrightarrow> triple' \<top> \<bottom> \<top>"
apply rule
unfolding triple'_def triple_def tminus_def
by (cases a;cases b; cases "snd (DA\<^sup>- as bs)", simp_all)+
lemma thm_3_3_cs3_2_impl_3:
fixes k :: nat and a b :: bool and as bs :: "bool list"
assumes "length as = k"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) -\<^sub>A (b#bs))"
shows "length as = length bs \<Longrightarrow>
2 ^ k \<le> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<and> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<le> (2 ^ Suc k) - 1 \<Longrightarrow> triple' \<top> \<bottom> \<top>"
proof goal_cases
case 1
have "\<top> = a" "\<bottom> = b" "\<top> = hd ((a#as) -\<^sub>A (b#bs))"
apply (smt "1"(2) add_0_left assms(1) bool2nat.simps(2) eval_eq_seval mult_is_0 of_nat_less_0_iff seval_upper_bound top_unfold ueval.simps(2))
apply (smt "1"(1) "1"(2) assms(1) bot_unfold eval_eq_seval of_nat_add of_nat_less_0_iff seval.simps(2) seval_upper_bound ueval.simps(2))
by (smt "1"(1) "1"(2) assms(1) bot_unfold eval_eq_seval list.sel(1) of_nat_add of_nat_less_0_iff seval.simps(2) seval_upper_bound thm_3_3_1_impl_2 thm_3_3_4_impl_1 thm_3_3_cs2_4_iff_3 tminus_def top_unfold triple_def ueval.simps(2))
then show ?case unfolding triple'_def triple_def by auto
qed
lemma thm_3_3_cs3_3_impl_1:
fixes k :: nat and a b :: bool and as bs :: "bool list"
assumes "length as = k"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) -\<^sub>A (b#bs))"
shows "length as = length bs \<Longrightarrow>
triple' \<top> \<bottom> \<top> \<Longrightarrow> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> = \<lparr>\<bottom>#((a#as) -\<^sub>A (b#bs))\<rparr> \<and> hd ((a#as) -\<^sub>A (b#bs)) = \<top>"
apply(subst thm_3_1_2)
using assms apply simp
unfolding sminus.simps uminus_def tminus_def seval.simps ueval.simps DAminus.simps prod.sel triple'_def triple_def list.sel(1)
using to_from_mod_id to_from_mod_id3 by auto
lemma thm_3_3_cs3_1_impl_2:
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "k \<equiv> length as"
shows "int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> = \<lparr>\<bottom>#((a#as) -\<^sub>A (b#bs))\<rparr> \<and> hd ((a#as) -\<^sub>A (b#bs)) = \<top> \<Longrightarrow>
2 ^ k \<le> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<and> int \<lbrakk>a#as\<rbrakk> - int \<lbrakk>b#bs\<rbrakk> \<le> (2 ^ Suc k) - 1"
apply rule
unfolding k_def tminus_def DAminus.simps prod.sel
using assms DAminus_eq_len seval_lower_bound seval_upper_bound
apply simp
by (smt DAminus_eq_len One_nat_def assms(1) bool2nat.simps(1) bool2nat.simps(2) bot_unfold comm_monoid_mult_class.mult_1 comm_semiring_class.distrib diff_Suc_1 int_nat_eq le_numeral_extra(4) length_Cons list.sel(1) mult_is_0 nat_2 numeral_2_eq_2 of_nat_add of_nat_diff of_nat_power semiring_normalization_rules(2) semiring_normalization_rules(27) seval.simps(2) seval_upper_bound top_unfold ueval.simps(2))
(* Theorem 3.4 *)
(* 4 \<longleftrightarrow> 3 : done *)
(* 3 \<longleftrightarrow> 5 : done *)
(* 2 \<longrightarrow> 4 : done *)
(* 4 \<longrightarrow> 1 : done *)
(* 1 \<longleftrightarrow> 2 : done *)
lemma thm_3_4_3_iff_5 :
fixes ak bk :: bool and as bs :: "bool list"
assumes "length (ak # as) = length (bk # bs)"
defines "triple' x y z \<equiv> triple x y z (ak # as) (bk # bs) ((ak # as) +\<^sub>A (bk # bs))" and
"rk \<equiv> hd ((ak # as) +\<^sub>A (bk # bs))"
shows "-(\<lbrakk>ak\<rbrakk>\<^sub>Z) - \<lbrakk>bk\<rbrakk>\<^sub>Z + \<lbrakk>rk\<rbrakk>\<^sub>Z = 0 \<or> -(\<lbrakk>ak\<rbrakk>\<^sub>Z) - \<lbrakk>bk\<rbrakk>\<^sub>Z + \<lbrakk>rk\<rbrakk>\<^sub>Z = -1 \<longleftrightarrow>
(triple' \<top> \<top> \<top> \<or> triple' \<top> \<bottom> \<top> \<or> triple' \<top> \<bottom> \<bottom> \<or> triple' \<bottom> \<top> \<top> \<or> triple' \<bottom> \<top> \<bottom> \<or> triple' \<bottom> \<bottom> \<bottom>)"
apply rule
unfolding triple'_def triple_def rk_def[symmetric] list.sel(1)
by(cases ak; cases bk; cases rk, simp_all)+
lemma thm_3_4_4_iff_3 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) +\<^sub>A (b#bs))"
shows "snd (DA\<^sup>+ (a#as) (b#bs)) = snd (DA\<^sup>+ as bs) \<longleftrightarrow>
(triple' \<top> \<top> \<top> \<or> triple' \<top> \<bottom> \<top> \<or> triple' \<top> \<bottom> \<bottom> \<or> triple' \<bottom> \<top> \<top> \<or> triple' \<bottom> \<top> \<bottom> \<or> triple' \<bottom> \<bottom> \<bottom>)"
apply rule
unfolding triple'_def triple_def tplus_def
by (cases a;cases b; cases "snd (DA\<^sup>+ as bs)", simp_all)+
lemma thm_3_4_2_impl_4 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "k \<equiv> length as"
shows "(- (2 ^ k) \<le> \<lparr>a#as\<rparr> + \<lparr>b#bs\<rparr> \<and> \<lparr>a#as\<rparr> + \<lparr>b#bs\<rparr> \<le> 2 ^ k - 1) \<Longrightarrow> snd (DA\<^sup>+ (a#as) (b#bs)) = snd (DA\<^sup>+ as bs)"
proof goal_cases
case 1
then have "- (2 ^ k) \<le> \<lparr> (a # as) +\<^sub>S\<^sub>A (b # bs) \<rparr> \<and> \<lparr> (a # as) +\<^sub>S\<^sub>A (b # bs) \<rparr> \<le> 2 ^ k - 1"
apply rule
apply rule
apply(subst thm_3_1_3[symmetric])
using assms apply simp
apply simp
apply(subst thm_3_1_3[symmetric])
using assms apply simp
by simp
then have "(\<lbrakk> a \<rbrakk>\<^sub>N + \<lbrakk> b \<rbrakk>\<^sub>N + \<lbrakk> snd (DA\<^sup>+ (a # as) (b # bs)) \<rbrakk>\<^sub>N) mod 2 = (\<lbrakk> a \<rbrakk>\<^sub>N + \<lbrakk> b \<rbrakk>\<^sub>N + \<lbrakk> snd (DA\<^sup>+ as bs) \<rbrakk>\<^sub>N) mod 2"
apply(cases a; cases b; cases "snd (DA\<^sup>+ (a # as) (b # bs))"; cases "snd (DA\<^sup>+ as bs)", simp_all)
proof goal_cases
case 1
then have 2: "2 ^ k \<le> \<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk>"
apply (subst(2) nat_int[symmetric])
apply(subst nat_le_iff)
using DAplus_eq_len assms by simp
have "\<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk> \<le> 2 ^ k - 1" using ueval_upper_bound DAplus_eq_len assms by metis
then have "\<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk> < 2 ^ k" using DAplus_eq_len assms ueval_upper_bound3 by metis
with 2 show ?case by simp
next
case 2
then have 1: "int \<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk> < 0"
using DAplus_eq_len assms by simp
then show ?case by simp
qed
then show ?case by (cases a; cases b; cases "snd (DA\<^sup>+ (a # as) (b # bs))"; cases "snd (DA\<^sup>+ as bs)", simp_all)
qed
lemma thm_3_4_4_impl_1 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "k \<equiv> length as"
shows "snd (DA\<^sup>+ (a#as) (b#bs)) = snd (DA\<^sup>+ as bs) \<Longrightarrow> \<lparr>a#as\<rparr> + \<lparr>b#bs\<rparr> = \<lparr>(a#as) +\<^sub>A (b#bs)\<rparr>"
apply(subst thm_3_1_3)
using assms apply simp
unfolding splus.simps tplus_def seval.simps DAplus.simps prod.sel
by simp
lemma thm_3_4_1_iff_2:
fixes k :: nat
assumes "length a = Suc k"
shows "length a = length b \<Longrightarrow>
\<lparr>a\<rparr> + \<lparr>b\<rparr> = \<lparr>a +\<^sub>A b\<rparr> \<longleftrightarrow> (- (2 ^ k) \<le> \<lparr>a\<rparr> + \<lparr>b\<rparr> \<and> \<lparr>a\<rparr> + \<lparr>b\<rparr> \<le> 2 ^ k - 1)"
apply rule+
proof goal_cases
case 1
have 2: "\<And> x y. 0 \<le> x \<Longrightarrow> - x \<le> int y" by simp
show ?case
apply (cases a ; cases b)
using 1 apply simp_all
unfolding tplus_def DAplus.simps prod.sel seval.simps
apply (subst DAplus_eq_len, simp)
using assms
apply simp
apply (case_tac aa; case_tac aaa; case_tac "snd (DA\<^sup>+ list lista)")
apply simp_all
apply(rule 2)
by simp
next
case 2
have 3: "\<And> xs k. \<lbrakk> xs \<rbrakk> \<le> 2 ^ k - 1 \<Longrightarrow> int \<lbrakk> xs \<rbrakk> \<le> 2 ^ k - 1"
proof -
fix xs :: "bool list" and ka :: nat
assume "\<lbrakk> xs \<rbrakk> \<le> 2 ^ ka - 1"
then have "int \<lbrakk> xs \<rbrakk> + - 1 * int (2 ^ ka - 1) \<le> 0" by simp
then show "int \<lbrakk> xs \<rbrakk> \<le> 2 ^ ka - 1"
using le_add_diff_inverse numeral_One of_nat_1 by force
qed
have 4: "\<And> a b c k. c \<ge> 0 \<Longrightarrow> length a = k \<Longrightarrow> int \<lbrakk> a \<rbrakk> - int b * c < 2 ^ k"
proof goal_cases
case (1 a b c k)
show ?case
apply (rule zle_diff1_eq[THEN subst])
apply (subst diff_le_eq)
apply (rule order_class.order.trans)
apply (rule 3[where k = k])
using ueval_upper_bound2 1
apply auto[1]
by (simp add: "1"(1))
qed
show ?case unfolding 2 using assms
apply (cases a ; cases b)
using 2 apply simp_all
unfolding tplus_def DAplus.simps prod.sel seval.simps
apply (subst DAplus_eq_len, simp)
apply (case_tac aa ; case_tac aaa ; case_tac "snd (DA\<^sup>- list lista)")
apply simp_all
by (rule 4 , simp, subst DAplus_eq_len, simp, simp)+
next
case 3
have subst1: "\<And> a b. length a = length b \<Longrightarrow> 0 \<le> \<lbrakk> a \<rbrakk> + \<lbrakk> b \<rbrakk> \<and> \<lbrakk> a \<rbrakk> + \<lbrakk> b \<rbrakk> \<le> 2 ^ length a - 1 \<Longrightarrow> \<lbrakk> fst (DA\<^sup>+ a b) \<rbrakk> = \<lbrakk> a \<rbrakk> + \<lbrakk> b \<rbrakk>"
using thm_3_2_1_iff_2 unfolding tplus_def by fastforce
show ?case
apply (cases a; cases b)
unfolding tplus_def
apply simp
using 3 apply (simp,simp)
proof goal_cases
case (1 a as b bs)
with 3 have len_eq: "length as = length bs" by simp
from 3 assms 1 have k_def: "k = length as" by simp
have subst3: "\<And> a b c d :: int. a + b + (c + d) = a + c + (b + d)" by simp
have subst1: "- int (\<lbrakk> a \<rbrakk>\<^sub>N * 2 ^ length as) + int \<lbrakk> as \<rbrakk> + (- int (\<lbrakk> b \<rbrakk>\<^sub>N * 2 ^ length bs) + int \<lbrakk> bs \<rbrakk>) =
- int (\<lbrakk> a \<rbrakk>\<^sub>N * 2 ^ length as) - int (\<lbrakk> b \<rbrakk>\<^sub>N * 2 ^ length as) + int (\<lbrakk> snd (DA\<^sup>+ as bs) \<rbrakk>\<^sub>N) * 2 ^ length as + int \<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk>"
apply(subst subst3)
apply(subst nat_transfer)
apply(subst thm_3_1_1, simp add: len_eq)
unfolding uplus_def DAplus.simps
apply simp
apply (subst DAplus_eq_len, simp add: len_eq)+
by (simp add: len_eq to_from_mod_id)
then have hyps:
"- (2 ^ length as) \<le> - int (\<lbrakk> a \<rbrakk>\<^sub>N * 2 ^ length as) - int (\<lbrakk> b \<rbrakk>\<^sub>N * 2 ^ length as) + int (\<lbrakk> snd (DA\<^sup>+ as bs) \<rbrakk>\<^sub>N) * 2 ^ length as + int \<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk>"
"- int (\<lbrakk> a \<rbrakk>\<^sub>N * 2 ^ length as) - int (\<lbrakk> b \<rbrakk>\<^sub>N * 2 ^ length as) + int (\<lbrakk> snd (DA\<^sup>+ as bs) \<rbrakk>\<^sub>N) * 2 ^ length as + int \<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk> \<le> 2 ^ length as - 1"
using 3 unfolding 1 k_def seval.simps by simp_all
have hyps2: "0 \<le> int \<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk>" "int \<lbrakk> fst (DA\<^sup>+ as bs) \<rbrakk> \<le> 2 ^ length as - 1"
apply simp
apply(rule nat_0_le[THEN subst])
apply simp
apply (subst Int.zle_int)
apply(rule order_class.order.trans)
apply(rule ueval_upper_bound, simp_all)
apply(subst DAplus_eq_len, simp add: len_eq)
apply(subst len_eq)
proof -
have f1: "Suc (nat (- 1 + 2 ^ length bs)) = nat (2 ^ length bs)" by (simp add: Suc_nat_eq_nat_zadd1)
have "(0::int) \<le> 2" by auto
then have "Suc (nat (- 1 + 2 ^ length bs)) = 2 ^ length bs"
using f1 nat_2 nat_power_eq numeral_2_eq_2 by presburger
then show "2 ^ length bs - Suc 0 \<le> nat (2 ^ length bs - 1)" by linarith
qed
show ?case unfolding 1 DAplus.simps prod.sel seval.simps
apply(subst subst3)
apply(subst nat_transfer)
apply(subst thm_3_1_1, simp add: len_eq)
unfolding uplus_def DAplus.simps
apply simp
apply (subst DAplus_eq_len, simp add: len_eq)+
apply (cases a ; cases b; cases "snd (DA\<^sup>+ as bs)")
apply (simp_all add:len_eq)
using hyps hyps2 by simp+
qed
qed
lemma thm_3_4_2_impl_1:
fixes k :: nat
assumes "length a = Suc k"
shows "length a = length b \<Longrightarrow>
(- (2 ^ k) \<le> \<lparr>a\<rparr> + \<lparr>b\<rparr> \<and> \<lparr>a\<rparr> + \<lparr>b\<rparr> \<le> 2 ^ k - 1) \<Longrightarrow> \<lparr>a\<rparr> + \<lparr>b\<rparr> = \<lparr>a +\<^sub>A b\<rparr>"
using thm_3_4_1_iff_2 assms by blast
(* Theorem 3.4 Condition Set 2 *)
(* 3 \<longleftrightarrow> 5 : done *)
(* 4 \<longleftrightarrow> 3 : done *)
(* 1 \<longrightarrow> 2 : done *)
(* 2 \<longrightarrow> 3 : done *)
(* 3 \<longrightarrow> 1 : done *)
lemma thm_3_4_cs2_3_iff_5 :
fixes ak bk :: bool and as bs :: "bool list"
assumes "length (ak # as) = length (bk # bs)"
defines "triple' x y z \<equiv> triple x y z (ak # as) (bk # bs) ((ak # as) +\<^sub>A (bk # bs))" and
"rk \<equiv> hd ((ak # as) +\<^sub>A (bk # bs))"
shows "-(\<lbrakk>ak\<rbrakk>\<^sub>Z) - \<lbrakk>bk\<rbrakk>\<^sub>Z + \<lbrakk>rk\<rbrakk>\<^sub>Z = -2 \<longleftrightarrow> triple' \<top> \<top> \<bottom>"
apply rule
unfolding triple'_def triple_def rk_def[symmetric] list.sel(1)
by(cases ak; cases bk; cases rk, simp_all)+
lemma thm_3_4_cs2_4_iff_3 :
fixes a b :: "bool" and as bs :: "bool list"
assumes "length as = length bs"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) +\<^sub>A (b#bs))"
shows "(snd (DA\<^sup>+ (a#as) (b#bs)) = \<top> \<and> snd (DA\<^sup>+ as bs) = \<bottom>) \<longleftrightarrow> triple' \<top> \<top> \<bottom>"
apply rule
unfolding triple'_def triple_def tplus_def
by (cases a;cases b; cases "snd (DA\<^sup>+ as bs)", simp_all)+
lemma thm_3_4_cs2_1_impl_2:
fixes k :: nat
assumes "length a = Suc k"
shows "length a = length b \<Longrightarrow>
(\<lparr>a\<rparr> + \<lparr>b\<rparr> = \<lparr>\<top>#(a +\<^sub>A b)\<rparr> \<and> hd (a +\<^sub>A b) = \<bottom>) \<Longrightarrow> - (2 ^ (Suc k)) \<le> \<lparr>a\<rparr> + \<lparr>b\<rparr> \<and> \<lparr>a\<rparr> + \<lparr>b\<rparr> \<le> - (2 ^ k) - 1"
apply rule+
proof goal_cases
case 1
then have "\<lparr>a\<rparr> + \<lparr>b\<rparr> = - int (2 ^ (Suc k)) + int \<lbrakk> a +\<^sub>A b \<rbrakk>" unfolding seval.simps
using DAplus_eq_len assms tplus_def by auto
then show ?case by simp
next
case 2
then have 1: "\<lparr>a\<rparr> + \<lparr>b\<rparr> = - int (2 ^ (Suc k)) + int \<lbrakk> a +\<^sub>A b \<rbrakk>" unfolding seval.simps
using DAplus_eq_len assms tplus_def by auto
show ?case unfolding 1
apply simp
apply (cases "a +\<^sub>A b")
using assms 2 apply simp_all
using ueval_upper_bound3
by (metis DAplus_eq_len add_diff_cancel_left' length_Cons plus_1_eq_Suc tplus_def)
qed
lemma thm_3_4_cs2_2_impl_3:
fixes k :: nat and a b :: bool and as bs :: "bool list"
assumes "length as = k"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) +\<^sub>A (b#bs))"
shows "length as = length bs \<Longrightarrow>
- (2 ^ (Suc k)) \<le> \<lparr>a#as\<rparr> + \<lparr>b#bs\<rparr> \<and> \<lparr>a#as\<rparr> + \<lparr>b#bs\<rparr> \<le> - (2 ^ k) - 1 \<Longrightarrow> triple' \<top> \<top> \<bottom>"
proof goal_cases
case 1
have 2: "- (2 ^ (Suc k)) \<le> \<lparr> (a#as) +\<^sub>S\<^sub>A (b#bs) \<rparr> \<and> \<lparr> (a#as) +\<^sub>S\<^sub>A (b#bs) \<rparr> \<le> - (2 ^ k) - 1"
apply rule
apply(subst thm_3_1_3[symmetric])
using 1 apply (simp,simp)
apply (subst thm_3_1_3[symmetric])
using 1 by simp_all
define sig_r ("\<sigma>\<^sub>r") where "\<sigma>\<^sub>r \<equiv> \<lbrakk> (\<lbrakk> a \<rbrakk>\<^sub>N + \<lbrakk> b \<rbrakk>\<^sub>N + \<lbrakk> snd (DA\<^sup>+ as bs) \<rbrakk>\<^sub>N) mod 2 \<rbrakk>\<^sub>B"
define r_k_minus_one ("r\<^sup>k\<^sup>-\<^sup>1") where "r\<^sup>k\<^sup>-\<^sup>1 \<equiv> fst (DA\<^sup>+ as bs)"
define R where "R \<equiv> \<lbrakk> (\<lbrakk> a \<rbrakk>\<^sub>N + \<lbrakk> b \<rbrakk>\<^sub>N + \<lbrakk> snd (\<sigma>\<^sub>r # r\<^sup>k\<^sup>-\<^sup>1, \<lbrakk> (\<lbrakk> a \<rbrakk>\<^sub>N + \<lbrakk> b \<rbrakk>\<^sub>N + \<lbrakk> snd (DA\<^sup>+ as bs) \<rbrakk>\<^sub>N) div 2 \<rbrakk>\<^sub>B) \<rbrakk>\<^sub>N) mod 2 \<rbrakk>\<^sub>B"
from 2 have 3:
"- (2 ^ (Suc k)) \<le> - int (\<lbrakk> R \<rbrakk>\<^sub>N) * (2 ^ (Suc k)) + int ((\<lbrakk>\<sigma>\<^sub>r\<rbrakk>\<^sub>N) * (2 ^ k) + \<lbrakk> r\<^sup>k\<^sup>-\<^sup>1 \<rbrakk>)"
"- int (\<lbrakk> R \<rbrakk>\<^sub>N) * (2 ^ (Suc k)) + int ((\<lbrakk>\<sigma>\<^sub>r\<rbrakk>\<^sub>N) * (2 ^ k) + \<lbrakk> r\<^sup>k\<^sup>-\<^sup>1 \<rbrakk>) \<le> - (2 ^ k) - 1"
unfolding splus.simps list.sel(1) DAplus.simps fst_conv sig_r_def
r_k_minus_one_def R_def seval.simps ueval.simps
using DAplus_eq_len assms(1) 1(1) by simp_all
from 3(2) have 4: "\<lbrakk> R \<rbrakk>\<^sub>N = 1"
by (smt One_nat_def add_diff_cancel_left' bool2nat.elims le_numeral_extra(4) mult_minus_left of_nat_diff of_nat_less_0_iff plus_1_eq_Suc zero_le_power)
then have 5: "R = \<top>" using bool2nat.elims by auto
from 3(2) 4 have "int ((\<lbrakk>\<sigma>\<^sub>r\<rbrakk>\<^sub>N) * (2 ^ k) + \<lbrakk> r\<^sup>k\<^sup>-\<^sup>1 \<rbrakk>) \<le> (2 ^ k) - 1" by simp
with 4 5 have "\<lbrakk>\<sigma>\<^sub>r\<rbrakk>\<^sub>N = 0"
by (smt bool2nat.simps(2) int_nat_eq mult.left_neutral nat_2 numeral_2_eq_2 of_nat_add of_nat_power_eq_of_nat_cancel_iff seval.simps(2) seval_lower_bound top_unfold)
then have 6: "\<sigma>\<^sub>r = \<bottom>" using bool2nat.elims by auto
with 5 have "\<top> = a \<and> \<top> = b \<and> \<bottom> = hd ((a#as) +\<^sub>A (b#bs))"
by (smt DAplus.simps(4) R_def add.right_neutral add_self_mod_2 bool2nat.simps(1) bool2nat.simps(2) bot_unfold fst_conv lem_2_1 list.sel(1) mult_2 nat.simps(3) one_div_two_eq_zero plus_1_eq_Suc sig_r_def snd_conv top_unfold tplus_def)
then show ?case unfolding triple'_def triple_def by auto
qed
lemma thm_3_4_cs2_3_impl_1:
fixes k :: nat and a b :: bool and as bs :: "bool list"
assumes "length as = k"
defines "triple' x y z \<equiv> triple x y z (a#as) (b#bs) ((a#as) +\<^sub>A (b#bs))"
shows "length as = length bs \<Longrightarrow>
triple' \<top> \<top> \<bottom> \<Longrightarrow> (\<lparr>a#as\<rparr> + \<lparr>b#bs\<rparr> = \<lparr>\<top>#((a#as) +\<^sub>A (b#bs))\<rparr> \<and> hd ((a#as) +\<^sub>A (b#bs)) = \<bottom>)"
apply(subst thm_3_1_3)
using assms apply simp
unfolding splus.simps tplus_def seval.simps DAplus.simps prod.sel triple'_def triple_def list.sel(1)
by (smt One_nat_def add_numeral_left add_self_div_2 bot_unfold mod_add_self1 nat2bool.simps(2) not_mod2_eq_Suc_0_eq_0 numeral_2_eq_2 numeral_One one_mod_two_eq_one plus_1_eq_Suc semiring_norm(2) to_from_mod_id2 top_unfold)