src/HOL/Nat.ML
changeset 1660 8cb42cd97579
parent 1618 372880456b5b
child 1672 2c109cd2fdd0
equal deleted inserted replaced
1659:41e37e5211f2 1660:8cb42cd97579
   289 by (cut_facts_tac prems 1);
   289 by (cut_facts_tac prems 1);
   290 by (ALLGOALS Asm_full_simp_tac);
   290 by (ALLGOALS Asm_full_simp_tac);
   291 qed "gr_implies_not0";
   291 qed "gr_implies_not0";
   292 Addsimps [gr_implies_not0];
   292 Addsimps [gr_implies_not0];
   293 
   293 
       
   294 qed_goal "zero_less_eq" Nat.thy "0 < n = (n ~= 0)" (fn _ => [
       
   295 	rtac iffI 1,
       
   296 	etac gr_implies_not0 1,
       
   297 	rtac natE 1,
       
   298 	contr_tac 1,
       
   299 	etac ssubst 1,
       
   300 	rtac zero_less_Suc 1]);
       
   301 
   294 (** Inductive (?) properties **)
   302 (** Inductive (?) properties **)
   295 
   303 
   296 val [prem] = goal Nat.thy "Suc(m) < n ==> m<n";
   304 val [prem] = goal Nat.thy "Suc(m) < n ==> m<n";
   297 by (rtac (prem RS rev_mp) 1);
   305 by (rtac (prem RS rev_mp) 1);
   298 by (nat_ind_tac "n" 1);
   306 by (nat_ind_tac "n" 1);
   339 qed "not_Suc_n_less_n";
   347 qed "not_Suc_n_less_n";
   340 Addsimps [not_Suc_n_less_n];
   348 Addsimps [not_Suc_n_less_n];
   341 
   349 
   342 goal Nat.thy "!!i. i<j ==> j<k --> Suc i < k";
   350 goal Nat.thy "!!i. i<j ==> j<k --> Suc i < k";
   343 by (nat_ind_tac "k" 1);
   351 by (nat_ind_tac "k" 1);
   344 by (ALLGOALS (asm_simp_tac (!simpset addsimps [less_Suc_eq])));
   352 by (ALLGOALS (asm_simp_tac (!simpset)));
       
   353 by (asm_simp_tac (!simpset addsimps [less_Suc_eq]) 1);
   345 by (fast_tac (HOL_cs addDs [Suc_lessD]) 1);
   354 by (fast_tac (HOL_cs addDs [Suc_lessD]) 1);
   346 qed_spec_mp "less_trans_Suc";
   355 qed_spec_mp "less_trans_Suc";
   347 
   356 
   348 (*"Less than" is a linear ordering*)
   357 (*"Less than" is a linear ordering*)
   349 goal Nat.thy "m<n | m=n | n<(m::nat)";
   358 goal Nat.thy "m<n | m=n | n<(m::nat)";
   351 by (nat_ind_tac "n" 1);
   360 by (nat_ind_tac "n" 1);
   352 by (rtac (refl RS disjI1 RS disjI2) 1);
   361 by (rtac (refl RS disjI1 RS disjI2) 1);
   353 by (rtac (zero_less_Suc RS disjI1) 1);
   362 by (rtac (zero_less_Suc RS disjI1) 1);
   354 by (fast_tac (HOL_cs addIs [lessI, Suc_mono, less_SucI] addEs [lessE]) 1);
   363 by (fast_tac (HOL_cs addIs [lessI, Suc_mono, less_SucI] addEs [lessE]) 1);
   355 qed "less_linear";
   364 qed "less_linear";
       
   365 
       
   366 qed_goal "nat_less_cases" Nat.thy 
       
   367    "[| (m::nat)<n ==> P n m; m=n ==> P n m; n<m ==> P n m |] ==> P n m"
       
   368 ( fn prems =>
       
   369         [
       
   370         (res_inst_tac [("m1","n"),("n1","m")] (less_linear RS disjE) 1),
       
   371         (etac disjE 2),
       
   372         (etac (hd (tl (tl prems))) 1),
       
   373         (etac (sym RS hd (tl prems)) 1),
       
   374         (etac (hd prems) 1)
       
   375         ]);
   356 
   376 
   357 (*Can be used with less_Suc_eq to get n=m | n<m *)
   377 (*Can be used with less_Suc_eq to get n=m | n<m *)
   358 goal Nat.thy "(~ m < n) = (n < Suc(m))";
   378 goal Nat.thy "(~ m < n) = (n < Suc(m))";
   359 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   379 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   360 by (ALLGOALS Asm_simp_tac);
   380 by (ALLGOALS Asm_simp_tac);
   382 by (nat_ind_tac "i" 1);
   402 by (nat_ind_tac "i" 1);
   383 by (ALLGOALS Asm_simp_tac);
   403 by (ALLGOALS Asm_simp_tac);
   384 qed "le_0";
   404 qed "le_0";
   385 
   405 
   386 Addsimps [less_not_refl,
   406 Addsimps [less_not_refl,
   387           less_Suc_eq, le0, le_0,
   407           (*less_Suc_eq,*) le0, le_0,
   388           Suc_Suc_eq, Suc_n_not_le_n,
   408           Suc_Suc_eq, Suc_n_not_le_n,
   389           n_not_Suc_n, Suc_n_not_n,
   409           n_not_Suc_n, Suc_n_not_n,
   390           nat_case_0, nat_case_Suc, nat_rec_0, nat_rec_Suc];
   410           nat_case_0, nat_case_Suc, nat_rec_0, nat_rec_Suc];
   391 
   411 
   392 (*Prevents simplification of f and g: much faster*)
   412 (*Prevents simplification of f and g: much faster*)
   415 goalw Nat.thy [le_def] "!!m. ~ m <= n ==> n<(m::nat)";
   435 goalw Nat.thy [le_def] "!!m. ~ m <= n ==> n<(m::nat)";
   416 by (fast_tac HOL_cs 1);
   436 by (fast_tac HOL_cs 1);
   417 qed "not_leE";
   437 qed "not_leE";
   418 
   438 
   419 goalw Nat.thy [le_def] "!!m. m < n ==> Suc(m) <= n";
   439 goalw Nat.thy [le_def] "!!m. m < n ==> Suc(m) <= n";
   420 by (Simp_tac 1);
   440 by (simp_tac (!simpset addsimps [less_Suc_eq]) 1);
   421 by (fast_tac (HOL_cs addEs [less_irrefl,less_asym]) 1);
   441 by (fast_tac (HOL_cs addEs [less_irrefl,less_asym]) 1);
   422 qed "lessD";
   442 qed "lessD";
   423 
   443 
   424 goalw Nat.thy [le_def] "!!m. Suc(m) <= n ==> m <= n";
   444 goalw Nat.thy [le_def] "!!m. Suc(m) <= n ==> m <= n";
   425 by (Asm_full_simp_tac 1);
   445 by (asm_full_simp_tac (!simpset addsimps [less_Suc_eq]) 1);
   426 by (fast_tac HOL_cs 1);
   446 by (fast_tac HOL_cs 1);
   427 qed "Suc_leD";
   447 qed "Suc_leD";
   428 
   448 
   429 goalw Nat.thy [le_def] "!!m. m <= n ==> m <= Suc n";
   449 goalw Nat.thy [le_def] "!!m. m <= n ==> m <= Suc n";
   430 by (fast_tac (HOL_cs addDs [Suc_lessD]) 1);
   450 by (fast_tac (HOL_cs addDs [Suc_lessD]) 1);
   517 val [prem] = goal Nat.thy "k < (LEAST x.P(x)) ==> ~P(k)";
   537 val [prem] = goal Nat.thy "k < (LEAST x.P(x)) ==> ~P(k)";
   518 by (rtac notI 1);
   538 by (rtac notI 1);
   519 by (etac (rewrite_rule [le_def] Least_le RS notE) 1);
   539 by (etac (rewrite_rule [le_def] Least_le RS notE) 1);
   520 by (rtac prem 1);
   540 by (rtac prem 1);
   521 qed "not_less_Least";
   541 qed "not_less_Least";
       
   542 
       
   543 qed_goalw "Least_Suc" Nat.thy [Least_def]
       
   544  "[| ? n. P (Suc n); ~ P 0 |] ==> (LEAST n. P n) = Suc (LEAST m. P (Suc m))"
       
   545  (fn prems => [
       
   546 	cut_facts_tac prems 1,
       
   547 	rtac select_equality 1,
       
   548 	fold_goals_tac [Least_def],
       
   549 	safe_tac (HOL_cs addSEs [LeastI]),
       
   550 	res_inst_tac [("n","j")] natE 1,
       
   551 	fast_tac HOL_cs 1,
       
   552 	fast_tac (HOL_cs addDs [Suc_less_SucD] addDs [not_less_Least]) 1,	
       
   553 	res_inst_tac [("n","k")] natE 1,
       
   554 	fast_tac HOL_cs 1,
       
   555 	hyp_subst_tac 1,
       
   556 	rewtac Least_def,
       
   557 	rtac (select_equality RS arg_cong RS sym) 1,
       
   558 	safe_tac HOL_cs,
       
   559 	dtac Suc_mono 1,
       
   560 	fast_tac HOL_cs 1,
       
   561 	cut_facts_tac [less_linear] 1,
       
   562 	safe_tac HOL_cs,
       
   563 	atac 2,
       
   564 	fast_tac HOL_cs 2,
       
   565 	dtac Suc_mono 1,
       
   566 	fast_tac HOL_cs 1]);