Live data from Hacker News

Calculate the difference and intersection of any two regexes

phylactery.org

91–100 of 127 posts

Re: Calculate the difference and intersection of any two regexes

#91

I created a similar regex web demo that shows how a regex is parsed -> NFA -> DFA -> minimal DFA, and finally outputs LLVMIR/Javascript/WebAssembly for from the minimal DFA: http://compiler.org/reason-re-nfa/src/index.html

Though going from NFA to explicit DFA isn't always a good idea.

Btw, you might also like looking into the Brzozowski derivative https://en.wikipedia.org/wiki/Brzozowski_derivative which can be used as an alternative way to match regular expressions.

Re: Calculate the difference and intersection of any two regexes

#92
post #90

Earlier quoted context omitted.

People are downvoting you because quirky/jokey super-colloquial language like “wossis mean? TIA” is hard to understand, and also just doesn’t really mesh with the vibe of the site.

What does TIA even mean?

Thanks In Advance.

Re: Calculate the difference and intersection of any two regexes

#94
I used 2 similar divide-by-3 regexes to test the page (after removing the ^ and $ to their ends), and it froze up:

Regex 1: ([0369]|([258]|[147][0369]*[147])([0369]|([147][0369]*[258]|[258][0369]*[147]))*([147]|[258][0369]*[258])|([147]|[258][0369]*[258])([0369]|([147][0369]*[258]|[258][0369]*[147]))*([258]|[147][0369]*[147]))*

Regex 2: ([0369]|[258][0369]*[147]|(([147]|[258][0369]*[258])([0369]|[147][0369]*[258])*([258]|[147][0369]*[147])))*

Everything up until the last '*' is parsable. The moment I put in the *, the entire page freezes up.

Without the *, it produced a valid verifier for parsing chunks of digits whose sum mod 3 = 0.

Re: Calculate the difference and intersection of any two regexes

#95
post #35

Earlier quoted context omitted.

It always amazes me how given the appropriate field, so much math can be transformed into linear algebra. Even Möbius transformations on the complex plane w=(az+b)/(cz+d) can be turned into linear algebra.

Linear transformations preserve the structure of the space so you can keep applying them. It's not surprising that you can always find some "space-preserving" part of a problem and fold the rest (the "non-linear" structure) into transformations or the definition of the space itself.

Linear transformations preserve some structure, not 'the' structure.

Re: Calculate the difference and intersection of any two regexes

#96
This is neat!

I was surprised then not surprised that the union & intersection REs it comes up with are not particularly concise. For example the two expressions "y.+" and ".+z" have a very simple intersection: "y.*z" (equality verified by the page, assuming I haven't typo'd anything). But the tool gives

    yz([^z][^z]*z|z)*|y[^z](zz*[^z]|[^z])*zz*
instead. I think there are reasons it gives the answer it does, and giving a minimal (by RE length in characters or whatever) regular expression is probably a lot harder.

Re: Calculate the difference and intersection of any two regexes

#97
post #91

I created a similar regex web demo that shows how a regex is parsed -> NFA -> DFA -> minimal DFA, and finally outputs LLVMIR/Javascript/WebAssembly for from the minimal DFA: http://compiler.org/reason-re-nfa/src/index.html

Though going from NFA to explicit DFA isn't always a good idea. Btw, you might also like looking into the Brzozowski derivative https://en.wikipedia.org/wiki/Brzozowski_derivative which can be used as an alternative way to match regular expressions.

I think it is also worth mentioning that the site linked at the top uses the antimirov extension to brzozovzki work on regex deivatives.

Re: Calculate the difference and intersection of any two regexes

#98
post #44

Earlier quoted context omitted.

It's very cool, but also no wonder that it doesn't support all those features of regexes which technically make them not regular expressions anymore. Though, I would have thought ^ and $ anchors shouldn't be a problem?

As ^ and $ are implicit, you can opt out of them simply by affixing `.*`.

Only when the ^ or $ were at the start/end of your string is it simple. Eg:

    (a|b|^)(c|d|^)foo
Rewriting without ^ can require much longer regex.

Re: Calculate the difference and intersection of any two regexes

#99
post #96

This is neat! I was surprised then not surprised that the union & intersection REs it comes up with are not particularly concise. For example the two expressions "y.+" and ".+z" have a very simple intersection: "y.*z" (equality verified by the page, assuming I haven't typo'd anything). But the tool gives yz([^z][^z]*z|z)*|y[^z](zz*[^z]|[^z])*zz* instead. I think there are reasons it gives the answer it does, and givi…

I think one of the reasons is the ".+z" gets bigger and uglier after you convert it to a deterministic automaton.

Re: Calculate the difference and intersection of any two regexes

#100
post #66
post #54

Earlier quoted context omitted.

I wouldn't use an LLM for anything that can be done 100% precisely, like this.

OK, just curious how LLMs are stacking up in logical tasks like this. I kept hearing we were close to AGI so just wondering how far there is to go.

We've been "close" to AGI for like 40+ years.
Post reply on HN