scala/ex.scala
changeset 240 696081f445c2
parent 239 ac3309722536
child 269 fa40fd8abb54
equal deleted inserted replaced
239:ac3309722536 240:696081f445c2
     4 import recs._
     4 import recs._
     5 import comp1._
     5 import comp1._
     6 import comp2._
     6 import comp2._
     7 
     7 
     8 val Lg = {
     8 val Lg = {
     9  val lgR = Le o (Power o (Id(3, 1), Id(3, 2)), Id(3, 0))
     9   val lgR = Le o (Power o (Id(3, 1), Id(3, 2)), Id(3, 0))
    10  val conR1 = Conj o (Less o (Const(1) o (Id(2, 0), Id(2, 0))), 
    10   val conR1 = Conj o (Less o (Const(1) o (Id(2, 0), Id(2, 0))), 
    11                      Less o (Const(1) o (Id(2, 0), Id(2, 1))))
    11                      Less o (Const(1) o (Id(2, 0), Id(2, 1))))
    12  val conR2 = Not o (conR1)
    12   val conR2 = Not o (conR1)
    13  Add o (recs.Mult o (conR1, Maxr(lgR) o (Id(2, 0), Id(2, 1), Id(2, 0))), 
    13   Add o (recs.Mult o (conR1, Maxr(lgR) o (Id(2, 0), Id(2, 1), Id(2, 0))), 
    14         recs.Mult o (conR2, Const(0) o (Id(2, 0)))) 
    14          recs.Mult o (conR2, Const(0) o (Id(2, 0)))) 
    15 }
    15 }
    16 
    16 
    17 
    17 
    18 
    18 
    19 // Turing machine examples
    19 // Turing machine examples
   101 println("(<=5) 1: " + (Less o (Id(1, 0), Const(5))).eval(1))
   101 println("(<=5) 1: " + (Less o (Id(1, 0), Const(5))).eval(1))
   102 println("(<=5) 5: " + (Less o (Id(1, 0), Const(5))).eval(5))
   102 println("(<=5) 5: " + (Less o (Id(1, 0), Const(5))).eval(5))
   103 println("(<=5) 6: " + (Less o (Id(1, 0), Const(5))).eval(6))
   103 println("(<=5) 6: " + (Less o (Id(1, 0), Const(5))).eval(6))
   104 println("Max (<=9): " + Maxr(Le o (Id(1, 0), Const(9))).eval(10))
   104 println("Max (<=9): " + Maxr(Le o (Id(1, 0), Const(9))).eval(10))
   105 println("Max (>=9): " + Maxr(Le o (Const(9), Id(1, 0))).eval(8))
   105 println("Max (>=9): " + Maxr(Le o (Const(9), Id(1, 0))).eval(8))
   106 println("Min (>=9): " + Minr(Le o (Const(9), Id(1, 0))).eval(10))
   106 println("test")
   107 println("Min (<=9): " + Minr(Le o (Id(1, 0), Const(9))).eval(10))
   107 println("Lg 4 2: " + Lg.eval(4, 2))
   108 println("Min (>=9): " + Minr(Le o (Const(9), Id(1, 0))).eval(8))
       
   109 //println("Lg 4 2: " + Lg.eval(4, 2))
       
   110 
   108 
   111 // compilation of rec to abacus tests
   109 // compilation of rec to abacus tests
   112 def test_comp2(f: Rec, ns: Int*) = {
   110 def test_comp2(f: Rec, ns: Int*) = {
   113   val (abc_f, arity, _) = compile_rec(f)
   111   val (abc_f, arity, _) = compile_rec(f)
   114   val abc_map = (0 until ns.length).zip(ns).toMap[Int, Int]
   112   val abc_map = (0 until ns.length).zip(ns).toMap[Int, Int]