package mopsa
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=9f673f79708b44a7effb3b6bb3618d2c
sha512=cb91cb428e43a22f1abbcb8219710d0c10a5b3756d0da392d4084b3b3a6157350776c596983e63def344f617d39964e91f244f60c07958695ee5c8c809a9f0f4
doc/containers/Containers/RelationSig/module-type-S/index.html
Module type RelationSig.SSource
Types
Represents a relation between a domain and a codomain. An element of t can be seen as a set of bindings, i.e., a subset of dom * codom, or as a function from dom to subsets of codom (i.e., a multi-map). Relations are imutable, purely functional data-structures.
Internally, the relation is represented as a map to sets. As a consequence, it is easy to get the post-image of an element of the domain, but hard to get the pre-image of an element of the codomain (use InvRelation if this is needed). We use Maps and Sets, so that it is required to provide OrderedType structures for the domain and codomain.
module CoDomSet : SetExtSig.SData-type for sets of codomain elements.
type codom_set = CoDomSet.tA set of elements of the codomain.
Construction and update
val empty : tThe empty relation.
image x r is the set of elements associated to x in r (possibly the empty set).
set_image x ys r is a new relation where the image of x has been updated to be ys.
is_image_empty x r returns true if there is no element associated to x in r.
val is_empty : t -> boolWhether the relation is empty.
add x y r returns r with a new binding (x,y) added. Previous bindings to x are preserved.
add_set x ys r returns r with all the bindings (x,y) for y in the set ys added. Previous bindings to x are preserved.
remove x y r returns r with the binding (x,y) removed, if it exists. Other bindings to x are preserved.
remove_set x ys r returns r with a all bindings (x,y) for y in the set ys removed. Other bindings to x are preserved.
min_binding r returns the smallest binding in r, for the lexicographic order of domain and codomain. Raises Not_found if the relation is empty.
max_binding r returns the largest binding in r, for the lexicographic order of domain and codomain. Raises Not_found if the relation is empty.
choose r returns an arbitrary binding in r. Raises Not_found if the relation is empty.
val cardinal : t -> intcardinal r returns the number of bindings in r.
Global operations
iter f r applies f x y to every binding (x,y) of r. The bindings are considered in increasing order for the lexicographic order sorting through dom first, and then codom.
fold f r acc folds acc through every binding (x,y) in r through f. The bindings are considered in increasing order for the lexicographic order sorting through dom first, and then codom.
map f r returns a relation where every binding (x,y) is replaced with (x',y')=f x y. The bindings are considered in increasing order for the lexicographic order sorting through dom first, and then codom.
domain_map f r returns a relation where every binding (x,y) is replaced with (f x,y). The bindings are considered in increasing order for the lexicographic order sorting through dom first, and then codom.
codomain_map f r returns a relation where every binding (x,y) is replaced with (x,f y). The bindings are considered in increasing order for the lexicographic order sorting through dom first, and then codom.
for_all f r returns true if f x y is true for every binding (x,y) in r. The bindings are considered in increasing order for the lexicographic order sorting through dom first, and then codom.
exists f r returns true if f x y is true for at leat one binding (x,y) in r. The bindings are considered in increasing order for the lexicographic order sorting through dom first, and then codom.
filter f r returns a relation with only the bindings (x,y) from r where f x y is true.
map_slice f r k1 k2 only applies f to bindings with domain greater or equal to k1 and smaller or equal to k2 to constructed relation is returned. Bindings with domain outside this range in r are put unchanged in the result.
iter_slice f r k1 k2 is similar to iter f r, but only calls f on bindings with domain greater or equal to k1 and smaller or equal to k2.
fold_slice f r k1 k2 a is similar to fold f r, but only calls f on bindings with domain greater or equal to k1 and smaller or equal to k2.
for_all_slice f r k1 k2 a is similar to for_all f r, but only calls f on bindings with domain greater or equal to k1 and smaller or equal to k2. It is as if, outside this range, f k a = true and has no effect.
exists_slice f r k1 k2 a is similar to exists f r, but only calls f on bindings with domain greater or equal to k1 and smaller or equal to k2. It is as if, outside this range, f k a = false and has no effect.
Set operations
subset r1 r2 returns whether the set of bindings in s1 is included in the set of bindings in s2.
Binary operations
val iter2 :
(dom -> codom -> unit) ->
(dom -> codom -> unit) ->
(dom -> codom -> unit) ->
t ->
t ->
unititer2 f1 f2 f r1 r2 applies f1 to the bindings only in r1, f2 to the bindings only in r2, and f to the bindings in both r1 and r2. The bindings are considered in increasing lexicographic order.
val fold2 :
(dom -> codom -> 'a -> 'a) ->
(dom -> codom -> 'a -> 'a) ->
(dom -> codom -> 'a -> 'a) ->
t ->
t ->
'a ->
'afold2 f1 f2 f r1 r2 applies f1 to the bindings only in r1, f2 to the bindings only in r2, and f to the bindings in both r1 and r2. The bindings are considered in increasing lexicographic order.
val for_all2 :
(dom -> codom -> bool) ->
(dom -> codom -> bool) ->
(dom -> codom -> bool) ->
t ->
t ->
boolfor_all2 f1 f2 f r1 r2 is true if f1 is true on all the bindings only in r1, f2 is true on all the bindings only in r2, and f is true on all the bindings both in r1 and r2. The bindings are considered in increasing lexicographic order.
val exists2 :
(dom -> codom -> bool) ->
(dom -> codom -> bool) ->
(dom -> codom -> bool) ->
t ->
t ->
boolexists2 f1 f2 f r1 r2 is true if f1 is true on one binding only in r1 or f2 is true on one binding only in r2, or f is true on one binding both in r1 and r2. The bindings are considered in increasing lexicographic order.
iter2_diff f1 f2 r1 r2 applies f1 to the bindings only in r1 and f2 to the bindings only in r2. The bindings both in r1 and r2 are ignored. The bindings are considered in increasing lexicographic order. It is equivalent to calling iter2 with f = fun x y -> (), but more efficient.
fold2_diff f1 f2 r1 r2 applies f1 to the bindings only in r1 and f2 to the bindings only in r2. The bindings both in r1 and r2 are ignored. The bindings are considered in increasing lexicographic order. It is equivalent to calling fold2 with f = fun x y acc -> acc, but more efficient.
for_all2_diff f1 f2 f r1 r2 is true if f1 is true on all the bindings only in r1 and f2 is true on all the bindings only in r2. The bindings both in r1 and r2 are ignored. The bindings are considered in increasing lexicographic order. It is equivalent to calling for_all2 with f = fun x y -> true, but more efficient.
exists2_diff f1 f2 f r1 r2 is true if f1 is true on one binding only in r1 or f2 is true on one binding only in r2. The bindings both in r1 and r2 are ignored. The bindings are considered in increasing lexicographic order. It is equivalent to calling exists2 with f = fun x y -> false, but more efficient.
Multi-map operations
These functions consider the relation as a map from domain elements to codomain sets.
iter_domain f r applies f x ys for every domain element x and its image set ys in r. The domain elements are considered in increasing order.
fold_domain f r acc applies f x ys acc for every domain element x and its image set ys in r. The domain elements are considered in increasing order.
map_domain f r returns a new relation where the image set ys of x in r is replaced with f x ys. The domain elements are considered in increasing order.
for_all_domain f r returns true if f x ys is true for every domain element x and its image set ys in r. The domain elements are considered in increasing order.
exists_domain f r returns true if f x ys is true for at least one domain element x and its image set ys in r. The domain elements are considered in increasing order.
filter_domain f r returns a new relation restricted to the domain elements x with their image ys from r such that f x ys is true.
min_domain r returns the smallest domain element in r. Raises Not_found if the relation is empty.
max_domain r returns the greatest domain element in r. Raises Not_found if the relation is empty.
choose_domain r returns any domain element in r. Raises Not_found if the relation is empty.
val cardinal_domain : t -> intcardinal r returns the number of distinct domain elements used in r.
elemets_domain r returns the list of domain elements used in r. The elements are returned in increasing order.
Printing
type relation_printer = {print_empty : string;(*Special text for empty relations
*)print_begin : string;(*Text before the first binding
*)print_open : string;(*Text before a domain element
*)print_comma : string;(*Text between a domain and a codomain element
*)print_close : string;(*Text after a codomain element
*)print_sep : string;(*Text between two bindings
*)print_end : string;(*Text after the last binding
*)
}Tells how to print a relation.
val printer_default : relation_printerPrint as set: (dom1,codom1),...,(domN,codomN)
val to_string :
relation_printer ->
(dom -> string) ->
(codom -> string) ->
t ->
stringString representation.
val print :
relation_printer ->
(Stdlib.out_channel -> dom -> unit) ->
(Stdlib.out_channel -> codom -> unit) ->
Stdlib.out_channel ->
t ->
unitPrints to an output_channel (for Printf.(f)printf).
val fprint :
relation_printer ->
(Stdlib.Format.formatter -> dom -> unit) ->
(Stdlib.Format.formatter -> codom -> unit) ->
Stdlib.Format.formatter ->
t ->
unitPrints to a formatter (for Format.(f)printf).
val bprint :
relation_printer ->
(Stdlib.Buffer.t -> dom -> unit) ->
(Stdlib.Buffer.t -> codom -> unit) ->
Stdlib.Buffer.t ->
t ->
unitPrints to a string buffer (for Printf.bprintf).