package bap-relation
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=63ada71fa4f602bd679174dc6bf780d54aeded40ad4ec20d256df15886e3d2d5
md5=b8b1aff8c6846f2213eafc54de07b304
doc/bap-relation/Bap_relation/index.html
Module Bap_relation
A representation of relations between two sets.
A relation between two sets is a set of pairs made from the elements of these sets. The precise mathematical defition is given below. This module implements a bidirectional mapping between two sets and computes their matching that defines bijections between the sets.
Formal Definition and Notation
Given two sets K and S, with meta-variables x,y,z ranging over K and meta-variables r,s,t ranging over S we will denote a finitary relation R as a subset of the cartesian product K x S, which is a set of pairs (x,r), ..., (z,t), which we represent as a bipartite graph G = (K,S,R).
val empty : ('k -> 'k -> int) -> ('s -> 's -> int) -> ('k, 's) tempty compare_k compare_s the empty relation between two sets.
compare_kis the function that defines order of the elements of the setK.
compare_sis the function that defines order of the elements of the setS.
Example
let empty = Bap_relation.empty
Int.compare
String.compareval is_empty : (_, _) t -> boolis_empty rel is true if the relation rel is an empty set.
add relation x s establishes a relation between x and s.
val mem : ('k, 's) t -> 'k -> 's -> boolmem rel x s is true if (k,s) is in the relation rel.
val findl : ('k, 's) t -> 'k -> 's listfindl rel x finds all pairs in rel that have x on the left.
val findr : ('k, 's) t -> 's -> 'k listfindr rel s finds all pairs in rel that have s on the right.
val fold : ('k, 's) t -> init:'a -> f:('k -> 's -> 'a -> 'a) -> 'afold rel init f folds over all pairs in the relation rel.
val iter : ('k, 's) t -> f:('k -> 's -> unit) -> unititer rel f iterates over all pairs in the relation rel.
Bijections and matching
The set of independent edges M (the matching) of the graph G forms a finite bijection between K and S. It is guaranteed that for each pair (x,s) in M there is no other pair in M, that will include x or s.
Edges R that are not in the matching M represent a subset of R that do not match because of one the two anomalies:
- A non-injective forward mapping occurs when the same value from the set
Sis in relation with more than one value from the setK, e.g.,(x,s), (y,s)is encoded asNon_injective_fwd ([x,y],s);
- A non-injective backward mapping occurs when the same value from the set
Kis in relation with more than one value from the setS, e.g.,(x,r), (x,s)is encoded asNon_injective_bwd ([r;s],x);
val matching :
('k, 's) t ->
?saturated:('k -> 's -> 'a -> 'a) ->
?unmatched:(('k, 's) non_injective -> 'a -> 'a) ->
'a ->
'amatching relation data computes the matching for the given relation.
Calls saturated x s data for each (x,s) in the matching M (see the module description) and unmatched z reason d for each (z,t) in the relation that are not matched, the reason is one of the:
Non_injective_fwd (xs,s)if the mappingK -> Sthat is induced by therelationis non-injective, because the set of valuesxsfromKare mapped to the same valuesinS.
Non_injective_bwd (ss,x)if the mappingS -> Kthat is induced by therelationis non-injective, because the set of valuesssfromSare mapped to the same valuexinK.