-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGD.thy
More file actions
3687 lines (3332 loc) · 125 KB
/
GD.thy
File metadata and controls
3687 lines (3332 loc) · 125 KB
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 GD
imports Pure
begin
text \<open>The following theory development formalizes Grounded Arithmetic.\<close>
named_theorems auto "Unconditionally applied lemmas of shape simp \<Longrightarrow> comp"
named_theorems cond "Conditionally applied if P can be solved: P \<Longrightarrow> simp \<Longrightarrow> comp"
named_theorems cases "Tag for cases lemmas used by cases tactic."
named_theorems induct "Tag for induction lemmas used by induct tactic."
section \<open>Axiomatization of truth in GD\<close>
typedecl o
judgment
Trueprop :: \<open>o \<Rightarrow> prop\<close> (\<open>_\<close> 5)
axiomatization
disj :: \<open>o \<Rightarrow> o \<Rightarrow> o\<close> (infixr \<open>\<or>\<close> 30) and
not :: \<open>o \<Rightarrow> o\<close> (\<open>\<not> _\<close> [40] 40)
where
disjI1: \<open>P \<Longrightarrow> P \<or> Q\<close> and
disjI2: \<open>Q \<Longrightarrow> P \<or> Q\<close> and
disjI3: \<open>\<lbrakk>\<not>P; \<not>Q\<rbrakk> \<Longrightarrow> \<not>(P \<or> Q)\<close> and
disjE1: \<open>\<lbrakk>P \<or> Q; P \<Longrightarrow> R; Q \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R\<close> and
disjE2: \<open>\<not>(P \<or> Q) \<Longrightarrow> \<not>P\<close> and
disjE3: \<open>\<not>(P \<or> Q) \<Longrightarrow> \<not>Q\<close> and
dNegI: \<open>P \<Longrightarrow> (\<not>\<not>P)\<close> and
dNegE: \<open>(\<not>\<not>P) \<Longrightarrow> P\<close> and
exF: \<open>\<lbrakk>P; \<not>P\<rbrakk> \<Longrightarrow> Q\<close>
section \<open>Axiomatization of naturals in GD\<close>
typedecl num
axiomatization
eq :: \<open>'a \<Rightarrow> 'a \<Rightarrow> o\<close> (infixl \<open>=\<close> 45)
where
eqSubst: \<open>\<lbrakk>a = b; Q a\<rbrakk> \<Longrightarrow> Q b\<close> and
eqSym: \<open>a = b \<Longrightarrow> b = a\<close> and
eq_reflection: \<open>x = y \<Longrightarrow> x \<equiv> y\<close>
lemma eq_trans: "a = b \<Longrightarrow> b = c \<Longrightarrow> a = c"
by (rule eqSubst[where a="b" and b="c"], assumption)
definition neq :: \<open>num \<Rightarrow> num \<Rightarrow> o\<close> (infixl \<open>\<noteq>\<close> 45)
where \<open>a \<noteq> b \<equiv> \<not> (a = b)\<close>
definition bJudg :: \<open>o \<Rightarrow> o\<close> (\<open>_ B\<close> [21] 20)
where \<open>(p B) \<equiv> (p \<or> \<not>p)\<close>
definition isNat :: \<open>num \<Rightarrow> o\<close> (\<open>_ N\<close> [21] 20)
where "x N \<equiv> x = x"
definition conj :: \<open>o \<Rightarrow> o \<Rightarrow> o\<close> (infixl \<open>\<and>\<close> 35)
where \<open>p \<and> q \<equiv> \<not>(\<not>p \<or> \<not>q)\<close>
definition impl :: \<open>o \<Rightarrow> o \<Rightarrow> o\<close> (infixr \<open>\<longrightarrow>\<close> 25)
where \<open>p \<longrightarrow> q \<equiv> \<not>p \<or> q\<close>
definition iff :: \<open>o \<Rightarrow> o \<Rightarrow> o\<close> (infixl \<open>\<longleftrightarrow>\<close> 25)
where \<open>p \<longleftrightarrow> q \<equiv> (p \<longrightarrow> q) \<and> (q \<longrightarrow> p)\<close>
axiomatization
where
iff_reflection: "p \<longleftrightarrow> q \<Longrightarrow> p \<equiv> q"
lemma conjE1:
assumes p_and_q: "p \<and> q"
shows "p"
apply (rule dNegE)
apply (rule disjE2[where Q="\<not>q"])
apply (fold conj_def)
apply (rule p_and_q)
done
lemma conjE2:
assumes p_and_q: "p \<and> q"
shows "q"
apply (rule dNegE)
apply (rule disjE3[where P="\<not>p"])
apply (fold conj_def)
apply (rule p_and_q)
done
lemma conjI [auto]:
assumes p: "p"
assumes q: "q"
shows "p \<and> q"
apply (unfold conj_def)
apply (rule disjI3)
apply (rule dNegI)
apply (rule p)
apply (rule dNegI)
apply (rule q)
done
axiomatization
zero :: \<open>num\<close> and
suc :: \<open>num \<Rightarrow> num\<close> (\<open>S(_)\<close> [800]) and
pred :: \<open>num \<Rightarrow> num\<close> (\<open>P(_)\<close> [800])
where
nat0: \<open>zero N\<close> and
sucInj: \<open>S a = S b \<Longrightarrow> a = b\<close> and
sucCong: \<open>a = b \<Longrightarrow> S a = S b\<close> and
predCong: \<open>a = b \<Longrightarrow> P a = P b\<close> and
eqBool: \<open>\<lbrakk>a N; b N\<rbrakk> \<Longrightarrow> (a = b) B\<close> and
eqBoolB: \<open>\<lbrakk>x B; y B\<rbrakk> \<Longrightarrow> (x = y) B\<close> and
sucNonZero: \<open>a N \<Longrightarrow> S a \<noteq> zero\<close> and
predSucInv: \<open>a N \<Longrightarrow> P(S(a)) = a\<close> and
pred0: \<open>P(zero) = zero\<close> and
ind [case_names HQ Base Step]:
"\<lbrakk>a N; Q zero; \<And>x. x N \<Longrightarrow> Q x \<Longrightarrow> Q S(x)\<rbrakk> \<Longrightarrow> Q a"
definition True
where \<open>True \<equiv> zero = zero\<close>
definition False
where \<open>False \<equiv> S(zero) = zero\<close>
lemma zeroRefl [auto]: "zero = zero"
apply (fold isNat_def)
apply (rule nat0)
done
lemma natS [auto]:
assumes a_nat: "a N"
shows "S a N"
apply (unfold isNat_def)
apply (rule sucCong)
apply (fold isNat_def)
apply (rule a_nat)
done
lemma natSI:
assumes a_nat: "S(a) N"
shows "a N"
apply (unfold isNat_def)
apply (rule sucInj)
apply (fold isNat_def)
apply (rule a_nat)
done
lemma natP [auto]:
assumes a_nat: "a N"
shows "P a N"
apply (unfold isNat_def)
apply (rule predCong)
apply (fold isNat_def)
apply (rule a_nat)
done
lemma implI:
assumes a_bool: "a B"
assumes a_deduce_b: "a \<Longrightarrow> b"
shows "a \<longrightarrow> b"
proof (unfold impl_def, rule disjE1[where P="a" and Q="\<not>a"])
show "a \<or> \<not>a" by (fold GD.bJudg_def, rule a_bool)
next
show "a \<Longrightarrow> \<not>a \<or> b" by (rule disjI2, rule a_deduce_b, assumption)
next
show "\<not>a \<Longrightarrow> \<not>a \<or> b" by (rule disjI1, assumption)
qed
lemma implE:
assumes H1: "a \<longrightarrow> b"
assumes H2: "a"
shows "b"
proof (rule disjE1[where P="\<not>a" and Q="b"])
show "\<not>a \<or> b"
apply (fold impl_def)
apply (rule H1)
done
next
assume not_a: "\<not>a"
show "b"
apply (rule exF[where P="a"])
apply (rule H2)
apply (rule not_a)
done
next
show "b \<Longrightarrow> b"
apply (assumption)
done
qed
lemma iffE1: "a \<longleftrightarrow> b \<Longrightarrow> a \<longrightarrow> b"
apply (rule conjE1)
apply (unfold iff_def)
apply (assumption)
done
lemma iffE2: "a \<longleftrightarrow> b \<Longrightarrow> b \<longrightarrow> a"
apply (rule conjE2)
apply (unfold iff_def)
apply (assumption)
done
lemma iffI:
assumes a_bool: "a B"
assumes b_bool: "b B"
assumes a_deduce_b: "a \<Longrightarrow> b"
assumes b_deduce_a: "b \<Longrightarrow> a"
shows "a \<longleftrightarrow> b"
unfolding iff_def
apply (rule conjI)
apply (rule implI, rule a_bool, rule a_deduce_b, assumption)
apply (rule implI, rule b_bool, rule b_deduce_a, assumption)
done
lemma grounded_contradiction:
assumes p_bool: \<open>p B\<close>
assumes notp_q: \<open>\<not>p \<Longrightarrow> q\<close>
assumes notp_notq: \<open>\<not>p \<Longrightarrow> \<not>q\<close>
shows \<open>p\<close>
proof (rule disjE1[where P="p" and Q="\<not>p"])
show "p \<or> \<not>p"
using p_bool unfolding GD.bJudg_def .
show "p \<Longrightarrow> p" by assumption
show "\<not>p \<Longrightarrow> p"
proof -
assume not_p: "\<not>p"
have q: "q" using notp_q[OF not_p] .
have not_q: "\<not>q" using notp_notq[OF not_p] .
from q and not_q show "p"
by (rule exF)
qed
qed
syntax
"_gd_num" :: "num_token \<Rightarrow> num" ("_")
ML_file "peano_numerals.ML"
parse_translation \<open>
[(@{syntax_const "_gd_num"}, Peano_Syntax.parse_gd_numeral)]
\<close>
lemma contradiction:
assumes p_bool: "p B"
assumes contr: "\<not>p \<Longrightarrow> False"
shows "p"
apply (rule grounded_contradiction[where q="False"])
apply (rule p_bool)
proof -
assume not_p: "\<not>p"
show "False"
apply (rule contr)
apply (rule not_p)
done
show "\<not>False"
apply (unfold False_def)
apply (fold neq_def)
apply (rule sucNonZero)
apply (rule nat0)
done
qed
(* Entailment reduces to almost the same as object-level implication \<longrightarrow>.
* The difference is that the \<longrightarrow> introduction rule requires 'a' to be
* proven boolean first ('a B'), while entailment does not. It is a
* direct object-level mirroring of the meta-level a \<Longrightarrow> b.
* Meta-level just means that it is of type prop \<Rightarrow> prop \<Rightarrow> prop,
* while entailment mirrors this at the object level, that is, it's
* of type o \<Rightarrow> o \<Rightarrow> o.
* With entailment, GD can reason about deducability at the object level,
* which adds a lot of expressive power.
*)
axiomatization
entails :: "o \<Rightarrow> o \<Rightarrow> o" (infixr "\<turnstile>" 10)
where
entailsI: "\<lbrakk>a \<Longrightarrow> b\<rbrakk> \<Longrightarrow> (a \<turnstile> b)" and
entailsE: "\<lbrakk>a \<turnstile> b; a\<rbrakk> \<Longrightarrow> b"
axiomatization
forall :: "(num \<Rightarrow> o) \<Rightarrow> o" (binder "\<forall>" [8] 9) and
exists :: "(num \<Rightarrow> o) \<Rightarrow> o" (binder "\<exists>" [8] 9)
where
forallI: "\<lbrakk>\<And>x. x N \<Longrightarrow> Q x\<rbrakk> \<Longrightarrow> \<forall>x. Q x" and
forallE: "\<lbrakk>\<forall>c'. Q c'; a N\<rbrakk> \<Longrightarrow> Q a" and
existsI: "\<lbrakk>a N; Q a\<rbrakk> \<Longrightarrow> \<exists>x. Q x" and
existsE: "\<lbrakk>\<exists>i. Q i; \<And>a. a N \<Longrightarrow> Q a \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
(*
forAllNeg: "\<lbrakk>\<not>(\<forall>x. Q x); (Q x) B\<rbrakk> \<Longrightarrow> \<exists>x. \<not>(Q x)" and
existsNeg: "\<lbrakk>\<not>(\<exists>x. Q x); (Q x) B\<rbrakk> \<Longrightarrow> \<forall>x. \<not>(Q x)" and
*)
section \<open>Axiomatization of conditional evaluation in GD\<close>
consts
cond :: \<open>o \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a\<close> (\<open>if _ then _ else _\<close> [25, 24, 24] 24)
axiomatization where
condI1: \<open>\<lbrakk>c; a N\<rbrakk> \<Longrightarrow> (if c then a else b) = a\<close> and
condI2: \<open>\<lbrakk>\<not>c; b N\<rbrakk> \<Longrightarrow> (if c then a else b) = b\<close> and
condT: \<open>\<lbrakk>c B; a N; b N\<rbrakk> \<Longrightarrow> if c then a else b N\<close> and
condI1B: \<open>\<lbrakk>c; d B\<rbrakk> \<Longrightarrow> (if c then d else e) = d\<close> and
condI2B: \<open>\<lbrakk>\<not>c; e B\<rbrakk> \<Longrightarrow> (if c then d else e) = e\<close> and
condTB: \<open>\<lbrakk>c B; d B; e B\<rbrakk> \<Longrightarrow> if c then d else e B\<close>
lemma condI1BEq:
assumes c_holds: "c"
assumes d_bool: "d B"
assumes a_eq_d: "a = d"
shows "(if c then a else b) = d"
apply (rule eqSubst[where a="d" and b="a"])
apply (rule eqSym)
apply (rule a_eq_d)
apply (rule condI1B)
apply (rule c_holds)
apply (rule d_bool)
done
lemma condI2BEq:
assumes not_c: "\<not>c"
assumes d_bool: "d B"
assumes a_eq_d: "b = d"
shows "(if c then a else b) = d"
apply (rule eqSubst[where a="d" and b="b"])
apply (rule eqSym)
apply (rule a_eq_d)
apply (rule condI2B)
apply (rule not_c)
apply (rule d_bool)
done
lemma condI3B:
shows "a B \<Longrightarrow> c B \<Longrightarrow> (if c then a else a) = a"
apply (rule disjE1[where P="c" and Q="\<not>c"])
apply (fold GD.bJudg_def, simp)
apply (rule condI1B, simp+)
apply (rule condI2B, simp+)
done
lemma condI3BEq:
assumes a_bool: "a B"
assumes c_bool: "c B"
assumes d_eq_a: "d = a"
assumes e_eq_a: "e = a"
shows "(if c then d else e) = a"
apply (rule disjE1[where P="c" and Q="\<not>c"])
apply (fold GD.bJudg_def)
apply (rule c_bool)
apply (rule eqSubst[where a="a" and b="d"])
apply (rule eqSym)
apply (rule d_eq_a)
apply (rule condI1B)
apply (assumption)
apply (rule a_bool)
apply (rule eqSubst[where a="a" and b="e"])
apply (rule eqSym)
apply (rule e_eq_a)
apply (rule condI2B)
apply (assumption)
apply (rule a_bool)
done
lemma condI1Eq:
assumes c_holds: "c"
assumes d_nat: "d N"
assumes a_eq_d: "a = d"
shows "(if c then a else b) = d"
apply (rule eqSubst[where a="d" and b="a"])
apply (rule eqSym)
apply (rule a_eq_d)
apply (rule condI1)
apply (rule c_holds)
apply (rule d_nat)
done
lemma condI2Eq:
assumes not_c: "\<not>c"
assumes d_nat: "d N"
assumes a_eq_d: "b = d"
shows "(if c then a else b) = d"
apply (rule eqSubst[where a="d" and b="b"])
apply (rule eqSym)
apply (rule a_eq_d)
apply (rule condI2)
apply (rule not_c)
apply (rule d_nat)
done
lemma condI3:
shows "a N \<Longrightarrow> c B \<Longrightarrow> (if c then a else a) = a"
apply (rule disjE1[where P="c" and Q="\<not>c"])
apply (fold GD.bJudg_def, simp)
apply (rule condI1, simp+)
apply (rule condI2, simp+)
done
lemma condI3Eq:
assumes a_nat: "a N"
assumes c_bool: "c B"
assumes d_eq_a: "c \<Longrightarrow> d = a"
assumes e_eq_a: "\<not> c \<Longrightarrow> e = a"
shows "(if c then d else e) = a"
apply (rule disjE1[where P="c" and Q="\<not>c"])
apply (fold GD.bJudg_def)
apply (rule c_bool)
apply (rule eqSubst[where a="a" and b="d"])
apply (rule eqSym)
apply (rule d_eq_a)
apply (assumption)
apply (rule condI1)
apply (assumption)
apply (rule a_nat)
apply (rule eqSubst[where a="a" and b="e"])
apply (rule eqSym)
apply (rule e_eq_a)
apply (assumption)
apply (rule condI2)
apply (assumption)
apply (rule a_nat)
done
ML_file "gd_auto.ML"
ML_file "gd_subst.ML"
section \<open>Definitional Mechanism in GD\<close>
axiomatization
def :: \<open>'a \<Rightarrow> 'a \<Rightarrow> o\<close> (infix \<open>:=\<close> 10)
where
defE: \<open>\<lbrakk>a := b; Q b\<rbrakk> \<Longrightarrow> Q a\<close> and
defI: \<open>\<lbrakk>a := b; Q a\<rbrakk> \<Longrightarrow> Q b\<close>
ML_file "gd_simp.ML"
lemmas [simp] = predSucInv neq_def pred0 condI1 condI1B condI2 condI2B condI3B condI3
lemmas [auto] = nat0 sucNonZero predSucInv pred0 eqBool eqBoolB disjI3 dNegI
lemma [simp]: "(a = a) \<equiv> (a N)"
unfolding isNat_def by (rule Pure.reflexive)
ML_file \<open>unfold_def.ML\<close>
section \<open>Deductions of non-elementary inference rules.\<close>
lemma true [auto]: "True"
unfolding True_def by auto
lemma true_bool [auto]: "True B"
unfolding bJudg_def by (rule disjI1, rule true)
lemma bool_refl: "a B \<Longrightarrow> a = a"
apply (rule eqSubst[where a="(if True then a else a)" and b="a"])
apply (rule condI1B, simp)
apply (rule condI1BEq, simp)
apply (rule condTB, simp)
apply (rule eqSym)
apply (rule condI1B, simp)
done
lemma eq_impl_term: "a = b \<Longrightarrow> a N"
apply (rule entailsE[where a="a=b"])
apply (unfold isNat_def)
apply (subst "a=b", assumption)
apply (rule entailsI, simp)
done
lemma [simp]: "a B \<Longrightarrow> (a = a) \<longleftrightarrow> True"
by (rule iffI, simp, rule bool_refl)
lemma [simp]: "\<not>c \<Longrightarrow> b N \<Longrightarrow> d N \<Longrightarrow> (if c then a else b) = d \<longleftrightarrow> b = d"
by (rule iffI, simp+)
lemma [simp]: "c \<Longrightarrow> a N \<Longrightarrow> d N \<Longrightarrow> (if c then a else b) = d \<longleftrightarrow> a = d"
by (rule iffI, simp+)
lemma [simp]: "\<not>c \<Longrightarrow> b B \<Longrightarrow> d B \<Longrightarrow> (if c then a else b) = d \<longleftrightarrow> b = d"
by (rule iffI, simp+)
lemma [simp]: "c \<Longrightarrow> a B \<Longrightarrow> d B \<Longrightarrow> (if c then a else b) = d \<longleftrightarrow> a = d"
by (rule iffI, simp+)
lemma [simp]: "c \<Longrightarrow> (if c then True else b) = True"
by simp
lemma [simp]: "\<not>c \<Longrightarrow> (if c then a else True) = True"
by simp
lemma [cond]: "a \<Longrightarrow> a B"
unfolding bJudg_def by (rule disjI1, simp)
lemma [cond]: "\<not>a \<Longrightarrow> a B"
unfolding bJudg_def by (rule disjI2, simp)
lemma if_trueI [auto]: "c \<Longrightarrow> if c then True else False"
by simp
lemma [auto]: "True = True"
by simp
lemma not_false [auto]: "\<not>False"
proof (unfold False_def)
show "\<not>(S(0) = 0)"
proof -
have "S(0) \<noteq> 0" by (rule sucNonZero) (rule nat0)
then show ?thesis by (unfold neq_def)
qed
qed
lemma false_bool [auto]: "False B"
proof (unfold bJudg_def)
show "False \<or> \<not>False"
proof -
have "\<not>False" by (rule not_false)
then show ?thesis by (rule disjI2[where Q="\<not>False" and P="False"])
qed
qed
lemma disj_comm:
assumes q_or_r: "Q \<or> R"
shows "R \<or> Q"
proof (rule disjE1[where P="Q" and Q="R" and R="R \<or> Q"])
show "Q \<or> R" by (rule q_or_r)
show "Q \<Longrightarrow> R \<or> Q"
proof -
assume Q
then show "R \<or> Q" by (rule disjI2[where Q="Q" and P="R"])
qed
show "R \<Longrightarrow> R \<or> Q"
proof -
assume R
then show "R \<or> Q" by (rule disjI1[where P="R" and Q="Q"])
qed
qed
lemma not_bool [auto]:
assumes a_bool: "a B"
shows "(\<not>a) B"
apply (unfold GD.bJudg_def)
apply (rule disjE1[where P="\<not>a" and Q="a"])
apply (rule disj_comm)
apply (fold GD.bJudg_def)
apply (rule a_bool)
apply (unfold GD.bJudg_def)
apply (rule disjI1)
apply (assumption)
apply (rule disjI2)
apply (rule dNegI)
apply (assumption)
done
lemma neq_sym:
assumes a_nat: "a N"
assumes b_nat: "b N"
assumes ab_neq: "a \<noteq> b"
shows "b \<noteq> a"
proof (unfold neq_def, rule grounded_contradiction[where q="a=b"])
show "(\<not>(b=a)) B"
apply (auto)
apply (rule b_nat)
apply (rule a_nat)
done
next
assume H: "\<not> \<not> b = a"
show "a = b"
apply (rule eqSym)
apply (rule dNegE)
apply (rule H)
done
next
assume H: "\<not> \<not> b = a"
show "\<not> a = b"
apply (fold neq_def)
apply (rule ab_neq)
done
qed
lemma neq_bool [auto]: "a N \<Longrightarrow> b N \<Longrightarrow> (a \<noteq> b) B"
by simp
lemma sucNotEqual [auto]: "a N \<Longrightarrow> a \<noteq> S(a)"
proof (rule ind[where a="a"], simp)
show "0 \<noteq> S(0)"
by (rule neq_sym, simp)
show "\<And>x. x N \<Longrightarrow> (x\<noteq>S(x)) \<Longrightarrow> (S(x) \<noteq> S(S(x)))"
proof -
fix x
assume x_neq_s: "x \<noteq> S(x)"
show "x N \<Longrightarrow> S(x) \<noteq> S(S(x))"
proof (rule grounded_contradiction[where q="False"], simp)
assume H: "\<not> (S x \<noteq> S(S x))"
have eq_suc: "x = S(x)"
apply (rule sucInj)
apply (rule dNegE)
apply (fold neq_def)
apply (rule H)
done
then show "False"
apply (rule exF)
apply (fold neq_def)
apply (rule x_neq_s)
done
show "\<not> False"
by simp
qed
qed
qed
section \<open>Definitions of basic arithmetic functions\<close>
(* Use the recursion mechanism to define the standard arithmetic functions to
* be available in a global context.
* Axiomatizing them simply means that the fact that they are defined with the
* given definitions are axioms.
* User-defined functions should be in locales,
* not in axiomatization blocks.
*)
(*
recdef add :: "num \<Rightarrow> num \<Rightarrow> num" where
"add x y := if y = 0 then x else S(add x P(y))"
*)
axiomatization
add :: "num \<Rightarrow> num \<Rightarrow> num" (infixl "+" 60) and
sub :: "num \<Rightarrow> num \<Rightarrow> num" (infixl "-" 60) and
mult :: "num \<Rightarrow> num \<Rightarrow> num" (infixl "*" 70) and
div :: "num \<Rightarrow> num \<Rightarrow> num" and
less :: "num \<Rightarrow> num \<Rightarrow> num" (infix "<" 50) and
leq :: "num \<Rightarrow> num \<Rightarrow> num" (infix "\<le>" 50) and
omega :: "'a"
where
add_def: "add x y := if y = 0 then x else S(add x (P y))" and
sub_def: "sub x y := if y = 0 then x else P(sub x (P y))" and
mult_def: "mult x y := if y = 0 then 0 else (x + mult x (P y))" and
leq_def: "leq x y := if x = 0 then 1
else if y = 0 then 0
else (leq (P x) (P y))" and
less_def: "less x y := if y = 0 then 0
else if x = 0 then 1
else (less (P x) (P y))" and
div_def: "div x y := if x < y = 1 then 0 else S(div (x - y) y)" and
omega_def: "omega := omega"
definition greater :: "num \<Rightarrow> num \<Rightarrow> num" (infix ">" 50) where
"greater x y \<equiv> 1 - (x \<le> y)"
definition geq :: "num \<Rightarrow> num \<Rightarrow> num" (infix "\<ge>" 50) where
"geq x y \<equiv> 1 - (x < y)"
lemma less_0_false [simp, auto]: "(x < 0) = 0"
apply (rule defE[OF less_def])
apply (rule condI1)
apply (rule zeroRefl)
apply (rule nat0)
done
lemma add_terminates [auto]:
assumes x_nat: \<open>x N\<close>
assumes y_nat: \<open>y N\<close>
shows \<open>add x y N\<close>
proof (rule ind[where a=y])
show "y N" by (rule y_nat)
show "add x 0 N"
proof (rule defE[OF add_def])
show "if (0 = 0) then x else S(add x P(0)) N"
apply (rule eqSubst[where a="x"])
apply (rule eqSym)
apply (rule condI1)
apply (rule zeroRefl)
apply (rule x_nat)
apply (rule x_nat)
done
qed
show ind_step: "\<And>a. a N \<Longrightarrow> ((x + a) N) \<Longrightarrow> ((x + S(a)) N)"
proof (rule defE[OF add_def])
fix a
assume a_nat: "a N" and BC: "add x a N"
show "if (S(a) = 0) then x else S(add x P(S(a))) N"
proof (rule condT)
show "S(a) = 0 B"
apply (rule eqBool)
apply (rule natS)
apply (rule a_nat)
apply (rule nat0)
done
show "x N" by (rule x_nat)
show "S(add x P(S(a))) N"
apply (rule GD.natS)
apply (rule eqSubst[where a="x+a"])
apply (rule eqSubst[where a="a" and b="P(S(a))"])
apply (rule eqSym)
apply (rule predSucInv)
apply (rule a_nat)
apply (fold isNat_def)
apply (rule BC)
apply (rule BC)
done
qed
qed
qed
lemma cases_bool:
assumes q_bool: "q B"
assumes H: "q \<Longrightarrow> p"
assumes H1: "\<not>q \<Longrightarrow> p"
shows "p"
apply (rule disjE1[where P="q" and Q="\<not>q"])
apply (fold bJudg_def)
apply (rule q_bool)
apply (rule H)
apply (assumption)
apply (rule H1)
apply (assumption)
done
(*
declare [[simp_trace = true, simp_trace_depth_limit = 8]]
*)
lemma [auto]: "c B \<Longrightarrow> if c then True else True"
by simp
lemma [auto]: "c B \<Longrightarrow> \<not> (if c then False else False)"
by simp
lemma mult_terminates [auto]:
shows \<open>x N \<Longrightarrow> y N \<Longrightarrow> mult x y N\<close>
proof (rule ind[where a=y])
show "y N \<Longrightarrow> y N" by simp
show "x N \<Longrightarrow> mult x 0 N"
by (unfold_def mult_def, simp)
fix a
show "a N \<Longrightarrow> x N \<Longrightarrow> mult x a N \<Longrightarrow> mult x (S a) N"
by (unfold_def mult_def, rule condT, simp+)
qed
lemma [auto]: "x N \<Longrightarrow> \<not> S(x) = 0"
by (fold neq_def, auto)
lemma add_zero [simp, auto]:
assumes a_nat: "a N"
shows "a + 0 = a"
apply (unfold_def add_def)
apply (rule condI1)
apply (rule zeroRefl)
apply (rule a_nat)
done
lemma zero_add [simp, auto]:
shows "a N \<Longrightarrow> 0 + a = a"
proof (rule ind[where a="a"], simp)
fix x
assume hyp: "0 + x = x"
show "a N \<Longrightarrow> x N \<Longrightarrow> 0 + S x = S x"
by (unfold_def add_def, simp add: hyp)
qed
lemma add_succ [auto]:
shows "a N \<Longrightarrow> b N \<Longrightarrow> a + S b = S (a + b)"
apply (rule eqSym)
apply (unfold_def add_def)
apply (rule eqSym)
apply (simp)+
done
lemma mult_zero [simp, auto]: shows "a * 0 = 0" by (unfold_def mult_def, rule condI1, auto)
lemma zero_mult [simp, auto]:
shows "a N \<Longrightarrow> 0 * a = 0"
proof (rule ind[where a="a"], auto)
fix x
assume hyp: "0 * x = 0"
show "a N \<Longrightarrow> x N \<Longrightarrow> 0 * S x = 0"
by (unfold_def mult_def, simp add: hyp)
qed
lemma mult_one [simp, auto]:
shows "a N \<Longrightarrow> a * 1 = a"
by (unfold_def mult_def, simp)
lemma plus_one_suc [simp, auto]:
shows "a N \<Longrightarrow> 1 + a = S a"
proof (rule ind[where a="a"], auto)
fix x
assume hyp: "1+x = S x"
show "a N \<Longrightarrow> x N \<Longrightarrow> 1+(S x) = S S x"
by (unfold_def add_def, simp add: hyp)
qed
lemma one_plus_suc [simp, auto]:
shows "a N \<Longrightarrow> a + 1 = S a"
by (unfold_def add_def, simp)
lemma [auto]: "x N \<Longrightarrow> x = x"
by (fold isNat_def)
lemma one_mult [simp, auto]:
shows "a N \<Longrightarrow> 1 * a = a"
proof (rule ind[where a="a"], auto)
fix x
assume hyp: "1*x = x"
show "a N \<Longrightarrow> x N \<Longrightarrow> 1*(S x) = S x"
by (unfold_def mult_def, simp add: hyp)
qed
lemma zero_leq_true [simp, auto]:
assumes x_nat: "x N"
shows "0 \<le> x = 1"
by (unfold_def leq_def, rule condI1Eq, auto)
lemma leq_terminates [auto]:
shows "x N \<Longrightarrow> y N \<Longrightarrow> x \<le> y N"
proof -
have H: "y N \<Longrightarrow> \<forall>x. x\<le>y N"
proof (rule ind[where a="y"], simp)
show "\<forall>x'. x' \<le> 0 N"
apply (rule forallI)
apply (rule defE[OF leq_def])
apply (rule condT)
apply (rule eqBool)
apply (assumption)
apply (rule nat0)
apply (rule natS)
apply (rule nat0)
apply (rule eqSubst[where a="0"])
apply (rule eqSym)
apply (rule condI1)
apply (rule zeroRefl)
apply (rule nat0)+
done
show "\<And>x. x N \<Longrightarrow> (\<forall>xa. xa \<le> x N) \<Longrightarrow> (\<forall>xa. xa \<le> S(x) N)"
proof -
fix x
assume H: "\<forall>xa. xa \<le> x N"
show "x N \<Longrightarrow> \<forall>xa. xa \<le> S(x) N"
proof (rule forallI)
fix xa
show "x N \<Longrightarrow> xa N \<Longrightarrow> xa \<le> S(x) N"
apply (rule defE[OF leq_def])
apply (rule condT)
apply (rule eqBool)
apply (assumption)
apply (rule nat0)+
apply (rule natS, rule nat0)
apply (rule condT)
apply (rule eqBool)
apply (rule natS, assumption)
apply (rule nat0)+
apply (rule eqSubst[where a="x" and b="P S x"])
apply (rule eqSym, rule predSucInv, assumption)
apply (rule forallE[where a="P xa"])
apply (rule H)
apply (rule natP, assumption)
done
qed
qed
qed
then show "x N \<Longrightarrow> y N \<Longrightarrow> x \<le> y N"
by (rule forallE)
qed
lemma less_terminates [auto]:
shows "x N \<Longrightarrow> y N \<Longrightarrow> x < y N"
proof -
have q: "y N \<Longrightarrow> \<forall>x. x < y N"
proof (rule ind[where a="y"], simp)
show "\<forall>x. x < 0 N"
by (rule forallI, simp)
show "\<And>x. x N \<Longrightarrow> (\<forall>xa. xa < x N) \<Longrightarrow> (\<forall>xa. xa < S x N)"
proof (rule forallI)+
fix x y
assume hyp: "\<forall>xa. xa < x N"
show "x N \<Longrightarrow> y N \<Longrightarrow> y < S x N"
apply (unfold_def less_def)
apply (rule condT)
apply (simp+)
apply (rule condT)
apply (simp+)
apply (rule forallE[where a="P y"])
apply (rule hyp)
apply (simp)
done
qed
qed
show "x N \<Longrightarrow> y N \<Longrightarrow> x < y N"
by (rule forallE[where a="x"], rule q, simp)
qed
lemma leq_refl [simp, auto]:
shows "x N \<Longrightarrow> (x \<le> x) = 1"
proof (rule ind[where a="x"], simp)
show "\<And>x. x N \<Longrightarrow> (x \<le> x = 1) \<Longrightarrow> (S(x) \<le> S(x) = 1)"
proof -
fix x
assume x_refl: "x \<le> x = 1"
show "x N \<Longrightarrow> ((S(x)) \<le> S(x)) = 1"
apply (unfold_def leq_def)
apply (simp add: x_refl)+
done
qed
qed
lemma pred_leq [simp, auto]:
assumes z_nat: "z N"
shows "P(z) \<le> z = 1"
proof (rule ind[where a="z"])
show "z N" by (rule z_nat)
show "((P(0)) \<le> 0) = 1"
by (unfold_def leq_def, simp)
show "\<And>x. x N \<Longrightarrow> ((P(x))\<le>x = 1) \<Longrightarrow> (((P(S(x)))\<le>S(x)) = 1)"
proof -
fix x
assume ind_hyp: "((P(x)) \<le> x) = 1"
show "x N \<Longrightarrow> ((P(S(x))) \<le> (S(x))) = 1"
apply (unfold_def leq_def)
apply (rule condI3Eq)
apply (simp add: ind_hyp)+
done
qed
qed
lemma leq_suc [simp, auto]:
shows "x N \<Longrightarrow> x \<le> S(x) = 1"
apply (rule ind[where a="x"])
proof (auto)
fix x
assume hyp: "x \<le> S x = 1"
show "x N \<Longrightarrow> S x \<le> S S x = 1"
by (unfold_def leq_def, simp add: hyp)
qed
lemma less_suc [simp, auto]:
shows "x N \<Longrightarrow> x < S(x) = 1"
apply (rule ind[where a="x"], simp)
apply (unfold_def less_def, simp)+
done
lemma [auto]: "x N \<Longrightarrow> \<not> 0 = S x"
apply (fold neq_def)
apply (rule neq_sym)
apply (simp)
done
lemma leq_0:
shows "x N \<Longrightarrow> x \<le> 0 = 1 \<Longrightarrow> x = 0"
proof (rule grounded_contradiction[where q="False"])
show "x N \<Longrightarrow> x = 0 B" by (simp)
show "x N \<Longrightarrow> x \<le> 0 = 1 \<Longrightarrow> \<not> x = 0 \<Longrightarrow> False"
apply (rule exF[where P="x \<le> 0 = 1"])
apply (simp)
apply (rule eqSubst[where a="0" and b="x \<le> 0"])
apply (unfold_def leq_def)
apply (simp+)
done
show "\<not>False" by (simp)
qed
lemma leq_monotone_suc [simp]:
shows "x N \<Longrightarrow> y N \<Longrightarrow> x \<le> y = 1 \<Longrightarrow> S x \<le> S y = 1"
by (unfold_def leq_def, simp)
lemma num_cases:
shows "x N \<Longrightarrow> x = 0 \<or> (\<exists>y. x = S y)"
proof (rule ind[where a="x"], simp)
show "0 = 0 \<or> (\<exists>y. 0 = S y)" by (rule disjI1, simp)
show "\<And>x. x N \<Longrightarrow> x=0 \<or> (\<exists>y. x = S y) \<Longrightarrow> S x = 0 \<or> (\<exists>y. S x = S y)"
proof -
fix x
show "x N \<Longrightarrow> S x = 0 \<or> (\<exists>y. S x = S y)"
apply (rule disjI2)
apply (rule existsI[where a="x"])
apply (simp)
done
qed
qed
lemma num_nonzero [auto]:
"x N \<Longrightarrow> \<not> x = 0 \<Longrightarrow> \<exists>y. x = S(y)"
proof -
have "x N \<Longrightarrow> x = 0 \<or> (\<exists>y. x = S y)"
by (rule num_cases, simp)
then show "x N \<Longrightarrow> \<not> x = 0 \<Longrightarrow> \<exists>y. x = S(y)"
apply (rule disjE1, simp)
apply (rule exF[where P="x=0"], simp)
done
qed
lemma leq_nz_monotone:
shows "ya N \<Longrightarrow> \<not> xa = 0 \<Longrightarrow> xa \<le> ya = 1 \<Longrightarrow> ya \<noteq> 0"
proof (rule grounded_contradiction[where q="xa \<le> 0 = 1"])
show "ya N \<Longrightarrow> ya \<noteq> 0 B" by (simp)
show "\<not> ya \<noteq> 0 \<Longrightarrow> xa \<le> ya = 1 \<Longrightarrow> xa \<le> 0 = 1"
proof -
assume H: "\<not> ya \<noteq> 0"
have ya_nz: "ya = 0" by (rule dNegE, fold neq_def, rule H)
show "xa \<le> ya = 1 \<Longrightarrow> xa \<le> 0 = 1"
apply (rule eqSubst[where a="ya" and b="0"])
apply (rule ya_nz)
apply (rule eqSubst[where a="1" and b="S ya"])
apply (rule sucCong)
apply (rule eqSym)
apply (rule ya_nz)
apply (simp)
done
qed
show "\<not> xa = 0 \<Longrightarrow> \<not> xa \<le> 0 = 1"
apply (rule eqSubst[where a="0" and b="xa \<le> 0"])
apply (rule eqSym)
apply (unfold_def leq_def)
apply (simp)
done