library colibrilib.fp_interval — module FpIntervalmodule FpInterval522use int.Int523use mach.int.Int63524use int.Power525use list.List526use option.Option527use real.RealInfix528use real.FromInt529use colibrilib.fp.Ereal530use colibrilib.fbin.Fp531use colibrilib.fp_facts.Facts532use Intervals533
NaN or a union of intervals; fp_interval.ml never returns the empty domain
Valid (23ms) (colibri2)type dom = { u: list (t, t); nan: bool; ghost fm: format }537invariant { ok_u u /\ fmt_u fm u }538by { u = Nil; nan = true; fm = any format }539
The floats of the format d.fm in d
predicate mem (v: t) (d: dom) =542fmt v = d.fm /\ if is_nan v then d.nan else mem_u v d.u543544predicate is_bot (d: dom) = d.u = Nil /\ not d.nan545Valid (322ms) (colibri2)546let union (ghost fm: format) (d1 d2: dom) : dom547requires { d1.fm = fm /\ d2.fm = fm }548ensures { result.fm = fm }549ensures { forall v. mem v result <-> mem v d1 \/ mem v d2 }550= { u = union_u fm d1.u d2.u; nan = d1.nan || d2.nan; fm = fm }551Valid (302ms) (cvc5)552let inter (ghost fm: format) (d1 d2: dom) : option dom553requires { d1.fm = fm /\ d2.fm = fm }554ensures { match result with Some r -> r.fm = fm | None -> true end }555ensures { match result with556| None -> forall v. not (mem v d1 /\ mem v d2)557| Some d -> not (is_bot d) /\ forall v. mem v d <-> mem v d1 /\ mem v d2558end }559= let u = inter_u fm d1.u d2.u in560let nan = d1.nan && d2.nan in561match u with562| Nil -> if nan then Some { u = u; nan = nan; fm = fm } else None563| _ -> Some { u = u; nan = nan; fm = fm }564end565Valid (71ms) (colibri2 12) (split_vc 8) (depth 4)566let is_distinct (ghost fm: format) (d1 d2: dom) : bool567requires { d1.fm = fm /\ d2.fm = fm }568ensures { result <-> forall v. not (mem v d1 /\ mem v d2) }569= let r = (not d1.nan || not d2.nan) && is_distinct_u fm d1.u d2.u in570{proof…}571assert { d1.nan /\ d2.nan -> mem (not_a_number fm) d1 /\ mem (not_a_number fm) d2 };572let lemma pt (v: t) : unit573requires { mem_u v d1.u /\ mem_u v d2.u }574ensures { mem v d1 /\ mem v d2 }575= mem_u_not_nan v d1.u in576{qed}577r578Valid (340ms) (cvc5)579let diff (ghost fm: format) (d1 d2: dom) : option dom580requires { d1.fm = fm /\ d2.fm = fm }581ensures { match result with Some r -> r.fm = fm | None -> true end }582ensures { match result with583| None -> forall v. not (mem v d1 /\ not mem v d2)584| Some d -> not (is_bot d) /\ forall v. mem v d <-> mem v d1 /\ not mem v d2585end }586= let l = diff_u fm d1.u d2.u in587let nan = d1.nan && not d2.nan in588{proof…}589let lemma pt (v: t) : unit590requires { mem_u v d1.u \/ mem_u v l }591ensures { not is_nan v }592= if pure { mem_u v d1.u } then mem_u_not_nan v d1.u593else mem_u_not_nan v l in594{qed}595match l with596| Nil -> if nan then Some { u = l; nan = nan; fm = fm } else None597| _ -> Some { u = l; nan = nan; fm = fm }598end599Valid (57ms) (colibri2 11) (split_vc 6) (depth 4)600let is_included (ghost fm: format) (d1 d2: dom) : bool601requires { d1.fm = fm /\ d2.fm = fm }602ensures { result <-> forall v. mem v d1 -> mem v d2 }603= let r = (not d1.nan || d2.nan) && is_included_u fm d1.u d2.u in604{proof…}605assert { d1.nan /\ not d2.nan -> mem (not_a_number fm) d1 /\ not mem (not_a_number fm) d2 };606let lemma pt (v: t) : unit607requires { mem_u v d1.u }608ensures { mem v d1 /\ (mem v d2 <-> mem_u v d2.u) }609= mem_u_not_nan v d1.u in610{qed}611r612
Exact: Included when included (also for the empty domain, which fp_interval.ml never passes), else Disjoint when disjoint, else Uncomparable
Valid (517ms) (colibri2 13) (cvc5 2) (split_vc 3) (depth 2)let is_distinct_or_included (ghost fm: format) (d1 d2: dom) : comparison617requires { d1.fm = fm /\ d2.fm = fm }618ensures { result = Included <-> forall v. mem v d1 -> mem v d2 }619ensures { result = Disjoint <->620(forall v. not (mem v d1 /\ mem v d2)) /\621not (forall v. mem v d1 -> mem v d2) }622= {proof…}623let lemma pt (v: t) : unit624requires { mem_u v d1.u }625ensures { mem v d1 /\ (mem v d2 <-> mem_u v d2.u) }626= mem_u_not_nan v d1.u in627assert { d1.nan -> mem (not_a_number fm) d1 /\ (mem (not_a_number fm) d2 <-> d2.nan) };628assert { forall v. is_nan v -> fmt v = fm ->629(mem v d1 <-> d1.nan) /\ (mem v d2 <-> d2.nan) };630{qed}631if d1.nan then632if d2.nan then (if is_included_u fm d1.u d2.u then Included else Uncomparable)633else (if is_distinct_u fm d1.u d2.u then Disjoint else Uncomparable)634else match d1.u with635| Nil -> Included636| Cons _ _ -> {proof…} head_mem d1.u; {qed} is_distinct_or_included_u fm d1.u d2.u637end638639type singleton = NaN | No | Sin t640
Exact: NaN when the domain is the NaNs, Sin a when it is {a}, No otherwise. F.equal a b of the OCaml is le_diff_zero b a here (a <= b is known).
Valid (321ms) (colibri2 18) (cvc5) (split_vc 4) (depth 2)let is_singleton (ghost fm: format) (d: dom) : singleton645requires { d.fm = fm }646ensures { match result with647| NaN -> forall v. mem v d <-> fmt v = fm /\ is_nan v648| Sin a -> not (is_nan a) /\ forall v. mem v d <-> v = a649| No -> not (forall v. mem v d <-> fmt v = fm /\ is_nan v) /\650forall a. not (forall v. mem v d <-> v = a)651end }652= {proof…}653assert { forall v. is_nan v -> fmt v = fm -> (mem v d <-> d.nan) };654let lemma pt (v: t) : unit655requires { mem_u v d.u }656ensures { mem v d }657= mem_u_not_nan v d.u in658{qed}659match d.u with660| Nil ->661if d.nan then NaN662else begin663{proof…} assert { not mem (not_a_number fm) d };664assert { forall v. not mem v d };665let lemma no_sin (a: t) : unit666ensures { not (forall v. mem v d <-> v = a) }667= assert { not mem a d } in {qed}668No669end670| Cons (a, b) r ->671{proof…} head_mem d.u; le_not_nan_any a b; le_refl_any b;672assert { mem a d /\ mem b d }; {qed}673if d.nan then begin674{proof…} assert { mem (not_a_number fm) d }; {qed}675No676end else match r with677| Nil ->678if le_diff_zero b a then begin679{proof…}680let lemma pt2 (v: t) : unit681requires { in_iv v a b } ensures { v = a }682= le_not_nan_any a v; le_trans_any v b a;683assert { index v = index a } in684{qed}685Sin a686end else begin687{proof…} total b a; assert { a <> b by index a < index b }; {qed}688No689end690| Cons (a', _) _ ->691{proof…} head_mem r; assert { mem a' d };692lt_le_trans_any b a' a'; le_lt_trans_any a b a';693assert { a <> a' by index a < index a' }; {qed}694No695end696end697698exception Empty699
The least float that is not NaN
Valid (20ms) (colibri2)let min_f (ghost fm: format) (d: dom) : t702requires { d.fm = fm }703ensures { fmt result = fm }704raises { Empty -> d.u = Nil }705ensures { mem_u result d.u /\ forall v. mem_u v d.u -> le_dz result v }706= match d.u with707| Nil -> raise Empty708| Cons (a, b) r ->709{proof…} head_mem d.u;710(match r with Nil -> () | Cons _ _ -> sorted_above b r end);711let lemma pt (v: t) : unit712requires { mem_u v d.u } ensures { le_dz a v }713= if pure { mem_u v r } then begin714le_lt_trans_any a b v; lt_le_any a v715end in716{qed}717a718end719
The last interval of a list
Valid (58ms) (colibri2)let rec last_iv (ghost fm: format) (l: list (t, t)) : (t, t)722requires { fmt_u fm l }723requires { ok_u l /\ l <> Nil }724ensures { let (a, b) = result in in_iv b a b /\ mem_u b l }725ensures { let (_, b) = result in forall v. mem_u v l -> le_dz v b }726variant { l }727= match l with728| Nil -> absurd729| Cons (a, b) Nil -> {proof…} le_not_nan_any a b; le_refl_any b; {qed} (a, b)730| Cons (_, b) r ->731let res = last_iv fm r in732{proof…} sorted_above b r;733let (_, b') = res in734let lemma pt (v: t) : unit735requires { mem_u v l } ensures { le_dz v b' }736= if pure { mem_u v r } then () else begin737lt_le_any b b'; le_trans_any v b b' end in738{qed}739res740end741
The greatest float that is not NaN
Valid (132ms) (colibri2)let max_f (ghost fm: format) (d: dom) : t744requires { d.fm = fm }745ensures { fmt result = fm }746raises { Empty -> d.u = Nil }747ensures { mem_u result d.u /\ forall v. mem_u v d.u -> le_dz v result }748= match d.u with749| Nil -> raise Empty750| Cons _ _ -> let (_, b) = last_iv fm d.u in b751end752
All the floats; minf and pinf are the infinities of the format
Valid (46ms) (colibri2 16) (split_vc 2) (depth 2)let top (ghost fm: format) (minf pinf: t) : dom755requires { fmt minf = fm /\ fmt pinf = fm }756ensures { result.fm = fm }757requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }758ensures { forall v. fmt v = fm -> mem v result }759= {proof…}760minus_infinity_lt pinf;761let lemma pt (v: t) : unit762requires { is_not_nan v /\ fmt v = fm } ensures { in_iv v minf pinf }763= if pure { is_plus_infinity v } then le_refl v764else begin lt_plus_infinity v; lt_le v pinf end;765if pure { is_minus_infinity v } then le_refl v766else begin minus_infinity_lt v; lt_le minf v end in767lt_le minf pinf;768{qed}769{ u = Cons (minf, pinf) Nil; nan = true; fm = fm }770Valid (292ms) (colibri2)771let complement (ghost fm: format) (minf pinf: t) (d: dom) : option dom772requires { fmt minf = fm /\ fmt pinf = fm /\ d.fm = fm }773ensures { match result with Some r -> r.fm = fm | None -> true end }774requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }775ensures { match result with776| None -> forall v. fmt v = fm -> mem v d777| Some c -> not (is_bot c) /\ forall v. mem v c <-> fmt v = fm /\ not mem v d778end }779= diff fm (top fm minf pinf) d780
All the floats but f (but the NaNs when f is NaN)
Valid (1.5s) (colibri2 37) (cvc4 5) (cvc5 4) (split_vc) (depth 1)let except (ghost fm: format) (minf pinf: t) (f: t) : dom783requires { fmt minf = fm /\ fmt pinf = fm /\ fmt f = fm }784ensures { result.fm = fm }785requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }786ensures { forall v. mem v result <->787fmt v = fm /\ if is_nan f then not (is_nan v) else v <> f }788= {proof…}789let ghost all = top fm minf pinf in790minus_infinity_lt pinf; lt_le minf pinf;791{qed}792if is_nan f then { u = Cons (minf, pinf) Nil; nan = false; fm = fm }793else if le_diff_zero f minf then begin794{proof…}795assert { f = minf by index f <= index minf796so (is_minus_infinity f \/ lt_dz minf f) };797succ_gt f; succ_least f pinf;798let lemma pt (v: t) : unit799requires { is_not_nan v /\ fmt v = fm } ensures { v <> f <-> in_iv v (succ_dz f) pinf }800= assert { mem v all };801if pure { v <> f } then begin802assert { lt_dz f v by index f < index v803so index f <= index v /\ index f <> index v };804succ_least f v end805else lt_le_trans f (succ_dz f) pinf;806if pure { in_iv v (succ_dz f) pinf } then lt_le_trans f (succ_dz f) v in807{qed}808{ u = Cons (succ_diff_zero f, pinf) Nil; nan = true; fm = fm }809end else if le_diff_zero pinf f then begin810{proof…}811total minf f;812assert { f = pinf by index pinf <= index f813so (is_plus_infinity f \/ lt_dz f pinf) };814pred_lt f; pred_greatest f minf;815let lemma pt (v: t) : unit816requires { is_not_nan v /\ fmt v = fm } ensures { v <> f <-> in_iv v minf (pred_dz f) }817= assert { mem v all };818if pure { v <> f } then begin819assert { lt_dz v f by index v < index f820so index v <= index f /\ index f <> index v };821pred_greatest f v end;822if pure { in_iv v minf (pred_dz f) } then le_lt_trans v (pred_dz f) f in823{qed}824{ u = Cons (minf, pred_diff_zero f) Nil; nan = true; fm = fm }825end else begin826{proof…}827total minf f; total f pinf;828succ_gt f; succ_least f pinf; pred_lt f; pred_greatest f minf;829lt_le_trans (pred_dz f) f (succ_dz f);830let lemma pt (v: t) : unit831requires { is_not_nan v /\ fmt v = fm }832ensures { v <> f <-> in_iv v minf (pred_dz f) \/ in_iv v (succ_dz f) pinf }833= assert { mem v all };834total_any v f;835if pure { lt_dz v f } then pred_greatest f v;836if pure { lt_dz f v } then succ_least f v;837if pure { in_iv v minf (pred_dz f) } then le_lt_trans v (pred_dz f) f;838if pure { in_iv v (succ_dz f) pinf } then lt_le_trans f (succ_dz f) v in839{qed}840{ u = Cons (minf, pred_diff_zero f) (Cons (succ_diff_zero f, pinf) Nil);841nan = true; fm = fm }842end843
The first float of a list is its least
Valid (17ms) (colibri2)let ghost head_min (fm: format) (l: list (t, t)) : unit846requires { fmt_u fm l }847requires { ok_u l }848ensures { match l with Nil -> true849| Cons (a, _) _ -> forall v. mem_u v l -> le_dz a v end }850= {proof…} match l with851| Nil -> ()852| Cons (a, b) r ->853(match r with Nil -> () | Cons _ _ -> sorted_above b r end);854let lemma pt (v: t) : unit855requires { mem_u v l } ensures { le_dz a v }856= if pure { mem_u v r } then begin857le_lt_trans_any a b v; lt_le_any a v858end in859()860end {qed}861862predicate is_inf (v: t) = is_plus_infinity v \/ is_minus_infinity v863
No NaN and no infinity
Valid (595ms) (colibri2 11) (cvc4) (split_vc 4) (depth 4)let is_finite (ghost fm: format) (minf pinf: t) (d: dom) : bool866requires { fmt minf = fm /\ fmt pinf = fm /\ d.fm = fm }867requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }868ensures { result <-> forall v. mem v d -> not (is_nan v) /\ not (is_inf v) }869= {proof…}870assert { d.nan -> mem (not_a_number fm) d };871let lemma pt (v: t) : unit872requires { mem_u v d.u } ensures { mem v d }873= mem_u_not_nan v d.u in874{qed}875if d.nan then false876else match d.u with877| Nil -> true878| Cons (a, _) _ ->879let (_, b) = last_iv fm d.u in880{proof…} head_min fm d.u; {qed}881not (le_diff_zero a minf) && not (le_diff_zero pinf b)882end883
An infinity is in the domain
Valid (743ms) (cvc4)let has_infinites (ghost fm: format) (minf pinf: t) (d: dom) : bool886requires { fmt minf = fm /\ fmt pinf = fm /\ d.fm = fm }887requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }888ensures { result <-> exists v. mem v d /\ is_inf v }889= match d.u with890| Nil -> false891| Cons (a, _) _ ->892let (_, b) = last_iv fm d.u in893{proof…} head_min fm d.u; head_mem d.u;894let lemma pt (v: t) : unit895requires { mem_u v d.u } ensures { mem v d }896= mem_u_not_nan v d.u in897{qed}898le_diff_zero a minf || le_diff_zero pinf b899end900
The bounds are the special values of the format (Farith's get_special_values), given with their index.
predicate at_index (fm: format) (x: t) (i: int) =907fmt x = fm /\ is_not_nan x /\ index x = i908
Facts on the format used for the bounds
Valid (30ms) (colibri2 7) (split_vc) (depth 1)let ghost format_facts (fm: format) () : unit911ensures { 2 <= power 2 ((sb fm) - 1) }912ensures { 3 * power 2 ((sb fm) - 1) + 1 <= (nb_sign fm) }913= {proof…}914assert { power 2 ((sb fm) - 1) = 2 * power 2 ((sb fm) - 2) };915assert { power 2 (eb fm) = 2 * power 2 ((eb fm) - 1) /\ power 2 ((eb fm) - 1) >= 2 };916assert { 2 <= power 2 ((sb fm) - 1) };917assert { power 2 (eb fm) - 1 >= 3 };918assert { (power 2 (eb fm) - 1) * power 2 ((sb fm) - 1) >= 3 * power 2 ((sb fm) - 1) }919{qed}920
Two intervals, one of each sign
Valid (30ms) (colibri2)let two (ghost fm: format) (a b c d: t) : dom923requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }924ensures { result.fm = fm }925requires { is_not_nan a /\ is_not_nan b /\ is_not_nan c /\ is_not_nan d }926requires { index a <= index b < index c <= index d }927ensures { forall v. mem v result <->928fmt v = fm /\ is_not_nan v /\ (index a <= index v <= index b \/ index c <= index v <= index d) }929= { u = Cons (a, b) (Cons (c, d) Nil); nan = false; fm = fm }930
One interval
Valid (17ms) (colibri2)let one (ghost fm: format) (a b: t) : dom933requires { fmt a = fm /\ fmt b = fm }934ensures { result.fm = fm }935requires { is_not_nan a /\ is_not_nan b /\ index a <= index b }936ensures { forall v. mem v result <->937fmt v = fm /\ is_not_nan v /\ index a <= index v <= index b }938= { u = Cons (a, b) Nil; nan = false; fm = fm }939Valid (549ms) (cvc4)940let normal (ghost fm: format) (nl nf pf pl: t) : dom941requires { fmt nl = fm /\ fmt nf = fm /\ fmt pf = fm /\ fmt pl = fm }942ensures { result.fm = fm }943requires { at_index fm nl (1 - (nb_sign fm)) /\ at_index fm nf (-1 - power 2 ((sb fm) - 1)) }944requires { at_index fm pf (power 2 ((sb fm) - 1)) /\ at_index fm pl ((nb_sign fm) - 2) }945ensures { forall v. mem v result <-> fmt v = fm /\ is_normal v }946= {proof…} format_facts fm (); {qed}947two fm nl nf pf pl948Valid (561ms) (cvc4)949let subnormal (ghost fm: format) (nl nf pf pl: t) : dom950requires { fmt nl = fm /\ fmt nf = fm /\ fmt pf = fm /\ fmt pl = fm }951ensures { result.fm = fm }952requires { at_index fm nl (- power 2 ((sb fm) - 1)) /\ at_index fm nf (-2) }953requires { at_index fm pf 1 /\ at_index fm pl (power 2 ((sb fm) - 1) - 1) }954ensures { forall v. mem v result <-> fmt v = fm /\ is_subnormal v }955= {proof…} format_facts fm (); {qed}956two fm nl nf pf pl957Valid (25ms) (colibri2)958let zeros (ghost fm: format) (nz pz: t) : dom959requires { fmt nz = fm /\ fmt pz = fm }960ensures { result.fm = fm }961requires { at_index fm nz (-1) /\ at_index fm pz 0 }962ensures { forall v. mem v result <-> fmt v = fm /\ is_zero v }963= one fm nz pz964Valid (533ms) (cvc5)965let infinites (ghost fm: format) (minf pinf: t) : dom966requires { fmt minf = fm /\ fmt pinf = fm }967ensures { result.fm = fm }968requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }969ensures { forall v. mem v result <-> fmt v = fm /\ is_inf v }970= {proof…} format_facts fm (); {qed}971two fm minf minf pinf pinf972
Neither NaN nor infinite
Valid (54ms) (colibri2 8) (split_vc 2) (depth 2)let finites (ghost fm: format) (nl pl: t) : dom975requires { fmt nl = fm /\ fmt pl = fm }976ensures { result.fm = fm }977requires { at_index fm nl (1 - (nb_sign fm)) /\ at_index fm pl ((nb_sign fm) - 2) }978ensures { forall v. mem v result <-> fmt v = fm /\ is_not_nan v /\ not (is_inf v) }979= {proof…} format_facts fm ();980let lemma pt (v: t) : unit981requires { fmt v = fm /\ is_not_nan v }982ensures { is_inf v <-> index v = - nb_sign fm \/ index v = nb_sign fm - 1 }983ensures { - nb_sign fm <= index v < nb_sign fm }984= index_range v in985{qed}986one fm nl pl987Valid (664ms) (cvc4)988let negatives (ghost fm: format) (minf nz: t) : dom989requires { fmt minf = fm /\ fmt nz = fm }990ensures { result.fm = fm }991requires { minf = (minus_infinity fm) /\ at_index fm nz (-1) }992ensures { forall v. mem v result <-> fmt v = fm /\ is_not_nan v /\ not (is_positive v) }993= {proof…} format_facts fm (); {qed}994one fm minf nz995Valid (499ms) (cvc5)996let positives (ghost fm: format) (pz pinf: t) : dom997requires { fmt pz = fm /\ fmt pinf = fm }998ensures { result.fm = fm }999requires { at_index fm pz 0 /\ pinf = (plus_infinity fm) }1000ensures { forall v. mem v result <-> fmt v = fm /\ is_not_nan v /\ is_positive v }1001= {proof…} format_facts fm (); {qed}1002one fm pz pinf1003
The special values of a format (Farith's get_special_values)
type specials = {1006minf: t; nl: t; nf: t; nsl: t; nsf: t; nz: t;1007pz: t; psf: t; psl: t; pf: t; pl: t; pinf: t;1008}10091010predicate ok_specials (fm: format) (sv: specials) =1011sv.minf = (minus_infinity fm) /\ sv.pinf = (plus_infinity fm) /\1012at_index fm sv.nl (1 - (nb_sign fm)) /\ at_index fm sv.nf (-1 - power 2 ((sb fm) - 1)) /\1013at_index fm sv.nsl (- power 2 ((sb fm) - 1)) /\ at_index fm sv.nsf (-2) /\1014at_index fm sv.nz (-1) /\ at_index fm sv.pz 0 /\1015at_index fm sv.psf 1 /\ at_index fm sv.psl (power 2 ((sb fm) - 1) - 1) /\1016at_index fm sv.pf (power 2 ((sb fm) - 1)) /\ at_index fm sv.pl ((nb_sign fm) - 2)10171018type classify = {1019clnan: bool; neg_infinity: bool; neg_normal: bool; neg_subnormal: bool;1020clzeros: bool; pos_subnormal: bool; pos_normal: bool; pos_infinity: bool;1021}1022
A float of [a, b] is in d
Valid (373ms) (colibri2 5) (split_vc 2) (depth 2)let meets (ghost fm: format) (a b: t) (d: dom) : bool1025requires { fmt a = fm /\ fmt b = fm /\ d.fm = fm }1026requires { is_not_nan a /\ is_not_nan b /\ index a <= index b }1027ensures { result <-> exists v. mem v d /\ is_not_nan v /\ index a <= index v <= index b }1028= {proof…}1029let lemma pt (v: t) : unit1030requires { mem_u v d.u } ensures { mem v d /\ is_not_nan v }1031= mem_u_not_nan v d.u in1032{qed}1033not (is_distinct_u fm (Cons (a, b) Nil) d.u)1034
Exact: each flag says whether d has a float of that class
Valid (839ms) (colibri2 13) (cvc4 10) (cvc5 5) (split_vc 5) (depth 2)let classify_dom (ghost fm: format) (sv: specials) (d: dom) : classify1037requires { d.fm = fm }1038requires { ok_specials fm sv }1039ensures { result.clnan <-> d.nan }1040ensures { result.neg_infinity <-> mem (minus_infinity fm) d }1041ensures { result.neg_normal <->1042exists v. mem v d /\ is_normal v /\ not is_positive v }1043ensures { result.neg_subnormal <->1044exists v. mem v d /\ is_subnormal v /\ not is_positive v }1045ensures { result.clzeros <-> exists v. mem v d /\ is_zero v }1046ensures { result.pos_subnormal <->1047exists v. mem v d /\ is_subnormal v /\ is_positive v }1048ensures { result.pos_normal <->1049exists v. mem v d /\ is_normal v /\ is_positive v }1050ensures { result.pos_infinity <-> mem (plus_infinity fm) d }1051= {proof…} format_facts fm ();1052assert { forall v. mem v d -> is_not_nan v -> (v = (minus_infinity fm) <-> index v = - (nb_sign fm)) };1053assert { forall v. mem v d -> is_not_nan v -> (v = (plus_infinity fm) <-> index v = (nb_sign fm) - 1) };1054{qed}1055{ clnan = d.nan;1056neg_infinity = meets fm sv.minf sv.minf d;1057neg_normal = meets fm sv.nl sv.nf d;1058neg_subnormal = meets fm sv.nsl sv.nsf d;1059clzeros = meets fm sv.nz sv.pz d;1060pos_subnormal = meets fm sv.psf sv.psl d;1061pos_normal = meets fm sv.pf sv.pl d;1062pos_infinity = meets fm sv.pinf sv.pinf d }1063
[neg b, neg a] is the image of [a, b]
Valid (58ms) (cvc4)let ghost in_iv_neg (fm: format) (v a b: t) : unit1068requires { is_not_nan v /\ is_not_nan a /\ is_not_nan b }1069ensures { in_iv v (neg b) (neg a) <-> in_iv (neg v) a b }1070= {proof…} () {qed}1071
The negation of l, reversed, in front of acc
Valid (597ms) (colibri2 10) (cvc5 3) (split_vc 2) (depth 2)let rec neg_rev (ghost fm: format) (l acc: list (t, t)) : list (t, t)1074requires { fmt_u fm l /\ fmt_u fm acc }1075ensures { fmt_u fm result }1076requires { ok_u l /\ ok_u acc }1077requires { match l, acc with1078| Cons (a, _) _, Cons (a', _) _ -> lt_dz (neg a) a'1079| _ -> true end }1080ensures { ok_u result }1081ensures { forall v. mem_u v result <->1082(is_not_nan v /\ mem_u (neg v) l) \/ mem_u v acc }1083variant { l }1084= match l with1085| Nil -> acc1086| Cons (a, b) r ->1087{proof…}1088let lemma pt (v: t) : unit1089requires { is_not_nan v }1090ensures { in_iv v (neg b) (neg a) <-> in_iv (neg v) a b }1091= in_iv_neg fm v a b in1092let lemma nn (v: t) : unit1093requires { mem_u (neg v) l } ensures { is_not_nan v }1094= mem_u_not_nan (neg v) l in1095{qed}1096neg_rev fm r (Cons (neg b, neg a) acc)1097end1098
Exact
Valid (99ms) (cvc4)let neg_dom (ghost fm: format) (d: dom) : dom1101requires { d.fm = fm }1102ensures { result.fm = fm }1103ensures { forall v. mem v result <-> mem (neg v) d }1104= {proof…}1105let lemma pt (v: t) : unit1106requires { mem_u (neg v) d.u } ensures { is_not_nan v }1107= mem_u_not_nan (neg v) d.u in1108{qed}1109{ u = neg_rev fm d.u Nil; nan = d.nan; fm = fm }1110
The absolute values of [a, b]; pz is +0
Valid (690ms) (colibri2 7) (cvc4 4) (cvc5) (split_vc 7) (depth 4)let abs_iv (ghost fm: format) (pz a b: t) : list (t, t)1113requires { fmt pz = fm /\ fmt a = fm /\ fmt b = fm }1114ensures { fmt_u fm result }1115requires { at_index fm pz 0 /\ is_not_nan a /\ is_not_nan b /\ le_dz a b }1116ensures { ok_u result }1117ensures { forall v. mem_u v result <->1118is_not_nan v /\ is_positive v /\ (in_iv v a b \/ in_iv (neg v) a b) }1119= if le_diff_zero pz a then Cons (a, b) Nil1120else if lt_diff_zero b pz then Cons (abs b, abs a) Nil1121else union_u fm (Cons (pz, abs a) Nil) (Cons (pz, b) Nil)1122Valid (326ms) (cvc5)1123let rec abs_u (ghost fm: format) (pz: t) (l: list (t, t)) : list (t, t)1124requires { fmt pz = fm /\ fmt_u fm l }1125ensures { fmt_u fm result }1126requires { at_index fm pz 0 /\ ok_u l }1127ensures { ok_u result }1128ensures { forall v. mem_u v result <->1129is_not_nan v /\ is_positive v /\ (mem_u v l \/ mem_u (neg v) l) }1130variant { l }1131= match l with1132| Nil -> Nil1133| Cons (a, b) r -> union_u fm (abs_iv fm pz a b) (abs_u fm pz r)1134end1135
Exact: the positive floats whose negation or itself is in d
Valid (190ms) (cvc4)let abs_dom (ghost fm: format) (pz: t) (d: dom) : dom1138requires { fmt pz = fm /\ d.fm = fm }1139ensures { result.fm = fm }1140requires { at_index fm pz 0 }1141ensures { forall v. mem v result <->1142fmt v = fm /\ if is_nan v then d.nan else is_positive v /\ (mem v d \/ mem (neg v) d) }1143ensures { forall v. mem v d -> mem (abs v) result }1144= let r = { u = abs_u fm pz d.u; nan = d.nan; fm = fm } in1145{proof…}1146let lemma pt (v: t) : unit1147requires { mem v d } ensures { mem (abs v) r }1148= if is_nan v then () else begin1149index_range v; mem_u_not_nan v d.u;1150if pure { is_positive v } then assert { abs v = v by1151of_index fm (index (abs v)) = of_index fm (index v) }1152else begin1153neg_neg v;1154assert { abs v = neg v by1155of_index fm (index (abs v)) = of_index fm (index (neg v)) }1156end1157end in1158{qed}1159r1160
The result is one of the arguments: the union, exact when the arguments range over the two domains independently.
Valid (63ms) (colibri2)let min_dom (ghost fm: format) (d1 d2: dom) : dom1167requires { d1.fm = fm /\ d2.fm = fm }1168ensures { result.fm = fm }1169ensures { forall x y. mem x d1 -> mem y d2 -> mem (min x y) result }1170ensures { forall v. mem v result <-> mem v d1 \/ mem v d2 }1171= union fm d1 d21172Valid (64ms) (colibri2)1173let max_dom (ghost fm: format) (d1 d2: dom) : dom1174requires { d1.fm = fm /\ d2.fm = fm }1175ensures { result.fm = fm }1176ensures { forall x y. mem x d1 -> mem y d2 -> mem (max x y) result }1177ensures { forall v. mem v result <-> mem v d1 \/ mem v d2 }1178= union fm d1 d21179Valid (21ms) (colibri2)1180let function nan_dom (ghost fm: format) : dom = { u = Nil; nan = true; fm = fm }1181
The interval [a, b] of two floats that are not NaN, a <= b
Valid (25ms) (colibri2)let interval (ghost fm: format) (a b: t) : dom1184requires { fmt a = fm /\ fmt b = fm }1185ensures { result.fm = fm }1186requires { is_not_nan a /\ is_not_nan b /\ le_dz a b }1187ensures { forall v. mem v result <-> not (is_nan v) /\ in_iv v a b }1188= { u = Cons (a, b) Nil; nan = false; fm = fm }1189
The domain of one float
Valid (83ms) (colibri2)let singleton (ghost fm: format) (v: t) : dom1192requires { fmt v = fm }1193ensures { result.fm = fm }1194ensures { mem v result }1195ensures { forall w. mem w result -> (is_nan v <-> is_nan w) }1196ensures { forall w. mem w result -> not (is_nan v) -> le_dz v w /\ le_dz w v }1197= if is_nan v then (nan_dom fm)1198else begin1199{proof…} le_refl_any v; {qed}1200interval fm v v1201end1202
By the monotonicity of add (Facts.add_box), on each pair of intervals; NaN for the infinities of opposite signs.
The sums of the box [a1, b1] x [a2, b2]
Valid (777ms) (colibri2 22) (cvc5 3) (split_vc) (depth 1)let add_iv (ghost fm: format) (minf pinf: t) (m: mode) (a1 b1 a2 b2: t) : dom1210requires { fmt minf = fm /\ fmt pinf = fm /\ fmt a1 = fm /\ fmt b1 = fm /\ fmt a2 = fm /\ fmt b2 = fm }1211ensures { result.fm = fm }1212requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }1213requires { is_not_nan a1 /\ is_not_nan b1 /\ le_dz a1 b1 }1214requires { is_not_nan a2 /\ is_not_nan b2 /\ le_dz a2 b2 }1215ensures { forall x y. in_iv x a1 b1 -> in_iv y a2 b2 ->1216mem (fp_add m x y) result }1217= let a3 = add m a1 a2 in1218let b3 = add m b1 b2 in1219{proof…}1220let lemma inf_le (x y: t) : unit1221requires { le_dz x y } ensures { is_plus_infinity x -> is_plus_infinity y }1222ensures { is_minus_infinity y -> is_minus_infinity x }1223= le_not_nan x y;1224if pure { is_plus_infinity x /\ not is_plus_infinity y } then begin1225lt_plus_infinity y; plus_infinity_unique x; lt_not_le y x end;1226if pure { is_minus_infinity y /\ not is_minus_infinity x } then begin1227minus_infinity_lt x; minus_infinity_unique y; lt_not_le y x end in1228{qed}1229match is_nan a3, is_nan b3 with1230| True, True -> (* -inf + +inf *) (nan_dom fm)1231| False, False ->1232{proof…}1233add_box m a1 b1 a2 b2;1234let lemma pt (x y: t) : unit1235requires { in_iv x a1 b1 /\ in_iv y a2 b2 }1236requires { is_not_nan (fp_add m x y) }1237ensures { in_iv (fp_add m x y) a3 b3 }1238= add_box m a1 x a2 y; add_box m x b1 y b2 in1239{qed}1240{ u = Cons (a3, b3) Nil;1241nan = (le_diff_zero pinf b1 && le_diff_zero a2 minf)1242|| (le_diff_zero pinf b2 && le_diff_zero a1 minf); fm = fm }1243| True, False ->1244(* b1 = +inf \/ b2 = +inf *)1245{proof…} le_refl_any pinf; {qed}1246{ u = Cons (pinf, pinf) Nil; nan = true; fm = fm }1247| False, True ->1248(* a1 = -inf \/ a2 = -inf *)1249{proof…} le_refl_any minf; {qed}1250{ u = Cons (minf, minf) Nil; nan = true; fm = fm }1251end1252
The sums of [a1, b1] and l2
Valid (85ms) (cvc5)let rec add_iv_u (ghost fm: format) (minf pinf: t) (m: mode) (a1 b1: t) (l2: list (t, t)) : dom1255requires { fmt minf = fm /\ fmt pinf = fm /\ fmt a1 = fm /\ fmt b1 = fm /\ fmt_u fm l2 }1256ensures { result.fm = fm }1257requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }1258requires { is_not_nan a1 /\ is_not_nan b1 /\ le_dz a1 b1 /\ ok_u l2 }1259ensures { forall x y. in_iv x a1 b1 -> mem_u y l2 ->1260mem (fp_add m x y) result }1261variant { l2 }1262= match l2 with1263| Nil -> { u = Nil; nan = false; fm = fm }1264| Cons (a2, b2) r ->1265union fm (add_iv fm minf pinf m a1 b1 a2 b2) (add_iv_u fm minf pinf m a1 b1 r)1266end1267Valid (55ms) (cvc5)1268let rec add_u (ghost fm: format) (minf pinf: t) (m: mode) (l1 l2: list (t, t)) : dom1269requires { fmt minf = fm /\ fmt pinf = fm /\ fmt_u fm l1 /\ fmt_u fm l2 }1270ensures { result.fm = fm }1271requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }1272requires { ok_u l1 /\ ok_u l2 }1273ensures { forall x y. mem_u x l1 -> mem_u y l2 -> mem (fp_add m x y) result }1274variant { l1 }1275= match l1 with1276| Nil -> { u = Nil; nan = false; fm = fm }1277| Cons (a1, b1) r ->1278union fm (add_iv_u fm minf pinf m a1 b1 l2) (add_u fm minf pinf m r l2)1279end1280
Sound: the sums of the floats of d1 and d2 are in the result
Valid (91ms) (cvc5)let add_dom (ghost fm: format) (minf pinf: t) (m: mode) (d1 d2: dom) : dom1283requires { fmt minf = fm /\ fmt pinf = fm /\ d1.fm = fm /\ d2.fm = fm }1284ensures { result.fm = fm }1285requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) }1286ensures { forall x y. mem x d1 -> mem y d2 -> mem (fp_add m x y) result }1287= let r = add_u fm minf pinf m d1.u d2.u in1288if d1.nan || d2.nan then union fm (nan_dom fm) r else r1289
By quadrants of signs: in each, the product is monotonic in the magnitudes (Facts.mul_mag), the bounds are the products of the ends of small magnitude and of the ends of large magnitude.
predicate specials4 (fm: format) (minf pinf nz pz: t) =1297minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) /\1298at_index fm nz (-1) /\ at_index fm pz 01299Valid (50ms) (colibri2)1300let is_zero_f (ghost fm: format) (nz pz: t) (x: t) : bool1301requires { fmt nz = fm /\ fmt pz = fm /\ fmt x = fm }1302requires { at_index fm nz (-1) /\ at_index fm pz 0 /\ is_not_nan x }1303ensures { result <-> is_zero x }1304= le_diff_zero nz x && le_diff_zero x pz1305Valid (61ms) (colibri2)1306let is_inf_f (ghost fm: format) (minf pinf: t) (x: t) : bool1307requires { fmt minf = fm /\ fmt pinf = fm /\ fmt x = fm }1308requires { minf = (minus_infinity fm) /\ pinf = (plus_infinity fm) /\ is_not_nan x }1309ensures { result <-> is_infinity x }1310= {proof…}1311index_range x; index_range pinf; index_range minf;1312{qed}1313le_diff_zero pinf x || le_diff_zero x minf1314
The products of x of sign px with |s1| <= |x| <= |l1| and y of sign py with |s2| <= |y| <= |l2|
Valid (813ms) (colibri2 37) (cvc4 5) (cvc5 12) (split_vc) (depth 1)let mul_quad (ghost fm: format) (minf pinf nz pz: t) (m: mode)1318(px: bool) (s1 l1: t) (py: bool) (s2 l2: t) : dom1319requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ fmt s1 = fm /\ fmt l1 = fm /\ fmt s2 = fm /\ fmt l2 = fm }1320ensures { result.fm = fm }1321requires { specials4 fm minf pinf nz pz }1322requires { mag_le px s1 l1 /\ mag_le py s2 l2 }1323ensures { forall x y. mag_le px s1 x -> mag_le px x l1 ->1324mag_le py s2 y -> mag_le py y l2 -> mem (fp_mul m x y) result }1325= let p = mul m s1 s2 in1326let q = mul m l1 l2 in1327let pos = if px then py else not py in1328{proof…}1329mag_le_sign px s1 l1; mag_le_sign py s2 l2;1330let lemma pt_sign (x y: t) : unit1331requires { mag_le px s1 x /\ mag_le px x l1 }1332requires { mag_le py s2 y /\ mag_le py y l2 }1333ensures { mul_zneg x y <-> not pos }1334ensures { is_zero x -> is_zero s1 }1335ensures { is_zero y -> is_zero s2 }1336ensures { is_infinity x -> is_infinity l1 }1337ensures { is_infinity y -> is_infinity l2 }1338ensures { is_zero l1 -> is_zero x }1339ensures { is_zero l2 -> is_zero y }1340ensures { is_infinity s1 -> is_infinity x }1341ensures { is_infinity s2 -> is_infinity y }1342= mag_le_sign px s1 x; mag_le_sign px x l1;1343mag_le_sign py s2 y; mag_le_sign py y l2;1344index_range x; index_range y; index_range s1; index_range s2;1345index_range l1; index_range l2 in1346{qed}1347match is_nan p, is_nan q with1348| True, True -> (* 0 * inf at both ends *) (nan_dom fm)1349| True, False ->1350(* an infinite end and a zero one: the infinity or NaN *)1351let i = if pos then pinf else minf in1352{proof…}1353le_refl_any i;1354let lemma pt (x y: t) : unit1355requires { mag_le px s1 x /\ mag_le px x l1 }1356requires { mag_le py s2 y /\ mag_le py y l2 }1357ensures { is_nan (fp_mul m x y) \/ fp_mul m x y = i }1358= pt_sign x y; mul_special m x y; mul_special m s1 s2;1359mul_special m l1 l2 in1360{qed}1361{ u = Cons (i, i) Nil; nan = true; fm = fm }1362| False, True ->1363(* a zero end and an infinite one: the zero or NaN *)1364let z = if pos then pz else nz in1365{proof…}1366le_refl_any z;1367let lemma pt (x y: t) : unit1368requires { mag_le px s1 x /\ mag_le px x l1 }1369requires { mag_le py s2 y /\ mag_le py y l2 }1370ensures { is_nan (fp_mul m x y) \/ fp_mul m x y = z }1371= pt_sign x y; mul_special m x y; mul_special m s1 s2;1372mul_special m l1 l2;1373let r = fp_mul m x y in1374if is_not_nan r then begin1375index_range r;1376assert { r = z by of_index fm (index r) = of_index fm (index z) }1377end in1378{qed}1379{ u = Cons (z, z) Nil; nan = true; fm = fm }1380| False, False ->1381{proof…}1382mul_mag m px py s1 l1 s2 l2;1383let lemma pt (x y: t) : unit1384requires { mag_le px s1 x /\ mag_le px x l1 }1385requires { mag_le py s2 y /\ mag_le py y l2 }1386requires { is_not_nan (fp_mul m x y) }1387ensures { if pos then in_iv (fp_mul m x y) p q1388else in_iv (fp_mul m x y) q p }1389= mul_mag m px py s1 x s2 y; mul_mag m px py x l1 y l2 in1390let lemma pn (x y: t) : unit1391requires { mag_le px s1 x /\ mag_le px x l1 }1392requires { mag_le py s2 y /\ mag_le py y l2 }1393requires { is_nan (fp_mul m x y) }1394ensures { (is_zero s1 /\ is_infinity l2) \/ (is_zero s2 /\ is_infinity l1) }1395= pt_sign x y; mul_special m x y in1396{qed}1397{ u = Cons (if pos then (p, q) else (q, p)) Nil;1398nan = (is_zero_f fm nz pz s1 && is_inf_f fm minf pinf l2)1399|| (is_zero_f fm nz pz s2 && is_inf_f fm minf pinf l1); fm = fm }1400end1401Valid (28ms) (colibri2)1402let function empty_dom (ghost fm: format) : dom = { u = Nil; nan = false; fm = fm }1403
The products of the box [a1, b1] x [a2, b2], by the four quadrants
Valid (563ms) (colibri2 50) (cvc4) (cvc5 5) (split_vc 13) (depth 4)let mul_iv (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a1 b1 a2 b2: t) : dom1406requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ fmt a1 = fm /\ fmt b1 = fm /\ fmt a2 = fm /\ fmt b2 = fm }1407ensures { result.fm = fm }1408requires { specials4 fm minf pinf nz pz }1409requires { is_not_nan a1 /\ is_not_nan b1 /\ le_dz a1 b1 }1410requires { is_not_nan a2 /\ is_not_nan b2 /\ le_dz a2 b2 }1411ensures { forall x y. in_iv x a1 b1 -> in_iv y a2 b2 ->1412mem (fp_mul m x y) result }1413= {proof…}1414let lemma sign_split (x: t) : unit1415requires { is_not_nan x /\ fmt x = fm }1416ensures { is_positive x <-> le_dz pz x }1417ensures { not is_positive x <-> le_dz x nz }1418= index_range x in1419{qed}1420(* the negative part [a, min b -0], the positive part [max a +0, b] *)1421let n1 = le_diff_zero a1 nz in1422let p1 = le_diff_zero pz b1 in1423let n2 = le_diff_zero a2 nz in1424let p2 = le_diff_zero pz b2 in1425let sn1 = if le_diff_zero b1 nz then b1 else nz in1426let sp1 = if le_diff_zero pz a1 then a1 else pz in1427let sn2 = if le_diff_zero b2 nz then b2 else nz in1428let sp2 = if le_diff_zero pz a2 then a2 else pz in1429{proof…}1430let lemma pt (x: t) (a b sn sp: t) : unit1431requires { is_not_nan a /\ is_not_nan b /\ in_iv x a b /\ fmt a = fm }1432requires { sn = (if le_dz b nz then b else nz) }1433requires { sp = (if le_dz pz a then a else pz) }1434ensures { is_positive x -> le_dz pz b /\ mag_le true sp x /\ mag_le true x b }1435ensures { not is_positive x ->1436le_dz a nz /\ mag_le false sn x /\ mag_le false x a }1437= index_range x; index_range a; index_range b in1438let lemma ends (a b sn sp: t) : unit1439requires { is_not_nan a /\ is_not_nan b /\ le_dz a b /\ fmt a = fm }1440requires { sn = (if le_dz b nz then b else nz) }1441requires { sp = (if le_dz pz a then a else pz) }1442ensures { le_dz a nz -> mag_le false sn a }1443ensures { le_dz pz b -> mag_le true sp b }1444= index_range a; index_range b in1445ends a1 b1 sn1 sp1; ends a2 b2 sn2 sp2;1446{qed}1447let pp = if p1 && p2 then mul_quad fm minf pinf nz pz m true sp1 b1 true sp2 b21448else (empty_dom fm) in1449let pn = if p1 && n2 then mul_quad fm minf pinf nz pz m true sp1 b1 false sn2 a21450else (empty_dom fm) in1451let np = if n1 && p2 then mul_quad fm minf pinf nz pz m false sn1 a1 true sp2 b21452else (empty_dom fm) in1453let nn = if n1 && n2 then mul_quad fm minf pinf nz pz m false sn1 a1 false sn2 a21454else (empty_dom fm) in1455{proof…}1456let lemma all (x y: t) : unit1457requires { in_iv x a1 b1 /\ in_iv y a2 b2 }1458ensures { mem (fp_mul m x y) pp \/ mem (fp_mul m x y) pn1459\/ mem (fp_mul m x y) np \/ mem (fp_mul m x y) nn }1460= pt x a1 b1 sn1 sp1; pt y a2 b2 sn2 sp2 in1461{qed}1462union fm (union fm pp pn) (union fm np nn)1463
The products of [a1, b1] and l2
Valid (92ms) (cvc5)let rec mul_iv_u (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a1 b1: t) (l2: list (t, t))1466: dom1467requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ fmt a1 = fm /\ fmt b1 = fm /\ fmt_u fm l2 }1468ensures { result.fm = fm }1469requires { specials4 fm minf pinf nz pz }1470requires { is_not_nan a1 /\ is_not_nan b1 /\ le_dz a1 b1 /\ ok_u l2 }1471ensures { forall x y. in_iv x a1 b1 -> mem_u y l2 ->1472mem (fp_mul m x y) result }1473variant { l2 }1474= match l2 with1475| Nil -> (empty_dom fm)1476| Cons (a2, b2) r ->1477union fm (mul_iv fm minf pinf nz pz m a1 b1 a2 b2)1478(mul_iv_u fm minf pinf nz pz m a1 b1 r)1479end1480Valid (85ms) (cvc5)1481let rec mul_u (ghost fm: format) (minf pinf nz pz: t) (m: mode) (l1 l2: list (t, t)) : dom1482requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ fmt_u fm l1 /\ fmt_u fm l2 }1483ensures { result.fm = fm }1484requires { specials4 fm minf pinf nz pz }1485requires { ok_u l1 /\ ok_u l2 }1486ensures { forall x y. mem_u x l1 -> mem_u y l2 -> mem (fp_mul m x y) result }1487variant { l1 }1488= match l1 with1489| Nil -> (empty_dom fm)1490| Cons (a1, b1) r ->1491union fm (mul_iv_u fm minf pinf nz pz m a1 b1 l2) (mul_u fm minf pinf nz pz m r l2)1492end1493
Sound: the products of the floats of d1 and d2 are in the result
Valid (56ms) (cvc5)let mul_dom (ghost fm: format) (minf pinf nz pz: t) (m: mode) (d1 d2: dom) : dom1496requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ d1.fm = fm /\ d2.fm = fm }1497ensures { result.fm = fm }1498requires { specials4 fm minf pinf nz pz }1499ensures { forall x y. mem x d1 -> mem y d2 -> mem (fp_mul m x y) result }1500= let r = mul_u fm minf pinf nz pz m d1.u d2.u in1501if d1.nan || d2.nan then union fm (nan_dom fm) r else r1502
Increasing (Facts.sqrt_le) from –0: NaN below.
Valid (527ms) (colibri2 8) (cvc4 4) (cvc5 4) (split_vc) (depth 1)let sqrt_iv (ghost fm: format) (nz: t) (m: mode) (a b: t) : dom1508requires { fmt nz = fm /\ fmt a = fm /\ fmt b = fm }1509ensures { result.fm = fm }1510requires { at_index fm nz (-1) }1511requires { is_not_nan a /\ is_not_nan b /\ le_dz a b }1512ensures { forall x. in_iv x a b -> mem (fp_sqrt m x) result }1513= if lt_diff_zero b nz then begin1514{proof…}1515let lemma pt (x: t) : unit1516requires { in_iv x a b } ensures { is_nan (fp_sqrt m x) }1517= sqrt_special m x; index_range x; index_range b in1518{qed}1519(nan_dom fm)1520end else begin1521let lo = if le_diff_zero nz a then a else nz in1522{proof…}1523index_range a; index_range b;1524sqrt_special m lo; sqrt_special m b;1525sqrt_le m lo b;1526let lemma pt (x: t) : unit1527requires { in_iv x a b }1528ensures { if is_nan (fp_sqrt m x) then lt_dz a nz1529else in_iv (fp_sqrt m x) (fp_sqrt m lo) (fp_sqrt m b) }1530= sqrt_special m x; index_range x;1531if is_not_nan (fp_sqrt m x) then begin1532sqrt_le m lo x; sqrt_le m x b end in1533{qed}1534{ u = Cons (sqrt m lo, sqrt m b) Nil; nan = lt_diff_zero a nz; fm = fm }1535end1536Valid (183ms) (colibri2)1537let rec sqrt_u (ghost fm: format) (nz: t) (m: mode) (l: list (t, t)) : dom1538requires { fmt nz = fm /\ fmt_u fm l }1539ensures { result.fm = fm }1540requires { at_index fm nz (-1) /\ ok_u l }1541ensures { forall x. mem_u x l -> mem (fp_sqrt m x) result }1542variant { l }1543= match l with1544| Nil -> (empty_dom fm)1545| Cons (a, b) r -> union fm (sqrt_iv fm nz m a b) (sqrt_u fm nz m r)1546end1547
Sound: the square roots of the floats of d are in the result
Valid (56ms) (cvc5)let sqrt_dom (ghost fm: format) (nz: t) (m: mode) (d: dom) : dom1550requires { fmt nz = fm /\ d.fm = fm }1551ensures { result.fm = fm }1552requires { at_index fm nz (-1) }1553ensures { forall x. mem x d -> mem (fp_sqrt m x) result }1554= let r = sqrt_u fm nz m d.u in1555if d.nan then union fm (nan_dom fm) r else r1556
Conversion to the format fm' is increasing (Facts.convert_le): each interval goes to the interval of the conversions of its bounds.
Valid (410ms) (cvc5)let rec convert_u (ghost fm: format) (fm': format) (m: mode) (l: list (t, t)) : dom1563requires { ok_u l /\ fmt_u fm l }1564ensures { result.fm = fm' }1565ensures { forall x. mem_u x l -> mem (fp_convert fm' m x) result }1566variant { l }1567= match l with1568| Nil -> empty_dom fm'1569| Cons (a, b) r ->1570{proof…} le_not_nan_any a b; {qed}1571let ca = convert fm' m a in1572let cb = convert fm' m b in1573{proof…}1574convert_not_nan fm' m a; convert_not_nan fm' m b; convert_le fm' m a b;1575{qed}1576let iv = interval fm' ca cb in1577{proof…}1578let lemma pt (x: t) : unit1579requires { in_iv x a b }1580ensures { mem (fp_convert fm' m x) iv }1581= convert_le fm' m a x; convert_le fm' m x b; convert_not_nan fm' m x in1582{qed}1583union fm' iv (convert_u fm fm' m r)1584end1585
The conversions of the floats of d
Valid (43ms) (colibri2)let convert_dom (ghost fm: format) (fm': format) (m: mode) (d: dom) : dom1588requires { d.fm = fm }1589ensures { result.fm = fm' }1590ensures { forall x. mem x d -> mem (fp_convert fm' m x) result }1591= let r = convert_u fm fm' m d.u in1592if d.nan then union fm' (nan_dom fm') r else r1593
Increasing (Facts.rti_le), as the conversion.
Valid (114ms) (cvc5)let rec rti_u (ghost fm: format) (m: mode) (l: list (t, t)) : dom1599requires { ok_u l /\ fmt_u fm l }1600ensures { result.fm = fm }1601ensures { forall x. mem_u x l -> mem (fp_rti m x) result }1602variant { l }1603= match l with1604| Nil -> empty_dom fm1605| Cons (a, b) r ->1606{proof…} le_not_nan_any a b; {qed}1607let ra = round_to_integral m a in1608let rb = round_to_integral m b in1609{proof…}1610rti_not_nan m a; rti_not_nan m b; rti_le m a b;1611{qed}1612let iv = interval fm ra rb in1613{proof…}1614let lemma pt (x: t) : unit1615requires { in_iv x a b }1616ensures { mem (fp_rti m x) iv }1617= rti_le m a x; rti_le m x b; rti_not_nan m x in1618{qed}1619union fm iv (rti_u fm m r)1620end1621
The roundings to an integral float of the floats of d
Valid (36ms) (colibri2)let rti_dom (ghost fm: format) (m: mode) (d: dom) : dom1624requires { d.fm = fm }1625ensures { result.fm = fm }1626ensures { forall x. mem x d -> mem (fp_rti m x) result }1627= let r = rti_u fm m d.u in1628if d.nan then union fm (nan_dom fm) r else r1629
As the multiplication, by quadrants (Facts.div_mag).
The quotients of x of sign px with |s1| <= |x| <= |l1| by y of sign py with |s2| <= |y| <= |l2|: from s1 / l2 to l1 / s2
Valid (859ms) (colibri2 37) (cvc4 6) (cvc5 14) (split_vc 2) (depth 2)let div_quad (ghost fm: format) (minf pinf nz pz: t) (m: mode)1637(px: bool) (s1 l1: t) (py: bool) (s2 l2: t) : dom1638requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ fmt s1 = fm /\ fmt l1 = fm /\ fmt s2 = fm /\ fmt l2 = fm }1639ensures { result.fm = fm }1640requires { specials4 fm minf pinf nz pz }1641requires { mag_le px s1 l1 /\ mag_le py s2 l2 }1642ensures { forall x y. mag_le px s1 x -> mag_le px x l1 ->1643mag_le py s2 y -> mag_le py y l2 -> mem (fp_div m x y) result }1644= let p = div m s1 l2 in1645let q = div m l1 s2 in1646let pos = if px then py else not py in1647{proof…}1648mag_le_sign px s1 l1; mag_le_sign py s2 l2;1649let lemma pt_sign (x y: t) : unit1650requires { mag_le px s1 x /\ mag_le px x l1 }1651requires { mag_le py s2 y /\ mag_le py y l2 }1652ensures { mul_zneg x y <-> not pos }1653ensures { is_zero x -> is_zero s1 }1654ensures { is_zero y -> is_zero s2 }1655ensures { is_infinity x -> is_infinity l1 }1656ensures { is_infinity y -> is_infinity l2 }1657ensures { is_zero l1 -> is_zero x }1658ensures { is_zero l2 -> is_zero y }1659ensures { is_infinity s1 -> is_infinity x }1660ensures { is_infinity s2 -> is_infinity y }1661= mag_le_sign px s1 x; mag_le_sign px x l1;1662mag_le_sign py s2 y; mag_le_sign py y l2;1663index_range x; index_range y; index_range s1; index_range s2;1664index_range l1; index_range l2 in1665{qed}1666match is_nan p, is_nan q with1667| True, True -> (* 0/0 or inf/inf at both ends *) (nan_dom fm)1668| True, False ->1669(* all the dividends infinite or all the divisors zeros *)1670let i = if pos then pinf else minf in1671{proof…}1672le_refl_any i;1673let lemma pt (x y: t) : unit1674requires { mag_le px s1 x /\ mag_le px x l1 }1675requires { mag_le py s2 y /\ mag_le py y l2 }1676ensures { is_nan (fp_div m x y) \/ fp_div m x y = i }1677= pt_sign x y; div_special m x y; div_special m s1 l2;1678div_special m l1 s2 in1679{qed}1680{ u = Cons (i, i) Nil; nan = true; fm = fm }1681| False, True ->1682(* all the dividends zeros or all the divisors infinite *)1683let z = if pos then pz else nz in1684{proof…}1685le_refl_any z;1686let lemma pt (x y: t) : unit1687requires { mag_le px s1 x /\ mag_le px x l1 }1688requires { mag_le py s2 y /\ mag_le py y l2 }1689ensures { is_nan (fp_div m x y) \/ fp_div m x y = z }1690= pt_sign x y; div_special m x y; div_special m s1 l2;1691div_special m l1 s2;1692let r = fp_div m x y in1693if is_not_nan r then begin1694index_range r;1695assert { r = z by of_index fm (index r) = of_index fm (index z) }1696end in1697{qed}1698{ u = Cons (z, z) Nil; nan = true; fm = fm }1699| False, False ->1700{proof…}1701div_mag m px py s1 l1 s2 l2;1702let lemma pt (x y: t) : unit1703requires { mag_le px s1 x /\ mag_le px x l1 }1704requires { mag_le py s2 y /\ mag_le py y l2 }1705requires { is_not_nan (fp_div m x y) }1706ensures { if pos then in_iv (fp_div m x y) p q1707else in_iv (fp_div m x y) q p }1708= div_mag m px py s1 x y l2; div_mag m px py x l1 s2 y in1709let lemma pn (x y: t) : unit1710requires { mag_le px s1 x /\ mag_le px x l1 }1711requires { mag_le py s2 y /\ mag_le py y l2 }1712requires { is_nan (fp_div m x y) }1713ensures { (is_zero s1 /\ is_zero s2) \/ (is_infinity l1 /\ is_infinity l2) }1714= pt_sign x y; div_special m x y in1715{qed}1716{ u = Cons (if pos then (p, q) else (q, p)) Nil;1717nan = (is_zero_f fm nz pz s1 && is_zero_f fm nz pz s2)1718|| (is_inf_f fm minf pinf l1 && is_inf_f fm minf pinf l2); fm = fm }1719end1720
The quotients of the box [a1, b1] x [a2, b2], by the four quadrants
Valid (381ms) (colibri2 50) (cvc5 6) (split_vc 13) (depth 4)let div_iv (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a1 b1 a2 b2: t) : dom1723requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ fmt a1 = fm /\ fmt b1 = fm /\ fmt a2 = fm /\ fmt b2 = fm }1724ensures { result.fm = fm }1725requires { specials4 fm minf pinf nz pz }1726requires { is_not_nan a1 /\ is_not_nan b1 /\ le_dz a1 b1 }1727requires { is_not_nan a2 /\ is_not_nan b2 /\ le_dz a2 b2 }1728ensures { forall x y. in_iv x a1 b1 -> in_iv y a2 b2 ->1729mem (fp_div m x y) result }1730= {proof…}1731let lemma sign_split (x: t) : unit1732requires { is_not_nan x /\ fmt x = fm }1733ensures { is_positive x <-> le_dz pz x }1734ensures { not is_positive x <-> le_dz x nz }1735= index_range x in1736{qed}1737(* the negative part [a, min b -0], the positive part [max a +0, b] *)1738let n1 = le_diff_zero a1 nz in1739let p1 = le_diff_zero pz b1 in1740let n2 = le_diff_zero a2 nz in1741let p2 = le_diff_zero pz b2 in1742let sn1 = if le_diff_zero b1 nz then b1 else nz in1743let sp1 = if le_diff_zero pz a1 then a1 else pz in1744let sn2 = if le_diff_zero b2 nz then b2 else nz in1745let sp2 = if le_diff_zero pz a2 then a2 else pz in1746{proof…}1747let lemma pt (x: t) (a b sn sp: t) : unit1748requires { is_not_nan a /\ is_not_nan b /\ in_iv x a b /\ fmt a = fm }1749requires { sn = (if le_dz b nz then b else nz) }1750requires { sp = (if le_dz pz a then a else pz) }1751ensures { is_positive x -> le_dz pz b /\ mag_le true sp x /\ mag_le true x b }1752ensures { not is_positive x ->1753le_dz a nz /\ mag_le false sn x /\ mag_le false x a }1754= index_range x; index_range a; index_range b in1755let lemma ends (a b sn sp: t) : unit1756requires { is_not_nan a /\ is_not_nan b /\ le_dz a b /\ fmt a = fm }1757requires { sn = (if le_dz b nz then b else nz) }1758requires { sp = (if le_dz pz a then a else pz) }1759ensures { le_dz a nz -> mag_le false sn a }1760ensures { le_dz pz b -> mag_le true sp b }1761= index_range a; index_range b in1762ends a1 b1 sn1 sp1; ends a2 b2 sn2 sp2;1763{qed}1764let pp = if p1 && p2 then div_quad fm minf pinf nz pz m true sp1 b1 true sp2 b21765else (empty_dom fm) in1766let pn = if p1 && n2 then div_quad fm minf pinf nz pz m true sp1 b1 false sn2 a21767else (empty_dom fm) in1768let np = if n1 && p2 then div_quad fm minf pinf nz pz m false sn1 a1 true sp2 b21769else (empty_dom fm) in1770let nn = if n1 && n2 then div_quad fm minf pinf nz pz m false sn1 a1 false sn2 a21771else (empty_dom fm) in1772{proof…}1773let lemma all (x y: t) : unit1774requires { in_iv x a1 b1 /\ in_iv y a2 b2 }1775ensures { mem (fp_div m x y) pp \/ mem (fp_div m x y) pn1776\/ mem (fp_div m x y) np \/ mem (fp_div m x y) nn }1777= pt x a1 b1 sn1 sp1; pt y a2 b2 sn2 sp2 in1778{qed}1779union fm (union fm pp pn) (union fm np nn)1780
The quotients of [a1, b1] and l2
Valid (309ms) (cvc5)let rec div_iv_u (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a1 b1: t) (l2: list (t, t))1783: dom1784requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ fmt a1 = fm /\ fmt b1 = fm /\ fmt_u fm l2 }1785ensures { result.fm = fm }1786requires { specials4 fm minf pinf nz pz }1787requires { is_not_nan a1 /\ is_not_nan b1 /\ le_dz a1 b1 /\ ok_u l2 }1788ensures { forall x y. in_iv x a1 b1 -> mem_u y l2 ->1789mem (fp_div m x y) result }1790variant { l2 }1791= match l2 with1792| Nil -> (empty_dom fm)1793| Cons (a2, b2) r ->1794union fm (div_iv fm minf pinf nz pz m a1 b1 a2 b2)1795(div_iv_u fm minf pinf nz pz m a1 b1 r)1796end1797Valid (325ms) (cvc5)1798let rec div_u (ghost fm: format) (minf pinf nz pz: t) (m: mode) (l1 l2: list (t, t)) : dom1799requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ fmt_u fm l1 /\ fmt_u fm l2 }1800ensures { result.fm = fm }1801requires { specials4 fm minf pinf nz pz }1802requires { ok_u l1 /\ ok_u l2 }1803ensures { forall x y. mem_u x l1 -> mem_u y l2 -> mem (fp_div m x y) result }1804variant { l1 }1805= match l1 with1806| Nil -> (empty_dom fm)1807| Cons (a1, b1) r ->1808union fm (div_iv_u fm minf pinf nz pz m a1 b1 l2) (div_u fm minf pinf nz pz m r l2)1809end1810
Sound: the quotients of the floats of d1 and d2 are in the result
Valid (89ms) (cvc5)let div_dom (ghost fm: format) (minf pinf nz pz: t) (m: mode) (d1 d2: dom) : dom1813requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ d1.fm = fm /\ d2.fm = fm }1814ensures { result.fm = fm }1815requires { specials4 fm minf pinf nz pz }1816ensures { forall x y. mem x d1 -> mem y d2 -> mem (fp_div m x y) result }1817= let r = div_u fm minf pinf nz pz m d1.u d2.u in1818if d1.nan || d2.nan then union fm (nan_dom fm) r else r1819
Exact: for the comparison x op y with x in d, the domain of the y such that some x of d makes it true (cmp_true_*, None when there is none) or false (cmp_false_*). The comparisons are those of IEEE 754 (fp_le, fp_lt, fp_eq: –0 = +0, NaN unordered).
Valid (23ms) (colibri2)let is_pz (ghost fm: format) (pz x: t) : bool1828requires { fmt pz = fm /\ fmt x = fm }1829requires { at_index fm pz 0 /\ is_not_nan x }1830ensures { result <-> index x = 0 }1831= le_diff_zero pz x && le_diff_zero x pz1832Valid (24ms) (colibri2)1833let is_nz (ghost fm: format) (nz x: t) : bool1834requires { fmt nz = fm /\ fmt x = fm }1835requires { at_index fm nz (-1) /\ is_not_nan x }1836ensures { result <-> index x = -1 }1837= le_diff_zero nz x && le_diff_zero x nz1838Valid (17ms) (colibri2)1839let first (ghost fm: format) (d: dom) : t1840requires { d.fm = fm }1841ensures { fmt result = fm }1842requires { d.u <> Nil }1843ensures { mem_u result d.u /\ is_not_nan result }1844ensures { forall v. mem_u v d.u -> le_dz result v }1845= let r = try min_f fm d with Empty -> absurd end in1846{proof…} mem_u_not_nan r d.u; {qed}1847r1848Valid (15ms) (colibri2)1849let last (ghost fm: format) (d: dom) : t1850requires { d.fm = fm }1851ensures { fmt result = fm }1852requires { d.u <> Nil }1853ensures { mem_u result d.u /\ is_not_nan result }1854ensures { forall v. mem_u v d.u -> le_dz v result }1855= let r = try max_f fm d with Empty -> absurd end in1856{proof…} mem_u_not_nan r d.u; {qed}1857r1858
x <= y
Valid (814ms) (colibri2 15) (cvc4 2) (cvc5 4) (split_vc 5) (depth 3)let cmp_true_le (ghost fm: format) (nz pz pinf: t) (d: dom) : option dom1861requires { fmt nz = fm /\ fmt pz = fm /\ fmt pinf = fm /\ d.fm = fm }1862ensures { match result with Some r -> r.fm = fm | None -> true end }1863requires { at_index fm nz (-1) /\ at_index fm pz 0 /\ pinf = (plus_infinity fm) }1864ensures { match result with1865| None -> forall x y. mem x d -> not fp_le x y1866| Some r -> not is_bot r /\ forall y. mem y r <-> exists x. mem x d /\ fp_le x y1867end }1868= match d.u with1869| Nil -> None1870| Cons _ _ ->1871let f1 = first fm d in1872let f1' = if is_pz fm pz f1 then nz else f1 in1873{proof…}1874index_range f1; index_range pinf;1875let lemma pt (y: t) : unit1876ensures { (is_not_nan y /\ in_iv y f1' pinf) <->1877exists x. mem x d /\ fp_le x y }1878= if is_not_nan y && pure { fmt y = fm } then begin1879index_range y; if pure { index f1 = 0 /\ index y = -1 } then1880assert { mem f1 d /\ fp_le f1 y }1881else if pure { index f1' <= index y } then1882assert { mem f1 d /\ fp_le f1 y }1883end;1884if pure { exists x. mem x d /\ fp_le x y } then begin1885let x = any t ensures { mem result d /\ fp_le result y } in1886index_range x1887end in1888{qed}1889Some (interval fm f1' pinf)1890end1891
x < y
Valid (623ms) (colibri2 24) (cvc4) (cvc5 7) (split_vc 4) (depth 2)let cmp_true_lt (ghost fm: format) (nz pz pinf: t) (d: dom) : option dom1894requires { fmt nz = fm /\ fmt pz = fm /\ fmt pinf = fm /\ d.fm = fm }1895ensures { match result with Some r -> r.fm = fm | None -> true end }1896requires { at_index fm nz (-1) /\ at_index fm pz 0 /\ pinf = (plus_infinity fm) }1897ensures { match result with1898| None -> forall x y. mem x d -> not fp_lt x y1899| Some r -> not is_bot r /\ forall y. mem y r <-> exists x. mem x d /\ fp_lt x y1900end }1901= match d.u with1902| Nil -> None1903| Cons _ _ ->1904let f1 = first fm d in1905if le_diff_zero pinf f1 then begin1906{proof…}1907let lemma pt (x y: t) : unit1908requires { mem x d } ensures { not fp_lt x y }1909= if not (is_nan x) && not (is_nan y) then begin1910index_range x; index_range y; index_range f1; index_range pinf1911end in1912{qed}1913None1914end else begin1915let f1' = if is_nz fm nz f1 then pz else f1 in1916{proof…}1917index_range f1; index_range pinf;1918{qed}1919let s = succ_diff_zero f1' in1920{proof…}1921succ_gt f1'; index_range s;1922succ_least f1' pinf; let lemma pt (y: t) : unit1923ensures { (is_not_nan y /\ in_iv y s pinf) <->1924exists x. mem x d /\ fp_lt x y }1925= if is_not_nan y && pure { fmt y = fm } then begin1926index_range y; if pure { index s <= index y } then1927assert { mem f1 d /\ fp_lt f1 y }1928end;1929if pure { exists x. mem x d /\ fp_lt x y } then begin1930let x = any t ensures { mem result d /\ fp_lt result y } in1931index_range x; index_range y;1932assert { lt_dz f1' y };1933succ_least f1' y1934end in1935{qed}1936Some (interval fm s pinf)1937end1938end1939
x >= y, that is y <= x
Valid (787ms) (colibri2 17) (cvc5 5) (split_vc 5) (depth 3)let cmp_true_ge (ghost fm: format) (nz pz minf: t) (d: dom) : option dom1942requires { fmt nz = fm /\ fmt pz = fm /\ fmt minf = fm /\ d.fm = fm }1943ensures { match result with Some r -> r.fm = fm | None -> true end }1944requires { at_index fm nz (-1) /\ at_index fm pz 0 /\ minf = (minus_infinity fm) }1945ensures { match result with1946| None -> forall x y. mem x d -> not fp_le y x1947| Some r -> not is_bot r /\ forall y. mem y r <-> exists x. mem x d /\ fp_le y x1948end }1949= match d.u with1950| Nil -> None1951| Cons _ _ ->1952let f2 = last fm d in1953let f2' = if is_nz fm nz f2 then pz else f2 in1954{proof…}1955index_range f2; index_range minf;1956let lemma pt (y: t) : unit1957ensures { (is_not_nan y /\ in_iv y minf f2') <->1958exists x. mem x d /\ fp_le y x }1959= if is_not_nan y && pure { fmt y = fm } then begin1960index_range y; if pure { index f2 = -1 /\ index y = 0 } then1961assert { mem f2 d /\ fp_le y f2 }1962else if pure { index y <= index f2' } then1963assert { mem f2 d /\ fp_le y f2 }1964end;1965if pure { exists x. mem x d /\ fp_le y x } then begin1966let x = any t ensures { mem result d /\ fp_le y result } in1967index_range x1968end in1969{qed}1970Some (interval fm minf f2')1971end1972
x > y, that is y < x
Valid (872ms) (colibri2 24) (cvc4) (cvc5 7) (split_vc 4) (depth 2)let cmp_true_gt (ghost fm: format) (nz pz minf: t) (d: dom) : option dom1975requires { fmt nz = fm /\ fmt pz = fm /\ fmt minf = fm /\ d.fm = fm }1976ensures { match result with Some r -> r.fm = fm | None -> true end }1977requires { at_index fm nz (-1) /\ at_index fm pz 0 /\ minf = (minus_infinity fm) }1978ensures { match result with1979| None -> forall x y. mem x d -> not fp_lt y x1980| Some r -> not is_bot r /\ forall y. mem y r <-> exists x. mem x d /\ fp_lt y x1981end }1982= match d.u with1983| Nil -> None1984| Cons _ _ ->1985let f2 = last fm d in1986if le_diff_zero f2 minf then begin1987{proof…}1988let lemma pt (x y: t) : unit1989requires { mem x d } ensures { not fp_lt y x }1990= if not (is_nan x) && not (is_nan y) then begin1991index_range x; index_range y; index_range f2; index_range minf1992end in1993{qed}1994None1995end else begin1996let f2' = if is_pz fm pz f2 then nz else f2 in1997{proof…}1998index_range f2; index_range minf;1999{qed}2000let s = pred_diff_zero f2' in2001{proof…}2002pred_lt f2'; index_range s;2003pred_greatest f2' minf; let lemma pt (y: t) : unit2004ensures { (is_not_nan y /\ in_iv y minf s) <->2005exists x. mem x d /\ fp_lt y x }2006= if is_not_nan y && pure { fmt y = fm } then begin2007index_range y; if pure { index y <= index s } then2008assert { mem f2 d /\ fp_lt y f2 }2009end;2010if pure { exists x. mem x d /\ fp_lt y x } then begin2011let x = any t ensures { mem result d /\ fp_lt y result } in2012index_range x; index_range y;2013assert { lt_dz y f2' };2014pred_greatest f2' y2015end in2016{qed}2017Some (interval fm minf s)2018end2019end2020
x = y
Valid (606ms) (colibri2 18) (cvc4 2) (cvc5 3) (split_vc 3) (depth 2)let cmp_true_eq (ghost fm: format) (nz pz: t) (d: dom) : option dom2023requires { fmt nz = fm /\ fmt pz = fm /\ d.fm = fm }2024ensures { match result with Some r -> r.fm = fm | None -> true end }2025requires { at_index fm nz (-1) /\ at_index fm pz 0 }2026ensures { match result with2027| None -> forall x y. mem x d -> not fp_eq x y2028| Some r -> not is_bot r /\ forall y. mem y r <-> exists x. mem x d /\ fp_eq x y2029end }2030= let l = if meets fm nz pz d then union_u fm d.u (Cons (nz, pz) Nil) else d.u in2031{proof…}2032le_refl_any nz; le_refl_any pz; index_range nz;2033let lemma pt (y: t) : unit2034ensures { mem_u y l <-> exists x. mem x d /\ fp_eq x y }2035= if pure { mem_u y l } then begin2036mem_u_not_nan y l; index_range y;2037if pure { mem_u y d.u } then begin2038mem_u_not_nan y d.u; assert { mem y d /\ fp_eq y y }2039end else begin2040let x = any t ensures { mem result d /\ is_not_nan result /\2041index nz <= index result <= index pz } in2042assert { fp_eq x y }2043end2044end;2045if pure { exists x. mem x d /\ fp_eq x y } then begin2046let x = any t ensures { mem result d /\ fp_eq result y } in2047if is_nan x then absurd;2048index_range x; mem_u_not_nan x d.u;2049if pure { is_zero x /\ is_zero y } then2050assert { index nz <= index y <= index pz /\ index nz <= index x <= index pz }2051end in2052{qed}2053match l with2054| Nil -> None2055| Cons _ _ -> Some { u = l; nan = false; fm = fm }2056end2057
not (x <= y): NaN, or below the largest x
Valid (584ms) (colibri2 29) (cvc4 2) (cvc5 9) (split_vc 8) (depth 5)let cmp_false_le (ghost fm: format) (minf pinf nz pz: t) (d: dom) : dom2060requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ d.fm = fm }2061ensures { result.fm = fm }2062requires { specials4 fm minf pinf nz pz }2063ensures { forall y. mem y result <->2064fmt y = fm /\ exists x. mem x d /\ not fp_le x y }2065= if d.nan then begin2066let r = top fm minf pinf in2067{proof…}2068let lemma pt (y: t) : unit2069requires { mem y r }2070ensures { exists x. mem x d /\ not fp_le x y }2071= assert { mem (not_a_number fm) d /\ not fp_le (not_a_number fm) y } in2072{qed}2073r2074end else match d.u with2075| Nil -> (empty_dom fm)2076| Cons _ _ ->2077let f2 = last fm d in2078let f2' = if is_pz fm pz f2 then nz else f2 in2079{proof…}2080index_range f2; index_range minf; index_range pinf;2081{qed}2082if le_diff_zero f2' minf then begin2083{proof…}2084let lemma pt (y: t) : unit2085requires { fmt y = fm }2086ensures { is_nan y <-> exists x. mem x d /\ not fp_le x y }2087= if is_nan y then assert { mem f2 d /\ not fp_le f2 y };2088if pure { exists x. mem x d /\ not fp_le x y } then begin2089let x = any t ensures { mem result d /\ not fp_le result y } in2090mem_u_not_nan x d.u; index_range x;2091if not (is_nan y) then index_range y2092end in2093{qed}2094(nan_dom fm)2095end else begin2096let p = pred_diff_zero f2' in2097{proof…}2098pred_lt f2'; index_range p; pred_greatest f2' minf;2099let lemma pt (y: t) : unit2100requires { fmt y = fm }2101ensures { (is_nan y \/ in_iv y minf p) <->2102exists x. mem x d /\ not fp_le x y }2103= if is_nan y then assert { mem f2 d /\ not fp_le f2 y }2104else begin2105index_range y;2106if pure { in_iv y minf p } then2107assert { mem f2 d /\ not fp_le f2 y };2108if pure { exists x. mem x d /\ not fp_le x y } then begin2109let x = any t ensures { mem result d /\ not fp_le result y } in2110mem_u_not_nan x d.u; index_range x;2111assert { lt_dz y f2' };2112pred_greatest f2' y2113end2114end in2115{qed}2116{ u = Cons (minf, p) Nil; nan = true; fm = fm }2117end2118end2119
not (x < y): NaN, or up to the largest x
Valid (507ms) (colibri2 21) (cvc4 3) (cvc5 3) (split_vc 7) (depth 5)let cmp_false_lt (ghost fm: format) (minf pinf nz pz: t) (d: dom) : dom2122requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ d.fm = fm }2123ensures { result.fm = fm }2124requires { specials4 fm minf pinf nz pz }2125ensures { forall y. mem y result <->2126fmt y = fm /\ exists x. mem x d /\ not fp_lt x y }2127= if d.nan then begin2128let r = top fm minf pinf in2129{proof…}2130let lemma pt (y: t) : unit2131requires { mem y r }2132ensures { exists x. mem x d /\ not fp_lt x y }2133= assert { mem (not_a_number fm) d /\ not fp_lt (not_a_number fm) y } in2134{qed}2135r2136end else match d.u with2137| Nil -> (empty_dom fm)2138| Cons _ _ ->2139let f2 = last fm d in2140let f2' = if is_nz fm nz f2 then pz else f2 in2141{proof…}2142index_range f2; index_range minf; index_range pinf;2143let lemma pt (y: t) : unit2144requires { fmt y = fm }2145ensures { (is_nan y \/ in_iv y minf f2') <->2146exists x. mem x d /\ not fp_lt x y }2147= if is_nan y then assert { mem f2 d /\ not fp_lt f2 y }2148else begin2149index_range y;2150if pure { in_iv y minf f2' } then2151assert { mem f2 d /\ not fp_lt f2 y };2152if pure { exists x. mem x d /\ not fp_lt x y } then begin2153let x = any t ensures { mem result d /\ not fp_lt result y } in2154mem_u_not_nan x d.u; index_range x2155end2156end in2157{qed}2158{ u = Cons (minf, f2') Nil; nan = true; fm = fm }2159end2160
not (x >= y), that is not (y <= x): NaN, or above the least x
Valid (1.1s) (colibri2 29) (cvc4 3) (cvc5 8) (split_vc 8) (depth 5)let cmp_false_ge (ghost fm: format) (minf pinf nz pz: t) (d: dom) : dom2163requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ d.fm = fm }2164ensures { result.fm = fm }2165requires { specials4 fm minf pinf nz pz }2166ensures { forall y. mem y result <->2167fmt y = fm /\ exists x. mem x d /\ not fp_le y x }2168= if d.nan then begin2169let r = top fm minf pinf in2170{proof…}2171let lemma pt (y: t) : unit2172requires { mem y r }2173ensures { exists x. mem x d /\ not fp_le y x }2174= assert { mem (not_a_number fm) d /\ not fp_le y (not_a_number fm) } in2175{qed}2176r2177end else match d.u with2178| Nil -> (empty_dom fm)2179| Cons _ _ ->2180let f1 = first fm d in2181let f1' = if is_nz fm nz f1 then pz else f1 in2182{proof…}2183index_range f1; index_range minf; index_range pinf;2184{qed}2185if le_diff_zero pinf f1' then begin2186{proof…}2187let lemma pt (y: t) : unit2188requires { fmt y = fm }2189ensures { is_nan y <-> exists x. mem x d /\ not fp_le y x }2190= if is_nan y then assert { mem f1 d /\ not fp_le y f1 };2191if pure { exists x. mem x d /\ not fp_le y x } then begin2192let x = any t ensures { mem result d /\ not fp_le y result } in2193mem_u_not_nan x d.u; index_range x;2194if not (is_nan y) then index_range y2195end in2196{qed}2197(nan_dom fm)2198end else begin2199let s = succ_diff_zero f1' in2200{proof…}2201succ_gt f1'; index_range s; succ_least f1' pinf;2202let lemma pt (y: t) : unit2203requires { fmt y = fm }2204ensures { (is_nan y \/ in_iv y s pinf) <->2205exists x. mem x d /\ not fp_le y x }2206= if is_nan y then assert { mem f1 d /\ not fp_le y f1 }2207else begin2208index_range y;2209if pure { in_iv y s pinf } then2210assert { mem f1 d /\ not fp_le y f1 };2211if pure { exists x. mem x d /\ not fp_le y x } then begin2212let x = any t ensures { mem result d /\ not fp_le y result } in2213mem_u_not_nan x d.u; index_range x;2214assert { lt_dz f1' y };2215succ_least f1' y2216end2217end in2218{qed}2219{ u = Cons (s, pinf) Nil; nan = true; fm = fm }2220end2221end2222
not (x > y), that is not (y < x): NaN, or from the least x
Valid (876ms) (colibri2 23) (cvc4 2) (cvc5 2) (split_vc 7) (depth 5)let cmp_false_gt (ghost fm: format) (minf pinf nz pz: t) (d: dom) : dom2225requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ d.fm = fm }2226ensures { result.fm = fm }2227requires { specials4 fm minf pinf nz pz }2228ensures { forall y. mem y result <->2229fmt y = fm /\ exists x. mem x d /\ not fp_lt y x }2230= if d.nan then begin2231let r = top fm minf pinf in2232{proof…}2233let lemma pt (y: t) : unit2234requires { mem y r }2235ensures { exists x. mem x d /\ not fp_lt y x }2236= assert { mem (not_a_number fm) d /\ not fp_lt y (not_a_number fm) } in2237{qed}2238r2239end else match d.u with2240| Nil -> (empty_dom fm)2241| Cons _ _ ->2242let f1 = first fm d in2243let f1' = if is_pz fm pz f1 then nz else f1 in2244{proof…}2245index_range f1; index_range minf; index_range pinf;2246let lemma pt (y: t) : unit2247requires { fmt y = fm }2248ensures { (is_nan y \/ in_iv y f1' pinf) <->2249exists x. mem x d /\ not fp_lt y x }2250= if is_nan y then assert { mem f1 d /\ not fp_lt y f1 }2251else begin2252index_range y;2253if pure { in_iv y f1' pinf } then2254assert { mem f1 d /\ not fp_lt y f1 };2255if pure { exists x. mem x d /\ not fp_lt y x } then begin2256let x = any t ensures { mem result d /\ not fp_lt y result } in2257mem_u_not_nan x d.u; index_range x2258end2259end in2260{qed}2261{ u = Cons (f1', pinf) Nil; nan = true; fm = fm }2262end2263
not (x = y): all the floats, but when the floats of d are one value of IEEE 754 (one float, or the two zeros)
Valid (524ms) (colibri2 28) (cvc4 5) (cvc5 8) (split_vc 3) (depth 3)let cmp_false_eq (ghost fm: format) (minf pinf nz pz: t) (d: dom) : dom2267requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm /\ d.fm = fm }2268ensures { result.fm = fm }2269requires { specials4 fm minf pinf nz pz }2270ensures { forall y. mem y result <->2271fmt y = fm /\ exists x. mem x d /\ not fp_eq x y }2272= if d.nan then begin2273let r = top fm minf pinf in2274{proof…}2275let lemma pt (y: t) : unit2276requires { mem y r }2277ensures { exists x. mem x d /\ not fp_eq x y }2278= assert { mem (not_a_number fm) d /\ not fp_eq (not_a_number fm) y } in2279{qed}2280r2281end else match d.u with2282| Nil -> (empty_dom fm)2283| Cons _ _ ->2284let f1 = first fm d in2285let f2 = last fm d in2286{proof…}2287index_range f1; index_range f2; index_range nz;2288{qed}2289let z1 = is_zero_f fm nz pz f1 in2290let z2 = is_zero_f fm nz pz f2 in2291if le_diff_zero f2 f1 || (z1 && z2) then begin2292let lo = if z1 then nz else f1 in2293let hi = if z2 then pz else f2 in2294{proof…}2295let lemma pt (y: t) : unit2296requires { fmt y = fm }2297ensures { not (is_not_nan y /\ in_iv y lo hi) <->2298exists x. mem x d /\ not fp_eq x y }2299= if is_nan y then assert { mem f1 d /\ not fp_eq f1 y }2300else begin2301index_range y;2302if pure { not in_iv y lo hi } then2303assert { mem f1 d /\ not fp_eq f1 y };2304if pure { exists x. mem x d /\ not fp_eq x y } then begin2305let x = any t ensures { mem result d /\ not fp_eq result y } in2306mem_u_not_nan x d.u; index_range x;2307if pure { in_iv y lo hi } then begin2308assert { index f1 <= index x <= index f2 };2309if z1 && z2 then assert { is_zero x /\ is_zero y }2310else begin2311assert { x = f1 by of_index fm (index x) = of_index fm (index f1) };2312assert { y = f1 by of_index fm (index y) = of_index fm (index f1) }2313end2314end2315end2316end in2317{qed}2318match complement fm minf pinf (interval fm lo hi) with2319| None -> absurd2320| Some c -> c2321end2322end else begin2323let r = top fm minf pinf in2324{proof…}2325let lemma pt (y: t) : unit2326requires { mem y r }2327ensures { exists x. mem x d /\ not fp_eq x y }2328= if pure { fp_eq f1 y } then begin2329assert { not fp_eq f2 y };2330assert { mem f2 d }2331end else assert { mem f1 d } in2332{qed}2333r2334end2335end2336
The x of the format fm whose conversion to the format fm' is in [a, b] are above the conversion down to fm of the predecessor of a and below the conversion up of the successor of b (Facts.convert_lower, convert_upper). Sound for any mode, from the monotonicity of the rounding only: the floats of fm between the predecessor of a and the preimage of a by the rounding are kept.
x is –inf (resp. +inf) of its format
Valid (16ms) (colibri2)let is_minf (ghost fm: format) (minf x: t) : bool2349requires { fmt minf = fm /\ fmt x = fm /\ minf = minus_infinity fm /\ is_not_nan x }2350ensures { result <-> is_minus_infinity x }2351= {proof…}2352if pure { is_minus_infinity x } then begin2353minus_infinity_unique x; le_refl x2354end else if pure { le_dz x minf } then begin2355minus_infinity_lt x; lt_not_le minf x2356end;2357{qed}2358le_diff_zero x minf2359Valid (21ms) (colibri2)2360let is_pinf (ghost fm: format) (pinf x: t) : bool2361requires { fmt pinf = fm /\ fmt x = fm /\ pinf = plus_infinity fm /\ is_not_nan x }2362ensures { result <-> is_plus_infinity x }2363= {proof…}2364if pure { is_plus_infinity x } then begin2365plus_infinity_unique x; le_refl x2366end else if pure { le_dz pinf x } then begin2367lt_plus_infinity x; lt_not_le x pinf2368end;2369{qed}2370le_diff_zero pinf x2371
The x such that x + y is in [a, b] for some y in [c, d]: above pa - d rounded down, below sb - c rounded up, where pa is the float below a in value (below –0 when a is a zero) and sb the float above b (Facts.add_lower, add_upper). Sound for any mode, from the monotonicity of the rounding only.
thr_lo fm' m a is the float t of the format fm' with one more bit such that the extended reals that round to a or above are at or above t (Intf.round_f_ge_thr), with a zero a taken as –0; thr_hi is the symmetric one, a zero b taken as +0.
Valid (462ms) (colibri2 16) (cvc4) (cvc5 9) (split_vc 2) (depth 2)let thr_lo (ghost fm: format) (fm': format) (nz pz: t) (m: mode) (a: t) : t2387requires { widens fm fm' /\ fmt a = fm /\ fmt nz = fm /\ fmt pz = fm }2388requires { at_index fm nz (-1) /\ at_index fm pz 0 }2389requires { is_not_nan a /\ not is_minus_infinity a }2390ensures { fmt result = fm' /\ is_not_nan result }2391ensures { forall z e. le_dz a (round_f fm m z e) -> ele (ext result) e }2392= let a0 = if is_zero_f fm nz pz a then nz else a in2393{proof…}2394index_range a;2395assert { index a <> - nb_sign fm };2396assert { le_dz a0 a /\ is_not_nan a0 /\ fmt a0 = fm };2397let ghost i = index a0 in2398assert { i <> 0 /\ - nb_sign fm < i < nb_sign fm };2399convert_widen fm' rtn a0; widen_nb_sign fm fm';2400let ghost w0 = windex i in2401assert { - nb_sign fm' + 2 <= w0 < nb_sign fm' };2402assert { w0 + lo_off m i < nb_sign fm' };2403of_index_range fm' w0; of_index_range fm' (w0 - 1); of_index_range fm' (w0 - 2);2404{qed}2405let w = convert fm' rtn a0 in2406let t = match m with2407| RTN -> w2408| RTP -> pred_diff_zero (pred_diff_zero w)2409| RTZ -> if le_diff_zero pz a0 then w else pred_diff_zero (pred_diff_zero w)2410| RNE | RNA -> pred_diff_zero w2411end in2412{proof…}2413assert { t = of_index fm' (w0 + lo_off m i) };2414of_index_range fm' (w0 + lo_off m i);2415let lemma thr (z: bool) (e: ereal) : unit2416requires { le_dz a (round_f fm m z e) } ensures { ele (ext t) e }2417= le_trans a0 a (round_f fm m z e) in2418{qed}2419t2420Valid (708ms) (colibri2 19) (cvc4) (cvc5 10) (split_vc 3) (depth 2)2421let thr_hi (ghost fm: format) (fm': format) (nz pz: t) (m: mode) (b: t) : t2422requires { widens fm fm' /\ fmt b = fm /\ fmt nz = fm /\ fmt pz = fm }2423requires { at_index fm nz (-1) /\ at_index fm pz 0 }2424requires { is_not_nan b /\ not is_plus_infinity b }2425ensures { fmt result = fm' /\ is_not_nan result }2426ensures { forall z e. le_dz (round_f fm m z e) b -> ele e (ext result) }2427= let b0 = if is_zero_f fm nz pz b then pz else b in2428{proof…}2429index_range b;2430assert { index b <> nb_sign fm - 1 };2431assert { le_dz b b0 /\ is_not_nan b0 /\ fmt b0 = fm };2432let ghost j = index b0 in2433assert { j <> -1 /\ - nb_sign fm <= j < nb_sign fm - 1 };2434convert_widen fm' rtn b0; widen_nb_sign fm fm';2435let ghost w0 = windex j in2436assert { - nb_sign fm' <= w0 <= nb_sign fm' - 3 };2437assert { - nb_sign fm' <= w0 + hi_off m j };2438of_index_range fm' w0; of_index_range fm' (w0 + 1); of_index_range fm' (w0 + 2);2439{qed}2440let w = convert fm' rtn b0 in2441let t = match m with2442| RTN -> succ_diff_zero (succ_diff_zero w)2443| RTP -> w2444| RTZ -> if lt_diff_zero b0 pz then w else succ_diff_zero (succ_diff_zero w)2445| RNE | RNA -> succ_diff_zero w2446end in2447{proof…}2448assert { t = of_index fm' (w0 + hi_off m j) };2449of_index_range fm' (w0 + hi_off m j);2450let lemma thr (z: bool) (e: ereal) : unit2451requires { le_dz (round_f fm m z e) b } ensures { ele e (ext t) }2452= le_trans (round_f fm m z e) b b0 in2453{qed}2454t2455
The x of the format fm whose conversion to fm' is in [a, b]: at or above thr_lo a (in fm' with one more bit) rounded up in fm, at or below thr_hi b rounded down (the rounding is monotonic, and exact on the floats of fm), then at most two steps while the bound itself converts out of [a, b]. The conversion keeps the sign: a +0 a (a –0 b) keeps the positive (negative) x.
Valid (492ms) (cvc5)let rec conv_trim_lo (ghost fm: format) (fm': format) (pinf: t) (m: mode) (a l: t)2466(fuel: int) : t2467requires { fmt pinf = fm /\ pinf = plus_infinity fm }2468requires { fmt a = fm' /\ fmt l = fm /\ is_not_nan l }2469requires { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_convert fm' m x) -> le_dz l x }2470ensures { fmt result = fm /\ is_not_nan result }2471ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_convert fm' m x) -> le_dz result x }2472variant { fuel }2473= if fuel <= 0 || is_pinf fm pinf l then l2474else begin2475{proof…} convert_not_nan fm' m l; {qed}2476if lt_diff_zero (convert fm' m l) a then begin2477{proof…}2478let lemma pt (x: t) : unit2479requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_convert fm' m x) }2480ensures { le_dz (succ_dz l) x }2481= lt_not_le (fp_convert fm' m l) a;2482if pure { x = l } then absurd;2483index_range x; index_range l;2484assert { lt_dz l x };2485succ_least l x in2486index_range l; of_index_range fm (index l + 1);2487{qed}2488conv_trim_lo fm fm' pinf m a (succ_diff_zero l) (fuel - 1)2489end else l2490end2491Valid (130ms) (cvc5)2492let rec conv_trim_hi (ghost fm: format) (fm': format) (minf: t) (m: mode) (b h: t)2493(fuel: int) : t2494requires { fmt minf = fm /\ minf = minus_infinity fm }2495requires { fmt b = fm' /\ fmt h = fm /\ is_not_nan h }2496requires { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_convert fm' m x) b -> le_dz x h }2497ensures { fmt result = fm /\ is_not_nan result }2498ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_convert fm' m x) b -> le_dz x result }2499variant { fuel }2500= if fuel <= 0 || is_minf fm minf h then h2501else begin2502{proof…} convert_not_nan fm' m h; {qed}2503if lt_diff_zero b (convert fm' m h) then begin2504{proof…}2505let lemma pt (x: t) : unit2506requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_convert fm' m x) b }2507ensures { le_dz x (pred_dz h) }2508= lt_not_le b (fp_convert fm' m h);2509if pure { x = h } then absurd;2510index_range x; index_range h;2511assert { lt_dz x h };2512pred_greatest h x in2513index_range h; of_index_range fm (index h - 1);2514{qed}2515conv_trim_hi fm fm' minf m b (pred_diff_zero h) (fuel - 1)2516end else h2517end2518Valid (719ms) (colibri2 76) (cvc4 2) (cvc5 15) (split_vc 3) (depth 2)2519let convert_back_iv (fm: format) (fm': format) (minf pinf minf' pinf': t) (m: mode)2520(a b: t)2521: dom2522requires { fmt minf = fm /\ fmt pinf = fm }2523requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }2524requires { fmt minf' = fm' /\ fmt pinf' = fm' }2525requires { minf' = minus_infinity fm' /\ pinf' = plus_infinity fm' }2526requires { fmt a = fm' /\ fmt b = fm' /\ le_dz a b }2527ensures { result.fm = fm }2528ensures { forall x. fmt x = fm -> is_not_nan x ->2529in_iv (fp_convert fm' m x) a b -> mem x result }2530= {proof…}2531le_not_nan a b; format_facts fm (); format_facts fm' ();2532of_index_range fm 0; of_index_range fm (-1);2533of_index_range fm' 0; of_index_range fm' (-1);2534index_range minf; index_range pinf;2535{qed}2536let nz = of_index_v fm (-1) in2537let pz = of_index_v fm 0 in2538let nz' = of_index_v fm' (-1) in2539let pz' = of_index_v fm' 0 in2540match widen fm' with2541| None ->2542{proof…}2543let lemma pt (x: t) : unit2544requires { fmt x = fm /\ is_not_nan x } ensures { in_iv x minf pinf }2545= index_range x in2546{qed}2547interval fm minf pinf2548| Some fw ->2549let lo =2550if is_minf fm' minf' a then minf2551else if is_pz fm' pz' a then begin2552(* the conversion keeps the sign: only the positive `x` reach +0 *)2553{proof…}2554let lemma pt (x: t) : unit2555requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_convert fm' m x) }2556ensures { le_dz pz x }2557= index_range x; index_range nz; index_range pz;2558if pure { index x < 0 } then begin2559convert_le fm' m x nz;2560let ghost cz = fp_convert fm' m nz in2561convert_not_nan fm' m nz;2562assert { ext nz = Fin 0.0 };2563assert { cz = round_f fm' m true (Fin 0.0) };2564assert { is_zero cz /\ not is_positive cz };2565index_range cz; index_range a;2566assert { index cz = -1 };2567le_trans a (fp_convert fm' m x) cz;2568absurd2569end in2570{qed}2571pz2572end else begin2573let t = thr_lo fm' fw nz' pz' m a in2574let l0 = convert fm rtp t in2575{proof…} convert_not_nan fm rtp t; {qed}2576let l = if is_zero_f fm nz pz l0 then nz else l0 in2577{proof…}2578let lemma pt (x: t) : unit2579requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_convert fm' m x) }2580ensures { le_dz l x }2581= let ghost zx = if is_positive x then false else true in2582assert { fp_convert fm' m x = round_f fm' m zx (ext x) };2583assert { ele (ext t) (ext x) };2584let ghost zt = if is_positive t then false else true in2585assert { l0 = round_f fm rtp zt (ext t) };2586round_f_ele fm rtp zt zx (ext t) (ext x);2587assert { round_f fm rtp zx (ext x) = x };2588assert { ele (ext l) (ext x) };2589ele_le l x in2590{qed}2591conv_trim_lo fm fm' pinf m a l 22592end in2593let hi =2594if is_pinf fm' pinf' b then pinf2595else if is_nz fm' nz' b then begin2596(* only the negative `x` reach -0 *)2597{proof…}2598let lemma pt (x: t) : unit2599requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_convert fm' m x) b }2600ensures { le_dz x nz }2601= index_range x; index_range nz; index_range pz;2602if pure { 0 <= index x } then begin2603convert_le fm' m pz x;2604let ghost cz = fp_convert fm' m pz in2605convert_not_nan fm' m pz;2606assert { ext pz = Fin 0.0 };2607assert { cz = round_f fm' m false (Fin 0.0) };2608assert { is_zero cz /\ is_positive cz };2609index_range cz; index_range b;2610assert { index cz = 0 };2611le_trans cz (fp_convert fm' m x) b;2612absurd2613end in2614{qed}2615nz2616end else begin2617let t = thr_hi fm' fw nz' pz' m b in2618let h0 = convert fm rtn t in2619{proof…} convert_not_nan fm rtn t; {qed}2620let h = if is_zero_f fm nz pz h0 then pz else h0 in2621{proof…}2622let lemma pt (x: t) : unit2623requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_convert fm' m x) b }2624ensures { le_dz x h }2625= let ghost zx = if is_positive x then false else true in2626assert { fp_convert fm' m x = round_f fm' m zx (ext x) };2627assert { ele (ext x) (ext t) };2628let ghost zt = if is_positive t then false else true in2629assert { h0 = round_f fm rtn zt (ext t) };2630round_f_ele fm rtn zx zt (ext x) (ext t);2631assert { round_f fm rtn zx (ext x) = x };2632assert { ele (ext x) (ext h) };2633ele_le x h in2634{qed}2635conv_trim_hi fm fm' minf m b h 22636end in2637{proof…}2638let lemma pt (x: t) : unit2639requires { fmt x = fm /\ is_not_nan x /\ in_iv (fp_convert fm' m x) a b }2640ensures { le_dz lo x /\ le_dz x hi }2641= index_range x in2642{qed}2643if lt_diff_zero hi lo then begin2644{proof…}2645let lemma no (x: t) : unit2646requires { fmt x = fm /\ is_not_nan x /\ in_iv (fp_convert fm' m x) a b }2647ensures { false }2648= pt x; le_trans lo x hi; lt_not_le hi lo in2649{qed}2650empty_dom fm2651end else begin2652{proof…} total lo hi; {qed}2653interval fm lo hi2654end2655end2656Valid (477ms) (cvc5)2657let rec convert_back_u (fm: format) (fm': format) (minf pinf minf' pinf': t) (m: mode)2658(l: list (t, t)) : dom2659requires { fmt minf = fm /\ fmt pinf = fm }2660requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }2661requires { fmt minf' = fm' /\ fmt pinf' = fm' }2662requires { minf' = minus_infinity fm' /\ pinf' = plus_infinity fm' }2663requires { ok_u l /\ fmt_u fm' l }2664ensures { result.fm = fm }2665ensures { forall x. fmt x = fm -> is_not_nan x ->2666mem_u (fp_convert fm' m x) l -> mem x result }2667variant { l }2668= match l with2669| Nil -> empty_dom fm2670| Cons (a, b) r ->2671union fm (convert_back_iv fm fm' minf pinf minf' pinf' m a b)2672(convert_back_u fm fm' minf pinf minf' pinf' m r)2673end2674
The floats of the format fm whose conversion to the format fm' is in r
Valid (326ms) (cvc5)let convert_back (fm: format) (fm': format) (minf pinf minf' pinf': t) (m: mode)2678(r: dom)2679: dom2680requires { fmt minf = fm /\ fmt pinf = fm }2681requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }2682requires { fmt minf' = fm' /\ fmt pinf' = fm' }2683requires { minf' = minus_infinity fm' /\ pinf' = plus_infinity fm' }2684requires { r.fm = fm' }2685ensures { result.fm = fm }2686ensures { forall x. fmt x = fm -> mem (fp_convert fm' m x) r -> mem x result }2687= let u = convert_back_u fm fm' minf pinf minf' pinf' m r.u in2688{proof…}2689let lemma pt (x: t) : unit2690requires { fmt x = fm /\ is_nan x } ensures { is_nan (fp_convert fm' m x) }2691= () in2692{qed}2693if r.nan then union fm (nan_dom fm) u else u2694
to_fp of SMT–LIB from a real r rounds Fin r with a zero result negative when r < 0. The reals that round to a or above are at or above real_lo a (–inf when a is –inf); the ones that round to b or below are at or below real_hi b (+inf when b is +inf), strictly when the flag is true. Unlike thr_lo and thr_hi, the sign of zero is used: the reals that round to +0 or above are at or above 0, the ones that round to –0 or below are below 0.
Valid (824ms) (cvc4)let real_lo (ghost fm: format) (fm': format) (minf nz pz: t) (m: mode) (a: t) : t2705requires { widens fm fm' /\ fmt a = fm /\ fmt minf = fm /\ fmt nz = fm /\ fmt pz = fm }2706requires { minf = minus_infinity fm /\ at_index fm nz (-1) /\ at_index fm pz 0 }2707requires { is_not_nan a }2708ensures { fmt result = fm' /\ is_not_nan result }2709ensures { forall r. le_dz a (round_f fm m (r <. 0.0) (Fin r)) -> ele (ext result) (Fin r) }2710= if is_minf fm minf a then begin2711{proof…}2712assert { ext (fp_convert fm' rtn a) = MInf };2713{qed}2714convert fm' rtn a2715end else if is_pz fm pz a then begin2716{proof…}2717let ghost z = convert fm' rtn pz in2718assert { is_zero (round_f fm' rtn false (Fin 0.0)) };2719assert { ext z = Fin 0.0 };2720let lemma pos (r: real) : unit2721requires { le_dz a (round_f fm m (r <. 0.0) (Fin r)) } ensures { 0.0 <=. r }2722= if r <. 0.0 then begin2723let x = round_f fm m true (Fin r) in2724let y = round_f fm m true (Fin 0.0) in2725assert { le_dz x y };2726assert { is_zero y /\ not is_positive y };2727assert { index y = -1 };2728assert { index a <= index x <= index y };2729absurd2730end in2731{qed}2732convert fm' rtn pz2733end else thr_lo fm fm' nz pz m a2734Valid (1.6s) (cvc4)2735let real_hi (ghost fm: format) (fm': format) (pinf nz pz: t) (m: mode) (b: t) : (t, bool)2736requires { widens fm fm' /\ fmt b = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }2737requires { pinf = plus_infinity fm /\ at_index fm nz (-1) /\ at_index fm pz 0 }2738requires { is_not_nan b }2739ensures { let (h, _) = result in fmt h = fm' /\ is_not_nan h }2740ensures { let (h, s) = result in forall r. le_dz (round_f fm m (r <. 0.0) (Fin r)) b ->2741if s then Fin r <> ext h /\ ele (Fin r) (ext h) else ele (Fin r) (ext h) }2742= if is_pinf fm pinf b then begin2743{proof…}2744assert { ext (fp_convert fm' rtn b) = PInf };2745{qed}2746(convert fm' rtn b, false)2747end else if is_nz fm nz b then begin2748{proof…}2749let ghost z = convert fm' rtn pz in2750assert { is_zero (round_f fm' rtn false (Fin 0.0)) };2751assert { ext z = Fin 0.0 };2752let lemma neg (r: real) : unit2753requires { le_dz (round_f fm m (r <. 0.0) (Fin r)) b } ensures { r <. 0.0 }2754= if not (r <. 0.0) then begin2755let x = round_f fm m false (Fin r) in2756let y = round_f fm m false (Fin 0.0) in2757assert { le_dz y x };2758assert { is_zero y /\ is_positive y };2759assert { index y = 0 };2760assert { index y <= index x <= index b };2761absurd2762end in2763{qed}2764(convert fm' rtn pz, true)2765end else (thr_hi fm fm' nz pz m b, false)2766
The least x such that x + d rounds to a or above, d finite: at or above t - d with t = thr_lo a, strictly when t rounds below a, computed with directed rounding in the format fm' then in fm. Sound by monotonicity; exact (tested against the former bisection).
Valid (651ms) (colibri2 53) (cvc4 2) (cvc5 22) (split_vc 3) (depth 2)let add_lo (ghost fm: format) (fm': format) (nz pz: t) (m: mode) (a d: t) : t2773requires { widens fm fm' /\ fmt a = fm /\ fmt d = fm /\ fmt nz = fm /\ fmt pz = fm }2774requires { at_index fm nz (-1) /\ at_index fm pz 0 }2775requires { is_not_nan a /\ not is_minus_infinity a /\ is_not_nan d /\ not is_infinity d }2776ensures { fmt result = fm /\ is_not_nan result }2777ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_add m x d) -> le_dz result x }2778= let fr = format_of a in2779let t = thr_lo fm fm' nz pz m a in2780let a0 = if is_zero_f fm nz pz a then nz else a in2781let d' = convert fm' rtn d in2782let c = convert fr m t in2783{proof…}2784convert_widen fm' rtn d; convert_not_nan fm m t;2785let ghost v = match ext d with Fin v -> v | _ -> absurd end in27862787assert { ext (neg d') = Fin (-. v) /\ fmt (neg d') = fm' };2788assert { not is_infinity (neg d') };2789assert { le_dz a0 a /\ fmt a0 = fm /\ is_not_nan a0 };2790(* the sum, rounded *)2791let lemma sum (x: t) : unit2792requires { fmt x = fm /\ is_not_nan x }2793ensures { fp_add m x d = round_f fm m (add_zneg m x d) (eadd (ext x) (Fin v)) }2794= () in2795{qed}2796if le_diff_zero a0 c then begin2797let s = add rtp t (neg d') in2798let l = convert fr rtp s in2799{proof…} convert_not_nan fm rtp s; {qed}2800let r = if is_zero_f fm nz pz l then nz else l in2801{proof…}2802let lemma pt (x: t) : unit2803requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_add m x d) }2804ensures { le_dz r x }2805= sum x;2806let ghost e = eadd (ext x) (Fin v) in2807assert { ele (ext t) e };2808eadd_move_ge (ext t) (ext x) v;2809let ghost zx = if is_positive x then false else true in2810convert_widen fm' rtp x;2811assert { fp_convert fm' rtp x = round_f fm' rtp zx (ext x) };2812round_f_ele fm' rtp (add_zneg rtp t (neg d')) zx (eadd (ext t) (Fin (-. v))) (ext x);2813assert { ele (ext s) (ext x) };2814let ghost zs = if is_positive s then false else true in2815round_f_ele fm rtp zs zx (ext s) (ext x);2816assert { round_f fm rtp zx (ext x) = x };2817assert { ele (ext l) (ext x) };2818assert { ele (ext r) (ext x) };2819ele_le r x in2820{qed}2821r2822end else begin2823let s = add rtn t (neg d') in2824let l = convert fr rtn s in2825{proof…} convert_not_nan fm rtn s; {qed}2826{proof…}2827let lemma below (x: t) : unit2828requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_add m x d) }2829ensures { lt_dz l x /\ not ele (ext x) (ext l) }2830= sum x;2831let ghost e = eadd (ext x) (Fin v) in2832let ghost zt = if is_positive t then false else true in2833assert { ele (ext t) e };2834(* `t` itself rounds below `a0`, so `e <> ext t` *)2835total a0 c;2836assert { lt_dz c a0 };2837assert { not (is_zero c /\ is_zero a0) by is_zero a0 -> a0 = nz };2838assert { not ele (ext a0) (ext c) };2839if pure { e = ext t } then begin2840round_f_val fm m (add_zneg m x d) zt e;2841ext_le a (fp_add m x d); ext_le a0 a;2842absurd2843end;2844eadd_move_gt (ext t) (ext x) v;2845round_f_down fm' (add_zneg rtn t (neg d')) (eadd (ext t) (Fin (-. v)));2846let ghost zs = if is_positive s then false else true in2847round_f_down fm zs (ext s);2848assert { not ele (ext x) (ext l) };2849total l x;2850if pure { le_dz x l } then begin ext_le x l; absurd end in2851{qed}2852{proof…}2853total a0 c;2854if pure { is_plus_infinity t } then begin2855assert { ext t = PInf /\ c = plus_infinity fm };2856index_range a0; index_range c; assert { le_dz a0 c }; absurd2857end;2858round_f_down fm' (add_zneg rtn t (neg d')) (eadd (ext t) (Fin (-. v)));2859let ghost zs0 = if is_positive s then false else true in2860round_f_down fm zs0 (ext s);2861assert { ext s <> PInf /\ ext l <> PInf };2862assert { not is_plus_infinity l };2863{qed}2864if is_zero_f fm nz pz l then begin2865{proof…}2866let lemma pt (x: t) : unit2867requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_add m x d) }2868ensures { le_dz (succ_dz pz) x }2869= below x;2870assert { ext l = Fin 0.0 /\ ext pz = Fin 0.0 };2871total pz x;2872if pure { le_dz x pz } then begin ext_le x pz; ext_le l x; absurd end;2873succ_least pz x in2874format_facts fm (); of_index_range fm 1;2875{qed}2876succ_diff_zero pz2877end else begin2878{proof…}2879let lemma pt (x: t) : unit2880requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_add m x d) }2881ensures { le_dz (succ_dz l) x }2882= below x; succ_least l x in2883index_range l; of_index_range fm (index l + 1);2884{qed}2885succ_diff_zero l2886end2887end2888
The greatest x such that x + c rounds to b or below, c finite, symmetric to add_lo
Valid (681ms) (colibri2 60) (cvc4 8) (cvc5 9) (split_vc 3) (depth 2)let add_hi (ghost fm: format) (fm': format) (nz pz: t) (m: mode) (b c: t) : t2892requires { widens fm fm' /\ fmt b = fm /\ fmt c = fm /\ fmt nz = fm /\ fmt pz = fm }2893requires { at_index fm nz (-1) /\ at_index fm pz 0 }2894requires { is_not_nan b /\ not is_plus_infinity b /\ is_not_nan c /\ not is_infinity c }2895ensures { fmt result = fm /\ is_not_nan result }2896ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_add m x c) b -> le_dz x result }2897= let fr = format_of b in2898let t = thr_hi fm fm' nz pz m b in2899let b0 = if is_zero_f fm nz pz b then pz else b in2900let c' = convert fm' rtn c in2901let k = convert fr m t in2902{proof…}2903convert_widen fm' rtn c; convert_not_nan fm m t;2904let ghost v = match ext c with Fin v -> v | _ -> absurd end in29052906assert { ext (neg c') = Fin (-. v) /\ fmt (neg c') = fm' };2907assert { not is_infinity (neg c') };2908assert { le_dz b b0 /\ fmt b0 = fm /\ is_not_nan b0 };2909let lemma sum (x: t) : unit2910requires { fmt x = fm /\ is_not_nan x }2911ensures { fp_add m x c = round_f fm m (add_zneg m x c) (eadd (ext x) (Fin v)) }2912= () in2913{qed}2914if le_diff_zero k b0 then begin2915let s = add rtn t (neg c') in2916let h = convert fr rtn s in2917{proof…} convert_not_nan fm rtn s; {qed}2918let r = if is_zero_f fm nz pz h then pz else h in2919{proof…}2920let lemma pt (x: t) : unit2921requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_add m x c) b }2922ensures { le_dz x r }2923= sum x;2924let ghost e = eadd (ext x) (Fin v) in2925assert { ele e (ext t) };2926eadd_move_le (ext t) (ext x) v;2927let ghost zx = if is_positive x then false else true in2928convert_widen fm' rtn x;2929assert { fp_convert fm' rtn x = round_f fm' rtn zx (ext x) };2930round_f_ele fm' rtn zx (add_zneg rtn t (neg c')) (ext x) (eadd (ext t) (Fin (-. v)));2931assert { ele (ext x) (ext s) };2932let ghost zs = if is_positive s then false else true in2933round_f_ele fm rtn zx zs (ext x) (ext s);2934assert { round_f fm rtn zx (ext x) = x };2935assert { ele (ext x) (ext h) };2936assert { ele (ext x) (ext r) };2937ele_le x r in2938{qed}2939r2940end else begin2941let s = add rtp t (neg c') in2942let h = convert fr rtp s in2943{proof…} convert_not_nan fm rtp s; {qed}2944{proof…}2945let lemma above (x: t) : unit2946requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_add m x c) b }2947ensures { lt_dz x h /\ not ele (ext h) (ext x) }2948= sum x;2949let ghost e = eadd (ext x) (Fin v) in2950let ghost zt = if is_positive t then false else true in2951assert { ele e (ext t) };2952(* `t` itself rounds above `b0`, so `e <> ext t` *)2953total k b0;2954assert { lt_dz b0 k };2955assert { not (is_zero b0 /\ is_zero k) by is_zero b0 -> b0 = pz };2956assert { not ele (ext k) (ext b0) };2957if pure { e = ext t } then begin2958round_f_val fm m (add_zneg m x c) zt e;2959ext_le (fp_add m x c) b; ext_le b b0;2960absurd2961end;2962eadd_move_lt (ext t) (ext x) v;2963round_f_up fm' (add_zneg rtp t (neg c')) (eadd (ext t) (Fin (-. v)));2964let ghost zs = if is_positive s then false else true in2965round_f_up fm zs (ext s);2966assert { not ele (ext h) (ext x) };2967total x h;2968if pure { le_dz h x } then begin ext_le h x; absurd end in2969total k b0;2970if pure { is_minus_infinity t } then begin2971assert { ext t = MInf /\ k = minus_infinity fm };2972index_range b0; index_range k; assert { le_dz k b0 }; absurd2973end;2974round_f_up fm' (add_zneg rtp t (neg c')) (eadd (ext t) (Fin (-. v)));2975let ghost zs0 = if is_positive s then false else true in2976round_f_up fm zs0 (ext s);2977assert { ext s <> MInf /\ ext h <> MInf };2978assert { not is_minus_infinity h };2979{qed}2980if is_zero_f fm nz pz h then begin2981{proof…}2982let lemma pt (x: t) : unit2983requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_add m x c) b }2984ensures { le_dz x (pred_dz nz) }2985= above x;2986assert { ext h = Fin 0.0 /\ ext nz = Fin 0.0 };2987total x nz;2988if pure { le_dz nz x } then begin ext_le nz x; ext_le x h; absurd end;2989pred_greatest nz x in2990format_facts fm (); of_index_range fm (-2);2991{qed}2992pred_diff_zero nz2993end else begin2994{proof…}2995let lemma pt (x: t) : unit2996requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_add m x c) b }2997ensures { le_dz x (pred_dz h) }2998= above x; pred_greatest h x in2999index_range h; of_index_range fm (index h - 1);3000{qed}3001pred_diff_zero h3002end3003end3004
One step up when the bound l is not a solution: for a zero a, add_lo takes a as –0, and l can be the x = -d whose exact sum, a zero, has the wrong sign
Valid (651ms) (cvc5)let trim_lo (ghost fm: format) (pinf: t) (m: mode) (a d l: t) : t3009requires { fmt pinf = fm /\ pinf = plus_infinity fm }3010requires { fmt a = fm /\ fmt d = fm /\ fmt l = fm /\ is_not_nan l }3011requires { is_not_nan d /\ not is_infinity d }3012requires { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_add m x d) -> le_dz l x }3013ensures { fmt result = fm /\ is_not_nan result }3014ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_add m x d) -> le_dz result x }3015= if is_pinf fm pinf l then l3016else if lt_diff_zero (add m l d) a then begin3017{proof…}3018let lemma pt (x: t) : unit3019requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_add m x d) }3020ensures { le_dz (succ_dz l) x }3021= lt_not_le (fp_add m l d) a;3022if pure { x = l } then absurd;3023index_range x; index_range l;3024assert { lt_dz l x };3025succ_least l x in3026index_range l; of_index_range fm (index l + 1);3027{qed}3028succ_diff_zero l3029end else l3030Valid (739ms) (cvc4)3031let trim_hi (ghost fm: format) (minf: t) (m: mode) (b c h: t) : t3032requires { fmt minf = fm /\ minf = minus_infinity fm }3033requires { fmt b = fm /\ fmt c = fm /\ fmt h = fm /\ is_not_nan h }3034requires { is_not_nan c /\ not is_infinity c }3035requires { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_add m x c) b -> le_dz x h }3036ensures { fmt result = fm /\ is_not_nan result }3037ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_add m x c) b -> le_dz x result }3038= if is_minf fm minf h then h3039else if lt_diff_zero b (add m h c) then begin3040{proof…}3041let lemma pt (x: t) : unit3042requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_add m x c) b }3043ensures { le_dz x (pred_dz h) }3044= lt_not_le b (fp_add m h c);3045if pure { x = h } then absurd;3046index_range x; index_range h;3047assert { lt_dz x h };3048pred_greatest h x in3049index_range h; of_index_range fm (index h - 1);3050{qed}3051pred_diff_zero h3052end else h3053
The least z of [lo, hi] with a <= z + w, w finite, or a lower bound of them (add_lo, then two steps of trim_lo, for the zero ends); None when there is none
Valid (186ms) (cvc5)let add_least (ghost fm: format) (minf pinf: t) (m: mode) (lo hi a w: t) : option t3058requires { fmt minf = fm /\ fmt pinf = fm }3059requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }3060requires { fmt lo = fm /\ fmt hi = fm /\ le_dz lo hi }3061requires { fmt a = fm /\ is_not_nan a /\ fmt w = fm /\ is_not_nan w /\ not is_infinity w }3062ensures { match result with3063| None -> forall z. in_iv z lo hi -> not le_dz a (fp_add m z w)3064| Some r -> in_iv r lo hi /\3065forall z. in_iv z lo hi -> le_dz a (fp_add m z w) -> le_dz r z end }3066= {proof…} le_not_nan lo hi; le_refl lo; le_refl hi; add_special m hi w; {qed}3067if lt_diff_zero (add m hi w) a then begin3068{proof…}3069let lemma no (z: t) : unit3070requires { in_iv z lo hi /\ le_dz a (fp_add m z w) } ensures { false }3071= le_not_nan lo z; add_special m z w; le_refl w; add_box m z hi w w;3072le_trans a (fp_add m z w) (fp_add m hi w); lt_not_le (fp_add m hi w) a in3073{qed}3074None3075end else if is_minf fm minf a then Some lo3076else begin3077let fr = format_of a in3078match widen fr with3079| None -> Some lo3080| Some fw ->3081{proof…} format_facts fm (); of_index_range fm 0; of_index_range fm (-1); {qed}3082let nz = of_index_v fr (-1) in3083let pz = of_index_v fr 0 in3084let l = trim_lo fm pinf m a w (trim_lo fm pinf m a w (add_lo fm fw nz pz m a w)) in3085let r = max_diff_zero l lo in3086if lt_diff_zero hi r then begin3087{proof…}3088let lemma no (z: t) : unit3089requires { in_iv z lo hi /\ le_dz a (fp_add m z w) } ensures { false }3090= le_not_nan lo z; le_trans r z hi; lt_not_le hi r in3091{qed}3092None3093end else begin3094{proof…} total r hi; {qed}3095Some r3096end3097end3098end3099
The greatest z of [lo, hi] with z + w <= b, w finite, or an upper bound of them (add_hi, then two steps of trim_hi); None when there is none
Valid (181ms) (cvc5)let add_greatest (ghost fm: format) (minf pinf: t) (m: mode) (lo hi b w: t) : option t3104requires { fmt minf = fm /\ fmt pinf = fm }3105requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }3106requires { fmt lo = fm /\ fmt hi = fm /\ le_dz lo hi }3107requires { fmt b = fm /\ is_not_nan b /\ fmt w = fm /\ is_not_nan w /\ not is_infinity w }3108ensures { match result with3109| None -> forall z. in_iv z lo hi -> not le_dz (fp_add m z w) b3110| Some r -> in_iv r lo hi /\3111forall z. in_iv z lo hi -> le_dz (fp_add m z w) b -> le_dz z r end }3112= {proof…} le_not_nan lo hi; le_refl lo; le_refl hi; add_special m lo w; {qed}3113if lt_diff_zero b (add m lo w) then begin3114{proof…}3115let lemma no (z: t) : unit3116requires { in_iv z lo hi /\ le_dz (fp_add m z w) b } ensures { false }3117= le_not_nan lo z; add_special m z w; le_refl w; add_box m lo z w w;3118le_trans (fp_add m lo w) (fp_add m z w) b; lt_not_le b (fp_add m lo w) in3119{qed}3120None3121end else if is_pinf fm pinf b then Some hi3122else begin3123let fr = format_of b in3124match widen fr with3125| None -> Some hi3126| Some fw ->3127{proof…} format_facts fm (); of_index_range fm 0; of_index_range fm (-1); {qed}3128let nz = of_index_v fr (-1) in3129let pz = of_index_v fr 0 in3130let h = trim_hi fm minf m b w (trim_hi fm minf m b w (add_hi fm fw nz pz m b w)) in3131let r = min_diff_zero h hi in3132if lt_diff_zero r lo then begin3133{proof…}3134let lemma no (z: t) : unit3135requires { in_iv z lo hi /\ le_dz (fp_add m z w) b } ensures { false }3136= le_not_nan lo z; le_trans lo z r; lt_not_le r lo in3137{qed}3138None3139end else begin3140{proof…} total lo r; {qed}3141Some r3142end3143end3144end3145
The x such that x + y is in [a, b] for some y in [c, d], by add_lo and add_hi
Valid (424ms) (colibri2 58) (cvc4 7) (cvc5 13) (split_vc) (depth 1)let add_back_iv_d (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode)3149(a b c d: t) : dom3150requires { widens fm fm' }3151requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }3152requires { specials4 fm minf pinf nz pz }3153requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }3154requires { le_dz a b /\ le_dz c d }3155ensures { result.fm = fm }3156ensures { forall x y. fmt x = fm -> is_not_nan x -> in_iv y c d ->3157in_iv (fp_add m x y) a b -> mem x result }3158= {proof…}3159le_not_nan a b; le_not_nan c d;3160{qed}3161let lo =3162if is_minf fm minf a || is_pinf fm pinf d then Some minf3163else if is_minf fm minf d then None3164else Some (trim_lo fm pinf m a d (add_lo fm fm' nz pz m a d)) in3165let hi =3166if is_pinf fm pinf b || is_minf fm minf c then Some pinf3167else if is_pinf fm pinf c then None3168else Some (trim_hi fm minf m b c (add_hi fm fm' nz pz m b c)) in3169match lo, hi with3170| Some lo, Some hi ->3171{proof…}3172let lemma pt (x y: t) : unit3173requires { fmt x = fm /\ is_not_nan x /\ in_iv y c d /\ in_iv (fp_add m x y) a b }3174ensures { le_dz lo x /\ le_dz x hi }3175= le_not_nan c y; le_not_nan y d; le_not_nan a (fp_add m x y); le_refl x;3176if pure { is_minus_infinity a \/ is_plus_infinity d } then begin3177if pure { is_minus_infinity x } then begin3178minus_infinity_unique x; le_refl x3179end else begin3180minus_infinity_lt x; lt_le minf x3181end3182end else begin3183add_special m x d; add_box m x x y d;3184le_trans a (fp_add m x y) (fp_add m x d)3185end;3186if pure { is_plus_infinity b \/ is_minus_infinity c } then begin3187if pure { is_plus_infinity x } then begin3188plus_infinity_unique x; le_refl x3189end else begin3190lt_plus_infinity x; lt_le x pinf3191end3192end else begin3193add_special m x c; add_box m x x c y;3194le_trans (fp_add m x c) (fp_add m x y) b3195end in3196{qed}3197if lt_diff_zero hi lo then begin3198{proof…}3199let lemma no (x y: t) : unit3200requires { fmt x = fm /\ is_not_nan x /\ in_iv y c d /\ in_iv (fp_add m x y) a b }3201ensures { false }3202= pt x y; le_trans lo x hi; lt_not_le hi lo in3203{qed}3204empty_dom fm3205end else begin3206{proof…} total lo hi; {qed}3207interval fm lo hi3208end3209| _ ->3210{proof…}3211let lemma no (x y: t) : unit3212requires { fmt x = fm /\ is_not_nan x /\ in_iv y c d /\ in_iv (fp_add m x y) a b }3213ensures { false }3214= le_not_nan c y; le_not_nan a (fp_add m x y);3215if pure { is_minus_infinity d } then begin3216index_range y; index_range d;3217assert { is_minus_infinity y by y = d \/ lt_dz y d };3218if pure { is_plus_infinity x } then add_special m x y3219else begin3220add_minus_infinity m x y;3221minus_infinity_unique a3222end3223end else begin3224index_range y; index_range c;3225assert { is_plus_infinity y by y = c \/ lt_dz c y };3226if pure { is_minus_infinity x } then add_special m x y3227else begin3228add_plus_infinity m x y;3229plus_infinity_unique b3230end3231end in3232{qed}3233empty_dom fm3234end3235
The direct bounds when the format with one more bit exists (always, in fbin), else every float
Valid (491ms) (colibri2 11) (cvc4) (cvc5) (split_vc) (depth 1)let add_back_iv (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a b c d: t) : dom3239requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }3240requires { specials4 fm minf pinf nz pz }3241requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }3242requires { le_dz a b /\ le_dz c d }3243ensures { result.fm = fm }3244ensures { forall x y. fmt x = fm -> is_not_nan x -> in_iv y c d ->3245in_iv (fp_add m x y) a b -> mem x result }3246= match widen (format_of a) with3247| Some fm' -> add_back_iv_d fm fm' minf pinf nz pz m a b c d3248| None ->3249{proof…}3250index_range minf; index_range pinf;3251let lemma pt (x: t) : unit3252requires { fmt x = fm /\ is_not_nan x } ensures { in_iv x minf pinf }3253= index_range x in3254{qed}3255interval fm minf pinf3256end3257Valid (494ms) (cvc5)3258let rec add_back_iv_u (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a b: t)3259(l: list (t, t)) : dom3260requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }3261requires { specials4 fm minf pinf nz pz }3262requires { fmt a = fm /\ fmt b = fm /\ le_dz a b /\ ok_u l /\ fmt_u fm l }3263ensures { result.fm = fm }3264ensures { forall x y. fmt x = fm -> is_not_nan x -> mem_u y l ->3265in_iv (fp_add m x y) a b -> mem x result }3266variant { l }3267= match l with3268| Nil -> empty_dom fm3269| Cons (c, d) r ->3270union fm (add_back_iv fm minf pinf nz pz m a b c d)3271(add_back_iv_u fm minf pinf nz pz m a b r)3272end3273Valid (348ms) (colibri2)3274let rec add_back_u (ghost fm: format) (minf pinf nz pz: t) (m: mode)3275(l1 l2: list (t, t)) : dom3276requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }3277requires { specials4 fm minf pinf nz pz }3278requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }3279ensures { result.fm = fm }3280ensures { forall x y. fmt x = fm -> is_not_nan x -> mem_u y l2 ->3281mem_u (fp_add m x y) l1 -> mem x result }3282variant { l1 }3283= match l1 with3284| Nil -> empty_dom fm3285| Cons (a, b) r ->3286union fm (add_back_iv_u fm minf pinf nz pz m a b l2)3287(add_back_u fm minf pinf nz pz m r l2)3288end3289
The x such that x + y is in r for some y in d; by commutativity (Facts.add_comm), also the y such that x + y is in r for some x in d
Valid (701ms) (cvc5)let add_back (ghost fm: format) (minf pinf nz pz: t) (m: mode) (r d: dom) : dom3294requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }3295requires { specials4 fm minf pinf nz pz }3296requires { r.fm = fm /\ d.fm = fm }3297ensures { result.fm = fm }3298ensures { forall x y. fmt x = fm -> mem y d -> mem (fp_add m x y) r -> mem x result }3299ensures { forall x y. fmt y = fm -> mem x d -> mem (fp_add m x y) r -> mem y result }3300= let u = add_back_u fm minf pinf nz pz m r.u d.u in3301let n =3302if r.nan then3303if d.nan then top fm minf pinf3304else begin3305let p = if meets fm minf minf d then singleton fm pinf else empty_dom fm in3306let q = if meets fm pinf pinf d then singleton fm minf else empty_dom fm in3307union fm (nan_dom fm) (union fm p q)3308end3309else empty_dom fm in3310let res = union fm n u in3311{proof…}3312let lemma pt (x y: t) : unit3313requires { fmt x = fm /\ mem y d /\ mem (fp_add m x y) r }3314ensures { mem x res }3315= add_special m x y;3316if pure { is_nan (fp_add m x y) } then begin3317if pure { is_not_nan x /\ is_not_nan y } then begin3318if pure { is_plus_infinity x } then begin3319plus_infinity_unique x; minus_infinity_unique y;3320index_range y; assert { index minf <= index y <= index minf }3321end else begin3322minus_infinity_unique x; plus_infinity_unique y;3323index_range y; assert { index pinf <= index y <= index pinf }3324end3325end3326end in3327let lemma pt2 (x y: t) : unit3328requires { fmt y = fm /\ mem x d /\ mem (fp_add m x y) r }3329ensures { mem y res }3330= add_comm m x y; pt y x in3331{qed}3332res3333
add_back without the infinities of d when r has neither NaN nor an infinity: a finite sum has finite arguments
Valid (1.3s) (colibri2 28) (cvc4 2) (cvc5 5) (split_vc 3) (depth 3)let add_back_fin (ghost fm: format) (minf pinf nz pz: t) (m: mode) (r d: dom) : dom3337requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }3338requires { specials4 fm minf pinf nz pz }3339requires { r.fm = fm /\ d.fm = fm }3340ensures { result.fm = fm }3341ensures { forall x y. fmt x = fm -> mem y d -> mem (fp_add m x y) r -> mem x result }3342ensures { forall x y. fmt y = fm -> mem x d -> mem (fp_add m x y) r -> mem y result }3343= {proof…} index_range minf; index_range pinf; {qed}3344if r.nan || meets fm minf minf r || meets fm pinf pinf r then3345add_back fm minf pinf nz pz m r d3346else begin3347{proof…}3348format_facts fm (); succ_gt minf; pred_lt pinf;3349of_index_range fm (index minf + 1); of_index_range fm (index pinf - 1);3350{qed}3351let fin = finites fm (succ_diff_zero minf) (pred_diff_zero pinf) in3352{proof…}3353let lemma fin_arg (x y: t) : unit3354requires { fmt x = fm /\ fmt y = fm /\ mem (fp_add m x y) r }3355ensures { mem x fin /\ mem y fin }3356= add_special m x y; index_range (fp_add m x y);3357assert { is_not_nan (fp_add m x y) };3358if pure { is_inf x \/ is_inf y } then begin3359assert { is_inf (fp_add m x y) };3360if pure { is_plus_infinity (fp_add m x y) } then begin3361plus_infinity_unique (fp_add m x y);3362assert { index pinf <= index (fp_add m x y) <= index pinf }3363end else begin3364minus_infinity_unique (fp_add m x y);3365assert { index minf <= index (fp_add m x y) <= index minf }3366end;3367absurd3368end in3369{qed}3370match inter fm d fin with3371| None -> empty_dom fm3372| Some d' -> add_back fm minf pinf nz pz m r d'3373end3374end3375
Soundness only, after Gallois–Wong, Boldo and Cuoq, "Optimal inverse projection of floating–point addition" (2020). From an end x of an interval of the candidates, a jump skips floats without a y that puts x' + y in the result, a bounded number of times. The bounds of fbin.AddBound (their Lemmas 4 and 5) come first. For one x, y0, the least y with a <= x + y, is searched from the hint a - x (their Theorem 2: in RNE the answer is next to it); x has a solution iff x + y0 <= b. Otherwise every y is at most yd = pred y0, with x' + yd < a, or at least y0, with x' + y0 > b for x' >= x: no x' below the least x1 with a <= x1 + yd has a solution (the soundness half of their Lemma 8, true in every mode and for any set of y). In their setting x1 is the least solution (their Theorem 3).
No y of [c, d] puts x + y in [a, b]
predicate no_cd (m: mode) (x a b c d: t) =3394forall y. in_iv y c d -> not in_iv (fp_add m x y) a b3395
No y of l2 puts x + y in [a, b]
predicate no_y (m: mode) (x a b: t) (l2: list (t, t)) =3398forall y. mem_u y l2 -> not in_iv (fp_add m x y) a b3399
No y of l2 puts x + y in l1
predicate no_add (m: mode) (x: t) (l1 l2: list (t, t)) =3402forall y. mem_u y l2 -> not mem_u (fp_add m x y) l13403
y -> x + y on [c, d], x finite: not NaN, and commutative
Valid (270ms) (cvc5)let ghost add_mono_x (fm: format) (m: mode) (x c d: t) : unit3406requires { fmt x = fm /\ fmt c = fm /\ is_not_nan x /\ not is_infinity x }3407ensures { forall y. in_iv y c d -> fp_add m y x = fp_add m x y /\3408is_not_nan (fp_add m x y) }3409= {proof…}3410let lemma comm (y: t) : unit3411requires { in_iv y c d }3412ensures { fp_add m y x = fp_add m x y }3413ensures { is_not_nan (fp_add m x y) /\ fmt (fp_add m x y) = fm }3414= le_not_nan c y; add_comm m x y; add_special m x y in3415let lemma mo (y1 y2: t) : unit3416requires { in_iv y1 c d /\ in_iv y2 c d /\ le_dz y1 y2 }3417ensures { le_dz (fp_add m y1 x) (fp_add m y2 x) }3418= comm y1; comm y2; le_refl x; add_box m x x y1 y2 in3419() {qed}3420
One float: [x, succ x) is {x}
Valid (449ms) (cvc5)let step_lo (x h: t) : option t3423requires { is_not_nan x /\ le_dz x h }3424ensures { match result with3425| None -> forall x'. in_iv x' x h -> x' = x3426| Some x1 -> in_iv x1 x h /\ forall x'. le_dz x x' -> lt_dz x' x1 -> x' = x3427end }3428= if le_diff_zero h x then begin3429{proof…}3430let lemma pt (x': t) : unit3431requires { in_iv x' x h } ensures { x' = x }3432= le_trans x' h x in3433{qed}3434None3435end else begin3436{proof…}3437le_not_nan x h; total h x; lt_not_plus_infinity x h; succ_gt x; succ_least x h;3438let lemma first (x': t) : unit3439requires { le_dz x x' /\ lt_dz x' (succ_dz x) } ensures { x' = x }3440= total x x';3441if pure { lt_dz x x' } then begin3442succ_least x x'; lt_not_le x' (succ_dz x); absurd3443end in3444{qed}3445Some (succ_diff_zero x)3446end3447
One float: (pred x, x] is {x}
Valid (599ms) (cvc4)let step_hi (l x: t) : option t3450requires { is_not_nan x /\ le_dz l x }3451ensures { match result with3452| None -> forall x'. in_iv x' l x -> x' = x3453| Some x1 -> in_iv x1 l x /\ forall x'. lt_dz x1 x' -> le_dz x' x -> x' = x3454end }3455= if le_diff_zero x l then begin3456{proof…}3457let lemma pt (x': t) : unit3458requires { in_iv x' l x } ensures { x' = x }3459= le_trans x l x' in3460{qed}3461None3462end else begin3463{proof…}3464le_not_nan l x; total x l; lt_not_minus_infinity l x; pred_lt x; pred_greatest x l;3465let lemma last (x': t) : unit3466requires { lt_dz (pred_dz x) x' /\ le_dz x' x } ensures { x' = x }3467= total x' x;3468if pure { lt_dz x' x } then begin3469pred_greatest x x'; lt_not_le (pred_dz x) x'; absurd3470end in3471{qed}3472Some (pred_diff_zero x)3473end3474
A jump up from x in [x, h] for y in [c, d] and sums in [a, b]: the floats of [x, result) have no solution; None when no float of [x, h] has one
Valid (594ms) (colibri2 115) (cvc4 4) (cvc5 14) (split_vc 2) (depth 2)let jump_lo_iv (ghost fm: format) (minf pinf: t) (m: mode) (x h a b c d: t)3479: option t3480requires { fmt minf = fm /\ fmt pinf = fm }3481requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }3482requires { fmt x = fm /\ fmt h = fm /\ le_dz x h }3483requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }3484requires { le_dz a b /\ le_dz c d }3485ensures { match result with3486| None -> forall x'. in_iv x' x h -> no_cd m x' a b c d3487| Some x1 -> in_iv x1 x h /\3488forall x'. le_dz x x' -> lt_dz x' x1 -> no_cd m x' a b c d3489end }3490= {proof…} le_not_nan x h; le_not_nan a b; le_not_nan c d; le_refl x; {qed}3491if is_inf_f fm minf pinf x then begin3492if le_diff_zero a x && le_diff_zero x b then Some x3493else begin3494{proof…}3495let lemma inf (y: t) : unit3496requires { in_iv y c d /\ in_iv (fp_add m x y) a b }3497ensures { false }3498= le_not_nan c y; add_special m x y;3499if pure { is_plus_infinity x } then begin3500plus_infinity_unique x; plus_infinity_unique (fp_add m x y);3501assert { fp_add m x y = x }3502end else begin3503minus_infinity_unique x; minus_infinity_unique (fp_add m x y);3504assert { fp_add m x y = x }3505end in3506{qed}3507step_lo x h3508end3509end else begin3510{proof…} add_mono_x fm m x c d; {qed}3511match add_least fm minf pinf m c d a x with3512| None ->3513(* x + d < a: no x' has a solution below the least x' with a <= x' + d *)3515if is_inf_f fm minf pinf d then begin3516{proof…}3517let lemma no (y: t) : unit3518requires { in_iv y c d /\ in_iv (fp_add m x y) a b } ensures { false }3519= le_not_nan a (fp_add m x y) in3520{qed}3521step_lo x h3522end else begin3523{proof…} le_refl d;3524let lemma below (x' y: t) : unit3525requires { le_dz x x' /\ lt_dz (fp_add m x' d) a }3526requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3527ensures { false }3528= le_not_nan a (fp_add m x' y); le_not_nan x x'; add_special m x' d;3529le_refl x'; add_box m x' x' y d;3530le_lt_trans a (fp_add m x' y) (fp_add m x' d); lt_not_le a a in3531{qed}3532let r = add_least fm minf pinf m x h a d in3533{proof…}3534(match r with3535| None ->3536let lemma pt (x' y: t) : unit3537requires { in_iv x' x h /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3538ensures { false }3539= le_not_nan x x'; add_special m x' d; total a (fp_add m x' d); below x' y in3540()3541| Some x1 ->3542let lemma pt (x' y: t) : unit3543requires { le_dz x x' /\ lt_dz x' x1 }3544requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3545ensures { false }3546= le_lt_trans x x' x1; lt_le x' x1; le_trans x' x1 h;3547le_not_nan x x'; add_special m x' d; total a (fp_add m x' d);3548if pure { le_dz a (fp_add m x' d) } then lt_not_le x' x1;3549below x' y in3550()3551end);3552{qed}3553r3554end3555| Some y0 ->3556let s = add m x y0 in3557if le_diff_zero s b then Some x3558else begin3559{proof…}3560le_not_nan c y0; total s b;3561let lemma above (x' y: t) : unit3562requires { le_dz x x' /\ le_dz y0 y }3563requires { in_iv (fp_add m x' y) a b }3564ensures { false }3565= le_not_nan a (fp_add m x' y);3566add_box m x x' y0 y; lt_le_trans b s (fp_add m x' y);3567lt_not_le b (fp_add m x' y) in3568{qed}3569if le_diff_zero y0 c then begin3570{proof…}3571let lemma pt (x' y: t) : unit3572requires { in_iv x' x h /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3573ensures { false }3574= le_trans y0 c y; above x' y in3575{qed}3576None3577end else begin3578{proof…}3579total y0 c; lt_not_minus_infinity c y0; pred_lt y0; pred_greatest y0 c;3580lt_le (pred_dz y0) y0;3581le_trans (pred_dz y0) y0 d;3582{qed}3583let yd = pred_diff_zero y0 in3584{proof…}3585total a (fp_add m x yd);3586if pure { le_dz a (fp_add m x yd) } then begin3587assert { le_dz y0 yd }; lt_not_le yd y0; absurd end;3588let lemma split (x' y: t) : unit3589requires { le_dz x x' /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3590ensures { le_dz y yd }3591= le_not_nan c y; total y0 y;3592if pure { le_dz y0 y } then begin above x' y; absurd end;3593pred_greatest y0 y in3594{qed}3595if is_inf_f fm minf pinf yd then begin3596{proof…}3597let lemma pt (x' y: t) : unit3598requires { le_dz x x' /\ lt_dz x' (succ_dz x) }3599requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3600ensures { false }3601= split x' y; le_not_nan c y; le_not_nan c yd;3602assert { is_minus_infinity yd }; minus_infinity_unique yd;3603assert { index yd <= index y }; assert { y = yd };3604le_not_nan a (fp_add m x' y); add_special m x' y in3605let lemma pt2 (x' y: t) : unit3606requires { in_iv x' x h /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3607ensures { false }3608= split x' y; le_not_nan c y; le_not_nan c yd;3609assert { is_minus_infinity yd }; minus_infinity_unique yd;3610assert { index yd <= index y }; assert { y = yd };3611le_not_nan a (fp_add m x' y); add_special m x' y in3612{qed}3613step_lo x h3614end else begin3615{proof…}3616let lemma below (x' y: t) : unit3617requires { le_dz x x' /\ lt_dz (fp_add m x' yd) a }3618requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3619ensures { false }3620= split x' y; le_not_nan a (fp_add m x' y); le_not_nan x x';3621add_special m x' yd; le_refl x'; add_box m x' x' y yd;3622le_lt_trans a (fp_add m x' y) (fp_add m x' yd); lt_not_le a a in3623{qed}3624let r = add_least fm minf pinf m x h a yd in3625{proof…}3626(match r with3627| None ->3628let lemma pt (x' y: t) : unit3629requires { in_iv x' x h /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3630ensures { false }3631= le_not_nan x x'; add_special m x' yd; total a (fp_add m x' yd);3632below x' y in3633()3634| Some x1 ->3635let lemma pt (x' y: t) : unit3636requires { le_dz x x' /\ lt_dz x' x1 }3637requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3638ensures { false }3639= le_lt_trans x x' x1; lt_le x' x1; le_trans x' x1 h;3640le_not_nan x x'; add_special m x' yd; total a (fp_add m x' yd);3641if pure { le_dz a (fp_add m x' yd) } then lt_not_le x' x1;3642below x' y in3643()3644end);3645{qed}3646r3647end3648end3649end3650end3651end3652
A jump down from x in [l, x]: the floats of (result, x] have no solution; None when no float of [l, x] has one
Valid (1.6s) (colibri2 119) (cvc4 3) (cvc5 12) (split_vc 2) (depth 2)let jump_hi_iv (ghost fm: format) (minf pinf: t) (m: mode) (l x a b c d: t)3656: option t3657requires { fmt minf = fm /\ fmt pinf = fm }3658requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }3659requires { fmt x = fm /\ fmt l = fm /\ le_dz l x }3660requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }3661requires { le_dz a b /\ le_dz c d }3662ensures { match result with3663| None -> forall x'. in_iv x' l x -> no_cd m x' a b c d3664| Some x1 -> in_iv x1 l x /\3665forall x'. lt_dz x1 x' -> le_dz x' x -> no_cd m x' a b c d3666end }3667= {proof…} le_not_nan l x; le_not_nan a b; le_not_nan c d; le_refl x; {qed}3668if is_inf_f fm minf pinf x then begin3669if le_diff_zero a x && le_diff_zero x b then Some x3670else begin3671{proof…}3672let lemma inf (y: t) : unit3673requires { in_iv y c d /\ in_iv (fp_add m x y) a b }3674ensures { false }3675= le_not_nan c y; add_special m x y;3676if pure { is_plus_infinity x } then begin3677plus_infinity_unique x; plus_infinity_unique (fp_add m x y);3678assert { fp_add m x y = x }3679end else begin3680minus_infinity_unique x; minus_infinity_unique (fp_add m x y);3681assert { fp_add m x y = x }3682end in3683{qed}3684step_hi l x3685end3686end else begin3687{proof…} add_mono_x fm m x c d; {qed}3688match add_greatest fm minf pinf m c d b x with3689| None ->3690(* x + c > b *)3691if is_inf_f fm minf pinf c then begin3692{proof…}3693let lemma no (y: t) : unit3694requires { in_iv y c d /\ in_iv (fp_add m x y) a b } ensures { false }3695= le_not_nan a (fp_add m x y) in3696{qed}3697step_hi l x3698end else begin3699{proof…} le_refl c;3700let lemma above (x' y: t) : unit3701requires { le_dz x' x /\ lt_dz b (fp_add m x' c) }3702requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3703ensures { false }3704= le_not_nan a (fp_add m x' y); le_not_nan x' x; add_special m x' c;3705le_refl x'; add_box m x' x' c y;3706lt_le_trans b (fp_add m x' c) (fp_add m x' y); lt_not_le b b in3707{qed}3708let r = add_greatest fm minf pinf m l x b c in3709{proof…}3710(match r with3711| None ->3712let lemma pt (x' y: t) : unit3713requires { in_iv x' l x /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3714ensures { false }3715= le_not_nan l x'; add_special m x' c; total (fp_add m x' c) b;3716above x' y in3717()3718| Some x1 ->3719let lemma pt (x' y: t) : unit3720requires { lt_dz x1 x' /\ le_dz x' x }3721requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3722ensures { false }3723= lt_le_trans x1 x' x; lt_le x1 x'; le_trans l x1 x';3724le_not_nan l x'; add_special m x' c; total (fp_add m x' c) b;3725if pure { le_dz (fp_add m x' c) b } then lt_not_le x1 x';3726above x' y in3727()3728end);3729{qed}3730r3731end3732| Some y1 ->3733let s = add m x y1 in3734if le_diff_zero a s then Some x3735else begin3736{proof…}3737le_not_nan y1 d; total a s;3738let lemma below (x' y: t) : unit3739requires { le_dz x' x /\ le_dz y y1 }3740requires { in_iv (fp_add m x' y) a b }3741ensures { false }3742= le_not_nan a (fp_add m x' y);3743add_box m x' x y y1; le_lt_trans (fp_add m x' y) s a;3744lt_not_le (fp_add m x' y) a in3745{qed}3746if le_diff_zero d y1 then begin3747{proof…}3748let lemma pt (x' y: t) : unit3749requires { in_iv x' l x /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3750ensures { false }3751= le_trans y d y1; below x' y in3752{qed}3753None3754end else begin3755{proof…}3756total d y1; lt_not_plus_infinity y1 d; succ_gt y1; succ_least y1 d;3757le_lt_trans c y1 (succ_dz y1);3758lt_le y1 (succ_dz y1); le_trans c y1 (succ_dz y1);3759{qed}3760let yu = succ_diff_zero y1 in3761{proof…}3762total (fp_add m x yu) b;3763if pure { le_dz (fp_add m x yu) b } then begin3764assert { le_dz yu y1 }; lt_not_le y1 yu; absurd end;3765let lemma split (x' y: t) : unit3766requires { le_dz x' x /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3767ensures { le_dz yu y }3768= le_not_nan c y; total y y1;3769if pure { le_dz y y1 } then begin below x' y; absurd end;3770succ_least y1 y in3771{qed}3772if is_inf_f fm minf pinf yu then begin3773{proof…}3774let lemma pt (x' y: t) : unit3775requires { lt_dz (pred_dz x) x' /\ le_dz x' x }3776requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3777ensures { false }3778= split x' y; le_not_nan c y; le_not_nan yu y;3779assert { is_plus_infinity yu }; plus_infinity_unique yu;3780assert { index y <= index yu }; assert { y = yu };3781le_not_nan a (fp_add m x' y); add_special m x' y in3782let lemma pt2 (x' y: t) : unit3783requires { in_iv x' l x /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3784ensures { false }3785= split x' y; le_not_nan c y; le_not_nan yu y;3786assert { is_plus_infinity yu }; plus_infinity_unique yu;3787assert { index y <= index yu }; assert { y = yu };3788le_not_nan a (fp_add m x' y); add_special m x' y in3789{qed}3790step_hi l x3791end else begin3792{proof…}3793let lemma above (x' y: t) : unit3794requires { le_dz x' x /\ lt_dz b (fp_add m x' yu) }3795requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3796ensures { false }3797= split x' y; le_not_nan a (fp_add m x' y); le_not_nan x' x;3798add_special m x' yu; le_refl x'; add_box m x' x' yu y;3799lt_le_trans b (fp_add m x' yu) (fp_add m x' y); lt_not_le b b in3800{qed}3801let r = add_greatest fm minf pinf m l x b yu in3802{proof…}3803(match r with3804| None ->3805let lemma pt (x' y: t) : unit3806requires { in_iv x' l x /\ in_iv y c d /\ in_iv (fp_add m x' y) a b }3807ensures { false }3808= le_not_nan l x'; add_special m x' yu; total (fp_add m x' yu) b;3809above x' y in3810()3811| Some x1 ->3812let lemma pt (x' y: t) : unit3813requires { lt_dz x1 x' /\ le_dz x' x }3814requires { in_iv y c d /\ in_iv (fp_add m x' y) a b }3815ensures { false }3816= lt_le_trans x1 x' x; lt_le x1 x'; le_trans l x1 x';3817le_not_nan l x'; add_special m x' yu; total (fp_add m x' yu) b;3818if pure { le_dz (fp_add m x' yu) b } then lt_not_le x1 x';3819above x' y in3820()3821end);3822{qed}3823r3824end3825end3826end3827end3828end3829
The least of two jumps up
Valid (26ms) (colibri2)let min_jump (x1 x2: option t) : option t3832requires { match x1, x2 with Some a, Some b -> is_not_nan a /\ is_not_nan b /\ fmt a = fmt b | _ -> true end }3833ensures { match x1, x2 with3834| None, _ -> result = x2 | _, None -> result = x13835| Some a, Some b -> (result = x1 /\ le_dz a b) \/ (result = x2 /\ le_dz b a) end }3836= match x1, x2 with3837| None, _ -> x23838| _, None -> x13839| Some a, Some b ->3840if le_diff_zero a b then x1 else begin {proof…} total a b; lt_le b a; {qed} x2 end3841end3842
The greatest of two jumps down
Valid (26ms) (colibri2)let max_jump (x1 x2: option t) : option t3845requires { match x1, x2 with Some a, Some b -> is_not_nan a /\ is_not_nan b /\ fmt a = fmt b | _ -> true end }3846ensures { match x1, x2 with3847| None, _ -> result = x2 | _, None -> result = x13848| Some a, Some b -> (result = x1 /\ le_dz b a) \/ (result = x2 /\ le_dz a b) end }3849= match x1, x2 with3850| None, _ -> x23851| _, None -> x13852| Some a, Some b ->3853if le_diff_zero b a then x1 else begin {proof…} total b a; lt_le a b; {qed} x2 end3854end3855
The jump up for the y of l2
Valid (1.6s) (colibri2 21) (cvc5) (split_vc) (depth 1)let rec jump_lo_y (ghost fm: format) (minf pinf: t) (m: mode) (x h a b: t)3858(l2: list (t, t)) : option t3859requires { fmt minf = fm /\ fmt pinf = fm }3860requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }3861requires { fmt x = fm /\ fmt h = fm /\ le_dz x h }3862requires { fmt a = fm /\ fmt b = fm /\ le_dz a b /\ ok_u l2 /\ fmt_u fm l2 }3863ensures { match result with3864| None -> forall x'. in_iv x' x h -> no_y m x' a b l23865| Some x1 -> in_iv x1 x h /\3866forall x'. le_dz x x' -> lt_dz x' x1 -> no_y m x' a b l23867end }3868variant { l2 }3869= match l2 with3870| Nil -> None3871| Cons (c, d) r ->3872let j1 = jump_lo_iv fm minf pinf m x h a b c d in3873let j2 = jump_lo_y fm minf pinf m x h a b r in3874{proof…}3875(match j1 with None -> () | Some x1 -> le_not_nan x x1 end);3876(match j2 with None -> () | Some x2 -> le_not_nan x x2 end);3877{qed}3878let res = min_jump j1 j2 in3879{proof…}3880(match j1, j2 with3881| Some x1, Some x2 ->3882let lemma pt (x': t) : unit3883ensures { le_dz x1 x2 -> lt_dz x' x1 -> lt_dz x' x2 }3884ensures { le_dz x2 x1 -> lt_dz x' x2 -> lt_dz x' x1 }3885= lt_le_trans_any x' x1 x2; lt_le_trans_any x' x2 x1 in ()3886| None, Some x2 ->3887let lemma pt (x': t) : unit3888requires { le_dz x x' /\ lt_dz x' x2 } ensures { in_iv x' x h }3889= lt_le x' x2; le_trans x' x2 h in ()3890| Some x1, None ->3891let lemma pt (x': t) : unit3892requires { le_dz x x' /\ lt_dz x' x1 } ensures { in_iv x' x h }3893= lt_le x' x1; le_trans x' x1 h in ()3894| None, None -> ()3895end);3896{qed}3897res3898end3899
The jump down for the y of l2
Valid (746ms) (colibri2 21) (cvc5 3) (split_vc 2) (depth 2)let rec jump_hi_y (ghost fm: format) (minf pinf: t) (m: mode) (l x a b: t)3902(l2: list (t, t)) : option t3903requires { fmt minf = fm /\ fmt pinf = fm }3904requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }3905requires { fmt x = fm /\ fmt l = fm /\ le_dz l x }3906requires { fmt a = fm /\ fmt b = fm /\ le_dz a b /\ ok_u l2 /\ fmt_u fm l2 }3907ensures { match result with3908| None -> forall x'. in_iv x' l x -> no_y m x' a b l23909| Some x1 -> in_iv x1 l x /\3910forall x'. lt_dz x1 x' -> le_dz x' x -> no_y m x' a b l23911end }3912variant { l2 }3913= match l2 with3914| Nil -> None3915| Cons (c, d) r ->3916let j1 = jump_hi_iv fm minf pinf m l x a b c d in3917let j2 = jump_hi_y fm minf pinf m l x a b r in3918{proof…}3919(match j1 with None -> () | Some x1 -> le_not_nan x1 x end);3920(match j2 with None -> () | Some x2 -> le_not_nan x2 x end);3921{qed}3922let res = max_jump j1 j2 in3923{proof…}3924(match j1, j2 with3925| Some x1, Some x2 ->3926let lemma pt (x': t) : unit3927ensures { le_dz x2 x1 -> lt_dz x1 x' -> lt_dz x2 x' }3928ensures { le_dz x1 x2 -> lt_dz x2 x' -> lt_dz x1 x' }3929= le_lt_trans_any x2 x1 x'; le_lt_trans_any x1 x2 x' in ()3930| None, Some x2 ->3931let lemma pt (x': t) : unit3932requires { lt_dz x2 x' /\ le_dz x' x } ensures { in_iv x' l x }3933= lt_le x2 x'; le_trans l x2 x' in ()3934| Some x1, None ->3935let lemma pt (x': t) : unit3936requires { lt_dz x1 x' /\ le_dz x' x } ensures { in_iv x' l x }3937= lt_le x1 x'; le_trans l x1 x' in ()3938| None, None -> ()3939end);3940{qed}3941res3942end3943
The jump up for the sums of l1 and the y of l2
Valid (1.5s) (cvc5)let rec jump_lo_u (ghost fm: format) (minf pinf: t) (m: mode) (x h: t)3946(l1 l2: list (t, t)) : option t3947requires { fmt minf = fm /\ fmt pinf = fm }3948requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }3949requires { fmt x = fm /\ fmt h = fm /\ le_dz x h }3950requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }3951ensures { match result with3952| None -> forall x'. in_iv x' x h -> no_add m x' l1 l23953| Some x1 -> in_iv x1 x h /\3954forall x'. le_dz x x' -> lt_dz x' x1 -> no_add m x' l1 l23955end }3956variant { l1 }3957= match l1 with3958| Nil -> None3959| Cons (a, b) r ->3960let j1 = jump_lo_y fm minf pinf m x h a b l2 in3961let j2 = jump_lo_u fm minf pinf m x h r l2 in3962{proof…}3963(match j1 with None -> () | Some x1 -> le_not_nan x x1 end);3964(match j2 with None -> () | Some x2 -> le_not_nan x x2 end);3965{qed}3966let res = min_jump j1 j2 in3967{proof…}3968(match j1, j2 with3969| Some x1, Some x2 ->3970let lemma pt (x': t) : unit3971ensures { le_dz x1 x2 -> lt_dz x' x1 -> lt_dz x' x2 }3972ensures { le_dz x2 x1 -> lt_dz x' x2 -> lt_dz x' x1 }3973= lt_le_trans_any x' x1 x2; lt_le_trans_any x' x2 x1 in ()3974| None, Some x2 ->3975let lemma pt (x': t) : unit3976requires { le_dz x x' /\ lt_dz x' x2 } ensures { in_iv x' x h }3977= lt_le x' x2; le_trans x' x2 h in ()3978| Some x1, None ->3979let lemma pt (x': t) : unit3980requires { le_dz x x' /\ lt_dz x' x1 } ensures { in_iv x' x h }3981= lt_le x' x1; le_trans x' x1 h in ()3982| None, None -> ()3983end);3984{qed}3985res3986end3987
The jump down for the sums of l1 and the y of l2
Valid (332ms) (colibri2 21) (cvc5 2) (split_vc 2) (depth 2)let rec jump_hi_u (ghost fm: format) (minf pinf: t) (m: mode) (l x: t)3990(l1 l2: list (t, t)) : option t3991requires { fmt minf = fm /\ fmt pinf = fm }3992requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }3993requires { fmt x = fm /\ fmt l = fm /\ le_dz l x }3994requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }3995ensures { match result with3996| None -> forall x'. in_iv x' l x -> no_add m x' l1 l23997| Some x1 -> in_iv x1 l x /\3998forall x'. lt_dz x1 x' -> le_dz x' x -> no_add m x' l1 l23999end }4000variant { l1 }4001= match l1 with4002| Nil -> None4003| Cons (a, b) r ->4004let j1 = jump_hi_y fm minf pinf m l x a b l2 in4005let j2 = jump_hi_u fm minf pinf m l x r l2 in4006{proof…}4007(match j1 with None -> () | Some x1 -> le_not_nan x1 x end);4008(match j2 with None -> () | Some x2 -> le_not_nan x2 x end);4009{qed}4010let res = max_jump j1 j2 in4011{proof…}4012(match j1, j2 with4013| Some x1, Some x2 ->4014let lemma pt (x': t) : unit4015ensures { le_dz x2 x1 -> lt_dz x1 x' -> lt_dz x2 x' }4016ensures { le_dz x1 x2 -> lt_dz x2 x' -> lt_dz x1 x' }4017= le_lt_trans_any x2 x1 x'; le_lt_trans_any x1 x2 x' in ()4018| None, Some x2 ->4019let lemma pt (x': t) : unit4020requires { lt_dz x2 x' /\ le_dz x' x } ensures { in_iv x' l x }4021= lt_le x2 x'; le_trans l x2 x' in ()4022| Some x1, None ->4023let lemma pt (x': t) : unit4024requires { lt_dz x1 x' /\ le_dz x' x } ensures { in_iv x' l x }4025= lt_le x1 x'; le_trans l x1 x' in ()4026| None, None -> ()4027end);4028{qed}4029res4030end4031
The least x' of [l, h] such that the floats of [l, x') are no_add, after at most fuel jumps; None when all [l, h] is
Valid (633ms) (cvc5)let rec shave_lo (ghost fm: format) (minf pinf: t) (m: mode)4035(l1 l2: list (t, t)) (fuel: int63) (l h: t) : option t4036requires { fmt minf = fm /\ fmt pinf = fm }4037requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4038requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }4039requires { fmt l = fm /\ fmt h = fm /\ le_dz l h }4040ensures { match result with4041| None -> forall x. in_iv x l h -> no_add m x l1 l24042| Some l' -> in_iv l' l h /\4043forall x. le_dz l x -> lt_dz x l' -> no_add m x l1 l2 end }4044variant { fuel }4045= {proof…} le_not_nan l h; le_refl l; {qed}4046if fuel <= 0 then begin4047{proof…}4048let lemma no (x: t) : unit4049requires { le_dz l x /\ lt_dz x l } ensures { false }4050= lt_not_le x l in4051{qed}4052Some l4053end else4054match jump_lo_u fm minf pinf m l h l1 l2 with4055| None -> None4056| Some l' ->4057if le_diff_zero l' l then begin4058{proof…}4059let lemma no (x: t) : unit4060requires { le_dz l x /\ lt_dz x l } ensures { false }4061= lt_not_le x l in4062{qed}4063Some l4064end else begin4065let res = shave_lo fm minf pinf m l1 l2 (fuel - 1) l' h in4066{proof…}4067let lemma split (x: t) : unit4068requires { le_dz l x } ensures { lt_dz x l' \/ le_dz l' x }4069= le_not_nan l x; le_not_nan l l'; total l' x;4070lt_le_any x l'; total_any x l' in4071(match res with4072| None ->4073let lemma pt (x: t) : unit4074requires { in_iv x l h } ensures { no_add m x l1 l2 }4075= split x in ()4076| Some l'' ->4077le_trans l l' l'';4078let lemma pt (x: t) : unit4079requires { le_dz l x /\ lt_dz x l'' } ensures { no_add m x l1 l2 }4080= split x in ()4081end);4082{qed}4083res4084end4085end4086
The greatest x' of [l, h] such that the floats of (x', h] are no_add, symmetric to shave_lo
Valid (638ms) (cvc5)let rec shave_hi (ghost fm: format) (minf pinf: t) (m: mode)4090(l1 l2: list (t, t)) (fuel: int63) (l h: t) : option t4091requires { fmt minf = fm /\ fmt pinf = fm }4092requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4093requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }4094requires { fmt l = fm /\ fmt h = fm /\ le_dz l h }4095ensures { match result with4096| None -> forall x. in_iv x l h -> no_add m x l1 l24097| Some h' -> in_iv h' l h /\4098forall x. lt_dz h' x -> le_dz x h -> no_add m x l1 l2 end }4099variant { fuel }4100= {proof…} le_not_nan l h; le_refl h; {qed}4101if fuel <= 0 then begin4102{proof…}4103let lemma no (x: t) : unit4104requires { lt_dz h x /\ le_dz x h } ensures { false }4105= lt_not_le h x in4106{qed}4107Some h4108end else4109match jump_hi_u fm minf pinf m l h l1 l2 with4110| None -> None4111| Some h' ->4112if le_diff_zero h h' then begin4113{proof…}4114let lemma no (x: t) : unit4115requires { lt_dz h x /\ le_dz x h } ensures { false }4116= lt_not_le h x in4117{qed}4118Some h4119end else begin4120let res = shave_hi fm minf pinf m l1 l2 (fuel - 1) l h' in4121{proof…}4122let lemma split (x: t) : unit4123requires { le_dz x h } ensures { lt_dz h' x \/ le_dz x h' }4124= le_not_nan x h; le_not_nan h' h; total x h';4125lt_le_any h' x; total_any h' x in4126(match res with4127| None ->4128let lemma pt (x: t) : unit4129requires { in_iv x l h } ensures { no_add m x l1 l2 }4130= split x in ()4131| Some h'' ->4132le_trans h'' h' h;4133let lemma pt (x: t) : unit4134requires { lt_dz h'' x /\ le_dz x h } ensures { no_add m x l1 l2 }4135= split x in ()4136end);4137{qed}4138res4139end4140end4141
The steps of the shaving at each end
let constant shave_fuel : int63 = 44144
The floats of a list, ends shaved
Valid (381ms) (colibri2 29) (cvc4) (cvc5 4) (split_vc) (depth 1)let rec shave_u (ghost fm: format) (minf pinf: t) (m: mode)4147(l1 l2 xs: list (t, t)) : list (t, t)4148requires { fmt minf = fm /\ fmt pinf = fm }4149requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4150requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }4151requires { ok_u xs /\ fmt_u fm xs }4152ensures { ok_u result /\ fmt_u fm result }4153ensures { forall v. mem_u v result -> mem_u v xs }4154ensures { forall v. mem_u v xs -> not no_add m v l1 l2 -> mem_u v result }4155variant { xs }4156= match xs with4157| Nil -> Nil4158| Cons (a, b) r ->4159let r' = shave_u fm minf pinf m l1 l2 r in4160{proof…}4161(match r with Nil -> () | Cons _ _ -> sorted_above b r end);4162assert { above b r' };4163above_head b r';4164{qed}4165match shave_lo fm minf pinf m l1 l2 shave_fuel a b with4166| None -> r'4167| Some a' ->4168match shave_hi fm minf pinf m l1 l2 shave_fuel a' b with4169| None ->4170{proof…}4171let lemma pt (v: t) : unit4172requires { in_iv v a b } ensures { no_add m v l1 l2 }4173= le_not_nan a v; total v a';4174if pure { le_dz a' v } then () in4175{qed}4176r'4177| Some b' ->4178{proof…}4179le_trans a a' b';4180(match r' with Nil -> () | Cons (c, _) _ -> le_lt_trans b' b c end);4181let lemma pt (v: t) : unit4182requires { in_iv v a b /\ not no_add m v l1 l2 } ensures { in_iv v a' b' }4183= le_not_nan a v; total v a'; total b' v;4184if pure { lt_dz v a' } then absurd;4185if pure { lt_dz b' v } then absurd in4186let lemma inc (v: t) : unit4187requires { in_iv v a' b' } ensures { in_iv v a b }4188= le_trans a a' v; le_trans v b' b in4189{qed}4190Cons (a', b') r'4191end4192end4193end4194
The x of d, ends shaved: every x of d with x + y in r for some y of e is kept. Nothing is shaved when r has NaN.
Valid (424ms) (cvc5)let add_shave (ghost fm: format) (minf pinf: t) (m: mode) (r e d: dom) : dom4198requires { fmt minf = fm /\ fmt pinf = fm }4199requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4200requires { r.fm = fm /\ e.fm = fm /\ d.fm = fm }4201ensures { result.fm = fm }4202ensures { forall v. mem v result -> mem v d }4203ensures { forall x y. mem x d -> mem y e -> mem (fp_add m x y) r -> mem x result }4204= if r.nan then d4205else begin4206let u = shave_u fm minf pinf m r.u e.u d.u in4207let res = { u = u; nan = d.nan; fm = fm } in4208{proof…}4209let lemma pt (x y: t) : unit4210requires { mem x d /\ mem y e /\ mem (fp_add m x y) r }4211ensures { mem x res }4212= add_special m x y;4213if pure { is_not_nan x } then begin4214assert { mem_u y e.u };4215assert { not no_add m x r.u e.u }4216end in4217{qed}4218res4219end4220
Exact: the x such that abs x is in d, that is the positive floats of d and their opposites (and NaN).
Valid (659ms) (colibri2 12) (cvc5 3) (split_vc) (depth 1)let abs_back (ghost fm: format) (pz pinf: t) (d: dom) : dom4226requires { fmt pz = fm /\ fmt pinf = fm /\ d.fm = fm }4227ensures { result.fm = fm }4228requires { at_index fm pz 0 /\ pinf = (plus_infinity fm) }4229ensures { forall x. mem x result <-> mem (abs x) d }4230= let pos = match inter fm d (positives fm pz pinf) with4231| None -> (empty_dom fm)4232| Some p -> union fm p (neg_dom fm p)4233end in4234let r = if d.nan then union fm (nan_dom fm) pos else pos in4235{proof…}4236let lemma pt (x: t) : unit4237ensures { mem x r <-> mem (abs x) d }4238= if is_nan x then assert { is_nan (abs x) }4239else begin4240index_range x;4241if pure { is_positive x } then begin4242assert { abs x = x by of_index fm (index (abs x)) = of_index fm (index x) };4243assert { not is_positive (neg x) }4244end else begin4245neg_neg x;4246assert { abs x = neg x by4247of_index fm (index (abs x)) = of_index fm (index (neg x)) };4248assert { is_positive (neg x) }4249end4250end in4251{qed}4252r4253
The positive x whose square root is in [a, b]: above pa * pa rounded down, below sb * sb rounded up, where pa is the float below a and sb the float above b (Facts.sqrt_lower, sqrt_upper). The negative x are –0, whose square root is computed, and the ones whose square root is NaN.
The least positive float y >= c whose square root is at least a, from a lower bound c of those floats
Valid (988ms) (colibri2)let rec sqrt_lo (ghost fm: format) (pinf: t) (m: mode) (a c: t) : t4265requires { fmt pinf = fm /\ pinf = plus_infinity fm /\ fmt a = fm /\ fmt c = fm }4266requires { is_not_nan a /\ is_not_nan c /\ is_positive c }4267requires { forall x. fmt x = fm -> is_not_nan x -> is_positive x ->4268le_dz a (fp_sqrt m x) -> le_dz c x }4269ensures { is_not_nan result /\ is_positive result /\ fmt result = fm }4270ensures { forall x. fmt x = fm -> is_not_nan x -> is_positive x ->4271le_dz a (fp_sqrt m x) -> le_dz result x }4272variant { index pinf - index c }4273= {proof…}4274sqrt_positive m c; index_range c; index_range pinf;4275{qed}4276if lt_diff_zero (sqrt m c) a then begin4277{proof…}4278if pure { is_plus_infinity c } then begin4279assert { ext c = PInf };4280assert { fp_sqrt m c = plus_infinity fm };4281lt_not_plus_infinity (fp_sqrt m c) a; absurd4282end;4283succ_gt c; index_range (succ_dz c);4284let lemma pt (x: t) : unit4285requires { fmt x = fm /\ is_not_nan x /\ is_positive x /\ le_dz a (fp_sqrt m x) }4286ensures { le_dz (succ_dz c) x }4287= total x c;4288if pure { le_dz x c } then begin4289sqrt_positive m x;4290sqrt_le m x c;4291le_lt_trans (fp_sqrt m x) (fp_sqrt m c) a;4292lt_not_le (fp_sqrt m x) a;4293absurd4294end;4295succ_least c x in4296le_positive c (succ_dz c);4297{qed}4298sqrt_lo fm pinf m a (succ_diff_zero c)4299end else c4300
The greatest float y <= c whose square root is at most b (or a negative float), from an upper bound c of the positive ones
Valid (520ms) (cvc4)let rec sqrt_hi (ghost fm: format) (pz: t) (m: mode) (b c: t) : t4304requires { fmt pz = fm /\ at_index fm pz 0 /\ fmt b = fm /\ fmt c = fm }4305requires { is_not_nan b /\ is_not_nan c }4306requires { forall x. fmt x = fm -> is_not_nan x -> is_positive x ->4307le_dz (fp_sqrt m x) b -> le_dz x c }4308ensures { is_not_nan result /\ fmt result = fm }4309ensures { forall x. fmt x = fm -> is_not_nan x -> is_positive x ->4310le_dz (fp_sqrt m x) b -> le_dz x result }4311variant { index c }4312= {proof…}4313index_range c;4314{qed}4315if lt_diff_zero c pz then c4316else begin4317{proof…} sqrt_positive m c; {qed}4318if lt_diff_zero b (sqrt m c) then begin4319{proof…}4320assert { 0 <= index c };4321if pure { is_minus_infinity c } then absurd;4322pred_lt c; index_range (pred_dz c);4323let lemma pt (x: t) : unit4324requires { fmt x = fm /\ is_not_nan x /\ is_positive x /\ le_dz (fp_sqrt m x) b }4325ensures { le_dz x (pred_dz c) }4326= total c x;4327if pure { le_dz c x } then begin4328sqrt_positive m x;4329sqrt_le m c x;4330lt_le_trans b (fp_sqrt m c) (fp_sqrt m x);4331lt_not_le b (fp_sqrt m x);4332absurd4333end;4334pred_greatest c x in4335{qed}4336sqrt_hi fm pz m b (pred_diff_zero c)4337end else c4338end4339Valid (1.7s) (colibri2 51) (cvc4 4) (cvc5 14) (split_vc) (depth 1)4340let sqrt_back_iv (ghost fm: format) (pinf pz: t) (m: mode) (a b: t) : dom4341requires { fmt pinf = fm /\ fmt pz = fm }4342requires { pinf = plus_infinity fm /\ at_index fm pz 0 }4343requires { fmt a = fm /\ fmt b = fm /\ le_dz a b }4344ensures { result.fm = fm }4345ensures { forall x. fmt x = fm -> is_not_nan x -> is_positive x ->4346in_iv (fp_sqrt m x) a b -> mem x result }4347= {proof…}4348le_not_nan a b; index_range a; index_range b; index_range pinf;4349{qed}4350let lo =4351if le_diff_zero a pz then pz4352else begin4353let pa = pred_diff_zero a in4354{proof…}4355pred_lt a; of_index_range fm (index a - 1); index_range pa;4356assert { is_positive pa };4357mul_special rtn pa pa;4358{qed}4359let l = mul rtn pa pa in4360{proof…}4361round_f_down fm false (emul (ext pa) (ext pa));4362if pure { is_plus_infinity l } then begin4363assert { ext l = PInf };4364assert { is_plus_infinity pa };4365lt_not_plus_infinity pa a; absurd4366end;4367succ_gt l;4368let lemma pt (x: t) : unit4369requires { fmt x = fm /\ is_not_nan x /\ is_positive x /\ le_dz a (fp_sqrt m x) }4370ensures { le_dz (succ_dz l) x }4371= sqrt_lower m pa a x; succ_least l x in4372round_f_le fm rtn false false (Fin 0.0) (emul (ext pa) (ext pa));4373le_positive (round_f fm rtn false (Fin 0.0)) l;4374le_positive l (succ_dz l);4375{qed}4376sqrt_lo fm pinf m a (succ_diff_zero l)4377end in4378let hi =4379if is_pinf fm pinf b then Some pinf4380else if lt_diff_zero b pz then None4381else begin4382let sb = succ_diff_zero b in4383{proof…}4384succ_gt b; of_index_range fm (index b + 1); index_range sb;4385assert { is_positive sb };4386mul_special rtp sb sb;4387{qed}4388let u = mul rtp sb sb in4389{proof…}4390round_f_up fm false (emul (ext sb) (ext sb));4391ext_sign sb;4392if pure { is_minus_infinity u } then begin4393assert { ext u = MInf };4394absurd4395end;4396pred_lt u;4397let lemma pt (x: t) : unit4398requires { fmt x = fm /\ is_not_nan x /\ is_positive x /\ le_dz (fp_sqrt m x) b }4399ensures { le_dz x (pred_dz u) }4400= sqrt_upper m sb b x; pred_greatest u x in4401{qed}4402Some (sqrt_hi fm pz m b (pred_diff_zero u))4403end in4404match hi with4405| Some hi ->4406{proof…}4407let lemma pt (x: t) : unit4408requires { fmt x = fm /\ is_not_nan x /\ is_positive x /\ in_iv (fp_sqrt m x) a b }4409ensures { le_dz lo x /\ le_dz x hi }4410= index_range x;4411if pure { is_plus_infinity b } then begin4412if pure { is_plus_infinity x } then begin4413plus_infinity_unique x; le_refl x4414end else begin4415lt_plus_infinity x; lt_le x pinf4416end4417end in4418{qed}4419if lt_diff_zero hi lo then begin4420{proof…}4421let lemma no (x: t) : unit4422requires { fmt x = fm /\ is_not_nan x /\ is_positive x /\ in_iv (fp_sqrt m x) a b }4423ensures { false }4424= pt x; le_trans lo x hi; lt_not_le hi lo in4425{qed}4426empty_dom fm4427end else begin4428{proof…} total lo hi; {qed}4429interval fm lo hi4430end4431| None ->4432{proof…}4433let lemma no (x: t) : unit4434requires { fmt x = fm /\ is_not_nan x /\ is_positive x /\ in_iv (fp_sqrt m x) a b }4435ensures { false }4436= sqrt_positive m x; le_positive (fp_sqrt m x) b in4437{qed}4438empty_dom fm4439end4440Valid (293ms) (cvc5)4441let rec sqrt_back_u (ghost fm: format) (pinf pz: t) (m: mode) (l: list (t, t)) : dom4442requires { fmt pinf = fm /\ fmt pz = fm }4443requires { pinf = plus_infinity fm /\ at_index fm pz 0 }4444requires { ok_u l /\ fmt_u fm l }4445ensures { result.fm = fm }4446ensures { forall x. fmt x = fm -> is_not_nan x -> is_positive x ->4447mem_u (fp_sqrt m x) l -> mem x result }4448variant { l }4449= match l with4450| Nil -> empty_dom fm4451| Cons (a, b) r ->4452union fm (sqrt_back_iv fm pinf pz m a b) (sqrt_back_u fm pinf pz m r)4453end4454
The x such that sqrt x is in r
Valid (759ms) (colibri2 26) (cvc4) (cvc5 4) (split_vc) (depth 1)let sqrt_back (ghost fm: format) (minf pinf nz pz: t) (m: mode) (r: dom) : dom4457requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }4458requires { specials4 fm minf pinf nz pz }4459requires { r.fm = fm }4460ensures { result.fm = fm }4461ensures { forall x. fmt x = fm -> mem (fp_sqrt m x) r -> mem x result }4462= {proof…}4463format_facts fm (); index_range nz; index_range minf; of_index_range fm (-2);4464{qed}4465let u = sqrt_back_u fm pinf pz m r.u in4466let s = sqrt m nz in4467{proof…} sqrt_special m nz; index_range s; {qed}4468let z = if meets fm s s r then singleton fm nz else empty_dom fm in4469let n =4470if r.nan then begin4471let pnz = pred_diff_zero nz in4472{proof…} pred_lt nz; minus_infinity_lt pnz; lt_le minf pnz; {qed}4473union fm (nan_dom fm) (interval fm minf pnz)4474end else empty_dom fm in4475let res = union fm n (union fm z u) in4476{proof…}4477let lemma pt (x: t) : unit4478requires { fmt x = fm /\ mem (fp_sqrt m x) r }4479ensures { mem x res }4480= sqrt_special m x;4481if pure { is_not_nan x } then begin4482index_range x;4483if pure { is_positive x } then ()4484else if pure { is_zero x } then begin4485assert { index x = -1 };4486assert { x = nz by of_index fm (index x) = of_index fm (index nz) };4487assert { index (fp_sqrt m x) = index s }4488end else begin4489assert { index x <= -2 };4490minus_infinity_unique minf; index_range minf;4491assert { in_iv x minf (pred_dz nz) }4492end4493end in4494{qed}4495res4496
Direct, as add_lo: the floats x with a <= roundToIntegral x have round_int m x at or above t = thr_lo a (in the format with one more bit), so at or above n = round_int RTP t, so x is at or above int_thr_lo m n, rounded up in the format. One step up when that float itself rounds below a (the ties of RNE and RNA, the strict bounds of RTP and RTZ). Sound for any mode; exact in the usual cases (tested against the floats of small formats).
The value of x, finite
Valid (36ms) (colibri2)let ghost fin_val (x: t) : real4509requires { is_not_nan x /\ not is_infinity x }4510ensures { ext x = Fin result /\ to_real x = result }4511= {proof…} match ext x with Fin v -> v | _ -> absurd end {qed}4512
At most fuel steps up from c, a lower bound of the x with a <= roundToIntegral x, while c itself rounds below a
Valid (127ms) (cvc5)let rec rti_up (ghost fm: format) (pinf: t) (m: mode) (a c: t) (fuel: int) : t4516requires { fmt pinf = fm /\ pinf = plus_infinity fm }4517requires { fmt a = fm /\ is_not_nan a /\ fmt c = fm /\ is_not_nan c }4518requires { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_rti m x) -> le_dz c x }4519ensures { fmt result = fm /\ is_not_nan result }4520ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_rti m x) -> le_dz result x }4521variant { fuel }4522= if fuel <= 0 || is_pinf fm pinf c then c4523else if lt_diff_zero (round_to_integral m c) a then begin4524{proof…}4525let lemma step (x: t) : unit4526requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_rti m x) }4527ensures { le_dz (succ_dz c) x }4528= if pure { x = c } then begin lt_not_le (fp_rti m c) a; absurd end;4529index_range x; index_range c;4530assert { index x <> index c };4531assert { lt_dz c x };4532succ_least c x in4533succ_gt c;4534{qed}4535rti_up fm pinf m a (succ_diff_zero c) (fuel - 1)4536end else c4537
At most fuel steps down from c, an upper bound of the x with roundToIntegral x <= b, while c itself rounds above b
Valid (114ms) (cvc5)let rec rti_down (ghost fm: format) (minf: t) (m: mode) (b c: t) (fuel: int) : t4541requires { fmt minf = fm /\ minf = minus_infinity fm }4542requires { fmt b = fm /\ is_not_nan b /\ fmt c = fm /\ is_not_nan c }4543requires { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_rti m x) b -> le_dz x c }4544ensures { fmt result = fm /\ is_not_nan result }4545ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_rti m x) b -> le_dz x result }4546variant { fuel }4547= if fuel <= 0 || is_minf fm minf c then c4548else if lt_diff_zero b (round_to_integral m c) then begin4549{proof…}4550let lemma step (x: t) : unit4551requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_rti m x) b }4552ensures { le_dz x (pred_dz c) }4553= if pure { x = c } then begin lt_not_le b (fp_rti m c); absurd end;4554index_range x; index_range c;4555assert { index x <> index c };4556assert { lt_dz x c };4557pred_greatest c x in4558pred_lt c;4559{qed}4560rti_down fm minf m b (pred_diff_zero c) (fuel - 1)4561end else c4562Valid (463ms) (colibri2 77) (cvc4) (cvc5 7) (split_vc) (depth 1)4563let rti_lo (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode) (a: t) : t4564requires { widens fm fm' /\ fmt a = fm /\ fmt minf = fm /\ fmt pinf = fm }4565requires { fmt nz = fm /\ fmt pz = fm }4566requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4567requires { at_index fm nz (-1) /\ at_index fm pz 0 /\ is_not_nan a }4568ensures { fmt result = fm /\ is_not_nan result }4569ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_rti m x) -> le_dz result x }4570= if is_minf fm minf a then begin4571{proof…}4572let lemma pt (x: t) : unit4573requires { fmt x = fm /\ is_not_nan x } ensures { le_dz minf x }4574= index_range x; index_range minf in4575{qed}4576minf4577end else if is_pz fm pz a && lt_diff_zero (round_to_integral m nz) a then begin4578(* `roundToIntegral` keeps the sign of a zero: only the positive floats reach +0 *)4580{proof…}4581let lemma pt (x: t) : unit4582requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_rti m x) } ensures { le_dz pz x }4583= index_range x;4584if pure { index x < 0 } then begin4585assert { le_dz x nz };4586rti_le m x nz; le_trans a (fp_rti m x) (fp_rti m nz);4587lt_not_le (fp_rti m nz) a; absurd4588end in4589{qed}4590pz4591end else begin4592let fr = format_of a in4593let t = thr_lo fm fm' nz pz m a in4594let minf' = convert fm' rtn minf in4595let pinf' = convert fm' rtn pinf in4596{proof…}4597assert { ext minf' = MInf /\ ext pinf' = PInf };4598convert_not_nan fm' rtn minf; convert_not_nan fm' rtn pinf;4599(* the floats `x` that reach `a`: their integer is above `t` *)4600let lemma reach (x: t) : unit4601requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_rti m x) }4602ensures { not is_minus_infinity x }4603ensures { not is_infinity x -> ele (ext t) (Fin (from_int (round_int m (to_real x)))) }4604= if pure { is_minus_infinity x } then begin4605assert { ext (fp_rti m x) = MInf };4606ext_le a (fp_rti m x); absurd4607end in4608{qed}4609if le_diff_zero t minf' then begin4610{proof…}4611let lemma pt (x: t) : unit4612requires { fmt x = fm /\ is_not_nan x } ensures { le_dz minf x }4613= index_range x; index_range minf in4614{qed}4615rti_up fm pinf m a minf 24616end else if le_diff_zero pinf' t then begin4617{proof…}4618let lemma pt (x: t) : unit4619requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_rti m x) }4620ensures { le_dz pinf x }4621= reach x;4622if pure { not is_infinity x } then begin4623index_range t; index_range pinf'; assert { ext t = PInf }; absurd4624end in4625{qed}4626pinf4627end else begin4628{proof…}4629index_range t; index_range pinf'; index_range minf'; assert { not is_infinity t };4630{qed}4631let a0 = if is_zero_f fm nz pz a then nz else a in4632let ct = convert fr m t in4633let strict = not (le_diff_zero a0 ct) in4634let n = if strict then round_int_v rtn t + 1 else round_int_v rtp t in4635{proof…}4636convert_not_nan fm m t;4637assert { le_dz a0 a /\ fmt a0 = fm /\ is_not_nan a0 };4638(* `t` rounds below `a0`: the integers are strictly above `t` *)4639let lemma nk (x: t) : unit4640requires { fmt x = fm /\ is_not_nan x /\ not is_infinity x /\ le_dz a (fp_rti m x) }4641ensures { n <= round_int m (to_real x) }4642= reach x;4643let ghost r = fin_val x in4644let ghost tt = fin_val t in4645let ghost k = round_int m r in4646if strict then begin4647if pure { from_int k = tt } then begin4648let ghost zx = if is_positive x then false else true in4649let ghost zt = if is_positive t then false else true in4650assert { fp_rti m x = round_f fm m zx (ext t) };4651assert { ct = round_f fm m zt (ext t) };4652round_f_val fm m zx zt (ext t);4653total a0 ct;4654assert { lt_dz ct a0 };4655assert { not (is_zero ct /\ is_zero a0) by is_zero a0 -> a0 = nz };4656assert { not ele (ext a0) (ext ct) };4657ext_le a (fp_rti m x); ext_le a0 a;4658absurd4659end;4660round_int_ge RTN tt (round_int RTN tt)4661end else round_int_ceil tt k in4662{qed}4663let k = match m with4664| RTN -> 2 * n4665| RTP -> 2 * n - 24666| RTZ -> if 0 < n then 2 * n else 2 * n - 24667| RNE | RNA -> 2 * n - 14668end in4669let c0 = of_q fr rtp true k 2 in4670let c = if is_zero_f fm nz pz c0 then nz else c0 in4671{proof…}4672assert { from_int k /. 2.0 = int_thr_lo m n };4673let lemma above (x: t) : unit4674requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_rti m x) }4675ensures { le_dz c x }4676= reach x;4677if pure { is_plus_infinity x } then begin4678index_range x; index_range c4679end else begin4680let ghost r = fin_val x in4681let ghost tt = fin_val t in4682nk x;4683round_int_ge m r n;4684let ghost zx = if is_positive x then false else true in4685convert_exact rtp x;4686assert { round_f fm rtp zx (ext x) = x };4687round_f_ele fm rtp true zx (Fin (from_int k /. 2.0)) (ext x);4688assert { ele (ext c) (ext x) };4689ele_le c x4690end in4691{qed}4692rti_up fm pinf m a c 24693end4694end4695Valid (413ms) (colibri2 77) (cvc4) (cvc5 7) (split_vc) (depth 1)4696let rti_hi (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode) (b: t) : t4697requires { widens fm fm' /\ fmt b = fm /\ fmt minf = fm /\ fmt pinf = fm }4698requires { fmt nz = fm /\ fmt pz = fm }4699requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4700requires { at_index fm nz (-1) /\ at_index fm pz 0 /\ is_not_nan b }4701ensures { fmt result = fm /\ is_not_nan result }4702ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_rti m x) b -> le_dz x result }4703= if is_pinf fm pinf b then begin4704{proof…}4705let lemma pt (x: t) : unit4706requires { fmt x = fm /\ is_not_nan x } ensures { le_dz x pinf }4707= index_range x; index_range pinf in4708{qed}4709pinf4710end else if is_nz fm nz b && lt_diff_zero b (round_to_integral m pz) then begin4711(* only the negative floats reach -0 or below *)4712{proof…}4713let lemma pt (x: t) : unit4714requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_rti m x) b } ensures { le_dz x nz }4715= index_range x;4716if pure { 0 <= index x } then begin4717assert { le_dz pz x };4718rti_le m pz x; le_trans (fp_rti m pz) (fp_rti m x) b;4719lt_not_le b (fp_rti m pz); absurd4720end in4721{qed}4722nz4723end else begin4724let fr = format_of b in4725let t = thr_hi fm fm' nz pz m b in4726let minf' = convert fm' rtn minf in4727let pinf' = convert fm' rtn pinf in4728{proof…}4729assert { ext minf' = MInf /\ ext pinf' = PInf };4730convert_not_nan fm' rtn minf; convert_not_nan fm' rtn pinf;4731let lemma reach (x: t) : unit4732requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_rti m x) b }4733ensures { not is_plus_infinity x }4734ensures { not is_infinity x -> ele (Fin (from_int (round_int m (to_real x)))) (ext t) }4735= if pure { is_plus_infinity x } then begin4736assert { ext (fp_rti m x) = PInf };4737ext_le (fp_rti m x) b; absurd4738end in4739{qed}4740if le_diff_zero pinf' t then begin4741{proof…}4742let lemma pt (x: t) : unit4743requires { fmt x = fm /\ is_not_nan x } ensures { le_dz x pinf }4744= index_range x; index_range pinf in4745{qed}4746rti_down fm minf m b pinf 24747end else if le_diff_zero t minf' then begin4748{proof…}4749let lemma pt (x: t) : unit4750requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_rti m x) b }4751ensures { le_dz x minf }4752= reach x;4753if pure { not is_infinity x } then begin4754index_range t; index_range minf'; assert { ext t = MInf }; absurd4755end in4756{qed}4757minf4758end else begin4759{proof…}4760index_range t; index_range pinf'; index_range minf'; assert { not is_infinity t };4761{qed}4762let b0 = if is_zero_f fm nz pz b then pz else b in4763let ct = convert fr m t in4764let strict = not (le_diff_zero ct b0) in4765let n = if strict then round_int_v rtp t - 1 else round_int_v rtn t in4766{proof…}4767convert_not_nan fm m t;4768assert { le_dz b b0 /\ fmt b0 = fm /\ is_not_nan b0 };4769(* `t` rounds above `b0`: the integers are strictly below `t` *)4770let lemma nk (x: t) : unit4771requires { fmt x = fm /\ is_not_nan x /\ not is_infinity x /\ le_dz (fp_rti m x) b }4772ensures { round_int m (to_real x) <= n }4773= reach x;4774let ghost r = fin_val x in4775let ghost tt = fin_val t in4776let ghost k = round_int m r in4777if strict then begin4778if pure { from_int k = tt } then begin4779let ghost zx = if is_positive x then false else true in4780let ghost zt = if is_positive t then false else true in4781assert { fp_rti m x = round_f fm m zx (ext t) };4782assert { ct = round_f fm m zt (ext t) };4783round_f_val fm m zx zt (ext t);4784total ct b0;4785assert { lt_dz b0 ct };4786assert { not (is_zero ct /\ is_zero b0) by is_zero b0 -> b0 = pz };4787assert { not ele (ext ct) (ext b0) };4788ext_le (fp_rti m x) b; ext_le b b0;4789absurd4790end;4791round_int_le RTP tt (round_int RTP tt)4792end else round_int_floor tt k in4793{qed}4794let k = match m with4795| RTN -> 2 * n + 24796| RTP -> 2 * n4797| RTZ -> if n < 0 then 2 * n else 2 * n + 24798| RNE | RNA -> 2 * n + 14799end in4800let c0 = of_q fr rtn false k 2 in4801let c = if is_zero_f fm nz pz c0 then pz else c0 in4802{proof…}4803assert { from_int k /. 2.0 = int_thr_hi m n };4804let lemma below (x: t) : unit4805requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_rti m x) b }4806ensures { le_dz x c }4807= reach x;4808if pure { is_minus_infinity x } then begin4809index_range x; index_range c4810end else begin4811let ghost r = fin_val x in4812let ghost tt = fin_val t in4813nk x;4814round_int_le m r n;4815let ghost zx = if is_positive x then false else true in4816convert_exact rtn x;4817assert { round_f fm rtn zx (ext x) = x };4818round_f_ele fm rtn zx false (ext x) (Fin (from_int k /. 2.0));4819assert { ele (ext x) (ext c) };4820ele_le x c4821end in4822{qed}4823rti_down fm minf m b c 24824end4825end4826Valid (315ms) (colibri2 17) (cvc4 2) (cvc5 6) (split_vc) (depth 1)4827let rti_back_iv (ghost fm: format) (minf pinf: t) (m: mode) (a b: t) : dom4828requires { fmt minf = fm /\ fmt pinf = fm }4829requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4830requires { fmt a = fm /\ fmt b = fm /\ le_dz a b }4831ensures { result.fm = fm }4832ensures { forall x. fmt x = fm -> is_not_nan x -> in_iv (fp_rti m x) a b -> mem x result }4833= let fr = format_of a in4834{proof…}4835le_not_nan a b; index_range minf; index_range pinf;4836let lemma reg (x: t) : unit4837requires { fmt x = fm /\ is_not_nan x } ensures { in_iv x minf pinf }4838= index_range x in4839{qed}4840match widen fr with4841| None -> interval fm minf pinf4842| Some fm' ->4843let nz = of_index_v fr (-1) in4844let pz = of_index_v fr 0 in4845{proof…} of_index_range fm (-1); of_index_range fm 0; {qed}4846let lo = rti_lo fm fm' minf pinf nz pz m a in4847let hi = rti_hi fm fm' minf pinf nz pz m b in4848if lt_diff_zero hi lo then begin4849{proof…}4850let lemma no (x: t) : unit4851requires { fmt x = fm /\ is_not_nan x /\ in_iv (fp_rti m x) a b }4852ensures { false }4853= le_trans lo x hi; lt_not_le hi lo in4854{qed}4855empty_dom fm4856end else begin4857{proof…} total lo hi; {qed}4858interval fm lo hi4859end4860end4861Valid (424ms) (cvc5)4862let rec rti_back_u (ghost fm: format) (minf pinf: t) (m: mode)4863(l: list (t, t)) : dom4864requires { fmt minf = fm /\ fmt pinf = fm }4865requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4866requires { ok_u l /\ fmt_u fm l }4867ensures { result.fm = fm }4868ensures { forall x. fmt x = fm -> is_not_nan x -> mem_u (fp_rti m x) l -> mem x result }4869variant { l }4870= match l with4871| Nil -> empty_dom fm4872| Cons (a, b) r ->4873union fm (rti_back_iv fm minf pinf m a b) (rti_back_u fm minf pinf m r)4874end4875
The x such that roundToIntegral x is in r
Valid (306ms) (cvc5)let rti_back (ghost fm: format) (minf pinf: t) (m: mode) (r: dom) : dom4878requires { fmt minf = fm /\ fmt pinf = fm }4879requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }4880requires { r.fm = fm }4881ensures { result.fm = fm }4882ensures { forall x. fmt x = fm -> mem (fp_rti m x) r -> mem x result }4883= let u = rti_back_u fm minf pinf m r.u in4884{proof…}4885let lemma pt (x: t) : unit4886requires { fmt x = fm /\ is_nan x } ensures { is_nan (fp_rti m x) }4887= () in4888let lemma pt2 (x: t) : unit4889requires { fmt x = fm /\ is_not_nan x } ensures { is_not_nan (fp_rti m x) }4890= rti_not_nan m x in4891{qed}4892if r.nan then union fm (nan_dom fm) u else u4893
The x such that x * y is in [a, b] for some y in [c, d]. By the sign s of x and the part of [c, d]: on the finite nonzero y of one sign, x * y is monotonic in x and in y (Facts.mul_mag), and the bounds are computed directly (mul_lo_pos, mul_hi_pos) with the end of [c, d] that gives the extreme product; the zeros and the infinities of [c, d] are exact cases.
The floats of sign s: [+0, +inf] or [-inf, -0]
predicate region (fm: format) (s: bool) (lo hi: t) =4905if s then at_index fm lo 0 /\ hi = plus_infinity fm4906else lo = minus_infinity fm /\ at_index fm hi (-1)4907Valid (875ms) (colibri2 4) (cvc5 2) (split_vc) (depth 1)4908let ghost region_facts (fm: format) (s: bool) (lo hi x: t) : unit4909requires { region fm s lo hi }4910ensures { fmt lo = fm /\ fmt hi = fm /\ le_dz lo hi }4911ensures { in_iv x lo hi <-> fmt x = fm /\ is_not_nan x /\ (is_positive x <-> s) }4912= {proof…}4913index_range lo; index_range hi;4914if is_not_nan x && pure { fmt x = fm } then index_range x;4915if pure { in_iv x lo hi } then le_not_nan lo x4916{qed}4917
Finite and not zero
predicate fin_nz (y: t) = is_not_nan y /\ not is_zero y /\ not is_infinity y4920Valid (552ms) (colibri2 18) (cvc4 2) (cvc5 6) (split_vc) (depth 1)4921let ghost mul_mono (fm: format) (m: mode) (s: bool) (lo hi y: t) : unit4922requires { region fm s lo hi /\ fmt y = fm /\ fin_nz y }4923ensures { is_positive y -> forall x1 x2. in_iv x1 lo hi -> in_iv x2 lo hi ->4924le_dz x1 x2 -> le_dz (fp_mul m x1 y) (fp_mul m x2 y) }4925ensures { not is_positive y -> forall x1 x2. in_iv x1 lo hi -> in_iv x2 lo hi ->4926le_dz x1 x2 -> le_dz (fp_mul m (neg x1) y) (fp_mul m (neg x2) y) }4927= {proof…}4928le_refl y;4929let lemma nn (x: t) : unit4930requires { in_iv x lo hi }4931ensures { is_not_nan (fp_mul m x y) /\ fmt (fp_mul m x y) = fm }4932ensures { is_not_nan (fp_mul m (neg x) y) /\ fmt (fp_mul m (neg x) y) = fm }4933= region_facts fm s lo hi x; mul_special m x y; mul_special m (neg x) y;4934mul_div_fmt m x y; mul_div_fmt m (neg x) y in4935let lemma mo (x1 x2: t) : unit4936requires { in_iv x1 lo hi /\ in_iv x2 lo hi /\ le_dz x1 x2 }4937ensures { is_positive y -> le_dz (fp_mul m x1 y) (fp_mul m x2 y) }4938ensures { not is_positive y -> le_dz (fp_mul m (neg x1) y) (fp_mul m (neg x2) y) }4939= region_facts fm s lo hi x1; region_facts fm s lo hi x2; nn x1; nn x2;4940index_range x1; index_range x2;4941index_range (neg x1); index_range (neg x2);4942if s then begin4943assert { mag_le false (neg x1) (neg x2) };4944if is_positive y then mul_mag m true true x1 x2 y y4945else mul_mag m false false (neg x1) (neg x2) y y4946end else begin4947assert { mag_le true (neg x2) (neg x1) };4948if is_positive y then mul_mag m false true x2 x1 y y4949else mul_mag m true false (neg x2) (neg x1) y y4950end in4951()4952{qed}4953
For y finite and positive, the x with a <= x * y have x * y at or above t = thr_lo a (in the format fm' with one more bit), so x at or above t / y, rounded up in fm' then in fm (both monotonic, and exact on the floats of fm). Then at most two steps up while the bound itself rounds below a (ties, strict thresholds). A zero a (resp. b) keeps its sign: the product has the sign of x. Sound for any mode; the same results as the former bisection (Search) on 300000 random cases of 3 formats and the 5 modes (2026–11–09). A negative y is the positive -y on -x.
Moving a positive factor across an inequality
Valid (40ms) (colibri2 4) (split_vc) (depth 1)let ghost emul_move_ge (e ex: ereal) (v: real) : unit4968requires { 0.0 <. v /\ ele e (emul ex (Fin v)) }4969ensures { ele (ediv e (Fin v)) ex }4970= {proof…}4971assert { einv (Fin v) = Fin (1.0 /. v) };4972match e, ex with4973| Fin r, Fin w -> assert { r <=. w *. v }; assert { r /. v <=. w }4974| _ -> ()4975end4976{qed}4977Valid (838ms) (colibri2 3) (cvc5) (split_vc) (depth 1)4978let ghost emul_move_le (e ex: ereal) (v: real) : unit4979requires { 0.0 <. v /\ ele (emul ex (Fin v)) e }4980ensures { ele ex (ediv e (Fin v)) }4981= {proof…}4982assert { einv (Fin v) = Fin (1.0 /. v) };4983match e, ex with4984| Fin r, Fin w -> assert { w *. v <=. r }; assert { w <=. r /. v }4985| _ -> ()4986end4987{qed}4988Valid (2.8s) (cvc5) (split_vc) (depth 1)4989let ghost emul_eneg (a b: ereal) : unit4990ensures { emul (eneg a) (eneg b) = emul a b }4991= {proof…} () {qed}4992
The product of the opposites
Valid (290ms) (cvc4)let ghost mul_neg_neg (m: mode) (x y: t) : unit4995requires { is_not_nan x /\ is_not_nan y /\ fmt x = fmt y }4996ensures { fp_mul m (neg x) (neg y) = fp_mul m x y }4997= {proof…}4998index_range x; index_range y;4999assert { is_zero (neg x) <-> is_zero x };5000assert { is_zero (neg y) <-> is_zero y };5001assert { is_infinity (neg x) <-> is_infinity x5002by is_plus_infinity x <-> index x = nb_sign (fmt x) - 1 };5003assert { is_infinity (neg y) <-> is_infinity y5004by is_plus_infinity y <-> index y = nb_sign (fmt y) - 1 };5005assert { is_positive (neg x) <-> not is_positive x };5006assert { is_positive (neg y) <-> not is_positive y };5007assert { mul_zneg (neg x) (neg y) = mul_zneg x y };5008emul_eneg (ext x) (ext y)5009{qed}5010
The opposite reverses the order
Valid (79ms) (colibri2)let ghost neg_le (u x: t) : unit5013requires { le_dz u x }5014ensures { le_dz (neg x) (neg u) }5015= {proof…} le_not_nan u x; index_range u; index_range x {qed}5016Valid (309ms) (cvc5)5017let rec mul_trim_lo (ghost fm: format) (pinf: t) (m: mode) (a y l: t) (fuel: int) : t5018requires { fmt pinf = fm /\ pinf = plus_infinity fm }5019requires { fmt a = fm /\ fmt y = fm /\ fmt l = fm /\ is_not_nan l /\ fin_nz y }5020requires { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_mul m x y) -> le_dz l x }5021ensures { fmt result = fm /\ is_not_nan result }5022ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_mul m x y) -> le_dz result x }5023variant { fuel }5024= if fuel <= 0 || is_pinf fm pinf l then l5025else if lt_diff_zero (mul m l y) a then begin5026{proof…}5027let lemma pt (x: t) : unit5028requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_mul m x y) }5029ensures { le_dz (succ_dz l) x }5030= lt_not_le (fp_mul m l y) a;5031if pure { x = l } then absurd;5032index_range x; index_range l;5033assert { lt_dz l x };5034succ_least l x in5035index_range l; of_index_range fm (index l + 1);5036{qed}5037mul_trim_lo fm pinf m a y (succ_diff_zero l) (fuel - 1)5038end else l5039Valid (269ms) (cvc5)5040let rec mul_trim_hi (ghost fm: format) (minf: t) (m: mode) (b y h: t) (fuel: int) : t5041requires { fmt minf = fm /\ minf = minus_infinity fm }5042requires { fmt b = fm /\ fmt y = fm /\ fmt h = fm /\ is_not_nan h /\ fin_nz y }5043requires { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_mul m x y) b -> le_dz x h }5044ensures { fmt result = fm /\ is_not_nan result }5045ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_mul m x y) b -> le_dz x result }5046variant { fuel }5047= if fuel <= 0 || is_minf fm minf h then h5048else if lt_diff_zero b (mul m h y) then begin5049{proof…}5050let lemma pt (x: t) : unit5051requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_mul m x y) b }5052ensures { le_dz x (pred_dz h) }5053= lt_not_le b (fp_mul m h y);5054if pure { x = h } then absurd;5055index_range x; index_range h;5056assert { lt_dz x h };5057pred_greatest h x in5058index_range h; of_index_range fm (index h - 1);5059{qed}5060mul_trim_hi fm minf m b y (pred_diff_zero h) (fuel - 1)5061end else h5062
A lower bound of the x with a <= x * y, y finite and positive
Valid (823ms) (colibri2 37) (cvc4 5) (cvc5 4) (split_vc) (depth 1)let mul_lo_pos (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode) (a y: t) : t5065requires { widens fm fm' /\ fmt a = fm /\ fmt y = fm }5066requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5067requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }5068requires { at_index fm nz (-1) /\ at_index fm pz 0 }5069requires { is_not_nan a /\ fin_nz y /\ is_positive y }5070ensures { fmt result = fm /\ is_not_nan result }5071ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_mul m x y) -> le_dz result x }5072= if is_minf fm minf a then begin5073{proof…}5074let lemma pt (x: t) : unit5075requires { fmt x = fm /\ is_not_nan x } ensures { le_dz minf x }5076= index_range x; index_range minf in5077{qed}5078minf5079end else if is_pz fm pz a && lt_diff_zero (mul m nz y) a then begin5080(* the product keeps the sign of `x`: only the positive `x` reach +0 *)5081{proof…}5082mul_mono fm m false minf nz y;5083let lemma pt (x: t) : unit5084requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_mul m x y) } ensures { le_dz pz x }5085= index_range x; index_range nz; index_range minf;5086if pure { index x < 0 } then begin5087assert { in_iv x minf nz /\ in_iv nz minf nz };5088assert { le_dz (fp_mul m x y) (fp_mul m nz y) };5089le_trans a (fp_mul m x y) (fp_mul m nz y);5090lt_not_le (fp_mul m nz y) a; absurd5091end in5092{qed}5093pz5094end else begin5095let fr = format_of a in5096let t = thr_lo fm fm' nz pz m a in5097let y' = convert fm' rtn y in5098{proof…}5099convert_widen fm' rtn y;5100let ghost v = fin_val y in5101assert { 0.0 <. v by ele (ext pz) (ext y) /\ ext y <> Fin 0.0 };5102assert { ext y' = Fin v /\ fmt y' = fm' /\ fin_nz y' };5103{qed}5104let q = div rtp t y' in5105let l0 = convert fr rtp q in5106{proof…} convert_not_nan fm rtp q; {qed}5107let l = if is_zero_f fm nz pz l0 then nz else l0 in5108{proof…}5109let lemma pt (x: t) : unit5110requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_mul m x y) }5111ensures { le_dz l x }5112= assert { fp_mul m x y = round_f fm m (mul_zneg x y) (emul (ext x) (Fin v)) };5113assert { ele (ext t) (emul (ext x) (Fin v)) };5114emul_move_ge (ext t) (ext x) v;5115let ghost zx = if is_positive x then false else true in5116convert_widen fm' rtp x;5117assert { fp_convert fm' rtp x = round_f fm' rtp zx (ext x) };5118round_f_ele fm' rtp (mul_zneg t y') zx (ediv (ext t) (Fin v)) (ext x);5119assert { ele (ext q) (ext x) };5120let ghost zq = if is_positive q then false else true in5121round_f_ele fm rtp zq zx (ext q) (ext x);5122assert { round_f fm rtp zx (ext x) = x };5123assert { ele (ext l) (ext x) };5124ele_le l x in5125{qed}5126mul_trim_lo fm pinf m a y l 25127end5128
An upper bound of the x with x * y <= b, y finite and positive
Valid (801ms) (colibri2 33) (cvc4 10) (cvc5 3) (split_vc) (depth 1)let mul_hi_pos (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode) (b y: t) : t5131requires { widens fm fm' /\ fmt b = fm /\ fmt y = fm }5132requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5133requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }5134requires { at_index fm nz (-1) /\ at_index fm pz 0 }5135requires { is_not_nan b /\ fin_nz y /\ is_positive y }5136ensures { fmt result = fm /\ is_not_nan result }5137ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_mul m x y) b -> le_dz x result }5138= if is_pinf fm pinf b then begin5139{proof…}5140let lemma pt (x: t) : unit5141requires { fmt x = fm /\ is_not_nan x } ensures { le_dz x pinf }5142= index_range x; index_range pinf in5143{qed}5144pinf5145end else if is_nz fm nz b && lt_diff_zero b (mul m pz y) then begin5146(* only the negative `x` reach -0 or below *)5147{proof…}5148mul_mono fm m true pz pinf y;5149let lemma pt (x: t) : unit5150requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_mul m x y) b } ensures { le_dz x nz }5151= index_range x; index_range pz; index_range pinf;5152if pure { 0 <= index x } then begin5153assert { in_iv x pz pinf /\ in_iv pz pz pinf };5154assert { le_dz (fp_mul m pz y) (fp_mul m x y) };5155le_trans (fp_mul m pz y) (fp_mul m x y) b;5156lt_not_le b (fp_mul m pz y); absurd5157end in5158{qed}5159nz5160end else begin5161let fr = format_of b in5162let t = thr_hi fm fm' nz pz m b in5163let y' = convert fm' rtn y in5164{proof…}5165convert_widen fm' rtn y;5166let ghost v = fin_val y in5167assert { 0.0 <. v by ele (ext pz) (ext y) /\ ext y <> Fin 0.0 };5168assert { ext y' = Fin v /\ fmt y' = fm' /\ fin_nz y' };5169{qed}5170let q = div rtn t y' in5171let h0 = convert fr rtn q in5172{proof…} convert_not_nan fm rtn q; {qed}5173let h = if is_zero_f fm nz pz h0 then pz else h0 in5174{proof…}5175let lemma pt (x: t) : unit5176requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_mul m x y) b }5177ensures { le_dz x h }5178= assert { fp_mul m x y = round_f fm m (mul_zneg x y) (emul (ext x) (Fin v)) };5179assert { ele (emul (ext x) (Fin v)) (ext t) };5180emul_move_le (ext t) (ext x) v;5181let ghost zx = if is_positive x then false else true in5182convert_widen fm' rtn x;5183assert { fp_convert fm' rtn x = round_f fm' rtn zx (ext x) };5184round_f_ele fm' rtn zx (mul_zneg t y') (ext x) (ediv (ext t) (Fin v));5185assert { ele (ext x) (ext q) };5186let ghost zq = if is_positive q then false else true in5187round_f_ele fm rtn zx zq (ext x) (ext q);5188assert { round_f fm rtn zx (ext x) = x };5189assert { ele (ext x) (ext h) };5190ele_le x h in5191{qed}5192mul_trim_hi fm minf m b y h 25193end5194
The x of sign s with x * y in [a, b] for some y of [c, d], finite, not zero and of one sign. lo, hi are the floats of sign s, lo', hi' the ones of the other sign. The bounds come from the end d (resp. c) for a positive x, c (resp. d) for a negative one. For a negative y, the bounds of -x by -y.
Valid (1.1s) (colibri2 76) (cvc4 5) (cvc5 19) (split_vc 2) (depth 2)let mul_back_fin (ghost fm: format) (m: mode) (s: bool) (lo hi lo' hi': t)5201(q: bool) (a b c d: t) : dom5202requires { region fm s lo hi /\ region fm (not s) lo' hi' }5203requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }5204requires { le_dz a b /\ le_dz c d /\ fin_nz c /\ fin_nz d }5205requires { (is_positive c <-> q) /\ (is_positive d <-> q) }5206ensures { result.fm = fm }5207ensures { forall x y. in_iv x lo hi -> in_iv y c d ->5208in_iv (fp_mul m x y) a b -> mem x result }5209= {proof…}5210le_not_nan a b; le_not_nan c d;5211region_facts fm s lo hi lo; region_facts fm (not s) lo' hi' lo;5212mul_mono fm m s lo hi c; mul_mono fm m s lo hi d;5213mul_mono fm m (not s) lo' hi' c; mul_mono fm m (not s) lo' hi' d;5214let lemma yfacts (y: t) : unit5215requires { in_iv y c d }5216ensures { fin_nz y /\ fmt y = fm /\ (is_positive y <-> is_positive c) }5217= le_not_nan c y; index_range c; index_range d; index_range y in5218{qed}5219let ya = if s then d else c in5220let yb = if s then c else d in5221{proof…}5222(* the extreme products *)5223let lemma ext (x y: t) : unit5224requires { in_iv x lo hi /\ in_iv y c d }5225ensures { le_dz (fp_mul m x y) (fp_mul m x ya) }5226ensures { le_dz (fp_mul m x yb) (fp_mul m x y) }5227= yfacts y; region_facts fm s lo hi x;5228le_refl x; mul_special m x y; mul_special m x c; mul_special m x d;5229if is_positive c then begin5230if s then begin5231mul_mag m true true x x y d; mul_mag m true true x x c y5232end else begin5233mul_mag m false true x x c y; mul_mag m false true x x y d5234end5235end else begin5236assert { mag_le false y c /\ mag_le false d y };5237if s then begin5238mul_mag m true false x x d y; mul_mag m true false x x y c5239end else begin5240mul_mag m false false x x y c; mul_mag m false false x x d y5241end5242end in5243{qed}5244{proof…}5245region_facts fm s lo hi lo; region_facts fm s lo hi hi;5246region_facts fm (not s) lo' hi' lo';5247index_range lo; index_range hi; index_range lo'; index_range hi';5248{qed}5249let fr = format_of a in5250let minf = if s then lo' else lo in5251let pinf = if s then hi else hi' in5252let nz = if s then hi' else hi in5253let pz = if s then lo else lo' in5254{proof…}5255assert { minf = minus_infinity fm /\ pinf = plus_infinity fm };5256assert { at_index fm nz (-1) /\ at_index fm pz 0 };5257{qed}5258match widen fr with5259| None -> interval fm lo hi5260| Some fm' ->5261let (l0, h0) =5262if q then5263(mul_lo_pos fm fm' minf pinf nz pz m a ya, mul_hi_pos fm fm' minf pinf nz pz m b yb)5264else begin5265{proof…}5266yfacts c; yfacts d; le_refl c; le_refl d;5267assert { fin_nz (neg ya) /\ is_positive (neg ya) /\ fmt (neg ya) = fm };5268assert { fin_nz (neg yb) /\ is_positive (neg yb) /\ fmt (neg yb) = fm };5269{qed}5270(neg (mul_hi_pos fm fm' minf pinf nz pz m b (neg yb)),5271neg (mul_lo_pos fm fm' minf pinf nz pz m a (neg ya)))5272end in5273let l = max_diff_zero l0 lo in5274let h = min_diff_zero h0 hi in5275{proof…}5276let lemma pt (x y: t) : unit5277requires { in_iv x lo hi /\ in_iv y c d /\ in_iv (fp_mul m x y) a b }5278ensures { le_dz l x /\ le_dz x h }5279= ext x y; le_trans a (fp_mul m x y) (fp_mul m x ya);5280le_trans (fp_mul m x yb) (fp_mul m x y) b;5281region_facts fm s lo hi x;5282if not q then begin5283yfacts c; yfacts d; le_refl c; le_refl d;5284mul_neg_neg m x ya; mul_neg_neg m x yb;5285index_range x; index_range (neg x); neg_neg x;5286assert { le_dz (neg h0) (neg x) /\ le_dz (neg x) (neg l0) };5287neg_le (neg h0) (neg x); neg_le (neg x) (neg l0);5288neg_neg h0; neg_neg l05289end in5290{qed}5291if lt_diff_zero h l then begin5292{proof…}5293let lemma no (x y: t) : unit5294requires { in_iv x lo hi /\ in_iv y c d /\ in_iv (fp_mul m x y) a b }5295ensures { false }5296= pt x y; le_trans l x h; lt_not_le h l in5297{qed}5298empty_dom fm5299end else begin5300{proof…} total l h; {qed}5301interval fm l h5302end5303end5304Valid (22ms) (colibri2)5305let in_ivf (v a b: t) : bool ensures { result <-> in_iv v a b }5306= le_diff_zero a v && le_diff_zero v b5307
[a, b] if c, else empty
Valid (23ms) (colibri2)let iv_if (ghost fm: format) (c: bool) (a b: t) : dom5310requires { fmt a = fm /\ fmt b = fm /\ is_not_nan a /\ is_not_nan b /\ le_dz a b }5311ensures { result.fm = fm }5312ensures { forall v. c -> is_not_nan v -> in_iv v a b -> mem v result }5313= if c then interval fm a b else empty_dom fm5314
The x with x * y in [a, b] for some y of [c, d]
Valid (3.7s) (colibri2 73) (cvc4 18) (cvc5 52) (split_vc 57) (depth 5)let mul_back_iv (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a b c d: t) : dom5317requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5318requires { specials4 fm minf pinf nz pz }5319requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }5320requires { le_dz a b /\ le_dz c d }5321ensures { result.fm = fm }5322ensures { forall x y. fmt x = fm -> is_not_nan x -> in_iv y c d ->5323in_iv (fp_mul m x y) a b -> mem x result }5324= {proof…}5325le_not_nan a b; le_not_nan c d; format_facts fm ();5326index_range minf; index_range pinf; index_range nz; index_range pz;5327of_index_range fm 1; of_index_range fm (-2);5328of_index_range fm (nb_sign fm - 2); of_index_range fm (1 - nb_sign fm);5329succ_gt pz; pred_lt pinf; succ_gt minf; pred_lt nz;5330{qed}5331let psub = succ_diff_zero pz in5332let pmax = pred_diff_zero pinf in5333let nmin = succ_diff_zero minf in5334let nmax = pred_diff_zero nz in5335{proof…}5336assert { index psub = 1 /\ index pmax = nb_sign fm - 2 };5337assert { index nmin = 1 - nb_sign fm /\ index nmax = -2 };5338region_facts fm true pz pinf pz; region_facts fm false minf nz pz;5339{qed}5340(* the finite positive y *)5341let c1 = max_diff_zero c psub in5342let d1 = min_diff_zero d pmax in5343let fp =5344if le_diff_zero c1 d1 then begin5345{proof…} index_range c1; index_range d1; {qed}5346union fm (mul_back_fin fm m true pz pinf minf nz true a b c1 d1)5347(mul_back_fin fm m false minf nz pz pinf true a b c1 d1)5348end else empty_dom fm in5349(* the finite negative y *)5350let c2 = max_diff_zero c nmin in5351let d2 = min_diff_zero d nmax in5352let fn =5353if le_diff_zero c2 d2 then begin5354{proof…} index_range c2; index_range d2; {qed}5355union fm (mul_back_fin fm m true pz pinf minf nz false a b c2 d2)5356(mul_back_fin fm m false minf nz pz pinf false a b c2 d2)5357end else empty_dom fm in5358(* the zeros: a finite x gives a zero *)5359let zn = in_ivf nz a b in5360let zp = in_ivf pz a b in5361let z1 = if in_ivf nz c d then union fm (iv_if fm zn pz pmax) (iv_if fm zp nmin nz)5362else empty_dom fm in5363let z2 = if in_ivf pz c d then union fm (iv_if fm zp pz pmax) (iv_if fm zn nmin nz)5364else empty_dom fm in5365(* the infinities: a nonzero x gives an infinity *)5366let im = in_ivf minf a b in5367let ip = in_ivf pinf a b in5368let i1 = if in_ivf minf c d then union fm (iv_if fm im psub pinf) (iv_if fm ip minf nmax)5369else empty_dom fm in5370let i2 = if in_ivf pinf c d then union fm (iv_if fm ip psub pinf) (iv_if fm im minf nmax)5371else empty_dom fm in5372let res = union fm (union fm fp fn) (union fm (union fm z1 z2) (union fm i1 i2)) in5373{proof…}5374let lemma pt (x y: t) : unit5375requires { fmt x = fm /\ is_not_nan x /\ in_iv y c d /\ in_iv (fp_mul m x y) a b }5376ensures { mem x res }5377= le_not_nan c y; le_not_nan a (fp_mul m x y);5378index_range x; index_range y;5379region_facts fm true pz pinf x; region_facts fm false minf nz x;5380mul_special m x y;5381if pure { is_zero y } then begin5382if pure { is_positive y } then5383assert { y = pz by of_index fm (index y) = of_index fm (index pz) }5384else5385assert { y = nz by of_index fm (index y) = of_index fm (index nz) };5386if pure { is_zero (fp_mul m x y) } then begin5387let r = fp_mul m x y in5388index_range r;5389if pure { is_positive r } then5390assert { r = pz by of_index fm (index r) = of_index fm (index pz) }5391else5392assert { r = nz by of_index fm (index r) = of_index fm (index nz) }5393end;5394assert { mem x z1 \/ mem x z2 }5395end else if pure { is_infinity y } then begin5396if pure { is_plus_infinity y } then plus_infinity_unique y5397else minus_infinity_unique y;5398assert { mem x i1 \/ mem x i2 }5399end else if pure { is_positive y } then begin5400assert { in_iv y c1 d1 };5401assert { mem x fp }5402end else begin5403assert { in_iv y c2 d2 };5404assert { mem x fn }5405end in5406{qed}5407res5408Valid (473ms) (cvc5)5409let rec mul_back_iv_u (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a b: t)5410(l: list (t, t)) : dom5411requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5412requires { specials4 fm minf pinf nz pz }5413requires { fmt a = fm /\ fmt b = fm /\ le_dz a b /\ ok_u l /\ fmt_u fm l }5414ensures { result.fm = fm }5415ensures { forall x y. fmt x = fm -> is_not_nan x -> mem_u y l ->5416in_iv (fp_mul m x y) a b -> mem x result }5417variant { l }5418= match l with5419| Nil -> empty_dom fm5420| Cons (c, d) r ->5421union fm (mul_back_iv fm minf pinf nz pz m a b c d)5422(mul_back_iv_u fm minf pinf nz pz m a b r)5423end5424Valid (506ms) (cvc5)5425let rec mul_back_u (ghost fm: format) (minf pinf nz pz: t) (m: mode)5426(l1 l2: list (t, t)) : dom5427requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5428requires { specials4 fm minf pinf nz pz }5429requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }5430ensures { result.fm = fm }5431ensures { forall x y. fmt x = fm -> is_not_nan x -> mem_u y l2 ->5432mem_u (fp_mul m x y) l1 -> mem x result }5433variant { l1 }5434= match l1 with5435| Nil -> empty_dom fm5436| Cons (a, b) r ->5437union fm (mul_back_iv_u fm minf pinf nz pz m a b l2)5438(mul_back_u fm minf pinf nz pz m r l2)5439end5440
The x such that x * y is in r for some y in d; by commutativity (Facts.mul_comm), also the y such that x * y is in r for some x in d
Valid (568ms) (colibri2 17) (cvc4 7) (cvc5 16) (split_vc) (depth 1)let mul_back (ghost fm: format) (minf pinf nz pz: t) (m: mode) (r d: dom) : dom5445requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5446requires { specials4 fm minf pinf nz pz }5447requires { r.fm = fm /\ d.fm = fm }5448ensures { result.fm = fm }5449ensures { forall x y. fmt x = fm -> mem y d -> mem (fp_mul m x y) r -> mem x result }5450ensures { forall x y. fmt y = fm -> mem x d -> mem (fp_mul m x y) r -> mem y result }5451= {proof…}5452index_range minf; index_range pinf; index_range nz; index_range pz;5453{qed}5454let u = mul_back_u fm minf pinf nz pz m r.u d.u in5455let n =5456if r.nan then5457if d.nan then top fm minf pinf5458else begin5459let p = if meets fm minf minf d || meets fm pinf pinf d5460then union fm (singleton fm nz) (singleton fm pz) else empty_dom fm in5461let q = if meets fm nz pz d5462then union fm (singleton fm minf) (singleton fm pinf) else empty_dom fm in5463union fm (nan_dom fm) (union fm p q)5464end5465else empty_dom fm in5466let res = union fm n u in5467{proof…}5468let lemma pt (x y: t) : unit5469requires { fmt x = fm /\ mem y d /\ mem (fp_mul m x y) r }5470ensures { mem x res }5471= mul_special m x y; mul_div_fmt m x y;5472if pure { is_nan (fp_mul m x y) } then begin5473if pure { is_not_nan x /\ is_not_nan y } then begin5474index_range x; index_range y;5475if pure { is_zero x } then begin5476if pure { is_positive x } then5477assert { x = pz by of_index fm (index x) = of_index fm (index pz) }5478else5479assert { x = nz by of_index fm (index x) = of_index fm (index nz) };5480if pure { is_plus_infinity y } then plus_infinity_unique y5481else minus_infinity_unique y5482end else begin5483if pure { is_plus_infinity x } then plus_infinity_unique x5484else minus_infinity_unique x;5485assert { index nz <= index y <= index pz }5486end5487end5488end in5489let lemma pt2 (x y: t) : unit5490requires { fmt y = fm /\ mem x d /\ mem (fp_mul m x y) r }5491ensures { mem y res }5492= mul_comm m x y; pt y x in5493{qed}5494res5495
The x such that x / y is in [a, b] for some y in [c, d], as for the product (Facts.div_mag); the zeros and infinities of y exchange their roles.
As for the product: for y finite and positive, a <= x / y gives x / y at or above t = thr_lo a in fm', so x at or above t * y, rounded up in fm' then in fm; then at most two steps. A negative y is the positive -y on -x.
Moving a positive divisor across an inequality
Valid (48ms) (colibri2 4) (split_vc) (depth 1)let ghost ediv_move_ge (e ex: ereal) (v: real) : unit5511requires { 0.0 <. v /\ ele e (ediv ex (Fin v)) }5512ensures { ele (emul e (Fin v)) ex }5513= {proof…}5514assert { einv (Fin v) = Fin (1.0 /. v) /\ 0.0 <. 1.0 /. v };5515match e, ex with5516| Fin r, Fin w -> assert { r <=. w *. (1.0 /. v) }; assert { r *. v <=. w }5517| _ -> ()5518end5519{qed}5520Valid (51ms) (colibri2)5521let ghost ediv_move_le (e ex: ereal) (v: real) : unit5522requires { 0.0 <. v /\ ele (ediv ex (Fin v)) e }5523ensures { ele ex (emul e (Fin v)) }5524= {proof…}5525assert { einv (Fin v) = Fin (1.0 /. v) /\ 0.0 <. 1.0 /. v };5526match e, ex with5527| Fin r, Fin w -> assert { w *. (1.0 /. v) <=. r }; assert { w <=. r *. v }5528| _ -> ()5529end5530{qed}5531
The quotient of the opposites
Valid (412ms) (colibri2 18) (cvc4) (cvc5) (split_vc) (depth 1)let ghost div_neg_neg (m: mode) (x y: t) : unit5534requires { is_not_nan x /\ is_not_nan y /\ fmt x = fmt y }5535ensures { fp_div m (neg x) (neg y) = fp_div m x y }5536= {proof…}5537index_range x; index_range y;5538assert { is_zero (neg x) <-> is_zero x };5539assert { is_zero (neg y) <-> is_zero y };5540assert { is_infinity (neg x) <-> is_infinity x5541by is_plus_infinity x <-> index x = nb_sign (fmt x) - 1 };5542assert { is_infinity (neg y) <-> is_infinity y5543by is_plus_infinity y <-> index y = nb_sign (fmt y) - 1 };5544assert { is_positive (neg x) <-> not is_positive x };5545assert { is_positive (neg y) <-> not is_positive y };5546assert { mul_zneg (neg x) (neg y) = mul_zneg x y };5547if pure { not is_zero y } then begin5548match ext y with5549| Fin v ->5550assert { v <> 0.0 };5551let ghost iv = 1.0 /. v in5552let ghost jv = 1.0 /. (-. v) in5553assert { v *. iv = 1.0 };5554assert { (-. v) *. (-. iv) = 1.0 };5555assert { jv *. (-. v) = 1.0 };5556assert { jv = jv *. ((-. v) *. (-. iv)) };5557assert { jv *. ((-. v) *. (-. iv)) = (jv *. (-. v)) *. (-. iv) };5558assert { 1.0 /. (-. v) = -. (1.0 /. v) }5559| _ -> ()5560end;5561assert { einv (ext (neg y)) = eneg (einv (ext y)) };5562emul_eneg (ext x) (einv (ext y))5563end5564{qed}5565Valid (244ms) (colibri2 18) (cvc4) (cvc5 7) (split_vc) (depth 1)5566let ghost div_num_mono (fm: format) (m: mode) (s: bool) (lo hi y: t) : unit5567requires { region fm s lo hi /\ fmt y = fm /\ fin_nz y }5568ensures { is_positive y -> forall x1 x2. in_iv x1 lo hi -> in_iv x2 lo hi ->5569le_dz x1 x2 -> le_dz (fp_div m x1 y) (fp_div m x2 y) }5570ensures { not is_positive y -> forall x1 x2. in_iv x1 lo hi -> in_iv x2 lo hi ->5571le_dz x1 x2 -> le_dz (fp_div m (neg x1) y) (fp_div m (neg x2) y) }5572= {proof…}5573le_refl y;5574let lemma nn (x: t) : unit5575requires { in_iv x lo hi }5576ensures { is_not_nan (fp_div m x y) /\ fmt (fp_div m x y) = fm }5577ensures { is_not_nan (fp_div m (neg x) y) /\ fmt (fp_div m (neg x) y) = fm }5578= region_facts fm s lo hi x; div_special m x y; div_special m (neg x) y;5579mul_div_fmt m x y; mul_div_fmt m (neg x) y in5580let lemma mo (x1 x2: t) : unit5581requires { in_iv x1 lo hi /\ in_iv x2 lo hi /\ le_dz x1 x2 }5582ensures { is_positive y -> le_dz (fp_div m x1 y) (fp_div m x2 y) }5583ensures { not is_positive y -> le_dz (fp_div m (neg x1) y) (fp_div m (neg x2) y) }5584= region_facts fm s lo hi x1; region_facts fm s lo hi x2; nn x1; nn x2;5585index_range x1; index_range x2;5586index_range (neg x1); index_range (neg x2);5587if s then begin5588assert { mag_le false (neg x1) (neg x2) };5589if is_positive y then div_mag m true true x1 x2 y y5590else div_mag m false false (neg x1) (neg x2) y y5591end else begin5592assert { mag_le true (neg x2) (neg x1) };5593if is_positive y then div_mag m false true x2 x1 y y5594else div_mag m true false (neg x2) (neg x1) y y5595end in5596()5597{qed}5598Valid (714ms) (cvc5)5599let rec div_trim_lo (ghost fm: format) (pinf: t) (m: mode) (a y l: t) (fuel: int) : t5600requires { fmt pinf = fm /\ pinf = plus_infinity fm }5601requires { fmt a = fm /\ fmt y = fm /\ fmt l = fm /\ is_not_nan l /\ fin_nz y }5602requires { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_div m x y) -> le_dz l x }5603ensures { fmt result = fm /\ is_not_nan result }5604ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_div m x y) -> le_dz result x }5605variant { fuel }5606= if fuel <= 0 || is_pinf fm pinf l then l5607else if lt_diff_zero (div m l y) a then begin5608{proof…}5609let lemma pt (x: t) : unit5610requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_div m x y) }5611ensures { le_dz (succ_dz l) x }5612= lt_not_le (fp_div m l y) a;5613if pure { x = l } then absurd;5614index_range x; index_range l;5615assert { lt_dz l x };5616succ_least l x in5617index_range l; of_index_range fm (index l + 1);5618{qed}5619div_trim_lo fm pinf m a y (succ_diff_zero l) (fuel - 1)5620end else l5621Valid (740ms) (cvc5)5622let rec div_trim_hi (ghost fm: format) (minf: t) (m: mode) (b y h: t) (fuel: int) : t5623requires { fmt minf = fm /\ minf = minus_infinity fm }5624requires { fmt b = fm /\ fmt y = fm /\ fmt h = fm /\ is_not_nan h /\ fin_nz y }5625requires { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_div m x y) b -> le_dz x h }5626ensures { fmt result = fm /\ is_not_nan result }5627ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_div m x y) b -> le_dz x result }5628variant { fuel }5629= if fuel <= 0 || is_minf fm minf h then h5630else if lt_diff_zero b (div m h y) then begin5631{proof…}5632let lemma pt (x: t) : unit5633requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_div m x y) b }5634ensures { le_dz x (pred_dz h) }5635= lt_not_le b (fp_div m h y);5636if pure { x = h } then absurd;5637index_range x; index_range h;5638assert { lt_dz x h };5639pred_greatest h x in5640index_range h; of_index_range fm (index h - 1);5641{qed}5642div_trim_hi fm minf m b y (pred_diff_zero h) (fuel - 1)5643end else h5644
A lower bound of the x with a <= x / y, y finite and positive
Valid (843ms) (colibri2 37) (cvc4 4) (cvc5 5) (split_vc) (depth 1)let div_lo_pos (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode) (a y: t) : t5647requires { widens fm fm' /\ fmt a = fm /\ fmt y = fm }5648requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5649requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }5650requires { at_index fm nz (-1) /\ at_index fm pz 0 }5651requires { is_not_nan a /\ fin_nz y /\ is_positive y }5652ensures { fmt result = fm /\ is_not_nan result }5653ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz a (fp_div m x y) -> le_dz result x }5654= if is_minf fm minf a then begin5655{proof…}5656let lemma pt (x: t) : unit5657requires { fmt x = fm /\ is_not_nan x } ensures { le_dz minf x }5658= index_range x; index_range minf in5659{qed}5660minf5661end else if is_pz fm pz a && lt_diff_zero (div m nz y) a then begin5662(* the quotient keeps the sign of `x`: only the positive `x` reach +0 *)5663{proof…}5664div_num_mono fm m false minf nz y;5665let lemma pt (x: t) : unit5666requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_div m x y) } ensures { le_dz pz x }5667= index_range x; index_range nz; index_range minf;5668if pure { index x < 0 } then begin5669assert { in_iv x minf nz /\ in_iv nz minf nz };5670assert { le_dz (fp_div m x y) (fp_div m nz y) };5671le_trans a (fp_div m x y) (fp_div m nz y);5672lt_not_le (fp_div m nz y) a; absurd5673end in5674{qed}5675pz5676end else begin5677let fr = format_of a in5678let t = thr_lo fm fm' nz pz m a in5679let y' = convert fm' rtn y in5680{proof…}5681convert_widen fm' rtn y;5682let ghost v = fin_val y in5683assert { 0.0 <. v by ele (ext pz) (ext y) /\ ext y <> Fin 0.0 };5684assert { ext y' = Fin v /\ fmt y' = fm' /\ fin_nz y' };5685{qed}5686let q = mul rtp t y' in5687let l0 = convert fr rtp q in5688{proof…} convert_not_nan fm rtp q; {qed}5689let l = if is_zero_f fm nz pz l0 then nz else l0 in5690{proof…}5691let lemma pt (x: t) : unit5692requires { fmt x = fm /\ is_not_nan x /\ le_dz a (fp_div m x y) }5693ensures { le_dz l x }5694= assert { fp_div m x y = round_f fm m (mul_zneg x y) (ediv (ext x) (Fin v)) };5695assert { ele (ext t) (ediv (ext x) (Fin v)) };5696ediv_move_ge (ext t) (ext x) v;5697let ghost zx = if is_positive x then false else true in5698convert_widen fm' rtp x;5699assert { fp_convert fm' rtp x = round_f fm' rtp zx (ext x) };5700round_f_ele fm' rtp (mul_zneg t y') zx (emul (ext t) (Fin v)) (ext x);5701assert { ele (ext q) (ext x) };5702let ghost zq = if is_positive q then false else true in5703round_f_ele fm rtp zq zx (ext q) (ext x);5704assert { round_f fm rtp zx (ext x) = x };5705assert { ele (ext l) (ext x) };5706ele_le l x in5707{qed}5708div_trim_lo fm pinf m a y l 25709end5710
An upper bound of the x with x / y <= b, y finite and positive
Valid (809ms) (colibri2 37) (cvc4 5) (cvc5 4) (split_vc) (depth 1)let div_hi_pos (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode) (b y: t) : t5713requires { widens fm fm' /\ fmt b = fm /\ fmt y = fm }5714requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5715requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }5716requires { at_index fm nz (-1) /\ at_index fm pz 0 }5717requires { is_not_nan b /\ fin_nz y /\ is_positive y }5718ensures { fmt result = fm /\ is_not_nan result }5719ensures { forall x. fmt x = fm -> is_not_nan x -> le_dz (fp_div m x y) b -> le_dz x result }5720= if is_pinf fm pinf b then begin5721{proof…}5722let lemma pt (x: t) : unit5723requires { fmt x = fm /\ is_not_nan x } ensures { le_dz x pinf }5724= index_range x; index_range pinf in5725{qed}5726pinf5727end else if is_nz fm nz b && lt_diff_zero b (div m pz y) then begin5728(* only the negative `x` reach -0 or below *)5729{proof…}5730div_num_mono fm m true pz pinf y;5731let lemma pt (x: t) : unit5732requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_div m x y) b } ensures { le_dz x nz }5733= index_range x; index_range pz; index_range pinf;5734if pure { 0 <= index x } then begin5735assert { in_iv x pz pinf /\ in_iv pz pz pinf };5736assert { le_dz (fp_div m pz y) (fp_div m x y) };5737le_trans (fp_div m pz y) (fp_div m x y) b;5738lt_not_le b (fp_div m pz y); absurd5739end in5740{qed}5741nz5742end else begin5743let fr = format_of b in5744let t = thr_hi fm fm' nz pz m b in5745let y' = convert fm' rtn y in5746{proof…}5747convert_widen fm' rtn y;5748let ghost v = fin_val y in5749assert { 0.0 <. v by ele (ext pz) (ext y) /\ ext y <> Fin 0.0 };5750assert { ext y' = Fin v /\ fmt y' = fm' /\ fin_nz y' };5751{qed}5752let q = mul rtn t y' in5753let h0 = convert fr rtn q in5754{proof…} convert_not_nan fm rtn q; {qed}5755let h = if is_zero_f fm nz pz h0 then pz else h0 in5756{proof…}5757let lemma pt (x: t) : unit5758requires { fmt x = fm /\ is_not_nan x /\ le_dz (fp_div m x y) b }5759ensures { le_dz x h }5760= assert { fp_div m x y = round_f fm m (mul_zneg x y) (ediv (ext x) (Fin v)) };5761assert { ele (ediv (ext x) (Fin v)) (ext t) };5762ediv_move_le (ext t) (ext x) v;5763let ghost zx = if is_positive x then false else true in5764convert_widen fm' rtn x;5765assert { fp_convert fm' rtn x = round_f fm' rtn zx (ext x) };5766round_f_ele fm' rtn zx (mul_zneg t y') (ext x) (emul (ext t) (Fin v));5767assert { ele (ext x) (ext q) };5768let ghost zq = if is_positive q then false else true in5769round_f_ele fm rtn zx zq (ext x) (ext q);5770assert { round_f fm rtn zx (ext x) = x };5771assert { ele (ext x) (ext h) };5772ele_le x h in5773{qed}5774div_trim_hi fm minf m b y h 25775end5776
The x of sign s with x / y in [a, b] for some y of [c, d], finite, not zero and of sign q
Valid (1.4s) (colibri2 70) (cvc4 2) (cvc5 24) (split_vc 2) (depth 2)let div_back_num_fin (ghost fm: format) (m: mode) (s: bool) (lo hi lo' hi': t)5780(q: bool) (a b c d: t) : dom5781requires { region fm s lo hi /\ region fm (not s) lo' hi' }5782requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }5783requires { le_dz a b /\ le_dz c d /\ fin_nz c /\ fin_nz d }5784requires { (is_positive c <-> q) /\ (is_positive d <-> q) }5785ensures { result.fm = fm }5786ensures { forall x y. in_iv x lo hi -> in_iv y c d ->5787in_iv (fp_div m x y) a b -> mem x result }5788= {proof…}5789le_not_nan a b; le_not_nan c d;5790region_facts fm s lo hi lo; region_facts fm (not s) lo' hi' lo;5791let lemma yfacts (y: t) : unit5792requires { in_iv y c d }5793ensures { fin_nz y /\ fmt y = fm /\ (is_positive y <-> is_positive c) }5794= le_not_nan c y; index_range c; index_range d; index_range y in5795{qed}5796let ya = if s then c else d in5797let yb = if s then d else c in5798{proof…}5799let lemma ext (x y: t) : unit5800requires { in_iv x lo hi /\ in_iv y c d }5801ensures { le_dz (fp_div m x y) (fp_div m x ya) }5802ensures { le_dz (fp_div m x yb) (fp_div m x y) }5803= yfacts y; region_facts fm s lo hi x;5804le_refl x; div_special m x y; div_special m x c; div_special m x d;5805if is_positive c then begin5806if s then begin5807div_mag m true true x x c y; div_mag m true true x x y d5808end else begin5809div_mag m false true x x c y; div_mag m false true x x y d5810end5811end else begin5812assert { mag_le false y c /\ mag_le false d y };5813if s then begin5814div_mag m true false x x y c; div_mag m true false x x d y5815end else begin5816div_mag m false false x x y c; div_mag m false false x x d y5817end5818end in5819{qed}5820{proof…}5821region_facts fm s lo hi lo; region_facts fm s lo hi hi;5822region_facts fm (not s) lo' hi' lo';5823index_range lo; index_range hi; index_range lo'; index_range hi';5824{qed}5825let fr = format_of a in5826let minf = if s then lo' else lo in5827let pinf = if s then hi else hi' in5828let nz = if s then hi' else hi in5829let pz = if s then lo else lo' in5830{proof…}5831assert { minf = minus_infinity fm /\ pinf = plus_infinity fm };5832assert { at_index fm nz (-1) /\ at_index fm pz 0 };5833{qed}5834match widen fr with5835| None -> interval fm lo hi5836| Some fm' ->5837let (l0, h0) =5838if q then5839(div_lo_pos fm fm' minf pinf nz pz m a ya, div_hi_pos fm fm' minf pinf nz pz m b yb)5840else begin5841{proof…}5842yfacts c; yfacts d; le_refl c; le_refl d;5843assert { fin_nz (neg ya) /\ is_positive (neg ya) /\ fmt (neg ya) = fm };5844assert { fin_nz (neg yb) /\ is_positive (neg yb) /\ fmt (neg yb) = fm };5845{qed}5846(neg (div_hi_pos fm fm' minf pinf nz pz m b (neg yb)),5847neg (div_lo_pos fm fm' minf pinf nz pz m a (neg ya)))5848end in5849let l = max_diff_zero l0 lo in5850let h = min_diff_zero h0 hi in5851{proof…}5852let lemma pt (x y: t) : unit5853requires { in_iv x lo hi /\ in_iv y c d /\ in_iv (fp_div m x y) a b }5854ensures { le_dz l x /\ le_dz x h }5855= ext x y; le_trans a (fp_div m x y) (fp_div m x ya);5856le_trans (fp_div m x yb) (fp_div m x y) b;5857region_facts fm s lo hi x;5858if not q then begin5859yfacts c; yfacts d; le_refl c; le_refl d;5860div_neg_neg m x ya; div_neg_neg m x yb;5861index_range x; index_range (neg x); neg_neg x;5862assert { le_dz (neg h0) (neg x) /\ le_dz (neg x) (neg l0) };5863neg_le (neg h0) (neg x); neg_le (neg x) (neg l0);5864neg_neg h0; neg_neg l05865end in5866{qed}5867if lt_diff_zero h l then begin5868{proof…}5869let lemma no (x y: t) : unit5870requires { in_iv x lo hi /\ in_iv y c d /\ in_iv (fp_div m x y) a b }5871ensures { false }5872= pt x y; le_trans l x h; lt_not_le h l in5873{qed}5874empty_dom fm5875end else begin5876{proof…} total l h; {qed}5877interval fm l h5878end5879end5880
The x with x / y in [a, b] for some y of [c, d]
Valid (2.4s) (colibri2 78) (cvc4 17) (cvc5 84) (split_vc 89) (depth 5)let div_back_num_iv (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a b c d: t) : dom5883requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5884requires { specials4 fm minf pinf nz pz }5885requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }5886requires { le_dz a b /\ le_dz c d }5887ensures { result.fm = fm }5888ensures { forall x y. fmt x = fm -> is_not_nan x -> in_iv y c d ->5889in_iv (fp_div m x y) a b -> mem x result }5890= {proof…}5891le_not_nan a b; le_not_nan c d; format_facts fm ();5892index_range minf; index_range pinf; index_range nz; index_range pz;5893of_index_range fm 1; of_index_range fm (-2);5894of_index_range fm (nb_sign fm - 2); of_index_range fm (1 - nb_sign fm);5895succ_gt pz; pred_lt pinf; succ_gt minf; pred_lt nz;5896{qed}5897let psub = succ_diff_zero pz in5898let pmax = pred_diff_zero pinf in5899let nmin = succ_diff_zero minf in5900let nmax = pred_diff_zero nz in5901{proof…}5902assert { index psub = 1 /\ index pmax = nb_sign fm - 2 };5903assert { index nmin = 1 - nb_sign fm /\ index nmax = -2 };5904region_facts fm true pz pinf pz; region_facts fm false minf nz pz;5905{qed}5906let c1 = max_diff_zero c psub in5907let d1 = min_diff_zero d pmax in5908let fp =5909if le_diff_zero c1 d1 then begin5910{proof…} index_range c1; index_range d1; {qed}5911union fm (div_back_num_fin fm m true pz pinf minf nz true a b c1 d1)5912(div_back_num_fin fm m false minf nz pz pinf true a b c1 d1)5913end else empty_dom fm in5914let c2 = max_diff_zero c nmin in5915let d2 = min_diff_zero d nmax in5916let fn =5917if le_diff_zero c2 d2 then begin5918{proof…} index_range c2; index_range d2; {qed}5919union fm (div_back_num_fin fm m true pz pinf minf nz false a b c2 d2)5920(div_back_num_fin fm m false minf nz pz pinf false a b c2 d2)5921end else empty_dom fm in5922(* the zeros: a nonzero x gives an infinity *)5923let im = in_ivf minf a b in5924let ip = in_ivf pinf a b in5925let z1 = if in_ivf nz c d then union fm (iv_if fm im psub pinf) (iv_if fm ip minf nmax)5926else empty_dom fm in5927let z2 = if in_ivf pz c d then union fm (iv_if fm ip psub pinf) (iv_if fm im minf nmax)5928else empty_dom fm in5929(* the infinities: a finite x gives a zero *)5930let zn = in_ivf nz a b in5931let zp = in_ivf pz a b in5932let i1 = if in_ivf minf c d then union fm (iv_if fm zn pz pmax) (iv_if fm zp nmin nz)5933else empty_dom fm in5934let i2 = if in_ivf pinf c d then union fm (iv_if fm zp pz pmax) (iv_if fm zn nmin nz)5935else empty_dom fm in5936let res = union fm (union fm fp fn) (union fm (union fm z1 z2) (union fm i1 i2)) in5937{proof…}5938let lemma pt (x y: t) : unit5939requires { fmt x = fm /\ is_not_nan x /\ in_iv y c d /\ in_iv (fp_div m x y) a b }5940ensures { mem x res }5941= le_not_nan c y; le_not_nan a (fp_div m x y);5942index_range x; index_range y;5943region_facts fm true pz pinf x; region_facts fm false minf nz x;5944div_special m x y;5945if pure { is_zero y } then begin5946if pure { is_positive y } then5947assert { y = pz by of_index fm (index y) = of_index fm (index pz) }5948else5949assert { y = nz by of_index fm (index y) = of_index fm (index nz) };5950assert { not is_zero x };5951assert { is_positive x -> le_dz psub x };5952assert { not is_positive x -> le_dz x nmax };5953assert { fp_div m x y = minf \/ fp_div m x y = pinf };5954assert { mem x z1 \/ mem x z2 }5955end else if pure { is_infinity y } then begin5956if pure { is_plus_infinity y } then plus_infinity_unique y5957else minus_infinity_unique y;5958if pure { is_zero (fp_div m x y) } then begin5959let r = fp_div m x y in5960index_range r;5961if pure { is_positive r } then5962assert { r = pz by of_index fm (index r) = of_index fm (index pz) }5963else5964assert { r = nz by of_index fm (index r) = of_index fm (index nz) }5965end;5966assert { mem x i1 \/ mem x i2 }5967end else if pure { is_positive y } then begin5968assert { in_iv y c1 d1 };5969assert { mem x fp }5970end else begin5971assert { in_iv y c2 d2 };5972assert { mem x fn }5973end in5974{qed}5975res5976Valid (455ms) (cvc5)5977let rec div_back_num_iv_u (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a b: t)5978(l: list (t, t)) : dom5979requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5980requires { specials4 fm minf pinf nz pz }5981requires { fmt a = fm /\ fmt b = fm /\ le_dz a b /\ ok_u l /\ fmt_u fm l }5982ensures { result.fm = fm }5983ensures { forall x y. fmt x = fm -> is_not_nan x -> mem_u y l ->5984in_iv (fp_div m x y) a b -> mem x result }5985variant { l }5986= match l with5987| Nil -> empty_dom fm5988| Cons (c, d) r ->5989union fm (div_back_num_iv fm minf pinf nz pz m a b c d)5990(div_back_num_iv_u fm minf pinf nz pz m a b r)5991end5992Valid (504ms) (cvc5)5993let rec div_back_num_u (ghost fm: format) (minf pinf nz pz: t) (m: mode)5994(l1 l2: list (t, t)) : dom5995requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }5996requires { specials4 fm minf pinf nz pz }5997requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }5998ensures { result.fm = fm }5999ensures { forall x y. fmt x = fm -> is_not_nan x -> mem_u y l2 ->6000mem_u (fp_div m x y) l1 -> mem x result }6001variant { l1 }6002= match l1 with6003| Nil -> empty_dom fm6004| Cons (a, b) r ->6005union fm (div_back_num_iv_u fm minf pinf nz pz m a b l2)6006(div_back_num_u fm minf pinf nz pz m r l2)6007end6008
The x such that x / y is in r for some y in d
Valid (573ms) (colibri2 15) (cvc4 4) (cvc5 17) (split_vc) (depth 1)let div_back_num (ghost fm: format) (minf pinf nz pz: t) (m: mode) (r d: dom) : dom6011requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }6012requires { specials4 fm minf pinf nz pz }6013requires { r.fm = fm /\ d.fm = fm }6014ensures { result.fm = fm }6015ensures { forall x y. fmt x = fm -> mem y d -> mem (fp_div m x y) r -> mem x result }6016= {proof…}6017index_range minf; index_range pinf; index_range nz; index_range pz;6018{qed}6019let u = div_back_num_u fm minf pinf nz pz m r.u d.u in6020let n =6021if r.nan then6022if d.nan then top fm minf pinf6023else begin6024let p = if meets fm nz pz d6025then union fm (singleton fm nz) (singleton fm pz) else empty_dom fm in6026let q = if meets fm minf minf d || meets fm pinf pinf d6027then union fm (singleton fm minf) (singleton fm pinf) else empty_dom fm in6028union fm (nan_dom fm) (union fm p q)6029end6030else empty_dom fm in6031let res = union fm n u in6032{proof…}6033let lemma pt (x y: t) : unit6034requires { fmt x = fm /\ mem y d /\ mem (fp_div m x y) r }6035ensures { mem x res }6036= div_special m x y; mul_div_fmt m x y;6037if pure { is_nan (fp_div m x y) } then begin6038if pure { is_not_nan x /\ is_not_nan y } then begin6039index_range x; index_range y;6040if pure { is_zero x } then begin6041if pure { is_positive x } then6042assert { x = pz by of_index fm (index x) = of_index fm (index pz) }6043else6044assert { x = nz by of_index fm (index x) = of_index fm (index nz) };6045assert { index nz <= index y <= index pz }6046end else begin6047if pure { is_plus_infinity x } then plus_infinity_unique x6048else minus_infinity_unique x;6049if pure { is_plus_infinity y } then plus_infinity_unique y6050else minus_infinity_unique y6051end6052end6053end in6054{qed}6055res6056
The y such that x / y is in [a, b] for some x in [c, d]. On the finite nonzero x of one sign q, x / y is monotonic in y on the floats of one sign s: increasing for a negative x, decreasing for a positive one.
For x finite and not zero and y positive, x / y is decreasing in y for a positive x, increasing for a negative one. The y with x / y <= b (positive x) or a <= x / y (negative x) are at or above x / t, t the threshold of b (resp. a) in fm', when t has the sign of x, rounded up in fm' then in fm; at or below for the other end. +0 gives an infinite quotient, +inf a zero one. Then at most two steps; None when no y is left. A zero end of the wrong sign leaves no y: the quotient has the sign of x. A negative y is the positive -y on -x. The same results as the former bisection (Search) on 300000 random cases of 3 formats and the 5 modes (2026–11–09), for both the dividend and the divisor.
The divisor from a bound of the quotient, u positive
Valid (144ms) (colibri2)let ghost ediv_den_pos (u w: real) (e: ereal) : unit6081requires { 0.0 <. u /\ 0.0 <. w }6082ensures { ele (ediv (Fin u) (Fin w)) e ->6083ele (Fin 0.0) e /\ e <> Fin 0.0 /\ ele (ediv (Fin u) e) (Fin w) }6084ensures { ele e (ediv (Fin u) (Fin w)) -> ele (Fin 0.0) e -> e <> Fin 0.0 ->6085ele (Fin w) (ediv (Fin u) e) }6086= {proof…}6087assert { ediv (Fin u) (Fin w) = Fin (u *. (1.0 /. w)) /\ 0.0 <. 1.0 /. w };6088assert { 0.0 <. u *. (1.0 /. w) };6089assert { u *. (1.0 /. w) *. w = u };6090match e with6091| Fin r ->6092if pure { 0.0 <. r } then begin6093assert { ediv (Fin u) e = Fin (u *. (1.0 /. r)) };6094assert { u *. (1.0 /. r) *. r = u };6095assert { u *. (1.0 /. w) <=. r -> u <=. r *. w };6096assert { r <=. u *. (1.0 /. w) -> r *. w <=. u };6097assert { u <=. r *. w -> u *. (1.0 /. r) <=. w };6098assert { r *. w <=. u -> w <=. u *. (1.0 /. r) }6099end6100| PInf -> assert { ediv (Fin u) e = Fin 0.0 }6101| MInf -> ()6102end6103{qed}6104
The divisor from a bound of the quotient, u negative
Valid (65ms) (colibri2 15) (split_vc) (depth 1)let ghost ediv_den_neg (u w: real) (e: ereal) : unit6107requires { u <. 0.0 /\ 0.0 <. w }6108ensures { ele e (ediv (Fin u) (Fin w)) ->6109ele e (Fin 0.0) /\ e <> Fin 0.0 /\ ele (ediv (Fin u) e) (Fin w) }6110ensures { ele (ediv (Fin u) (Fin w)) e -> ele e (Fin 0.0) -> e <> Fin 0.0 ->6111ele (Fin w) (ediv (Fin u) e) }6112= {proof…}6113assert { ediv (Fin u) (Fin w) = Fin (u *. (1.0 /. w)) /\ 0.0 <. 1.0 /. w };6114assert { u *. (1.0 /. w) <. 0.0 };6115assert { u *. (1.0 /. w) *. w = u };6116match e with6117| Fin r ->6118if pure { r <. 0.0 } then begin6119assert { ediv (Fin u) e = Fin (u *. (1.0 /. r)) };6120assert { u *. (1.0 /. r) *. r = u };6121assert { r <=. u *. (1.0 /. w) -> r *. w <=. u };6122assert { u *. (1.0 /. w) <=. r -> u <=. r *. w };6123assert { r *. w <=. u -> u *. (1.0 /. r) <=. w };6124assert { 1.0 /. r <. 0.0 /\ r *. (1.0 /. r) = 1.0 };6125assert { (r *. w) *. (1.0 /. r) = w *. (r *. (1.0 /. r)) };6126assert { u <=. r *. w -> (r *. w) *. (1.0 /. r) <=. u *. (1.0 /. r) };6127assert { u <=. r *. w -> w <=. u *. (1.0 /. r) }6128end6129| MInf -> assert { ediv (Fin u) e = Fin 0.0 }6130| PInf -> ()6131end6132{qed}6133
The constraint on a divisor: x / y <= b for a positive x, a <= x / y for a negative one
predicate den_lo_c (m: mode) (a b x y: t) =6137if is_positive x then le_dz (fp_div m x y) b else le_dz a (fp_div m x y)6138
The other end: a <= x / y for a positive x, x / y <= b for a negative one
predicate den_hi_c (m: mode) (a b x y: t) =6142if is_positive x then le_dz a (fp_div m x y) else le_dz (fp_div m x y) b6143
At most fuel steps up from l while l fails the constraint; None when +inf fails it too
Valid (995ms) (cvc5)let rec den_trim_lo (ghost fm: format) (pinf: t) (m: mode) (px: bool) (a b x l: t) (fuel: int)6147: option t6148requires { fmt pinf = fm /\ pinf = plus_infinity fm }6149requires { fmt a = fm /\ fmt b = fm /\ fmt x = fm /\ fmt l = fm /\ is_not_nan l /\ fin_nz x }6150requires { px <-> is_positive x }6151requires { forall y. fmt y = fm -> is_not_nan y -> is_positive y -> den_lo_c m a b x y -> le_dz l y }6152ensures { match result with6153| Some r -> fmt r = fm /\ is_not_nan r /\6154forall y. fmt y = fm -> is_not_nan y -> is_positive y -> den_lo_c m a b x y -> le_dz r y6155| None -> forall y. fmt y = fm -> is_not_nan y -> is_positive y -> not den_lo_c m a b x y6156end }6157variant { fuel }6158= if fuel <= 0 then Some l6159else if (if px then lt_diff_zero b (div m x l) else lt_diff_zero (div m x l) a)6160then begin6161{proof…}6162let lemma pt (y: t) : unit6163requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_lo_c m a b x y }6164ensures { lt_dz l y }6165= if is_positive x then lt_not_le b (fp_div m x l) else lt_not_le (fp_div m x l) a;6166if pure { y = l } then absurd;6167index_range y; index_range l in6168{qed}6169if is_pinf fm pinf l then begin6170{proof…}6171let lemma no (y: t) : unit6172requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_lo_c m a b x y }6173ensures { false }6174= pt y; index_range y; index_range pinf in6175{qed}6176None6177end else begin6178{proof…}6179let lemma pt2 (y: t) : unit6180requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_lo_c m a b x y }6181ensures { le_dz (succ_dz l) y }6182= pt y; index_range y; index_range l; succ_least l y in6183index_range l; index_range pinf; of_index_range fm (index l + 1);6184{qed}6185den_trim_lo fm pinf m px a b x (succ_diff_zero l) (fuel - 1)6186end6187end else Some l6188
At most fuel steps down from h while h fails the constraint; None when +0 fails it too
Valid (1.2s) (cvc4)let rec den_trim_hi (ghost fm: format) (pz: t) (m: mode) (px: bool) (a b x h: t) (fuel: int)6192: option t6193requires { fmt pz = fm /\ at_index fm pz 0 }6194requires { fmt a = fm /\ fmt b = fm /\ fmt x = fm /\ fmt h = fm /\ is_not_nan h /\ fin_nz x }6195requires { px <-> is_positive x }6196requires { forall y. fmt y = fm -> is_not_nan y -> is_positive y -> den_hi_c m a b x y -> le_dz y h }6197ensures { match result with6198| Some r -> fmt r = fm /\ is_not_nan r /\6199forall y. fmt y = fm -> is_not_nan y -> is_positive y -> den_hi_c m a b x y -> le_dz y r6200| None -> forall y. fmt y = fm -> is_not_nan y -> is_positive y -> not den_hi_c m a b x y6201end }6202variant { fuel }6203= if fuel <= 0 then Some h6204else if (if px then lt_diff_zero (div m x h) a else lt_diff_zero b (div m x h))6205then begin6206{proof…}6207let lemma pt (y: t) : unit6208requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_hi_c m a b x y }6209ensures { lt_dz y h }6210= if is_positive x then lt_not_le (fp_div m x h) a else lt_not_le b (fp_div m x h);6211if pure { y = h } then absurd;6212index_range y; index_range h in6213{qed}6214if le_diff_zero h pz then begin6215{proof…}6216let lemma no (y: t) : unit6217requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_hi_c m a b x y }6218ensures { false }6219= pt y; index_range y; index_range h in6220{qed}6221None6222end else begin6223{proof…}6224let lemma pt2 (y: t) : unit6225requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_hi_c m a b x y }6226ensures { le_dz y (pred_dz h) }6227= pt y; index_range y; index_range h; pred_greatest h y in6228index_range h; of_index_range fm (index h - 1);6229{qed}6230den_trim_hi fm pz m px a b x (pred_diff_zero h) (fuel - 1)6231end6232end else Some h6233
A lower bound of the positive y with den_lo_c m a b x y
Valid (1.9s) (colibri2 68) (cvc4 22) (cvc5 37) (split_vc 4) (depth 2)let den_lo (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode) (a b x: t) : option t6236requires { widens fm fm' /\ fmt a = fm /\ fmt b = fm /\ fmt x = fm }6237requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }6238requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }6239requires { at_index fm nz (-1) /\ at_index fm pz 0 }6240requires { is_not_nan a /\ is_not_nan b /\ fin_nz x }6241ensures { match result with6242| Some r -> fmt r = fm /\ is_not_nan r /\6243forall y. fmt y = fm -> is_not_nan y -> is_positive y -> den_lo_c m a b x y -> le_dz r y6244| None -> forall y. fmt y = fm -> is_not_nan y -> is_positive y -> not den_lo_c m a b x y6245end }6246= {proof…} index_range x; index_range pz; index_range pinf; {qed}6247let px = le_diff_zero pz x in6248if (if px then is_pinf fm pinf b else is_minf fm minf a) then begin6249{proof…}6250let lemma pt (y: t) : unit6251requires { fmt y = fm /\ is_not_nan y /\ is_positive y } ensures { le_dz pz y }6252= index_range y in6253{qed}6254Some pz6255end else if (if px then lt_diff_zero b pz else lt_diff_zero nz a) then begin6256(* the quotient has the sign of `x`: never below +0 for a positive `x`, never above -0 for a negative one *)6258{proof…}6259let lemma no (y: t) : unit6260requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_lo_c m a b x y }6261ensures { false }6262= index_range y; index_range a; index_range b; index_range nz; index_range pz;6263div_special m x y; mul_div_fmt m x y;6264let ghost u = fin_val x in6265assert { px -> 0.0 <. u by ele (ext pz) (ext x) /\ ext x <> Fin 0.0 };6266assert { not px -> u <. 0.0 by ele (ext x) (ext nz) /\ ext x <> Fin 0.0 };6267let ghost r = fp_div m x y in6268let ghost zn = if px then false else true in6269assert { mul_zneg x y = zn };6270let ghost z0 = round_f fm m zn (Fin 0.0) in6271assert { is_zero z0 /\ fmt z0 = fm /\ is_not_nan z0 /\ (is_positive z0 <-> px) };6272index_range z0; index_range r;6273if pure { is_zero y } then begin6274assert { r = if px then plus_infinity fm else minus_infinity fm };6275assert { px -> le_dz pz r };6276assert { not px -> le_dz r nz }6277end else begin6278let ghost e = ediv (Fin u) (ext y) in6279assert { r = round_f fm m zn e };6280if pure { is_infinity y } then begin6281plus_infinity_unique y; assert { e = Fin 0.0 }6282end else begin6283let ghost w = fin_val y in6284assert { 0.0 <. w by ele (ext pz) (ext y) /\ ext y <> Fin 0.0 };6285assert { 0.0 <. 1.0 /. w };6286assert { e = Fin (u *. (1.0 /. w)) }6287end;6288if px then begin6289assert { ele (Fin 0.0) e }; assert { le_dz z0 r };6290assert { z0 = pz by index z0 = 0 /\ of_index fm (index z0) = of_index fm (index pz) }6291end else begin6292assert { ele e (Fin 0.0) }; assert { le_dz r z0 };6293assert { z0 = nz by index z0 = -1 /\ of_index fm (index z0) = of_index fm (index nz) }6294end6295end;6296if px then begin le_trans pz r b; lt_not_le b pz end6297else begin le_trans a r nz; lt_not_le nz a end in6298{qed}6299None6300end else begin6301let fr = format_of x in6302let t = if px then thr_hi fm fm' nz pz m b else thr_lo fm fm' nz pz m a in6303{proof…}6304format_facts fm' (); of_index_range fm' 0; of_index_range fm' (-1);6305{qed}6306let pz' = of_index_v fm' 0 in6307let nz' = of_index_v fm' (-1) in6308if (if px then lt_diff_zero pz' t else lt_diff_zero t nz') then begin6309let x' = convert fm' rtn x in6310{proof…}6311convert_widen fm' rtn x;6312let ghost u = fin_val x in6313assert { px -> 0.0 <. u by ele (ext pz) (ext x) /\ ext x <> Fin 0.0 };6314assert { not px -> u <. 0.0 by ele (ext x) (ext nz) /\ ext x <> Fin 0.0 };6315assert { ext x' = Fin u /\ fmt x' = fm' /\ fin_nz x' };6316index_range t; index_range pz'; index_range nz';6317assert { not is_zero t };6318{qed}6319let q = div rtp x' t in6320let l0 = convert fr rtp q in6321{proof…} convert_not_nan fm rtp q; {qed}6322let l = max_diff_zero l0 pz in6323{proof…}6324let lemma pt (y: t) : unit6325requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_lo_c m a b x y }6326ensures { le_dz l y }6327= index_range y; div_special m x y;6328if pure { is_zero y } then begin6329assert { y = pz by of_index fm (index y) = of_index fm (index pz) };6330if px then plus_infinity_unique b else minus_infinity_unique a;6331absurd6332end else if pure { is_infinity y } then begin6333plus_infinity_unique y; index_range l6334end else begin6335let ghost w = fin_val y in6336assert { 0.0 <. w by ele (ext pz) (ext y) /\ ext y <> Fin 0.0 };6337assert { fp_div m x y = round_f fm m (mul_zneg x y) (ediv (Fin u) (Fin w)) };6338if px then begin6339assert { ele (ediv (Fin u) (Fin w)) (ext t) };6340ediv_den_pos u w (ext t)6341end else begin6342assert { ele (ext t) (ediv (Fin u) (Fin w)) };6343ediv_den_neg u w (ext t)6344end;6345assert { ele (ediv (Fin u) (ext t)) (Fin w) };6346assert { ext q = ext (round_f fm' rtp (mul_zneg x' t) (ediv (Fin u) (ext t))) };6347let ghost zy = if is_positive y then false else true in6348convert_widen fm' rtp y;6349assert { fp_convert fm' rtp y = round_f fm' rtp zy (ext y) };6350round_f_ele fm' rtp (mul_zneg x' t) zy (ediv (Fin u) (ext t)) (ext y);6351assert { ele (ext q) (ext y) };6352let ghost zq = if is_positive q then false else true in6353round_f_ele fm rtp zq zy (ext q) (ext y);6354assert { round_f fm rtp zy (ext y) = y };6355assert { ele (ext l0) (ext y) };6356ele_le l0 y; le_trans pz pz y6357end in6358{qed}6359den_trim_lo fm pinf m px a b x l 26360end else begin6361(* no finite `y`: the quotient would have the sign of `x` *)6362{proof…}6363let lemma pt (y: t) : unit6364requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_lo_c m a b x y }6365ensures { le_dz pinf y }6366= index_range y; div_special m x y; index_range t; index_range pz'; index_range nz';6367let ghost u = fin_val x in6368assert { px -> 0.0 <. u by ele (ext pz) (ext x) /\ ext x <> Fin 0.0 };6369assert { not px -> u <. 0.0 by ele (ext x) (ext nz) /\ ext x <> Fin 0.0 };6370if pure { is_zero y } then begin6371assert { y = pz by of_index fm (index y) = of_index fm (index pz) };6372if px then plus_infinity_unique b else minus_infinity_unique a;6373absurd6374end else if pure { is_infinity y } then begin6375plus_infinity_unique y6376end else begin6377let ghost w = fin_val y in6378assert { 0.0 <. w by ele (ext pz) (ext y) /\ ext y <> Fin 0.0 };6379assert { fp_div m x y = round_f fm m (mul_zneg x y) (ediv (Fin u) (Fin w)) };6380if px then begin6381assert { ele (ext t) (ext pz') };6382assert { ele (ediv (Fin u) (Fin w)) (ext t) };6383ediv_den_pos u w (ext t);6384assert { ext t <> Fin 0.0 -> not is_zero t };6385absurd6386end else begin6387assert { ele (ext nz') (ext t) };6388assert { ele (ext t) (ediv (Fin u) (Fin w)) };6389ediv_den_neg u w (ext t);6390absurd6391end6392end in6393{qed}6394den_trim_lo fm pinf m px a b x pinf 16395end6396end6397
An upper bound of the positive y with den_hi_c m a b x y
Valid (1.5s) (colibri2 44) (cvc4 8) (cvc5 18) (split_vc 2) (depth 2)let den_hi (ghost fm: format) (fm': format) (minf pinf nz pz: t) (m: mode) (a b x: t) : option t6400requires { widens fm fm' /\ fmt a = fm /\ fmt b = fm /\ fmt x = fm }6401requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }6402requires { minf = minus_infinity fm /\ pinf = plus_infinity fm }6403requires { at_index fm nz (-1) /\ at_index fm pz 0 }6404requires { is_not_nan a /\ is_not_nan b /\ fin_nz x }6405ensures { match result with6406| Some r -> fmt r = fm /\ is_not_nan r /\6407forall y. fmt y = fm -> is_not_nan y -> is_positive y -> den_hi_c m a b x y -> le_dz y r6408| None -> forall y. fmt y = fm -> is_not_nan y -> is_positive y -> not den_hi_c m a b x y6409end }6410= {proof…}6411index_range x; index_range pz; index_range pinf;6412let lemma top (y: t) : unit6413requires { fmt y = fm /\ is_not_nan y } ensures { le_dz y pinf }6414= index_range y in6415{qed}6416let px = le_diff_zero pz x in6417if (if px then is_minf fm minf a else is_pinf fm pinf b) then Some pinf6418else begin6419let fr = format_of x in6420let t = if px then thr_lo fm fm' nz pz m a else thr_hi fm fm' nz pz m b in6421{proof…}6422format_facts fm' (); of_index_range fm' 0; of_index_range fm' (-1);6423{qed}6424let pz' = of_index_v fm' 0 in6425let nz' = of_index_v fm' (-1) in6426if (if px then lt_diff_zero pz' t else lt_diff_zero t nz') then begin6427let x' = convert fm' rtn x in6428{proof…}6429convert_widen fm' rtn x;6430let ghost u = fin_val x in6431assert { px -> 0.0 <. u by ele (ext pz) (ext x) /\ ext x <> Fin 0.0 };6432assert { not px -> u <. 0.0 by ele (ext x) (ext nz) /\ ext x <> Fin 0.0 };6433assert { ext x' = Fin u /\ fmt x' = fm' /\ fin_nz x' };6434index_range t; index_range pz'; index_range nz';6435assert { not is_zero t };6436{qed}6437let q = div rtn x' t in6438let h0 = convert fr rtn q in6439{proof…} convert_not_nan fm rtn q; {qed}6440let h = max_diff_zero h0 pz in6441{proof…}6442let lemma pt (y: t) : unit6443requires { fmt y = fm /\ is_not_nan y /\ is_positive y /\ den_hi_c m a b x y }6444ensures { le_dz y h }6445= index_range y; div_special m x y;6446if pure { is_zero y } then begin6447assert { y = pz by of_index fm (index y) = of_index fm (index pz) };6448le_refl pz6449end else if pure { is_infinity y } then begin6450plus_infinity_unique y;6451assert { fp_div m x y = round_f fm m (mul_zneg x y) (ediv (Fin u) PInf) };6452assert { ediv (Fin u) PInf = Fin 0.0 };6453if px then assert { ele (ext t) (Fin 0.0) }6454else assert { ele (Fin 0.0) (ext t) };6455assert { px -> ele (ext pz') (ext t) /\ ext t <> Fin 0.0 };6456assert { not px -> ele (ext t) (ext nz') /\ ext t <> Fin 0.0 };6457absurd6458end else begin6459let ghost w = fin_val y in6460assert { 0.0 <. w by ele (ext pz) (ext y) /\ ext y <> Fin 0.0 };6461assert { fp_div m x y = round_f fm m (mul_zneg x y) (ediv (Fin u) (Fin w)) };6462if px then begin6463assert { ele (ext t) (ediv (Fin u) (Fin w)) };6464assert { ele (ext pz') (ext t) /\ ext t <> Fin 0.0 };6465ediv_den_pos u w (ext t)6466end else begin6467assert { ele (ediv (Fin u) (Fin w)) (ext t) };6468assert { ele (ext t) (ext nz') /\ ext t <> Fin 0.0 };6469ediv_den_neg u w (ext t)6470end;6471assert { ele (Fin w) (ediv (Fin u) (ext t)) };6472assert { ext q = ext (round_f fm' rtn (mul_zneg x' t) (ediv (Fin u) (ext t))) };6473let ghost zy = if is_positive y then false else true in6474convert_widen fm' rtn y;6475assert { fp_convert fm' rtn y = round_f fm' rtn zy (ext y) };6476round_f_ele fm' rtn zy (mul_zneg x' t) (ext y) (ediv (Fin u) (ext t));6477assert { ele (ext y) (ext q) };6478let ghost zq = if is_positive q then false else true in6479round_f_ele fm rtn zy zq (ext y) (ext q);6480assert { round_f fm rtn zy (ext y) = y };6481assert { ele (ext y) (ext h0) };6482ele_le y h06483end in6484{qed}6485den_trim_hi fm pz m px a b x h 26486end else den_trim_hi fm pz m px a b x pinf 26487end6488
The y of sign s with x / y in [a, b] for some x of [c, d], finite, not zero and of sign q
Valid (946ms) (colibri2 75) (cvc4 6) (cvc5 19) (split_vc) (depth 1)let div_back_den_fin (ghost fm: format) (m: mode) (s: bool) (lo hi lo' hi': t)6492(q: bool) (a b c d: t) : dom6493requires { region fm s lo hi /\ region fm (not s) lo' hi' }6494requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }6495requires { le_dz a b /\ le_dz c d /\ fin_nz c /\ fin_nz d }6496requires { (is_positive c <-> q) /\ (is_positive d <-> q) }6497ensures { result.fm = fm }6498ensures { forall x y. in_iv y lo hi -> in_iv x c d ->6499in_iv (fp_div m x y) a b -> mem y result }6500= {proof…}6501le_not_nan a b; le_not_nan c d;6502region_facts fm s lo hi lo; region_facts fm (not s) lo' hi' lo;6503let lemma xfacts (x: t) : unit6504requires { in_iv x c d }6505ensures { fin_nz x /\ fmt x = fm /\ (is_positive x <-> is_positive c) }6506= le_not_nan c x; index_range c; index_range d; index_range x in6507{qed}6508let xa = if s then d else c in6509let xb = if s then c else d in6510{proof…}6511let lemma ext (x y: t) : unit6512requires { in_iv y lo hi /\ in_iv x c d }6513ensures { le_dz (fp_div m x y) (fp_div m xa y) }6514ensures { le_dz (fp_div m xb y) (fp_div m x y) }6515= xfacts x; region_facts fm s lo hi y;6516le_refl y; div_special m x y; div_special m c y; div_special m d y;6517if is_positive c then begin6518if s then begin6519div_mag m true true x d y y; div_mag m true true c x y y6520end else begin6521div_mag m true false x d y y; div_mag m true false c x y y6522end6523end else begin6524assert { mag_le false x c /\ mag_le false d x };6525if s then begin6526div_mag m false true x c y y; div_mag m false true d x y y6527end else begin6528div_mag m false false x c y y; div_mag m false false d x y y6529end6530end in6531{qed}6532{proof…}6533region_facts fm s lo hi lo; region_facts fm s lo hi hi;6534region_facts fm (not s) lo' hi' lo';6535index_range lo; index_range hi; index_range lo'; index_range hi';6536{qed}6537let fr = format_of a in6538let minf = if s then lo' else lo in6539let pinf = if s then hi else hi' in6540let nz = if s then hi' else hi in6541let pz = if s then lo else lo' in6542{proof…}6543assert { minf = minus_infinity fm /\ pinf = plus_infinity fm };6544assert { at_index fm nz (-1) /\ at_index fm pz 0 };6545xfacts c; xfacts d; le_refl c; le_refl d;6546{qed}6547(* the `x` of the lower and the upper bound of a positive `y` *)6548let xl = if s then (if q then xb else xa) else (if q then xa else xb) in6549let xh = if s then (if q then xa else xb) else (if q then xb else xa) in6550match widen fr with6551| None -> interval fm lo hi6552| Some fm' ->6553let (o1, o2) =6554if s then6555(den_lo fm fm' minf pinf nz pz m a b xl, den_hi fm fm' minf pinf nz pz m a b xh)6556else begin6557{proof…}6558assert { fin_nz (neg xl) /\ fmt (neg xl) = fm };6559assert { fin_nz (neg xh) /\ fmt (neg xh) = fm };6560{qed}6561(den_hi fm fm' minf pinf nz pz m a b (neg xh),6562den_lo fm fm' minf pinf nz pz m a b (neg xl))6563end in6564{proof…}6565(* the constraints on a positive divisor *)6566let lemma cs (x y: t) : unit6567requires { in_iv y lo hi /\ in_iv x c d /\ in_iv (fp_div m x y) a b }6568ensures { s -> is_positive y /\ is_not_nan y /\ fmt y = fm /\6569den_lo_c m a b xl y /\ den_hi_c m a b xh y }6570ensures { not s -> is_positive (neg y) /\ is_not_nan (neg y) /\ fmt (neg y) = fm /\6571den_lo_c m a b (neg xl) (neg y) /\ den_hi_c m a b (neg xh) (neg y) }6572= ext x y; le_trans a (fp_div m x y) (fp_div m xa y);6573le_trans (fp_div m xb y) (fp_div m x y) b;6574region_facts fm s lo hi y; index_range y;6575if not s then begin6576index_range (neg y); neg_neg y;6577div_neg_neg m xa y; div_neg_neg m xb y6578end in6579{qed}6580match o1, o2 with6581| Some r1, Some r2 ->6582let l0 = if s then r1 else neg r1 in6583let h0 = if s then r2 else neg r2 in6584let l = max_diff_zero l0 lo in6585let h = min_diff_zero h0 hi in6586{proof…}6587let lemma pt (x y: t) : unit6588requires { in_iv y lo hi /\ in_iv x c d /\ in_iv (fp_div m x y) a b }6589ensures { le_dz l y /\ le_dz y h }6590= cs x y; region_facts fm s lo hi y;6591if not s then begin6592index_range y; neg_neg y;6593assert { le_dz (neg y) r1 /\ le_dz r2 (neg y) };6594neg_le (neg y) r1; neg_le r2 (neg y)6595end in6596{qed}6597if lt_diff_zero h l then begin6598{proof…}6599let lemma no (x y: t) : unit6600requires { in_iv y lo hi /\ in_iv x c d /\ in_iv (fp_div m x y) a b }6601ensures { false }6602= pt x y; le_trans l y h; lt_not_le h l in6603{qed}6604empty_dom fm6605end else begin6606{proof…} total l h; {qed}6607interval fm l h6608end6609| _ ->6610{proof…}6611let lemma no (x y: t) : unit6612requires { in_iv y lo hi /\ in_iv x c d /\ in_iv (fp_div m x y) a b }6613ensures { false }6614= cs x y in6615{qed}6616empty_dom fm6617end6618end6619
The y with x / y in [a, b] for some x of [c, d]
Valid (2.8s) (colibri2 61) (cvc4 8) (cvc5 44) (split_vc 5) (depth 4)let div_back_den_iv (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a b c d: t) : dom6622requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }6623requires { specials4 fm minf pinf nz pz }6624requires { fmt a = fm /\ fmt b = fm /\ fmt c = fm /\ fmt d = fm }6625requires { le_dz a b /\ le_dz c d }6626ensures { result.fm = fm }6627ensures { forall x y. fmt y = fm -> is_not_nan y -> in_iv x c d ->6628in_iv (fp_div m x y) a b -> mem y result }6629= {proof…}6630le_not_nan a b; le_not_nan c d; format_facts fm ();6631index_range minf; index_range pinf; index_range nz; index_range pz;6632of_index_range fm 1; of_index_range fm (-2);6633of_index_range fm (nb_sign fm - 2); of_index_range fm (1 - nb_sign fm);6634succ_gt pz; pred_lt pinf; succ_gt minf; pred_lt nz;6635{qed}6636let psub = succ_diff_zero pz in6637let pmax = pred_diff_zero pinf in6638let nmin = succ_diff_zero minf in6639let nmax = pred_diff_zero nz in6640{proof…}6641assert { index psub = 1 /\ index pmax = nb_sign fm - 2 };6642assert { index nmin = 1 - nb_sign fm /\ index nmax = -2 };6643region_facts fm true pz pinf pz; region_facts fm false minf nz pz;6644{qed}6645let c1 = max_diff_zero c psub in6646let d1 = min_diff_zero d pmax in6647let fp =6648if le_diff_zero c1 d1 then begin6649{proof…} index_range c1; index_range d1; {qed}6650union fm (div_back_den_fin fm m true pz pinf minf nz true a b c1 d1)6651(div_back_den_fin fm m false minf nz pz pinf true a b c1 d1)6652end else empty_dom fm in6653let c2 = max_diff_zero c nmin in6654let d2 = min_diff_zero d nmax in6655let fn =6656if le_diff_zero c2 d2 then begin6657{proof…} index_range c2; index_range d2; {qed}6658union fm (div_back_den_fin fm m true pz pinf minf nz false a b c2 d2)6659(div_back_den_fin fm m false minf nz pz pinf false a b c2 d2)6660end else empty_dom fm in6661(* the zeros: a nonzero y gives a zero *)6662let zn = in_ivf nz a b in6663let zp = in_ivf pz a b in6664let z1 = if in_ivf nz c d then union fm (iv_if fm zn psub pinf) (iv_if fm zp minf nmax)6665else empty_dom fm in6666let z2 = if in_ivf pz c d then union fm (iv_if fm zp psub pinf) (iv_if fm zn minf nmax)6667else empty_dom fm in6668(* the infinities: a finite y gives an infinity *)6669let im = in_ivf minf a b in6670let ip = in_ivf pinf a b in6671let i1 = if in_ivf minf c d then union fm (iv_if fm im pz pmax) (iv_if fm ip nmin nz)6672else empty_dom fm in6673let i2 = if in_ivf pinf c d then union fm (iv_if fm ip pz pmax) (iv_if fm im nmin nz)6674else empty_dom fm in6675let fpn = union fm fp fn in6676let zs = union fm z1 z2 in6677let zi = union fm i1 i2 in6678let res = union fm fpn (union fm zs zi) in6679{proof…}6680let lemma pt (x y: t) : unit6681requires { fmt y = fm /\ is_not_nan y /\ in_iv x c d /\ in_iv (fp_div m x y) a b }6682ensures { mem y res }6683= le_not_nan c x; le_not_nan a (fp_div m x y);6684index_range x; index_range y;6685region_facts fm true pz pinf y; region_facts fm false minf nz y;6686div_special m x y;6687if pure { is_zero x } then begin6688if pure { is_positive x } then6689assert { x = pz by of_index fm (index x) = of_index fm (index pz) }6690else6691assert { x = nz by of_index fm (index x) = of_index fm (index nz) };6692assert { not is_zero y };6693assert { is_positive y -> in_iv y psub pinf };6694assert { not is_positive y -> in_iv y minf nmax };6695let r = fp_div m x y in6696index_range r;6697if pure { is_positive r } then6698assert { r = pz by of_index fm (index r) = of_index fm (index pz) }6699else6700assert { r = nz by of_index fm (index r) = of_index fm (index nz) };6701assert { mem y zs }6702end else if pure { is_infinity x } then begin6703if pure { is_plus_infinity x } then plus_infinity_unique x6704else minus_infinity_unique x;6705assert { not is_infinity y };6706assert { is_positive y -> in_iv y pz pmax };6707assert { not is_positive y -> in_iv y nmin nz };6708let r = fp_div m x y in6709if pure { is_plus_infinity r } then plus_infinity_unique r6710else minus_infinity_unique r;6711assert { mem y zi }6712end else if pure { is_positive x } then begin6713assert { fmt x = fm /\ 1 <= index x <= nb_sign fm - 2 };6714assert { le_dz psub x /\ le_dz x pmax };6715assert { in_iv x c1 d1 };6716le_trans c1 x d1;6717assert { le_dz c1 d1 };6718assert { is_positive y -> in_iv y pz pinf };6719assert { not is_positive y -> in_iv y minf nz };6720assert { mem y fp };6721assert { mem y fpn }6722end else begin6723assert { fmt x = fm /\ 1 - nb_sign fm <= index x <= -2 };6724assert { le_dz nmin x /\ le_dz x nmax };6725assert { in_iv x c2 d2 };6726le_trans c2 x d2;6727assert { le_dz c2 d2 };6728assert { is_positive y -> in_iv y pz pinf };6729assert { not is_positive y -> in_iv y minf nz };6730assert { mem y fn };6731assert { mem y fpn }6732end in6733{qed}6734res6735Valid (466ms) (cvc5)6736let rec div_back_den_iv_u (ghost fm: format) (minf pinf nz pz: t) (m: mode) (a b: t)6737(l: list (t, t)) : dom6738requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }6739requires { specials4 fm minf pinf nz pz }6740requires { fmt a = fm /\ fmt b = fm /\ le_dz a b /\ ok_u l /\ fmt_u fm l }6741ensures { result.fm = fm }6742ensures { forall x y. fmt y = fm -> is_not_nan y -> mem_u x l ->6743in_iv (fp_div m x y) a b -> mem y result }6744variant { l }6745= match l with6746| Nil -> empty_dom fm6747| Cons (c, d) r ->6748union fm (div_back_den_iv fm minf pinf nz pz m a b c d)6749(div_back_den_iv_u fm minf pinf nz pz m a b r)6750end6751Valid (502ms) (cvc5)6752let rec div_back_den_u (ghost fm: format) (minf pinf nz pz: t) (m: mode)6753(l1 l2: list (t, t)) : dom6754requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }6755requires { specials4 fm minf pinf nz pz }6756requires { ok_u l1 /\ fmt_u fm l1 /\ ok_u l2 /\ fmt_u fm l2 }6757ensures { result.fm = fm }6758ensures { forall x y. fmt y = fm -> is_not_nan y -> mem_u x l2 ->6759mem_u (fp_div m x y) l1 -> mem y result }6760variant { l1 }6761= match l1 with6762| Nil -> empty_dom fm6763| Cons (a, b) r ->6764union fm (div_back_den_iv_u fm minf pinf nz pz m a b l2)6765(div_back_den_u fm minf pinf nz pz m r l2)6766end6767
The y such that x / y is in r for some x in n
Valid (1.0s) (colibri2 28) (cvc4) (cvc5 7) (split_vc) (depth 1)let div_back_den (ghost fm: format) (minf pinf nz pz: t) (m: mode) (r n: dom) : dom6770requires { fmt minf = fm /\ fmt pinf = fm /\ fmt nz = fm /\ fmt pz = fm }6771requires { specials4 fm minf pinf nz pz }6772requires { r.fm = fm /\ n.fm = fm }6773ensures { result.fm = fm }6774ensures { forall x y. fmt y = fm -> mem x n -> mem (fp_div m x y) r -> mem y result }6775= {proof…}6776index_range minf; index_range pinf; index_range nz; index_range pz;6777{qed}6778let u = div_back_den_u fm minf pinf nz pz m r.u n.u in6779let nn =6780if r.nan then6781if n.nan then top fm minf pinf6782else begin6783let p = if meets fm nz pz n6784then union fm (singleton fm nz) (singleton fm pz) else empty_dom fm in6785let q = if meets fm minf minf n || meets fm pinf pinf n6786then union fm (singleton fm minf) (singleton fm pinf) else empty_dom fm in6787union fm (nan_dom fm) (union fm p q)6788end6789else empty_dom fm in6790let res = union fm nn u in6791{proof…}6792let lemma pt (x y: t) : unit6793requires { fmt y = fm /\ mem x n /\ mem (fp_div m x y) r }6794ensures { mem y res }6795= div_special m x y; mul_div_fmt m x y;6796if pure { is_nan (fp_div m x y) } then begin6797if pure { is_not_nan x /\ is_not_nan y } then begin6798index_range x; index_range y;6799if pure { is_zero y } then begin6800if pure { is_positive y } then6801assert { y = pz by of_index fm (index y) = of_index fm (index pz) }6802else6803assert { y = nz by of_index fm (index y) = of_index fm (index nz) };6804assert { index nz <= index x <= index pz }6805end else begin6806if pure { is_plus_infinity y } then plus_infinity_unique y6807else minus_infinity_unique y;6808if pure { is_plus_infinity x } then plus_infinity_unique x6809else minus_infinity_unique x6810end6811end6812end in6813{qed}6814res6815end6816