expression.is_equivalent(exp)

Whether this expression is equivalent to exp, i.e., whether they accept the same words with the same weights.

Preconditions:

  • Both labelsets are free, or nullable of free
  • Both weightsets are either $\mathbb{B}, \mathbb{Z}$, or a field ($\mathbb{F}_2, \mathbb{Q}, \mathbb{Q}_\text{mp}, \mathbb{R}$).

Algorithm:

  • Compute the derived-term automaton of both expressions, and check whether the automata are equivalent.

See also:

Examples

In [1]:
import vcsn
In [2]:
b = vcsn.context('lal_char, b')
r1 = b.expression('a')
r2 = b.expression('b')
r1.is_equivalent(r2)
Out[2]:
False
In [3]:
r1 = b.expression('a')
r2 = b.expression('a+a')
r1.is_equivalent(r2)
Out[3]:
True
In [4]:
z = vcsn.context('lal_char, z')
r1 = z.expression('<42>a')
r2 = z.expression('<51>a')
r1.is_equivalent(r2)
Out[4]:
False
In [5]:
r1 = z.expression('<42>a+<9>a')
r2 = z.expression('<51>a')
r1.is_equivalent(r2)
Out[5]:
True

Heterogeneous Comparisons

Note that rational expressions of different, but compatible, contexts, can be equivalent.

In [6]:
q = vcsn.context('lal_char, q')
z.expression('[abc]*').is_equivalent(q.expression('[abc]*'))
Out[6]:
True
In [7]:
z.expression('<42>[abc]*').is_equivalent(q.expression('<51>[abc]*'))
Out[7]:
False