Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 45903
Kernel: Python 3

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 B,Z\mathbb{B}, \mathbb{Z}, or a field (F2,Q,Qmp,R\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

import vcsn
b = vcsn.context('lal_char, b') r1 = b.expression('a') r2 = b.expression('b') r1.is_equivalent(r2)
False
r1 = b.expression('a') r2 = b.expression('a+a') r1.is_equivalent(r2)
True
z = vcsn.context('lal_char, z') r1 = z.expression('<42>a') r2 = z.expression('<51>a') r1.is_equivalent(r2)
False
r1 = z.expression('<42>a+<9>a') r2 = z.expression('<51>a') r1.is_equivalent(r2)
True

Heterogeneous Comparisons

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

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