Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expressions Equivalence

Is there a way to find out if two arbitrary regular expressions are equivalent? Looks like complex problem to me, but there might be some DFA simplification mechanism or something?

like image 741
amit Avatar asked Feb 18 '09 08:02

amit


People also ask

Do all regular expressions have an equivalent DFA?

Theorem: For every regular expression, there's an equivalent DFA. Proof: Regular expressions are built up with *, |, concatenation.

What is ε in regular expression?

ε is a Regular Expression indicates the language containing an empty string. ( L (ε) = {ε}) φ is a Regular Expression denoting an empty language. (

Which regex is not equal to the others?

Which one of the following regular expressions is NOT equivalent to the regular expression (a + b + c) *? Explanation: C– (ab)* + c*)* will always give strings with “ab” together. Whereas (a+b+c)* would generate language where a,b,c may not be always together.

Why regular expressions and finite automata are equivalent?

Regular expressions and finite automata have equivalent expressive power: For every regular expression R, there is a corresponding FA that accepts the set of strings generated by R. For every FA A there is a corresponding regular expression that generates the set of strings accepted by A.


2 Answers

To test equivalence you can compute the minimal DFAs for the expressions and compare them.

like image 162
starblue Avatar answered Oct 18 '22 18:10

starblue


Testability of equality is one of the classical properties of regular expressions. (N.B. This doesn't hold if you're really talking about Perl regular expressions or some other technically nonregular superlanguage.)

Turn your REs to generalised finite automata A and B, then construct a new automaton A-B such that the accepting states of A have null transitions to the start states of B, and that the accepting states of B are inverted. This gives you an automaton that accepts all those strings accepted by A, except for all those accepted by B.

Do the same for B-A, and reduce both to pure FAs. If an FA has no accepting states accessible from a start state then it accepts the empty language. If you can show that both A-B and B-A are empty, you've shown that A = B.

Edit Heh, I can't believe no one noticed the gigantic error there -- an intentional one, of course :-p

The automata A-B as described will accept those strings whose first half is accepted by A and whose second half is not accepted by B. Building the desired A-B is a slightly trickier process. I can't think of it off the top of my head, but I do know it's well-defined (and likely involves creating states to the represent the products of accepting states in A and non-accepting states in B).

like image 24
Edmund Avatar answered Oct 18 '22 17:10

Edmund