progs/cw1.scala
changeset 547 81eb43c41416
parent 493 4e97783862ff
child 550 71fc4a7a7039
--- a/progs/cw1.scala	Thu Feb 01 21:06:20 2018 +0000
+++ b/progs/cw1.scala	Mon Feb 05 10:58:48 2018 +0000
@@ -36,7 +36,7 @@
   case UPNTIMES(_, _) => true
   case FROMNTIMES(r, n) => if (n == 0) true else nullable(r)
   case NMTIMES(r, n, m) => if (n == 0) true else nullable(r)
-  case NOT(r) => !(nullable(r))
+  case NOT(r) => !nullable(r)
   case CFUN(_) => false
 }
 
@@ -58,7 +58,7 @@
   case UPNTIMES(r, n) =>
     if (n == 0) ZERO else SEQ(der(c, r), UPNTIMES(r, n - 1))
   case FROMNTIMES(r, n) =>
-    if (n == 0) ZERO else SEQ(der(c, r), FROMNTIMES(r, n - 1))
+    if (n == 0) SEQ(der(c, r), STAR(r)) else SEQ(der(c, r), FROMNTIMES(r, n - 1))
   case NMTIMES(r, n, m) =>
     if (m < n) ZERO else
     if (n == 0 && m == 0) ZERO else 
@@ -232,3 +232,23 @@
 TEST("/f&", COMMENT3)
 TEST("/f& ", COMMENT3)
 
+
+
+//test: ("a" | "aa") ~ ("a" | "aa")*
+for (i <- 1 to 100 by 1) {
+  println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL3, "a" * i))) + " size: " + size(ders(("a" * i).toList, EVIL3)))
+}
+
+val auxEVIL3 = ALT(CHAR('a'), SEQ(CHAR('a'), CHAR('a')))
+val EVIL3 = SEQ(auxEVIL3, STAR(auxEVIL3))
+val EVIL3p = FROMNTIMES(auxEVIL3, 1)
+
+val t1 = EVIL3
+val t2 = simp(der('a', t1))
+val t3 = simp(der('a', t2))
+val t4 = simp(der('a', t3))
+
+val t1 = EVIL3p
+val t2 = simp(der('a', t1))
+val t3 = simp(der('a', t2))
+val t4 = simp(der('a', t3))