-
Notifications
You must be signed in to change notification settings - Fork 140
/
arithmeticScript.sml
4483 lines (3957 loc) · 167 KB
/
arithmeticScript.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* ===================================================================== *)
(* FILE : mk_arithmetic.sml *)
(* DESCRIPTION : Definitions and properties of +,-,*,EXP, <=, >=, etc. *)
(* Translated from hol88. *)
(* *)
(* AUTHORS : (c) Mike Gordon and *)
(* Tom Melham, University of Cambridge *)
(* DATE : 88.04.02 *)
(* TRANSLATOR : Konrad Slind, University of Calgary *)
(* DATE : September 15, 1991 *)
(* ADDITIONS : December 22, 1992 *)
(* ===================================================================== *)
structure arithmeticScript =
struct
(* interactive use:
app load ["prim_recTheory", "Q", "metisLib", "boolSimps", "SatisfySimps"];
*)
open HolKernel boolLib Parse
Prim_rec simpLib boolSimps metisLib BasicProvers;
local open OpenTheoryMap
val ns = ["Number","Natural"]
in
fun ot0 x y = OpenTheory_const_name{const={Thy="arithmetic",Name=x},name=(ns,y)}
fun ot x = ot0 x x
fun otunwanted x = OpenTheory_const_name{const={Thy="arithmetic",Name=x},name=(["Unwanted"],"id")}
end
val _ = new_theory "arithmetic";
val _ = if !Globals.interactive then () else Feedback.emit_WARNING := false;
val NOT_SUC = numTheory.NOT_SUC
and INV_SUC = numTheory.INV_SUC
and INDUCTION = numTheory.INDUCTION;
val num_Axiom = prim_recTheory.num_Axiom;
val INV_SUC_EQ = prim_recTheory.INV_SUC_EQ
and LESS_REFL = prim_recTheory.LESS_REFL
and SUC_LESS = prim_recTheory.SUC_LESS
and NOT_LESS_0 = prim_recTheory.NOT_LESS_0
and LESS_MONO = prim_recTheory.LESS_MONO
and LESS_SUC_REFL = prim_recTheory.LESS_SUC_REFL
and LESS_SUC = prim_recTheory.LESS_SUC
and LESS_THM = prim_recTheory.LESS_THM
and LESS_SUC_IMP = prim_recTheory.LESS_SUC_IMP
and LESS_0 = prim_recTheory.LESS_0
and EQ_LESS = prim_recTheory.EQ_LESS
and SUC_ID = prim_recTheory.SUC_ID
and NOT_LESS_EQ = prim_recTheory.NOT_LESS_EQ
and LESS_NOT_EQ = prim_recTheory.LESS_NOT_EQ
and LESS_SUC_SUC = prim_recTheory.LESS_SUC_SUC
and PRE = prim_recTheory.PRE;
(*---------------------------------------------------------------------------*
* The basic arithmetic operations. *
*---------------------------------------------------------------------------*)
val ADD = new_recursive_definition
{name = "ADD",
rec_axiom = num_Axiom,
def = --`($+ 0 n = n) /\
($+ (SUC m) n = SUC($+ m n))`--};
val _ = set_fixity "+" (Infixl 500);
val _ = ot "+"
(*---------------------------------------------------------------------------*
* Define NUMERAL, a tag put on numeric literals, and the basic constructors *
* of the "numeral type". *
*---------------------------------------------------------------------------*)
val NUMERAL_DEF = new_definition("NUMERAL_DEF", --`NUMERAL (x:num) = x`--);
val ALT_ZERO = new_definition("ALT_ZERO", --`ZERO = 0`--);
local open OpenTheoryMap in
val _ = OpenTheory_const_name {const={Thy="arithmetic",Name="ZERO"},name=(["Number","Natural"],"zero")}
val _ = OpenTheory_const_name {const={Thy="num",Name="0"},name=(["Number","Natural"],"zero")}
end
val BIT1 =
new_definition("BIT1",
--`BIT1 n = n + (n + SUC 0)`--);
val BIT2 =
new_definition("BIT2",
--`BIT2 n = n + (n + SUC (SUC 0))`--);
val _ = new_definition(
GrammarSpecials.nat_elim_term,
--`^(mk_var(GrammarSpecials.nat_elim_term, Type`:num->num`)) n = n`--);
val _ = otunwanted "NUMERAL"
val _ = ot0 "BIT1" "bit1"
val _ = ot0 "BIT2" "bit2"
(*---------------------------------------------------------------------------*
* After this call, numerals parse into `NUMERAL( ... )` *
*---------------------------------------------------------------------------*)
val _ = add_numeral_form (#"n", NONE);
val _ = set_fixity "-" (Infixl 500);
val _ = Unicode.unicode_version {u = UTF8.chr 0x2212, tmnm = "-"};
val _ = TeX_notation {hol = UTF8.chr 0x2212, TeX = ("\\ensuremath{-}", 1)}
val SUB = new_recursive_definition
{name = "SUB",
rec_axiom = num_Axiom,
def = --`(0 - m = 0) /\
(SUC m - n = if m < n then 0 else SUC(m - n))`--};
val _ = ot "-"
(* Also add concrete syntax for unary negation so that future numeric types
can use it. We can't do anything useful with it for the natural numbers
of course, but it seems like this is the best ancestral place for it.
Descendents wanting to use this will include at least
integer, real, words, rat
*)
val _ = add_rule { term_name = "numeric_negate",
fixity = Prefix 900,
pp_elements = [TOK "-"],
paren_style = OnlyIfNecessary,
block_style = (AroundEachPhrase, (PP.CONSISTENT,0))};
(* Similarly, add syntax for the injection from nats symbol (&). This isn't
required in this theory, but will be used by descendents. *)
val _ = add_rule {term_name = GrammarSpecials.num_injection,
fixity = Prefix 900,
pp_elements = [TOK GrammarSpecials.num_injection],
paren_style = OnlyIfNecessary,
block_style = (AroundEachPhrase, (PP.CONSISTENT,0))};
(* overload it to the nat_elim term *)
val _ = overload_on (GrammarSpecials.num_injection,
mk_const(GrammarSpecials.nat_elim_term, ``:num -> num``))
val _ = set_fixity "*" (Infixl 600);
val MULT = new_recursive_definition
{name = "MULT",
rec_axiom = num_Axiom,
def = --`(0 * n = 0) /\
(SUC m * n = (m * n) + n)`--};
val _ = TeX_notation {hol = "*", TeX = ("\\HOLTokenProd{}", 1)}
val _ = ot "*"
val EXP = new_recursive_definition
{name = "EXP",
rec_axiom = num_Axiom,
def = --`($EXP m 0 = 1) /\
($EXP m (SUC n) = m * ($EXP m n))`--};
val _ = ot0 "EXP" "exp"
val _ = set_fixity "EXP" (Infixr 700);
val _ = add_infix("**", 700, HOLgrammars.RIGHT);
val _ = overload_on ("**", Term`$EXP`);
val _ = TeX_notation {hol = "**", TeX = ("\\HOLTokenExp{}", 2)}
(* special-case squares and cubes *)
val _ = add_rule {fixity = Suffix 2100,
term_name = UnicodeChars.sup_2,
block_style = (AroundEachPhrase,(PP.CONSISTENT, 0)),
paren_style = OnlyIfNecessary,
pp_elements = [TOK UnicodeChars.sup_2]}
val _ = overload_on (UnicodeChars.sup_2, ``\x. x ** 2``)
val _ = add_rule {fixity = Suffix 2100,
term_name = UnicodeChars.sup_3,
block_style = (AroundEachPhrase,(PP.CONSISTENT, 0)),
paren_style = OnlyIfNecessary,
pp_elements = [TOK UnicodeChars.sup_3]}
val _ = overload_on (UnicodeChars.sup_3, ``\x. x ** 3``)
val GREATER_DEF = new_definition("GREATER_DEF", ``$> m n = n < m``)
val _ = set_fixity ">" (Infix(NONASSOC, 450))
val _ = TeX_notation {hol = ">", TeX = ("\\HOLTokenGt{}", 1)}
val _ = ot ">"
val LESS_OR_EQ = new_definition ("LESS_OR_EQ", ``$<= m n = m < n \/ (m = n)``)
val _ = set_fixity "<=" (Infix(NONASSOC, 450))
val _ = Unicode.unicode_version { u = Unicode.UChar.leq, tmnm = "<="}
val _ = TeX_notation {hol = Unicode.UChar.leq, TeX = ("\\HOLTokenLeq{}", 1)}
val _ = TeX_notation {hol = "<=", TeX = ("\\HOLTokenLeq{}", 1)}
val _ = ot "<="
val GREATER_OR_EQ =
new_definition("GREATER_OR_EQ", ``$>= m n = m > n \/ (m = n)``)
val _ = set_fixity ">=" (Infix(NONASSOC, 450))
val _ = Unicode.unicode_version { u = Unicode.UChar.geq, tmnm = ">="};
val _ = TeX_notation {hol = ">=", TeX = ("\\HOLTokenGeq{}", 1)}
val _ = TeX_notation {hol = Unicode.UChar.geq, TeX = ("\\HOLTokenGeq{}", 1)}
val _ = ot ">="
val EVEN = new_recursive_definition
{name = "EVEN",
rec_axiom = num_Axiom,
def = --`(EVEN 0 = T) /\
(EVEN (SUC n) = ~EVEN n)`--};
val _ = ot0 "EVEN" "even"
val ODD = new_recursive_definition
{name = "ODD",
rec_axiom = num_Axiom,
def = --`(ODD 0 = F) /\
(ODD (SUC n) = ~ODD n)`--};
val _ = ot0 "ODD" "odd"
val num_case_def = new_recursive_definition
{name = "num_case_def",
rec_axiom = num_Axiom,
def = --`(num_case b f 0 = (b:'a)) /\
(num_case b f (SUC n) = f n)`--};
val FUNPOW = new_recursive_definition
{name = "FUNPOW",
rec_axiom = num_Axiom,
def = --`(FUNPOW f 0 x = x) /\
(FUNPOW f (SUC n) x = FUNPOW f n (f x))`--};
val NRC = new_recursive_definition {
name = "NRC",
rec_axiom = num_Axiom,
def = ``(NRC R 0 x y = (x = y)) /\
(NRC R (SUC n) x y = ?z. R x z /\ NRC R n z y)``};
val _ = overload_on ("RELPOW", ``NRC``)
val _ = overload_on ("NRC", ``NRC``)
(*---------------------------------------------------------------------------
THEOREMS
---------------------------------------------------------------------------*)
val ONE = store_thm("ONE", Term `1 = SUC 0`,
REWRITE_TAC [NUMERAL_DEF, BIT1, ALT_ZERO, ADD]);
val TWO = store_thm("TWO", Term`2 = SUC 1`,
REWRITE_TAC [NUMERAL_DEF, BIT2, ONE, ADD, ALT_ZERO,BIT1]);
val NORM_0 = store_thm("NORM_0",Term `NUMERAL ZERO = 0`,
REWRITE_TAC [NUMERAL_DEF, ALT_ZERO]);
fun INDUCT_TAC g = INDUCT_THEN INDUCTION ASSUME_TAC g;
val EQ_SYM_EQ' = INST_TYPE [alpha |-> Type`:num`] EQ_SYM_EQ;
(*---------------------------------------------------------------------------*)
(* Definition of num_case more suitable to call-by-value computations *)
(*---------------------------------------------------------------------------*)
val num_case_compute = store_thm("num_case_compute",
Term `!n. num_case (f:'a) g n = if n=0 then f else g (PRE n)`,
INDUCT_TAC THEN REWRITE_TAC [num_case_def,NOT_SUC,PRE]);
(* --------------------------------------------------------------------- *)
(* SUC_NOT = |- !n. ~(0 = SUC n) *)
(* --------------------------------------------------------------------- *)
val SUC_NOT = save_thm("SUC_NOT",
GEN (--`n:num`--) (NOT_EQ_SYM (SPEC (--`n:num`--) NOT_SUC)));
val ADD_0 = store_thm("ADD_0",
--`!m. m + 0 = m`--,
INDUCT_TAC
THEN ASM_REWRITE_TAC[ADD]);
val ADD_SUC = store_thm("ADD_SUC",
--`!m n. SUC(m + n) = (m + SUC n)`--,
INDUCT_TAC THEN ASM_REWRITE_TAC[ADD]);
val ADD_CLAUSES = store_thm("ADD_CLAUSES",
--`(0 + m = m) /\
(m + 0 = m) /\
(SUC m + n = SUC(m + n)) /\
(m + SUC n = SUC(m + n))`--,
REWRITE_TAC[ADD, ADD_0, ADD_SUC]);
val ADD_SYM = store_thm ("ADD_SYM",
--`!m n. m + n = n + m`--,
INDUCT_TAC
THEN ASM_REWRITE_TAC[ADD_0, ADD, ADD_SUC]);
val ADD_COMM = save_thm("ADD_COMM", ADD_SYM);
val ADD_ASSOC = store_thm ("ADD_ASSOC",
--`!m n p. m + (n + p) = (m + n) + p`--,
INDUCT_TAC
THEN ASM_REWRITE_TAC[ADD_CLAUSES]);
val num_CASES = store_thm ("num_CASES",
--`!m. (m = 0) \/ ?n. m = SUC n`--,
INDUCT_TAC
THEN REWRITE_TAC[NOT_SUC]
THEN EXISTS_TAC (--`(m:num)`--)
THEN REWRITE_TAC[]);
val NOT_ZERO_LT_ZERO = store_thm(
"NOT_ZERO_LT_ZERO",
Term`!n. ~(n = 0) = 0 < n`,
GEN_TAC THEN STRUCT_CASES_TAC (Q.SPEC `n` num_CASES) THEN
REWRITE_TAC [NOT_LESS_0, LESS_0, NOT_SUC]);
(* --------------------------------------------------------------------- *)
(* LESS_ADD proof rewritten: TFM 90.O9.21 *)
(* --------------------------------------------------------------------- *)
val LESS_ADD = store_thm ("LESS_ADD",
--`!m n. n<m ==> ?p. p+n = m`--,
INDUCT_TAC THEN GEN_TAC THEN
REWRITE_TAC[NOT_LESS_0,LESS_THM] THEN
REPEAT STRIP_TAC THENL
[EXISTS_TAC (--`SUC 0`--) THEN ASM_REWRITE_TAC[ADD],
RES_THEN (STRIP_THM_THEN (SUBST1_TAC o SYM)) THEN
EXISTS_TAC (--`SUC p`--) THEN REWRITE_TAC [ADD]]);
val LESS_TRANS = store_thm ("LESS_TRANS",
--`!m n p. (m < n) /\ (n < p) ==> (m < p)`--,
REPEAT GEN_TAC
THEN SPEC_TAC(--`(n:num)`--,--`(n:num)`--)
THEN SPEC_TAC(--`(m:num)`--,--`(m:num)`--)
THEN SPEC_TAC(--`(p:num)`--,--`(p:num)`--)
THEN INDUCT_TAC
THEN REWRITE_TAC[NOT_LESS_0, LESS_THM]
THEN REPEAT STRIP_TAC
THEN RES_TAC
THENL [SUBST_TAC[SYM(ASSUME (--`n:num = p`--))], ALL_TAC]
THEN ASM_REWRITE_TAC[]);
val LESS_ANTISYM = store_thm ("LESS_ANTISYM",
--`!m n. ~((m < n) /\ (n < m))`--,
REPEAT STRIP_TAC
THEN IMP_RES_TAC LESS_TRANS
THEN IMP_RES_TAC LESS_REFL);
val LESS_LESS_SUC = store_thm ("LESS_LESS_SUC",
--`!m n. ~((m < n) /\ (n < SUC m))`--,
REWRITE_TAC[LESS_THM]
THEN REPEAT STRIP_TAC
THEN IMP_RES_TAC LESS_TRANS
THEN IMP_RES_TAC(DISCH_ALL(SUBS[ASSUME(--`(n:num)=m`--)]
(ASSUME(--`m<n`--))))
THEN IMP_RES_TAC LESS_REFL
THEN ASM_REWRITE_TAC[]);
(* Doesn't belong here. kls. *)
val FUN_EQ_LEMMA = store_thm ("FUN_EQ_LEMMA",
--`!f:'a->bool. !x1 x2. f x1 /\ ~f x2 ==> ~(x1 = x2)`--,
REPEAT STRIP_TAC
THEN IMP_RES_TAC
(DISCH_ALL(SUBS[ASSUME (--`(x1:'a)=x2`--)]
(ASSUME(--`(f:'a->bool)x1`--))))
THEN RES_TAC
THEN ASM_REWRITE_TAC[]);
val transitive_measure = Q.store_thm(
"transitive_measure",
`!f. transitive (measure f)`,
SRW_TAC [][relationTheory.transitive_def,prim_recTheory.measure_thm]
THEN MATCH_MP_TAC LESS_TRANS
THEN SRW_TAC [SatisfySimps.SATISFY_ss][]);
(*---------------------------------------------------------------------------
* |- !m n. SUC m < SUC n = m < n
*---------------------------------------------------------------------------*)
val LESS_MONO_REV = store_thm ("LESS_MONO_REV",
--`!m n. SUC m < SUC n ==> m < n`--,
REPEAT GEN_TAC
THEN REWRITE_TAC[LESS_THM]
THEN STRIP_TAC
THEN IMP_RES_TAC SUC_LESS
THEN IMP_RES_TAC EQ_LESS
THEN ASM_REWRITE_TAC[]);
val LESS_MONO_EQ = save_thm("LESS_MONO_EQ",
GENL [--`m:num`--, --`n:num`--]
(IMP_ANTISYM_RULE (SPEC_ALL LESS_MONO_REV)
(SPEC_ALL LESS_MONO)));
val LESS_OR = store_thm ("LESS_OR",
--`!m n. m < n ==> SUC m <= n`--,
REWRITE_TAC[LESS_OR_EQ]
THEN GEN_TAC THEN INDUCT_TAC
THEN REWRITE_TAC[NOT_LESS_0,LESS_MONO_EQ,INV_SUC_EQ, LESS_THM]
THEN STRIP_TAC THENL [ALL_TAC, RES_TAC] THEN ASM_REWRITE_TAC[]);
val LESS_SUC_EQ = LESS_OR;
val OR_LESS = store_thm ("OR_LESS",
--`!m n. (SUC m <= n) ==> (m < n)`--,
REPEAT GEN_TAC
THEN REWRITE_TAC[LESS_OR_EQ]
THEN STRIP_TAC
THEN IMP_RES_TAC SUC_LESS
THEN IMP_RES_TAC EQ_LESS
THEN ASM_REWRITE_TAC[]);
(* |- !m n. (m < n) = (SUC m <= n) *)
val LESS_EQ = save_thm("LESS_EQ",
GENL [--`m:num`--, --`n:num`--]
(IMP_ANTISYM_RULE (SPEC_ALL LESS_OR)
(SPEC_ALL OR_LESS)));
val LESS_SUC_EQ_COR = store_thm ("LESS_SUC_EQ_COR",
--`!m n. ((m < n) /\ (~(SUC m = n))) ==> (SUC m < n)`--,
REPEAT STRIP_TAC
THEN IMP_RES_TAC LESS_SUC_EQ
THEN MP_TAC(ASSUME (--`(SUC m) <= n`--))
THEN REWRITE_TAC[LESS_OR_EQ]
THEN REPEAT STRIP_TAC
THEN RES_TAC); (* RES_TAC doesn't solve the goal when --`F`-- is
in the assumptions *)
val LESS_NOT_SUC = store_thm("LESS_NOT_SUC",
--`!m n. (m < n) /\ ~(n = SUC m) ==> SUC m < n`--,
REPEAT GEN_TAC
THEN ASM_CASES_TAC (--`n = SUC m`--)
THEN ASM_REWRITE_TAC[]
THEN STRIP_TAC
THEN MP_TAC(REWRITE_RULE[LESS_OR_EQ]
(EQ_MP(SPEC_ALL LESS_EQ)
(ASSUME (--`m < n`--))))
THEN STRIP_TAC
THEN ASSUME_TAC(SYM(ASSUME (--`SUC m = n`--)))
THEN RES_TAC); (* RES_TAC doesn't solve --`F`-- in assumptions *)
val LESS_0_CASES = store_thm("LESS_0_CASES",
--`!m. (0 = m) \/ 0<m`--,
INDUCT_TAC
THEN REWRITE_TAC[LESS_0]);
val LESS_CASES_IMP = store_thm("LESS_CASES_IMP",
--`!m n. ~(m < n) /\ ~(m = n) ==> (n < m)`--,
GEN_TAC
THEN INDUCT_TAC
THEN STRIP_TAC
THENL
[MP_TAC(ASSUME (--`~(m = 0)`--))
THEN ACCEPT_TAC
(DISJ_IMP
(SUBS
[SPECL[--`0`--, --`m:num`--]EQ_SYM_EQ']
(SPEC_ALL LESS_0_CASES))),
MP_TAC(ASSUME (--`~(m < (SUC n))`--))
THEN REWRITE_TAC[LESS_THM, DE_MORGAN_THM]
THEN STRIP_TAC
THEN RES_TAC
THEN IMP_RES_TAC LESS_NOT_SUC
THEN ASM_REWRITE_TAC[]]);
val LESS_CASES = store_thm("LESS_CASES",
--`!m n. (m < n) \/ (n <= m)`--,
REPEAT GEN_TAC
THEN ASM_REWRITE_TAC[LESS_OR_EQ, DE_MORGAN_THM]
THEN ASM_CASES_TAC (--`(m:num) = n`--)
THEN ASM_CASES_TAC (--`m < n`--)
THEN IMP_RES_TAC LESS_CASES_IMP
THEN ASM_REWRITE_TAC[]);
val ADD_INV_0 = store_thm("ADD_INV_0",
--`!m n. (m + n = m) ==> (n = 0)`--,
INDUCT_TAC THEN ASM_REWRITE_TAC[ADD_CLAUSES, INV_SUC_EQ]);
val LESS_EQ_ADD = store_thm ("LESS_EQ_ADD",
--`!m n. m <= m + n`--,
GEN_TAC
THEN REWRITE_TAC[LESS_OR_EQ]
THEN INDUCT_TAC
THEN ASM_REWRITE_TAC[ADD_CLAUSES]
THEN MP_TAC(ASSUME (--`(m < (m + n)) \/ (m = (m + n))`--))
THEN STRIP_TAC
THENL
[IMP_RES_TAC LESS_SUC
THEN ASM_REWRITE_TAC[],
REWRITE_TAC[SYM(ASSUME (--`m = m + n`--)),LESS_SUC_REFL]]);
val LESS_EQ_ADD_EXISTS = store_thm ("LESS_EQ_ADD_EXISTS",
--`!m n. n<=m ==> ?p. p+n = m`--,
SIMP_TAC bool_ss [LESS_OR_EQ, DISJ_IMP_THM, FORALL_AND_THM,
LESS_ADD]
THEN GEN_TAC
THEN EXISTS_TAC (--`0`--)
THEN REWRITE_TAC[ADD]);
val LESS_STRONG_ADD = store_thm ("LESS_STRONG_ADD",
--`!m n. n < m ==> ?p. (SUC p)+n = m`--,
REPEAT STRIP_TAC
THEN IMP_RES_TAC LESS_OR
THEN IMP_RES_TAC LESS_EQ_ADD_EXISTS
THEN EXISTS_TAC (--`p:num`--)
THEN FULL_SIMP_TAC bool_ss [ADD_CLAUSES]);
val LESS_EQ_SUC_REFL = store_thm ("LESS_EQ_SUC_REFL",
--`!m. m <= SUC m`--,
GEN_TAC
THEN REWRITE_TAC[LESS_OR_EQ,LESS_SUC_REFL]);
val LESS_ADD_NONZERO = store_thm ("LESS_ADD_NONZERO",
--`!m n. ~(n = 0) ==> m < m + n`--,
GEN_TAC
THEN INDUCT_TAC
THEN REWRITE_TAC[NOT_SUC,ADD_CLAUSES]
THEN ASM_CASES_TAC (--`n = 0`--)
THEN ASSUME_TAC(SPEC (--`m + n`--) LESS_SUC_REFL)
THEN RES_TAC
THEN IMP_RES_TAC LESS_TRANS
THEN ASM_REWRITE_TAC[ADD_CLAUSES,LESS_SUC_REFL]);
val LESS_EQ_ANTISYM = store_thm ("LESS_EQ_ANTISYM",
--`!m n. ~(m < n /\ n <= m)`--,
REWRITE_TAC[LESS_OR_EQ]
THEN REPEAT STRIP_TAC
THEN IMP_RES_TAC LESS_ANTISYM
THEN ASM_REWRITE_TAC[]
THEN ASSUME_TAC(SYM(ASSUME (--`(n:num) = m`--)))
THEN IMP_RES_TAC NOT_LESS_EQ
THEN ASM_REWRITE_TAC[]);
val NOT_LESS = store_thm ("NOT_LESS",
--`!m n. ~(m < n) = (n <= m)`--,
REPEAT GEN_TAC
THEN ASM_CASES_TAC (--`m < n`--)
THEN ASM_CASES_TAC (--`n <= m`--)
THEN IMP_RES_TAC(DISJ_IMP(SPEC_ALL LESS_CASES))
THEN IMP_RES_TAC(CONTRAPOS(DISJ_IMP(SPEC_ALL LESS_CASES)))
THEN RES_TAC
THEN IMP_RES_TAC LESS_EQ_ANTISYM
THEN ASM_REWRITE_TAC[]);
val _ = print "Now proving properties of subtraction\n"
val SUB_0 = store_thm ("SUB_0",
--`!m. (0 - m = 0) /\ (m - 0 = m)`--,
INDUCT_TAC
THEN ASM_REWRITE_TAC[SUB, NOT_LESS_0]);
(* I was exhausted when I did the proof below - it can almostly certainly be
drastically shortened. *)
val SUB_EQ_0 = store_thm ("SUB_EQ_0",
--`!m n. (m - n = 0) = (m <= n)`--,
INDUCT_TAC
THEN GEN_TAC
THEN REWRITE_TAC[SUB,LESS_OR_EQ]
THENL
[REWRITE_TAC[SPECL[--`0 < n`--, --`0 = n`--]DISJ_SYM,LESS_0_CASES],
ALL_TAC]
THEN ASM_CASES_TAC (--`m < n`--)
THEN ASM_CASES_TAC (--`SUC m = n`--)
THEN IMP_RES_TAC EQ_LESS
THEN IMP_RES_TAC LESS_SUC_EQ_COR
THEN IMP_RES_TAC(fst(EQ_IMP_RULE(SPEC_ALL NOT_LESS)))
THEN IMP_RES_TAC(fst(EQ_IMP_RULE(SPEC_ALL LESS_OR_EQ)))
THEN ASM_REWRITE_TAC
[SPECL[--`(n:num)=m`--,--`n<m`--]DISJ_SYM,
NOT_SUC,NOT_LESS,LESS_OR_EQ,LESS_THM]);
val ADD1 = store_thm ("ADD1",
--`!m. SUC m = m + 1`--,
INDUCT_TAC THENL [
REWRITE_TAC [ADD_CLAUSES, ONE],
ASM_REWRITE_TAC [] THEN REWRITE_TAC [ONE, ADD_CLAUSES]
]);
val SUC_SUB1 = store_thm("SUC_SUB1",
--`!m. SUC m - 1 = m`--,
INDUCT_TAC THENL [
REWRITE_TAC [SUB, LESS_0, ONE],
PURE_ONCE_REWRITE_TAC[SUB] THEN
ASM_REWRITE_TAC[NOT_LESS_0, LESS_MONO_EQ, ONE]
]);
val PRE_SUB1 = store_thm ("PRE_SUB1",
--`!m. (PRE m = (m - 1))`--,
GEN_TAC
THEN STRUCT_CASES_TAC(SPEC (--`m:num`--) num_CASES)
THEN ASM_REWRITE_TAC[PRE, CONJUNCT1 SUB, SUC_SUB1]);
val MULT_0 = store_thm ("MULT_0",
--`!m. m * 0 = 0`--,
INDUCT_TAC
THEN ASM_REWRITE_TAC[MULT,ADD_CLAUSES]);
val MULT_SUC = store_thm ("MULT_SUC",
--`!m n. m * (SUC n) = m + m*n`--,
INDUCT_TAC
THEN ASM_REWRITE_TAC[MULT,ADD_CLAUSES,ADD_ASSOC]);
val MULT_LEFT_1 = store_thm ("MULT_LEFT_1",
--`!m. 1 * m = m`--,
GEN_TAC THEN REWRITE_TAC[ONE, MULT,ADD_CLAUSES]);
val MULT_RIGHT_1 = store_thm ("MULT_RIGHT_1",
--`!m. m * 1 = m`--,
REWRITE_TAC [ONE] THEN INDUCT_TAC THEN
ASM_REWRITE_TAC[MULT, ADD_CLAUSES]);
val MULT_CLAUSES = store_thm ("MULT_CLAUSES",
--`!m n. (0 * m = 0) /\
(m * 0 = 0) /\
(1 * m = m) /\
(m * 1 = m) /\
(SUC m * n = m * n + n) /\
(m * SUC n = m + m * n)`--,
REWRITE_TAC[MULT,MULT_0,MULT_LEFT_1,MULT_RIGHT_1,MULT_SUC]);
val MULT_SYM = store_thm("MULT_SYM",
--`!m n. m * n = n * m`--,
INDUCT_TAC
THEN GEN_TAC
THEN ASM_REWRITE_TAC[MULT_CLAUSES,SPECL[--`m*n`--,--`n:num`--]ADD_SYM]);
val MULT_COMM = save_thm("MULT_COMM", MULT_SYM);
val RIGHT_ADD_DISTRIB = store_thm ("RIGHT_ADD_DISTRIB",
--`!m n p. (m + n) * p = (m * p) + (n * p)`--,
GEN_TAC
THEN GEN_TAC
THEN INDUCT_TAC
THEN ASM_REWRITE_TAC[MULT_CLAUSES,ADD_CLAUSES,ADD_ASSOC]
THEN REWRITE_TAC[SPECL[--`m+(m*p)`--,--`n:num`--]ADD_SYM,ADD_ASSOC]
THEN SUBST_TAC[SPEC_ALL ADD_SYM]
THEN REWRITE_TAC[]);
(* A better proof of LEFT_ADD_DISTRIB would be using
MULT_SYM and RIGHT_ADD_DISTRIB *)
val LEFT_ADD_DISTRIB = store_thm ("LEFT_ADD_DISTRIB",
--`!m n p. p * (m + n) = (p * m) + (p * n)`--,
GEN_TAC
THEN GEN_TAC
THEN INDUCT_TAC
THEN ASM_REWRITE_TAC[MULT_CLAUSES,ADD_CLAUSES,SYM(SPEC_ALL ADD_ASSOC)]
THEN REWRITE_TAC[SPECL[--`m:num`--,--`(p*n)+n`--]ADD_SYM,
SYM(SPEC_ALL ADD_ASSOC)]
THEN SUBST_TAC[SPEC_ALL ADD_SYM]
THEN REWRITE_TAC[]);
val MULT_ASSOC = store_thm ("MULT_ASSOC",
--`!m n p. m * (n * p) = (m * n) * p`--,
INDUCT_TAC
THEN ASM_REWRITE_TAC[MULT_CLAUSES,RIGHT_ADD_DISTRIB]);
val SUB_ADD = store_thm ("SUB_ADD",
--`!m n. (n <= m) ==> ((m - n) + n = m)`--,
INDUCT_TAC
THEN REWRITE_TAC[LESS_OR_EQ]
THEN REPEAT STRIP_TAC
THEN ASM_REWRITE_TAC[SUB,ADD_CLAUSES,LESS_SUC_REFL]
THEN IMP_RES_TAC NOT_LESS_0
THEN ASM_CASES_TAC (--`m < n`--)
THEN IMP_RES_TAC LESS_LESS_SUC
THEN IMP_RES_TAC(fst(EQ_IMP_RULE(SPEC_ALL NOT_LESS)))
THEN RES_TAC
THEN ASM_REWRITE_TAC[ADD_CLAUSES]);
val PRE_SUB = store_thm ("PRE_SUB",
--`!m n. PRE(m - n) = (PRE m) - n`--,
INDUCT_TAC
THEN GEN_TAC
THEN ASM_REWRITE_TAC[SUB,PRE]
THEN ASM_CASES_TAC (--`m < n`--)
THEN ASM_REWRITE_TAC
[PRE,LESS_OR_EQ,
SUBS[SPECL[--`m-n`--,--`0`--]EQ_SYM_EQ']
(SPECL [--`m:num`--,--`n:num`--] SUB_EQ_0)])
val ADD_EQ_0 = store_thm ("ADD_EQ_0",
--`!m n. (m + n = 0) = (m = 0) /\ (n = 0)`--,
INDUCT_TAC
THEN GEN_TAC
THEN ASM_REWRITE_TAC[ADD_CLAUSES,NOT_SUC]);
val ADD_EQ_1 = store_thm(
"ADD_EQ_1",
--`!m n. (m + n = 1) = (m = 1) /\ (n = 0) \/ (m = 0) /\ (n = 1)`--,
INDUCT_TAC THENL [
REWRITE_TAC [ADD_CLAUSES, ONE, GSYM NOT_SUC],
REWRITE_TAC [NOT_SUC, ADD_CLAUSES, ONE, INV_SUC_EQ, ADD_EQ_0]
]);
val ADD_INV_0_EQ = store_thm ("ADD_INV_0_EQ",
--`!m n. (m + n = m) = (n = 0)`--,
REPEAT GEN_TAC
THEN EQ_TAC
THEN REWRITE_TAC[ADD_INV_0]
THEN STRIP_TAC
THEN ASM_REWRITE_TAC[ADD_CLAUSES]);
val PRE_SUC_EQ = store_thm ("PRE_SUC_EQ",
--`!m n. 0<n ==> ((m = PRE n) = (SUC m = n))`--,
INDUCT_TAC
THEN INDUCT_TAC
THEN REWRITE_TAC[PRE,LESS_REFL,INV_SUC_EQ]);
val INV_PRE_EQ = store_thm ("INV_PRE_EQ",
--`!m n. 0<m /\ 0<n ==> ((PRE m = (PRE n)) = (m = n))`--,
INDUCT_TAC
THEN INDUCT_TAC
THEN REWRITE_TAC[PRE,LESS_REFL,INV_SUC_EQ]);
val LESS_SUC_NOT = store_thm ("LESS_SUC_NOT",
--`!m n. (m < n) ==> ~(n < SUC m)`--,
REPEAT GEN_TAC
THEN ASM_REWRITE_TAC[NOT_LESS]
THEN REPEAT STRIP_TAC
THEN IMP_RES_TAC LESS_OR
THEN ASM_REWRITE_TAC[]);
(* About now I burned out and resorted to dreadful hacks. The name of the
next theorem speaks for itself. *)
val TOTALLY_AD_HOC_LEMMA = prove
(--`!m n. (m + SUC n = n) = (SUC m = 0)`--,
REPEAT GEN_TAC
THEN REWRITE_TAC
[NOT_SUC,SYM(SPECL [--`m:num`--,--`n:num`--] (CONJUNCT2 ADD)),
(fn [_, _, _, th] => th | _ => raise Match) (CONJUNCTS ADD_CLAUSES)]
THEN REWRITE_TAC[SPECL[--`SUC m`--,--`n:num`--]ADD_SYM]
THEN STRIP_TAC
THEN IMP_RES_TAC ADD_INV_0
THEN IMP_RES_TAC NOT_SUC);
(* The next proof took me ages - there must be a better way! *)
val ADD_EQ_SUB = store_thm ("ADD_EQ_SUB",
--`!m n p. (n <= p) ==> (((m + n) = p) = (m = (p - n)))`--,
INDUCT_TAC
THEN INDUCT_TAC
THEN INDUCT_TAC
THEN ASM_REWRITE_TAC
[LESS_OR_EQ,ADD_CLAUSES,NOT_LESS_0,INV_SUC_EQ,LESS_MONO_EQ,
NOT_SUC,NOT_EQ_SYM(SPEC_ALL NOT_SUC),LESS_0,SUB,SUB_0]
THEN STRIP_TAC
THEN IMP_RES_TAC LESS_NOT_EQ
THEN ASM_REWRITE_TAC[LESS_SUC_REFL]
THEN IMP_RES_TAC LESS_SUC_NOT
THEN ASM_REWRITE_TAC[NOT_EQ_SYM(SPEC_ALL NOT_SUC),INV_SUC_EQ]
THEN IMP_RES_TAC(fst(EQ_IMP_RULE(SPEC_ALL NOT_LESS)))
THEN RES_TAC
THEN ASM_REWRITE_TAC
[SYM ((fn [_, _, _, th] => th | _ => raise Match)
(CONJUNCTS (SPEC_ALL ADD_CLAUSES))),
TOTALLY_AD_HOC_LEMMA]);
val LESS_MONO_ADD = store_thm ("LESS_MONO_ADD",
--`!m n p. (m < n) ==> (m + p) < (n + p)`--,
GEN_TAC
THEN GEN_TAC
THEN INDUCT_TAC
THEN DISCH_TAC
THEN RES_TAC
THEN ASM_REWRITE_TAC[ADD_CLAUSES,LESS_MONO_EQ]);
val LESS_MONO_ADD_INV = store_thm ("LESS_MONO_ADD_INV",
--`!m n p. (m + p) < (n + p) ==> (m < n)`--,
GEN_TAC
THEN GEN_TAC
THEN INDUCT_TAC
THEN ASM_REWRITE_TAC[ADD_CLAUSES,LESS_MONO_EQ]);
val LESS_MONO_ADD_EQ = store_thm ("LESS_MONO_ADD_EQ",
--`!m n p. ((m + p) < (n + p)) = (m < n)`--,
REPEAT GEN_TAC
THEN EQ_TAC
THEN REWRITE_TAC[LESS_MONO_ADD,LESS_MONO_ADD_INV]);
val LT_ADD_RCANCEL = save_thm("LT_ADD_RCANCEL", LESS_MONO_ADD_EQ)
val LT_ADD_LCANCEL = save_thm("LT_ADD_LCANCEL",
ONCE_REWRITE_RULE [ADD_COMM] LT_ADD_RCANCEL)
val EQ_MONO_ADD_EQ = store_thm ("EQ_MONO_ADD_EQ",
--`!m n p. ((m + p) = (n + p)) = (m = n)`--,
GEN_TAC
THEN GEN_TAC
THEN INDUCT_TAC
THEN ASM_REWRITE_TAC[ADD_CLAUSES,INV_SUC_EQ]);
val _ = print "Proving properties of <=\n"
val LESS_EQ_MONO_ADD_EQ = store_thm ("LESS_EQ_MONO_ADD_EQ",
--`!m n p. ((m + p) <= (n + p)) = (m <= n)`--,
REPEAT GEN_TAC
THEN REWRITE_TAC[LESS_OR_EQ]
THEN REPEAT STRIP_TAC
THEN REWRITE_TAC[LESS_MONO_ADD_EQ,EQ_MONO_ADD_EQ]);
val LESS_EQ_TRANS = store_thm ("LESS_EQ_TRANS",
--`!m n p. (m <= n) /\ (n <= p) ==> (m <= p)`--,
REWRITE_TAC[LESS_OR_EQ]
THEN REPEAT STRIP_TAC
THEN IMP_RES_TAC LESS_TRANS
THEN ASM_REWRITE_TAC[]
THEN SUBST_TAC[SYM(ASSUME (--`(n:num) = p`--))]
THEN ASM_REWRITE_TAC[]);
(* % Proof modified for new IMP_RES_TAC [TFM 90.04.25] *)
val LESS_EQ_LESS_EQ_MONO = store_thm ("LESS_EQ_LESS_EQ_MONO",
--`!m n p q. (m <= p) /\ (n <= q) ==> ((m + n) <= (p + q))`--,
REPEAT STRIP_TAC THEN
let val th1 = snd(EQ_IMP_RULE (SPEC_ALL LESS_EQ_MONO_ADD_EQ))
val th2 = PURE_ONCE_REWRITE_RULE [ADD_SYM] th1
in
IMP_RES_THEN (ASSUME_TAC o SPEC (--`n:num`--)) th1 THEN
IMP_RES_THEN (ASSUME_TAC o SPEC (--`p:num`--)) th2 THEN
IMP_RES_TAC LESS_EQ_TRANS
end);
val LESS_EQ_REFL = store_thm ("LESS_EQ_REFL",
--`!m. m <= m`--,
GEN_TAC
THEN REWRITE_TAC[LESS_OR_EQ]);
val LESS_IMP_LESS_OR_EQ = store_thm ("LESS_IMP_LESS_OR_EQ",
--`!m n. (m < n) ==> (m <= n)`--,
REPEAT STRIP_TAC
THEN ASM_REWRITE_TAC[LESS_OR_EQ]);
val LESS_MONO_MULT = store_thm ("LESS_MONO_MULT",
--`!m n p. (m <= n) ==> ((m * p) <= (n * p))`--,
GEN_TAC
THEN GEN_TAC
THEN INDUCT_TAC
THEN DISCH_TAC
THEN ASM_REWRITE_TAC
[ADD_CLAUSES,MULT_CLAUSES,LESS_EQ_MONO_ADD_EQ,LESS_EQ_REFL]
THEN RES_TAC
THEN IMP_RES_TAC(SPECL[--`m:num`--,--`m*p`--,--`n:num`--,--`n*p`--]
LESS_EQ_LESS_EQ_MONO)
THEN ASM_REWRITE_TAC[]);
val LESS_MONO_MULT2 = store_thm(
"LESS_MONO_MULT2",
``!m n i j. m <= i /\ n <= j ==> m * n <= i * j``,
mesonLib.MESON_TAC [LESS_EQ_TRANS, LESS_MONO_MULT, MULT_COMM]);
(* Proof modified for new IMP_RES_TAC [TFM 90.04.25] *)
val RIGHT_SUB_DISTRIB = store_thm ("RIGHT_SUB_DISTRIB",
--`!m n p. (m - n) * p = (m * p) - (n * p)`--,
REPEAT GEN_TAC THEN
ASM_CASES_TAC (--`n <= m`--) THENL
[let val imp = SPECL [--`(m-n)*p`--,
--`n*p`--,
--`m*p`--] ADD_EQ_SUB
in
IMP_RES_THEN (SUBST1_TAC o SYM o MP imp o SPEC (--`p:num`--))
LESS_MONO_MULT THEN
REWRITE_TAC[SYM(SPEC_ALL RIGHT_ADD_DISTRIB)] THEN
IMP_RES_THEN SUBST1_TAC SUB_ADD THEN REFL_TAC
end,
IMP_RES_TAC (REWRITE_RULE[](AP_TERM (--`$~`--)
(SPEC_ALL NOT_LESS))) THEN
IMP_RES_TAC LESS_IMP_LESS_OR_EQ THEN
IMP_RES_THEN (ASSUME_TAC o SPEC (--`p:num`--)) LESS_MONO_MULT THEN
IMP_RES_TAC SUB_EQ_0 THEN
ASM_REWRITE_TAC[MULT_CLAUSES]]);
val LEFT_SUB_DISTRIB = store_thm("LEFT_SUB_DISTRIB",
--`!m n p. p * (m - n) = (p * m) - (p * n)`--,
PURE_ONCE_REWRITE_TAC [MULT_SYM] THEN
REWRITE_TAC [RIGHT_SUB_DISTRIB]);
(* The following theorem (and proof) are from tfm [rewritten TFM 90.09.21] *)
val LESS_ADD_1 = store_thm ("LESS_ADD_1",
--`!m n. (n<m) ==> ?p. m = n + (p + 1)`--,
REWRITE_TAC [ONE] THEN INDUCT_TAC THEN
REWRITE_TAC[NOT_LESS_0,LESS_THM] THEN
REPEAT STRIP_TAC THENL [
EXISTS_TAC (--`0`--) THEN ASM_REWRITE_TAC [ADD_CLAUSES],
RES_THEN (STRIP_THM_THEN SUBST1_TAC) THEN
EXISTS_TAC (--`SUC p`--) THEN REWRITE_TAC [ADD_CLAUSES]
]);
(* ---------------------------------------------------------------------*)
(* The following arithmetic theorems were added by TFM in 88.03.31 *)
(* *)
(* These are needed to build the recursive type definition package *)
(* ---------------------------------------------------------------------*)
val EXP_ADD = store_thm ("EXP_ADD",
--`!p q n. n EXP (p+q) = (n EXP p) * (n EXP q)`--,
INDUCT_TAC THEN
ASM_REWRITE_TAC [EXP,ADD_CLAUSES,MULT_CLAUSES,MULT_ASSOC]);
val NOT_ODD_EQ_EVEN = store_thm ("NOT_ODD_EQ_EVEN",
--`!n m. ~(SUC(n + n) = (m + m))`--,
REPEAT (INDUCT_TAC THEN REWRITE_TAC [ADD_CLAUSES]) THENL
[MATCH_ACCEPT_TAC NOT_SUC,
REWRITE_TAC [INV_SUC_EQ,NOT_EQ_SYM (SPEC_ALL NOT_SUC)],
REWRITE_TAC [INV_SUC_EQ,NOT_SUC],
ASM_REWRITE_TAC [INV_SUC_EQ]]);
val MULT_SUC_EQ = store_thm ("MULT_SUC_EQ",
--`!p m n. ((n * (SUC p)) = (m * (SUC p))) = (n = m)`--,
REPEAT STRIP_TAC THEN
STRIP_ASSUME_TAC (REWRITE_RULE [LESS_OR_EQ] (SPEC_ALL LESS_CASES)) THEN
ASM_REWRITE_TAC [] THENL
[ ALL_TAC
,
ONCE_REWRITE_TAC [EQ_SYM_EQ'] THEN
POP_ASSUM MP_TAC THEN
(MAP_EVERY SPEC_TAC [(--`m:num`--,--`m:num`--),
(--`n:num`--,--`n:num`--)
]) THEN
MAP_EVERY X_GEN_TAC [--`m:num`--,--`n:num`--] THEN
DISCH_TAC
] THEN
IMP_RES_THEN (fn th => REWRITE_TAC [NOT_EQ_SYM th]) LESS_NOT_EQ THEN
POP_ASSUM (STRIP_THM_THEN SUBST1_TAC o MATCH_MP LESS_ADD_1) THEN
REWRITE_TAC [MULT_CLAUSES,SYM(SPEC_ALL ADD_ASSOC)] THEN
ONCE_REWRITE_TAC [ADD_SYM] THEN REWRITE_TAC [EQ_MONO_ADD_EQ] THEN
REWRITE_TAC [RIGHT_ADD_DISTRIB,MULT_CLAUSES] THEN
ONCE_REWRITE_TAC [SPEC (--`p * q`--) ADD_SYM] THEN
ONCE_REWRITE_TAC [EQ_SYM_EQ] THEN
REWRITE_TAC [ADD_ASSOC,REWRITE_RULE [ADD_CLAUSES]
(SPEC (--`0`--) EQ_MONO_ADD_EQ)] THEN
ONCE_REWRITE_TAC [EQ_SYM_EQ] THEN
REWRITE_TAC [ONE, ADD_CLAUSES,NOT_SUC]);
val MULT_EXP_MONO = store_thm ("MULT_EXP_MONO",
--`!p q n m.((n * ((SUC q) EXP p)) = (m * ((SUC q) EXP p))) = (n = m)`--,
INDUCT_TAC THENL
[REWRITE_TAC [EXP,MULT_CLAUSES,ADD_CLAUSES],
ASM_REWRITE_TAC [EXP,MULT_ASSOC,MULT_SUC_EQ]]);
val LESS_EQUAL_ANTISYM = store_thm ("LESS_EQUAL_ANTISYM",
--`!n m. n <= m /\ m <= n ==> (n = m)`--,
REWRITE_TAC [LESS_OR_EQ] THEN
REPEAT STRIP_TAC THENL
[IMP_RES_TAC LESS_ANTISYM,
ASM_REWRITE_TAC[]]);
val LESS_ADD_SUC = store_thm("LESS_ADD_SUC",
--`!m n. m < m + SUC n`--,
INDUCT_TAC THENL
[REWRITE_TAC [LESS_0,ADD_CLAUSES],
POP_ASSUM (ASSUME_TAC o REWRITE_RULE [ADD_CLAUSES]) THEN
ASM_REWRITE_TAC [LESS_MONO_EQ,ADD_CLAUSES]]);
val ZERO_LESS_EQ = store_thm("ZERO_LESS_EQ",
--`!n. 0 <= n`--,
GEN_TAC THEN
REPEAT_TCL STRIP_THM_THEN SUBST1_TAC (SPEC (--`n:num`--) num_CASES) THEN
REWRITE_TAC [LESS_0,LESS_OR_EQ]);
val LESS_EQ_MONO = store_thm("LESS_EQ_MONO",
--`!n m. (SUC n <= SUC m) = (n <= m)`--,
REWRITE_TAC [LESS_OR_EQ,LESS_MONO_EQ,INV_SUC_EQ]);
(* Following proof revised for version 1.12 resolution. [TFM 91.01.18] *)
val LESS_OR_EQ_ADD = store_thm ("LESS_OR_EQ_ADD",
--`!n m. n < m \/ ?p. n = p+m`--,
REPEAT GEN_TAC THEN ASM_CASES_TAC (--`n<m`--) THENL
[DISJ1_TAC THEN FIRST_ASSUM ACCEPT_TAC,
DISJ2_TAC THEN IMP_RES_TAC NOT_LESS THEN IMP_RES_TAC LESS_OR_EQ THENL
[CONV_TAC (ONCE_DEPTH_CONV SYM_CONV) THEN
IMP_RES_THEN MATCH_ACCEPT_TAC LESS_ADD,
EXISTS_TAC (--`0`--) THEN ASM_REWRITE_TAC [ADD]]]);
(*----------------------------------------------------------------------*)
(* Added TFM 88.03.31 *)
(* *)
(* Prove the well ordering property: *)
(* *)
(* |- !P. (?n. P n) ==> (?n. P n /\ (!m. m < n ==> ~P m)) *)
(* *)
(* I.e. considering P to be a set, that is the set of numbers, x , such *)
(* that P(x), then every non-empty P has a smallest element. *)
(* *)
(* We first prove that, if there does NOT exist a smallest n such that *)
(* P(n) is true, then for all n P is false of all numbers smaller than n.*)
(* The main step is an induction on n. *)
(*----------------------------------------------------------------------*)
val lemma = TAC_PROOF(([],
--`(~?n. P n /\ !m. (m<n) ==> ~P m) ==>
(!n m. (m<n) ==> ~P m)`--),
CONV_TAC (DEPTH_CONV NOT_EXISTS_CONV) THEN
DISCH_TAC THEN
INDUCT_TAC THEN
REWRITE_TAC [NOT_LESS_0,LESS_THM] THEN
REPEAT (FILTER_STRIP_TAC (--`P:num->bool`--)) THENL
[POP_ASSUM SUBST1_TAC THEN DISCH_TAC,ALL_TAC] THEN
RES_TAC);
(* We now prove the well ordering property. *)
val WOP = store_thm("WOP",
--`!P. (?n.P n) ==> (?n. P n /\ (!m. (m<n) ==> ~P m))`--,
GEN_TAC THEN
CONV_TAC CONTRAPOS_CONV THEN