author huffman Wed Jun 13 16:43:02 2007 +0200 (2007-06-13) changeset 23372 0035be079bee parent 23371 ed60e560048d child 23373 ead82c82da9e
clean up instance proofs; reorganize section headings
 src/HOL/IntDef.thy file | annotate | diff | revisions
```     1.1 --- a/src/HOL/IntDef.thy	Wed Jun 13 14:21:54 2007 +0200
1.2 +++ b/src/HOL/IntDef.thy	Wed Jun 13 16:43:02 2007 +0200
1.3 @@ -54,8 +54,6 @@
1.4
1.5  subsection{*Construction of the Integers*}
1.6
1.7 -subsubsection{*Preliminary Lemmas about the Equivalence Relation*}
1.8 -
1.9  lemma intrel_iff [simp]: "(((x,y),(u,v)) \<in> intrel) = (x+v = u+y)"
1.11
1.12 @@ -83,7 +81,7 @@
1.13  done
1.14
1.15
1.16 -subsubsection{*Integer Unary Negation*}
1.17 +subsection{*Arithmetic Operations*}
1.18
1.19  lemma minus: "- Abs_Integ(intrel``{(x,y)}) = Abs_Integ(intrel `` {(y,x)})"
1.20  proof -
1.21 @@ -93,15 +91,6 @@
1.22      by (simp add: minus_int_def UN_equiv_class [OF equiv_intrel])
1.23  qed
1.24
1.25 -lemma zminus_zminus: "- (- z) = (z::int)"
1.26 -  by (cases z) (simp add: minus)
1.27 -
1.28 -lemma zminus_0: "- 0 = (0::int)"
1.29 -  by (simp add: Zero_int_def minus)
1.30 -
1.31 -
1.33 -
1.35       "Abs_Integ (intrel``{(x,y)}) + Abs_Integ (intrel``{(u,v)}) =
1.36        Abs_Integ (intrel``{(x+u, y+v)})"
1.37 @@ -114,41 +103,6 @@
1.38                    UN_equiv_class2 [OF equiv_intrel equiv_intrel])
1.39  qed
1.40
1.41 -lemma zminus_zadd_distrib: "- (z + w) = (- z) + (- w::int)"
1.43 -
1.44 -lemma zadd_commute: "(z::int) + w = w + z"
1.46 -
1.47 -lemma zadd_assoc: "((z1::int) + z2) + z3 = z1 + (z2 + z3)"
1.49 -
1.50 -(*For AC rewriting*)
1.51 -lemma zadd_left_commute: "x + (y + z) = y + ((x + z)  ::int)"
1.52 -  apply (rule mk_left_commute [of "op +"])
1.55 -  done
1.56 -
1.58 -
1.59 -lemmas zmult_ac = OrderedGroup.mult_ac
1.60 -
1.61 -(*also for the instance declaration int :: comm_monoid_add*)
1.62 -lemma zadd_0: "(0::int) + z = z"
1.65 -done
1.66 -
1.67 -lemma zadd_0_right: "z + (0::int) = z"
1.69 -
1.70 -lemma zadd_zminus_inverse2: "(- z) + z = (0::int)"
1.72 -
1.73 -
1.74 -subsection{*Integer Multiplication*}
1.75 -
1.76  text{*Congruence property for multiplication*}
1.77  lemma mult_congruent2:
1.78       "(%p1 p2. (%(x,y). (%(u,v). intrel``{(x*u + y*v, x*v + y*u)}) p2) p1)
1.79 @@ -162,60 +116,36 @@
1.81  done
1.82
1.83 -
1.84  lemma mult:
1.85       "Abs_Integ((intrel``{(x,y)})) * Abs_Integ((intrel``{(u,v)})) =
1.86        Abs_Integ(intrel `` {(x*u + y*v, x*v + y*u)})"
1.87  by (simp add: mult_int_def UN_UN_split_split_eq mult_congruent2
1.88                UN_equiv_class2 [OF equiv_intrel equiv_intrel])
1.89
1.90 -lemma zmult_zminus: "(- z) * w = - (z * (w::int))"
1.92 -
1.93 -lemma zmult_commute: "(z::int) * w = w * z"
1.95 -
1.96 -lemma zmult_assoc: "((z1::int) * z2) * z3 = z1 * (z2 * z3)"
1.97 -by (cases z1, cases z2, cases z3, simp add: mult add_mult_distrib2 mult_ac)
1.98 -
1.99 -lemma zadd_zmult_distrib: "((z1::int) + z2) * w = (z1 * w) + (z2 * w)"
1.101 -
1.102 -lemma zadd_zmult_distrib2: "(w::int) * (z1 + z2) = (w * z1) + (w * z2)"
1.104 -
1.105 -lemma zdiff_zmult_distrib: "((z1::int) - z2) * w = (z1 * w) - (z2 * w)"
1.107 -
1.108 -lemma zdiff_zmult_distrib2: "(w::int) * (z1 - z2) = (w * z1) - (w * z2)"
1.109 -by (simp add: zmult_commute [of w] zdiff_zmult_distrib)
1.110 -
1.111 -lemmas int_distrib =
1.113 -  zdiff_zmult_distrib zdiff_zmult_distrib2
1.114 -
1.115 -
1.116 -lemma zmult_1: "(1::int) * z = z"
1.117 -by (cases z, simp add: One_int_def mult)
1.118 -
1.119 -lemma zmult_1_right: "z * (1::int) = z"
1.120 -by (rule trans [OF zmult_commute zmult_1])
1.121 -
1.122 -
1.123  text{*The integers form a @{text comm_ring_1}*}
1.124  instance int :: comm_ring_1
1.125  proof
1.126    fix i j k :: int
1.127 -  show "(i + j) + k = i + (j + k)" by (simp add: zadd_assoc)
1.128 -  show "i + j = j + i" by (simp add: zadd_commute)
1.129 -  show "0 + i = i" by (rule zadd_0)
1.130 -  show "- i + i = 0" by (rule zadd_zminus_inverse2)
1.131 -  show "i - j = i + (-j)" by (simp add: diff_int_def)
1.132 -  show "(i * j) * k = i * (j * k)" by (rule zmult_assoc)
1.133 -  show "i * j = j * i" by (rule zmult_commute)
1.134 -  show "1 * i = i" by (rule zmult_1)
1.135 -  show "(i + j) * k = i * k + j * k" by (simp add: int_distrib)
1.136 -  show "0 \<noteq> (1::int)" by (simp add: Zero_int_def One_int_def)
1.137 +  show "(i + j) + k = i + (j + k)"
1.139 +  show "i + j = j + i"
1.141 +  show "0 + i = i"
1.143 +  show "- i + i = 0"
1.145 +  show "i - j = i + - j"
1.146 +    by (simp add: diff_int_def)
1.147 +  show "(i * j) * k = i * (j * k)"
1.148 +    by (cases i, cases j, cases k) (simp add: mult ring_eq_simps)
1.149 +  show "i * j = j * i"
1.150 +    by (cases i, cases j) (simp add: mult ring_eq_simps)
1.151 +  show "1 * i = i"
1.152 +    by (cases i) (simp add: One_int_def mult)
1.153 +  show "(i + j) * k = i * k + j * k"
1.154 +    by (cases i, cases j, cases k) (simp add: add mult ring_eq_simps)
1.155 +  show "0 \<noteq> (1::int)"
1.156 +    by (simp add: Zero_int_def One_int_def)
1.157  qed
1.158
1.159  abbreviation
1.160 @@ -237,73 +167,46 @@
1.161    "(Abs_Integ(intrel``{(x,y)}) < Abs_Integ(intrel``{(u,v)})) = (x+v < u+y)"
1.162  by (simp add: less_int_def le order_less_le)
1.163
1.164 -lemma zle_refl: "w \<le> (w::int)"
1.165 -by (cases w, simp add: le)
1.166 -
1.167 -lemma zle_trans: "[| i \<le> j; j \<le> k |] ==> i \<le> (k::int)"
1.168 -by (cases i, cases j, cases k, simp add: le)
1.169 -
1.170 -lemma zle_anti_sym: "[| z \<le> w; w \<le> z |] ==> z = (w::int)"
1.171 -by (cases w, cases z, simp add: le)
1.172 -
1.173 -instance int :: order
1.174 -  by intro_classes
1.175 -    (assumption |
1.176 -      rule zle_refl zle_trans zle_anti_sym less_int_def [THEN meta_eq_to_obj_eq])+
1.177 -
1.178 -lemma zle_linear: "(z::int) \<le> w \<or> w \<le> z"
1.179 -by (cases z, cases w) (simp add: le linorder_linear)
1.180 -
1.181  instance int :: linorder
1.182 -  by intro_classes (rule zle_linear)
1.183 -
1.184 -lemmas zless_linear = linorder_less_linear [where 'a = int]
1.185 -
1.186 -
1.187 -lemma int_0_less_1: "0 < (1::int)"
1.188 -by (simp add: Zero_int_def One_int_def less)
1.189 -
1.190 -lemma int_0_neq_1 [simp]: "0 \<noteq> (1::int)"
1.191 -by (rule int_0_less_1 [THEN less_imp_neq])
1.192 -
1.193 -
1.194 -subsection{*Monotonicity results*}
1.195 +proof
1.196 +  fix i j k :: int
1.197 +  show "(i < j) = (i \<le> j \<and> i \<noteq> j)"
1.198 +    by (simp add: less_int_def)
1.199 +  show "i \<le> i"
1.200 +    by (cases i) (simp add: le)
1.201 +  show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k"
1.202 +    by (cases i, cases j, cases k) (simp add: le)
1.203 +  show "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j"
1.204 +    by (cases i, cases j) (simp add: le)
1.205 +  show "i \<le> j \<or> j \<le> i"
1.206 +    by (cases i, cases j) (simp add: le linorder_linear)
1.207 +qed
1.208
1.210  proof
1.211 -  fix a b c :: int
1.212 -  show "a \<le> b \<Longrightarrow> c + a \<le> c + b"
1.213 -    by (cases a, cases b, cases c, simp add: le add)
1.214 +  fix i j k :: int
1.215 +  show "i \<le> j \<Longrightarrow> k + i \<le> k + j"
1.216 +    by (cases i, cases j, cases k) (simp add: le add)
1.217  qed
1.218
1.219 -lemma zadd_left_mono: "i \<le> j ==> k + i \<le> k + (j::int)"
1.221 -
1.222 -lemma zadd_strict_right_mono: "i < j ==> i + k < j + (k::int)"
1.224 -
1.225 -lemma zadd_zless_mono: "[| w'<w; z'\<le>z |] ==> w' + z' < w + (z::int)"
1.227 -
1.228 -
1.229 -subsection{*Strict Monotonicity of Multiplication*}
1.230 +text{*Strict Monotonicity of Multiplication*}
1.231
1.232  text{*strict, in 1st argument; proof is by induction on k>0*}
1.233  lemma zmult_zless_mono2_lemma:
1.234 -     "(i::int)<j ==> 0<k ==> of_nat k * i < of_nat k * j"
1.235 +     "(i::int)<j ==> 0<k ==> int k * i < int k * j"
1.236  apply (induct "k", simp)
1.238  apply (case_tac "k=0")
1.240  done
1.241
1.242 -lemma zero_le_imp_eq_int: "(0::int) \<le> k ==> \<exists>n. k = of_nat n"
1.243 +lemma zero_le_imp_eq_int: "(0::int) \<le> k ==> \<exists>n. k = int n"
1.244  apply (cases k)
1.246  apply (rule_tac x="x-y" in exI, simp)
1.247  done
1.248
1.249 -lemma zero_less_imp_eq_int: "(0::int) < k ==> \<exists>n>0. k = of_nat n"
1.250 +lemma zero_less_imp_eq_int: "(0::int) < k ==> \<exists>n>0. k = int n"
1.251  apply (cases k)
1.252  apply (simp add: less int_def Zero_int_def)
1.253  apply (rule_tac x="x-y" in exI, simp)
1.254 @@ -327,8 +230,10 @@
1.255  instance int :: ordered_idom
1.256  proof
1.257    fix i j k :: int
1.258 -  show "i < j ==> 0 < k ==> k * i < k * j" by (rule zmult_zless_mono2)
1.259 -  show "\<bar>i\<bar> = (if i < 0 then -i else i)" by (simp only: zabs_def)
1.260 +  show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j"
1.261 +    by (rule zmult_zless_mono2)
1.262 +  show "\<bar>i\<bar> = (if i < 0 then -i else i)"
1.263 +    by (simp only: zabs_def)
1.264  qed
1.265
1.266  lemma zless_imp_add1_zle: "w<z ==> w + (1::int) \<le> z"
1.267 @@ -447,21 +352,25 @@
1.268  by (force simp add: order_eq_iff [of "- int n"] int_zle_neg)
1.269
1.270  lemma zle_iff_zadd: "(w \<le> z) = (\<exists>n. z = w + int n)"
1.272 -  fix a b c d
1.273 -  assume "w = Abs_Integ (intrel `` {(a,b)})" "z = Abs_Integ (intrel `` {(c,d)})"
1.274 -  show "(a+d \<le> c+b) = (\<exists>n. c+b = a+n+d)"
1.275 -  proof
1.276 -    assume "a + d \<le> c + b"
1.277 -    thus "\<exists>n. c + b = a + n + d"
1.278 -      by (auto intro!: exI [where x="c+b - (a+d)"])
1.279 -  next
1.280 -    assume "\<exists>n. c + b = a + n + d"
1.281 -    then obtain n where "c + b = a + n + d" ..
1.282 -    thus "a + d \<le> c + b" by arith
1.283 -  qed
1.284 +proof -
1.285 +  have "(w \<le> z) = (0 \<le> z - w)"
1.286 +    by (simp only: le_diff_eq add_0_left)
1.287 +  also have "\<dots> = (\<exists>n. z - w = int n)"
1.288 +    by (auto elim: zero_le_imp_eq_int)
1.289 +  also have "\<dots> = (\<exists>n. z = w + int n)"
1.290 +    by (simp only: group_eq_simps)
1.291 +  finally show ?thesis .
1.292  qed
1.293
1.294 +lemma zadd_int_left: "(int m) + (int n + z) = int (m + n) + z"
1.295 +by simp
1.296 +
1.297 +lemma int_Suc: "int (Suc m) = 1 + (int m)"
1.298 +by simp
1.299 +
1.300 +lemma int_Suc0_eq_1: "int (Suc 0) = 1"
1.301 +by simp
1.302 +
1.303  lemma abs_of_nat [simp]: "\<bar>of_nat n::'a::ordered_idom\<bar> = of_nat n"
1.304  by (rule  of_nat_0_le_iff [THEN abs_of_nonneg]) (* belongs in Nat.thy *)
1.305
1.306 @@ -498,7 +407,7 @@
1.307  by (simp add: neg_def linorder_not_less)
1.308
1.309
1.310 -subsection{*To simplify inequalities when Numeral1 can get simplified to 1*}
1.311 +text{*To simplify inequalities when Numeral1 can get simplified to 1*}
1.312
1.313  lemma not_neg_0: "~ neg 0"
1.314  by (simp add: One_int_def neg_def)
1.315 @@ -647,6 +556,9 @@
1.317  qed
1.318
1.319 +lemma of_nat_nat: "0 \<le> z ==> of_nat (nat z) = of_int z"
1.320 +by (cases z rule: eq_Abs_Integ, simp add: nat le of_int Zero_int_def)
1.321 +
1.322
1.323  subsection{*The Set of Integers*}
1.324
1.325 @@ -766,7 +678,7 @@
1.327      "(w < z) = (\<exists>n. z = w + int (Suc n))"
1.328  apply (cases z, cases w)
1.331  apply (rename_tac a b c d)
1.332  apply (rule_tac x="a+d - Suc(c+b)" in exI)
1.333  apply arith
1.334 @@ -785,7 +697,7 @@
1.335  apply (blast dest: nat_0_le [THEN sym])
1.336  done
1.337
1.338 -theorem int_induct'[induct type: int, case_names nonneg neg]:
1.339 +theorem int_induct [induct type: int, case_names nonneg neg]:
1.340       "[|!! n. P (int n);  !!n. P (- (int (Suc n))) |] ==> P z"
1.341    by (cases z rule: int_cases) auto
1.342
1.343 @@ -797,20 +709,47 @@
1.345  done
1.346
1.347 -lemma of_nat_nat: "0 \<le> z ==> of_nat (nat z) = of_int z"
1.348 -by (cases z rule: eq_Abs_Integ, simp add: nat le of_int Zero_int_def)
1.349 -
1.350
1.351  subsection {* Legacy theorems *}
1.352
1.353 -lemma zadd_int_left: "(int m) + (int n + z) = int (m + n) + z"
1.354 -by simp
1.355 +lemmas zminus_zminus = minus_minus [where 'a=int]
1.356 +lemmas zminus_0 = minus_zero [where 'a=int]
1.362 +lemmas zmult_ac = OrderedGroup.mult_ac
1.365 +lemmas zadd_zminus_inverse2 = left_minus [where 'a=int]
1.366 +lemmas zmult_zminus = mult_minus_left [where 'a=int]
1.367 +lemmas zmult_commute = mult_commute [where 'a=int]
1.368 +lemmas zmult_assoc = mult_assoc [where 'a=int]
1.369 +lemmas zadd_zmult_distrib = left_distrib [where 'a=int]
1.370 +lemmas zadd_zmult_distrib2 = right_distrib [where 'a=int]
1.371 +lemmas zdiff_zmult_distrib = left_diff_distrib [where 'a=int]
1.372 +lemmas zdiff_zmult_distrib2 = right_diff_distrib [where 'a=int]
1.373
1.374 -lemma int_Suc: "int (Suc m) = 1 + (int m)"
1.375 -by simp
1.376 +lemmas int_distrib =
1.378 +  zdiff_zmult_distrib zdiff_zmult_distrib2
1.379 +
1.380 +lemmas zmult_1 = mult_1_left [where 'a=int]
1.381 +lemmas zmult_1_right = mult_1_right [where 'a=int]
1.382
1.383 -lemma int_Suc0_eq_1: "int (Suc 0) = 1"
1.384 -by simp
1.385 +lemmas zle_refl = order_refl [where 'a=int]
1.386 +lemmas zle_trans = order_trans [where 'a=int]
1.387 +lemmas zle_anti_sym = order_antisym [where 'a=int]
1.388 +lemmas zle_linear = linorder_linear [where 'a=int]
1.389 +lemmas zless_linear = linorder_less_linear [where 'a = int]
1.390 +