Common — library colibrilib.generic_divrem_rewrite — module DefE
324
module DefE
325
use real.RealInfix
326
use real.Abs
327
use real.FromInt
328
329
use colibrilib.q.Real as Real
330
331
use real.Truncate as Truncate
332
333
334
function
toward_zero
(d:real) (b:real) : int =
335
if b <. 0. then (Truncate.ceil d) else (Truncate.floor d)
336
337
predicate
in_bound_e
(y r:real) = 0. <=. r <. abs y
338
339
use int.Int
340
use Round

The axioms in_bound_uniq and Scaling of the clone

    Valid (36ms) (colibri2 7) (cvc5) (split_vc) (depth 1)
343
let lemma
uniq_e
(x y r:real) (d:int)
344
requires { y <> 0. }
345
requires { in_bound_e y r }
346
requires { x = y *. from_int d +. r }
347
ensures { d = toward_zero (x /. y) y /\ r = x -. y *. from_int (toward_zero (x /. y) y) }
348
= assert { x /. y = from_int d +. r /. y };
349
if y <. 0. then begin
350
assert { -. 1. <. r /. y <=. 0. };
351
ceil_shift d (r /. y)
352
end else begin
353
assert { 0. <=. r /. y <. 1. };
354
floor_shift d (r /. y)
355
end
356
Valid (369ms) (cvc5)
357
let lemma
scaling_e
(y:real) (n:int) (r_y:real) (r_n:int)
358
requires { y >. 0. /\ 0 <= r_n < n /\ 0. <=. r_y <. y }
359
ensures { 0. <=. (from_int r_n *. y) +. r_y <. y *. from_int n }
360
= assert { from_int r_n <=. from_int n -. 1. };
361
assert { from_int r_n *. y <=. (from_int n -. 1.) *. y }
362
363
clone Gen as GE {… begin (* cloned colibrilib.generic_divrem_rewrite.Gen *) Valid (30ms) (colibri2) lemma
GE.round_increasing
Valid (25ms) (colibri2) lemma
GE.round_zero
Valid (68ms) (colibri2) lemma
GE.round_add_int
function
GE.div
real real : int function
GE.mod
real real : real Valid (318ms) (cvc5) (split_vc) (depth 1) lemma
GE.mod_in_bound
Valid (22ms) (colibri2) lemma
GE.in_bound_scale
Valid (366ms) (cvc5) lemma
GE.in_bound_bigger_scale
Valid (383ms) (cvc5) lemma
GE.in_bound_scale2
Valid (27ms) (colibri2) lemma
GE.in_bound_uniq
Valid (28ms) (colibri2) lemma
GE.Scaling
function
GE.div_int
int int : int function
GE.mod_int
int int : int let ghost
GE.mod_from_int
int int : int let ghost
GE.divmod_uniq
real real real int : unit let ghost
GE.divmod_uniq2
real real real int : unit let ghost
GE.divmod_facts
real real : unit let ghost
GE.mod_unique
real real real int : unit let ghost
GE.on_diff_period
real real real int : unit let ghost
GE.on_mod
real real : unit let ghost
GE.on_add
real real real : unit let ghost
GE.on_mul
real real int int int : unit let ghost
GE.on_mul_x_int
int real real : unit let ghost
GE.on_mul_int
int int int : unit let ghost
GE.on_add_period
real real int : unit let ghost
GE.on_scale
real real real : unit let ghost
GE.on_x_mul_to_y
real real real : unit let ghost
GE.on_neg
real real : unit let ghost
GE.on_sub
real real real : unit let ghost
GE.on_y_scale
real real int : unit let ghost
GE.when_in_bound
real real : unit let ghost
GE.on_out_mod
real real real : unit let ghost
GE.on_same
real : unit let ghost
GE.on_zero
real : unit let ghost
GE.on_eq_mod
real real real real : unit let ghost
GE.on_eq_div
real real real : unit let ghost
GE.mod_split
real real int : unit let ghost
GE.mod_mod_divisible
real real int : unit let ghost
GE.div_mod_divisible
real real int : int let ghost
GE.div_split
real real int : unit end
}
with function round = toward_zero, predicate in_bound = in_bound_e
364
Valid (21ms) (colibri2)
365
lemma
div_e
: forall x y. Real.div_e x y = GE.div x y Valid (28ms) (colibri2)
366
lemma
mod_e
: forall x y. Real.mod_e x y = GE.mod x y
367
368
use int.Int

The sign of the divisor does not change the Euclidean remainder (norm of colibrilib/congruence.mlw divides by |y|)

    Valid (63ms) (colibri2)
372
let ghost
neg_divisor
(x y:real) : unit
373
requires { y <> 0. }
374
ensures { GE.mod x (-. y) = GE.mod x y }
375
ensures { GE.div x (-. y) = - GE.div x y } =
376
GE.divmod_facts x y;
377
assert { abs (-. y) = abs y };
378
assert { from_int (- GE.div x y) = -. from_int (GE.div x y) };
379
GE.divmod_uniq x (-. y) (GE.mod x y) (- GE.div x y)
380
Valid (39ms) (colibri2)
381
let ghost
abs_divisor
(x y:real) : unit
382
requires { y <> 0. }
383
ensures { GE.mod x (abs y) = GE.mod x y } =
384
if y <. 0. then neg_divisor x y
389
390
(* let ghost contradiction () : unit ensures { false } = GE.div_add 3. 3. 2. *)
391
392
end