POV-Ray : Newsgroups : povray.off-topic : An even more interesting problem Server Time
28 Jul 2024 16:32:42 EDT (-0400)
  An even more interesting problem (Message 1 to 8 of 8)  
From: Orchid Win7 v1
Subject: An even more interesting problem
Date: 24 May 2013 14:20:10
Message: <519faf5a$1@news.povray.org>
Suppose I give you two arbitrary regular expressions. Are they equivalent?

Does there exist an algorithm to determine whether two regexes are 
equivalent? What complexity class does this algorithm live in? What does 
"equivalent" even mean in this context? What about if one expression 
matches a subset of the other? Or a superset? Or in general two 
partially-overlapping sets?


Post a reply to this message

From: Kevin Wampler
Subject: Re: An even more interesting problem
Date: 24 May 2013 14:44:06
Message: <519fb4f6@news.povray.org>
On 5/24/2013 11:20 AM, Orchid Win7 v1 wrote:
> Suppose I give you two arbitrary regular expressions. Are they equivalent?

It depends on what you specifically mean by "regular expression", but 
probably this problem is PSPACE-complete.  From what I can tell is 
generally solved by converting each regexp into a DFA and checking if 
they are isomorphic.

> Does there exist an algorithm to determine whether two regexes are
> equivalent? What complexity class does this algorithm live in? What does
> "equivalent" even mean in this context? What about if one expression
> matches a subset of the other? Or a superset? Or in general two
> partially-overlapping sets?

There exists a Perl library to do some related computations of this 
sort, although it will sometimes fail to detect an equivalence (but I 
think never detects a false equivalence).

http://search.cpan.org/~vbar/Regexp-Compare-0.17/lib/Regexp/Compare.pm


Post a reply to this message

From: Warp
Subject: Re: An even more interesting problem
Date: 24 May 2013 15:22:21
Message: <519fbded@news.povray.org>
Kevin Wampler <nob### [at] nowherenet> wrote:
> On 5/24/2013 11:20 AM, Orchid Win7 v1 wrote:
> > Suppose I give you two arbitrary regular expressions. Are they equivalent?

> It depends on what you specifically mean by "regular expression", but 
> probably this problem is PSPACE-complete.  From what I can tell is 
> generally solved by converting each regexp into a DFA and checking if 
> they are isomorphic.

No. Two regular expressions expressing the same "language" (ie. matching
the exact same things) is not a question of isomorphism. Isomorphism is
a much stricter comparison.

For example "a|aa+" and "a+" are equivalent (both match the exact same
things), but not isomorphic (the former has more nodes than the latter.)

The more accurate comparison is the one that says that "every named path
in one graph exists in the other, and vice-versa." I think the term for
this is strong bilinearity. The comparison can be made faster than in
exponential time.

-- 
                                                          - Warp


Post a reply to this message

From: Kevin Wampler
Subject: Re: An even more interesting problem
Date: 24 May 2013 16:02:15
Message: <519fc747$1@news.povray.org>
On 5/24/2013 12:22 PM, Warp wrote:
> Kevin Wampler <nob### [at] nowherenet> wrote:
>> On 5/24/2013 11:20 AM, Orchid Win7 v1 wrote:
>>> Suppose I give you two arbitrary regular expressions. Are they equivalent?
>
>> It depends on what you specifically mean by "regular expression", but
>> probably this problem is PSPACE-complete.  From what I can tell is
>> generally solved by converting each regexp into a DFA and checking if
>> they are isomorphic.
>
> No. Two regular expressions expressing the same "language" (ie. matching
> the exact same things) is not a question of isomorphism. Isomorphism is
> a much stricter comparison.

I should have been more explicit: solved by converting each regex into a 
*minimal* DFA  and checking if they are isomorphic.

Graph isomorphism is of course GI-complete, but the conversion to a 
minimal DFA is in general PSPACE-complete.


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: An even more interesting problem
Date: 25 May 2013 04:30:31
Message: <51a076a7$1@news.povray.org>
On 24/05/2013 07:44 PM, Kevin Wampler wrote:
> On 5/24/2013 11:20 AM, Orchid Win7 v1 wrote:
>> Suppose I give you two arbitrary regular expressions. Are they
>> equivalent?
>
> It depends on what you specifically mean by "regular expression", but
> probably this problem is PSPACE-complete. From what I can tell is
> generally solved by converting each regexp into a DFA and checking if
> they are isomorphic.

Does the situation change if we disallow the Kleene star?


Post a reply to this message

From: Tim Cook
Subject: Re: An even more interesting problem
Date: 25 May 2013 04:55:01
Message: <51a07c65@news.povray.org>
On 2013-05-24 13:20, Orchid Win7 v1 wrote:
> Suppose I give you two arbitrary regular expressions. Are they equivalent?
>
> Does there exist an algorithm to determine whether two regexes are
> equivalent?

Piece of cake:

if( string RegExp1 == string RegExp2 ){
	printf( "They're equivalent!\n" );
}else{
	printf( "They're not identically equivalent!\n" );
}

*wink*


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: An even more interesting problem
Date: 25 May 2013 07:00:33
Message: <51a099d1$1@news.povray.org>
>> Does there exist an algorithm to determine whether two regexes are
>> equivalent?
>
> Piece of cake:
>
> if( string RegExp1 == string RegExp2 ){
> printf( "They're equivalent!\n" );
> }else{
> printf( "They're not identically equivalent!\n" );
> }
>
> *wink*

Oh come on. You could at least parse the string into an AST and compare 
the two ASTs. :-P That would at least remove trivial differences like 
extra spaces and so on.


Post a reply to this message

From: Kevin Wampler
Subject: Re: An even more interesting problem
Date: 25 May 2013 11:05:05
Message: <51a0d321$1@news.povray.org>
On 5/25/2013 1:30 AM, Orchid Win7 v1 wrote:
>
> Does the situation change if we disallow the Kleene star?

Yes, although not usefully so.  Without the Kleene star it's co-NP complete.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.