scala/ex.scala
changeset 269 fa40fd8abb54
parent 240 696081f445c2
child 270 ccec33db31d4
--- a/scala/ex.scala	Thu Jun 06 17:27:45 2013 +0100
+++ b/scala/ex.scala	Wed Jun 26 14:35:43 2013 +0100
@@ -60,51 +60,75 @@
 println("Compiled Expo 3 ^ 4: " + toTM(Expo(0, 1, 2, 3, 4, 10000).p).run(Tape(3,4,0,0,0)))
 
 // Recursive function examples 
+println("Const 8:   " + Const(8).eval(67))
 println("Add 3 4:   " + Add.eval(3, 4))
 println("Mult 3 4:  " + recs.Mult.eval(3, 4))
-println("Twice 4:   " + Twice.eval(4))
-println("FourTm 4:  " + Fourtimes.eval(4))
+println("Power 2 3: " + Power.eval(2, 3))
+println("Fact 5:    " + Fact.eval(5))
 println("Pred 9:    " + Pred.eval(9))
 println("Pred 0:    " + Pred.eval(0))
 println("Minus 6 2: " + Minus.eval(6, 2))
 println("Minus 6 8: " + Minus.eval(6, 8))
-println("Const 8:   " + Const(8).eval(67))
-println("Power 2 3: " + Power.eval(2, 3))
+
+
 println("Sign 8:    " + Sign.eval(8))
 println("Sign 0:    " + Sign.eval(0))
+println("Not 0:     " + Not.eval(0))
+println("Not 6:     " + Not.eval(6))
+println("Eq 4 4:    " + Eq.eval(4, 4))
+println("Eq 4 6:    " + Eq.eval(4, 6))
+println("Eq 6 4:    " + Eq.eval(6, 4))
+println("NotEq 4 4: " + Noteq.eval(4, 4))
+println("NotEq 4 6: " + Noteq.eval(4, 6))
+println("NotEq 6 4: " + Noteq.eval(6, 4))
+println("Conj 0 6:  " + Conj.eval(0, 6))
+println("Conj 6 4:  " + Conj.eval(6, 4))
+println("Conj 0 0:  " + Conj.eval(0, 0))
+println("Disj 0 6:  " + Disj.eval(0, 6))
+println("Disj 6 4:  " + Disj.eval(6, 4))
+println("Disj 0 0:  " + Disj.eval(0, 0))
+println("Imp  6 1:  " + Imp.eval(6, 1))
+println("Imp  6 4:  " + Imp.eval(6, 4))
+println("Imp  1 0:  " + Imp.eval(1, 0))
+println("Ifz  0 1 2:" + Ifz.eval(0, 1, 2))
+println("Ifz  1 1 2:" + Ifz.eval(1, 1, 2))
+println("If   0 1 2:" + If.eval(0, 1, 2))
+println("If   1 1 2:" + If.eval(1, 1, 2))
+
+
 println("Less 4 4:  " + Less.eval(4, 4))
 println("Less 4 6:  " + Less.eval(4, 6))
 println("Less 6 4:  " + Less.eval(6, 4))
 println("Le 4 4:    " + recs.Le.eval(4, 4))
 println("Le 4 6:    " + recs.Le.eval(4, 6))
 println("Le 6 4:    " + recs.Le.eval(6, 4))
-println("Not 0:     " + Not.eval(0))
-println("Not 6:     " + Not.eval(6))
-println("Eq 4 4:    " + Eq.eval(4, 4))
-println("Eq 4 6:    " + Eq.eval(4, 6))
-println("Eq 6 4:    " + Eq.eval(6, 4))
-println("Conj 0 6:  " + Conj.eval(0, 6))
-println("Conj 6 4:  " + Conj.eval(6, 4))
-println("Conj 0 0:  " + Conj.eval(0, 0))
-println("Disj 0 6:  " + Disj.eval(0, 6))
-println("Disj 6 4:  " + Disj.eval(6, 4))
-println("Disj 0 0:  " + Disj.eval(0, 0))
-println("Sigma Add 2 3 -> 14:  " + Sigma(Add).eval(2,3))
-println("Accum Add 2 3 -> 120: " + Accum(Add).eval(2,3))
-println("Accum Mult 2 3 -> 0:  " + Accum(recs.Mult).eval(2,3))
-println("Fact 5:  " + Fact.eval(5))
-println("Prime 0..15: " + (0 to 15).map(n => (n, Prime.eval(n))))
-println("NextPrime 3: " + NextPrime.eval(3))
-println("NthPrime 1:  " + NthPrime.eval(1))
-println("Listsum [2, 3, 4 , 5, 6]: " + Listsum(5, 4).eval(2, 3, 4, 5, 6))
-println("Strt:  " + Strt(2).eval(2, 3))
-println("(<=5) 1: " + (Less o (Id(1, 0), Const(5))).eval(1))
-println("(<=5) 5: " + (Less o (Id(1, 0), Const(5))).eval(5))
-println("(<=5) 6: " + (Less o (Id(1, 0), Const(5))).eval(6))
-println("Max (<=9): " + Maxr(Le o (Id(1, 0), Const(9))).eval(10))
-println("Max (>=9): " + Maxr(Le o (Const(9), Id(1, 0))).eval(8))
-println("test")
-println("Lg 4 2: " + Lg.eval(4, 2))
+
+println("Sigma1 Add 2 3 -> 12: " + Sigma1(Add).eval(2, 3))
+println("Accum1 Add 2 3 -> 60:  " + Accum1(Add).eval(2,3))
+println("Accum1 Mult 2 3 -> 0:  " + Accum1(Mult).eval(2,3))
+println("Accum1 (Id(2, 1)) 2 3 -> 27:  " + Accum1(Id(2, 1)).eval(2,3))
+println("Accum2 (Id(3, 1)) 2 3 3 -> 27:  " + Accum2(Id(3, 1)).eval(2,3,3))
+println("Accum3 (Id(4, 1)) 2 3 3 3 -> 27:  " + Accum3(Id(4, 1)).eval(2,3,3,3))
+println("All1 Add 2 0 -> 0:  " + All1(Add).eval(2,0))
+println("All1 Add 2 1 -> 1:  " + All1(Add).eval(2,1))
+println("All1_less Add 3 0 -> 0:  " + All1_less(Add).eval(2,0))
+println("All1_less Add 3 1 -> 1:  " + All1_less(Add).eval(2,1))
+println("All2_less (Id 3 1) 2 3 0 -> 1:  " + All2_less(Id(3, 1)).eval(2,3,0))
+println("All2_less (Id 3 0) 2 3 0 -> 0:  " + All2_less(Id(3, 0)).eval(2,3,0))
+println("Ex1 Add 2 0 -> 1:       " + Ex1(Add).eval(2,0))
+println("Ex2 Id(3,1) 2 1 0 -> 1: " + Ex2(Id(3, 1)).eval(2,1,0))
+println("Ex2 Id(3,2) 2 1 0 -> 0: " + Ex2(Id(3, 2)).eval(2,1,0))
+
+println("Quo 6 4 -> 1:   " + Quo.eval(6, 4))
+println("Quo 13 4 -> 3:  " + Quo.eval(13, 4))
+
+println("Triangle 0 - 5: " + (0 until 5).map(Triangle.eval(_)).mkString(","))
+println("MaxTriangle 10 -> 4 " + MaxTriangle.eval(10))
+
+println("Penc 1 2 -> 7: " + Penc.eval(1, 2))
+println("Pdec1 7 -> 1:  " + Pdec1.eval(7))
+println("Pdec2 7 -> 2:  " + Pdec2.eval(7))
+println("Enclen 0 .. 10: " + (0 until 10).map(EncLen.eval(_)))
 
 // compilation of rec to abacus tests
 def test_comp2(f: Rec, ns: Int*) = {
@@ -125,9 +149,6 @@
 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("Prime(5)      " + test_comp2(Prime, 5))
-//println("Prime(4)      " + test_comp2(Prime, 4))
-println("Strt(1)(2)    " + test_comp2(Strt(1), 2))
 
 
 def test_comp1(f: Rec, ns: Int*) = {