diff -r 6e2cef17a9b3 -r 6756b026c5fe exps/both.scala --- a/exps/both.scala Thu Feb 07 10:52:41 2019 +0000 +++ b/exps/both.scala Fri Feb 08 12:47:35 2019 +0000 @@ -114,7 +114,7 @@ } -//-------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------- // START OF NON-BITCODE PART // @@ -264,12 +264,43 @@ def lexing_simp(r: Rexp, s: String) : Val = lex_simp(r, s.toList) -println(lexing_simp(("a" | "ab") ~ ("b" | ""), "ab")) +//println(lexing_simp(("a" | "ab") ~ ("b" | ""), "ab")) + + +def tokenise_simp(r: Rexp, s: String) = + env(lexing_simp(r, s)).map(esc2) + +//-------------------------------------------------------------------- +// Partial Derivatives -def tokenise_simp(r: Rexp, s: String) = env(lexing_simp(r, s)).map(esc2) +def pder(c: Char, r: Rexp): Set[Rexp] = r match { + case ZERO => Set() + case ONE => Set() + case PRED(f, _) => if (f(c)) Set(ONE) else Set() + case ALTS(rs) => rs.toSet.flatMap(pder(c, _)) + case SEQ(r1, r2) => + (for (pr1 <- pder(c, r1)) yield SEQ(pr1, r2)) ++ + (if (nullable(r1)) pder(c, r2) else Set()) + case STAR(r1) => + for (pr1 <- pder(c, r1)) yield SEQ(pr1, STAR(r1)) + case RECD(_, r1) => pder(c, r1) +} -//-------------------------------------------------------------------------------------------------------- +def pders(cs: List[Char], r: Rexp): Set[Rexp] = cs match { + case Nil => Set(r) + case c::cs => pder(c, r).flatMap(pders(cs, _)) +} + +def pders_simp(cs: List[Char], r: Rexp): Set[Rexp] = cs match { + case Nil => Set(r) + case c::cs => pder(c, r).flatMap(pders_simp(cs, _)).map(simp(_)._1) +} + +def psize(rs: Set[Rexp]) = + rs.map(size).sum + +//-------------------------------------------------------------------- // BITCODED PART @@ -595,7 +626,7 @@ println("Size Bit " + asize(bders_simp((fib_prog * 1).toList, internalise(WHILE_REGS)))) println("Size Bitf " + asize(bders_simp_full((fib_prog * 1).toList, internalise(WHILE_REGS)))) println("Size Old " + size(ders_simp((fib_prog * 1).toList, WHILE_REGS))) - +println("Size Pder " + psize(pders_simp((fib_prog * 1).toList, WHILE_REGS))) System.exit(0)