progs/re2.scala
changeset 564 b5d57d7064bb
parent 513 676e6484f29b
child 566 b153c04834eb
--- a/progs/re2.scala	Fri Sep 28 13:54:18 2018 +0100
+++ b/progs/re2.scala	Sun Sep 30 12:01:14 2018 +0100
@@ -45,6 +45,7 @@
 
 
 //optional regular expression: one or zero times
+//this regular expression is still defined in terms of ALT
 def OPT(r: Rexp) = ALT(r, ONE)
 
 
@@ -73,11 +74,11 @@
 
 
 //test: (a*)* b
-for (i <- 1 to 20) {
+for (i <- 1 to 21) {
   println(i + " " + "%.5f".format(time_needed(2, matches(EVIL2, "a" * i))))
 }
 
-for (i <- 1 to 20) {
+for (i <- 1 to 21) {
   println(i + " " + "%.5f".format(time_needed(2, matches(EVIL2, "a" * i))))
 }
 
@@ -95,19 +96,29 @@
 }
 
 // EVIL1(n) has now a constant size, no matter
-// what n is 
+// what n is; also the derivative only grows 
+// moderately 
 
 size(EVIL1(1))  // 7
 size(EVIL1(3))  // 7
 size(EVIL1(5))  // 7
 size(EVIL1(7))  // 7
 
+size(ders("".toList, EVIL1(5)))       // 7
+size(ders("a".toList, EVIL1(5)))      // 16
+size(ders("aa".toList, EVIL1(5)))     // 35
+size(ders("aaa".toList, EVIL1(5)))    // 59
+size(ders("aaaa".toList, EVIL1(5)))   // 88
+size(ders("aaaaa".toList, EVIL1(5)))  // 122
+size(ders("aaaaaa".toList, EVIL1(5))) // 151
 
 // but the size of the derivatives can still grow 
-// quite dramatically
+// quite dramatically in case of EVIL2
 
-size(ders("".toList, EVIL2))     // 5
-size(ders("a".toList, EVIL2))    // 12
-size(ders("aa".toList, EVIL2))   // 28
-size(ders("aaa".toList, EVIL2))  // 58
-size(ders("aaaa".toList, EVIL2)) // 116
+size(ders("".toList, EVIL2))       // 5
+size(ders("a".toList, EVIL2))      // 12
+size(ders("aa".toList, EVIL2))     // 28
+size(ders("aaa".toList, EVIL2))    // 58
+size(ders("aaaa".toList, EVIL2))   // 116
+size(ders("aaaaa".toList, EVIL2))  // 230
+size(ders("aaaaaa".toList, EVIL2)) // 456