src/HOL/Nat.ML
changeset 1465 5d7a7e439cec
parent 1327 6c29cfab679c
child 1475 7f5a4cd08209
equal deleted inserted replaced
1464:a608f83e3421 1465:5d7a7e439cec
     1 (*  Title: 	HOL/nat
     1 (*  Title:      HOL/nat
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author: 	Tobias Nipkow, Cambridge University Computer Laboratory
     3     Author:     Tobias Nipkow, Cambridge University Computer Laboratory
     4     Copyright   1991  University of Cambridge
     4     Copyright   1991  University of Cambridge
     5 
     5 
     6 For nat.thy.  Type nat is defined as a set (Nat) over the type ind.
     6 For nat.thy.  Type nat is defined as a set (Nat) over the type ind.
     7 *)
     7 *)
     8 
     8 
    45 qed "nat_induct";
    45 qed "nat_induct";
    46 
    46 
    47 (*Perform induction on n. *)
    47 (*Perform induction on n. *)
    48 fun nat_ind_tac a i = 
    48 fun nat_ind_tac a i = 
    49     EVERY [res_inst_tac [("n",a)] nat_induct i,
    49     EVERY [res_inst_tac [("n",a)] nat_induct i,
    50 	   rename_last_tac a ["1"] (i+1)];
    50            rename_last_tac a ["1"] (i+1)];
    51 
    51 
    52 (*A special form of induction for reasoning about m<n and m-n*)
    52 (*A special form of induction for reasoning about m<n and m-n*)
    53 val prems = goal Nat.thy
    53 val prems = goal Nat.thy
    54     "[| !!x. P x 0;  \
    54     "[| !!x. P x 0;  \
    55 \       !!y. P 0 (Suc y);  \
    55 \       !!y. P 0 (Suc y);  \
   131 by (fast_tac (set_cs addIs [select_equality] addEs [Zero_neq_Suc]) 1);
   131 by (fast_tac (set_cs addIs [select_equality] addEs [Zero_neq_Suc]) 1);
   132 qed "nat_case_0";
   132 qed "nat_case_0";
   133 
   133 
   134 goalw Nat.thy [nat_case_def] "nat_case a f (Suc k) = f(k)";
   134 goalw Nat.thy [nat_case_def] "nat_case a f (Suc k) = f(k)";
   135 by (fast_tac (set_cs addIs [select_equality] 
   135 by (fast_tac (set_cs addIs [select_equality] 
   136 	               addEs [make_elim Suc_inject, Suc_neq_Zero]) 1);
   136                        addEs [make_elim Suc_inject, Suc_neq_Zero]) 1);
   137 qed "nat_case_Suc";
   137 qed "nat_case_Suc";
   138 
   138 
   139 (** Introduction rules for 'pred_nat' **)
   139 (** Introduction rules for 'pred_nat' **)
   140 
   140 
   141 goalw Nat.thy [pred_nat_def] "(n, Suc(n)) : pred_nat";
   141 goalw Nat.thy [pred_nat_def] "(n, Suc(n)) : pred_nat";
   151 
   151 
   152 goalw Nat.thy [wf_def] "wf(pred_nat)";
   152 goalw Nat.thy [wf_def] "wf(pred_nat)";
   153 by (strip_tac 1);
   153 by (strip_tac 1);
   154 by (nat_ind_tac "x" 1);
   154 by (nat_ind_tac "x" 1);
   155 by (fast_tac (HOL_cs addSEs [mp, pred_natE, Pair_inject, 
   155 by (fast_tac (HOL_cs addSEs [mp, pred_natE, Pair_inject, 
   156 			     make_elim Suc_inject]) 2);
   156                              make_elim Suc_inject]) 2);
   157 by (fast_tac (HOL_cs addSEs [mp, pred_natE, Pair_inject, Zero_neq_Suc]) 1);
   157 by (fast_tac (HOL_cs addSEs [mp, pred_natE, Pair_inject, Zero_neq_Suc]) 1);
   158 qed "wf_pred_nat";
   158 qed "wf_pred_nat";
   159 
   159 
   160 
   160 
   161 (*** nat_rec -- by wf recursion on pred_nat ***)
   161 (*** nat_rec -- by wf recursion on pred_nat ***)
   243 val major::prems = goalw Nat.thy [less_def]
   243 val major::prems = goalw Nat.thy [less_def]
   244     "[| i<k;  k=Suc(i) ==> P;  !!j. [| i<j;  k=Suc(j) |] ==> P \
   244     "[| i<k;  k=Suc(i) ==> P;  !!j. [| i<j;  k=Suc(j) |] ==> P \
   245 \    |] ==> P";
   245 \    |] ==> P";
   246 by (rtac (major RS tranclE) 1);
   246 by (rtac (major RS tranclE) 1);
   247 by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE'
   247 by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE'
   248 		  eresolve_tac (prems@[pred_natE, Pair_inject])));
   248                   eresolve_tac (prems@[pred_natE, Pair_inject])));
   249 by (rtac refl 1);
   249 by (rtac refl 1);
   250 qed "lessE";
   250 qed "lessE";
   251 
   251 
   252 goal Nat.thy "~ n<0";
   252 goal Nat.thy "~ n<0";
   253 by (rtac notI 1);
   253 by (rtac notI 1);
   269 by (fast_tac (HOL_cs addSDs [Suc_inject]) 1);
   269 by (fast_tac (HOL_cs addSDs [Suc_inject]) 1);
   270 qed "less_SucE";
   270 qed "less_SucE";
   271 
   271 
   272 goal Nat.thy "(m < Suc(n)) = (m < n | m = n)";
   272 goal Nat.thy "(m < Suc(n)) = (m < n | m = n)";
   273 by (fast_tac (HOL_cs addSIs [lessI]
   273 by (fast_tac (HOL_cs addSIs [lessI]
   274 		     addEs  [less_trans, less_SucE]) 1);
   274                      addEs  [less_trans, less_SucE]) 1);
   275 qed "less_Suc_eq";
   275 qed "less_Suc_eq";
   276 
   276 
   277 val prems = goal Nat.thy "m<n ==> n ~= 0";
   277 val prems = goal Nat.thy "m<n ==> n ~= 0";
   278 by(res_inst_tac [("n","n")] natE 1);
   278 by(res_inst_tac [("n","n")] natE 1);
   279 by(cut_facts_tac prems 1);
   279 by(cut_facts_tac prems 1);
   287 by (rtac (prem RS rev_mp) 1);
   287 by (rtac (prem RS rev_mp) 1);
   288 by (nat_ind_tac "n" 1);
   288 by (nat_ind_tac "n" 1);
   289 by (rtac impI 1);
   289 by (rtac impI 1);
   290 by (etac less_zeroE 1);
   290 by (etac less_zeroE 1);
   291 by (fast_tac (HOL_cs addSIs [lessI RS less_SucI]
   291 by (fast_tac (HOL_cs addSIs [lessI RS less_SucI]
   292 	 	     addSDs [Suc_inject]
   292                      addSDs [Suc_inject]
   293 		     addEs  [less_trans, lessE]) 1);
   293                      addEs  [less_trans, lessE]) 1);
   294 qed "Suc_lessD";
   294 qed "Suc_lessD";
   295 
   295 
   296 val [major,minor] = goal Nat.thy 
   296 val [major,minor] = goal Nat.thy 
   297     "[| Suc(i)<k;  !!j. [| i<j;  k=Suc(j) |] ==> P \
   297     "[| Suc(i)<k;  !!j. [| i<j;  k=Suc(j) |] ==> P \
   298 \    |] ==> P";
   298 \    |] ==> P";
   313 by (fast_tac (HOL_cs addIs prems) 1);
   313 by (fast_tac (HOL_cs addIs prems) 1);
   314 by (nat_ind_tac "n" 1);
   314 by (nat_ind_tac "n" 1);
   315 by (rtac impI 1);
   315 by (rtac impI 1);
   316 by (etac less_zeroE 1);
   316 by (etac less_zeroE 1);
   317 by (fast_tac (HOL_cs addSIs [lessI]
   317 by (fast_tac (HOL_cs addSIs [lessI]
   318 	 	     addSDs [Suc_inject]
   318                      addSDs [Suc_inject]
   319 		     addEs  [less_trans, lessE]) 1);
   319                      addEs  [less_trans, lessE]) 1);
   320 qed "Suc_mono";
   320 qed "Suc_mono";
   321 
   321 
   322 goal Nat.thy "(Suc(m) < Suc(n)) = (m<n)";
   322 goal Nat.thy "(Suc(m) < Suc(n)) = (m<n)";
   323 by (EVERY1 [rtac iffI, etac Suc_less_SucD, etac Suc_mono]);
   323 by (EVERY1 [rtac iffI, etac Suc_less_SucD, etac Suc_mono]);
   324 qed "Suc_less_eq";
   324 qed "Suc_less_eq";