News for hackers. Stuff that matters.
Re:Divisibility by 7 is a Walk on a Graph (2009) by newsignup on Sunday November 08, 2015 @11:15PM (#10531346)
> a 12,701 character regex for divisibility by 7:

I wonder if that's the optimal regex or can be reduced further using some rules[1] like the ones which we(humans) generally use to do it manually.

[1]. https://www.math.hmc.edu/funfacts/ffiles/10005.5.shtml

Re:Divisibility by 7 is a Walk on a Graph (2009) by anderskaseorg on Monday November 09, 2015 @05:55AM (#10532308)
I wrote a 11811-character regex for divisibility by 7 back in August 2008: http://web.mit.edu/andersk/Public/regex
Re:Divisibility by 7 is a Walk on a Graph (2009) by fizbin on Monday November 09, 2015 @03:09PM (#10535458)
And unlike the one on stackexchange, it's actually correct!

(I have a regex -> DFA compiler here that I just threw your regex through. Seven states, connected as expected)

Re:Divisibility by 7 is a Walk on a Graph (2009) by eru on Monday November 09, 2015 @01:14PM (#10534688)
Do you have the source to the program you wrote the regex with? (Or did you write it by hand?)
Re:Divisibility by 7 is a Walk on a Graph (2009) by eru on Monday November 09, 2015 @05:49AM (#10532286)
It's definitely not the optimal regex. Finding the smallest regex is a hard problem (at least in theory): https://cs.stackexchange.com/questions/19686/is-regex-golf-n...

(I think I've read that finding the smallest one is not only NP-hard, but P-Space complete.)

Re:Divisibility by 7 is a Walk on a Graph (2009) by ant6n on Sunday November 08, 2015 @11:23PM (#10531379)
Don't regular expressions have minimal, canonical forms?
[deleted]
Re:Divisibility by 7 is a Walk on a Graph (2009) by areyousure on Monday November 09, 2015 @12:25AM (#10531519)
The minimum DFA does not correspond in any particular sense to a minimal regular expression.
Re:Divisibility by 7 is a Walk on a Graph (2009) by dllthomas on Monday November 09, 2015 @12:36AM (#10531546)
Of course not - my bad!
Re:Divisibility by 7 is a Walk on a Graph (2009) by Ar-Curunir on Sunday November 08, 2015 @11:32PM (#10531407)
Yes they do. For reference, check Sipser.
Re:Divisibility by 7 is a Walk on a Graph (2009) by sirsar on Sunday November 08, 2015 @11:48PM (#10531448)
Could you give a page number? I skimmed the regular expression section and couldn't find it. Also, while it is self-evident to me that there is a minimal form for each regex, the construction for finding one isn't immediately obvious to me (I can surely enumerate several ways of eliminating redundancy). Beyond that, I'm not sure a minimal form would minimize character length.

Of (a \star b \star ) \star and ( a ∪ b ) \star, which is the canonical form? The transformation from the former to the latter is nontrivial as a \star b \star is not equivalent with a ∪ b.

Re:Divisibility by 7 is a Walk on a Graph (2009) by areyousure on Monday November 09, 2015 @12:24AM (#10531514)
Of course, there is a shortest equivalent regular expression, but in general it's PSPACE-complete to find it: https://en.wikipedia.org/wiki/PSPACE-complete#Regular_expres...

It remains PSPACE-complete if you're given a corresponding DFA: "Jiang and Ravikumar [7] show moreover that the minimization problem for ... regular expressions remains PSPACE-complete, even when specifying the regular language by a dfa" from http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.60....

In that sense, the grandparent is incorrect. It is unknown, in both practice and theory, how to find the shortest equivalent regex.

Re:Divisibility by 7 is a Walk on a Graph (2009) by adrianN on Monday November 09, 2015 @02:43AM (#10531795)
It's not unknown, it just takes a long time.
Re:Divisibility by 7 is a Walk on a Graph (2009) by acchow on Monday November 09, 2015 @04:04AM (#10532005)
I think you should think deeper on the idea of "unknown"
Re:Divisibility by 7 is a Walk on a Graph (2009) by adrianN on Monday November 09, 2015 @05:07AM (#10532159)
I don't understand what you mean. Regex minimization is in PSPACE, so take any PSPACE complete problem, eg Q-Sat, do the reduction and apply the algorithm. Q-Sat can be solved by recursively enumerating all possibilities. So there is a method for minimizing regular expressions. It just takes a long time to run. If you have time you can probably think of an algorithm that works directly on the regex problem without doing the Q-Sat thing. It might even be faster.

Heck, there might be an algorithm that works really well in practice. People who do model checking and verification laugh PSPACE completeness in the face and are not even really concerned with undecidability.

Re:Divisibility by 7 is a Walk on a Graph (2009) by eru on Monday November 09, 2015 @01:16PM (#10534706)
I would be very interested in finding an approach that works well in practice.
Re:Divisibility by 7 is a Walk on a Graph (2009) by kragen on Monday November 09, 2015 @09:12AM (#10533061)
Okay, fine, but in this case N=7. What are the constant factors?