Common — library colibrilib.generic_divrem_rewrite — module DefF
395
module DefF
396
use real.RealInfix
397
use real.Abs
398
use real.FromInt
399
400
use colibrilib.q.Real as Real
401
402
use real.Truncate as Truncate
403
404
function
floor
(d:real) (_:real) : int = Truncate.floor d
405
predicate
in_bound_f
(y r:real) = if y <. 0. then y <. r <=. 0. else 0. <=. r <. y
406
407
use Round

The axiom in_bound_uniq of the clone

    Valid (35ms) (colibri2)
410
let lemma
uniq_f
(x y r:real) (d:int)
411
requires { y <> 0. }
412
requires { in_bound_f y r }
413
requires { x = y *. from_int d +. r }
414
ensures { d = floor (x /. y) y /\ r = x -. y *. from_int (floor (x /. y) y) }
415
= assert { x /. y = from_int d +. r /. y };
416
assert { 0. <=. r /. y <. 1. };
417
floor_shift d (r /. y)
418
419
clone Gen as GF {… begin (* cloned colibrilib.generic_divrem_rewrite.Gen *) Valid (20ms) (colibri2) lemma
GF.round_increasing
Valid (21ms) (colibri2) lemma
GF.round_zero
Valid (122ms) (colibri2) lemma
GF.round_add_int
function
GF.div
real real : int function
GF.mod
real real : real Valid (55ms) (cvc4) (split_vc) (depth 1) lemma
GF.mod_in_bound
Valid (182ms) (cvc4) lemma
GF.in_bound_scale
Valid (53ms) (cvc5) lemma
GF.in_bound_bigger_scale
Valid (66ms) (cvc5) lemma
GF.in_bound_scale2
Valid (33ms) (colibri2) lemma
GF.in_bound_uniq
Valid (410ms) (cvc4) lemma
GF.Scaling
function
GF.div_int
int int : int function
GF.mod_int
int int : int let ghost
GF.mod_from_int
int int : int let ghost
GF.divmod_uniq
real real real int : unit let ghost
GF.divmod_uniq2
real real real int : unit let ghost
GF.divmod_facts
real real : unit let ghost
GF.mod_unique
real real real int : unit let ghost
GF.on_diff_period
real real real int : unit let ghost
GF.on_mod
real real : unit let ghost
GF.on_add
real real real : unit let ghost
GF.on_mul
real real int int int : unit let ghost
GF.on_mul_x_int
int real real : unit let ghost
GF.on_mul_int
int int int : unit let ghost
GF.on_add_period
real real int : unit let ghost
GF.on_scale
real real real : unit let ghost
GF.on_x_mul_to_y
real real real : unit let ghost
GF.on_neg
real real : unit let ghost
GF.on_sub
real real real : unit let ghost
GF.on_y_scale
real real int : unit let ghost
GF.when_in_bound
real real : unit let ghost
GF.on_out_mod
real real real : unit let ghost
GF.on_same
real : unit let ghost
GF.on_zero
real : unit let ghost
GF.on_eq_mod
real real real real : unit let ghost
GF.on_eq_div
real real real : unit let ghost
GF.mod_split
real real int : unit let ghost
GF.mod_mod_divisible
real real int : unit let ghost
GF.div_mod_divisible
real real int : int let ghost
GF.div_split
real real int : unit end
}
with function round = floor, predicate in_bound = in_bound_f Valid (16ms) (colibri2)
420
lemma
div_f
: forall x y. Real.div_f x y = GF.div x y Valid (19ms) (colibri2)
421
lemma
mod_f
: forall x y. Real.mod_f x y = GF.mod x y
422
423
use int.Int

Changing the sign of both arguments

    Valid (36ms) (cvc5)
426
let ghost
neg_both
(x y:real) : unit
427
requires { y <> 0. }
428
ensures { GF.mod (-. x) (-. y) = -. GF.mod x y }
429
ensures { GF.div (-. x) (-. y) = GF.div x y } =
430
GF.divmod_facts x y;
431
GF.divmod_uniq (-. x) (-. y) (-. GF.mod x y) (GF.div x y)

y * div x y is the largest multiple of y not above x (floor_a_nz of colibrilib/congruence.mlw)

    Valid (464ms) (cvc4)
435
let ghost
div_max
(x y:real) (k:int) : unit
436
requires { y >. 0. }
437
requires { from_int k *. y <=. x }
438
ensures { k <= GF.div x y } =
439
GF.divmod_facts x y;
440
let d = GF.div x y in
441
if k >= d + 1 then begin
442
assert { from_int k >=. from_int d +. 1. };
443
assert { from_int k *. y >=. (from_int d +. 1.) *. y };
444
assert { false }
445
end
454
(* use int.Int let ghost div_add_error (x1 x2 y:real) : unit requires { y <> 0. } ensures { (GF.div (x1+.x2) y) = GF.div x1 y + GF.div x2 y } = GF.mod_add x1 x2 y; GF.div_uniq (x1+.x2) y (GF.mod (x1 +. x2) y) (GF.div x1 y + GF.div x2 y + GF.div (GF.mod (x1 +. x2) y) y) *)
455
end