This library defines the core data structures for weighted finite automata (WFAs) and the word type used throughout SWAL.
Automata.WFA — Weighted finite automaton parameterized over a semiring. A WFA is a triple (ι, δ, λ) where ι is a row vector of initial weights, δ maps each character to a transition matrix, and λ is a column vector of output weights. The semantic function WFA.Make(S).outs computes ι · M(a₁) · … · M(aₙ) · λ for word a₁…aₙ.Automata.Word — Words over the character alphabet, represented as string list. Provides ordered / hashable type for use as map keys, and the Word.suffixes / Word.prefixes closures used by the gen encoding and the learner.Automata.Char — Characters (single string values) with comparator and map / set types.Weights are stored as flat arrays (row-major) wrapped in Algebra.Matrix. The mk constructor takes flat lists for ease of hand-writing benchmarks:
let aut = WFA.Make(S).mk
[S.one; S.zero] (* initial vector *)
(Map.singleton (module Char) "a" [S.zero; S.one; S.one; S.zero])
[S.one; S.zero] (* output vector *)