--- a/progs/nfa.scala Sun May 07 03:01:29 2017 +0100
+++ b/progs/nfa.scala Tue May 09 12:31:55 2017 +0100
@@ -85,4 +85,15 @@
// subset constructions
-//def subset(nfa: NFA[A, C]) : DFA[Set[A], C] =
+def subset[A, C](nfa: NFA[A, C]) : DFA[Set[A], C] = {
+ DFA(nfa.starts,
+ { case (qs, c) => nfa.nexts(qs, c) },
+ _.exists(nfa.fins))
+}
+
+subset(nfa1).accepts("aa".toList) // false
+subset(nfa1).accepts("aaaaa".toList) // false
+subset(nfa1).accepts("aaaaab".toList) // true
+subset(nfa1).accepts("aaaaabbb".toList) // true
+subset(nfa1).accepts("aaaaabbbaaa".toList) // false
+subset(nfa1).accepts("ac".toList) // false