Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Why machine-generated solutions will never cease to amaze me

by hv (Parson)
on Nov 11, 2004 at 13:34 UTC ( #407031=note: print w/replies, xml ) Need Help??


in reply to Re: Why machine-generated solutions will never cease to amaze me
in thread Why machine-generated solutions will never cease to amaze me

The proof for the (x?|y) case follows immediately from regex union being commutative.

Regexp union is not commutative when one of the alternates is a leading substring of another: then order becomes important - (E|x) will always match E in preference to x.

It is the presence of the outer anchors in the original pattern that disambiguates and thus makes it commutative.

Hugo

Replies are listed 'Best First'.
Re^3: Why machine-generated solutions will never cease to amaze me
by tmoertel (Chaplain) on Nov 11, 2004 at 16:18 UTC
    hv wrote:
    Regexp union is not commutative when one of the alternates is a leading substring of another: then order becomes important - (E|x) will always match E in preference to x.
    Excellent point. (However, union is commutative even in the face of overlapping operands when the union is forced to match all of the target string or not match at all.)
    It is the presence of the outer anchors in the original pattern that disambiguates and thus makes (regexp union) commutative.
    Even anchoring isn't sufficient. What if one of the anchors matches the difference between the union operands? Consider (a|aa) in:
    "aaaa" =~ /a(a|aa)a/

    Fortunately, in the case of the OP's regexes – s(?:al|pre)?ad and s(?:(?:al)?|pre)ad) – the union operands don't overlap, and so classical equivalence (do the regexps generate the same language?) predicts the equivalence of Perl's matching behavior (do the regexps match the same strings identically?)

    Cheers,
    Tom

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://407031]
help
Chatterbox?
[LanX]: Pacific Crest Trail is really hard stuff
[Eily]: erix he plans to go as far as leuca
[erix]: ah, that's really down at the heel point :)
[Eily]: LanX how dare you imply that I made a typo? It's true but still!
[Eily]: or is it a typo if the mistake was in my brain rather than in the process of typing?
[LanX]: they were talking about meatspace recently ...
[choroba]: a "thinko"
[erix]: my app (google, really) makes that 1530 km...
[Eily]: google tells me 1662 km ...
[LanX]: Nancy? Somewhere near Metz ...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-12-13 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (369 votes). Check out past polls.

    Notices?