library colibrilib.fbin — module SpecialThe floats of F.get_special_values by their index (ix neg k is the index of the magnitude k with the sign neg), and the classes of a float.
module Special3077use int.Int3078use int.Power3079use Pow2r3080use Format3081use Float3082use Round3083use Impl30843085function ix (neg: bool) (k: int) : int = if neg then -1 - k else k30863087type signed = {3088sv_zero: t; sv_first_subnormal: t; sv_last_subnormal: t;3089sv_first_normal: t; sv_last_normal: t; sv_infinite: t }30903091predicate at_i (fm: format) (x: t) (i: int) = x.fmt = fm /\ not is_nan x /\ index x = i3092Valid (1.2s) (cvc4)3093let signed_values (fm: format) (neg: bool) : signed3094ensures { at_i fm result.sv_zero (ix neg 0) }3095ensures { at_i fm result.sv_first_subnormal (ix neg 1) }3096ensures { at_i fm result.sv_last_subnormal (ix neg (binade fm - 1)) }3097ensures { at_i fm result.sv_first_normal (ix neg (binade fm)) }3098ensures { at_i fm result.sv_last_normal (ix neg (nb_sign fm - 2)) }3099ensures { at_i fm result.sv_infinite (ix neg (nb_sign fm - 1)) }3100ensures { if neg then is_minus_infinity result.sv_infinite3101else is_plus_infinity result.sv_infinite }3102= let p = binade_p fm in3103let nb = nb_sign_p fm in3104let ix (k: int) : int ensures { result = ix neg k } = if neg then -1 - k else k in3105{proof…}3106binade_ge_2 fm; nb_sign_ge fm;3107assert { binade fm < nb_sign fm - 2 by3108nb_sign fm = (power 2 fm.eb - 1) * binade fm + 1 /\ 3 <= power 2 fm.eb - 1 };3109of_index_range fm (ix 0); of_index_range fm (ix 1);3110of_index_range fm (ix (p - 1)); of_index_range fm (ix p);3111of_index_range fm (ix (nb - 2)); of_index_range fm (ix (nb - 1));3112{qed}3113{ sv_zero = of_index_p fm (ix 0);3114sv_first_subnormal = of_index_p fm (ix 1);3115sv_last_subnormal = of_index_p fm (ix (p - 1));3116sv_first_normal = of_index_p fm (ix p);3117sv_last_normal = of_index_p fm (ix (nb - 2));3118sv_infinite = of_index_p fm (ix (nb - 1)) }3119Valid (42ms) (colibri2)3120let is_subnormal_p (x: t) : bool3121ensures { result <-> is_subnormal x }3122= match x.value with Finite _ k -> 0 < k && k < binade_p x.fmt | _ -> false end3123Valid (35ms) (colibri2)3124let is_normal_p (x: t) : bool3125ensures { result <-> is_normal x }3126= match x.value with Finite _ k -> binade_p x.fmt <= k | _ -> false end3127end3128