src/HOL/Int.thy
changeset 29667 53103fc8ffa3
parent 29046 773098b76201
child 29668 33ba3faeaa0e
equal deleted inserted replaced
29549:7187373c6cb1 29667:53103fc8ffa3
   155   show "- i + i = 0"
   155   show "- i + i = 0"
   156     by (cases i) (simp add: Zero_int_def minus add)
   156     by (cases i) (simp add: Zero_int_def minus add)
   157   show "i - j = i + - j"
   157   show "i - j = i + - j"
   158     by (simp add: diff_int_def)
   158     by (simp add: diff_int_def)
   159   show "(i * j) * k = i * (j * k)"
   159   show "(i * j) * k = i * (j * k)"
   160     by (cases i, cases j, cases k) (simp add: mult ring_simps)
   160     by (cases i, cases j, cases k) (simp add: mult algebra_simps)
   161   show "i * j = j * i"
   161   show "i * j = j * i"
   162     by (cases i, cases j) (simp add: mult ring_simps)
   162     by (cases i, cases j) (simp add: mult algebra_simps)
   163   show "1 * i = i"
   163   show "1 * i = i"
   164     by (cases i) (simp add: One_int_def mult)
   164     by (cases i) (simp add: One_int_def mult)
   165   show "(i + j) * k = i * k + j * k"
   165   show "(i + j) * k = i * k + j * k"
   166     by (cases i, cases j, cases k) (simp add: add mult ring_simps)
   166     by (cases i, cases j, cases k) (simp add: add mult algebra_simps)
   167   show "0 \<noteq> (1::int)"
   167   show "0 \<noteq> (1::int)"
   168     by (simp add: Zero_int_def One_int_def)
   168     by (simp add: Zero_int_def One_int_def)
   169 qed
   169 qed
   170 
   170 
   171 lemma int_def: "of_nat m = Abs_Integ (intrel `` {(m, 0)})"
   171 lemma int_def: "of_nat m = Abs_Integ (intrel `` {(m, 0)})"
   299   [code del]: "of_int z = contents (\<Union>(i, j) \<in> Rep_Integ z. { of_nat i - of_nat j })"
   299   [code del]: "of_int z = contents (\<Union>(i, j) \<in> Rep_Integ z. { of_nat i - of_nat j })"
   300 
   300 
   301 lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j"
   301 lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j"
   302 proof -
   302 proof -
   303   have "(\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) }) respects intrel"
   303   have "(\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) }) respects intrel"
   304     by (simp add: congruent_def compare_rls of_nat_add [symmetric]
   304     by (simp add: congruent_def algebra_simps of_nat_add [symmetric]
   305             del: of_nat_add) 
   305             del: of_nat_add) 
   306   thus ?thesis
   306   thus ?thesis
   307     by (simp add: of_int_def UN_equiv_class [OF equiv_intrel])
   307     by (simp add: of_int_def UN_equiv_class [OF equiv_intrel])
   308 qed
   308 qed
   309 
   309 
   310 lemma of_int_0 [simp]: "of_int 0 = 0"
   310 lemma of_int_0 [simp]: "of_int 0 = 0"
   311   by (simp add: of_int Zero_int_def)
   311 by (simp add: of_int Zero_int_def)
   312 
   312 
   313 lemma of_int_1 [simp]: "of_int 1 = 1"
   313 lemma of_int_1 [simp]: "of_int 1 = 1"
   314   by (simp add: of_int One_int_def)
   314 by (simp add: of_int One_int_def)
   315 
   315 
   316 lemma of_int_add [simp]: "of_int (w+z) = of_int w + of_int z"
   316 lemma of_int_add [simp]: "of_int (w+z) = of_int w + of_int z"
   317   by (cases w, cases z, simp add: compare_rls of_int OrderedGroup.compare_rls add)
   317 by (cases w, cases z, simp add: algebra_simps of_int add)
   318 
   318 
   319 lemma of_int_minus [simp]: "of_int (-z) = - (of_int z)"
   319 lemma of_int_minus [simp]: "of_int (-z) = - (of_int z)"
   320   by (cases z, simp add: compare_rls of_int minus)
   320 by (cases z, simp add: algebra_simps of_int minus)
   321 
   321 
   322 lemma of_int_diff [simp]: "of_int (w - z) = of_int w - of_int z"
   322 lemma of_int_diff [simp]: "of_int (w - z) = of_int w - of_int z"
   323   by (simp add: OrderedGroup.diff_minus diff_minus)
   323 by (simp add: OrderedGroup.diff_minus diff_minus)
   324 
   324 
   325 lemma of_int_mult [simp]: "of_int (w*z) = of_int w * of_int z"
   325 lemma of_int_mult [simp]: "of_int (w*z) = of_int w * of_int z"
   326 apply (cases w, cases z)
   326 apply (cases w, cases z)
   327 apply (simp add: compare_rls of_int left_diff_distrib right_diff_distrib
   327 apply (simp add: algebra_simps of_int mult of_nat_mult)
   328                  mult add_ac of_nat_mult)
       
   329 done
   328 done
   330 
   329 
   331 text{*Collapse nested embeddings*}
   330 text{*Collapse nested embeddings*}
   332 lemma of_int_of_nat_eq [simp]: "of_int (of_nat n) = of_nat n"
   331 lemma of_int_of_nat_eq [simp]: "of_int (of_nat n) = of_nat n"
   333   by (induct n) auto
   332 by (induct n) auto
   334 
   333 
   335 end
   334 end
   336 
   335 
   337 context ordered_idom
   336 context ordered_idom
   338 begin
   337 begin
   339 
   338 
   340 lemma of_int_le_iff [simp]:
   339 lemma of_int_le_iff [simp]:
   341   "of_int w \<le> of_int z \<longleftrightarrow> w \<le> z"
   340   "of_int w \<le> of_int z \<longleftrightarrow> w \<le> z"
   342   by (cases w, cases z, simp add: of_int le minus compare_rls of_nat_add [symmetric] del: of_nat_add)
   341 by (cases w, cases z, simp add: of_int le minus algebra_simps of_nat_add [symmetric] del: of_nat_add)
   343 
   342 
   344 text{*Special cases where either operand is zero*}
   343 text{*Special cases where either operand is zero*}
   345 lemmas of_int_0_le_iff [simp] = of_int_le_iff [of 0, simplified]
   344 lemmas of_int_0_le_iff [simp] = of_int_le_iff [of 0, simplified]
   346 lemmas of_int_le_0_iff [simp] = of_int_le_iff [of _ 0, simplified]
   345 lemmas of_int_le_0_iff [simp] = of_int_le_iff [of _ 0, simplified]
   347 
   346 
   509   have "(w \<le> z) = (0 \<le> z - w)"
   508   have "(w \<le> z) = (0 \<le> z - w)"
   510     by (simp only: le_diff_eq add_0_left)
   509     by (simp only: le_diff_eq add_0_left)
   511   also have "\<dots> = (\<exists>n. z - w = of_nat n)"
   510   also have "\<dots> = (\<exists>n. z - w = of_nat n)"
   512     by (auto elim: zero_le_imp_eq_int)
   511     by (auto elim: zero_le_imp_eq_int)
   513   also have "\<dots> = (\<exists>n. z = w + of_nat n)"
   512   also have "\<dots> = (\<exists>n. z = w + of_nat n)"
   514     by (simp only: group_simps)
   513     by (simp only: algebra_simps)
   515   finally show ?thesis .
   514   finally show ?thesis .
   516 qed
   515 qed
   517 
   516 
   518 lemma zadd_int_left: "of_nat m + (of_nat n + z) = of_nat (m + n) + (z\<Colon>int)"
   517 lemma zadd_int_left: "of_nat m + (of_nat n + z) = of_nat (m + n) + (z\<Colon>int)"
   519 by simp
   518 by simp
   827   thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing
   826   thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing
   828                              le_imp_0_less [THEN order_less_imp_le])  
   827                              le_imp_0_less [THEN order_less_imp_le])  
   829 next
   828 next
   830   case (neg n)
   829   case (neg n)
   831   thus ?thesis by (simp del: of_nat_Suc of_nat_add
   830   thus ?thesis by (simp del: of_nat_Suc of_nat_add
   832     add: compare_rls of_nat_1 [symmetric] of_nat_add [symmetric])
   831     add: algebra_simps of_nat_1 [symmetric] of_nat_add [symmetric])
   833 qed
   832 qed
   834 
   833 
   835 lemma bin_less_0_simps:
   834 lemma bin_less_0_simps:
   836   "Pls < 0 \<longleftrightarrow> False"
   835   "Pls < 0 \<longleftrightarrow> False"
   837   "Min < 0 \<longleftrightarrow> True"
   836   "Min < 0 \<longleftrightarrow> True"
  1065 by (simp add: iszero_def eq_commute)
  1064 by (simp add: iszero_def eq_commute)
  1066 
  1065 
  1067 lemma eq_number_of_eq:
  1066 lemma eq_number_of_eq:
  1068   "((number_of x::'a::number_ring) = number_of y) =
  1067   "((number_of x::'a::number_ring) = number_of y) =
  1069    iszero (number_of (x + uminus y) :: 'a)"
  1068    iszero (number_of (x + uminus y) :: 'a)"
  1070   unfolding iszero_def number_of_add number_of_minus
  1069 unfolding iszero_def number_of_add number_of_minus
  1071   by (simp add: compare_rls)
  1070 by (simp add: algebra_simps)
  1072 
  1071 
  1073 lemma iszero_number_of_Pls:
  1072 lemma iszero_number_of_Pls:
  1074   "iszero ((number_of Pls)::'a::number_ring)"
  1073   "iszero ((number_of Pls)::'a::number_ring)"
  1075   unfolding iszero_def numeral_0_eq_0 ..
  1074 unfolding iszero_def numeral_0_eq_0 ..
  1076 
  1075 
  1077 lemma nonzero_number_of_Min:
  1076 lemma nonzero_number_of_Min:
  1078   "~ iszero ((number_of Min)::'a::number_ring)"
  1077   "~ iszero ((number_of Min)::'a::number_ring)"
  1079   unfolding iszero_def numeral_m1_eq_minus_1 by simp
  1078 unfolding iszero_def numeral_m1_eq_minus_1 by simp
  1080 
  1079 
  1081 
  1080 
  1082 subsubsection {* Comparisons, for Ordered Rings *}
  1081 subsubsection {* Comparisons, for Ordered Rings *}
  1083 
  1082 
  1084 lemmas double_eq_0_iff = double_zero
  1083 lemmas double_eq_0_iff = double_zero
  1160   thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing
  1159   thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing
  1161                              le_imp_0_less [THEN order_less_imp_le])  
  1160                              le_imp_0_less [THEN order_less_imp_le])  
  1162 next
  1161 next
  1163   case (neg n)
  1162   case (neg n)
  1164   thus ?thesis by (simp del: of_nat_Suc of_nat_add
  1163   thus ?thesis by (simp del: of_nat_Suc of_nat_add
  1165     add: compare_rls of_nat_1 [symmetric] of_nat_add [symmetric])
  1164     add: algebra_simps of_nat_1 [symmetric] of_nat_add [symmetric])
  1166 qed
  1165 qed
  1167 
  1166 
  1168 text {* Less-Than or Equals *}
  1167 text {* Less-Than or Equals *}
  1169 
  1168 
  1170 text {* Reduces @{term "a\<le>b"} to @{term "~ (b<a)"} for ALL numerals. *}
  1169 text {* Reduces @{term "a\<le>b"} to @{term "~ (b<a)"} for ALL numerals. *}
  1247   by (simp add: diff_minus add_number_of_left)
  1246   by (simp add: diff_minus add_number_of_left)
  1248 
  1247 
  1249 lemma add_number_of_diff2 [simp]:
  1248 lemma add_number_of_diff2 [simp]:
  1250   "number_of v + (c - number_of w) =
  1249   "number_of v + (c - number_of w) =
  1251    number_of (v + uminus w) + (c::'a::number_ring)"
  1250    number_of (v + uminus w) + (c::'a::number_ring)"
  1252 apply (subst diff_number_of_eq [symmetric])
  1251 by (simp add: algebra_simps diff_number_of_eq [symmetric])
  1253 apply (simp only: compare_rls)
       
  1254 done
       
  1255 
  1252 
  1256 
  1253 
  1257 subsection {* The Set of Integers *}
  1254 subsection {* The Set of Integers *}
  1258 
  1255 
  1259 context ring_1
  1256 context ring_1