src/HOL/Nat.ML
author paulson
Thu Aug 13 18:14:26 1998 +0200 (1998-08-13)
changeset 5316 7a8975451a89
parent 5188 633ec5f6c155
child 5644 85fd64148873
permissions -rw-r--r--
even more tidying of Goal commands
     1 (*  Title:      HOL/Nat.ML
     2     ID:         $Id$
     3     Author:     Tobias Nipkow
     4     Copyright   1997 TU Muenchen
     5 *)
     6 
     7 (** conversion rules for nat_rec **)
     8 
     9 val [nat_rec_0, nat_rec_Suc] = nat.recs;
    10 
    11 (*These 2 rules ease the use of primitive recursion.  NOTE USE OF == *)
    12 val prems = Goal
    13     "[| !!n. f(n) == nat_rec c h n |] ==> f(0) = c";
    14 by (simp_tac (simpset() addsimps prems) 1);
    15 qed "def_nat_rec_0";
    16 
    17 val prems = Goal
    18     "[| !!n. f(n) == nat_rec c h n |] ==> f(Suc(n)) = h n (f n)";
    19 by (simp_tac (simpset() addsimps prems) 1);
    20 qed "def_nat_rec_Suc";
    21 
    22 val [nat_case_0, nat_case_Suc] = nat.cases;
    23 
    24 Goal "n ~= 0 ==> EX m. n = Suc m";
    25 by (exhaust_tac "n" 1);
    26 by (REPEAT (Blast_tac 1));
    27 qed "not0_implies_Suc";
    28 
    29 Goal "m<n ==> n ~= 0";
    30 by (exhaust_tac "n" 1);
    31 by (ALLGOALS Asm_full_simp_tac);
    32 qed "gr_implies_not0";
    33 
    34 Goal "(n ~= 0) = (0 < n)";
    35 by (exhaust_tac "n" 1);
    36 by (Blast_tac 1);
    37 by (Blast_tac 1);
    38 qed "neq0_conv";
    39 AddIffs [neq0_conv];
    40 
    41 (*This theorem is useful with blast_tac: (n=0 ==> False) ==> 0<n *)
    42 bind_thm ("gr0I", [neq0_conv, notI] MRS iffD1);
    43 
    44 Goal "(~(0 < n)) = (n=0)";
    45 by (rtac iffI 1);
    46  by (etac swap 1);
    47  by (ALLGOALS Asm_full_simp_tac);
    48 qed "not_gr0";
    49 Addsimps [not_gr0];
    50 
    51 Goal "m<n ==> 0 < n";
    52 by (dtac gr_implies_not0 1);
    53 by (Asm_full_simp_tac 1);
    54 qed "gr_implies_gr0";
    55 Addsimps [gr_implies_gr0];
    56 
    57 qed_goalw "Least_Suc" thy [Least_nat_def]
    58  "!!P. [| ? n. P(Suc n); ~ P 0 |] ==> (LEAST n. P n) = Suc (LEAST m. P(Suc m))"
    59  (fn _ => [
    60         rtac select_equality 1,
    61         fold_goals_tac [Least_nat_def],
    62         safe_tac (claset() addSEs [LeastI]),
    63         rename_tac "j" 1,
    64         exhaust_tac "j" 1,
    65         Blast_tac 1,
    66         blast_tac (claset() addDs [Suc_less_SucD, not_less_Least]) 1,
    67         rename_tac "k n" 1,
    68         exhaust_tac "k" 1,
    69         Blast_tac 1,
    70         hyp_subst_tac 1,
    71         rewtac Least_nat_def,
    72         rtac (select_equality RS arg_cong RS sym) 1,
    73         Safe_tac,
    74         dtac Suc_mono 1,
    75         Blast_tac 1,
    76         cut_facts_tac [less_linear] 1,
    77         Safe_tac,
    78         atac 2,
    79         Blast_tac 2,
    80         dtac Suc_mono 1,
    81         Blast_tac 1]);
    82 
    83 qed_goal "nat_induct2" thy 
    84 "[| P 0; P 1; !!k. P k ==> P (Suc (Suc k)) |] ==> P n" (fn prems => [
    85         cut_facts_tac prems 1,
    86         rtac less_induct 1,
    87         exhaust_tac "n" 1,
    88          hyp_subst_tac 1,
    89          atac 1,
    90         hyp_subst_tac 1,
    91         exhaust_tac "nat" 1,
    92          hyp_subst_tac 1,
    93          atac 1,
    94         hyp_subst_tac 1,
    95         resolve_tac prems 1,
    96         dtac spec 1,
    97         etac mp 1,
    98         rtac (lessI RS less_trans) 1,
    99         rtac (lessI RS Suc_mono) 1]);
   100 
   101 Goal "min 0 n = 0";
   102 by (rtac min_leastL 1);
   103 by (trans_tac 1);
   104 qed "min_0L";
   105 
   106 Goal "min n 0 = 0";
   107 by (rtac min_leastR 1);
   108 by (trans_tac 1);
   109 qed "min_0R";
   110 
   111 Goalw [min_def] "min (Suc m) (Suc n) = Suc(min m n)";
   112 by (Simp_tac 1);
   113 qed "min_Suc_Suc";
   114 
   115 Addsimps [min_0L,min_0R,min_Suc_Suc];