79 println("Fact 5: " + Fact.eval(5)) |
79 println("Fact 5: " + Fact.eval(5)) |
80 println("Prime 0..15: " + (0 to 15).map(n => (n, Prime.eval(n)))) |
80 println("Prime 0..15: " + (0 to 15).map(n => (n, Prime.eval(n)))) |
81 println("NextPrime 3: " + NextPrime.eval(3)) |
81 println("NextPrime 3: " + NextPrime.eval(3)) |
82 println("NthPrime 1: " + NthPrime.eval(1)) |
82 println("NthPrime 1: " + NthPrime.eval(1)) |
83 println("Listsum [2, 3, 4 , 5, 6]: " + Listsum(5, 4).eval(2, 3, 4, 5, 6)) |
83 println("Listsum [2, 3, 4 , 5, 6]: " + Listsum(5, 4).eval(2, 3, 4, 5, 6)) |
84 println("Strt: " + Strt(2).eval(2, 3)) |
84 println("Strt: " + Strt(2).eval(2,3)) |
|
85 |
|
86 |
|
87 // compilation of rec to abacus tests |
|
88 def test_comp2(f: Rec, ns: Int*) = { |
|
89 val (abc_f, arity, _) = compile_rec(f) |
|
90 val abc_map = (0 until ns.length).zip(ns).toMap[Int, Int] |
|
91 val res = (abc_f.run(abc_map))(arity) |
|
92 ("Result: " + res + " length: " + abc_f.p.length) |
|
93 } |
|
94 |
|
95 println("S(3) " + test_comp2(S, 3)) |
|
96 println("Const(1) " + test_comp2(Const(1), 0)) |
|
97 println("Const(10) " + test_comp2(Const(10), 0)) |
|
98 println("Add(69, 30) " + test_comp2(Add, 69, 30)) |
|
99 println("Mult(13, 9) " + test_comp2(recs.Mult, 13, 9)) |
|
100 println("Power(3, 4) " + test_comp2(Power, 3, 4)) |
|
101 println("Minus(30, 4) " + test_comp2(Minus, 30, 4)) |
|
102 println("Fact(5) " + test_comp2(Fact, 5)) |
|
103 println("Prime(5) " + test_comp2(Prime, 5)) |
|
104 println("Prime(6) " + test_comp2(Prime, 6)) |
|
105 println("Strt(1)(2) " + test_comp2(Strt(1), 2)) |
85 |
106 |
86 |
107 |
87 |
108 |
88 |
109 |
89 println(Const(1)) |
110 |
90 println(compile_rec(Const(1))) |
111 //println(toTM(compile_rec(Add)._1.p).run(Tape(3, 4, 0))) |
91 println(compile_rec(Const(1))._1.run(Map(0 -> 1, 1 -> 1, 2 -> 0))) |
112 //println(compile_rec(Add)._1.run(Map(0 -> 3, 1 -> 8, 2 -> 0))) |
92 println(toTM(compile_rec(Const(1))._1.p).run(Tape(1, 1, 0))) |
|
93 println(Add) |
|
94 println(compile_rec(Add)._1) |
|
95 println(toTM(compile_rec(Add)._1.p).run(Tape(3, 4, 0))) |
|
96 println(compile_rec(Add)._1.run(Map(0 -> 3, 1 -> 8, 2 -> 0))) |
|
97 //compile_rec(Add)._1.run(Map(0 -> 3, 1 -> 4, 2 -> 0)) |
113 //compile_rec(Add)._1.run(Map(0 -> 3, 1 -> 4, 2 -> 0)) |