src/HOL/Int.thy
changeset 61944 5d06ecfdb472
parent 61799 4cf66f21b764
child 62128 3201ddb00097
equal deleted inserted replaced
61943:7fba644ed827 61944:5d06ecfdb472
   527 text\<open>This version is proved for all ordered rings, not just integers!
   527 text\<open>This version is proved for all ordered rings, not just integers!
   528       It is proved here because attribute \<open>arith_split\<close> is not available
   528       It is proved here because attribute \<open>arith_split\<close> is not available
   529       in theory \<open>Rings\<close>.
   529       in theory \<open>Rings\<close>.
   530       But is it really better than just rewriting with \<open>abs_if\<close>?\<close>
   530       But is it really better than just rewriting with \<open>abs_if\<close>?\<close>
   531 lemma abs_split [arith_split, no_atp]:
   531 lemma abs_split [arith_split, no_atp]:
   532      "P(abs(a::'a::linordered_idom)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
   532      "P \<bar>a::'a::linordered_idom\<bar> = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
   533 by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
   533 by (force dest: order_less_le_trans simp add: abs_if linorder_not_less)
   534 
   534 
   535 lemma negD: "x < 0 \<Longrightarrow> \<exists>n. x = - (int (Suc n))"
   535 lemma negD: "x < 0 \<Longrightarrow> \<exists>n. x = - (int (Suc n))"
   536 apply transfer
   536 apply transfer
   537 apply clarsimp
   537 apply clarsimp
   942 lemma nat_mult_distrib_neg: "z \<le> (0::int) ==> nat(z*z') = nat(-z) * nat(-z')"
   942 lemma nat_mult_distrib_neg: "z \<le> (0::int) ==> nat(z*z') = nat(-z) * nat(-z')"
   943 apply (rule trans)
   943 apply (rule trans)
   944 apply (rule_tac [2] nat_mult_distrib, auto)
   944 apply (rule_tac [2] nat_mult_distrib, auto)
   945 done
   945 done
   946 
   946 
   947 lemma nat_abs_mult_distrib: "nat (abs (w * z)) = nat (abs w) * nat (abs z)"
   947 lemma nat_abs_mult_distrib: "nat \<bar>w * z\<bar> = nat \<bar>w\<bar> * nat \<bar>z\<bar>"
   948 apply (cases "z=0 | w=0")
   948 apply (cases "z=0 | w=0")
   949 apply (auto simp add: abs_if nat_mult_distrib [symmetric]
   949 apply (auto simp add: abs_if nat_mult_distrib [symmetric]
   950                       nat_mult_distrib_neg [symmetric] mult_less_0_iff)
   950                       nat_mult_distrib_neg [symmetric] mult_less_0_iff)
   951 done
   951 done
   952 
   952 
  1113 qed
  1113 qed
  1114 
  1114 
  1115 subsection\<open>Intermediate value theorems\<close>
  1115 subsection\<open>Intermediate value theorems\<close>
  1116 
  1116 
  1117 lemma int_val_lemma:
  1117 lemma int_val_lemma:
  1118      "(\<forall>i<n::nat. abs(f(i+1) - f i) \<le> 1) -->
  1118      "(\<forall>i<n::nat. \<bar>f(i+1) - f i\<bar> \<le> 1) -->
  1119       f 0 \<le> k --> k \<le> f n --> (\<exists>i \<le> n. f i = (k::int))"
  1119       f 0 \<le> k --> k \<le> f n --> (\<exists>i \<le> n. f i = (k::int))"
  1120 unfolding One_nat_def
  1120 unfolding One_nat_def
  1121 apply (induct n)
  1121 apply (induct n)
  1122 apply simp
  1122 apply simp
  1123 apply (intro strip)
  1123 apply (intro strip)
  1131 done
  1131 done
  1132 
  1132 
  1133 lemmas nat0_intermed_int_val = int_val_lemma [rule_format (no_asm)]
  1133 lemmas nat0_intermed_int_val = int_val_lemma [rule_format (no_asm)]
  1134 
  1134 
  1135 lemma nat_intermed_int_val:
  1135 lemma nat_intermed_int_val:
  1136      "[| \<forall>i. m \<le> i & i < n --> abs(f(i + 1::nat) - f i) \<le> 1; m < n;
  1136      "[| \<forall>i. m \<le> i & i < n --> \<bar>f(i + 1::nat) - f i\<bar> \<le> 1; m < n;
  1137          f m \<le> k; k \<le> f n |] ==> ? i. m \<le> i & i \<le> n & f i = (k::int)"
  1137          f m \<le> k; k \<le> f n |] ==> ? i. m \<le> i & i \<le> n & f i = (k::int)"
  1138 apply (cut_tac n = "n-m" and f = "%i. f (i+m) " and k = k
  1138 apply (cut_tac n = "n-m" and f = "%i. f (i+m) " and k = k
  1139        in int_val_lemma)
  1139        in int_val_lemma)
  1140 unfolding One_nat_def
  1140 unfolding One_nat_def
  1141 apply simp
  1141 apply simp
  1430 next
  1430 next
  1431   assume H: "m * n dvd m" hence H2: "m * n dvd m * 1" by simp
  1431   assume H: "m * n dvd m" hence H2: "m * n dvd m * 1" by simp
  1432   from zdvd_mult_cancel[OF H2 mp] show "\<bar>n\<bar> = 1" by (simp only: zdvd1_eq)
  1432   from zdvd_mult_cancel[OF H2 mp] show "\<bar>n\<bar> = 1" by (simp only: zdvd1_eq)
  1433 qed
  1433 qed
  1434 
  1434 
  1435 lemma int_dvd_iff: "(int m dvd z) = (m dvd nat (abs z))"
  1435 lemma int_dvd_iff: "(int m dvd z) = (m dvd nat \<bar>z\<bar>)"
  1436   unfolding zdvd_int by (cases "z \<ge> 0") simp_all
  1436   unfolding zdvd_int by (cases "z \<ge> 0") simp_all
  1437 
  1437 
  1438 lemma dvd_int_iff: "(z dvd int m) = (nat (abs z) dvd m)"
  1438 lemma dvd_int_iff: "(z dvd int m) = (nat \<bar>z\<bar> dvd m)"
  1439   unfolding zdvd_int by (cases "z \<ge> 0") simp_all
  1439   unfolding zdvd_int by (cases "z \<ge> 0") simp_all
  1440 
  1440 
  1441 lemma dvd_int_unfold_dvd_nat:
  1441 lemma dvd_int_unfold_dvd_nat:
  1442   "k dvd l \<longleftrightarrow> nat \<bar>k\<bar> dvd nat \<bar>l\<bar>"
  1442   "k dvd l \<longleftrightarrow> nat \<bar>k\<bar> dvd nat \<bar>l\<bar>"
  1443   unfolding dvd_int_iff [symmetric] by simp
  1443   unfolding dvd_int_iff [symmetric] by simp