src/HOL/Matrix/Float.thy
changeset 15178 5f621aa35c25
child 15236 f289e8ba2bb3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Matrix/Float.thy	Fri Sep 03 17:10:36 2004 +0200
     1.3 @@ -0,0 +1,508 @@
     1.4 +theory Float = Hyperreal:
     1.5 +
     1.6 +constdefs  
     1.7 +  pow2 :: "int \<Rightarrow> real"
     1.8 +  "pow2 a == if (0 <= a) then (2^(nat a)) else (inverse (2^(nat (-a))))" 
     1.9 +  float :: "int * int \<Rightarrow> real"
    1.10 +  "float x == (real (fst x)) * (pow2 (snd x))"
    1.11 +
    1.12 +lemma pow2_0[simp]: "pow2 0 = 1"
    1.13 +by (simp add: pow2_def)
    1.14 +
    1.15 +lemma pow2_1[simp]: "pow2 1 = 2"
    1.16 +by (simp add: pow2_def)
    1.17 +
    1.18 +lemma pow2_neg: "pow2 x = inverse (pow2 (-x))"
    1.19 +by (simp add: pow2_def)
    1.20 +
    1.21 +lemma pow2_add1: "pow2 (1 + a) = 2 * (pow2 a)" 
    1.22 +proof -
    1.23 +  have h: "! n. nat (2 + int n) - Suc 0 = nat (1 + int n)" by arith
    1.24 +  have g: "! a b. a - -1 = a + (1::int)" by arith
    1.25 +  have pos: "! n. pow2 (int n + 1) = 2 * pow2 (int n)"
    1.26 +    apply (auto, induct_tac n)
    1.27 +    apply (simp_all add: pow2_def)
    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 +  show ?thesis
    1.33 +  proof (induct a)
    1.34 +    case (1 n)
    1.35 +    from pos show ?case by (simp add: ring_eq_simps)
    1.36 +  next
    1.37 +    case (2 n)
    1.38 +    show ?case
    1.39 +      apply (auto)
    1.40 +      apply (subst pow2_neg[of "- int n"])
    1.41 +      apply (subst pow2_neg[of "-1 - int n"])
    1.42 +      apply (auto simp add: g pos)
    1.43 +      done
    1.44 +  qed  
    1.45 +qed
    1.46 +  
    1.47 +lemma pow2_add: "pow2 (a+b) = (pow2 a) * (pow2 b)"
    1.48 +proof (induct b)
    1.49 +  case (1 n) 
    1.50 +  show ?case
    1.51 +  proof (induct n)
    1.52 +    case 0
    1.53 +    show ?case by simp
    1.54 +  next
    1.55 +    case (Suc m)
    1.56 +    show ?case by (auto simp add: ring_eq_simps pow2_add1 prems)
    1.57 +  qed
    1.58 +next
    1.59 +  case (2 n)
    1.60 +  show ?case 
    1.61 +  proof (induct n)
    1.62 +    case 0
    1.63 +    show ?case 
    1.64 +      apply (auto)
    1.65 +      apply (subst pow2_neg[of "a + -1"])
    1.66 +      apply (subst pow2_neg[of "-1"])
    1.67 +      apply (simp)
    1.68 +      apply (insert pow2_add1[of "-a"])
    1.69 +      apply (simp add: ring_eq_simps)
    1.70 +      apply (subst pow2_neg[of "-a"])
    1.71 +      apply (simp)
    1.72 +      done
    1.73 +    case (Suc m)
    1.74 +    have a: "int m - (a + -2) =  1 + (int m - a + 1)" by arith	
    1.75 +    have b: "int m - -2 = 1 + (int m + 1)" by arith
    1.76 +    show ?case
    1.77 +      apply (auto)
    1.78 +      apply (subst pow2_neg[of "a + (-2 - int m)"])
    1.79 +      apply (subst pow2_neg[of "-2 - int m"])
    1.80 +      apply (auto simp add: ring_eq_simps)
    1.81 +      apply (subst a)
    1.82 +      apply (subst b)
    1.83 +      apply (simp only: pow2_add1)
    1.84 +      apply (subst pow2_neg[of "int m - a + 1"])
    1.85 +      apply (subst pow2_neg[of "int m + 1"])
    1.86 +      apply auto
    1.87 +      apply (insert prems)
    1.88 +      apply (auto simp add: ring_eq_simps)
    1.89 +      done
    1.90 +  qed
    1.91 +qed
    1.92 +
    1.93 +lemma "float (a, e) + float (b, e) = float (a + b, e)"  
    1.94 +by (simp add: float_def ring_eq_simps)
    1.95 +
    1.96 +constdefs 
    1.97 +  int_of_real :: "real \<Rightarrow> int"
    1.98 +  "int_of_real x == SOME y. real y = x"  
    1.99 +  real_is_int :: "real \<Rightarrow> bool"
   1.100 +  "real_is_int x == ? (u::int). x = real u" 
   1.101 +
   1.102 +lemma real_is_int_def2: "real_is_int x = (x = real (int_of_real x))"
   1.103 +by (auto simp add: real_is_int_def int_of_real_def)
   1.104 +
   1.105 +lemma float_transfer: "real_is_int ((real a)*(pow2 c)) \<Longrightarrow> float (a, b) = float (int_of_real ((real a)*(pow2 c)), b - c)"
   1.106 +by (simp add: float_def real_is_int_def2 pow2_add[symmetric])
   1.107 +
   1.108 +lemma pow2_int: "pow2 (int c) = (2::real)^c"
   1.109 +by (simp add: pow2_def)
   1.110 +
   1.111 +lemma float_transfer_nat: "float (a, b) = float (a * 2^c, b - int c)" 
   1.112 +by (simp add: float_def pow2_int[symmetric] pow2_add[symmetric])
   1.113 +
   1.114 +lemma real_is_int_real[simp]: "real_is_int (real (x::int))"
   1.115 +by (auto simp add: real_is_int_def int_of_real_def)
   1.116 +
   1.117 +lemma int_of_real_real[simp]: "int_of_real (real x) = x"
   1.118 +by (simp add: int_of_real_def)
   1.119 +
   1.120 +lemma real_int_of_real[simp]: "real_is_int x \<Longrightarrow> real (int_of_real x) = x"
   1.121 +by (auto simp add: int_of_real_def real_is_int_def)
   1.122 +
   1.123 +lemma real_is_int_add_int_of_real: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> (int_of_real (a+b)) = (int_of_real a) + (int_of_real b)"
   1.124 +by (auto simp add: int_of_real_def real_is_int_def)
   1.125 +
   1.126 +lemma real_is_int_add[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a+b)"
   1.127 +apply (subst real_is_int_def2)
   1.128 +apply (simp add: real_is_int_add_int_of_real real_int_of_real)
   1.129 +done
   1.130 +
   1.131 +lemma int_of_real_sub: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> (int_of_real (a-b)) = (int_of_real a) - (int_of_real b)"
   1.132 +by (auto simp add: int_of_real_def real_is_int_def)
   1.133 +
   1.134 +lemma real_is_int_sub[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a-b)"
   1.135 +apply (subst real_is_int_def2)
   1.136 +apply (simp add: int_of_real_sub real_int_of_real)
   1.137 +done
   1.138 +
   1.139 +lemma real_is_int_rep: "real_is_int x \<Longrightarrow> ?! (a::int). real a = x"
   1.140 +by (auto simp add: real_is_int_def)
   1.141 +
   1.142 +lemma int_of_real_mult: 
   1.143 +  assumes "real_is_int a" "real_is_int b"
   1.144 +  shows "(int_of_real (a*b)) = (int_of_real a) * (int_of_real b)"
   1.145 +proof -
   1.146 +  from prems have a: "?! (a'::int). real a' = a" by (rule_tac real_is_int_rep, auto)
   1.147 +  from prems have b: "?! (b'::int). real b' = b" by (rule_tac real_is_int_rep, auto)
   1.148 +  from a obtain a'::int where a':"a = real a'" by auto
   1.149 +  from b obtain b'::int where b':"b = real b'" by auto
   1.150 +  have r: "real a' * real b' = real (a' * b')" by auto
   1.151 +  show ?thesis
   1.152 +    apply (simp add: a' b')
   1.153 +    apply (subst r)
   1.154 +    apply (simp only: int_of_real_real)
   1.155 +    done
   1.156 +qed
   1.157 +
   1.158 +lemma real_is_int_mult[simp]: "real_is_int a \<Longrightarrow> real_is_int b \<Longrightarrow> real_is_int (a*b)"
   1.159 +apply (subst real_is_int_def2)
   1.160 +apply (simp add: int_of_real_mult)
   1.161 +done
   1.162 +
   1.163 +lemma real_is_int_0[simp]: "real_is_int (0::real)"
   1.164 +by (simp add: real_is_int_def int_of_real_def)
   1.165 +
   1.166 +lemma real_is_int_1[simp]: "real_is_int (1::real)"
   1.167 +proof -
   1.168 +  have "real_is_int (1::real) = real_is_int(real (1::int))" by auto
   1.169 +  also have "\<dots> = True" by (simp only: real_is_int_real)
   1.170 +  ultimately show ?thesis by auto
   1.171 +qed
   1.172 +
   1.173 +lemma real_is_int_n1: "real_is_int (-1::real)"
   1.174 +proof -
   1.175 +  have "real_is_int (-1::real) = real_is_int(real (-1::int))" by auto
   1.176 +  also have "\<dots> = True" by (simp only: real_is_int_real)
   1.177 +  ultimately show ?thesis by auto
   1.178 +qed
   1.179 +
   1.180 +lemma real_is_int_number_of[simp]: "real_is_int ((number_of::bin\<Rightarrow>real) x)"
   1.181 +proof -
   1.182 +  have neg1: "real_is_int (-1::real)"
   1.183 +  proof -
   1.184 +    have "real_is_int (-1::real) = real_is_int(real (-1::int))" by auto
   1.185 +    also have "\<dots> = True" by (simp only: real_is_int_real)
   1.186 +    ultimately show ?thesis by auto
   1.187 +  qed
   1.188 +  
   1.189 +  { 
   1.190 +    fix x::int
   1.191 +    have "!! y. real_is_int ((number_of::bin\<Rightarrow>real) (Abs_Bin x))"
   1.192 +      apply (simp add: number_of_eq)
   1.193 +      apply (subst Abs_Bin_inverse)
   1.194 +      apply (simp add: Bin_def)
   1.195 +      apply (induct x)
   1.196 +      apply (induct_tac n)
   1.197 +      apply (simp)
   1.198 +      apply (simp)
   1.199 +      apply (induct_tac n)
   1.200 +      apply (simp add: neg1)
   1.201 +    proof -
   1.202 +      fix n :: nat
   1.203 +      assume rn: "(real_is_int (of_int (- (int (Suc n)))))"
   1.204 +      have s: "-(int (Suc (Suc n))) = -1 + - (int (Suc n))" by simp
   1.205 +      show "real_is_int (of_int (- (int (Suc (Suc n)))))"
   1.206 +	apply (simp only: s of_int_add)
   1.207 +	apply (rule real_is_int_add)
   1.208 +	apply (simp add: neg1)
   1.209 +	apply (simp only: rn)
   1.210 +	done
   1.211 +    qed
   1.212 +  }
   1.213 +  note Abs_Bin = this
   1.214 +  {
   1.215 +    fix x :: bin
   1.216 +    have "? u. x = Abs_Bin u"
   1.217 +      apply (rule exI[where x = "Rep_Bin x"])
   1.218 +      apply (simp add: Rep_Bin_inverse)
   1.219 +      done
   1.220 +  }
   1.221 +  then obtain u::int where "x = Abs_Bin u" by auto
   1.222 +  with Abs_Bin show ?thesis by auto
   1.223 +qed
   1.224 +
   1.225 +lemma int_of_real_0[simp]: "int_of_real (0::real) = (0::int)"
   1.226 +by (simp add: int_of_real_def)
   1.227 +
   1.228 +lemma int_of_real_1[simp]: "int_of_real (1::real) = (1::int)"
   1.229 +proof - 
   1.230 +  have 1: "(1::real) = real (1::int)" by auto
   1.231 +  show ?thesis by (simp only: 1 int_of_real_real)
   1.232 +qed
   1.233 +
   1.234 +lemma int_of_real_number_of[simp]: "int_of_real (number_of b) = number_of b"
   1.235 +proof -
   1.236 +  have "real_is_int (number_of b)" by simp
   1.237 +  then have uu: "?! u::int. number_of b = real u" by (auto simp add: real_is_int_rep)
   1.238 +  then obtain u::int where u:"number_of b = real u" by auto
   1.239 +  have "number_of b = real ((number_of b)::int)" 
   1.240 +    by (simp add: number_of_eq real_of_int_def)
   1.241 +  have ub: "number_of b = real ((number_of b)::int)" 
   1.242 +    by (simp add: number_of_eq real_of_int_def)
   1.243 +  from uu u ub have unb: "u = number_of b"
   1.244 +    by blast
   1.245 +  have "int_of_real (number_of b) = u" by (simp add: u)
   1.246 +  with unb show ?thesis by simp
   1.247 +qed
   1.248 +
   1.249 +lemma float_transfer_even: "even a \<Longrightarrow> float (a, b) = float (a div 2, b+1)"
   1.250 +  apply (subst float_transfer[where a="a" and b="b" and c="-1", simplified])
   1.251 +  apply (simp_all add: pow2_def even_def real_is_int_def ring_eq_simps)
   1.252 +  apply (auto)
   1.253 +proof -
   1.254 +  fix q::int
   1.255 +  have a:"b - (-1\<Colon>int) = (1\<Colon>int) + b" by arith
   1.256 +  show "(float (q, (b - (-1\<Colon>int)))) = (float (q, ((1\<Colon>int) + b)))" 
   1.257 +    by (simp add: a)
   1.258 +qed
   1.259 +    
   1.260 +consts
   1.261 +  norm_float :: "int*int \<Rightarrow> int*int"
   1.262 +
   1.263 +lemma int_div_zdiv: "int (a div b) = (int a) div (int b)"
   1.264 +apply (subst split_div, auto)
   1.265 +apply (subst split_zdiv, auto)
   1.266 +apply (rule_tac a="int (b * i) + int j" and b="int b" and r="int j" and r'=ja in IntDiv.unique_quotient)
   1.267 +apply (auto simp add: IntDiv.quorem_def int_eq_of_nat)
   1.268 +done
   1.269 +
   1.270 +lemma int_mod_zmod: "int (a mod b) = (int a) mod (int b)"
   1.271 +apply (subst split_mod, auto)
   1.272 +apply (subst split_zmod, auto)
   1.273 +apply (rule_tac a="int (b * i) + int j" and b="int b" and q="int i" and q'=ia in IntDiv.unique_remainder)
   1.274 +apply (auto simp add: IntDiv.quorem_def int_eq_of_nat)
   1.275 +done
   1.276 +
   1.277 +lemma abs_div_2_less: "a \<noteq> 0 \<Longrightarrow> a \<noteq> -1 \<Longrightarrow> abs((a::int) div 2) < abs a"
   1.278 +by arith
   1.279 +
   1.280 +lemma terminating_norm_float: "\<forall>a. (a::int) \<noteq> 0 \<and> even a \<longrightarrow> a \<noteq> 0 \<and> \<bar>a div 2\<bar> < \<bar>a\<bar>"
   1.281 +apply (auto)
   1.282 +apply (rule abs_div_2_less)
   1.283 +apply (auto)
   1.284 +done
   1.285 +
   1.286 +ML {* simp_depth_limit := 2 *} 
   1.287 +recdef norm_float "measure (% (a,b). nat (abs a))"
   1.288 +  "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.289 +(hints simp: terminating_norm_float)
   1.290 +ML {* simp_depth_limit := 1000 *}
   1.291 +
   1.292 +
   1.293 +lemma norm_float: "float x = float (norm_float x)"
   1.294 +proof -
   1.295 +  {
   1.296 +    fix a b :: int 
   1.297 +    have norm_float_pair: "float (a,b) = float (norm_float (a,b))" 
   1.298 +    proof (induct a b rule: norm_float.induct)
   1.299 +      case (1 u v)
   1.300 +      show ?case 
   1.301 +      proof cases
   1.302 +	assume u: "u \<noteq> 0 \<and> even u"
   1.303 +	with prems have ind: "float (u div 2, v + 1) = float (norm_float (u div 2, v + 1))" by auto
   1.304 +	with u have "float (u,v) = float (u div 2, v+1)" by (simp add: float_transfer_even) 
   1.305 +	then show ?thesis
   1.306 +	  apply (subst norm_float.simps)
   1.307 +	  apply (simp add: ind)
   1.308 +	  done
   1.309 +      next
   1.310 +	assume "~(u \<noteq> 0 \<and> even u)"
   1.311 +	then show ?thesis
   1.312 +	  by (simp add: prems float_def)
   1.313 +      qed
   1.314 +    qed
   1.315 +  }
   1.316 +  note helper = this
   1.317 +  have "? a b. x = (a,b)" by auto
   1.318 +  then obtain a b where "x = (a, b)" by blast
   1.319 +  then show ?thesis by (simp only: helper)
   1.320 +qed
   1.321 +
   1.322 +lemma pow2_int: "pow2 (int n) = 2^n"
   1.323 +  by (simp add: pow2_def)
   1.324 +
   1.325 +lemma float_add: 
   1.326 +  "float (a1, e1) + float (a2, e2) = 
   1.327 +  (if e1<=e2 then float (a1+a2*2^(nat(e2-e1)), e1) 
   1.328 +  else float (a1*2^(nat (e1-e2))+a2, e2))"
   1.329 +  apply (simp add: float_def ring_eq_simps)
   1.330 +  apply (auto simp add: pow2_int[symmetric] pow2_add[symmetric])
   1.331 +  done
   1.332 +
   1.333 +lemma float_mult:
   1.334 +  "float (a1, e1) * float (a2, e2) = 
   1.335 +  (float (a1 * a2, e1 + e2))"
   1.336 +  by (simp add: float_def pow2_add)
   1.337 +
   1.338 +lemma float_minus:
   1.339 +  "- (float (a,b)) = float (-a, b)"
   1.340 +  by (simp add: float_def)
   1.341 +
   1.342 +lemma zero_less_pow2:
   1.343 +  "0 < pow2 x"
   1.344 +proof -
   1.345 +  {
   1.346 +    fix y
   1.347 +    have "0 <= y \<Longrightarrow> 0 < pow2 y"    
   1.348 +      by (induct y, induct_tac n, simp_all add: pow2_add)
   1.349 +  }
   1.350 +  note helper=this
   1.351 +  show ?thesis
   1.352 +    apply (case_tac "0 <= x")
   1.353 +    apply (simp add: helper)
   1.354 +    apply (subst pow2_neg)
   1.355 +    apply (simp add: helper)
   1.356 +    done
   1.357 +qed
   1.358 +
   1.359 +lemma zero_le_float:
   1.360 +  "(0 <= float (a,b)) = (0 <= a)"
   1.361 +  apply (auto simp add: float_def)
   1.362 +  apply (auto simp add: zero_le_mult_iff zero_less_pow2) 
   1.363 +  apply (insert zero_less_pow2[of b])
   1.364 +  apply (simp_all)
   1.365 +  done
   1.366 +
   1.367 +lemma float_abs:
   1.368 +  "abs (float (a,b)) = (if 0 <= a then (float (a,b)) else (float (-a,b)))"
   1.369 +  apply (auto simp add: abs_if)
   1.370 +  apply (simp_all add: zero_le_float[symmetric, of a b] float_minus)
   1.371 +  done
   1.372 +
   1.373 +lemma norm_0_1: "(0::_::number_ring) = Numeral0 & (1::_::number_ring) = Numeral1"
   1.374 +  by auto
   1.375 +  
   1.376 +lemma add_left_zero: "0 + a = (a::'a::comm_monoid_add)"
   1.377 +  by simp
   1.378 +
   1.379 +lemma add_right_zero: "a + 0 = (a::'a::comm_monoid_add)"
   1.380 +  by simp
   1.381 +
   1.382 +lemma mult_left_one: "1 * a = (a::'a::semiring_1)"
   1.383 +  by simp
   1.384 +
   1.385 +lemma mult_right_one: "a * 1 = (a::'a::semiring_1)"
   1.386 +  by simp
   1.387 +
   1.388 +lemma int_pow_0: "(a::int)^(Numeral0) = 1"
   1.389 +  by simp
   1.390 +
   1.391 +lemma int_pow_1: "(a::int)^(Numeral1) = a"
   1.392 +  by simp
   1.393 +
   1.394 +lemma zero_eq_Numeral0_nring: "(0::'a::number_ring) = Numeral0"
   1.395 +  by simp
   1.396 +
   1.397 +lemma one_eq_Numeral1_nring: "(1::'a::number_ring) = Numeral1"
   1.398 +  by simp
   1.399 +
   1.400 +lemma zero_eq_Numeral0_nat: "(0::nat) = Numeral0"
   1.401 +  by simp
   1.402 +
   1.403 +lemma one_eq_Numeral1_nat: "(1::nat) = Numeral1"
   1.404 +  by simp
   1.405 +
   1.406 +lemma zpower_Pls: "(z::int)^Numeral0 = Numeral1"
   1.407 +  by simp
   1.408 +
   1.409 +lemma zpower_Min: "(z::int)^((-1)::nat) = Numeral1"
   1.410 +proof -
   1.411 +  have 1:"((-1)::nat) = 0"
   1.412 +    by simp
   1.413 +  show ?thesis by (simp add: 1)
   1.414 +qed
   1.415 +
   1.416 +lemma fst_cong: "a=a' \<Longrightarrow> fst (a,b) = fst (a',b)"
   1.417 +  by simp
   1.418 +
   1.419 +lemma snd_cong: "b=b' \<Longrightarrow> snd (a,b) = snd (a,b')"
   1.420 +  by simp
   1.421 +
   1.422 +lemma lift_bool: "x \<Longrightarrow> x=True"
   1.423 +  by simp
   1.424 +
   1.425 +lemma nlift_bool: "~x \<Longrightarrow> x=False"
   1.426 +  by simp
   1.427 +
   1.428 +lemma not_false_eq_true: "(~ False) = True" by simp
   1.429 +
   1.430 +lemma not_true_eq_false: "(~ True) = False" by simp
   1.431 +
   1.432 +
   1.433 +lemmas binarith = 
   1.434 +  Pls_0_eq Min_1_eq
   1.435 +  bin_pred_Pls bin_pred_Min bin_pred_1 bin_pred_0     
   1.436 +  bin_succ_Pls bin_succ_Min bin_succ_1 bin_succ_0
   1.437 +  bin_add_Pls bin_add_Min bin_add_BIT_0 bin_add_BIT_10
   1.438 +  bin_add_BIT_11 bin_minus_Pls bin_minus_Min bin_minus_1 
   1.439 +  bin_minus_0 bin_mult_Pls bin_mult_Min bin_mult_1 bin_mult_0 
   1.440 +  bin_add_Pls_right bin_add_Min_right
   1.441 +
   1.442 +thm eq_number_of_eq
   1.443 +
   1.444 +lemma int_eq_number_of_eq: "(((number_of v)::int)=(number_of w)) = iszero ((number_of (bin_add v (bin_minus w)))::int)"
   1.445 +  by simp
   1.446 +
   1.447 +lemma int_iszero_number_of_Pls: "iszero (Numeral0::int)" 
   1.448 +  by (simp only: iszero_number_of_Pls)
   1.449 +
   1.450 +lemma int_nonzero_number_of_Min: "~(iszero ((-1)::int))"
   1.451 +  by simp
   1.452 +thm iszero_number_of_1
   1.453 +
   1.454 +lemma int_iszero_number_of_0: "iszero ((number_of (w BIT False))::int) = iszero ((number_of w)::int)"
   1.455 +  by simp
   1.456 +
   1.457 +lemma int_iszero_number_of_1: "\<not> iszero ((number_of (w BIT True))::int)" 
   1.458 +  by simp
   1.459 +
   1.460 +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.461 +  by simp
   1.462 +
   1.463 +lemma int_not_neg_number_of_Pls: "\<not> (neg (Numeral0::int))" 
   1.464 +  by simp
   1.465 +
   1.466 +lemma int_neg_number_of_Min: "neg (-1::int)"
   1.467 +  by simp
   1.468 +
   1.469 +lemma int_neg_number_of_BIT: "neg ((number_of (w BIT x))::int) = neg ((number_of w)::int)"
   1.470 +  by simp
   1.471 +
   1.472 +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.473 +  by simp
   1.474 +
   1.475 +lemmas intarithrel = 
   1.476 +  (*abs_zero abs_one*)
   1.477 +  int_eq_number_of_eq 
   1.478 +  lift_bool[OF int_iszero_number_of_Pls] nlift_bool[OF int_nonzero_number_of_Min] int_iszero_number_of_0 
   1.479 +  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.480 +  int_neg_number_of_BIT int_le_number_of_eq
   1.481 +
   1.482 +lemma int_number_of_add_sym: "((number_of v)::int) + number_of w = number_of (bin_add v w)"
   1.483 +  by simp
   1.484 +
   1.485 +lemma int_number_of_diff_sym: "((number_of v)::int) - number_of w = number_of (bin_add v (bin_minus w))"
   1.486 +  by simp
   1.487 +
   1.488 +lemma int_number_of_mult_sym: "((number_of v)::int) * number_of w = number_of (bin_mult v w)"
   1.489 +  by simp
   1.490 +
   1.491 +lemma int_number_of_minus_sym: "- ((number_of v)::int) = number_of (bin_minus v)"
   1.492 +  by simp
   1.493 +
   1.494 +lemmas intarith = int_number_of_add_sym int_number_of_minus_sym int_number_of_diff_sym int_number_of_mult_sym
   1.495 +
   1.496 +lemmas natarith = (*zero_eq_Numeral0_nat one_eq_Numeral1_nat*) add_nat_number_of 
   1.497 +  diff_nat_number_of mult_nat_number_of eq_nat_number_of less_nat_number_of
   1.498 +
   1.499 +lemmas powerarith = nat_number_of zpower_number_of_even 
   1.500 +  zpower_number_of_odd[simplified zero_eq_Numeral0_nring one_eq_Numeral1_nring]   
   1.501 +  zpower_Pls zpower_Min
   1.502 +
   1.503 +lemmas floatarith[simplified norm_0_1] = float_add float_mult float_minus float_abs zero_le_float
   1.504 +
   1.505 +lemmas arith = binarith intarith intarithrel natarith powerarith floatarith not_false_eq_true not_true_eq_false
   1.506 +
   1.507 +(* needed for the verifying code generator *)
   1.508 +lemmas arith_no_let = arith[simplified Let_def]
   1.509 +
   1.510 +end
   1.511 +