IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Brzozowski's algorithm...
Okay, I tried out a really cool algorithm the other day, and I wanted to share. It's Brzozowski's algorithm for turning an NFA into a minimal DFA.


def brzozowski(nfa):
return reachable(subset(reverse(reachable(subset(reverse(nfa))))))


The auxilliary procedures are:


  • reachable: Return only the states and transitions reachable from the start states.

  • subset: The subset construction to turn an NFA into a DFA.

  • reverse: Reverse all of the transitions and swap the start and final state sets. (Eg, if the NFA has a transition (1, 'a') -> 4, it would become (4, 'a') -> 1.)



We can write a 1-liner for calculating the optimal DFA. Isn't it pretty?

P.S.: I know I'm hopeless. Deal. :)
New On a related note...
I am in the process of writing a "proof of concept" NFA engine and then applying a home-brewed optimization to it. Here are my claims:

  1. Said optimization can be incrementally applied, as much or little as you want. (There is an exponential possible blow-up in the size of the RE in optimizing it.)
  2. The optimization leaves the RE an NFA. That is it means that you will continue to find the same matches, and it is compatible with all features you can shove into an NFA. (It does not optimize all features, it just is willing to recognize that there are bits it can't optimize, and treat them properly.)
  3. Any RE which could be computed by an NFA can be optimized perfectly - the time to test a string will be linear in the length of the string.
  4. This is true even though you are capturing backreferences.
  5. The bulk of this optimization could be applied lazily at run-time, but my proof of concept won't show that. Said lazy approach is also unavoidably slow.

Expect more from me later. (Like in a month or two.)

Cheers,
Ben
     Brzozowski's algorithm... - (neelk) - (1)
         On a related note... - (ben_tilly)

Powered by orbiting brain lasers!
67 ms