src/HOL/Nat.ML
author oheimb
Wed, 12 Aug 1998 15:00:46 +0200
changeset 5293 4ce5539aa969
parent 5188 633ec5f6c155
child 5316 7a8975451a89
permissions -rw-r--r--
added ospec AddIffs [elem_o2s]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2441
decc46a5cdb5 added nat_induct2
oheimb
parents: 2268
diff changeset
     1
(*  Title:      HOL/Nat.ML
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2441
diff changeset
     3
    Author:     Tobias Nipkow
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2441
diff changeset
     4
    Copyright   1997 TU Muenchen
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
5188
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
     7
(** conversion rules for nat_rec **)
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
     8
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
     9
val [nat_rec_0, nat_rec_Suc] = nat.recs;
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    10
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    11
(*These 2 rules ease the use of primitive recursion.  NOTE USE OF == *)
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    12
val prems = goal thy
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    13
    "[| !!n. f(n) == nat_rec c h n |] ==> f(0) = c";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    14
by (simp_tac (simpset() addsimps prems) 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    15
qed "def_nat_rec_0";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    16
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    17
val prems = goal thy
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    18
    "[| !!n. f(n) == nat_rec c h n |] ==> f(Suc(n)) = h n (f n)";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    19
by (simp_tac (simpset() addsimps prems) 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    20
qed "def_nat_rec_Suc";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    21
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    22
val [nat_case_0, nat_case_Suc] = nat.cases;
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    23
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    24
Goal "n ~= 0 ==> EX m. n = Suc m";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    25
by (exhaust_tac "n" 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    26
by (REPEAT (Blast_tac 1));
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    27
qed "not0_implies_Suc";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    28
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    29
val prems = goal thy "m<n ==> n ~= 0";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    30
by (exhaust_tac "n" 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    31
by (cut_facts_tac prems 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    32
by (ALLGOALS Asm_full_simp_tac);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    33
qed "gr_implies_not0";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    34
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    35
Goal "(n ~= 0) = (0 < n)";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    36
by (exhaust_tac "n" 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    37
by (Blast_tac 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    38
by (Blast_tac 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    39
qed "neq0_conv";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    40
AddIffs [neq0_conv];
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    41
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    42
(*This theorem is useful with blast_tac: (n=0 ==> False) ==> 0<n *)
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    43
bind_thm ("gr0I", [neq0_conv, notI] MRS iffD1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    44
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    45
Goal "(~(0 < n)) = (n=0)";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    46
by (rtac iffI 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    47
 by (etac swap 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    48
 by (ALLGOALS Asm_full_simp_tac);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    49
qed "not_gr0";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    50
Addsimps [not_gr0];
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    51
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    52
Goal "m<n ==> 0 < n";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    53
by (dtac gr_implies_not0 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    54
by (Asm_full_simp_tac 1);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    55
qed "gr_implies_gr0";
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    56
Addsimps [gr_implies_gr0];
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    57
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    58
qed_goalw "Least_Suc" thy [Least_nat_def]
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    59
 "!!P. [| ? n. P(Suc n); ~ P 0 |] ==> (LEAST n. P n) = Suc (LEAST m. P(Suc m))"
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    60
 (fn _ => [
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    61
        rtac select_equality 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    62
        fold_goals_tac [Least_nat_def],
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    63
        safe_tac (claset() addSEs [LeastI]),
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    64
        rename_tac "j" 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    65
        exhaust_tac "j" 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    66
        Blast_tac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    67
        blast_tac (claset() addDs [Suc_less_SucD, not_less_Least]) 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    68
        rename_tac "k n" 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    69
        exhaust_tac "k" 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    70
        Blast_tac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    71
        hyp_subst_tac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    72
        rewtac Least_nat_def,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    73
        rtac (select_equality RS arg_cong RS sym) 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    74
        Safe_tac,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    75
        dtac Suc_mono 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    76
        Blast_tac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    77
        cut_facts_tac [less_linear] 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    78
        Safe_tac,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    79
        atac 2,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    80
        Blast_tac 2,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    81
        dtac Suc_mono 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    82
        Blast_tac 1]);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    83
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    84
qed_goal "nat_induct2" thy 
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    85
"[| P 0; P 1; !!k. P k ==> P (Suc (Suc k)) |] ==> P n" (fn prems => [
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    86
        cut_facts_tac prems 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    87
        rtac less_induct 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    88
        exhaust_tac "n" 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    89
         hyp_subst_tac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    90
         atac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    91
        hyp_subst_tac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    92
        exhaust_tac "nat" 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    93
         hyp_subst_tac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    94
         atac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    95
        hyp_subst_tac 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    96
        resolve_tac prems 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    97
        dtac spec 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    98
        etac mp 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
    99
        rtac (lessI RS less_trans) 1,
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
   100
        rtac (lessI RS Suc_mono) 1]);
633ec5f6c155 Declaration of type 'nat' as a datatype (this allows usage of
berghofe
parents: 5069
diff changeset
   101
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
   102
Goal "min 0 n = 0";
3023
01364e2f30ad Ran expandshort
paulson
parents: 2608
diff changeset
   103
by (rtac min_leastL 1);
01364e2f30ad Ran expandshort
paulson
parents: 2608
diff changeset
   104
by (trans_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2441
diff changeset
   105
qed "min_0L";
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
   106
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
   107
Goal "min n 0 = 0";
3023
01364e2f30ad Ran expandshort
paulson
parents: 2608
diff changeset
   108
by (rtac min_leastR 1);
01364e2f30ad Ran expandshort
paulson
parents: 2608
diff changeset
   109
by (trans_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2441
diff changeset
   110
qed "min_0R";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4686
diff changeset
   112
Goalw [min_def] "min (Suc m) (Suc n) = Suc(min m n)";
3023
01364e2f30ad Ran expandshort
paulson
parents: 2608
diff changeset
   113
by (Simp_tac 1);
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2441
diff changeset
   114
qed "min_Suc_Suc";
1660
8cb42cd97579 *** empty log message ***
oheimb
parents: 1618
diff changeset
   115
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2441
diff changeset
   116
Addsimps [min_0L,min_0R,min_Suc_Suc];