src/HOL/Arith.ML
changeset 3352 04502e5431fb
parent 3339 cfa72a70f2b5
child 3366 2402c6ab1561
     1.1 --- a/src/HOL/Arith.ML	Mon May 26 14:54:24 1997 +0200
     1.2 +++ b/src/HOL/Arith.ML	Tue May 27 13:03:41 1997 +0200
     1.3 @@ -325,10 +325,10 @@
     1.4  Addsimps [diff_self_eq_0];
     1.5  
     1.6  (*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
     1.7 -val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)";
     1.8 +val [prem] = goal Arith.thy "~ m<n ==> n+(m-n) = (m::nat)";
     1.9  by (rtac (prem RS rev_mp) 1);
    1.10  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
    1.11 -by (ALLGOALS (Asm_simp_tac));
    1.12 +by (ALLGOALS Asm_simp_tac);
    1.13  qed "add_diff_inverse";
    1.14  
    1.15  Delsimps  [diff_Suc];
    1.16 @@ -336,6 +336,12 @@
    1.17  
    1.18  (*** More results about difference ***)
    1.19  
    1.20 +val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
    1.21 +by (rtac (prem RS rev_mp) 1);
    1.22 +by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
    1.23 +by (ALLGOALS Asm_simp_tac);
    1.24 +qed "Suc_diff_n";
    1.25 +
    1.26  goal Arith.thy "m - n < Suc(m)";
    1.27  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
    1.28  by (etac less_SucE 3);
    1.29 @@ -347,6 +353,30 @@
    1.30  by (ALLGOALS Asm_simp_tac);
    1.31  qed "diff_le_self";
    1.32  
    1.33 +goal Arith.thy "!!i::nat. i-j-k = i - (j+k)";
    1.34 +by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
    1.35 +by (ALLGOALS Asm_simp_tac);
    1.36 +qed "diff_diff_left";
    1.37 +
    1.38 +(*This and the next few suggested by Florian Kammüller*)
    1.39 +goal Arith.thy "!!i::nat. i-j-k = i-k-j";
    1.40 +by (simp_tac (!simpset addsimps [diff_diff_left, add_commute]) 1);
    1.41 +qed "diff_commute";
    1.42 +
    1.43 +goal Arith.thy "!!i j k:: nat. k<=j --> j<=i --> i - (j - k) = i - j + k";
    1.44 +by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
    1.45 +by (ALLGOALS Asm_simp_tac);
    1.46 +by (asm_simp_tac
    1.47 +    (!simpset addsimps [Suc_diff_n, le_imp_less_Suc, le_Suc_eq]) 1);
    1.48 +by (simp_tac
    1.49 +    (!simpset addsimps [add_diff_inverse, not_less_iff_le, add_commute]) 1);
    1.50 +qed_spec_mp "diff_diff_right";
    1.51 +
    1.52 +goal Arith.thy "!!i j k:: nat. k<=j --> (i + j) - k = i + (j - k)";
    1.53 +by (res_inst_tac [("m","j"),("n","k")] diff_induct 1);
    1.54 +by (ALLGOALS Asm_simp_tac);
    1.55 +qed_spec_mp "diff_add_assoc";
    1.56 +
    1.57  goal Arith.thy "!!n::nat. (n+m) - n = m";
    1.58  by (induct_tac "n" 1);
    1.59  by (ALLGOALS Asm_simp_tac);
    1.60 @@ -354,8 +384,7 @@
    1.61  Addsimps [diff_add_inverse];
    1.62  
    1.63  goal Arith.thy "!!n::nat.(m+n) - n = m";
    1.64 -by (res_inst_tac [("m1","m")] (add_commute RS ssubst) 1);
    1.65 -by (REPEAT (ares_tac [diff_add_inverse] 1));
    1.66 +by (simp_tac (!simpset addsimps [diff_add_assoc]) 1);
    1.67  qed "diff_add_inverse2";
    1.68  Addsimps [diff_add_inverse2];
    1.69  
    1.70 @@ -363,7 +392,7 @@
    1.71  by (rtac (prem RS rev_mp) 1);
    1.72  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
    1.73  by (asm_simp_tac (!simpset addsimps [less_Suc_eq]) 1);
    1.74 -by (ALLGOALS (Asm_simp_tac));
    1.75 +by (ALLGOALS Asm_simp_tac);
    1.76  qed "less_imp_diff_is_0";
    1.77  
    1.78  val prems = goal Arith.thy "m-n = 0  -->  n-m = 0  -->  m=n";
    1.79 @@ -374,15 +403,9 @@
    1.80  val [prem] = goal Arith.thy "m<n ==> 0<n-m";
    1.81  by (rtac (prem RS rev_mp) 1);
    1.82  by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
    1.83 -by (ALLGOALS (Asm_simp_tac));
    1.84 +by (ALLGOALS Asm_simp_tac);
    1.85  qed "less_imp_diff_positive";
    1.86  
    1.87 -val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
    1.88 -by (rtac (prem RS rev_mp) 1);
    1.89 -by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
    1.90 -by (ALLGOALS (Asm_simp_tac));
    1.91 -qed "Suc_diff_n";
    1.92 -
    1.93  goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
    1.94  by (simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]
    1.95                      setloop (split_tac [expand_if])) 1);