diff -r 739039774cee -r 94b84d880c2b progs/matcher/re3.sc --- a/progs/matcher/re3.sc Mon Jan 24 00:14:02 2022 +0000 +++ b/progs/matcher/re3.sc Tue Mar 22 00:36:18 2022 +0000 @@ -187,3 +187,43 @@ // runs with amm2 and amm3 + +def pp(r: Rexp): String = r match { + case SEQ(CHAR(a1), SEQ(r1, r2)) => s"${a1}${pp(r1)}${pp(r2)}" + case SEQ(ONE, SEQ(r1, r2)) => s"1${pp(r1)}${pp(r2)}" + case SEQ(ZERO, SEQ(r1, r2)) => s"0${pp(r1)}${pp(r2)}" + case SEQ(CHAR(a1), CHAR(a2)) => s"${a1}${a2}" + case SEQ(ONE, CHAR(a2)) => s"1${a2}" + case SEQ(ZERO, CHAR(a2)) => s"0${a2}" + case ZERO => "0" + case ONE => "1" + case CHAR(a) => a.toString + case ALT(r1, r2) => s"(${pp(r1)} + ${pp(r2)})" + case SEQ(r1, r2) => s"(${pp(r1)} o ${pp(r2)})" + case STAR(r1) => s"(${pp(r1)})*" +} + + +val REG = STAR(ALT(CHAR('a'), SEQ(CHAR('a'), CHAR('a')))) + +print(pp(ders("".toList, REG))) +print(pp(ders("a".toList, REG))) +print(pp(ders("aa".toList, REG))) +print(pp(ders("aaa".toList, REG))) + +size(ders("".toList, REG)) // 6 +size(ders("a".toList, REG)) // 12 +size(ders("aa".toList, REG)) // 27 +size(ders("aaa".toList, REG)) // 55 +size(ders("aaaa".toList, REG)) // 8 +size(ders("aaaaa".toList, REG)) // 169 +size(ders("aaaaaa".toList, REG)) // 283 +size(ders(("a" * 7).toList, REG)) // 468 +size(ders(("a" * 8).toList, REG)) // 767 +size(ders(("a" * 9).toList, REG)) // 1251 +size(ders(("a" * 10).toList, REG))// 2034 +size(ders(("a" * 11).toList, REG))// 3301 + +for (i <- (0 to 40)) { + println(s"$i:" + size(ders(("a" * i).toList, REG))) +} \ No newline at end of file