Common — library colibrilib.sbdd — module SNode
552
module SNode
553
use colibrilib.bdd.Node
554
use mach.int.Int63
555
type
snode
= {
n
: Node.t;
s
: int63;
scal
: bool }
556
557
use int.Int

The snode nd shifted by off: a scalar snode (the sign of its node) is not moved

    Valid (63ms) (colibri2)
560
let ghost function
shift_snode
(nd: snode) (off: int) : snode
561
requires { nd.scal \/ in_bounds (to_int nd.s - off) }
562
ensures { result.n = nd.n /\ result.scal = nd.scal }
563
ensures { not nd.scal -> to_int result.s = to_int nd.s - off }
564
ensures { nd.scal -> result = nd }
565
= if nd.scal then nd else { n = nd.n; s = of_int (to_int nd.s - off); scal = false }
566
567
use set.Set

The valuation of the snodes shifted by k

570
function
shifted
(sn: Set.set snode) (k: int) : Set.set snode = fun nd -> sn (shift_snode nd k)

The shift of a snode does not fit in an int63

573
exception
Overflow
574
Valid (225ms) (colibri2)
575
let
shift_snode_checked
(nd: snode) (off: int63) : snode
576
ensures { nd.scal \/ in_bounds (to_int nd.s - to_int off) }
577
ensures { result = shift_snode nd off }
578
raises { Overflow -> not nd.scal /\ not (in_bounds (to_int nd.s - to_int off)) }
579
= (* not a nested [if] without [else]: the OCaml extraction drops its [begin end] *)
581
let out = if nd.scal then false else if off >= 0 then nd.s < min_int + off else nd.s > max_int + off in
582
if out then raise Overflow;
583
if nd.scal then nd else { n = nd.n; s = nd.s - off; scal = false }
584
585
end