src/HOL/Real/Float.thy
 changeset 19765 dfe940911617 parent 16890 c4e5afaba440 child 20217 25b068a99d2b
```     1.1 --- a/src/HOL/Real/Float.thy	Fri Jun 02 20:12:59 2006 +0200
1.2 +++ b/src/HOL/Real/Float.thy	Fri Jun 02 23:22:29 2006 +0200
1.3 @@ -5,11 +5,11 @@
1.4
1.5  theory Float imports Real begin
1.6
1.7 -constdefs
1.8 +definition
1.9    pow2 :: "int \<Rightarrow> real"
1.10 -  "pow2 a == if (0 <= a) then (2^(nat a)) else (inverse (2^(nat (-a))))"
1.11 +  "pow2 a = (if (0 <= a) then (2^(nat a)) else (inverse (2^(nat (-a)))))"
1.12    float :: "int * int \<Rightarrow> real"
1.13 -  "float x == (real (fst x)) * (pow2 (snd x))"
1.14 +  "float x = real (fst x) * pow2 (snd x)"
1.15
1.16  lemma pow2_0[simp]: "pow2 0 = 1"
1.17  by (simp add: pow2_def)
1.18 @@ -20,7 +20,7 @@
1.19  lemma pow2_neg: "pow2 x = inverse (pow2 (-x))"
1.20  by (simp add: pow2_def)
1.21
1.22 -lemma pow2_add1: "pow2 (1 + a) = 2 * (pow2 a)"
1.23 +lemma pow2_add1: "pow2 (1 + a) = 2 * (pow2 a)"
1.24  proof -
1.25    have h: "! n. nat (2 + int n) - Suc 0 = nat (1 + int n)" by arith
1.26    have g: "! a b. a - -1 = a + (1::int)" by arith
1.27 @@ -30,7 +30,7 @@
1.28      apply (rule_tac m1="2" and n1="nat (2 + int na)" in ssubst[OF realpow_num_eq_if])
1.29      apply (auto simp add: h)
1.30      apply arith
1.31 -    done
1.32 +    done
1.33    show ?thesis
1.34    proof (induct a)
1.35      case (1 n)
1.36 @@ -43,12 +43,12 @@
1.37        apply (subst pow2_neg[of "-1 - int n"])
1.38        apply (auto simp add: g pos)
1.39        done
1.40 -  qed
1.41 +  qed
1.42  qed
1.43 -
1.44 +
1.45  lemma pow2_add: "pow2 (a+b) = (pow2 a) * (pow2 b)"
1.46  proof (induct b)
1.47 -  case (1 n)
1.48 +  case (1 n)
1.49    show ?case
1.50    proof (induct n)
1.51      case 0
1.52 @@ -59,10 +59,10 @@
1.53    qed
1.54  next
1.55    case (2 n)
1.56 -  show ?case
1.57 +  show ?case
1.58    proof (induct n)
1.59      case 0
1.60 -    show ?case
1.61 +    show ?case
1.62        apply (auto)
1.63        apply (subst pow2_neg[of "a + -1"])
1.64        apply (subst pow2_neg[of "-1"])
1.65 @@ -73,7 +73,7 @@
1.66        apply (simp)
1.67        done
1.68      case (Suc m)
1.69 -    have a: "int m - (a + -2) =  1 + (int m - a + 1)" by arith
1.70 +    have a: "int m - (a + -2) =  1 + (int m - a + 1)" by arith
1.71      have b: "int m - -2 = 1 + (int m + 1)" by arith
1.72      show ?case
1.73        apply (auto)
1.74 @@ -92,14 +92,14 @@
1.75    qed
1.76  qed
1.77
1.78 -lemma "float (a, e) + float (b, e) = float (a + b, e)"
1.79 +lemma "float (a, e) + float (b, e) = float (a + b, e)"
1.80  by (simp add: float_def ring_eq_simps)
1.81
1.82 -constdefs
1.83 +definition
1.84    int_of_real :: "real \<Rightarrow> int"
1.85 -  "int_of_real x == SOME y. real y = x"
1.86 +  "int_of_real x = (SOME y. real y = x)"
1.87    real_is_int :: "real \<Rightarrow> bool"
1.88 -  "real_is_int x == ? (u::int). x = real u"
1.89 +  "real_is_int x = (EX (u::int). x = real u)"
1.90
1.91  lemma real_is_int_def2: "real_is_int x = (x = real (int_of_real x))"
1.92  by (auto simp add: real_is_int_def int_of_real_def)
1.93 @@ -110,7 +110,7 @@
1.94  lemma pow2_int: "pow2 (int c) = (2::real)^c"
1.95  by (simp add: pow2_def)
1.96
1.97 -lemma float_transfer_nat: "float (a, b) = float (a * 2^c, b - int c)"
1.98 +lemma float_transfer_nat: "float (a, b) = float (a * 2^c, b - int c)"
1.99  by (simp add: float_def pow2_int[symmetric] pow2_add[symmetric])
1.100
1.101  lemma real_is_int_real[simp]: "real_is_int (real (x::int))"
1.102 @@ -141,7 +141,7 @@
1.103  lemma real_is_int_rep: "real_is_int x \<Longrightarrow> ?! (a::int). real a = x"
1.104  by (auto simp add: real_is_int_def)
1.105
1.106 -lemma int_of_real_mult:
1.107 +lemma int_of_real_mult:
1.108    assumes "real_is_int a" "real_is_int b"
1.109    shows "(int_of_real (a*b)) = (int_of_real a) * (int_of_real b)"
1.110  proof -
1.111 @@ -187,8 +187,8 @@
1.112      also have "\<dots> = True" by (simp only: real_is_int_real)
1.113      ultimately show ?thesis by auto
1.114    qed
1.115 -
1.116 -  {
1.117 +
1.118 +  {
1.119      fix x::int
1.120      have "!! y. real_is_int ((number_of::bin\<Rightarrow>real) (Abs_Bin x))"
1.121        apply (simp add: number_of_eq)
1.122 @@ -205,11 +205,11 @@
1.123        assume rn: "(real_is_int (of_int (- (int (Suc n)))))"
1.124        have s: "-(int (Suc (Suc n))) = -1 + - (int (Suc n))" by simp
1.125        show "real_is_int (of_int (- (int (Suc (Suc n)))))"
1.126 -	apply (simp only: s of_int_add)
1.127 -	apply (rule real_is_int_add)
1.128 -	apply (simp add: neg1)
1.129 -	apply (simp only: rn)
1.130 -	done
1.131 +        apply (simp only: s of_int_add)
1.132 +        apply (rule real_is_int_add)
1.133 +        apply (simp add: neg1)
1.134 +        apply (simp only: rn)
1.135 +        done
1.136      qed
1.137    }
1.138    note Abs_Bin = this
1.139 @@ -228,7 +228,7 @@
1.140  by (simp add: int_of_real_def)
1.141
1.142  lemma int_of_real_1[simp]: "int_of_real (1::real) = (1::int)"
1.143 -proof -
1.144 +proof -
1.145    have 1: "(1::real) = real (1::int)" by auto
1.146    show ?thesis by (simp only: 1 int_of_real_real)
1.147  qed
1.148 @@ -238,9 +238,9 @@
1.149    have "real_is_int (number_of b)" by simp
1.150    then have uu: "?! u::int. number_of b = real u" by (auto simp add: real_is_int_rep)
1.151    then obtain u::int where u:"number_of b = real u" by auto
1.152 -  have "number_of b = real ((number_of b)::int)"
1.153 +  have "number_of b = real ((number_of b)::int)"
1.154      by (simp add: number_of_eq real_of_int_def)
1.155 -  have ub: "number_of b = real ((number_of b)::int)"
1.156 +  have ub: "number_of b = real ((number_of b)::int)"
1.157      by (simp add: number_of_eq real_of_int_def)
1.158    from uu u ub have unb: "u = number_of b"
1.159      by blast
1.160 @@ -255,10 +255,10 @@
1.161  proof -
1.162    fix q::int
1.163    have a:"b - (-1\<Colon>int) = (1\<Colon>int) + b" by arith
1.164 -  show "(float (q, (b - (-1\<Colon>int)))) = (float (q, ((1\<Colon>int) + b)))"
1.165 +  show "(float (q, (b - (-1\<Colon>int)))) = (float (q, ((1\<Colon>int) + b)))"
1.166      by (simp add: a)
1.167  qed
1.168 -
1.169 +
1.170  consts
1.171    norm_float :: "int*int \<Rightarrow> int*int"
1.172
1.173 @@ -285,7 +285,7 @@
1.174  apply (auto)
1.175  done
1.176
1.177 -ML {* simp_depth_limit := 2 *}
1.178 +ML {* simp_depth_limit := 2 *}
1.179  recdef norm_float "measure (% (a,b). nat (abs a))"
1.180    "norm_float (a,b) = (if (a \<noteq> 0) & (even a) then norm_float (a div 2, b+1) else (if a=0 then (0,0) else (a,b)))"
1.181  (hints simp: terminating_norm_float)
1.182 @@ -294,23 +294,23 @@
1.183  lemma norm_float: "float x = float (norm_float x)"
1.184  proof -
1.185    {
1.186 -    fix a b :: int
1.187 -    have norm_float_pair: "float (a,b) = float (norm_float (a,b))"
1.188 +    fix a b :: int
1.189 +    have norm_float_pair: "float (a,b) = float (norm_float (a,b))"
1.190      proof (induct a b rule: norm_float.induct)
1.191        case (1 u v)
1.192 -      show ?case
1.193 +      show ?case
1.194        proof cases
1.195 -	assume u: "u \<noteq> 0 \<and> even u"
1.196 -	with prems have ind: "float (u div 2, v + 1) = float (norm_float (u div 2, v + 1))" by auto
1.197 -	with u have "float (u,v) = float (u div 2, v+1)" by (simp add: float_transfer_even)
1.198 -	then show ?thesis
1.199 -	  apply (subst norm_float.simps)
1.200 -	  apply (simp add: ind)
1.201 -	  done
1.202 +        assume u: "u \<noteq> 0 \<and> even u"
1.203 +        with prems have ind: "float (u div 2, v + 1) = float (norm_float (u div 2, v + 1))" by auto
1.204 +        with u have "float (u,v) = float (u div 2, v+1)" by (simp add: float_transfer_even)
1.205 +        then show ?thesis
1.206 +          apply (subst norm_float.simps)
1.207 +          apply (simp add: ind)
1.208 +          done
1.209        next
1.210 -	assume "~(u \<noteq> 0 \<and> even u)"
1.211 -	then show ?thesis
1.212 -	  by (simp add: prems float_def)
1.213 +        assume "~(u \<noteq> 0 \<and> even u)"
1.214 +        then show ?thesis
1.215 +          by (simp add: prems float_def)
1.216        qed
1.217      qed
1.218    }
1.219 @@ -323,16 +323,16 @@
1.220  lemma pow2_int: "pow2 (int n) = 2^n"
1.221    by (simp add: pow2_def)
1.222
1.224 -  "float (a1, e1) + float (a2, e2) =
1.225 -  (if e1<=e2 then float (a1+a2*2^(nat(e2-e1)), e1)
1.227 +  "float (a1, e1) + float (a2, e2) =
1.228 +  (if e1<=e2 then float (a1+a2*2^(nat(e2-e1)), e1)
1.229    else float (a1*2^(nat (e1-e2))+a2, e2))"
1.230    apply (simp add: float_def ring_eq_simps)
1.231    apply (auto simp add: pow2_int[symmetric] pow2_add[symmetric])
1.232    done
1.233
1.234  lemma float_mult:
1.235 -  "float (a1, e1) * float (a2, e2) =
1.236 +  "float (a1, e1) * float (a2, e2) =
1.237    (float (a1 * a2, e1 + e2))"
1.239
1.240 @@ -345,7 +345,7 @@
1.241  proof -
1.242    {
1.243      fix y
1.244 -    have "0 <= y \<Longrightarrow> 0 < pow2 y"
1.245 +    have "0 <= y \<Longrightarrow> 0 < pow2 y"
1.246        by (induct y, induct_tac n, simp_all add: pow2_add)
1.247    }
1.248    note helper=this
1.249 @@ -360,7 +360,7 @@
1.250  lemma zero_le_float:
1.251    "(0 <= float (a,b)) = (0 <= a)"
1.252    apply (auto simp add: float_def)
1.253 -  apply (auto simp add: zero_le_mult_iff zero_less_pow2)
1.254 +  apply (auto simp add: zero_le_mult_iff zero_less_pow2)
1.255    apply (insert zero_less_pow2[of b])
1.256    apply (simp_all)
1.257    done
1.258 @@ -393,7 +393,7 @@
1.259
1.260  lemma norm_0_1: "(0::_::number_ring) = Numeral0 & (1::_::number_ring) = Numeral1"
1.261    by auto
1.262 -
1.263 +
1.264  lemma add_left_zero: "0 + a = (a::'a::comm_monoid_add)"
1.265    by simp
1.266
1.267 @@ -451,19 +451,19 @@
1.268  lemma not_true_eq_false: "(~ True) = False" by simp
1.269
1.270
1.271 -lemmas binarith =
1.272 +lemmas binarith =
1.273    Pls_0_eq Min_1_eq
1.274 -  bin_pred_Pls bin_pred_Min bin_pred_1 bin_pred_0
1.275 +  bin_pred_Pls bin_pred_Min bin_pred_1 bin_pred_0
1.276    bin_succ_Pls bin_succ_Min bin_succ_1 bin_succ_0
1.278 -  bin_add_BIT_11 bin_minus_Pls bin_minus_Min bin_minus_1
1.279 -  bin_minus_0 bin_mult_Pls bin_mult_Min bin_mult_1 bin_mult_0
1.280 +  bin_add_BIT_11 bin_minus_Pls bin_minus_Min bin_minus_1
1.281 +  bin_minus_0 bin_mult_Pls bin_mult_Min bin_mult_1 bin_mult_0
1.283
1.284  lemma int_eq_number_of_eq: "(((number_of v)::int)=(number_of w)) = iszero ((number_of (bin_add v (bin_minus w)))::int)"
1.285    by simp
1.286
1.287 -lemma int_iszero_number_of_Pls: "iszero (Numeral0::int)"
1.288 +lemma int_iszero_number_of_Pls: "iszero (Numeral0::int)"
1.289    by (simp only: iszero_number_of_Pls)
1.290
1.291  lemma int_nonzero_number_of_Min: "~(iszero ((-1)::int))"
1.292 @@ -472,13 +472,13 @@
1.293  lemma int_iszero_number_of_0: "iszero ((number_of (w BIT bit.B0))::int) = iszero ((number_of w)::int)"
1.294    by simp
1.295
1.296 -lemma int_iszero_number_of_1: "\<not> iszero ((number_of (w BIT bit.B1))::int)"
1.297 +lemma int_iszero_number_of_1: "\<not> iszero ((number_of (w BIT bit.B1))::int)"
1.298    by simp
1.299
1.300  lemma int_less_number_of_eq_neg: "(((number_of x)::int) < number_of y) = neg ((number_of (bin_add x (bin_minus y)))::int)"
1.301    by simp
1.302
1.303 -lemma int_not_neg_number_of_Pls: "\<not> (neg (Numeral0::int))"
1.304 +lemma int_not_neg_number_of_Pls: "\<not> (neg (Numeral0::int))"
1.305    by simp
1.306
1.307  lemma int_neg_number_of_Min: "neg (-1::int)"
1.308 @@ -490,9 +490,9 @@
1.309  lemma int_le_number_of_eq: "(((number_of x)::int) \<le> number_of y) = (\<not> neg ((number_of (bin_add y (bin_minus x)))::int))"
1.310    by simp
1.311
1.312 -lemmas intarithrel =
1.313 -  int_eq_number_of_eq
1.314 -  lift_bool[OF int_iszero_number_of_Pls] nlift_bool[OF int_nonzero_number_of_Min] int_iszero_number_of_0
1.315 +lemmas intarithrel =
1.316 +  int_eq_number_of_eq
1.317 +  lift_bool[OF int_iszero_number_of_Pls] nlift_bool[OF int_nonzero_number_of_Min] int_iszero_number_of_0
1.318    lift_bool[OF int_iszero_number_of_1] int_less_number_of_eq_neg nlift_bool[OF int_not_neg_number_of_Pls] lift_bool[OF int_neg_number_of_Min]
1.319    int_neg_number_of_BIT int_le_number_of_eq
1.320
1.321 @@ -512,8 +512,8 @@
1.322
1.323  lemmas natarith = add_nat_number_of diff_nat_number_of mult_nat_number_of eq_nat_number_of less_nat_number_of
1.324
1.325 -lemmas powerarith = nat_number_of zpower_number_of_even
1.326 -  zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring]
1.327 +lemmas powerarith = nat_number_of zpower_number_of_even
1.328 +  zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring]
1.329    zpower_Pls zpower_Min
1.330
1.331  lemmas floatarith[simplified norm_0_1] = float_add float_mult float_minus float_abs zero_le_float float_pprt float_nprt
1.332 @@ -522,4 +522,3 @@
1.333  lemmas arith = binarith intarith intarithrel natarith powerarith floatarith not_false_eq_true not_true_eq_false
1.334
1.335  end
1.336 -
```