Module Matrix.Make

Parameters

module S : Semiring.T

Signature

type s = S.t

Internal representation: dimensions (rows, cols) and flat row-major array.

type t = {
  1. dim : Base.int * Base.int;
  2. mat : s Base.array;
}

Internal representation: dimensions (rows, cols) and flat row-major array.

val zero : Base.int -> Base.int -> t

zero r c returns the r×c zero matrix (all entries = S.zero).

val one : Base.int -> t

one n returns the n×n identity matrix (diagonal = S.one, rest S.zero).

val of_list : Base.int -> Base.int -> s Base.list -> t

of_list r c lst constructs an r×c matrix from a flat row-major list. Raises a fatal error if List.length lst ≠ r * c.

val of_rows : t Base.list -> t

of_rows rows stacks a list of 1×n row matrices into an m×n matrix.

val of_cols : t Base.list -> t

of_cols cols assembles a list of m×1 column matrices into an m×n matrix.

val get : t -> Base.int -> Base.int -> s

get m i j returns entry (i, j).

val set : t -> Base.int -> Base.int -> s -> t

set m i j v returns a copy of m with entry (i, j) replaced by v.

val add : t -> t -> t

Semiring matrix addition (entry-wise ⊕).

val mul : t -> t -> t

Semiring matrix multiplication (row × column dot product with ⊕ and ⊗).

val app_col : t -> t -> t

app_col m c appends column vector c to the right of matrix m, increasing the column count by 1. Used by Learner.Angluin to extend observation table rows with new suffix columns.

val app_row : t -> t -> t

app_row m r appends row vector r below matrix m.

val rows : t -> t Base.list

Decompose a matrix into a list of 1×n row matrices.

val cols : t -> t Base.list

Decompose a matrix into a list of m×1 column matrices.

val count : f:(s -> Base.bool) -> t -> Base.int

count ~f m counts the number of entries satisfying predicate f.

val dim : t -> Base.int * Base.int
val solve : t Base.list -> t -> t Base.option

solve basis vec returns coefficient vector c such that Σ_i c_i * basis_i = vec if one exists, or None. Enumerates all combinations of semiring elements (requires finite semiring via S.elements); used by Learner.Angluin for the closed-table check.

val compare : t -> t -> Base.int
val equal : t -> t -> Base.bool
val hash : t -> Base.int
val hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
val to_string : t -> Base.string
val sexp_of_t : t -> Base.Sexp.t
val entries : t -> s Base.list

Flatten the matrix to a row-major list.