Common — library colibrilib.bitwise_rules — module TermSize

The size of a node, from its value, its domain of the reals and its types: the proofs of Term.size and Term.monome (the driver binds them to these functions)

775
module TermSize
776
use int.Int
777
use real.RealInfix
778
use real.FromInt
779
use real.Truncate
780
use option.Option
781
use colibrilib.zarith.Zbit
782
use colibrilib.bdd.Node
783
use colibrilib.ibdd.IBDD
784
use colibrilib.env.Env
785
use colibrilib.spec.Opt
786
use colibrilib.stda.StdA as A
787
use colibrilib.union_congr.UnionCongr as UC
788
use Term
789
use TermInterval

The size of the non–negative integers of a domain: the bits of the floor of its upper bound, when its lower bound is non–negative

  Valid (1.0s) (colibri2 3) (split_vc) (depth 1)
793
let
dom_size
(d:env) (n:Node.t) : option int
794
ensures { when_some (has_size d n) result }
795
= match interval d n with
796
| None -> None
797
| Some u ->
798
match UC.get_convex_hull u with
799
| (Some (lo, _), Some (hi, _)) ->
800
let f = A.floor_z hi in
801
if A.le (A.of_bigint 0) lo && 0 <= f then begin
802
{proof…}
803
assert { live d -> 0 <= ienv d n <= f };
804
{qed}
805
Some (Zbit.numbits f)
806
end else None
807
| _ -> None
808
end
809
end

Dom_genrelbitv.get_bv_size: from the value when it is known, else the least of the sizes of the domain and of the types

  Valid (1.1s) (colibri2)
813
let
size
(d:env) (n:Node.t) : option int
814
ensures { when_some (has_size d n) result }
815
= let t = type_size d n in
816
match int_value d n with
817
| Some v ->
818
if 0 <= v then begin
819
Some (Zbit.numbits v)
820
end else t
821
| None ->
822
match t, dom_size d n with
823
| Some a, Some b -> Some (if a <= b then a else b)
824
| Some a, None -> Some a
825
| None, o -> o
826
end
827
end

Dom_genrelbitv.monome_int: the term of the node, of its size if it is known

  Valid (62ms) (colibri2)
831
let
monome
(d:env) (n:Node.t) : IBDD.t
832
ensures { is_term d n result }
833
= monome_sized d n (size d n)
834
end