Quick Tour

Loading the package

TensorAutomata.jl runs in combination with Semirings.jl. The first step is to import both packages.

julia> using Semirings
julia> using TensorAutomata

Creating a Finte State Automaton

Create a semiring type that will be used for the automaton transitions' weight

julia> S = LogSemiring{Float64,1}Semirings.LogSemiring{Float64, 1}

Define the alphabet over which the automaton is defined

julia> Σ = symtable('a':'z')Dict{Int64, String} with 27 entries:
  5  => "d"
  16 => "o"
  20 => "s"
  12 => "k"
  24 => "w"
  8  => "g"
  17 => "p"
  1  => "ϵ"
  19 => "r"
  22 => "u"
  23 => "v"
  6  => "e"
  11 => "j"
  9  => "h"
  14 => "m"
  3  => "b"
  7  => "f"
  25 => "x"
  4  => "c"
  ⋮  => ⋮

An easy way to create an automaton is to compile it from a text input

julia> fsa = compile(
          TensorFSA{S,2},
          """
          1 2 a x 0.5
          1 2 b y 1.5
          2 3 c z 2.5
          2 3.5
          """;
          symbols = (Σ, Σ)
       )TensorFSA{Semirings.LogSemiring{Float64, 1}, 2, Int64}((Dict(5 => "d", 16 => "o", 20 => "s", 12 => "k", 24 => "w", 8 => "g", 17 => "p", 1 => "ϵ", 19 => "r", 22 => "u"…), Dict(5 => "d", 16 => "o", 20 => "s", 12 => "k", 24 => "w", 8 => "g", 17 => "p", 1 => "ϵ", 19 => "r", 22 => "u"…)), Semirings.LogSemiring{Float64, 1}[-Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; … ;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; … ;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; … ;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;;; … ;;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf 0.5 -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; … ;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf 1.5 -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; … ;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; … ;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf;;; -Inf -Inf -Inf; -Inf -Inf -Inf; -Inf -Inf -Inf],   [1]  =  0.0,   [2]  =  3.5)

To visualize the automaton