library colibrilib.fp_facts — module FactsEach fact on the order has a version with requires, used when the hypotheses are known, and a total version (_any, implications) that can be called in any branch.
module Facts12use int.Int13use int.Power14use int.EuclideanDivision15use real.RealInfix16use colibrilib.fp.Ereal17use colibrilib.fbin.Fp18Valid (28ms) (colibri2)19let ghost le_refl (x: t) : unit20requires { is_not_nan x }21ensures { le_dz x x }22= {proof…} () {qed}23Valid (27ms) (colibri2)24let ghost le_trans (x y z: t) : unit25requires { le_dz x y /\ le_dz y z }26ensures { le_dz x z }27= {proof…} () {qed}28Valid (35ms) (colibri2)29let ghost lt_le_trans (x y z: t) : unit30requires { lt_dz x y /\ le_dz y z }31ensures { lt_dz x z }32= {proof…} () {qed}33Valid (25ms) (colibri2)34let ghost le_lt_trans (x y z: t) : unit35requires { le_dz x y /\ lt_dz y z }36ensures { lt_dz x z }37= {proof…} () {qed}38Valid (20ms) (colibri2)39let ghost total (x y: t) : unit40requires { is_not_nan x /\ is_not_nan y /\ fmt x = fmt y }41ensures { le_dz x y \/ lt_dz y x }42= {proof…} () {qed}43Valid (23ms) (colibri2)44let ghost lt_not_le (x y: t) : unit45requires { lt_dz x y }46ensures { not (le_dz y x) }47= {proof…} () {qed}48Valid (28ms) (colibri2)49let ghost lt_le (x y: t) : unit50requires { lt_dz x y }51ensures { le_dz x y }52= {proof…} () {qed}53Valid (23ms) (colibri2)54let ghost le_refl_any (x: t) : unit55ensures { is_not_nan x -> le_dz x x }56= if not (is_nan x) then le_refl x57Valid (22ms) (colibri2)58let ghost le_not_nan_any (x y: t) : unit59ensures { le_dz x y -> is_not_nan x /\ is_not_nan y }60= ()61Valid (27ms) (colibri2)62let ghost le_trans_any (x y z: t) : unit63ensures { le_dz x y -> le_dz y z -> le_dz x z }64= if le_diff_zero x y && le_diff_zero y z then le_trans x y z65Valid (31ms) (colibri2)66let ghost lt_le_trans_any (x y z: t) : unit67ensures { lt_dz x y -> le_dz y z -> lt_dz x z }68= if lt_diff_zero x y && le_diff_zero y z then lt_le_trans x y z69Valid (33ms) (colibri2)70let ghost le_lt_trans_any (x y z: t) : unit71ensures { le_dz x y -> lt_dz y z -> lt_dz x z }72= if le_diff_zero x y && lt_diff_zero y z then le_lt_trans x y z73Valid (30ms) (colibri2)74let ghost total_any (x y: t) : unit75ensures { is_not_nan x -> is_not_nan y -> fmt x = fmt y ->76le_dz x y \/ lt_dz y x }77= if not (is_nan x) && not (is_nan y) && pure { fmt x = fmt y } then total x y78Valid (25ms) (colibri2)79let ghost lt_not_le_any (x y: t) : unit80ensures { lt_dz x y -> not (le_dz y x) }81= if lt_diff_zero x y then lt_not_le x y82Valid (24ms) (colibri2)83let ghost lt_le_any (x y: t) : unit84ensures { lt_dz x y -> le_dz x y }85= if lt_diff_zero x y then lt_le x y86
The minimum and the maximum
Valid (22ms) (colibri2)let min_diff_zero (x y: t) : t90requires { is_not_nan x /\ is_not_nan y /\ fmt x = fmt y }91ensures { (result = x /\ le_dz x y) \/ (result = y /\ le_dz y x) }92= if le_diff_zero x y then x else begin total x y; lt_le y x; y end93Valid (25ms) (colibri2)94let max_diff_zero (x y: t) : t95requires { is_not_nan x /\ is_not_nan y /\ fmt x = fmt y }96ensures { (result = y /\ le_dz x y) \/ (result = x /\ le_dz y x) }97= if le_diff_zero x y then y else begin total x y; lt_le y x; x end98
Valid (35ms) (colibri2 4) (split_vc) (depth 1)let ghost neg_neg (x: t) : unit102ensures { neg (neg x) = x }103= {proof…}104if is_nan x then assert { neg (neg x) = not_a_number (fmt x) = x }105else begin106assert { index (neg (neg x)) = index x };107assert { of_index (fmt x) (index (neg (neg x))) = of_index (fmt x) (index x) }108end109{qed}110
succ_dz, pred_dz and their implementations succ_diff_zero, pred_diff_zero are in Intf; their properties are below, not ensures that every call would bring into the context.
Valid (255ms) (colibri2 4) (cvc4) (split_vc) (depth 1)let ghost succ_gt (x: t) : unit118requires { is_not_nan x /\ not is_plus_infinity x }119ensures { is_not_nan (succ_dz x) /\ lt_dz x (succ_dz x) }120= {proof…}121assert { lt_dz x (plus_infinity (fmt x)) };122index_range (plus_infinity (fmt x)); index_range x;123of_index_range (fmt x) (index x + 1)124{qed}125
No float between x and its successor
Valid (276ms) (colibri2 4) (cvc5) (split_vc) (depth 1)let ghost succ_least (x y: t) : unit128requires { lt_dz x y }129ensures { le_dz (succ_dz x) y }130= {proof…}131index_range x; index_range y; of_index_range (fmt x) (index x + 1);132assert { index (succ_dz x) = index x + 1 <= index y }133{qed}134Valid (39ms) (colibri2)135let ghost pred_lt (x: t) : unit136requires { is_not_nan x /\ not is_minus_infinity x }137ensures { is_not_nan (pred_dz x) /\ lt_dz (pred_dz x) x }138= {proof…}139assert { lt_dz (minus_infinity (fmt x)) x };140index_range (minus_infinity (fmt x)); index_range x;141of_index_range (fmt x) (index x - 1)142{qed}143Valid (282ms) (colibri2 4) (cvc5) (split_vc) (depth 1)144let ghost pred_greatest (x y: t) : unit145requires { lt_dz y x }146ensures { le_dz y (pred_dz x) }147= {proof…}148index_range x; index_range y; of_index_range (fmt x) (index x - 1);149assert { index y <= index x - 1 = index (pred_dz x) }150{qed}151
The positive floats are above the negative ones
Valid (21ms) (colibri2)let ghost le_positive (x y: t) : unit156requires { le_dz x y } ensures { is_positive x -> is_positive y }157= {proof…} le_not_nan x y {qed}158
NaN on a NaN or on two infinities of opposite signs; an infinity otherwise wins
Valid (329ms) (cvc5)let ghost add_special (m: mode) (x y: t) : unit162ensures { is_nan (fp_add m x y) <->163is_nan x \/ is_nan y \/ (is_plus_infinity x /\ is_minus_infinity y)164\/ (is_minus_infinity x /\ is_plus_infinity y) }165ensures { is_not_nan x /\ is_not_nan y ->166(is_plus_infinity x /\ not is_minus_infinity y) \/167(is_plus_infinity y /\ not is_minus_infinity x) ->168is_plus_infinity (fp_add m x y) }169ensures { is_not_nan x /\ is_not_nan y ->170(is_minus_infinity x /\ not is_plus_infinity y) \/171(is_minus_infinity y /\ not is_plus_infinity x) ->172is_minus_infinity (fp_add m x y) }173= {proof…}174plus_infinity_unique (plus_infinity (fmt x));175minus_infinity_unique (minus_infinity (fmt x));176if is_not_nan x && is_not_nan y then177round_f_not_nan (fmt x) m (add_zneg m x y) (eadd (ext x) (ext y))178{qed}179
add is increasing in both arguments where it is not NaN
Valid (334ms) (cvc5)let ghost add_box (m: mode) (x1 x2 y1 y2: t) : unit182requires { le_dz x1 x2 /\ le_dz y1 y2 }183requires { is_not_nan (fp_add m x1 y1) /\ is_not_nan (fp_add m x2 y2) }184ensures { le_dz (fp_add m x1 y1) (fp_add m x2 y2) }185= {proof…}186le_not_nan x1 x2; le_not_nan y1 y2;187add_special m x1 y1; add_special m x2 y2;188eadd_le2 (ext x1) (ext x2) (ext y1) (ext y2);189le_positive x1 x2; le_positive y1 y2;190assert { add_zneg m x2 y2 -> add_zneg m x1 y1 }191{qed}192
The sign of the extended real of a float
Valid (523ms) (colibri2)let ghost ext_sign (x: t) : unit197requires { is_not_nan x }198ensures { is_positive x -> ele (Fin 0.0) (ext x) }199ensures { not is_positive x -> ele (ext x) (Fin 0.0) }200ensures { is_zero x <-> ext x = Fin 0.0 }201= {proof…}202of_index_range (fmt x) 0; of_index_range (fmt x) (-1);203let ghost pz = of_index (fmt x) 0 in204let ghost nz = of_index (fmt x) (-1) in205if pure { is_positive x } then assert { le_dz pz x }206else assert { le_dz x nz }207{qed}208
|x1| <= |x2|, both of the sign p (true: positive)
predicate mag_le (p: bool) (x1 x2: t) =211is_not_nan x1 /\ is_not_nan x2 /\212if p then is_positive x1 /\ le_dz x1 x2213else not is_positive x1 /\ le_dz x2 x1214Valid (42ms) (colibri2 10) (split_vc 3) (depth 3)215let ghost mag_le_sign (p: bool) (x1 x2: t) : unit216requires { mag_le p x1 x2 }217ensures { is_positive x1 <-> p }218ensures { is_positive x2 <-> p }219ensures { emag_le p (ext x1) (ext x2) }220= {proof…}221ext_sign x1; ext_sign x2;222if p then le_positive x1 x2223else if pure { is_positive x2 } then le_positive x2 x1224{qed}225
NaN on a NaN or on 0 times an infinity; the signs
Valid (109ms) (cvc4)let ghost mul_special (m: mode) (x y: t) : unit228ensures { is_nan (fp_mul m x y) <-> is_nan x \/ is_nan y229\/ (is_zero x /\ is_infinity y) \/ (is_infinity x /\ is_zero y) }230ensures { is_not_nan x /\ is_not_nan y ->231(is_infinity x /\ not is_zero y) \/ (is_infinity y /\ not is_zero x) ->232fp_mul m x y =233if mul_zneg x y then minus_infinity (fmt x) else plus_infinity (fmt x) }234ensures { is_not_nan x /\ is_not_nan y ->235(is_zero x /\ not is_infinity y) \/ (is_zero y /\ not is_infinity x) ->236is_zero (fp_mul m x y) /\ (is_positive (fp_mul m x y) <-> not mul_zneg x y) }237= {proof…}238plus_infinity_unique (plus_infinity (fmt x));239minus_infinity_unique (minus_infinity (fmt x));240if is_not_nan x && is_not_nan y then begin241ext_sign x; ext_sign y;242round_f_not_nan (fmt x) m (mul_zneg x y) (emul (ext x) (ext y))243end244{qed}245
The product is increasing in the magnitudes, in a quadrant
Valid (421ms) (cvc5)let ghost mul_mag (m: mode) (p q: bool) (x1 x2 y1 y2: t) : unit248requires { mag_le p x1 x2 /\ mag_le q y1 y2 }249requires { is_not_nan (fp_mul m x1 y1) /\ is_not_nan (fp_mul m x2 y2) }250ensures { if p = q then le_dz (fp_mul m x1 y1) (fp_mul m x2 y2)251else le_dz (fp_mul m x2 y2) (fp_mul m x1 y1) }252= {proof…}253mag_le_sign p x1 x2; mag_le_sign q y1 y2;254ext_sign x1; ext_sign x2; ext_sign y1; ext_sign y2;255assert { mul_zneg x1 y1 = mul_zneg x2 y2 };256emul_mag p q (ext x1) (ext x2) (ext y1) (ext y2)257{qed}258
NaN on a NaN, on 0/0 and on inf/inf; the signs
Valid (522ms) (colibri2 7) (cvc4) (cvc5 2) (split_vc) (depth 1)let ghost div_special (m: mode) (x y: t) : unit263ensures { is_nan (fp_div m x y) <-> is_nan x \/ is_nan y264\/ (is_zero x /\ is_zero y) \/ (is_infinity x /\ is_infinity y) }265ensures { is_not_nan x /\ is_not_nan y ->266(is_infinity x /\ not is_infinity y) \/ (is_zero y /\ not is_zero x) ->267fp_div m x y =268if mul_zneg x y then minus_infinity (fmt x) else plus_infinity (fmt x) }269ensures { is_not_nan x /\ is_not_nan y ->270(is_zero x /\ not is_zero y) \/ (is_infinity y /\ not is_infinity x) ->271is_zero (fp_div m x y) /\ (is_positive (fp_div m x y) <-> not mul_zneg x y) }272= {proof…}273plus_infinity_unique (plus_infinity (fmt x));274minus_infinity_unique (minus_infinity (fmt x));275if is_not_nan x && is_not_nan y then begin276ext_sign x; ext_sign y;277round_f_not_nan (fmt x) m (mul_zneg x y) (ediv (ext x) (ext y));278match ext y with279| Fin c -> if pure { c <> 0.0 } then begin280if pure { c >. 0.0 } then assert { 1.0 /. c >. 0.0 }281else assert { 1.0 /. c <. 0.0 }282end283| _ -> ()284end;285match ext x with286| Fin c -> assert { c *. 0.0 = 0.0 }287| _ -> ()288end289end290{qed}291
The quotient is increasing in the magnitude of the dividend and decreasing in the magnitude of the divisor, in a quadrant
Valid (805ms) (cvc5)let ghost div_mag (m: mode) (p q: bool) (x1 x2 y1 y2: t) : unit295requires { mag_le p x1 x2 /\ mag_le q y1 y2 }296requires { is_not_nan (fp_div m x1 y2) /\ is_not_nan (fp_div m x2 y1) }297ensures { if p = q then le_dz (fp_div m x1 y2) (fp_div m x2 y1)298else le_dz (fp_div m x2 y1) (fp_div m x1 y2) }299= {proof…}300mag_le_sign p x1 x2; mag_le_sign q y1 y2;301ext_sign x1; ext_sign x2; ext_sign y1; ext_sign y2;302div_special m x1 y2; div_special m x2 y1;303let ghost r1 = fp_div m x1 y2 in304let ghost r2 = fp_div m x2 y1 in305if is_zero y1 then begin306if pure { p = q } then begin307if pure { r1 <> plus_infinity (fmt x1) } then begin308lt_plus_infinity r1; lt_le r1 r2 end309else le_refl r1310end else begin311if pure { r1 <> minus_infinity (fmt x1) } then begin312minus_infinity_lt r1; lt_le r2 r1 end313else le_refl r1314end315end else begin316assert { mul_zneg x1 y2 = mul_zneg x2 y1 };317einv_mag q (ext y1) (ext y2);318emul_mag p q (ext x1) (ext x2) (einv (ext y2)) (einv (ext y1))319end320{qed}321
Valid (39ms) (colibri2)let ghost sqrt_special (m: mode) (x: t) : unit325ensures { is_nan (fp_sqrt m x) <->326is_nan x \/ (not is_positive x /\ not is_zero x) }327= {proof…}328if is_not_nan x then329round_f_not_nan (fmt x) m (if is_positive x then false else true) (esqrt (ext x))330{qed}331
Increasing where it is not NaN
Valid (47ms) (cvc5)let ghost sqrt_le (m: mode) (x1 x2: t) : unit334requires { le_dz x1 x2 }335requires { is_not_nan (fp_sqrt m x1) /\ is_not_nan (fp_sqrt m x2) }336ensures { le_dz (fp_sqrt m x1) (fp_sqrt m x2) }337= {proof…}338le_not_nan x1 x2; sqrt_special m x1; sqrt_special m x2;339ext_sign x1; ext_sign x2; le_positive x1 x2;340esqrt_le (ext x1) (ext x2)341{qed}342
The square root of a positive float is a positive float
Valid (38ms) (colibri2)let ghost sqrt_positive (m: mode) (x: t) : unit345requires { is_not_nan x /\ is_positive x }346ensures { is_not_nan (fp_sqrt m x) /\ is_positive (fp_sqrt m x) }347= {proof…}348let ghost fm = fmt x in349ext_sign x; sqrt_special m x;350esqrt_le (Fin 0.0) (ext x);351round_f_le fm m false false (Fin 0.0) (esqrt (ext x));352le_positive (round_f fm m false (Fin 0.0)) (fp_sqrt m x)353{qed}354
The positive x whose square root is at least a are above pa * pa rounded down, for a positive pa below a
Valid (1.1s) (cvc5)let ghost sqrt_lower (m: mode) (pa a x: t) : unit358requires { fmt pa = fmt a /\ fmt x = fmt a }359requires { is_not_nan pa /\ is_positive pa /\ lt_dz pa a }360requires { is_not_nan x /\ is_positive x }361requires { le_dz a (fp_sqrt m x) }362ensures { lt_dz (fp_mul rtn pa pa) x }363= {proof…}364let ghost fm = fmt a in365ext_sign pa; ext_sign x;366mul_special rtn pa pa;367let ghost l = fp_mul rtn pa pa in368assert { l = round_f fm rtn false (emul (ext pa) (ext pa)) };369round_f_not_nan fm rtn false (emul (ext pa) (ext pa));370round_f_down fm false (emul (ext pa) (ext pa));371round_f_le fm rtn false false (Fin 0.0) (emul (ext pa) (ext pa));372le_positive (round_f fm rtn false (Fin 0.0)) l;373ext_sign l;374total l x;375if pure { le_dz x l } then begin376le_not_nan a (fp_sqrt m x);377sqrt_special m l;378sqrt_le m x l;379esqrt_le_sq (ext l) (ext pa);380round_f_exact m pa;381round_f_le fm m false false (esqrt (ext l)) (ext pa);382le_trans (fp_sqrt m x) (fp_sqrt m l) pa;383le_lt_trans (fp_sqrt m x) pa a;384lt_not_le (fp_sqrt m x) a;385absurd386end387{qed}388
The positive x whose square root is at most b are below sb * sb rounded up, for a positive sb above b
Valid (268ms) (colibri2 14) (cvc4 3) (cvc5 3) (split_vc) (depth 1)let ghost sqrt_upper (m: mode) (sb b x: t) : unit392requires { fmt sb = fmt b /\ fmt x = fmt b }393requires { is_not_nan sb /\ is_positive sb /\ lt_dz b sb }394requires { is_not_nan x /\ is_positive x }395requires { le_dz (fp_sqrt m x) b }396ensures { lt_dz x (fp_mul rtp sb sb) }397= {proof…}398let ghost fm = fmt b in399ext_sign sb; ext_sign x;400mul_special rtp sb sb;401let ghost u = fp_mul rtp sb sb in402assert { u = round_f fm rtp false (emul (ext sb) (ext sb)) };403round_f_not_nan fm rtp false (emul (ext sb) (ext sb));404round_f_up fm false (emul (ext sb) (ext sb));405round_f_le fm rtp false false (Fin 0.0) (emul (ext sb) (ext sb));406le_positive (round_f fm rtp false (Fin 0.0)) u;407ext_sign u;408total x u;409if pure { le_dz u x } then begin410le_not_nan (fp_sqrt m x) b;411sqrt_special m u;412sqrt_le m u x;413esqrt_ge_sq (ext u) (ext sb);414round_f_exact m sb;415round_f_le fm m false false (ext sb) (esqrt (ext u));416le_trans sb (fp_sqrt m u) (fp_sqrt m x);417lt_le_trans b sb (fp_sqrt m x);418lt_not_le b (fp_sqrt m x);419absurd420end421{qed}422
The product is commutative
Valid (47ms) (cvc5)let ghost mul_comm (m: mode) (x y: t) : unit425requires { fmt x = fmt y }426ensures { fp_mul m x y = fp_mul m y x }427= {proof…}428assert { mul_zneg x y = mul_zneg y x };429assert { emul (ext x) (ext y) = emul (ext y) (ext x) }430{qed}431
The format of a product and of a quotient is the one of the first argument
Valid (44ms) (cvc5)let ghost mul_div_fmt (m: mode) (x y: t) : unit435ensures { fmt (fp_mul m x y) = fmt x /\ fmt (fp_div m x y) = fmt x }436= {proof…}437round_f_not_nan (fmt x) m (mul_zneg x y) (emul (ext x) (ext y));438round_f_not_nan (fmt x) m (mul_zneg x y) (ediv (ext x) (ext y))439{qed}440
Valid (18ms) (colibri2)let ghost convert_not_nan (fm: format) (m: mode) (x: t) : unit444requires { is_not_nan x }445ensures { is_not_nan (fp_convert fm m x) /\ fmt (fp_convert fm m x) = fm }446= {proof…}447round_f_not_nan fm m (if is_positive x then false else true) (ext x)448{qed}449
Valid (20ms) (colibri2)let ghost rti_not_nan (m: mode) (x: t) : unit453requires { is_not_nan x }454ensures { is_not_nan (fp_rti m x) /\ fmt (fp_rti m x) = fmt x }455= {proof…}456round_f_not_nan (fmt x) m (if is_positive x then false else true)457(eround_int m (ext x))458{qed}459
Increasing
Valid (363ms) (cvc5)let ghost rti_le (m: mode) (x1 x2: t) : unit462requires { le_dz x1 x2 }463ensures { le_dz (fp_rti m x1) (fp_rti m x2) }464= {proof…}465le_not_nan x1 x2; le_positive x1 x2;466assert { ele (eround_int m (ext x1)) (eround_int m (ext x2)) }467{qed}468
Increasing
Valid (58ms) (colibri2)let ghost convert_le (fm: format) (m: mode) (x1 x2: t) : unit471requires { le_dz x1 x2 }472ensures { le_dz (fp_convert fm m x1) (fp_convert fm m x2) }473= {proof…}474le_not_nan x1 x2; le_positive x1 x2475{qed}476
Valid (44ms) (cvc4)let ghost add_comm (m: mode) (x y: t) : unit480requires { fmt x = fmt y }481ensures { fp_add m x y = fp_add m y x }482= {proof…}483assert { opposite (ext x) (ext y) <-> opposite (ext y) (ext x) };484assert { add_zneg m x y = add_zneg m y x };485assert { eadd (ext x) (ext y) = eadd (ext y) (ext x) }486{qed}487
Adding –inf (resp. +inf) gives –inf (resp. +inf), or NaN
Valid (45ms) (cvc4)let ghost add_minus_infinity (m: mode) (x y: t) : unit490requires { fmt x = fmt y /\ is_minus_infinity y /\ is_not_nan x /\ not is_plus_infinity x }491ensures { fp_add m x y = minus_infinity (fmt x) }492= {proof…}493assert { ext y = MInf };494assert { eadd (ext x) MInf = MInf };495add_special m x y496{qed}497Valid (266ms) (cvc4)498let ghost add_plus_infinity (m: mode) (x y: t) : unit499requires { fmt x = fmt y /\ is_plus_infinity y /\ is_not_nan x /\ not is_minus_infinity x }500ensures { fp_add m x y = plus_infinity (fmt x) }501= {proof…}502assert { ext y = PInf };503assert { eadd (ext x) PInf = PInf };504add_special m x y505{qed}506
The x such that x + y is at least a for some y <= d, d finite, are above pa - d rounded down, where pa is below a and not –0
Valid (246ms) (colibri2 15) (cvc4 2) (cvc5 2) (split_vc) (depth 1)let ghost add_lower (m: mode) (pa a d x y: t) : unit511requires { fmt pa = fmt a /\ fmt d = fmt a /\ fmt x = fmt a /\ fmt y = fmt a }512requires { is_not_nan pa /\ lt_dz pa a /\ (is_zero pa -> is_positive pa) }513requires { is_not_nan d /\ not is_infinity d }514requires { le_dz y d /\ is_not_nan x }515requires { le_dz a (fp_add m x y) }516ensures { lt_dz (fp_add rtn pa (neg d)) x }517= {proof…}518let ghost fm = fmt a in519let ghost nd = neg d in520assert { is_not_nan nd /\ fmt nd = fm };521let ghost v = match ext d with Fin v -> v | _ -> absurd end in522assert { ext d = Fin v /\ ext nd = Fin (-. v) };523add_special rtn pa nd;524let ghost l = fp_add rtn pa nd in525assert { l = round_f fm rtn (add_zneg rtn pa nd) (eadd (ext pa) (Fin (-. v))) };526assert { ele (ext l) (eadd (ext pa) (Fin (-. v))) };527round_f_not_nan fm rtn (add_zneg rtn pa nd) (eadd (ext pa) (Fin (-. v)));528total l x;529if pure { le_dz x l } then begin530le_not_nan a (fp_add m x y);531add_special m l d;532add_box m x l y d;533eadd_sub_le (ext l) (ext pa) v;534let ghost zpa = if is_positive pa then false else true in535assert { round_f fm m zpa (ext pa) = pa };536round_f_le fm m (add_zneg m l d) zpa (eadd (ext l) (Fin v)) (ext pa);537assert { fp_add m l d = round_f fm m (add_zneg m l d) (eadd (ext l) (Fin v)) };538le_trans (fp_add m x y) (fp_add m l d) pa;539le_lt_trans (fp_add m x y) pa a;540lt_not_le (fp_add m x y) a;541absurd542end543{qed}544Valid (286ms) (colibri2 14) (cvc4) (cvc5 4) (split_vc) (depth 1)545let ghost add_upper (m: mode) (sb b c x y: t) : unit546requires { fmt sb = fmt b /\ fmt c = fmt b /\ fmt x = fmt b /\ fmt y = fmt b }547requires { is_not_nan sb /\ lt_dz b sb /\ (is_zero sb -> not is_positive sb) }548requires { is_not_nan c /\ not is_infinity c }549requires { le_dz c y /\ is_not_nan x }550requires { le_dz (fp_add m x y) b }551ensures { lt_dz x (fp_add rtp sb (neg c)) }552= {proof…}553let ghost fm = fmt b in554let ghost nc = neg c in555assert { is_not_nan nc /\ fmt nc = fm };556let ghost v = match ext c with Fin v -> v | _ -> absurd end in557assert { ext c = Fin v /\ ext nc = Fin (-. v) };558add_special rtp sb nc;559let ghost u = fp_add rtp sb nc in560assert { u = round_f fm rtp (add_zneg rtp sb nc) (eadd (ext sb) (Fin (-. v))) };561assert { ele (eadd (ext sb) (Fin (-. v))) (ext u) };562round_f_not_nan fm rtp (add_zneg rtp sb nc) (eadd (ext sb) (Fin (-. v)));563total x u;564if pure { le_dz u x } then begin565le_not_nan (fp_add m x y) b;566add_special m u c;567add_box m u x c y;568eadd_sub_ge (ext u) (ext sb) v;569let ghost zsb = if is_positive sb then false else true in570assert { round_f fm m zsb (ext sb) = sb };571round_f_le fm m zsb (add_zneg m u c) (ext sb) (eadd (ext u) (Fin v));572assert { fp_add m u c = round_f fm m (add_zneg m u c) (eadd (ext u) (Fin v)) };573le_trans sb (fp_add m u c) (fp_add m x y);574lt_le_trans b sb (fp_add m x y);575lt_not_le b (fp_add m x y);576absurd577end578{qed}579
A float converted to its own format
Valid (15ms) (colibri2)let ghost convert_exact (m: mode) (x: t) : unit582requires { is_not_nan x }583ensures { fp_convert (fmt x) m x = x }584= ()585
The conversion down to fm of a float p of another format is below p: converted back, it is below p
Valid (41ms) (colibri2)let ghost convert_down_back (fm: format) (m: mode) (p: t) : unit589requires { is_not_nan p }590ensures { le_dz (fp_convert (fmt p) m (fp_convert fm rtn p)) p }591= {proof…}592let ghost zp = if is_positive p then false else true in593let ghost l = fp_convert fm rtn p in594convert_not_nan fm rtn p;595assert { l = round_f fm rtn zp (ext p) };596assert { ele (ext l) (ext p) };597let ghost zl = if is_positive l then false else true in598let ghost cl = fp_convert (fmt p) m l in599assert { cl = round_f (fmt p) m zl (ext l) };600ext_sign p; ext_sign l;601if pure { zp /\ is_positive l } then begin602assert { ele (ext l) (Fin 0.0) };603assert { is_zero l };604absurd605end;606assert { round_f (fmt p) m zp (ext p) = p };607round_f_le (fmt p) m zl zp (ext l) (ext p)608{qed}609Valid (35ms) (colibri2)610let ghost convert_up_back (fm: format) (m: mode) (p: t) : unit611requires { is_not_nan p }612ensures { le_dz p (fp_convert (fmt p) m (fp_convert fm rtp p)) }613= {proof…}614let ghost zp = if is_positive p then false else true in615let ghost u = fp_convert fm rtp p in616convert_not_nan fm rtp p;617assert { u = round_f fm rtp zp (ext p) };618assert { ele (ext p) (ext u) };619let ghost zu = if is_positive u then false else true in620let ghost cu = fp_convert (fmt p) m u in621assert { cu = round_f (fmt p) m zu (ext u) };622ext_sign p; ext_sign u;623if pure { zu /\ is_positive p } then begin624assert { ele (Fin 0.0) (ext u) };625assert { is_zero u };626absurd627end;628assert { round_f (fmt p) m zp (ext p) = p };629round_f_le (fmt p) m zp zu (ext p) (ext u)630{qed}631
The x of the format fm whose conversion to the format of a is at least a are above the conversion down of the predecessor of a
Valid (281ms) (cvc5)let ghost convert_lower (fm: format) (m: mode) (a x: t) : unit635requires { is_not_nan a /\ not is_minus_infinity a }636requires { fmt x = fm /\ is_not_nan x }637requires { le_dz a (fp_convert (fmt a) m x) }638ensures { lt_dz (fp_convert fm rtn (pred_dz a)) x }639= {proof…}640let ghost pa = pred_dz a in641pred_lt a;642let ghost l = fp_convert fm rtn pa in643convert_not_nan fm rtn pa;644total l x;645if pure { le_dz x l } then begin646convert_le (fmt a) m x l;647convert_down_back fm m pa;648le_trans (fp_convert (fmt a) m x) (fp_convert (fmt a) m l) pa;649le_lt_trans (fp_convert (fmt a) m x) pa a;650lt_not_le (fp_convert (fmt a) m x) a;651absurd652end653{qed}654Valid (37ms) (cvc5)655let ghost convert_upper (fm: format) (m: mode) (b x: t) : unit656requires { is_not_nan b /\ not is_plus_infinity b }657requires { fmt x = fm /\ is_not_nan x }658requires { le_dz (fp_convert (fmt b) m x) b }659ensures { lt_dz x (fp_convert fm rtp (succ_dz b)) }660= {proof…}661let ghost sb = succ_dz b in662succ_gt b;663let ghost u = fp_convert fm rtp sb in664convert_not_nan fm rtp sb;665total x u;666if pure { le_dz u x } then begin667convert_le (fmt b) m u x;668convert_up_back fm m sb;669le_trans sb (fp_convert (fmt b) m u) (fp_convert (fmt b) m x);670lt_le_trans b sb (fp_convert (fmt b) m x);671lt_not_le b (fp_convert (fmt b) m x);672absurd673end674{qed}675
Valid (149ms) (colibri2 2) (cvc5) (split_vc) (depth 1)let ghost widen_nb_sign (fm fm': format) : unit679requires { widens fm fm' }680ensures { nb_sign fm' = 2 * nb_sign fm - 1 }681= {proof…}682assert { power 2 (sb fm' - 1) = 2 * power 2 (sb fm - 1)683by sb fm' - 1 = (sb fm - 1) + 1 /\ 0 <= sb fm - 1684so power 2 ((sb fm - 1) + 1) = power 2 (sb fm - 1) * power 2 1 };685let ghost q = power 2 (sb fm - 1) in686let ghost e = power 2 (eb fm) - 1 in687assert { nb_sign fm = e * q + 1 /\ nb_sign fm' = e * (2 * q) + 1 }688{qed}689
The conversion to the format with one more bit is exact, at windex
Valid (207ms) (colibri2)let ghost convert_widen (fm': format) (m: mode) (x: t) : unit693requires { widens (fmt x) fm' /\ is_not_nan x }694ensures { - nb_sign fm' <= windex (index x) < nb_sign fm' }695ensures { fp_convert fm' m x = of_index fm' (windex (index x)) }696ensures { ext (fp_convert fm' m x) = ext x }697= {proof…}698let ghost fm = fmt x in699let ghost i = index x in700index_range x; widen_nb_sign fm fm';701of_index_range fm' (windex i);702let ghost y = of_index fm' (windex i) in703assert { ext y = ext x by ext y = ext (of_index fm i) /\ of_index fm i = x };704assert { is_positive y <-> is_positive x };705assert { round_f fm' m (if is_positive y then false else true) (ext y) = y }706{qed}707
The value of the rounding does not depend on the sign of zero
Valid (347ms) (cvc5)let ghost round_f_val (fm: format) (m: mode) (z1 z2: bool) (e: ereal) : unit710ensures { ext (round_f fm m z1 e) = ext (round_f fm m z2 e) }711= {proof…}712let ghost r1 = round_f fm m z1 e in713let ghost r2 = round_f fm m z2 e in714if pure { is_zero r1 /\ is_zero r2 } then715assert { ext r1 = Fin 0.0 /\ ext r2 = Fin 0.0 }716else begin717assert { le_dz r1 r2 /\ le_dz r2 r1 };718assert { ele (ext r1) (ext r2) /\ ele (ext r2) (ext r1) }719end720{qed}721
Increasing in value
Valid (148ms) (cvc5)let ghost round_f_ele (fm: format) (m: mode) (z1 z2: bool) (e1 e2: ereal) : unit724requires { ele e1 e2 }725ensures { ele (ext (round_f fm m z1 e1)) (ext (round_f fm m z2 e2)) }726= {proof…}727assert { le_dz (round_f fm m z1 e1) (round_f fm m z1 e2) };728round_f_val fm m z1 z2 e2729{qed}730
The order of the values is the order of the floats, but –0 and +0
Valid (166ms) (colibri2)let ghost ele_le (x y: t) : unit733requires { fmt x = fmt y /\ is_not_nan x /\ is_not_nan y /\ ele (ext x) (ext y) }734requires { is_zero x /\ is_zero y -> is_positive x -> is_positive y }735ensures { le_dz x y }736= {proof…}737total x y;738if pure { lt_dz y x } then begin739if pure { is_zero x /\ is_zero y } then begin740index_range x; index_range y; absurd741end;742absurd743end744{qed}745end746