progs/nfa.scala
changeset 490 4fee50f38305
parent 489 e28d7a327870
child 491 d5776c6018f0
--- 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