kaMatrix
functor
signature kaMATRIX
functor kaMatrix
(KA) : kaMATRIX
This functor generates the Kleenean algebra of matrices over a Kleenean algebra.
structure Ring : KA
type t
val dimension : t -> int * int
val tabulate : int * int -> (int * int -> Ring.t) -> t
val sub : t * (int * int) -> Ring.t
val map : (Ring.t -> Ring.t) -> t -> t
val zero : int * int -> t
val unit : int * int -> t
val sum : t * t -> t
val prod : t * t -> t
val star : t -> t
type t
dimension A
tabulate (i, j) f
sub (A, (i, j))
map f t
zero (i, j)
unit (i, j)
sum (A, B)
prod (A, B)
star t
KA, Path
Example:
The matrix algebra can be used for an efficient `all_pairs_shortest_paths'-algorithm: To compute the minimal weight of paths between nodes i and j in a graph, the weights of arcs are coded as a matrix P over the Kleenean algebra Path. The minimal weights of paths between i and j are then the entries of P* in field (i,j).
structure PathMat = kaMatrix(Path); let val z = Path.zero val P = (PathMat.tabulate) (5,5) (fn (0,0) => 0 | (0,1) => 3 | (0,2) => 8 | (0,3) => z | (0,4) => ~4 | (1,0) => z | (1,1) => 0 | (1,2) => z | (1,3) => 1 | (1,4) => 7 | (2,0) => z | (2,1) => 4 | (2,2) => 0 | (2,3) => z | (2,4) => z | (3,0) => 2 | (3,1) => z | (3,2) => ~5| (3,3) => 0 | (3,4) => z | (4,0) => z | (4,1) => z | (4,2) => z | (4,3) => 6 | (4,4) => 0 | _ => raise Size) in PathMat.star P endThis matrix P* is sometimes computed iteratively byfun fast_path M = let val (n,k) = PathMat.dimension M fun f (m,M) = if n-1 <= m then M else f(2*m, PathMat.prod(M,M)) in f (1,M) end;