src/HOL/Library/Float.thy
changeset 55565 f663fc1e653b
parent 54784 54f1ce13c140
child 55945 e96383acecf9
equal deleted inserted replaced
55564:e81ee43ab290 55565:f663fc1e653b
   159 lift_definition abs_float :: "float \<Rightarrow> float" is abs by simp
   159 lift_definition abs_float :: "float \<Rightarrow> float" is abs by simp
   160 declare abs_float.rep_eq[simp]
   160 declare abs_float.rep_eq[simp]
   161 lift_definition sgn_float :: "float \<Rightarrow> float" is sgn by simp
   161 lift_definition sgn_float :: "float \<Rightarrow> float" is sgn by simp
   162 declare sgn_float.rep_eq[simp]
   162 declare sgn_float.rep_eq[simp]
   163 
   163 
   164 lift_definition equal_float :: "float \<Rightarrow> float \<Rightarrow> bool" is "op = :: real \<Rightarrow> real \<Rightarrow> bool" ..
   164 lift_definition equal_float :: "float \<Rightarrow> float \<Rightarrow> bool" is "op = :: real \<Rightarrow> real \<Rightarrow> bool" .
   165 
   165 
   166 lift_definition less_eq_float :: "float \<Rightarrow> float \<Rightarrow> bool" is "op \<le>" ..
   166 lift_definition less_eq_float :: "float \<Rightarrow> float \<Rightarrow> bool" is "op \<le>" .
   167 declare less_eq_float.rep_eq[simp]
   167 declare less_eq_float.rep_eq[simp]
   168 lift_definition less_float :: "float \<Rightarrow> float \<Rightarrow> bool" is "op <" ..
   168 lift_definition less_float :: "float \<Rightarrow> float \<Rightarrow> bool" is "op <" .
   169 declare less_float.rep_eq[simp]
   169 declare less_float.rep_eq[simp]
   170 
   170 
   171 instance
   171 instance
   172   proof qed (transfer, fastforce simp add: field_simps intro: mult_left_mono mult_right_mono)+
   172   proof qed (transfer, fastforce simp add: field_simps intro: mult_left_mono mult_right_mono)+
   173 end
   173 end
   464 
   464 
   465 lemma compute_float_sgn[code]: "sgn (Float m1 e1) = (if 0 < m1 then 1 else if m1 < 0 then -1 else 0)"
   465 lemma compute_float_sgn[code]: "sgn (Float m1 e1) = (if 0 < m1 then 1 else if m1 < 0 then -1 else 0)"
   466   by transfer (simp add: sgn_times)
   466   by transfer (simp add: sgn_times)
   467 hide_fact (open) compute_float_sgn
   467 hide_fact (open) compute_float_sgn
   468 
   468 
   469 lift_definition is_float_pos :: "float \<Rightarrow> bool" is "op < 0 :: real \<Rightarrow> bool" ..
   469 lift_definition is_float_pos :: "float \<Rightarrow> bool" is "op < 0 :: real \<Rightarrow> bool" .
   470 
   470 
   471 lemma compute_is_float_pos[code]: "is_float_pos (Float m e) \<longleftrightarrow> 0 < m"
   471 lemma compute_is_float_pos[code]: "is_float_pos (Float m e) \<longleftrightarrow> 0 < m"
   472   by transfer (auto simp add: zero_less_mult_iff not_le[symmetric, of _ 0])
   472   by transfer (auto simp add: zero_less_mult_iff not_le[symmetric, of _ 0])
   473 hide_fact (open) compute_is_float_pos
   473 hide_fact (open) compute_is_float_pos
   474 
   474 
   475 lemma compute_float_less[code]: "a < b \<longleftrightarrow> is_float_pos (b - a)"
   475 lemma compute_float_less[code]: "a < b \<longleftrightarrow> is_float_pos (b - a)"
   476   by transfer (simp add: field_simps)
   476   by transfer (simp add: field_simps)
   477 hide_fact (open) compute_float_less
   477 hide_fact (open) compute_float_less
   478 
   478 
   479 lift_definition is_float_nonneg :: "float \<Rightarrow> bool" is "op \<le> 0 :: real \<Rightarrow> bool" ..
   479 lift_definition is_float_nonneg :: "float \<Rightarrow> bool" is "op \<le> 0 :: real \<Rightarrow> bool" .
   480 
   480 
   481 lemma compute_is_float_nonneg[code]: "is_float_nonneg (Float m e) \<longleftrightarrow> 0 \<le> m"
   481 lemma compute_is_float_nonneg[code]: "is_float_nonneg (Float m e) \<longleftrightarrow> 0 \<le> m"
   482   by transfer (auto simp add: zero_le_mult_iff not_less[symmetric, of _ 0])
   482   by transfer (auto simp add: zero_le_mult_iff not_less[symmetric, of _ 0])
   483 hide_fact (open) compute_is_float_nonneg
   483 hide_fact (open) compute_is_float_nonneg
   484 
   484 
   485 lemma compute_float_le[code]: "a \<le> b \<longleftrightarrow> is_float_nonneg (b - a)"
   485 lemma compute_float_le[code]: "a \<le> b \<longleftrightarrow> is_float_nonneg (b - a)"
   486   by transfer (simp add: field_simps)
   486   by transfer (simp add: field_simps)
   487 hide_fact (open) compute_float_le
   487 hide_fact (open) compute_float_le
   488 
   488 
   489 lift_definition is_float_zero :: "float \<Rightarrow> bool"  is "op = 0 :: real \<Rightarrow> bool" by simp
   489 lift_definition is_float_zero :: "float \<Rightarrow> bool"  is "op = 0 :: real \<Rightarrow> bool" .
   490 
   490 
   491 lemma compute_is_float_zero[code]: "is_float_zero (Float m e) \<longleftrightarrow> 0 = m"
   491 lemma compute_is_float_zero[code]: "is_float_zero (Float m e) \<longleftrightarrow> 0 = m"
   492   by transfer (auto simp add: is_float_zero_def)
   492   by transfer (auto simp add: is_float_zero_def)
   493 hide_fact (open) compute_is_float_zero
   493 hide_fact (open) compute_is_float_zero
   494 
   494 
  1531   unfolding pprt_def sup_float_def max_def sup_real_def by auto
  1531   unfolding pprt_def sup_float_def max_def sup_real_def by auto
  1532 
  1532 
  1533 lemma real_of_float_nprt[simp]: fixes a::float shows "real (nprt a) = nprt (real a)"
  1533 lemma real_of_float_nprt[simp]: fixes a::float shows "real (nprt a) = nprt (real a)"
  1534   unfolding nprt_def inf_float_def min_def inf_real_def by auto
  1534   unfolding nprt_def inf_float_def min_def inf_real_def by auto
  1535 
  1535 
  1536 lift_definition int_floor_fl :: "float \<Rightarrow> int" is floor by simp
  1536 lift_definition int_floor_fl :: "float \<Rightarrow> int" is floor .
  1537 
  1537 
  1538 lemma compute_int_floor_fl[code]:
  1538 lemma compute_int_floor_fl[code]:
  1539   "int_floor_fl (Float m e) = (if 0 \<le> e then m * 2 ^ nat e else m div (2 ^ (nat (-e))))"
  1539   "int_floor_fl (Float m e) = (if 0 \<le> e then m * 2 ^ nat e else m div (2 ^ (nat (-e))))"
  1540   by transfer (simp add: powr_int int_of_reals floor_divide_eq_div del: real_of_ints)
  1540   by transfer (simp add: powr_int int_of_reals floor_divide_eq_div del: real_of_ints)
  1541 hide_fact (open) compute_int_floor_fl
  1541 hide_fact (open) compute_int_floor_fl