# Weights

The weights of WFSTs typically belong to particular semirings. The two binary operations $\oplus$ and $\otimes$ are exported as + and *. The null element $\bar{0}$ and unity element $\bar{1}$ can be obtained using the functions zero(W) and one(W) where W<:Semiring.

## Semirings

FiniteStateTransducers.LeftStringWeightType

LeftStringWeight(x)

Set$\oplus$$\otimes$$\bar{0}$$\bar{1} L^*\cup\{\infty\}longest common prefix\cdot$$\infty$$\epsilon where L^* is Kleene closure of the set of characters L and \epsilon the empty string. FiniteStateTransducers.RightStringWeightType RightStringWeight(x) Set\oplus$$\otimes$$\bar{0}$$\bar{1}$
$L^*\cup\{\infty\}$longest common suffix$\cdot$$\infty$$\epsilon$

where $L^*$ is Kleene closure of the set of characters $L$ and $\epsilon$ the empty string.

FiniteStateTransducers.ProductWeightType

ProductWeight(x...)

Set$\oplus$$\otimes$$\bar{0}$$\bar{1} \mathbb{W}_1\times \dots\times\mathbb{W}_N$$\oplus_{\mathbb{W}_1} \times \dots\times\oplus_{\mathbb{W}_N}$$\otimes_{\mathbb{W}_1} \times \dots\times\otimes_{\mathbb{W}_N}$$(\bar{0}_{\mathbb{W}_1},\dots,\bar{0}_{\mathbb{W}_N})$$(\bar{1}_{\mathbb{W}_1},\dots,\bar{1}_{\mathbb{W}_N})$

Use get to extract the contained object by the semiring:

julia> w = TropicalWeight{Float32}(2.3)
2.3f0

julia> typeof(w), typeof(get(w))
(TropicalWeight{Float32}, Float32)


## Semiring properties

Some algorithms are only available for WFST's whose weights belong to semirings that satisfies certain properties. A list of these properties follows:

FiniteStateTransducers.isleftFunction

isleft(::Type{W})

Check if the semiring type W satisfies:

$\forall a,b,c \in \mathbb{W} : c \otimes(a \oplus b) = c \otimes a \oplus c \otimes b$

FiniteStateTransducers.isrightFunction

isright(::Type{W})

Check if the semiring type W satisfies:

$\forall a,b,c \in \mathbb{W} : c \otimes(a \oplus b) = a \otimes c \oplus b \otimes c$

FiniteStateTransducers.isweaklydivisibleFunction

isweaklydivisible(::Type{W})

Check if the semiring type W satisfies:

$\forall a,b \in \mathbb{W} \ \text{s.t.} \ a \oplus b \neq \bar{0} \ \exists z : x = (x \oplus y ) \otimes z$

Notice that these functions are not exported by the package.