17

Given languages $A$ and $B$, let's say that their concatenation $AB$ is unambiguous if for all words $w \in AB$, there is exactly one decomposition $w = ab$ with $a \in A$ and $b \in B$, and ambiguous otherwise. (I don't know if there's an established term for this property—hard thing to search for!) As a trivial example, the concatenation of $\{\varepsilon, \mathrm{a}\}$ with itself is ambiguous ($w = \mathrm{a} = \varepsilon \mathrm{a} = \mathrm{a} \varepsilon$), but the concatenation of $\{\mathrm{a}\}$ with itself is unambiguous.

Is there an algorithm for deciding whether the concatenation of two regular languages is unambiguous?

Raphael
  • 73,212
  • 30
  • 182
  • 400
rstern
  • 171
  • 5

2 Answers2

10

Hint: Given DFAs for $A$ and $B$, construct an NFA which accepts words in $AB$ having at least two different decompositions. The NFA keeps track of two copies of the standard NFA for $AB$ (formed by joining DFAs for $A$ and $B$ with $\epsilon$ transitions), ensuring that the switch from $A$ to $B$ happens at two different points.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
9

Updated (thanks to Yuval Filmus).

Given two languages $X$ and $Y$ of $A^*$, let \begin{align} X^{-1}Y &= \{u \in A^* \mid \text{there exists $x \in X$ such that $xu \in Y$} \} \\ YX^{-1} &= \{u \in A^* \mid \text{there exists $x \in X$ such that $ux \in Y$} \} \end{align} I claim that $XY$ is unambiguous if and only if the language $X^{-1}X \cap YY^{-1} \cap A^+$ is empty.

Proof. Suppose that $XY$ is ambiguous. Then there exists a word $u$ which has two decompositions over $XY$, say $u = x_1y_2 = x_2y_1$, where $x_1, x_2 \in X$ and $y_1, y_2 \in Y$. Without loss of generality, we may assume that $x_1$ is a prefix of $x_2$, that is, $x_2 = x_1z$ for some $z \in A^+$. It follows that $u = x_1y_2 = x_1zy_1$, whence $y_2 = zy_1$. Thus $z \in X^{-1}X \cap YY^{-1}$.

Suppose now that $X^{-1}X \cap YY^{-1}$ contains some nonempty word $z$. Then there exist $x_1, x_2 \in X$ and $y_1, y_2 \in Y$ such that $x_2 = x_1z$ and $y_2 = zy_1$. It follows that $x_2y_1 = x_1zy_1 = x_1y_2$ and hence the product $XY$ is ambiguous.

If $X$ and $Y$ are regular, then both $X^{-1}X$ and $YY^{-1}$ are regular and thus $X^{-1}X \cap YY^{-1}$ is also regular (see Yuval's answer for an automaton accepting this language).

J.-E. Pin
  • 6,219
  • 21
  • 39