diff -r ccec33db31d4 -r 4457185b22ef scala/ex.scala --- a/scala/ex.scala Wed Jun 26 14:42:42 2013 +0100 +++ b/scala/ex.scala Wed Jul 17 10:33:19 2013 +0100 @@ -2,8 +2,8 @@ import turing._ import abacus._ import recs._ -//import comp1._ -//import comp2._ +import comp1._ +import comp2._ // Turing machine examples @@ -123,18 +123,22 @@ println("Pdec2 7 -> 2: " + Pdec2.eval(7)) println("Enclen 0 .. 10: " + (0 until 10).map(Enclen.eval(_))) -/* +println("Size of UF -> 140843: " + UF.size) + + // compilation of rec to abacus tests def test_comp2(f: Rec, ns: Int*) = { - val (abc_f, arity, _) = compile_rec(f) + val (abc_f, _) = compile_rec(f) val abc_map = (0 until ns.length).zip(ns).toMap[Int, Int] - val start = System.nanoTime() - val res = (abc_f.run(abc_map))(arity) - val end = System.nanoTime() - val time = (end - start)/1.0e9 - ("Result: " + res + " length: " + abc_f.p.length + " time: " + "%.5f".format(time)) + //val start = System.nanoTime() + //val res = (abc_f.run(abc_map))(arity) + //val end = System.nanoTime() + //val time = (end - start)/1.0e9 + //("Result: " + res + " length: " + abc_f.p.length + " time: " + "%.5f".format(time)) + ("Length: " + abc_f.p.length) } + println("S(3) " + test_comp2(S, 3)) println("Const(1) " + test_comp2(Const(1), 0)) println("Const(10) " + test_comp2(Const(10), 0)) @@ -143,23 +147,25 @@ println("Power(3, 4) " + test_comp2(Power, 3, 4)) println("Minus(30, 4) " + test_comp2(Minus, 30, 4)) println("Fact(5) " + test_comp2(Fact, 5)) - +//println("UF(0) " + test_comp2(UF, 0)) def test_comp1(f: Rec, ns: Int*) = { - val (abc_f, arity, _) = compile_rec(f) - val tm = toTM(abc_f.p) :+ TMMopup(arity) - val start = System.nanoTime() - val res = tm.run(Tape(ns.toList)) - val end = System.nanoTime() - val time = (end - start)/1.0e9 - ("length: " + tm.p.length + " tape: " + arity + " time: " + "%.5f".format(time) + "\nResult: " + res) + val (abc_f, _) = compile_rec(f) + println("Abacus Length: " + abc_f.p.length) + val tm = toTM(abc_f.p) :+ TMMopup(f.arity) + //val start = System.nanoTime() + //val res = tm.run(Tape(ns.toList)) + //val end = System.nanoTime() + //val time = (end - start)/1.0e9 + //("length: " + tm.p.length + " tape: " + arity + " time: " + "%.5f".format(time) + "\nResult: " + res) + ("Length: " + abc_f.p.length + " " + tm.p.length) } -println("") -println("S(3) " + test_comp1(S, 3)) -println("Const(10) " + test_comp1(Const(10), 0)) -println("Add(6, 3) " + test_comp1(Add, 6, 3)) -println("Mult(4, 5) " + test_comp1(recs.Mult, 4, 5)) -println("Fact(4) " + test_comp1(Fact, 4)) +//println("") +//println("S(3) " + test_comp1(S, 3)) +//println("Const(10) " + test_comp1(Const(10), 0)) +//println("Add(6, 3) " + test_comp1(Add, 6, 3)) +//println("Mult(4, 5) " + test_comp1(recs.Mult, 4, 5)) +//println("Fact(4) " + test_comp1(Fact, 4)) +println("UF(0) " + test_comp1(UF, 0)) -*/