diff -r 6ea1062da89a -r ac3309722536 scala/ex.scala --- a/scala/ex.scala Mon Apr 22 10:33:40 2013 +0100 +++ b/scala/ex.scala Wed Apr 24 09:49:00 2013 +0100 @@ -5,6 +5,16 @@ import comp1._ import comp2._ +val Lg = { + val lgR = Le o (Power o (Id(3, 1), Id(3, 2)), Id(3, 0)) + val conR1 = Conj o (Less o (Const(1) o (Id(2, 0), Id(2, 0))), + Less o (Const(1) o (Id(2, 0), Id(2, 1)))) + val conR2 = Not o (conR1) + Add o (recs.Mult o (conR1, Maxr(lgR) o (Id(2, 0), Id(2, 1), Id(2, 0))), + recs.Mult o (conR2, Const(0) o (Id(2, 0)))) +} + + // Turing machine examples val TMCopy = TM((WBk, 5), (R, 2), (R, 3), (R, 2), (WOc, 3), @@ -65,6 +75,9 @@ 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)) @@ -84,8 +97,16 @@ 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("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("Min (>=9): " + Minr(Le o (Const(9), Id(1, 0))).eval(10)) +println("Min (<=9): " + Minr(Le o (Id(1, 0), Const(9))).eval(10)) +println("Min (>=9): " + Minr(Le o (Const(9), Id(1, 0))).eval(8)) +//println("Lg 4 2: " + Lg.eval(4, 2)) // compilation of rec to abacus tests def test_comp2(f: Rec, ns: Int*) = {