src/HOL/Nat.ML
author nipkow
Fri Nov 27 17:00:30 1998 +0100 (1998-11-27)
changeset 5983 79e301a6a51b
parent 5644 85fd64148873
child 6109 82b50115564c
permissions -rw-r--r--
At last: linear arithmetic for nat!
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)";
nipkow@5644
    42
by(exhaust_tac "n" 1);
nipkow@5644
    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";
berghofe@5188
    55
Addsimps [not_gr0];
berghofe@5188
    56
berghofe@5188
    57
Goal "m<n ==> 0 < n";
berghofe@5188
    58
by (dtac gr_implies_not0 1);
berghofe@5188
    59
by (Asm_full_simp_tac 1);
berghofe@5188
    60
qed "gr_implies_gr0";
berghofe@5188
    61
Addsimps [gr_implies_gr0];
berghofe@5188
    62
berghofe@5188
    63
qed_goalw "Least_Suc" thy [Least_nat_def]
berghofe@5188
    64
 "!!P. [| ? n. P(Suc n); ~ P 0 |] ==> (LEAST n. P n) = Suc (LEAST m. P(Suc m))"
berghofe@5188
    65
 (fn _ => [
berghofe@5188
    66
        rtac select_equality 1,
berghofe@5188
    67
        fold_goals_tac [Least_nat_def],
berghofe@5188
    68
        safe_tac (claset() addSEs [LeastI]),
berghofe@5188
    69
        rename_tac "j" 1,
berghofe@5188
    70
        exhaust_tac "j" 1,
berghofe@5188
    71
        Blast_tac 1,
berghofe@5188
    72
        blast_tac (claset() addDs [Suc_less_SucD, not_less_Least]) 1,
berghofe@5188
    73
        rename_tac "k n" 1,
berghofe@5188
    74
        exhaust_tac "k" 1,
berghofe@5188
    75
        Blast_tac 1,
berghofe@5188
    76
        hyp_subst_tac 1,
berghofe@5188
    77
        rewtac Least_nat_def,
berghofe@5188
    78
        rtac (select_equality RS arg_cong RS sym) 1,
berghofe@5188
    79
        Safe_tac,
berghofe@5188
    80
        dtac Suc_mono 1,
berghofe@5188
    81
        Blast_tac 1,
berghofe@5188
    82
        cut_facts_tac [less_linear] 1,
berghofe@5188
    83
        Safe_tac,
berghofe@5188
    84
        atac 2,
berghofe@5188
    85
        Blast_tac 2,
berghofe@5188
    86
        dtac Suc_mono 1,
berghofe@5188
    87
        Blast_tac 1]);
berghofe@5188
    88
berghofe@5188
    89
qed_goal "nat_induct2" thy 
berghofe@5188
    90
"[| P 0; P 1; !!k. P k ==> P (Suc (Suc k)) |] ==> P n" (fn prems => [
berghofe@5188
    91
        cut_facts_tac prems 1,
berghofe@5188
    92
        rtac less_induct 1,
berghofe@5188
    93
        exhaust_tac "n" 1,
berghofe@5188
    94
         hyp_subst_tac 1,
berghofe@5188
    95
         atac 1,
berghofe@5188
    96
        hyp_subst_tac 1,
berghofe@5188
    97
        exhaust_tac "nat" 1,
berghofe@5188
    98
         hyp_subst_tac 1,
berghofe@5188
    99
         atac 1,
berghofe@5188
   100
        hyp_subst_tac 1,
berghofe@5188
   101
        resolve_tac prems 1,
berghofe@5188
   102
        dtac spec 1,
berghofe@5188
   103
        etac mp 1,
berghofe@5188
   104
        rtac (lessI RS less_trans) 1,
berghofe@5188
   105
        rtac (lessI RS Suc_mono) 1]);
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];