cleaned up float theories; removed duplicate definitions and theorems
authorhoelzl
Mon Nov 14 18:36:31 2011 +0100 (2011-11-14)
changeset 45495c55a07526dbe
parent 45494 e828ccc5c110
child 45496 5c0444d2abfe
child 45500 e2e27909bb66
cleaned up float theories; removed duplicate definitions and theorems
src/HOL/Library/Float.thy
src/HOL/Matrix/ComputeFloat.thy
     1.1 --- a/src/HOL/Library/Float.thy	Mon Nov 14 12:28:34 2011 +0100
     1.2 +++ b/src/HOL/Library/Float.thy	Mon Nov 14 18:36:31 2011 +0100
     1.3 @@ -72,78 +72,19 @@
     1.4  lemma pow2_1[simp]: "pow2 1 = 2" by simp
     1.5  lemma pow2_neg: "pow2 x = inverse (pow2 (-x))" by simp
     1.6  
     1.7 -declare pow2_def[simp del]
     1.8 +lemma pow2_powr: "pow2 a = 2 powr a"
     1.9 +  by (simp add: powr_realpow[symmetric] powr_minus)
    1.10  
    1.11 -lemma pow2_add1: "pow2 (1 + a) = 2 * (pow2 a)"
    1.12 -proof -
    1.13 -  have h: "! n. nat (2 + int n) - Suc 0 = nat (1 + int n)" by arith
    1.14 -  have g: "! a b. a - -1 = a + (1::int)" by arith
    1.15 -  have pos: "! n. pow2 (int n + 1) = 2 * pow2 (int n)"
    1.16 -    apply (auto, induct_tac n)
    1.17 -    apply (simp_all add: pow2_def)
    1.18 -    apply (rule_tac m1="2" and n1="nat (2 + int na)" in ssubst[OF realpow_num_eq_if])
    1.19 -    by (auto simp add: h)
    1.20 -  show ?thesis
    1.21 -  proof (induct a)
    1.22 -    case (nonneg n)
    1.23 -    from pos show ?case by (simp add: algebra_simps)
    1.24 -  next
    1.25 -    case (neg n)
    1.26 -    show ?case
    1.27 -      apply (auto)
    1.28 -      apply (subst pow2_neg[of "- int n"])
    1.29 -      apply (subst pow2_neg[of "-1 - int n"])
    1.30 -      apply (auto simp add: g pos)
    1.31 -      done
    1.32 -  qed
    1.33 -qed
    1.34 +declare pow2_def[simp del]
    1.35  
    1.36  lemma pow2_add: "pow2 (a+b) = (pow2 a) * (pow2 b)"
    1.37 -proof (induct b)
    1.38 -  case (nonneg n)
    1.39 -  show ?case
    1.40 -  proof (induct n)
    1.41 -    case 0
    1.42 -    show ?case by simp
    1.43 -  next
    1.44 -    case (Suc m)
    1.45 -    then show ?case by (auto simp add: algebra_simps pow2_add1)
    1.46 -  qed
    1.47 -next
    1.48 -  case (neg n)
    1.49 -  show ?case
    1.50 -  proof (induct n)
    1.51 -    case 0
    1.52 -    show ?case
    1.53 -      apply (auto)
    1.54 -      apply (subst pow2_neg[of "a + -1"])
    1.55 -      apply (subst pow2_neg[of "-1"])
    1.56 -      apply (simp)
    1.57 -      apply (insert pow2_add1[of "-a"])
    1.58 -      apply (simp add: algebra_simps)
    1.59 -      apply (subst pow2_neg[of "-a"])
    1.60 -      apply (simp)
    1.61 -      done
    1.62 -  next
    1.63 -    case (Suc m)
    1.64 -    have a: "int m - (a + -2) =  1 + (int m - a + 1)" by arith
    1.65 -    have b: "int m - -2 = 1 + (int m + 1)" by arith
    1.66 -    show ?case
    1.67 -      apply (auto)
    1.68 -      apply (subst pow2_neg[of "a + (-2 - int m)"])
    1.69 -      apply (subst pow2_neg[of "-2 - int m"])
    1.70 -      apply (auto simp add: algebra_simps)
    1.71 -      apply (subst a)
    1.72 -      apply (subst b)
    1.73 -      apply (simp only: pow2_add1)
    1.74 -      apply (subst pow2_neg[of "int m - a + 1"])
    1.75 -      apply (subst pow2_neg[of "int m + 1"])
    1.76 -      apply auto
    1.77 -      apply (insert Suc)
    1.78 -      apply (auto simp add: algebra_simps)
    1.79 -      done
    1.80 -  qed
    1.81 -qed
    1.82 +  by (simp add: pow2_powr powr_add)
    1.83 +
    1.84 +lemma pow2_diff: "pow2 (a - b) = pow2 a / pow2 b"
    1.85 +  by (simp add: pow2_powr powr_divide2)
    1.86 +  
    1.87 +lemma pow2_add1: "pow2 (1 + a) = 2 * (pow2 a)"
    1.88 +  by (simp add: pow2_add)
    1.89  
    1.90  lemma float_components[simp]: "Float (mantissa f) (scale f) = f" by (cases f) auto
    1.91  
    1.92 @@ -185,23 +126,7 @@
    1.93  
    1.94  lemma zero_less_pow2[simp]:
    1.95    "0 < pow2 x"
    1.96 -proof -
    1.97 -  {
    1.98 -    fix y
    1.99 -    have "0 <= y \<Longrightarrow> 0 < pow2 y"
   1.100 -      apply (induct y)
   1.101 -      apply (induct_tac n)
   1.102 -      apply (simp_all add: pow2_add)
   1.103 -      done
   1.104 -  }
   1.105 -  note helper=this
   1.106 -  show ?thesis
   1.107 -    apply (case_tac "0 <= x")
   1.108 -    apply (simp add: helper)
   1.109 -    apply (subst pow2_neg)
   1.110 -    apply (simp add: helper)
   1.111 -    done
   1.112 -qed
   1.113 +  by (simp add: pow2_powr)
   1.114  
   1.115  lemma normfloat_imp_odd_or_zero: "normfloat f = Float a b \<Longrightarrow> odd a \<or> (a = 0 \<and> b = 0)"
   1.116  proof (induct f rule: normfloat.induct)
   1.117 @@ -245,46 +170,19 @@
   1.118    and floateq: "real (Float a b) = real (Float a' b')"
   1.119    shows "b \<le> b'"
   1.120  proof - 
   1.121 +  from odd have "a' \<noteq> 0" by auto
   1.122 +  with floateq have a': "real a' = real a * pow2 (b - b')"
   1.123 +    by (simp add: pow2_diff field_simps)
   1.124 +
   1.125    {
   1.126      assume bcmp: "b > b'"
   1.127 -    from floateq have eq: "real a * pow2 b = real a' * pow2 b'" by simp
   1.128 -    {
   1.129 -      fix x y z :: real
   1.130 -      assume "y \<noteq> 0"
   1.131 -      then have "(x * inverse y = z) = (x = z * y)"
   1.132 -        by auto
   1.133 -    }
   1.134 -    note inverse = this
   1.135 -    have eq': "real a * (pow2 (b - b')) = real a'"
   1.136 -      apply (subst diff_int_def)
   1.137 -      apply (subst pow2_add)
   1.138 -      apply (subst pow2_neg[where x = "-b'"])
   1.139 -      apply simp
   1.140 -      apply (subst mult_assoc[symmetric])
   1.141 -      apply (subst inverse)
   1.142 -      apply (simp_all add: eq)
   1.143 -      done
   1.144 -    have "\<exists> z > 0. pow2 (b-b') = 2^z"
   1.145 -      apply (rule exI[where x="nat (b - b')"])
   1.146 -      apply (auto)
   1.147 -      apply (insert bcmp)
   1.148 -      apply simp
   1.149 -      apply (subst pow2_int[symmetric])
   1.150 -      apply auto
   1.151 -      done
   1.152 -    then obtain z where z: "z > 0 \<and> pow2 (b-b') = 2^z" by auto
   1.153 -    with eq' have "real a * 2^z = real a'"
   1.154 -      by auto
   1.155 -    then have "real a * real ((2::int)^z) = real a'"
   1.156 -      by auto
   1.157 -    then have "real (a * 2^z) = real a'"
   1.158 -      apply (subst real_of_int_mult)
   1.159 -      apply simp
   1.160 -      done
   1.161 -    then have a'_rep: "a * 2^z = a'" by arith
   1.162 -    then have "a' = a*2^z" by simp
   1.163 -    with z have "even a'" by simp
   1.164 -    with odd have False by auto
   1.165 +    then have "\<exists>c::nat. b - b' = int c + 1"
   1.166 +      by arith
   1.167 +    then guess c ..
   1.168 +    with a' have "real a' = real (a * 2^c * 2)"
   1.169 +      by (simp add: pow2_def nat_add_distrib)
   1.170 +    with odd have False
   1.171 +      unfolding real_of_int_inject by simp
   1.172    }
   1.173    then show ?thesis by arith
   1.174  qed
     2.1 --- a/src/HOL/Matrix/ComputeFloat.thy	Mon Nov 14 12:28:34 2011 +0100
     2.2 +++ b/src/HOL/Matrix/ComputeFloat.thy	Mon Nov 14 18:36:31 2011 +0100
     2.3 @@ -9,94 +9,6 @@
     2.4  uses "~~/src/Tools/float.ML" ("~~/src/HOL/Tools/float_arith.ML")
     2.5  begin
     2.6  
     2.7 -definition pow2 :: "int \<Rightarrow> real"
     2.8 -  where "pow2 a = (if (0 <= a) then (2^(nat a)) else (inverse (2^(nat (-a)))))"
     2.9 -
    2.10 -definition float :: "int * int \<Rightarrow> real"
    2.11 -  where "float x = real (fst x) * pow2 (snd x)"
    2.12 -
    2.13 -lemma pow2_0[simp]: "pow2 0 = 1"
    2.14 -by (simp add: pow2_def)
    2.15 -
    2.16 -lemma pow2_1[simp]: "pow2 1 = 2"
    2.17 -by (simp add: pow2_def)
    2.18 -
    2.19 -lemma pow2_neg: "pow2 x = inverse (pow2 (-x))"
    2.20 -by (simp add: pow2_def)
    2.21 -
    2.22 -lemma pow2_add1: "pow2 (1 + a) = 2 * (pow2 a)"
    2.23 -proof -
    2.24 -  have h: "! n. nat (2 + int n) - Suc 0 = nat (1 + int n)" by arith
    2.25 -  have g: "! a b. a - -1 = a + (1::int)" by arith
    2.26 -  have pos: "! n. pow2 (int n + 1) = 2 * pow2 (int n)"
    2.27 -    apply (auto, induct_tac n)
    2.28 -    apply (simp_all add: pow2_def)
    2.29 -    apply (rule_tac m1="2" and n1="nat (2 + int na)" in ssubst[OF realpow_num_eq_if])
    2.30 -    by (auto simp add: h)
    2.31 -  show ?thesis
    2.32 -  proof (induct a)
    2.33 -    case (nonneg n)
    2.34 -    from pos show ?case by (simp add: algebra_simps)
    2.35 -  next
    2.36 -    case (neg n)
    2.37 -    show ?case
    2.38 -      apply (auto)
    2.39 -      apply (subst pow2_neg[of "- int n"])
    2.40 -      apply (subst pow2_neg[of "-1 - int n"])
    2.41 -      apply (auto simp add: g pos)
    2.42 -      done
    2.43 -  qed
    2.44 -qed
    2.45 -
    2.46 -lemma pow2_add: "pow2 (a+b) = (pow2 a) * (pow2 b)"
    2.47 -proof (induct b)
    2.48 -  case (nonneg n)
    2.49 -  show ?case
    2.50 -  proof (induct n)
    2.51 -    case 0
    2.52 -    show ?case by simp
    2.53 -  next
    2.54 -    case (Suc m)
    2.55 -    show ?case by (auto simp add: algebra_simps pow2_add1 nonneg Suc)
    2.56 -  qed
    2.57 -next
    2.58 -  case (neg n)
    2.59 -  show ?case
    2.60 -  proof (induct n)
    2.61 -    case 0
    2.62 -    show ?case
    2.63 -      apply (auto)
    2.64 -      apply (subst pow2_neg[of "a + -1"])
    2.65 -      apply (subst pow2_neg[of "-1"])
    2.66 -      apply (simp)
    2.67 -      apply (insert pow2_add1[of "-a"])
    2.68 -      apply (simp add: algebra_simps)
    2.69 -      apply (subst pow2_neg[of "-a"])
    2.70 -      apply (simp)
    2.71 -      done
    2.72 -    case (Suc m)
    2.73 -    have a: "int m - (a + -2) =  1 + (int m - a + 1)" by arith
    2.74 -    have b: "int m - -2 = 1 + (int m + 1)" by arith
    2.75 -    show ?case
    2.76 -      apply (auto)
    2.77 -      apply (subst pow2_neg[of "a + (-2 - int m)"])
    2.78 -      apply (subst pow2_neg[of "-2 - int m"])
    2.79 -      apply (auto simp add: algebra_simps)
    2.80 -      apply (subst a)
    2.81 -      apply (subst b)
    2.82 -      apply (simp only: pow2_add1)
    2.83 -      apply (subst pow2_neg[of "int m - a + 1"])
    2.84 -      apply (subst pow2_neg[of "int m + 1"])
    2.85 -      apply auto
    2.86 -      apply (insert Suc)
    2.87 -      apply (auto simp add: algebra_simps)
    2.88 -      done
    2.89 -  qed
    2.90 -qed
    2.91 -
    2.92 -lemma "float (a, e) + float (b, e) = float (a + b, e)"
    2.93 -by (simp add: float_def algebra_simps)
    2.94 -
    2.95  definition int_of_real :: "real \<Rightarrow> int"
    2.96    where "int_of_real x = (SOME y. real y = x)"
    2.97  
    2.98 @@ -104,16 +16,7 @@
    2.99    where "real_is_int x = (EX (u::int). x = real u)"
   2.100  
   2.101  lemma real_is_int_def2: "real_is_int x = (x = real (int_of_real x))"
   2.102 -by (auto simp add: real_is_int_def int_of_real_def)
   2.103 -
   2.104 -lemma float_transfer: "real_is_int ((real a)*(pow2 c)) \<Longrightarrow> float (a, b) = float (int_of_real ((real a)*(pow2 c)), b - c)"
   2.105 -by (simp add: float_def real_is_int_def2 pow2_add[symmetric])
   2.106 -
   2.107 -lemma pow2_int: "pow2 (int c) = 2^c"
   2.108 -by (simp add: pow2_def)
   2.109 -
   2.110 -lemma float_transfer_nat: "float (a, b) = float (a * 2^c, b - int c)"
   2.111 -by (simp add: float_def pow2_int[symmetric] pow2_add[symmetric])
   2.112 +  by (auto simp add: real_is_int_def int_of_real_def)
   2.113  
   2.114  lemma real_is_int_real[simp]: "real_is_int (real (x::int))"
   2.115  by (auto simp add: real_is_int_def int_of_real_def)
   2.116 @@ -146,18 +49,9 @@
   2.117  lemma int_of_real_mult:
   2.118    assumes "real_is_int a" "real_is_int b"
   2.119    shows "(int_of_real (a*b)) = (int_of_real a) * (int_of_real b)"
   2.120 -proof -
   2.121 -  from assms have a: "?! (a'::int). real a' = a" by (rule_tac real_is_int_rep, auto)
   2.122 -  from assms have b: "?! (b'::int). real b' = b" by (rule_tac real_is_int_rep, auto)
   2.123 -  from a obtain a'::int where a':"a = real a'" by auto
   2.124 -  from b obtain b'::int where b':"b = real b'" by auto
   2.125 -  have r: "real a' * real b' = real (a' * b')" by auto
   2.126 -  show ?thesis
   2.127 -    apply (simp add: a' b')
   2.128 -    apply (subst r)
   2.129 -    apply (simp only: int_of_real_real)
   2.130 -    done
   2.131 -qed
   2.132 +  using assms
   2.133 +  by (auto simp add: real_is_int_def real_of_int_mult[symmetric]
   2.134 +           simp del: real_of_int_mult)
   2.135  
   2.136  lemma real_is_int_mult[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a*b)"
   2.137  apply (subst real_is_int_def2)
   2.138 @@ -182,47 +76,7 @@
   2.139  qed
   2.140  
   2.141  lemma real_is_int_number_of[simp]: "real_is_int ((number_of \<Colon> int \<Rightarrow> real) x)"
   2.142 -proof -
   2.143 -  have neg1: "real_is_int (-1::real)"
   2.144 -  proof -
   2.145 -    have "real_is_int (-1::real) = real_is_int(real (-1::int))" by auto
   2.146 -    also have "\<dots> = True" by (simp only: real_is_int_real)
   2.147 -    ultimately show ?thesis by auto
   2.148 -  qed
   2.149 -
   2.150 -  {
   2.151 -    fix x :: int
   2.152 -    have "real_is_int ((number_of \<Colon> int \<Rightarrow> real) x)"
   2.153 -      unfolding number_of_eq
   2.154 -      apply (induct x)
   2.155 -      apply (induct_tac n)
   2.156 -      apply (simp)
   2.157 -      apply (simp)
   2.158 -      apply (induct_tac n)
   2.159 -      apply (simp add: neg1)
   2.160 -    proof -
   2.161 -      fix n :: nat
   2.162 -      assume rn: "(real_is_int (of_int (- (int (Suc n)))))"
   2.163 -      have s: "-(int (Suc (Suc n))) = -1 + - (int (Suc n))" by simp
   2.164 -      show "real_is_int (of_int (- (int (Suc (Suc n)))))"
   2.165 -        apply (simp only: s of_int_add)
   2.166 -        apply (rule real_is_int_add)
   2.167 -        apply (simp add: neg1)
   2.168 -        apply (simp only: rn)
   2.169 -        done
   2.170 -    qed
   2.171 -  }
   2.172 -  note Abs_Bin = this
   2.173 -  {
   2.174 -    fix x :: int
   2.175 -    have "? u. x = u"
   2.176 -      apply (rule exI[where x = "x"])
   2.177 -      apply (simp)
   2.178 -      done
   2.179 -  }
   2.180 -  then obtain u::int where "x = u" by auto
   2.181 -  with Abs_Bin show ?thesis by auto
   2.182 -qed
   2.183 +  by (auto simp: real_is_int_def intro!: exI[of _ "number_of x"])
   2.184  
   2.185  lemma int_of_real_0[simp]: "int_of_real (0::real) = (0::int)"
   2.186  by (simp add: int_of_real_def)
   2.187 @@ -234,30 +88,9 @@
   2.188  qed
   2.189  
   2.190  lemma int_of_real_number_of[simp]: "int_of_real (number_of b) = number_of b"
   2.191 -proof -
   2.192 -  have "real_is_int (number_of b)" by simp
   2.193 -  then have uu: "?! u::int. number_of b = real u" by (auto simp add: real_is_int_rep)
   2.194 -  then obtain u::int where u:"number_of b = real u" by auto
   2.195 -  have "number_of b = real ((number_of b)::int)"
   2.196 -    by (simp add: number_of_eq real_of_int_def)
   2.197 -  have ub: "number_of b = real ((number_of b)::int)"
   2.198 -    by (simp add: number_of_eq real_of_int_def)
   2.199 -  from uu u ub have unb: "u = number_of b"
   2.200 -    by blast
   2.201 -  have "int_of_real (number_of b) = u" by (simp add: u)
   2.202 -  with unb show ?thesis by simp
   2.203 -qed
   2.204 -
   2.205 -lemma float_transfer_even: "even a \<Longrightarrow> float (a, b) = float (a div 2, b+1)"
   2.206 -  apply (subst float_transfer[where a="a" and b="b" and c="-1", simplified])
   2.207 -  apply (simp_all add: pow2_def even_def real_is_int_def algebra_simps)
   2.208 -  apply (auto)
   2.209 -proof -
   2.210 -  fix q::int
   2.211 -  have a:"b - (-1\<Colon>int) = (1\<Colon>int) + b" by arith
   2.212 -  show "(float (q, (b - (-1\<Colon>int)))) = (float (q, ((1\<Colon>int) + b)))"
   2.213 -    by (simp add: a)
   2.214 -qed
   2.215 +  unfolding int_of_real_def
   2.216 +  by (intro some_equality)
   2.217 +     (auto simp add: real_of_int_inject[symmetric] simp del: real_of_int_inject)
   2.218  
   2.219  lemma int_div_zdiv: "int (a div b) = (int a) div (int b)"
   2.220  by (rule zdiv_int)
   2.221 @@ -268,163 +101,6 @@
   2.222  lemma abs_div_2_less: "a \<noteq> 0 \<Longrightarrow> a \<noteq> -1 \<Longrightarrow> abs((a::int) div 2) < abs a"
   2.223  by arith
   2.224  
   2.225 -function norm_float :: "int \<Rightarrow> int \<Rightarrow> int \<times> int" where
   2.226 -  "norm_float a b = (if a \<noteq> 0 \<and> even a then norm_float (a div 2) (b + 1)
   2.227 -    else if a = 0 then (0, 0) else (a, b))"
   2.228 -by auto
   2.229 -
   2.230 -termination by (relation "measure (nat o abs o fst)")
   2.231 -  (auto intro: abs_div_2_less)
   2.232 -
   2.233 -lemma norm_float: "float x = float (split norm_float x)"
   2.234 -proof -
   2.235 -  {
   2.236 -    fix a b :: int
   2.237 -    have norm_float_pair: "float (a, b) = float (norm_float a b)"
   2.238 -    proof (induct a b rule: norm_float.induct)
   2.239 -      case (1 u v)
   2.240 -      show ?case
   2.241 -      proof cases
   2.242 -        assume u: "u \<noteq> 0 \<and> even u"
   2.243 -        with 1 have ind: "float (u div 2, v + 1) = float (norm_float (u div 2) (v + 1))" by auto
   2.244 -        with u have "float (u,v) = float (u div 2, v+1)" by (simp add: float_transfer_even)
   2.245 -        then show ?thesis
   2.246 -          apply (subst norm_float.simps)
   2.247 -          apply (simp add: ind)
   2.248 -          done
   2.249 -      next
   2.250 -        assume nu: "~(u \<noteq> 0 \<and> even u)"
   2.251 -        show ?thesis
   2.252 -          by (simp add: nu float_def)
   2.253 -      qed
   2.254 -    qed
   2.255 -  }
   2.256 -  note helper = this
   2.257 -  have "? a b. x = (a,b)" by auto
   2.258 -  then obtain a b where "x = (a, b)" by blast
   2.259 -  then show ?thesis by (simp add: helper)
   2.260 -qed
   2.261 -
   2.262 -lemma float_add_l0: "float (0, e) + x = x"
   2.263 -  by (simp add: float_def)
   2.264 -
   2.265 -lemma float_add_r0: "x + float (0, e) = x"
   2.266 -  by (simp add: float_def)
   2.267 -
   2.268 -lemma float_add:
   2.269 -  "float (a1, e1) + float (a2, e2) =
   2.270 -  (if e1<=e2 then float (a1+a2*2^(nat(e2-e1)), e1)
   2.271 -  else float (a1*2^(nat (e1-e2))+a2, e2))"
   2.272 -  apply (simp add: float_def algebra_simps)
   2.273 -  apply (auto simp add: pow2_int[symmetric] pow2_add[symmetric])
   2.274 -  done
   2.275 -
   2.276 -lemma float_add_assoc1:
   2.277 -  "(x + float (y1, e1)) + float (y2, e2) = (float (y1, e1) + float (y2, e2)) + x"
   2.278 -  by simp
   2.279 -
   2.280 -lemma float_add_assoc2:
   2.281 -  "(float (y1, e1) + x) + float (y2, e2) = (float (y1, e1) + float (y2, e2)) + x"
   2.282 -  by simp
   2.283 -
   2.284 -lemma float_add_assoc3:
   2.285 -  "float (y1, e1) + (x + float (y2, e2)) = (float (y1, e1) + float (y2, e2)) + x"
   2.286 -  by simp
   2.287 -
   2.288 -lemma float_add_assoc4:
   2.289 -  "float (y1, e1) + (float (y2, e2) + x) = (float (y1, e1) + float (y2, e2)) + x"
   2.290 -  by simp
   2.291 -
   2.292 -lemma float_mult_l0: "float (0, e) * x = float (0, 0)"
   2.293 -  by (simp add: float_def)
   2.294 -
   2.295 -lemma float_mult_r0: "x * float (0, e) = float (0, 0)"
   2.296 -  by (simp add: float_def)
   2.297 -
   2.298 -definition lbound :: "real \<Rightarrow> real"
   2.299 -  where "lbound x = min 0 x"
   2.300 -
   2.301 -definition ubound :: "real \<Rightarrow> real"
   2.302 -  where "ubound x = max 0 x"
   2.303 -
   2.304 -lemma lbound: "lbound x \<le> x"   
   2.305 -  by (simp add: lbound_def)
   2.306 -
   2.307 -lemma ubound: "x \<le> ubound x"
   2.308 -  by (simp add: ubound_def)
   2.309 -
   2.310 -lemma float_mult:
   2.311 -  "float (a1, e1) * float (a2, e2) =
   2.312 -  (float (a1 * a2, e1 + e2))"
   2.313 -  by (simp add: float_def pow2_add)
   2.314 -
   2.315 -lemma float_minus:
   2.316 -  "- (float (a,b)) = float (-a, b)"
   2.317 -  by (simp add: float_def)
   2.318 -
   2.319 -lemma zero_less_pow2:
   2.320 -  "0 < pow2 x"
   2.321 -proof -
   2.322 -  {
   2.323 -    fix y
   2.324 -    have "0 <= y \<Longrightarrow> 0 < pow2 y"
   2.325 -      by (induct y, induct_tac n, simp_all add: pow2_add)
   2.326 -  }
   2.327 -  note helper=this
   2.328 -  show ?thesis
   2.329 -    apply (case_tac "0 <= x")
   2.330 -    apply (simp add: helper)
   2.331 -    apply (subst pow2_neg)
   2.332 -    apply (simp add: helper)
   2.333 -    done
   2.334 -qed
   2.335 -
   2.336 -lemma zero_le_float:
   2.337 -  "(0 <= float (a,b)) = (0 <= a)"
   2.338 -  apply (auto simp add: float_def)
   2.339 -  apply (auto simp add: zero_le_mult_iff zero_less_pow2)
   2.340 -  apply (insert zero_less_pow2[of b])
   2.341 -  apply (simp_all)
   2.342 -  done
   2.343 -
   2.344 -lemma float_le_zero:
   2.345 -  "(float (a,b) <= 0) = (a <= 0)"
   2.346 -  apply (auto simp add: float_def)
   2.347 -  apply (auto simp add: mult_le_0_iff)
   2.348 -  apply (insert zero_less_pow2[of b])
   2.349 -  apply auto
   2.350 -  done
   2.351 -
   2.352 -lemma float_abs:
   2.353 -  "abs (float (a,b)) = (if 0 <= a then (float (a,b)) else (float (-a,b)))"
   2.354 -  apply (auto simp add: abs_if)
   2.355 -  apply (simp_all add: zero_le_float[symmetric, of a b] float_minus)
   2.356 -  done
   2.357 -
   2.358 -lemma float_zero:
   2.359 -  "float (0, b) = 0"
   2.360 -  by (simp add: float_def)
   2.361 -
   2.362 -lemma float_pprt:
   2.363 -  "pprt (float (a, b)) = (if 0 <= a then (float (a,b)) else (float (0, b)))"
   2.364 -  by (auto simp add: zero_le_float float_le_zero float_zero)
   2.365 -
   2.366 -lemma pprt_lbound: "pprt (lbound x) = float (0, 0)"
   2.367 -  apply (simp add: float_def)
   2.368 -  apply (rule pprt_eq_0)
   2.369 -  apply (simp add: lbound_def)
   2.370 -  done
   2.371 -
   2.372 -lemma nprt_ubound: "nprt (ubound x) = float (0, 0)"
   2.373 -  apply (simp add: float_def)
   2.374 -  apply (rule nprt_eq_0)
   2.375 -  apply (simp add: ubound_def)
   2.376 -  done
   2.377 -
   2.378 -lemma float_nprt:
   2.379 -  "nprt (float (a, b)) = (if 0 <= a then (float (0,b)) else (float (a, b)))"
   2.380 -  by (auto simp add: zero_le_float float_le_zero float_zero)
   2.381 -
   2.382  lemma norm_0_1: "(0::_::number_ring) = Numeral0 & (1::_::number_ring) = Numeral1"
   2.383    by auto
   2.384  
   2.385 @@ -549,6 +225,79 @@
   2.386    zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring]
   2.387    zpower_Pls zpower_Min
   2.388  
   2.389 +definition float :: "(int \<times> int) \<Rightarrow> real" where
   2.390 +  "float = (\<lambda>(a, b). real a * 2 powr real b)"
   2.391 +
   2.392 +lemma float_add_l0: "float (0, e) + x = x"
   2.393 +  by (simp add: float_def)
   2.394 +
   2.395 +lemma float_add_r0: "x + float (0, e) = x"
   2.396 +  by (simp add: float_def)
   2.397 +
   2.398 +lemma float_add:
   2.399 +  "float (a1, e1) + float (a2, e2) =
   2.400 +  (if e1<=e2 then float (a1+a2*2^(nat(e2-e1)), e1) else float (a1*2^(nat (e1-e2))+a2, e2))"
   2.401 +  by (simp add: float_def algebra_simps powr_realpow[symmetric] powr_divide2[symmetric])
   2.402 +
   2.403 +lemma float_mult_l0: "float (0, e) * x = float (0, 0)"
   2.404 +  by (simp add: float_def)
   2.405 +
   2.406 +lemma float_mult_r0: "x * float (0, e) = float (0, 0)"
   2.407 +  by (simp add: float_def)
   2.408 +
   2.409 +lemma float_mult:
   2.410 +  "float (a1, e1) * float (a2, e2) = (float (a1 * a2, e1 + e2))"
   2.411 +  by (simp add: float_def powr_add)
   2.412 +
   2.413 +lemma float_minus:
   2.414 +  "- (float (a,b)) = float (-a, b)"
   2.415 +  by (simp add: float_def)
   2.416 +
   2.417 +lemma zero_le_float:
   2.418 +  "(0 <= float (a,b)) = (0 <= a)"
   2.419 +  using powr_gt_zero[of 2 "real b", arith]
   2.420 +  by (simp add: float_def zero_le_mult_iff)
   2.421 +
   2.422 +lemma float_le_zero:
   2.423 +  "(float (a,b) <= 0) = (a <= 0)"
   2.424 +  using powr_gt_zero[of 2 "real b", arith]
   2.425 +  by (simp add: float_def mult_le_0_iff)
   2.426 +
   2.427 +lemma float_abs:
   2.428 +  "abs (float (a,b)) = (if 0 <= a then (float (a,b)) else (float (-a,b)))"
   2.429 +  using powr_gt_zero[of 2 "real b", arith]
   2.430 +  by (simp add: float_def abs_if mult_less_0_iff)
   2.431 +
   2.432 +lemma float_zero:
   2.433 +  "float (0, b) = 0"
   2.434 +  by (simp add: float_def)
   2.435 +
   2.436 +lemma float_pprt:
   2.437 +  "pprt (float (a, b)) = (if 0 <= a then (float (a,b)) else (float (0, b)))"
   2.438 +  by (auto simp add: zero_le_float float_le_zero float_zero)
   2.439 +
   2.440 +lemma float_nprt:
   2.441 +  "nprt (float (a, b)) = (if 0 <= a then (float (0,b)) else (float (a, b)))"
   2.442 +  by (auto simp add: zero_le_float float_le_zero float_zero)
   2.443 +
   2.444 +definition lbound :: "real \<Rightarrow> real"
   2.445 +  where "lbound x = min 0 x"
   2.446 +
   2.447 +definition ubound :: "real \<Rightarrow> real"
   2.448 +  where "ubound x = max 0 x"
   2.449 +
   2.450 +lemma lbound: "lbound x \<le> x"   
   2.451 +  by (simp add: lbound_def)
   2.452 +
   2.453 +lemma ubound: "x \<le> ubound x"
   2.454 +  by (simp add: ubound_def)
   2.455 +
   2.456 +lemma pprt_lbound: "pprt (lbound x) = float (0, 0)"
   2.457 +  by (auto simp: float_def lbound_def)
   2.458 +
   2.459 +lemma nprt_ubound: "nprt (ubound x) = float (0, 0)"
   2.460 +  by (auto simp: float_def ubound_def)
   2.461 +
   2.462  lemmas floatarith[simplified norm_0_1] = float_add float_add_l0 float_add_r0 float_mult float_mult_l0 float_mult_r0 
   2.463            float_minus float_abs zero_le_float float_pprt float_nprt pprt_lbound nprt_ubound
   2.464