Arith.thy -> thy; proved a few new theorems
authorpaulson
Wed Mar 11 11:03:43 1998 +0100 (1998-03-11)
changeset 473210af4886b33f
parent 4731 0196377b5703
child 4733 2c984ac036f5
Arith.thy -> thy; proved a few new theorems
src/HOL/Arith.ML
     1.1 --- a/src/HOL/Arith.ML	Wed Mar 11 10:17:16 1998 +0100
     1.2 +++ b/src/HOL/Arith.ML	Wed Mar 11 11:03:43 1998 +0100
     1.3 @@ -12,13 +12,13 @@
     1.4  
     1.5  (** Difference **)
     1.6  
     1.7 -qed_goal "diff_0_eq_0" Arith.thy
     1.8 +qed_goal "diff_0_eq_0" thy
     1.9      "0 - n = 0"
    1.10   (fn _ => [induct_tac "n" 1,  ALLGOALS Asm_simp_tac]);
    1.11  
    1.12  (*Must simplify BEFORE the induction!!  (Else we get a critical pair)
    1.13    Suc(m) - Suc(n)   rewrites to   pred(Suc(m) - n)  *)
    1.14 -qed_goal "diff_Suc_Suc" Arith.thy
    1.15 +qed_goal "diff_Suc_Suc" thy
    1.16      "Suc(m) - Suc(n) = m - n"
    1.17   (fn _ =>
    1.18    [Simp_tac 1, induct_tac "n" 1, ALLGOALS Asm_simp_tac]);
    1.19 @@ -28,17 +28,11 @@
    1.20  (* Could be (and is, below) generalized in various ways;
    1.21     However, none of the generalizations are currently in the simpset,
    1.22     and I dread to think what happens if I put them in *)
    1.23 -goal Arith.thy "!!n. 0 < n ==> Suc(n-1) = n";
    1.24 +goal thy "!!n. 0 < n ==> Suc(n-1) = n";
    1.25  by (asm_simp_tac (simpset() addsplits [expand_nat_case]) 1);
    1.26  qed "Suc_pred";
    1.27  Addsimps [Suc_pred];
    1.28  
    1.29 -(* Generalize? *)
    1.30 -goal Arith.thy "!!n. 0<n ==> n-1 < n";
    1.31 -by (asm_simp_tac (simpset() addsplits [expand_nat_case]) 1);
    1.32 -qed "pred_less";
    1.33 -Addsimps [pred_less];
    1.34 -
    1.35  Delsimps [diff_Suc];
    1.36  
    1.37  
    1.38 @@ -46,48 +40,48 @@
    1.39  
    1.40  (*** Addition ***)
    1.41  
    1.42 -qed_goal "add_0_right" Arith.thy "m + 0 = m"
    1.43 +qed_goal "add_0_right" thy "m + 0 = m"
    1.44   (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
    1.45  
    1.46 -qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)"
    1.47 +qed_goal "add_Suc_right" thy "m + Suc(n) = Suc(m+n)"
    1.48   (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
    1.49  
    1.50  Addsimps [add_0_right,add_Suc_right];
    1.51  
    1.52  (*Associative law for addition*)
    1.53 -qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)"
    1.54 +qed_goal "add_assoc" thy "(m + n) + k = m + ((n + k)::nat)"
    1.55   (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
    1.56  
    1.57  (*Commutative law for addition*)  
    1.58 -qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)"
    1.59 +qed_goal "add_commute" thy "m + n = n + (m::nat)"
    1.60   (fn _ =>  [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
    1.61  
    1.62 -qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)"
    1.63 +qed_goal "add_left_commute" thy "x+(y+z)=y+((x+z)::nat)"
    1.64   (fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1,
    1.65             rtac (add_commute RS arg_cong) 1]);
    1.66  
    1.67  (*Addition is an AC-operator*)
    1.68  val add_ac = [add_assoc, add_commute, add_left_commute];
    1.69  
    1.70 -goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)";
    1.71 +goal thy "!!k::nat. (k + m = k + n) = (m=n)";
    1.72  by (induct_tac "k" 1);
    1.73  by (Simp_tac 1);
    1.74  by (Asm_simp_tac 1);
    1.75  qed "add_left_cancel";
    1.76  
    1.77 -goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)";
    1.78 +goal thy "!!k::nat. (m + k = n + k) = (m=n)";
    1.79  by (induct_tac "k" 1);
    1.80  by (Simp_tac 1);
    1.81  by (Asm_simp_tac 1);
    1.82  qed "add_right_cancel";
    1.83  
    1.84 -goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)";
    1.85 +goal thy "!!k::nat. (k + m <= k + n) = (m<=n)";
    1.86  by (induct_tac "k" 1);
    1.87  by (Simp_tac 1);
    1.88  by (Asm_simp_tac 1);
    1.89  qed "add_left_cancel_le";
    1.90  
    1.91 -goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)";
    1.92 +goal thy "!!k::nat. (k + m < k + n) = (m<n)";
    1.93  by (induct_tac "k" 1);
    1.94  by (Simp_tac 1);
    1.95  by (Asm_simp_tac 1);
    1.96 @@ -98,26 +92,26 @@
    1.97  
    1.98  (** Reasoning about m+0=0, etc. **)
    1.99  
   1.100 -goal Arith.thy "(m+n = 0) = (m=0 & n=0)";
   1.101 +goal thy "(m+n = 0) = (m=0 & n=0)";
   1.102  by (induct_tac "m" 1);
   1.103  by (ALLGOALS Asm_simp_tac);
   1.104  qed "add_is_0";
   1.105  AddIffs [add_is_0];
   1.106  
   1.107 -goal Arith.thy "(0<m+n) = (0<m | 0<n)";
   1.108 +goal thy "(0<m+n) = (0<m | 0<n)";
   1.109  by (simp_tac (simpset() delsimps [neq0_conv] addsimps [neq0_conv RS sym]) 1);
   1.110  qed "add_gr_0";
   1.111  AddIffs [add_gr_0];
   1.112  
   1.113  (* FIXME: really needed?? *)
   1.114 -goal Arith.thy "((m+n)-1 = 0) = (m=0 & n-1 = 0 | m-1 = 0 & n=0)";
   1.115 +goal thy "((m+n)-1 = 0) = (m=0 & n-1 = 0 | m-1 = 0 & n=0)";
   1.116  by (exhaust_tac "m" 1);
   1.117  by (ALLGOALS (fast_tac (claset() addss (simpset()))));
   1.118  qed "pred_add_is_0";
   1.119  Addsimps [pred_add_is_0];
   1.120  
   1.121  (* Could be generalized, eg to "!!n. k<n ==> m+(n-(Suc k)) = (m+n)-(Suc k)" *)
   1.122 -goal Arith.thy "!!n. 0<n ==> m + (n-1) = (m+n)-1";
   1.123 +goal thy "!!n. 0<n ==> m + (n-1) = (m+n)-1";
   1.124  by (exhaust_tac "m" 1);
   1.125  by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_Suc]
   1.126                                        addsplits [expand_nat_case])));
   1.127 @@ -127,7 +121,7 @@
   1.128  
   1.129  (**** Additional theorems about "less than" ****)
   1.130  
   1.131 -goal Arith.thy "i<j --> (EX k. j = Suc(i+k))";
   1.132 +goal thy "i<j --> (EX k. j = Suc(i+k))";
   1.133  by (induct_tac "j" 1);
   1.134  by (Simp_tac 1);
   1.135  by (blast_tac (claset() addSEs [less_SucE] 
   1.136 @@ -137,21 +131,21 @@
   1.137  (* [| i<j;  !!x. j = Suc(i+x) ==> Q |] ==> Q *)
   1.138  bind_thm ("less_natE", lemma RS mp RS exE);
   1.139  
   1.140 -goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))";
   1.141 +goal thy "!!m. m<n --> (? k. n=Suc(m+k))";
   1.142  by (induct_tac "n" 1);
   1.143  by (ALLGOALS (simp_tac (simpset() addsimps [less_Suc_eq])));
   1.144  by (blast_tac (claset() addSEs [less_SucE] 
   1.145                         addSIs [add_0_right RS sym, add_Suc_right RS sym]) 1);
   1.146  qed_spec_mp "less_eq_Suc_add";
   1.147  
   1.148 -goal Arith.thy "n <= ((m + n)::nat)";
   1.149 +goal thy "n <= ((m + n)::nat)";
   1.150  by (induct_tac "m" 1);
   1.151  by (ALLGOALS Simp_tac);
   1.152  by (etac le_trans 1);
   1.153  by (rtac (lessI RS less_imp_le) 1);
   1.154  qed "le_add2";
   1.155  
   1.156 -goal Arith.thy "n <= ((n + m)::nat)";
   1.157 +goal thy "n <= ((n + m)::nat)";
   1.158  by (simp_tac (simpset() addsimps add_ac) 1);
   1.159  by (rtac le_add2 1);
   1.160  qed "le_add1";
   1.161 @@ -171,49 +165,49 @@
   1.162  (*"i < j ==> i < m+j"*)
   1.163  bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans));
   1.164  
   1.165 -goal Arith.thy "!!i. i+j < (k::nat) ==> i<k";
   1.166 +goal thy "!!i. i+j < (k::nat) ==> i<k";
   1.167  by (etac rev_mp 1);
   1.168  by (induct_tac "j" 1);
   1.169  by (ALLGOALS Asm_simp_tac);
   1.170  by (blast_tac (claset() addDs [Suc_lessD]) 1);
   1.171  qed "add_lessD1";
   1.172  
   1.173 -goal Arith.thy "!!i::nat. ~ (i+j < i)";
   1.174 +goal thy "!!i::nat. ~ (i+j < i)";
   1.175  by (rtac notI 1);
   1.176  by (etac (add_lessD1 RS less_irrefl) 1);
   1.177  qed "not_add_less1";
   1.178  
   1.179 -goal Arith.thy "!!i::nat. ~ (j+i < i)";
   1.180 +goal thy "!!i::nat. ~ (j+i < i)";
   1.181  by (simp_tac (simpset() addsimps [add_commute, not_add_less1]) 1);
   1.182  qed "not_add_less2";
   1.183  AddIffs [not_add_less1, not_add_less2];
   1.184  
   1.185 -goal Arith.thy "!!k::nat. m <= n ==> m <= n+k";
   1.186 +goal thy "!!k::nat. m <= n ==> m <= n+k";
   1.187  by (etac le_trans 1);
   1.188  by (rtac le_add1 1);
   1.189  qed "le_imp_add_le";
   1.190  
   1.191 -goal Arith.thy "!!k::nat. m < n ==> m < n+k";
   1.192 +goal thy "!!k::nat. m < n ==> m < n+k";
   1.193  by (etac less_le_trans 1);
   1.194  by (rtac le_add1 1);
   1.195  qed "less_imp_add_less";
   1.196  
   1.197 -goal Arith.thy "m+k<=n --> m<=(n::nat)";
   1.198 +goal thy "m+k<=n --> m<=(n::nat)";
   1.199  by (induct_tac "k" 1);
   1.200  by (ALLGOALS Asm_simp_tac);
   1.201  by (blast_tac (claset() addDs [Suc_leD]) 1);
   1.202  qed_spec_mp "add_leD1";
   1.203  
   1.204 -goal Arith.thy "!!n::nat. m+k<=n ==> k<=n";
   1.205 +goal thy "!!n::nat. m+k<=n ==> k<=n";
   1.206  by (full_simp_tac (simpset() addsimps [add_commute]) 1);
   1.207  by (etac add_leD1 1);
   1.208  qed_spec_mp "add_leD2";
   1.209  
   1.210 -goal Arith.thy "!!n::nat. m+k<=n ==> m<=n & k<=n";
   1.211 +goal thy "!!n::nat. m+k<=n ==> m<=n & k<=n";
   1.212  by (blast_tac (claset() addDs [add_leD1, add_leD2]) 1);
   1.213  bind_thm ("add_leE", result() RS conjE);
   1.214  
   1.215 -goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n";
   1.216 +goal thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n";
   1.217  by (safe_tac (claset() addSDs [less_eq_Suc_add]));
   1.218  by (asm_full_simp_tac
   1.219      (simpset() delsimps [add_Suc_right]
   1.220 @@ -226,13 +220,13 @@
   1.221  (*** Monotonicity of Addition ***)
   1.222  
   1.223  (*strict, in 1st argument*)
   1.224 -goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k";
   1.225 +goal thy "!!i j k::nat. i < j ==> i + k < j + k";
   1.226  by (induct_tac "k" 1);
   1.227  by (ALLGOALS Asm_simp_tac);
   1.228  qed "add_less_mono1";
   1.229  
   1.230  (*strict, in both arguments*)
   1.231 -goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l";
   1.232 +goal thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l";
   1.233  by (rtac (add_less_mono1 RS less_trans) 1);
   1.234  by (REPEAT (assume_tac 1));
   1.235  by (induct_tac "j" 1);
   1.236 @@ -240,7 +234,7 @@
   1.237  qed "add_less_mono";
   1.238  
   1.239  (*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
   1.240 -val [lt_mono,le] = goal Arith.thy
   1.241 +val [lt_mono,le] = goal thy
   1.242       "[| !!i j::nat. i<j ==> f(i) < f(j);       \
   1.243  \        i <= j                                 \
   1.244  \     |] ==> f(i) <= (f(j)::nat)";
   1.245 @@ -250,14 +244,14 @@
   1.246  qed "less_mono_imp_le_mono";
   1.247  
   1.248  (*non-strict, in 1st argument*)
   1.249 -goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k";
   1.250 +goal thy "!!i j k::nat. i<=j ==> i + k <= j + k";
   1.251  by (res_inst_tac [("f", "%j. j+k")] less_mono_imp_le_mono 1);
   1.252  by (etac add_less_mono1 1);
   1.253  by (assume_tac 1);
   1.254  qed "add_le_mono1";
   1.255  
   1.256  (*non-strict, in both arguments*)
   1.257 -goal Arith.thy "!!k l::nat. [|i<=j;  k<=l |] ==> i + k <= j + l";
   1.258 +goal thy "!!k l::nat. [|i<=j;  k<=l |] ==> i + k <= j + l";
   1.259  by (etac (add_le_mono1 RS le_trans) 1);
   1.260  by (simp_tac (simpset() addsimps [add_commute]) 1);
   1.261  (*j moves to the end because it is free while k, l are bound*)
   1.262 @@ -268,56 +262,56 @@
   1.263  (*** Multiplication ***)
   1.264  
   1.265  (*right annihilation in product*)
   1.266 -qed_goal "mult_0_right" Arith.thy "m * 0 = 0"
   1.267 +qed_goal "mult_0_right" thy "m * 0 = 0"
   1.268   (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
   1.269  
   1.270  (*right successor law for multiplication*)
   1.271 -qed_goal "mult_Suc_right" Arith.thy  "m * Suc(n) = m + (m * n)"
   1.272 +qed_goal "mult_Suc_right" thy  "m * Suc(n) = m + (m * n)"
   1.273   (fn _ => [induct_tac "m" 1,
   1.274             ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]);
   1.275  
   1.276  Addsimps [mult_0_right, mult_Suc_right];
   1.277  
   1.278 -goal Arith.thy "1 * n = n";
   1.279 +goal thy "1 * n = n";
   1.280  by (Asm_simp_tac 1);
   1.281  qed "mult_1";
   1.282  
   1.283 -goal Arith.thy "n * 1 = n";
   1.284 +goal thy "n * 1 = n";
   1.285  by (Asm_simp_tac 1);
   1.286  qed "mult_1_right";
   1.287  
   1.288  (*Commutative law for multiplication*)
   1.289 -qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)"
   1.290 +qed_goal "mult_commute" thy "m * n = n * (m::nat)"
   1.291   (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
   1.292  
   1.293  (*addition distributes over multiplication*)
   1.294 -qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)"
   1.295 +qed_goal "add_mult_distrib" thy "(m + n)*k = (m*k) + ((n*k)::nat)"
   1.296   (fn _ => [induct_tac "m" 1,
   1.297             ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]);
   1.298  
   1.299 -qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)"
   1.300 +qed_goal "add_mult_distrib2" thy "k*(m + n) = (k*m) + ((k*n)::nat)"
   1.301   (fn _ => [induct_tac "m" 1,
   1.302             ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]);
   1.303  
   1.304  (*Associative law for multiplication*)
   1.305 -qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)"
   1.306 +qed_goal "mult_assoc" thy "(m * n) * k = m * ((n * k)::nat)"
   1.307    (fn _ => [induct_tac "m" 1, 
   1.308              ALLGOALS (asm_simp_tac (simpset() addsimps [add_mult_distrib]))]);
   1.309  
   1.310 -qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)"
   1.311 +qed_goal "mult_left_commute" thy "x*(y*z) = y*((x*z)::nat)"
   1.312   (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
   1.313             rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
   1.314  
   1.315  val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
   1.316  
   1.317 -goal Arith.thy "(m*n = 0) = (m=0 | n=0)";
   1.318 +goal thy "(m*n = 0) = (m=0 | n=0)";
   1.319  by (induct_tac "m" 1);
   1.320  by (induct_tac "n" 2);
   1.321  by (ALLGOALS Asm_simp_tac);
   1.322  qed "mult_is_0";
   1.323  Addsimps [mult_is_0];
   1.324  
   1.325 -goal Arith.thy "!!m::nat. m <= m*m";
   1.326 +goal thy "!!m::nat. m <= m*m";
   1.327  by (induct_tac "m" 1);
   1.328  by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_assoc RS sym])));
   1.329  by (etac (le_add2 RSN (2,le_trans)) 1);
   1.330 @@ -327,21 +321,21 @@
   1.331  (*** Difference ***)
   1.332  
   1.333  
   1.334 -qed_goal "diff_self_eq_0" Arith.thy "m - m = 0"
   1.335 +qed_goal "diff_self_eq_0" thy "m - m = 0"
   1.336   (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
   1.337  Addsimps [diff_self_eq_0];
   1.338  
   1.339  (*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
   1.340 -goal Arith.thy "~ m<n --> n+(m-n) = (m::nat)";
   1.341 +goal thy "~ m<n --> n+(m-n) = (m::nat)";
   1.342  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   1.343  by (ALLGOALS Asm_simp_tac);
   1.344  qed_spec_mp "add_diff_inverse";
   1.345  
   1.346 -goal Arith.thy "!!m. n<=m ==> n+(m-n) = (m::nat)";
   1.347 +goal thy "!!m. n<=m ==> n+(m-n) = (m::nat)";
   1.348  by (asm_simp_tac (simpset() addsimps [add_diff_inverse, not_less_iff_le]) 1);
   1.349  qed "le_add_diff_inverse";
   1.350  
   1.351 -goal Arith.thy "!!m. n<=m ==> (m-n)+n = (m::nat)";
   1.352 +goal thy "!!m. n<=m ==> (m-n)+n = (m::nat)";
   1.353  by (asm_simp_tac (simpset() addsimps [le_add_diff_inverse, add_commute]) 1);
   1.354  qed "le_add_diff_inverse2";
   1.355  
   1.356 @@ -350,25 +344,28 @@
   1.357  
   1.358  (*** More results about difference ***)
   1.359  
   1.360 -val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
   1.361 +val [prem] = goal thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
   1.362  by (rtac (prem RS rev_mp) 1);
   1.363  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   1.364  by (ALLGOALS Asm_simp_tac);
   1.365  qed "Suc_diff_n";
   1.366  
   1.367 -goal Arith.thy "m - n < Suc(m)";
   1.368 +goal thy "m - n < Suc(m)";
   1.369  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   1.370  by (etac less_SucE 3);
   1.371  by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq])));
   1.372  qed "diff_less_Suc";
   1.373  
   1.374 -goal Arith.thy "!!m::nat. m - n <= m";
   1.375 +goal thy "!!m::nat. m - n <= m";
   1.376  by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
   1.377  by (ALLGOALS Asm_simp_tac);
   1.378  qed "diff_le_self";
   1.379  Addsimps [diff_le_self];
   1.380  
   1.381 -goal Arith.thy "!!i::nat. i-j-k = i - (j+k)";
   1.382 +(* j<k ==> j-n < k *)
   1.383 +bind_thm ("less_imp_diff_less", diff_le_self RS le_less_trans);
   1.384 +
   1.385 +goal thy "!!i::nat. i-j-k = i - (j+k)";
   1.386  by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
   1.387  by (ALLGOALS Asm_simp_tac);
   1.388  qed "diff_diff_left";
   1.389 @@ -376,95 +373,111 @@
   1.390  (* This is a trivial consequence of diff_diff_left;
   1.391     could be got rid of if diff_diff_left were in the simpset...
   1.392  *)
   1.393 -goal Arith.thy "(Suc m - n)-1 = m - n";
   1.394 +goal thy "(Suc m - n)-1 = m - n";
   1.395  by (simp_tac (simpset() addsimps [diff_diff_left]) 1);
   1.396  qed "pred_Suc_diff";
   1.397  Addsimps [pred_Suc_diff];
   1.398  
   1.399 +goal thy "!!n. 0<n ==> n - Suc i < n";
   1.400 +by (res_inst_tac [("n","n")] natE 1);
   1.401 +by Safe_tac;
   1.402 +by (asm_simp_tac (simpset() addsimps [le_eq_less_Suc RS sym]) 1);
   1.403 +qed "diff_Suc_less";
   1.404 +Addsimps [diff_Suc_less];
   1.405 +
   1.406 +goal thy "!!n::nat. m - n <= Suc m - n";
   1.407 +by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   1.408 +by (ALLGOALS Asm_simp_tac);
   1.409 +qed "diff_le_Suc_diff";
   1.410 +
   1.411  (*This and the next few suggested by Florian Kammueller*)
   1.412 -goal Arith.thy "!!i::nat. i-j-k = i-k-j";
   1.413 +goal thy "!!i::nat. i-j-k = i-k-j";
   1.414  by (simp_tac (simpset() addsimps [diff_diff_left, add_commute]) 1);
   1.415  qed "diff_commute";
   1.416  
   1.417 -goal Arith.thy "!!i j k:: nat. k<=j --> j<=i --> i - (j - k) = i - j + k";
   1.418 +goal thy "!!i j k:: nat. k<=j --> j<=i --> i - (j - k) = i - j + k";
   1.419  by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
   1.420  by (ALLGOALS Asm_simp_tac);
   1.421  by (asm_simp_tac
   1.422      (simpset() addsimps [Suc_diff_n, le_imp_less_Suc, le_Suc_eq]) 1);
   1.423  qed_spec_mp "diff_diff_right";
   1.424  
   1.425 -goal Arith.thy "!!i j k:: nat. k<=j --> (i + j) - k = i + (j - k)";
   1.426 +goal thy "!!i j k:: nat. k<=j --> (i + j) - k = i + (j - k)";
   1.427  by (res_inst_tac [("m","j"),("n","k")] diff_induct 1);
   1.428  by (ALLGOALS Asm_simp_tac);
   1.429  qed_spec_mp "diff_add_assoc";
   1.430  
   1.431 -goal Arith.thy "!!n::nat. (n+m) - n = m";
   1.432 +goal thy "!!i j k:: nat. k<=j --> (j + i) - k = i + (j - k)";
   1.433 +by (asm_simp_tac (simpset() addsimps [add_commute, diff_add_assoc]) 1);
   1.434 +qed_spec_mp "diff_add_assoc2";
   1.435 +
   1.436 +goal thy "!!n::nat. (n+m) - n = m";
   1.437  by (induct_tac "n" 1);
   1.438  by (ALLGOALS Asm_simp_tac);
   1.439  qed "diff_add_inverse";
   1.440  Addsimps [diff_add_inverse];
   1.441  
   1.442 -goal Arith.thy "!!n::nat.(m+n) - n = m";
   1.443 +goal thy "!!n::nat.(m+n) - n = m";
   1.444  by (simp_tac (simpset() addsimps [diff_add_assoc]) 1);
   1.445  qed "diff_add_inverse2";
   1.446  Addsimps [diff_add_inverse2];
   1.447  
   1.448 -goal Arith.thy "!!i j k::nat. i<=j ==> (j-i=k) = (j=k+i)";
   1.449 +goal thy "!!i j k::nat. i<=j ==> (j-i=k) = (j=k+i)";
   1.450  by Safe_tac;
   1.451  by (ALLGOALS Asm_simp_tac);
   1.452  qed "le_imp_diff_is_add";
   1.453  
   1.454 -val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0";
   1.455 +val [prem] = goal thy "m < Suc(n) ==> m-n = 0";
   1.456  by (rtac (prem RS rev_mp) 1);
   1.457  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   1.458  by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
   1.459  by (ALLGOALS Asm_simp_tac);
   1.460  qed "less_imp_diff_is_0";
   1.461  
   1.462 -val prems = goal Arith.thy "m-n = 0  -->  n-m = 0  -->  m=n";
   1.463 +val prems = goal thy "m-n = 0  -->  n-m = 0  -->  m=n";
   1.464  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   1.465  by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
   1.466  qed_spec_mp "diffs0_imp_equal";
   1.467  
   1.468 -val [prem] = goal Arith.thy "m<n ==> 0<n-m";
   1.469 +val [prem] = goal thy "m<n ==> 0<n-m";
   1.470  by (rtac (prem RS rev_mp) 1);
   1.471  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   1.472  by (ALLGOALS Asm_simp_tac);
   1.473  qed "less_imp_diff_positive";
   1.474  
   1.475 -goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
   1.476 +goal thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
   1.477  by (simp_tac (simpset() addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]) 1);
   1.478  qed "if_Suc_diff_n";
   1.479  
   1.480 -goal Arith.thy "Suc(m)-n <= Suc(m-n)";
   1.481 +goal thy "Suc(m)-n <= Suc(m-n)";
   1.482  by (simp_tac (simpset() addsimps [if_Suc_diff_n]) 1);
   1.483  qed "diff_Suc_le_Suc_diff";
   1.484  
   1.485 -goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
   1.486 +goal thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
   1.487  by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
   1.488  by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac));
   1.489  qed "zero_induct_lemma";
   1.490  
   1.491 -val prems = goal Arith.thy "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
   1.492 +val prems = goal thy "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
   1.493  by (rtac (diff_self_eq_0 RS subst) 1);
   1.494  by (rtac (zero_induct_lemma RS mp RS mp) 1);
   1.495  by (REPEAT (ares_tac ([impI,allI]@prems) 1));
   1.496  qed "zero_induct";
   1.497  
   1.498 -goal Arith.thy "!!k::nat. (k+m) - (k+n) = m - n";
   1.499 +goal thy "!!k::nat. (k+m) - (k+n) = m - n";
   1.500  by (induct_tac "k" 1);
   1.501  by (ALLGOALS Asm_simp_tac);
   1.502  qed "diff_cancel";
   1.503  Addsimps [diff_cancel];
   1.504  
   1.505 -goal Arith.thy "!!m::nat. (m+k) - (n+k) = m - n";
   1.506 +goal thy "!!m::nat. (m+k) - (n+k) = m - n";
   1.507  val add_commute_k = read_instantiate [("n","k")] add_commute;
   1.508  by (asm_simp_tac (simpset() addsimps ([add_commute_k])) 1);
   1.509  qed "diff_cancel2";
   1.510  Addsimps [diff_cancel2];
   1.511  
   1.512  (*From Clemens Ballarin*)
   1.513 -goal Arith.thy "!!n::nat. [| k<=n; n<=m |] ==> (m-k) - (n-k) = m-n";
   1.514 +goal thy "!!n::nat. [| k<=n; n<=m |] ==> (m-k) - (n-k) = m-n";
   1.515  by (subgoal_tac "k<=n --> n<=m --> (m-k) - (n-k) = m-n" 1);
   1.516  by (Asm_full_simp_tac 1);
   1.517  by (induct_tac "k" 1);
   1.518 @@ -479,7 +492,7 @@
   1.519  		       addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1);
   1.520  qed "diff_right_cancel";
   1.521  
   1.522 -goal Arith.thy "!!n::nat. n - (n+m) = 0";
   1.523 +goal thy "!!n::nat. n - (n+m) = 0";
   1.524  by (induct_tac "n" 1);
   1.525  by (ALLGOALS Asm_simp_tac);
   1.526  qed "diff_add_0";
   1.527 @@ -487,12 +500,12 @@
   1.528  
   1.529  (** Difference distributes over multiplication **)
   1.530  
   1.531 -goal Arith.thy "!!m::nat. (m - n) * k = (m * k) - (n * k)";
   1.532 +goal thy "!!m::nat. (m - n) * k = (m * k) - (n * k)";
   1.533  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
   1.534  by (ALLGOALS Asm_simp_tac);
   1.535  qed "diff_mult_distrib" ;
   1.536  
   1.537 -goal Arith.thy "!!m::nat. k * (m - n) = (k * m) - (k * n)";
   1.538 +goal thy "!!m::nat. k * (m - n) = (k * m) - (k * n)";
   1.539  val mult_commute_k = read_instantiate [("m","k")] mult_commute;
   1.540  by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1);
   1.541  qed "diff_mult_distrib2" ;
   1.542 @@ -501,13 +514,13 @@
   1.543  
   1.544  (*** Monotonicity of Multiplication ***)
   1.545  
   1.546 -goal Arith.thy "!!i::nat. i<=j ==> i*k<=j*k";
   1.547 +goal thy "!!i::nat. i<=j ==> i*k<=j*k";
   1.548  by (induct_tac "k" 1);
   1.549  by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_le_mono])));
   1.550  qed "mult_le_mono1";
   1.551  
   1.552  (*<=monotonicity, BOTH arguments*)
   1.553 -goal Arith.thy "!!i::nat. [| i<=j; k<=l |] ==> i*k<=j*l";
   1.554 +goal thy "!!i::nat. [| i<=j; k<=l |] ==> i*k<=j*l";
   1.555  by (etac (mult_le_mono1 RS le_trans) 1);
   1.556  by (rtac le_trans 1);
   1.557  by (stac mult_commute 2);
   1.558 @@ -516,26 +529,26 @@
   1.559  qed "mult_le_mono";
   1.560  
   1.561  (*strict, in 1st argument; proof is by induction on k>0*)
   1.562 -goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j";
   1.563 +goal thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j";
   1.564  by (eres_inst_tac [("i","0")] less_natE 1);
   1.565  by (Asm_simp_tac 1);
   1.566  by (induct_tac "x" 1);
   1.567  by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_less_mono])));
   1.568  qed "mult_less_mono2";
   1.569  
   1.570 -goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k";
   1.571 +goal thy "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k";
   1.572  by (dtac mult_less_mono2 1);
   1.573  by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute])));
   1.574  qed "mult_less_mono1";
   1.575  
   1.576 -goal Arith.thy "(0 < m*n) = (0<m & 0<n)";
   1.577 +goal thy "(0 < m*n) = (0<m & 0<n)";
   1.578  by (induct_tac "m" 1);
   1.579  by (induct_tac "n" 2);
   1.580  by (ALLGOALS Asm_simp_tac);
   1.581  qed "zero_less_mult_iff";
   1.582  Addsimps [zero_less_mult_iff];
   1.583  
   1.584 -goal Arith.thy "(m*n = 1) = (m=1 & n=1)";
   1.585 +goal thy "(m*n = 1) = (m=1 & n=1)";
   1.586  by (induct_tac "m" 1);
   1.587  by (Simp_tac 1);
   1.588  by (induct_tac "n" 1);
   1.589 @@ -544,29 +557,29 @@
   1.590  qed "mult_eq_1_iff";
   1.591  Addsimps [mult_eq_1_iff];
   1.592  
   1.593 -goal Arith.thy "!!k. 0<k ==> (m*k < n*k) = (m<n)";
   1.594 +goal thy "!!k. 0<k ==> (m*k < n*k) = (m<n)";
   1.595  by (safe_tac (claset() addSIs [mult_less_mono1]));
   1.596  by (cut_facts_tac [less_linear] 1);
   1.597  by (blast_tac (claset() addIs [mult_less_mono1] addEs [less_asym]) 1);
   1.598  qed "mult_less_cancel2";
   1.599  
   1.600 -goal Arith.thy "!!k. 0<k ==> (k*m < k*n) = (m<n)";
   1.601 +goal thy "!!k. 0<k ==> (k*m < k*n) = (m<n)";
   1.602  by (dtac mult_less_cancel2 1);
   1.603  by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1);
   1.604  qed "mult_less_cancel1";
   1.605  Addsimps [mult_less_cancel1, mult_less_cancel2];
   1.606  
   1.607 -goal Arith.thy "(Suc k * m < Suc k * n) = (m < n)";
   1.608 +goal thy "(Suc k * m < Suc k * n) = (m < n)";
   1.609  by (rtac mult_less_cancel1 1);
   1.610  by (Simp_tac 1);
   1.611  qed "Suc_mult_less_cancel1";
   1.612  
   1.613 -goalw Arith.thy [le_def] "(Suc k * m <= Suc k * n) = (m <= n)";
   1.614 +goalw thy [le_def] "(Suc k * m <= Suc k * n) = (m <= n)";
   1.615  by (simp_tac (simpset_of HOL.thy) 1);
   1.616  by (rtac Suc_mult_less_cancel1 1);
   1.617  qed "Suc_mult_le_cancel1";
   1.618  
   1.619 -goal Arith.thy "!!k. 0<k ==> (m*k = n*k) = (m=n)";
   1.620 +goal thy "!!k. 0<k ==> (m*k = n*k) = (m=n)";
   1.621  by (cut_facts_tac [less_linear] 1);
   1.622  by Safe_tac;
   1.623  by (assume_tac 2);
   1.624 @@ -574,13 +587,13 @@
   1.625  by (ALLGOALS Asm_full_simp_tac);
   1.626  qed "mult_cancel2";
   1.627  
   1.628 -goal Arith.thy "!!k. 0<k ==> (k*m = k*n) = (m=n)";
   1.629 +goal thy "!!k. 0<k ==> (k*m = k*n) = (m=n)";
   1.630  by (dtac mult_cancel2 1);
   1.631  by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1);
   1.632  qed "mult_cancel1";
   1.633  Addsimps [mult_cancel1, mult_cancel2];
   1.634  
   1.635 -goal Arith.thy "(Suc k * m = Suc k * n) = (m = n)";
   1.636 +goal thy "(Suc k * m = Suc k * n) = (m = n)";
   1.637  by (rtac mult_cancel1 1);
   1.638  by (Simp_tac 1);
   1.639  qed "Suc_mult_cancel1";
   1.640 @@ -588,7 +601,7 @@
   1.641  
   1.642  (** Lemma for gcd **)
   1.643  
   1.644 -goal Arith.thy "!!m n. m = m*n ==> n=1 | m=0";
   1.645 +goal thy "!!m n. m = m*n ==> n=1 | m=0";
   1.646  by (dtac sym 1);
   1.647  by (rtac disjCI 1);
   1.648  by (rtac nat_less_cases 1 THEN assume_tac 2);
   1.649 @@ -599,7 +612,7 @@
   1.650  
   1.651  (*** Subtraction laws -- from Clemens Ballarin ***)
   1.652  
   1.653 -goal Arith.thy "!! a b c::nat. [| a < b; c <= a |] ==> a-c < b-c";
   1.654 +goal thy "!! a b c::nat. [| a < b; c <= a |] ==> a-c < b-c";
   1.655  by (subgoal_tac "c+(a-c) < c+(b-c)" 1);
   1.656  by (Full_simp_tac 1);
   1.657  by (subgoal_tac "c <= b" 1);
   1.658 @@ -607,29 +620,29 @@
   1.659  by (Asm_simp_tac 1);
   1.660  qed "diff_less_mono";
   1.661  
   1.662 -goal Arith.thy "!! a b c::nat. a+b < c ==> a < c-b";
   1.663 +goal thy "!! a b c::nat. a+b < c ==> a < c-b";
   1.664  by (dtac diff_less_mono 1);
   1.665  by (rtac le_add2 1);
   1.666  by (Asm_full_simp_tac 1);
   1.667  qed "add_less_imp_less_diff";
   1.668  
   1.669 -goal Arith.thy "!! n. n <= m ==> Suc m - n = Suc (m - n)";
   1.670 +goal thy "!! n. n <= m ==> Suc m - n = Suc (m - n)";
   1.671  by (asm_full_simp_tac (simpset() addsimps [Suc_diff_n, le_eq_less_Suc]) 1);
   1.672  qed "Suc_diff_le";
   1.673  
   1.674 -goal Arith.thy "!! n. Suc i <= n ==> Suc (n - Suc i) = n - i";
   1.675 +goal thy "!! n. Suc i <= n ==> Suc (n - Suc i) = n - i";
   1.676  by (asm_full_simp_tac
   1.677      (simpset() addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1);
   1.678  qed "Suc_diff_Suc";
   1.679  
   1.680 -goal Arith.thy "!! i::nat. i <= n ==> n - (n - i) = i";
   1.681 +goal thy "!! i::nat. i <= n ==> n - (n - i) = i";
   1.682  by (etac rev_mp 1);
   1.683  by (res_inst_tac [("m","n"),("n","i")] diff_induct 1);
   1.684  by (ALLGOALS (asm_simp_tac  (simpset() addsimps [Suc_diff_le])));
   1.685  qed "diff_diff_cancel";
   1.686  Addsimps [diff_diff_cancel];
   1.687  
   1.688 -goal Arith.thy "!!k::nat. k <= n ==> m <= n + m - k";
   1.689 +goal thy "!!k::nat. k <= n ==> m <= n + m - k";
   1.690  by (etac rev_mp 1);
   1.691  by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1);
   1.692  by (Simp_tac 1);
   1.693 @@ -638,22 +651,18 @@
   1.694  qed "le_add_diff";
   1.695  
   1.696  
   1.697 +
   1.698  (** (Anti)Monotonicity of subtraction -- by Stefan Merz **)
   1.699  
   1.700  (* Monotonicity of subtraction in first argument *)
   1.701 -goal Arith.thy "!!n::nat. m<=n --> (m-l) <= (n-l)";
   1.702 +goal thy "!!n::nat. m<=n --> (m-l) <= (n-l)";
   1.703  by (induct_tac "n" 1);
   1.704  by (Simp_tac 1);
   1.705  by (simp_tac (simpset() addsimps [le_Suc_eq]) 1);
   1.706 -by (rtac impI 1);
   1.707 -by (etac impE 1);
   1.708 -by (atac 1);
   1.709 -by (etac le_trans 1);
   1.710 -by (res_inst_tac [("m1","n")] (pred_Suc_diff RS subst) 1);
   1.711 -by (simp_tac (simpset() addsimps [diff_Suc] addsplits [expand_nat_case]) 1);
   1.712 +by (blast_tac (claset() addIs [diff_le_Suc_diff, le_trans]) 1);
   1.713  qed_spec_mp "diff_le_mono";
   1.714  
   1.715 -goal Arith.thy "!!n::nat. m<=n ==> (l-n) <= (l-m)";
   1.716 +goal thy "!!n::nat. m<=n ==> (l-n) <= (l-m)";
   1.717  by (induct_tac "l" 1);
   1.718  by (Simp_tac 1);
   1.719  by (case_tac "n <= l" 1);