Module Bigraph.Sparse
type tThe type of Boolean matrices. Only true values are stored in the matrix as row-column pairs. For example adding value
"(2, 1)"means that the second element in the third row of the matrix is true.
Basic operations
val make : int -> int -> tmake r creturns an empty matrix withrrows andccolumns.
val to_string : t -> stringReturn the string representation of a matrix.
"0" = falseand"1" = true.
val pp : Stdlib.Format.formatter -> t -> unitPretty printer
val apply_rows : Iso.t -> t -> tapply_rows iso mreturns matrixmwith the rows reordered according toiso. The domain ofisois assumed to be{0,...,r}withrthe number of rows ofm.
val apply_cols : Iso.t -> t -> tSame as
apply_rowsbut on columns.
val apply : Iso.t -> t -> tSame as
apply_rowsbut on both rows and columns. The matrix is assumed square.
val parse_vectors : int list list -> int -> tparse_vectors l rparses listlof column vectors to a matrix withrrows andccolumns, withcthe length ofl. Example:parse_vectors [[0;1;2];[1;2]] 4is parsed to the following 4x2 matrix10 11 11 00
val parse_string : int -> int -> int -> Stdlib.String.t list -> (t * t) * (t * t)parse_string r n s rowsparses listrowsof rows encoded as'0''1'strings. The resulting matrix is split as follows:+-----------+-----------+ | | | | a | b | | | | +-----------+-----------+ | | | | c | d | | | | +-----------+-----------+with
a: r * n,b: r * s,c: n * n, andd: n * s.- raises Invalid_argument
when the input strings are not in the correct format.
val dom : t -> IntSet.tReturn the domain of a matrix, that is the set of rows having at least one
trueelement.
val codom : t -> IntSet.tReturn the codomain of a matrix, that is the set of columns having at least one
trueelement.
val iter : (int -> int -> unit) -> t -> unitSame as
Map.iter.
val fold : (int -> int -> 'a -> 'a) -> t -> 'a -> 'aFold iterating over every pair
(i, j)defined by the map.
val fold_c : (int -> IntSet.t -> 'a -> 'a) -> t -> 'a -> 'aDual of
Sparse.fold_r.
val add : int -> int -> t -> tadd i j madds element(i,j). Argumentsiandjare assumed to be valid indexes.
val add_list : t -> (int * int) list -> tAdd a list of elements as in
Sparse.add.
val entries : t -> intReturn the number of
trueelements in a matrix. This is equivalent to the number of edges in a graph.
val edges : t -> (int * int) listReturn the representation of a binary matrix as a list of edges.
val mem : t -> int -> int -> boolmem m i jreturnstrueif edge(i,j)is defined bym.
Matrix operations
val row : int -> trow nreturns a row vector ofntrueelements.
val col : int -> tcol nreturns a column vector ofntrueelements.
val diag : int -> tdiag nreturns a square matrix of sizenwith alltrueelements on the diagonal.
val tens : t -> t -> ttens a breturns the tensor product of matricesaandb. The tensor product is defined according to the following schema:+-----------+-----------+ | | | | a | | | | | +-----------+-----------+ | | | | | b | | | | +-----------+-----------+
val append : t -> t -> tappend a bappends matrixbto the right of matrixa. The two matrices are assumed to have the same number of rows. This operation is described by the diagram below:+-----------+-----------+ | | | | a | b | | | | +-----------+-----------+
val stack : t -> t -> tstack a bstacks matrixaon top of matrixb. The two matrices are assumed to have the same number of columns. This operation is described by the following diagram:+-----------+ | | | a | | | +-----------+ | | | b | | | +-----------+
val glue : t -> t -> t -> t -> ttens a b c dcomputes the matrix defined below:+-----------+-----------+ | | | | a | b | | | | +-----------+-----------+ | | | | c | d | | | | +-----------+-----------+
Graph operations
val siblings : t -> int -> IntSet.tsiblings i mreturns the set of siblings ofi. Two nodes are siblings if they share a parent.
val partners : t -> int -> IntSet.tDual of
Sparse.siblings.
val descendants : t -> int -> IntSet.tdescendants m ireturns the set of nodes reachable fromiin graphm.
val connected_comps : t -> IntSet.t listReturn a list of the connected components of an undirected graph.
val levels : t -> IntSet.t listlevels mreturns the level decomposition ofm. Each level is obtained by iteratively removing the leaves in the graph until no nodes are left. Argumentmis assumed square.
val row_eq : t -> IntSet.t -> IntSet.trow_eq m jscomputes a set of rows such that the union of their children set is equal tojs.
val col_eq : t -> IntSet.t -> IntSet.tDual of
Sparse.row_eq.