package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=fdee20e988343751de440b4f6b67c0f4
sha512=f5cbf1328785d3f5ce40155dada2d95e5de5cce4f084ea30cfb04d1ab10cc9403a26cfb3fa55d0f9da72244482130fdb89c286a9aed0d640bba46b7c00e09500
doc/containers/Containers/InvRelation/Make/index.html
Module InvRelation.Make
Source
Generic functor to build a relation data-type from an ordered domain to an ordered codomain.
Parameters
module Dom : InvRelationSig.OrderedType
module CoDom : InvRelationSig.OrderedType
Signature
Types
Represents a relation between a domain and a co-domain. An element of t
can be see as a set of bindings, i.e., a subset of dom
* codom
, or as a function from dom
to subsets of codom
. Relations are imutable, purely functional data-structures.
This data-type maintains both the relation and its inverse, so that we can efficiently compute both the image of a domain element and the inverse image of a codomain element, at the cost of slower insersion and removal (to keep the maps consistent).
Data-type for sets of domain elements.
Data-type for sets of codomain elements.
A set of elements of the codomain.
Construction and update
image x r
is the set of codomain elements associated to x
in r
(possibly the empty set).
inverse y r
is the set of domain elements associated to y
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
.
set_inverse y xs r
is a new relation where the inverse of y
has been updated to be xs
.
is_image_empty x r
returns true if there is a codomain element associated to x
in r
is_inverse_empty y r
returns true if there is a domain element associated to y
in r
.
add x y r
returns r
with a new binding (x
,y
) added. Previous bindings to x
are preserved.
add_image_set x ys r
returns r
with all the bindings (x
,y
) for y
in the set ys
added. Others bindings are preserved.
add_inverse_set xs y r
returns r
with all the bindings (x
,y
) for x
in the set xs
added. Other bindings are preserved.
remove x y r
returns r
with the binding (x
,y
) removed. Other bindings are preserved.
remove_image_set x ys r
returns r
with a all bindings (x
,y
) for y
in the set ys
removed. Other bindings are preserved.
remove_inverse_set xs y r
returns r
with a all bindings (x
,y
) for x
in the set xs
removed. Other bindings are preserved.
remove_inverse y r
returns r
with all bindings (x
,y
) removed.
mem x y r
returns true
if the binding (x
,y
) is present in r
.
of_list l
returns a relation constructed from the list of bindings.
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.
Global operations
iter f r
applies f x y
to every binding (x
,y
) of r
.
fold f r acc
folds acc
through every binding (x
,y
) in r
through f
.
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 dual lexicographic order sorting through codom first, and then dom.
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.
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 ->
unit
iter2 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 ->
'a
fold2 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 ->
bool
for_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 ->
bool
exists2 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.
val fold2_diff :
(dom -> codom -> 'a -> 'a) ->
(dom -> codom -> 'a -> 'a) ->
t ->
t ->
'a ->
'a
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 domain 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.
map2_domain f r1 r2
is similar to map_domain
but applies f
to pairs of image sets ys1
and ys2
corresponding to the same domain element x
in r1
and r2
respectively. r1
and r2
must have the same domain set. The bindings are passed to f
in increasing order of domain elements.
val map2o_domain :
(dom -> codom_set -> codom_set) ->
(dom -> codom_set -> codom_set) ->
(dom -> codom_set -> codom_set -> codom_set) ->
t ->
t ->
t
map2_domain f1 f2 f r1 r2
is similar to map2_domain
but accepts relations with different domain sets. To get a new binding, f1
is used for domain elements appearing only in r1
, f2
for domain elements appearing only in r2
and f
for common domain elements. The bindings are passed in increasing order of domain elements.
val map2zo_domain :
(dom -> codom_set -> codom_set) ->
(dom -> codom_set -> codom_set) ->
(dom -> codom_set -> codom_set -> codom_set) ->
t ->
t ->
t
map2zo_domain f1 f2 f r1 r2
is similar to map2o_domain
but f
is not called on physically equal image sets. The bindings are passed in increasing order of domain elements.
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.
cardinal 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.
Multi-map codomain operations
These functions consider the relation as a map from codomain elements to domain sets.
iter_codomain f r
applies f y xs
for every codomain element y
and its inverse image set xs
in r
. The codomain elements are considered in increasing order.
fold_codomain f r acc
applies f y xs acc
for every codomain element y
and its inverse image set xs
in r
. The codomain elements are considered in increasing order.
map_codomain f r
returns a new relation where the inverse image set xs
of y
in r
is replaced with f y xs
. The codomain elements are considered in increasing order.
for_all_codomain f r
returns true if f y xs
is true for every codomain element y
and its inverse image set xs
in r
. The codomain elements are considered in increasing order.
exists_codomain f r
returns true if f y xs
is true for at least one codomain element y
and its inverse image set xs
in r
. The codomain elements are considered in increasing order.
filter_codomain f r
returns a new relation restricted to the codomain elements y
with their inverse image xs
from r
such that f y xs
is true.
min_codomain r
returns the smallest codomain element in r
. Raises Not_found
if the relation is empty.
max_codomain r
returns the greatest codomain element in r
. Raises Not_found
if the relation is empty.
choose_codomain r
returns any codomain element in r
. Raises Not_found
if the relation is empty.
cardinal r
returns the number of distinct codomain elements used in r
.
elemets_codomain r
returns the list of codomain 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.
Print as set: (dom1,codom1),...,(domN,codomN)
String representation.
val print :
relation_printer ->
(Stdlib.out_channel -> dom -> unit) ->
(Stdlib.out_channel -> codom -> unit) ->
Stdlib.out_channel ->
t ->
unit
Prints 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 ->
unit
Prints 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 ->
unit
Prints to a string buffer (for Printf.bprintf).