diff -r 4fee50f38305 -r d5776c6018f0 progs/thompson.scala --- a/progs/thompson.scala Tue May 09 12:31:55 2017 +0100 +++ b/progs/thompson.scala Wed May 10 17:03:21 2017 +0100 @@ -1,5 +1,6 @@ // Thompson Construction -// (needs :load nfa.scala +// (needs :load dfa.scala +// :load nfa.scala // :load enfa.scala) @@ -119,6 +120,9 @@ def tmatches2(r: Rexp, s: String) : Boolean = thompson(r).accepts2(s.toList) +// dfa via subset construction +def tmatches_dfa(r: Rexp, s: String) : Boolean = + subset(thompson(r)).accepts(s.toList) // Test Cases @@ -155,3 +159,19 @@ for (i <- 1 to 8) { println(i + " " + "%.5f".format(time_needed(2, tmatches2(EVIL2, "a" * i)))) } + + + +// while my thompson-enfa-subset-partial-function-chain +// is probably not the most effcient way to obtain a fast DFA +// (the below should be much faster with a more direct construction), +// in general the DFAs can be slow because of the state explosion +// in the subset construction + +for (i <- 1 to 13) { + println(i + ": " + "%.5f".format(time_needed(2, tmatches_dfa(EVIL1(i), "a" * i)))) +} + +for (i <- 1 to 100 by 5) { + println(i + " " + "%.5f".format(time_needed(2, tmatches_dfa(EVIL2, "a" * i)))) +}