Keywords

1 Introduction

Finite-state transducers are used for a large spectrum of translation tasks in text analysis and natural language processing [4,5,6,7]. Many practical translation tasks are functional in the sense that a given input needs to be transformed into a unique output. While (non-deterministic versions of) finite-state transducers can model arbitrary “regular” (s.b.) functions between strings, many regular functions cannot be recognized by deterministic finite-state transducers. In contrast, bimachines as a more powerful type of finite-state device enable a fully deterministic processing of arbitrary regular string functions [11].

For a given regular string function f it is often simple to find a non-deterministic finite-state transducer that represents f. Since a deterministic processing via bimachines is more efficient, there is an obvious interest in general methods for converting functional finite-state transducers into bimachines or equivalent devices [10, 12]. The classical algorithm, described in [7], starts with a preparation step for converting the transducer into an unambiguous transducer. The conversion requires that the source transducer is “pseudo-deterministic”. Afterwards it uses a specialized determinization for discarding unwanted paths. Essentially, only the least accepting paths under some lexicographical order are left. This construction can be applied to arbitrary output monoids after introducing a linear order on the outputs of single transitions.

Here we introduce a new single-step method that can be applied to any functional real-time transducer with output (codomain) in an arbitrary monoid. States of the right deterministic automaton of the bimachine are sets R of active states obtained when using inversed transitions of the functional input transducer \({{\mathcal {T}}}\), starting from final states. States of the left deterministic automaton of the bimachine are sets L of active states of \({{\mathcal {T}}}\) that are enhanced by a special function. Using this enhancement the bimachine satisfies the “path reconstruction” principle: (i) At each step, the bimachine output m represents the output of a single transducer transition step \({\langle { q,{\langle {a,m}\rangle } ,q'}\rangle }\) for some \(q\in L \cap R\). (ii) for any input w: the sequence of bimachine outputs w is given by the sequence of outputs of \({{\mathcal {T}}}\) for w on a specific path.

After formal preliminaries in Sect. 2 the new construction is described in Sect. 3. We start with a generic and flexible version that is conceptually simple. Afterwards a specialized version is added which leads to better complexity bounds for the number of states of the left and right deterministic automata of the bimachine. Correctness proofs are given. For the sake of comparison we sketch the classical bimachine construction in Sect. 4. A class of examples is given where the new construction leads to an exponentially lower number of states. A conclusion is presented in Sect. 5.

2 Formal Preliminaries

We assume that the reader is familiar with the basic notions of words over an alphabet and monoids (see e.g. [2]). The set \(\varSigma ^*\) with concatenation as monoid operation and the empty word \(\varepsilon \) as unit element is called the free monoid over \(\varSigma \). We list notions needed for the discussion of the paper. A monoidal finite-state automaton is a tuple of the form \({{\mathcal {A}}} = {\langle { {{\mathcal {M}}},Q,I,F,\varDelta }\rangle }\) where

  • \({{\mathcal {M}}}={\langle {M,\circ ,e}\rangle }\) is a monoid,

  • Q is a finite set called the set of states,

  • \(I\subseteq Q\) is the set of initial states,

  • \(F\subseteq Q\) is the set of final states, and

  • \(\varDelta \subseteq Q\times M \times Q\) is a finite set of transitions called the transition relation.

A proper path in \({\mathcal {A}}\) is a finite sequence of \(k>0\) transitions, denoted

$$\begin{aligned} \pi = q_0 \rightarrow ^{a_1} q_1 \ldots \rightarrow ^{a_k} q_k \end{aligned}$$

where \({\langle {q_{i-1},a_i,q_i}\rangle } \in \varDelta \) for \(i=1\ldots k\). The monoid element \(w=a_1 \circ \ldots \circ a_k\) is called the label of \(\pi \). A successful path is a path starting in an initial state and ending in a final state.

The generalized transition relation \(\varDelta ^*\) is defined as the smallest subset of \(Q \times M \times Q\) with the following closure properties:

  • for all \(q\in Q\) we have \({\langle {q,e,q}\rangle } \in \varDelta ^*\).

  • For all \(q_1, q_2, q_3\in Q\) and \(w, a \in M\): if \({\langle {q_1,w,q_2}\rangle } \in \varDelta ^*\) and \({\langle {q_2,a,q_3}\rangle } \in \varDelta \), then also \({\langle {q_1,w \circ a,q_3}\rangle } \in \varDelta ^*\).

The monoidal language accepted (or recognized) by \({{\mathcal {A}}}\) is defined as \(L({{\mathcal {A}}}) :={\{w\in M\,|\,\exists p \in I\ \exists q \in F: {\langle {p,w,q}\rangle }\in \varDelta ^*\}}\).

A monoidal finite-state automaton \({{\mathcal {A}}}\) is unambiguous iff for every element \(m \in M\) there exists at most one successful path in \({{\mathcal {A}}}\) with label m.

A state \(q\in Q\) is accessible if q is the ending of a path of \({{\mathcal {A}}}\) starting from an initial state. A state \(q\in Q\) is co-accessible if q is the starting of a path of \({{\mathcal {A}}}\) ending in a final state. A monoidal finite-state automaton \({{\mathcal {A}}}\) is trimmed iff each state \(q\in Q\) is accessible and co-accessible.

A deterministic finite-state automaton is a monoidal finite-state automaton over the free monoid \({{\mathcal {A}}} = {\langle {\varSigma ^*,Q,I,F,\varDelta }\rangle }\), such that \(|I|=1\) and \(\varDelta \) is a graph of a (partial) function with domain \( dom (\varDelta ) \subseteq Q \times \varSigma \). In this case we identify \(\varDelta \) with the function \(\varDelta : Q \times \varSigma \rightarrow Q\) that it represents. The reversed finite-state automaton for \({{\mathcal {A}}}\) is \({{\mathcal {A}}}^{rev}={\langle {\varSigma ^*,Q,F,I,\varDelta ^{rev}}\rangle }\), where \(\varDelta ^{rev}={\{{\langle {q,a^{rev},p}\rangle }\,|\,{\langle {p,a,q}\rangle }\in \varDelta \}}\).

Definition 1

A monoidal finite-state automaton \({{\mathcal {T}}}\) over a monoid \({{\mathcal {M}}}\) is a monoidal finite-state transducer iff \({{\mathcal {M}}}\) can be represented as the Cartesian product of a free monoid \(\varSigma ^*\) with another monoid \({{\mathcal {M}}}'\), i.e. \({{\mathcal {M}}} = \varSigma ^*\times {{\mathcal {M}}}'\). For a monoidal finite-state transducer \({{\mathcal {T}}}= {\langle { \varSigma ^*\times {{\mathcal {M}}},Q,I,F,\varDelta }\rangle }\) the underlying finite-state automaton is the monoidal finite-state automaton \({{\mathcal {A}}}_{{\mathcal {T}}}={\langle {\varSigma ^*,Q,I,F,\varDelta _{\varSigma }}\rangle }\) where \(\varDelta _{\varSigma }={\{{\langle {p,a,q}\rangle }\,|\,\exists m\in M({\langle {p,{\langle {a,m}\rangle },q}\rangle }\in \varDelta \}}\). A monoidal finite-state transducer \({{\mathcal {T}}} = {\langle { \varSigma ^*\times {{\mathcal {M}}}',Q,I,F,\varDelta }\rangle }\) is said to be real-time if \(\varDelta \subseteq Q\times (\varSigma \times M') \times Q\).

Let \({{\mathcal {M}}}\) be a monoid. A set \(L \subseteq M\) is rational iff it is accepted by a monoidal finite-state automaton. If M is a Cartesian product, then rational sets are relations. A rational function is a rational set that is a function.

Definition 2

A bimachine is a tuple \({{\mathcal {B}}}={\langle {{{\mathcal {M}}},{{\mathcal {A}}}_L,{{\mathcal {A}}}_R, \psi }\rangle }\), where:

  • \({{\mathcal {A}}}_L = {\langle {\varSigma ,L,s_L,L,\delta _L}\rangle }\) and \({{\mathcal {A}}}_R = {\langle {\varSigma ,R,s_R,R,\delta _R}\rangle }\) are deterministic finite-state automata called the left and right automaton of the bimachine;

  • \({{\mathcal {M}}} = {\langle {M,\circ ,e}\rangle }\) is the output monoid and \(\psi : (L \times \varSigma \times R) \rightarrow M\) is a partial function called the output function.

Note that all states of \({{\mathcal {A}}}_L\) and \({{\mathcal {A}}}_L\) are final. The function \(\psi \) is naturally extended to the generalized output function \(\psi ^*\) as follows:

  • \(\psi ^*(l,\varepsilon ,r)=e\) for all \(l\in L, r\in R\);

  • \(\psi ^*(l,t\sigma ,r)= \psi ^*(l,t,\delta _R(r,\sigma )) \circ \psi (\delta ^*_L(l,t),\sigma ,r)\) for \(l\in L, r\in R, t\in \varSigma ^*, \sigma \in \varSigma \).

The function represented by the bimachine is

$$\begin{aligned} O_{{\mathcal {B}}}:\varSigma ^*\rightarrow M: t \mapsto \psi ^*(s_L,t,s_R). \end{aligned}$$

If \(O_{{\mathcal {B}}}(t)=t'\) we say that the bimachine \({{\mathcal {B}}}\) translates t into \(t'\).

Note that for any states \(p,q\in Q\) of a monoidal finite-state transducer \({{\mathcal {T}}} = {\langle { \varSigma ^*\times {{\mathcal {M}}},Q,I,F,\varDelta }\rangle }\) and word \(w\in \varSigma ^*\) holds \(\exists m\in M : {\langle {p,{\langle {w,m}\rangle },q}\rangle }\in \varDelta ^* \iff {\langle {p,w,q}\rangle }\in \varDelta _{\varSigma }^*\), where \(\varDelta _{\varSigma }\) is the transition relation of its underlying automaton.

If \({{\mathcal {A}}}^{rev}={\langle {\varSigma ^*,Q,F,I,\varDelta ^{rev}}\rangle }\) is the reversed finite-state automaton of \({{\mathcal {A}}}={\langle {\varSigma ^*,Q,I,F,\varDelta }\rangle }\), then for any states \(q,p \in Q\) and any word \(w \in \varSigma ^*\) we have \({\langle {p,w,q}\rangle } \in \varDelta ^*\iff {\langle {q,w^{rev},p}\rangle } \in {\varDelta ^{rev}}^*.\)

After applying the power-set construction to transform a nondeterministic automaton \({{\mathcal {A}}}={\langle {\varSigma ^*,Q,I,F,\varDelta }\rangle }\) into an equivalent deterministic one \({{\mathcal {A}}}_D= {\langle {\varSigma ^*,Q_D,\{I\},F_D,\delta _D}\rangle }\) with states \(Q_D\subseteq 2^Q\) the following holds:

$$\begin{aligned} \forall w\in \varSigma ^*\ \forall P\in Q_D : \delta _D^*(P,w)={\{q\,|\,\exists p\in P : {\langle {p,w,q}\rangle }\in \varDelta ^*\}}. \end{aligned}$$

Proposition 1

(Cf. e.g. [7]) Let \({{\mathcal {A}}}= {\langle {\varSigma ^*\times {{\mathcal {M}}}, Q, I, F, \varDelta }\rangle }\) be a trimmed monoidal transducer. If \({{\mathcal {A}}}\) does not contain any cycle of the form \( {\langle { p,{\langle {\varepsilon ,m}\rangle },p}\rangle }\in \varDelta ^*\) with \(m\ne e\), then \({{\mathcal {A}}}\) can be effectively transformed into a real-time transducer \({{\mathcal {A}}}'\) such that \(L({{\mathcal {A}}})\cap (\varSigma ^+ \times M) =L({{\mathcal {A}}'})\cap (\varSigma ^+ \times M)\). Furthermore, we can effectively compute the set \({\{m\,|\,{\langle {\varepsilon ,m}\rangle }\in L({{\mathcal {A}}})\}}\).

3 New Bimachine Construction

From now on we assume that \({{\mathcal {T}}}= {\langle {\varSigma ^*\times {{\mathcal {M}}}, Q, I, F, \varDelta }\rangle }\) is any trimmed real-time functional monoidal transducer. We assume that \({\langle {\varepsilon ,e}\rangle } \in L({{\mathcal {T}}})\). Let \({{\mathcal {A}}}_{{\mathcal {T}}}={\langle {\varSigma ^*,Q,I,F,\varDelta _{\varSigma }}\rangle }\) be the underlying finite-state automaton of \({{\mathcal {T}}}\) and \({{\mathcal {A}}}^{rev}_{{\mathcal {T}}}={\langle {\varSigma ^*,Q,F,I,\varDelta ^{rev}_{\varSigma }}\rangle }\) be the reverse finite-state automaton of \({{\mathcal {A}}}_{{\mathcal {T}}}\). Let \({{{\mathcal {A}}}_{{\mathcal {T}}}}_D={\langle {\varSigma ^*,2^Q,\{I\},F_D,{\delta _{\varSigma }}_D}\rangle }\) and \({{{\mathcal {A}}}^{rev}_{{\mathcal {T}}}}_D={\langle {\varSigma ^*,2^Q,\{F\},I_D,{\delta ^{rev}_{\varSigma }}_D}\rangle }\) be the deterministic finite-state automata for \({{\mathcal {A}}}_{{\mathcal {T}}}\) and \({{\mathcal {A}}}^{rev}_{{\mathcal {T}}}\), respectively.

For each set of states \(P\subseteq Q\) and \(w\in \varSigma ^*\), we define the set of w-successors and w-predecessors of P as

$$\begin{aligned} Succ _w(P):= & {} {\delta _{\varSigma }}_D^*(P,w) = {\{q\in Q\,|\, \exists p\in P,m\in M: {\langle {p,{\langle {w,m}\rangle }, q}\rangle } \in \varDelta ^*\}}\\ Pred _w(P):= & {} {\delta ^{rev}_{\varSigma }}_D^*(P,w) = {\{q\in Q\,|\,\exists p\in P,m\in M: {\langle {q,{\langle {w^{rev},m }\rangle }, p}\rangle } \in \varDelta ^*\}}. \end{aligned}$$

Note that the first (second) clause is based on a left-to-right (right-to-left) reading order.

Lemma 1

(Butterfly Lemma). Let \({{\mathcal {T}}}\) be as above. Let \(u,v\in \varSigma ^*\), \(a\in \varSigma \), let \(L := Succ _{u}(I)\), \(L' := Succ _{ua}(I)\), \(R' := Pred _{v}(F)\) and \(R := Pred _{av}(F)\). Then

  1. 1.

    for all \(q\in L\cap R\) there is \(q'\in L'\cap R'\) and \(m\in M\) such that \({\langle q,\langle a,m\rangle ,q'\rangle \in \varDelta }\),

  2. 2.

    for all \(q'\in L'\cap R'\) there is \(q\in L\cap R\) and \(m\in M\) such that \({\langle q,\langle a,m\rangle ,q'\rangle \in \varDelta }\),

  3. 3.

    \(L\cap R \ne \emptyset \) iff \(L'\cap R' \ne \emptyset \).

Proof

As to 1, let \(q\in L\cap R\). Since \(R= Pred _a(R')\) there exists a transition of the form \(\langle q,\langle a,m\rangle ,q'\rangle \in \varDelta \) such that \(q'\in R\). Since \(q \in L\) we have \(q'\in L'\). 2 follows by a symmetric argument. 3 directly follows from 1 and 2.    \(\square \)

3.1 Generic Construction

We now show how to build an equivalent bimachine \({{\mathcal {B}}}={\langle {{{\mathcal {M}}},{{\mathcal {A}}}_L,{{\mathcal {A}}}_R, \psi }\rangle }\), given the transducer \({{\mathcal {T}}}\) as input. First, we construct the right automaton \({{\mathcal {A}}}_R\) applying a determinization procedure to the reversed underlying automaton of \({{\mathcal {T}}}\). Let

$$\begin{aligned}{{\mathcal {A}}}_R = {{{\mathcal {A}}}^{rev}_{{\mathcal {T}}}}_D={\langle {\varSigma ^*,Q_R,s_R,F_R,\delta _R}\rangle }.\end{aligned}$$

By definition \(s_R=\{F\}\) and \(\delta _R(R,a) = {\delta ^{rev}_{\varSigma }}_D(R,a) = Pred _a(R)\) for \(R \in Q_R\) and \(a\in \varSigma \). The idea for the left automaton is to use the accessible sets in \({{{\mathcal {A}}}_{{\mathcal {T}}}}_D\)

$$\begin{aligned}Q_L' := {\{{\delta _{\varSigma }}^*_D(I,w)\,|\,w\in \varSigma ^*\}} = {\{ Succ _w(I)\,|\,w\in \varSigma ^*\}}\end{aligned}$$

as a “core” part of the states, but to enrich this core part by additional information that enables the reconstruction of successful paths in \({{\mathcal {T}}}\). Let \(L\in Q_L'\). An L-centered state selector function is a partial function \(\phi : Q_R \rightarrow Q\) such that the following conditions hold for any state of the right automaton \(R \in Q_R\):

  1. 1.

    \(\phi (R)\) is defined iff \(R\cap L\ne \emptyset \) and

  2. 2.

    if \(\phi (R)\) is defined, then \(\phi (R)\in R\cap L\).

A state of the left automaton \({{\mathcal {A}}}_L = {\langle {\varSigma , Q_L, s_L, Q_L, \delta _L}\rangle }\) is a pair \({\langle {L,\phi }\rangle }\) where \(L \in Q_L'\) and \(\phi \) is an L-centered state selector function. The following induction defines \(s_L\), the set of states \(Q_L\), and the transition function \(\delta _L\).

  • \(s_L := {\langle {I,\phi _0}\rangle }\) where \(\phi _0(R) := \left\{ \begin{array}{ll}\text{ any } \text{ element } \text{ of } R\cap I &{} \text{ if } R\cap I\ne \emptyset \\ \text{ undefined } &{} \text{ otherwise. } \end{array}\right. \)

  • For \({\langle {L,\phi }\rangle }\in Q_L\) and \(a\in \varSigma \) we define \(\delta _L({\langle {L,\phi }\rangle },a) := \langle L',\phi '\rangle \) where

    • \(L' := Succ _a(L)\).

    • \(\phi '(R') := \left\{ \begin{array}{ll}\text{ any } \text{ element } \text{ of }&{} {\{q'\,|\,\exists m \in M : {\langle {q, {\langle {a,m}\rangle }, q'}\rangle } \in \varDelta \}}\\ &{} \text{ if } q=\phi ( Pred _a(R')) \text{ is } \text{ defined }\\ \text{ undefined } &{} \text{ otherwise. } \end{array}\right. \)

In the above notions we show that

  1. 1.

    for each state \({\langle {L,\phi }\rangle }\) always \(\phi \) is an L-centered state selection function, and

  2. 2.

    if \(\phi ( Pred _a(R'))\) is defined, then \(q'=\phi '(R')\) is also defined.

The proof is by induction. For \(s_L := {\langle {I,\phi _0}\rangle }\) clearly \(\phi _0\) is defined as an I-centered state selection function. For the induction step, given state \({\langle {L,\phi }\rangle }\) assume that \(\phi \) is an L-centered state selection function. Let \(R'\in Q_R\) and \(R := Pred _a(R')\). First, if \(q=\phi (R)\) is defined, then (\(\phi \) is L-centered) \(L\cap R\ne \emptyset \) and \(q\in L\cap R\). By the Butterfly Lemma we have that \(L'\cap R' \ne \emptyset \) and further there exists a transition \(\langle q,\langle a,m\rangle ,q'\rangle \in \varDelta \) such that \(q'\in L'\cap R'\). Therefore \(q'=\phi '(R')\) is defined and \(\phi '(R')\in L'\cap R'\). On the other hand, if \(\phi (R)\) is undefined, then (\(\phi \) is L-centered) \(L\cap R=\emptyset \) and (Butterfly Lemma) \(L'\cap R' = \emptyset \). It follows that \(\phi '\) is \(L'\)-centered.

It remains to define the output function \(\psi \) of the bimachine. Given a pair of states \({\langle {L,\phi }\rangle }\) and \(R'\) of the left and right automaton and \(a\in \varSigma \), let \({\langle {L',\phi '}\rangle } := \delta _L(\langle L,\phi \rangle ,a)\) and \(R := Pred _a(R')=\delta _R(R',a)\). Then

$$\begin{aligned}\psi ({\langle {L,\phi }\rangle },a,R') := \left\{ \begin{array}{ll}\text{ any } \text{ element } \text{ of } {\{m\,|\,{\langle {\phi (R),{\langle {a,m}\rangle },\phi '(R')}\rangle }\in \varDelta \}} &{} \text{ if } !\phi (R) \\ \text{ undefined } &{} \text{ otherwise } \end{array}\right. \end{aligned}$$

(We have shown above that there always exists a transition of the above form.)

Correctness. We now show that the function defined by the bimachine \({{\mathcal {B}}} = {\langle {{{\mathcal {A}}}_L, {{\mathcal {A}}}_R, \psi }\rangle }\) coincides with the language of the transducer \({{\mathcal {T}}}\).

Theorem 1

Let \(u=a_1\ldots a_k \in dom ({{\mathcal {T}}})\). For \(i\in \{0,1,\dots ,k\}\) let \({\langle {L_i,\phi _i}\rangle } :=\delta _L^*(s_L,a_1\dots a_i)\) and \(R_i :=\delta _R^*(s_R,a_k,\dots ,a_{i+1})\). Then for any \(i\le k\) the following hold:

  1. 1.

    \(q_i :=\phi _i(R_i)\) is defined.

  2. 2.

    \(m_{i+1} :=\psi (L_i,a_{i+1},R_{i+1})\) is defined and \({\langle {q_i,{\langle {a_{i+1},m_{i+1}}\rangle },q_{i+1}}\rangle }\in \varDelta \).

Furthermore \(O_{{\mathcal {B}}}=L({{\mathcal {T}}})\).

Proof

Let \(u_i=a_1\dots a_i\) and \(v_i=a_{i+1}\dots a_k\). Then we have that \(L_i=Succ_{u_i}(I)\) and \(R_i=Pred_{v_i}(F)\). Since \(u_iv_i=u\in dom ({{\mathcal {T}}})\) it follows that \(L_i\cap R_i\ne \emptyset \). Thus, since \(\phi _i\) is \(L_i\)-centered we deduce that \(q_i=\phi _i(R_i)\) is defined. Further, since \(q_{i+1}=\phi _{i+1}(R_{i+1})\) is well-defined it follows that there is a transition \({\langle {q_i,{\langle {a_{i+1},m_{i+1}}\rangle },q_{i+1}}\rangle }\in \varDelta \). As a consequence we obtain

$$\begin{aligned} {\langle {q_0,{\langle {u,m_1\dots m_k}\rangle },q_k}\rangle }\in \varDelta ^*. \end{aligned}$$

Since \(q_0=\phi _0(R_0)\in L_0= I\) and \(q_k=\phi _k(R_k)\in R_k=F\) we have \({\langle {u,m_1\dots m_k}\rangle }\in L({{\mathcal {T}}})\). Furthermore in this case \(O_{{\mathcal {B}}}(u)=m_1\dots m_k=L({{\mathcal {T}}})(u)\). This proves that if \(u\in dom ({{\mathcal {T}}})\), then \(u\in dom ({{\mathcal {B}}})\) and \(L({{\mathcal {T}}})(u)=O_{{\mathcal {B}}}(u)\).

Finally, if \(u\not \in dom ({{\mathcal {T}}})\), then \(R_0\cap I=\emptyset \) and therefore \(\phi _0(R_0)\) is not defined. In particular, \(O_{{\mathcal {B}}}(u)\) is not defined. Hence both functions have the same domain and coincide.

Remark 1

The construction can be applied to a non-functional transducer \({{\mathcal {T}}}\) and in this case for the output function of the bimachine we have \(O_{{\mathcal {B}}} \subseteq L({{\mathcal {T}}})\).

Applying the standard conversion of a bimachine to transducer we obtain the following corollary.

Corollary 1

For any functional monoidal finite-state transducer \({{\mathcal {T}}}\) there exists an unambiguous monoidal finite-state transducer \({{\mathcal {T}}}'\) such that \(L({{\mathcal {T}}}) = L({{\mathcal {T}}}')\).

Proof

After constructing the bimachine \({{\mathcal {B}}}\) we define the monoidal finite-state transducer \({{\mathcal {T}}'} = {\langle {\varSigma ^*\times {{\mathcal {M}}}, Q_L \times Q_R, \{s_L\}\times Q_R, Q_L \times \{s_R\},\varDelta '}\rangle }\), where

$$\begin{aligned}\varDelta := {\{{\langle {{\langle {l,r}\rangle },{\langle {a,m}\rangle },{\langle {l',r'}\rangle }}\rangle }\,|\,l'=\delta _L(l,a), r = \delta _R(r',a), m = \psi (l,a,r')\}}.\end{aligned}$$

It can be shown that \(L({{\mathcal {T}}}) = L({{\mathcal {T}}}')\).

3.2 Complexity Analysis and Specialized Construction

When using the generic construction presented above we obtain the bound \(|Q_R| \le \vert 2^Q\vert \) for the number of states of the right automaton \({{\mathcal {A}}}_R\). The number of (partial) functions mapping \(Q_R\) to Q is \((|Q|+1)^{|Q_R|}\). Hence the number of states of \({{\mathcal {A}}}_L\) satisfies

$$\begin{aligned} |Q_L| \le 2^{|Q|} (|Q|+1)^{|Q_R|} \le 2^{|Q|}(|Q|+1)^{2^{|Q|}}=2^{|Q|+2^{|Q|}\log (|Q|+1)}. \end{aligned}$$

A characteristics of the above generic construction is the arbitrariness of the selection of a state \(q'\) in the second clause of the inductive definition of the states of the left automaton. Since each new state selection function introduced during the construction produces its own swarm of followers the question arises if a more principled approach to select \(q'\) helps to avoid any unnecessary blow-up and to reduce the upper bound on the number of states of \({{\mathcal {A}}}_L\).

To this end we apply the idea to compare paths of transducers using the lexicographic ordering. It has been successfully used in different uniformization problems related to transducers [3, 8, 9, 12]. In the context of bimachines, we use the idea to specialize the generic selection mechanism described in the previous section.

figure a

First, we define the states of the left automaton \({{\mathcal {A}}}_L\) as pairs \(p={\langle {L,<_p}\rangle }\), see also Algorithm 1. As before, the left component L is always an element of \(Q_L' := \{ Succ _w(I)\mid w\in \varSigma ^*\}\). The second component \(<_p\) is a strict linear order on L. The ordering \(<_p\) induces a canonical state selector function \(\phi _{<_p}(R)\): if \(L\cap R\ne \emptyset \), then \(\phi _{<_p}(R)\) is defined as the \(<_p\)-minimal element of \(L\cap R\). Otherwise \(\phi _{<_p}(R)\) is undefined. Note that in this way state selector functions are always L-centered. Still, in order to follow this line, we need a method for defining the a-successor \(q={\langle {L',<_q}\rangle }\) of a state \(p={\langle {L,<_p}\rangle }\) in such a way that the \(<_q\)-minimal element of \(L'\cap R'\) always represents a state \(q'\) with \({\langle {q,{\langle {a,.}\rangle },q'}\rangle }\in \varDelta \).

Given \({\langle {L,<_p}\rangle }\) and a state \(r' \in L':= Succ _a(L)\) the set of a-predecessors of \(r'\) in L is defined as \( Pred _{a,L}(r') := L\cap Pred_a(\{r'\})\). Note that, by the definition of \(L'\), each set \( Pred _{a,L}(r')\) where \(r'\in L'\) is non-empty. The \(<_p\) -minimal a -predecessor of \(r'\) in L, denoted \( min\_pred _{a,L}(r')\), is the minimal element of \( Pred _{a,L}(r')\) with respect to the ordering \(<_p\).

We define the initial state, \(s_L\), the set of states, \(Q_L\), and the new transition function, \(\delta _L\), for the new definition of the left automaton, \({{\mathcal {A}}}_L\), as follows:

  • \(s_L := {\langle {I,<_0}\rangle }\) where \(<_0\) is any fixed linear order of I.

  • For \({\langle {L,<}\rangle }\in Q_L\) and \(a\in \varSigma \) we define \(\delta _L({\langle {L,<}\rangle },a) :=(L',<')\) where \(L' := Succ _a(L)\) and \(<'\) is any linear order on \(L'\) satisfying the condition

    $$\begin{aligned} \forall p',r'\in L': p' \le ' r' \Rightarrow min\_pred _{a,L}(p') \le min\_pred _{a,L}(r'). \end{aligned}$$

A linear order \(<'\) of this form is obtained by starting with the elements of \(L'\) that have the <-minimal element \(q_{min}\) of L as their <-minimal a-predecessor (the ordering between these elements of \(L'\) is arbitrary). We then continue with the elements of \(L'\) that have the <-minimal element of \(L\setminus \{q_{min}\}\) as their <-minimal a-predecessor, etc.

The following lemma shows that the new construction is a specialized version of the former construction described above.

Lemma 2

Let \((L,<)\) and \((L',<')\) be as above. Let \(\phi _{<}\) and \(\phi _{<'}\) denote the canonical state selector functions corresponding to < and \(<'\), respectively. Let \(R'\in Q_R\) and \(R := Pred _a(R')\). Then \(\phi _{<'}(R')\) is defined iff \(\phi _{<}(R)\) is defined. Furthermore, if \(q=\phi _{<}(R)\) and \(q'=\phi '(R')\) are defined, then \(\langle q,{\langle {a,m}\rangle },q'\rangle \in \varDelta \) for some \(m\in M\).

Proof

The Butterfly Lemma shows that

$$\begin{aligned} \phi _<(R) \text{ is } \text{ defined }\overset{def}{\iff } L \cap R \ne \emptyset \underset{\text {Lemma}}{\overset{\text {Butterfly}}{\iff }} L' \cap R' \ne \emptyset \overset{def}{\iff } \phi _{<'}(R') \text{ is } \text{ defined } \end{aligned}$$

If \(\phi _{<}(R)\) and \(\phi _{<'}(R')\) are defined, then \(q := \phi _{<}(R)\) is a <-minimal state of \(L\cap R\) and \(q' := \phi _{<'}(R')\) is a \(<'\)-minimal state of \(L'\cap R'\). The Butterfly Lemma shows that there exist \(p \in L\cap R\), \(m\in M\), and a transition \(\langle p,\langle a,m\rangle ,q'\rangle \in \varDelta \). Let \(p_0\) be a <-minimal element of \(L \cap R\) with this property. We claim that \(p_0=q\). The Butterfly Lemma shows that there exist \(p'\in L' \cap R'\) and \(m'\in M\) with \(\langle q,\langle a,m'\rangle , p'\rangle \in \varDelta \). From the minimality of \(q'\) we obtain \(q'\le ' p'\), the definition of \(\le '\) shows that \(p_0\le q\). Minimality of q implies that in fact \(p_0=q\). It follows that there exists a transition \(\langle q,\langle a,m\rangle , q'\rangle \in \varDelta \).

Theorem 2

Given a functional real-time transducer \({{\mathcal {T}}}={\langle {\varSigma ,{{\mathcal {M}}},Q,I,\varDelta ,F}\rangle }\) we can construct an equivalent bimachine \({{\mathcal {B}}}={\langle {{{\mathcal {A}}}_L,{{\mathcal {A}}}_R,\psi }\rangle }\) such that the number of states of \({{\mathcal {A}}}_L\) is O(|Q|!) and the number of states of \({{\mathcal {A}}}_R\) is \(O(2^{|Q|})\).

Proof

Clearly, the number of states of \({{\mathcal {A}}}_R\) is \(O(2^{|Q|})\). Let Seq(Q) denote the set of linearly ordered subsets of Q. In the specialized construction, the states of \({{\mathcal {A}}}_L\) can be represented as elements of Seq(Q). We have

$$\begin{aligned} |Seq(Q)|=\sum _{k=0}^{|Q|} \left( {\begin{array}{c}|Q|\\ k\end{array}}\right) k!=\sum _{k=0}^{|Q|} \frac{|Q|!}{(|Q|-k)!}= 2|Q|! +\sum _{k=0}^{|Q|-2} \frac{|Q|!}{(|Q|-k)!}. \end{aligned}$$

Taking into account that \((|Q|-k)!\ge 2^{|Q|-k}\) for \(k\le |Q|-2\) we obtain:

$$\begin{aligned} |Seq(Q)|= 2|Q|! +\sum _{k=0}^{|Q|-2} \frac{|Q|!}{(|Q|-k)!}\le 2|Q|! +\sum _{k=0}^{|Q|-2}\frac{|Q|!}{2^{|Q|-k}}\le 3|Q|! \end{aligned}$$

thus showing that \(|Q_L'|\le |Seq(Q)|\le 3|Q|!\).    \(\square \)

4 Remark on the Classical Bimachine Construction

The classical construction of bimachines [2] refers to the special case where \({{\mathcal {M}}}={\langle {\varOmega ^*,\circ ,\varepsilon }\rangle }\) is the free monoid generated by an alphabet \(\varOmega \). As described in [7], but see also the proofs in [1, 2, 8], it departs from a pseudo-deterministic transducer, i.e. a transducer \({{\mathcal {T}}}={\langle {\varSigma \times \varOmega ^*,Q,I,F,\varDelta }\rangle }\) that can be considered as a deterministic finite-state automaton over the new alphabet \(\varSigma \times \varOmega ^*\). This means that I contains a single state i and \(\varDelta \) is a finite graph of a function \(Q\times (\varSigma \times \varOmega ^*)\rightarrow Q\).

The next step is the core of the construction. The goal is to construct an unambiguous transducer \({{\mathcal {T}}}'\) equivalent to \({{\mathcal {T}}}\). This is achieved by specializing the standard determinization construction for finite-state automata: the sets generated by the determinization procedure are split into two parts, a single guessed positive state – this is our positive hypothesis for the successful path to be followed, and a set of negative states – these are the alternative hypotheses that must all fail in order for our positive hypothesis to be confirmed. Formally, the states in the resulting transducer are pairs \({\langle {p,N}\rangle }\in Q\times 2^Q\). The initial state is \(i'={\langle {i,\emptyset }\rangle }\). The algorithm inductively defines transitions in \(\varDelta '\) and states in \(Q'\). Let \(\prec _{lex}\) denote the lexicographic order on \(\varSigma ^*\). For a generated state \({\langle {p,N}\rangle }\) and each transition \({\langle {p,{\langle {a,v}\rangle },p'}\rangle }\in \varDelta \) we obtain a transition

$$\begin{aligned}&{\langle {{\langle {p,N}\rangle },{\langle {a,v}\rangle },{\langle {p',N'}\rangle }}\rangle }\in \varDelta ', \text { where }\\ N'= & {} Succ_a(N) \cup \{q \,|\, \exists v'\prec _{lex} v({\langle {p,{\langle {a,v'}\rangle },q}\rangle }\in \varDelta \}. \end{aligned}$$

The pair \({\langle {p',N'}\rangle }\) is added to \(Q'\). Intuitively, this transition makes a guess about the lexicographically smallest continuation of the output that can be followed to a final state \(f\in F\). Accordingly, all transitions that have the same input character, a, but lexicographically smaller output, are implicitly assumed to fail. To reflect this, we add those states to the set of negative hypotheses, \(N'\). To maintain the previously accumulated negative hypotheses along the path to \({\langle {p,N}\rangle }\) the a-successors of N are added to \(N'\). Following these lines, the set of final states of \({{\mathcal {T}}}'\) is defined as:

$$\begin{aligned} F'=\{{\langle {f,N}\rangle }\,|\, f\in F \text { and } N\cap F=\emptyset \}. \end{aligned}$$

Note, that \({\langle {f,N}\rangle }\) becomes final only if \(f\in F\) and there is no final state \(n\in N\) reached with smaller output on a parallel path. It can be formally shown [7], that this construction indeed leads to an unambiguous transducer:

$$\begin{aligned} {{\mathcal {T}}}'={\langle {\varSigma \times \varOmega ^*,Q',\{i'\},F',\varDelta '}\rangle } \end{aligned}$$

equivalent to \({{\mathcal {T}}}\).

The final step is to convert the (trimmed part of) \({{\mathcal {T}}}'\) in an equivalent bimachine. This can be easily done by a determinization of \({{\mathcal {A}}}_L={{\mathcal {A}}}_{{{\mathcal {T}}}',D}\) and \({{\mathcal {A}}}_R={{{\mathcal {A}}}_\mathcal{{T}'}^{rev}}_{D}\) and defining an appropriate output function \(\psi :Q_L\times \varSigma \times Q_R\rightarrow \varOmega ^*\). The following points have to be stressed about this construction.

Remark 2

The states of the left automaton are sets \(L\subseteq 2^{Q\times 2^{Q}}\). Yet, these sets have an inner structure that enables a non-trivial upper bound on their number, \(|Q_L|=O(|Q|!\exp (|Q|+1))\). We sketch the main points of the proof:

  • First, if \(q={\langle {p',N'}\rangle }\in L\), then, since q is co-accessible in \({{\mathcal {T}}}'\), it follows that \(p'\not \in N'\). Assume now that \({\langle {p',N'}\rangle },{\langle {p'',N''}\rangle }\in L\).

  • Let \({\langle {p',N'}\rangle }\ne {\langle {p'',N''}\rangle }\in {{\mathcal {T}}}'\) be distinct states accessible via the same input word \(u\in \varSigma ^*\). Then either \(\{p'\}\cup N'\subseteq N''\) or \(\{p''\}\cup N''\subseteq N'\) (the proof uses a simple induction on |u|).

  • Let \({\langle {p',N'}\rangle }\ne {\langle {p'',N''}\rangle }\in L\) be distinct. Then, \({\langle {p',N'}\rangle }\) and \({\langle {p'',N''}\rangle }\) are all accessible in \({{\mathcal {T}}}\) via a common word \(u\in \varSigma \). By the above argument we can assume that \(\{p'\}\cup N'\subseteq N''\). By the first argument we have that \(p''\not \in N''\) and therefore \(\{p'\}\cup N' \subsetneq \{p''\}\cup N''\).

  • This proves that every left state \(L=\{{\langle {p_i,N_i}\rangle }\,|\, i\le |L|\}\) induces a linear order on \(\{p_1,\dots , p_{|L|}\}\) by defining \(p_i< p_j\) if and only if \(\{p_i\}\cup N_i\subsetneq \{p_j\} \cup N_j\). This shows that the left states L arise as linear orders of the states \(\{p_1,\dots ,p_{|L|}\}\) and some additional elements \(q\in Q\setminus \{p_1,\dots ,p_{|L|}\}\) that belong to some \(N_i\). By the third point we can assign each such state q to the least \(N_i\) with \(q\in N_i\). By the linear order it will belong to all the bigger sets \(\{p_j\}\cup N_j\).

  • With this remarks, the problem becomes a combinatorial one and using ideas similar to those in the proof of Theorem 2 one can prove that

    $$\begin{aligned} |Q_L|\le \sum _{k=1}^{|Q|} \left( {\begin{array}{c}|Q|\\ k\end{array}}\right) k! (k+1)^{|Q|-k}=|Q|! \sum _{k=1}^{|Q|}\frac{ (k+1)^{|Q|-k|}}{(|Q|-k)!}. \end{aligned}$$

    Looking at the term for \(k=|Q|\), one sees that the upper bound for \(Q_L\) is at least Q!. On the other hand, since \(k\le |Q|\), substituting \(k+1\) with \(|Q|+1\) we easily get that: \(|Q_L|\le |Q|! \sum _{k=1}^{|Q|}\frac{(|Q|+1)^{|Q|-k}}{(|Q|-k)!}\le |Q|!\exp (|Q|+1)\).

Remark 3

Since the transducer \({{\mathcal {T}}}'\) is unambiguous any two states \(L\in Q_L\) and \(R\in Q_R\) have at most one common element. This shows that for each \(L\in Q_L\), there is a unique L-centered function \(\phi _L\) and therefore our construction would find exactly this function if run on \({{\mathcal {T}}}'\). Thus in this case the output function \(\psi :Q_L\times \varSigma \times Q_R\rightarrow \varOmega ^*\) will be defined in exactly the same way.

Fig. 1.
figure 1

A class of ambiguous finite-state transducers representing the rational functions \({\{{\langle {a,a}\rangle },{\langle {b,b}\rangle }\}}^* \{{\langle {a,a}\rangle }, {\langle {b,\varepsilon }\rangle }\} \{{\langle {a,a}\rangle },{\langle {b,b}\rangle }\}^{n-1}\), which deletes the n-th character from right-to-left if it is a b. The table shows the number of states of the source transducer, the pseudo-deterministic transducer, the left and the right automaton of the bimachine built by the standard and the new constructions.

Remark 4

The classical construction is starting from a pseudo-deterministic transducer. However, if \({{\mathcal {T}}}\) is an arbitrary real-time transducer the initial conversion to a pseudo-deterministic transducer may cause an exponential blow-up. In contrast, our constructions can be applied directly to arbitrary real-time transducers and thus avoids this blow-up. See Fig. 1 for an example.

5 Conclusion

In this paper we introduced a new generic algorithm and a specialization for building bimachines from functional finite-state transducers. The generic procedure is conceptually simple. Both constructions avoid the preparatory steps used in the classical construction, namely pseudodeterminization and disambiguation.

For the specialized construction we derived an upper bound on the size of the bimachine. We showed that this construction is asymptotically not worse than the classical construction. Moreover we presented a class of transducers for which the classical construction generates a bimachine with exponentially more states than the new construction.

The generic construction described in Subsect. 3.1 is not based on any order of the successful paths. It provides a simple and general algorithmic scheme for bimachine constructions, leaving room for other specialization, with new path selection strategies that might lead to even smaller bimachines. The study of optimal path selection strategies is a point for future research.