src/HOL/Int.thy
changeset 82518 da14e77a48b2
parent 82349 a854ca7ca7d9
equal deleted inserted replaced
82517:111b1b2a2d13 82518:da14e77a48b2
   933   by (force simp add: Ints_def simp flip: of_int_add intro: range_eqI)
   933   by (force simp add: Ints_def simp flip: of_int_add intro: range_eqI)
   934 
   934 
   935 lemma Ints_minus [simp]: "a \<in> \<int> \<Longrightarrow> -a \<in> \<int>"
   935 lemma Ints_minus [simp]: "a \<in> \<int> \<Longrightarrow> -a \<in> \<int>"
   936   by (force simp add: Ints_def simp flip: of_int_minus intro: range_eqI)
   936   by (force simp add: Ints_def simp flip: of_int_minus intro: range_eqI)
   937 
   937 
   938 lemma minus_in_Ints_iff: "-x \<in> \<int> \<longleftrightarrow> x \<in> \<int>"
   938 lemma minus_in_Ints_iff [simp]: "-x \<in> \<int> \<longleftrightarrow> x \<in> \<int>"
   939   using Ints_minus[of x] Ints_minus[of "-x"] by auto
   939   using Ints_minus[of x] Ints_minus[of "-x"] by auto
   940 
   940 
   941 lemma Ints_diff [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a - b \<in> \<int>"
   941 lemma Ints_diff [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a - b \<in> \<int>"
   942   by (force simp add: Ints_def simp flip: of_int_diff intro: range_eqI)
   942   by (force simp add: Ints_def simp flip: of_int_diff intro: range_eqI)
   943 
   943 
  1077   also have "\<dots> \<longleftrightarrow> a < 0"
  1077   also have "\<dots> \<longleftrightarrow> a < 0"
  1078     by (simp add: a)
  1078     by (simp add: a)
  1079   finally show ?thesis .
  1079   finally show ?thesis .
  1080 qed
  1080 qed
  1081 
  1081 
       
  1082 lemma add_in_Ints_iff_left [simp]: "x \<in> \<int> \<Longrightarrow> x + y \<in> \<int> \<longleftrightarrow> y \<in> \<int>"
       
  1083   by (metis Ints_add Ints_diff add_diff_cancel_left')
       
  1084 
       
  1085 lemma add_in_Ints_iff_right [simp]: "y \<in> \<int> \<Longrightarrow> x + y \<in> \<int> \<longleftrightarrow> x \<in> \<int>"
       
  1086   by (subst add.commute) auto
       
  1087 
       
  1088 lemma diff_in_Ints_iff_left [simp]: "x \<in> \<int> \<Longrightarrow> x - y \<in> \<int> \<longleftrightarrow> y \<in> \<int>"
       
  1089   by (metis Ints_diff add_in_Ints_iff_left diff_add_cancel)
       
  1090 
       
  1091 lemma diff_in_Ints_iff_right [simp]: "y \<in> \<int> \<Longrightarrow> x - y \<in> \<int> \<longleftrightarrow> x \<in> \<int>"
       
  1092   by (metis Ints_minus diff_in_Ints_iff_left minus_diff_eq)
       
  1093 
       
  1094 lemmas [simp] = minus_in_Ints_iff
       
  1095 
       
  1096 lemma fraction_not_in_Ints:
       
  1097   assumes "\<not>(n dvd m)" "n \<noteq> 0"
       
  1098   shows   "of_int m / of_int n \<notin> (\<int> :: 'a :: {division_ring,ring_char_0} set)"
       
  1099 proof
       
  1100   assume "of_int m / (of_int n :: 'a) \<in> \<int>"
       
  1101   then obtain k where "of_int m / of_int n = (of_int k :: 'a)" by (elim Ints_cases)
       
  1102   with assms have "of_int m = (of_int (k * n) :: 'a)" by (auto simp add: field_split_simps)
       
  1103   hence "m = k * n" by (subst (asm) of_int_eq_iff)
       
  1104   hence "n dvd m" by simp
       
  1105   with assms(1) show False by contradiction
       
  1106 qed
       
  1107 
       
  1108 lemma of_int_div_of_int_in_Ints_iff:
       
  1109   "(of_int n / of_int m :: 'a :: {division_ring,ring_char_0}) \<in> \<int> \<longleftrightarrow> m = 0 \<or> m dvd n"
       
  1110 proof
       
  1111   assume *: "m = 0 \<or> m dvd n"
       
  1112   have "of_int n / of_int m \<in> (\<int> :: 'a set)" if "m \<noteq> 0" "m dvd n"
       
  1113   proof -
       
  1114     from \<open>m dvd n\<close> obtain k where "n = m * k"
       
  1115       by (elim dvdE)
       
  1116     hence "n = k * m"
       
  1117       by (simp add: mult.commute)
       
  1118     hence "of_int n / (of_int m :: 'a) = of_int k"
       
  1119       using \<open>m \<noteq> 0\<close> by (simp add: field_simps)
       
  1120     also have "\<dots> \<in> \<int>"
       
  1121       by auto
       
  1122     finally show ?thesis .
       
  1123   qed
       
  1124   with * show "of_int n / of_int m \<in> (\<int> :: 'a set)"
       
  1125     by (cases "m = 0") auto
       
  1126 next
       
  1127   assume *: "(of_int n / of_int m :: 'a) \<in> \<int>"
       
  1128   thus "m = 0 \<or> m dvd n"
       
  1129     using fraction_not_in_Ints[of m n, where ?'a = 'a] by auto
       
  1130 qed
       
  1131 
       
  1132 lemma fraction_numeral_not_in_Ints [simp]:
       
  1133   assumes "\<not>(numeral b :: int) dvd numeral a"
       
  1134   shows   "numeral a / numeral b \<notin> (\<int> :: 'a :: {division_ring, ring_char_0} set)"
       
  1135   using fraction_not_in_Ints[of "numeral b" "numeral a", where ?'a = 'a] assms by simp
       
  1136 
  1082 
  1137 
  1083 subsection \<open>\<^term>\<open>sum\<close> and \<^term>\<open>prod\<close>\<close>
  1138 subsection \<open>\<^term>\<open>sum\<close> and \<^term>\<open>prod\<close>\<close>
  1084 
  1139 
  1085 context semiring_1
  1140 context semiring_1
  1086 begin
  1141 begin
  1729 proof -
  1784 proof -
  1730   from assms have "a dvd (x + t) \<longleftrightarrow> a dvd ((x + t) + c * d)"
  1785   from assms have "a dvd (x + t) \<longleftrightarrow> a dvd ((x + t) + c * d)"
  1731     by (simp add: dvd_add_left_iff)
  1786     by (simp add: dvd_add_left_iff)
  1732   then show ?thesis
  1787   then show ?thesis
  1733     by (simp add: ac_simps)
  1788     by (simp add: ac_simps)
       
  1789 qed
       
  1790 
       
  1791 lemma fraction_numeral_not_in_Ints' [simp]:
       
  1792   assumes "b \<noteq> Num.One"
       
  1793   shows   "1 / numeral b \<notin> (\<int> :: 'a :: {division_ring, ring_char_0} set)"
       
  1794 proof -
       
  1795   have *: "\<not>numeral b dvd (1 :: int)"
       
  1796     using assms by simp
       
  1797   have "of_int 1 / of_int (numeral b) \<notin> (\<int> :: 'a set)"
       
  1798     by (rule fraction_not_in_Ints) (use * in auto)
       
  1799   thus ?thesis
       
  1800     by simp
  1734 qed
  1801 qed
  1735 
  1802 
  1736 
  1803 
  1737 subsection \<open>Powers with integer exponents\<close>
  1804 subsection \<open>Powers with integer exponents\<close>
  1738 
  1805