src/HOL/Nat.ML
author paulson
Wed Jul 21 15:23:18 1999 +0200 (1999-07-21)
changeset 7058 8dfea70eb6b7
parent 6805 52b13dfbe954
child 7089 9bfb8e218b99
permissions -rw-r--r--
removed 2 qed_goals
oheimb@2441
     1
(*  Title:      HOL/Nat.ML
clasohm@923
     2
    ID:         $Id$
nipkow@2608
     3
    Author:     Tobias Nipkow
nipkow@2608
     4
    Copyright   1997 TU Muenchen
clasohm@923
     5
*)
clasohm@923
     6
berghofe@5188
     7
(** conversion rules for nat_rec **)
berghofe@5188
     8
berghofe@5188
     9
val [nat_rec_0, nat_rec_Suc] = nat.recs;
berghofe@5188
    10
berghofe@5188
    11
(*These 2 rules ease the use of primitive recursion.  NOTE USE OF == *)
paulson@5316
    12
val prems = Goal
berghofe@5188
    13
    "[| !!n. f(n) == nat_rec c h n |] ==> f(0) = c";
berghofe@5188
    14
by (simp_tac (simpset() addsimps prems) 1);
berghofe@5188
    15
qed "def_nat_rec_0";
berghofe@5188
    16
paulson@5316
    17
val prems = Goal
berghofe@5188
    18
    "[| !!n. f(n) == nat_rec c h n |] ==> f(Suc(n)) = h n (f n)";
berghofe@5188
    19
by (simp_tac (simpset() addsimps prems) 1);
berghofe@5188
    20
qed "def_nat_rec_Suc";
berghofe@5188
    21
berghofe@5188
    22
val [nat_case_0, nat_case_Suc] = nat.cases;
berghofe@5188
    23
berghofe@5188
    24
Goal "n ~= 0 ==> EX m. n = Suc m";
berghofe@5188
    25
by (exhaust_tac "n" 1);
berghofe@5188
    26
by (REPEAT (Blast_tac 1));
berghofe@5188
    27
qed "not0_implies_Suc";
berghofe@5188
    28
paulson@5316
    29
Goal "m<n ==> n ~= 0";
berghofe@5188
    30
by (exhaust_tac "n" 1);
berghofe@5188
    31
by (ALLGOALS Asm_full_simp_tac);
berghofe@5188
    32
qed "gr_implies_not0";
berghofe@5188
    33
berghofe@5188
    34
Goal "(n ~= 0) = (0 < n)";
berghofe@5188
    35
by (exhaust_tac "n" 1);
berghofe@5188
    36
by (Blast_tac 1);
berghofe@5188
    37
by (Blast_tac 1);
berghofe@5188
    38
qed "neq0_conv";
berghofe@5188
    39
AddIffs [neq0_conv];
berghofe@5188
    40
nipkow@5644
    41
Goal "(0 ~= n) = (0 < n)";
paulson@6301
    42
by (exhaust_tac "n" 1);
paulson@6301
    43
by (Auto_tac);
nipkow@5644
    44
qed "zero_neq_conv";
nipkow@5644
    45
AddIffs [zero_neq_conv];
nipkow@5644
    46
berghofe@5188
    47
(*This theorem is useful with blast_tac: (n=0 ==> False) ==> 0<n *)
berghofe@5188
    48
bind_thm ("gr0I", [neq0_conv, notI] MRS iffD1);
berghofe@5188
    49
berghofe@5188
    50
Goal "(~(0 < n)) = (n=0)";
berghofe@5188
    51
by (rtac iffI 1);
berghofe@5188
    52
 by (etac swap 1);
berghofe@5188
    53
 by (ALLGOALS Asm_full_simp_tac);
berghofe@5188
    54
qed "not_gr0";
nipkow@6109
    55
AddIffs [not_gr0];
berghofe@5188
    56
paulson@6805
    57
(*Useful in certain inductive arguments*)
paulson@6805
    58
Goal "(m < Suc n) = (m=0 | (EX j. m = Suc j & j < n))";
paulson@6805
    59
by (exhaust_tac "m" 1);
paulson@6805
    60
by Auto_tac;
paulson@6805
    61
qed "less_Suc_eq_0_disj";
paulson@6805
    62
paulson@7058
    63
Goalw [Least_nat_def]
paulson@7058
    64
 "[| ? n. P(Suc n); ~ P 0 |] ==> (LEAST n. P n) = Suc (LEAST m. P(Suc m))";
paulson@7058
    65
by (rtac select_equality 1);
paulson@7058
    66
by (fold_goals_tac [Least_nat_def]);
paulson@7058
    67
by (safe_tac (claset() addSEs [LeastI]));
paulson@7058
    68
by (rename_tac "j" 1);
paulson@7058
    69
by (exhaust_tac "j" 1);
paulson@7058
    70
by (Blast_tac 1);
paulson@7058
    71
by (blast_tac (claset() addDs [Suc_less_SucD, not_less_Least]) 1);
paulson@7058
    72
by (rename_tac "k n" 1);
paulson@7058
    73
by (exhaust_tac "k" 1);
paulson@7058
    74
by (Blast_tac 1);
paulson@7058
    75
by (hyp_subst_tac 1);
paulson@7058
    76
by (rewtac Least_nat_def);
paulson@7058
    77
by (rtac (select_equality RS arg_cong RS sym) 1);
paulson@7058
    78
by (Safe_tac);
paulson@7058
    79
by (dtac Suc_mono 1);
paulson@7058
    80
by (Blast_tac 1);
paulson@7058
    81
by (cut_facts_tac [less_linear] 1);
paulson@7058
    82
by (Safe_tac);
paulson@7058
    83
by (atac 2);
paulson@7058
    84
by (Blast_tac 2);
paulson@7058
    85
by (dtac Suc_mono 1);
paulson@7058
    86
by (Blast_tac 1);
paulson@7058
    87
qed "Least_Suc";
berghofe@5188
    88
paulson@7058
    89
val prems = Goal "[| P 0; P 1; !!k. P k ==> P (Suc (Suc k)) |] ==> P n";
paulson@7058
    90
by (cut_facts_tac prems 1);
paulson@7058
    91
by (rtac less_induct 1);
paulson@7058
    92
by (exhaust_tac "n" 1);
paulson@7058
    93
by (hyp_subst_tac 1);
paulson@7058
    94
by (atac 1);
paulson@7058
    95
by (hyp_subst_tac 1);
paulson@7058
    96
by (exhaust_tac "nat" 1);
paulson@7058
    97
by (hyp_subst_tac 1);
paulson@7058
    98
by (atac 1);
paulson@7058
    99
by (hyp_subst_tac 1);
paulson@7058
   100
by (resolve_tac prems 1);
paulson@7058
   101
by (dtac spec 1);
paulson@7058
   102
by (etac mp 1);
paulson@7058
   103
by (rtac (lessI RS less_trans) 1);
paulson@7058
   104
by (rtac (lessI RS Suc_mono) 1);
paulson@7058
   105
qed "nat_induct2";
berghofe@5188
   106
wenzelm@5069
   107
Goal "min 0 n = 0";
paulson@3023
   108
by (rtac min_leastL 1);
nipkow@5983
   109
by (Simp_tac 1);
nipkow@2608
   110
qed "min_0L";
nipkow@1301
   111
wenzelm@5069
   112
Goal "min n 0 = 0";
paulson@3023
   113
by (rtac min_leastR 1);
nipkow@5983
   114
by (Simp_tac 1);
nipkow@2608
   115
qed "min_0R";
clasohm@923
   116
wenzelm@5069
   117
Goalw [min_def] "min (Suc m) (Suc n) = Suc(min m n)";
paulson@3023
   118
by (Simp_tac 1);
nipkow@2608
   119
qed "min_Suc_Suc";
oheimb@1660
   120
nipkow@2608
   121
Addsimps [min_0L,min_0R,min_Suc_Suc];
nipkow@6433
   122
nipkow@6433
   123
Goalw [max_def] "max 0 n = n";
nipkow@6433
   124
by (Simp_tac 1);
nipkow@6433
   125
qed "max_0L";
nipkow@6433
   126
nipkow@6433
   127
Goalw [max_def] "max n 0 = n";
nipkow@6433
   128
by (Simp_tac 1);
nipkow@6433
   129
qed "max_0R";
nipkow@6433
   130
nipkow@6433
   131
Goalw [max_def] "max (Suc m) (Suc n) = Suc(max m n)";
nipkow@6433
   132
by (Simp_tac 1);
nipkow@6433
   133
qed "max_Suc_Suc";
nipkow@6433
   134
nipkow@6433
   135
Addsimps [max_0L,max_0R,max_Suc_Suc];