turing.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 21 Feb 2013 05:34:39 +0000
changeset 190 f1ecb4a68a54
parent 189 5974111de158
child 191 98370b96c1c5
permissions -rw-r--r--
renamed sete definition to adjust and old special case of adjust to adjust0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     1
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     2
//some list functions
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     3
def tl[A](xs: List[A]) : List[A] = xs match {
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     4
  case Nil => Nil
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     5
  case x::xs => xs
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     6
}
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     7
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     8
def hd[A](xs: List[A]) : A = xs.head
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
     9
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    10
def nth_of[A](xs: List[A], n: Int) = 
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    11
  if (n <= xs.length) Some(xs(n)) else None 
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    12
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    13
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    14
//some map functions
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    15
def dget(m: Map[Int, Int], n: Int) = m.getOrElse(n, 0)
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    16
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    17
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    18
//some string functions
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    19
def join[A](xs: List[A]) = xs.foldLeft("")(_.toString + _)
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    20
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    21
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    22
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    23
abstract class Cell {
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    24
  def * (n: Int) : List[Cell] = n match {
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    25
    case 0 => Nil
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    26
    case n => this :: this * (n - 1)
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    27
  }
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    28
}
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
case object Bk extends Cell { override def toString = "0" }
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
case object Oc extends Cell { override def toString = "1" }
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
abstract class Action
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
case object WBk extends Action
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
case object WOc extends Action
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
case object R extends Action
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
case object L extends Action
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
case object Nop extends Action
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
type State = Int
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    40
type Inst = (Action, State)
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    41
type Prog = List[Inst]
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
//tapes
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
case class Tape(l: List[Cell], r: List[Cell]) {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  def update(a: Action) = a match {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
    case WBk => Tape(l, Bk::tl(r))
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
    case WOc => Tape(l, Oc::tl(r))
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
    case L => if (l == Nil) Tape(Nil, Bk::r) else Tape (tl(l), hd(l)::r)
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
    case R => if (r == Nil) Tape(Bk::l, Nil) else Tape(hd(r)::l, tl(r))
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
    case Nop => Tape(l, r)
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
  }
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  def read = r match {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
    case Nil => Bk
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
    case x::_ => x
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  }
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    58
  override def toString = join(l.reverse) + ">" + join(r)
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
}
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
// standard tapes
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    62
class STape(ns: Int*) extends 
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    63
  Tape(Nil, ns.map(n => Oc * (n + 1)).reduceLeft(_ ::: List(Bk) ::: _))
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    64
  
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
// configurations
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
case class Config(s: State, tp: Tape) {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
  def is_final = s == 0
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
  override def toString = tp.toString
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
}
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
183
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
    74
// Turing machines
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
    75
case class TM(p: Prog) {
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    76
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    77
  def ++ (that: TM) = TM(this.p ::: that.p)
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    78
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    79
  def shift(n: Int) =
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
    80
    TM(p.map{case (a, s) => (a, if (s == 0) 0 else s + n)})
189
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
    81
  def adjust(n: Int) : TM =
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
    82
    TM(p.map{case (a, s) => (a, if (s == 0) n else s)})
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
    83
  def adjust : TM = adjust(p.length / 2 + 1)
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
  
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
  def fetch(s: State, a: Cell) = (s, a) match {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
    case (0, _) => (Nop, 0)
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    87
    case (s, Bk) => nth_of(p, 2 * (s - 1)) match {
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    88
      case None => (Nop, 0)
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    89
      case Some(i) => i
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
    90
    }
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
    case (s, Oc) => nth_of(p, 2 * (s - 1) + 1) match {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
      case None => (Nop, 0)
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
      case Some(i) => i
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
    }
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
  } 
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
  def step(cf: Config) : Config = fetch (cf.s, cf.tp.read) match {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
    case (a, s_next) => Config(s_next, cf.tp.update(a))
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
  }
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
  def steps(cf: Config, n: Int) : Config = n match {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
    case 0 => cf
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
    case n => steps(step(cf), n - 1)
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
  } 
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
  def run(cf: Config) : Config = {
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
    if (cf.is_final) cf else run(step(cf))
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
  }
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
 
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   110
  def run(tp: Tape) : Tape = run(Config(1, tp)).tp
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
}
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
183
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   114
// Turing machine examples
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   115
val TMCopy = TM(List((WBk, 5), (R, 2), (R, 3), (R, 2), (WOc, 3), 
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   116
                     (L, 4), (L, 4), (L, 5), (R, 11), (R, 6), 
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   117
                     (R, 7), (WBk, 6), (R, 7), (R, 8), (WOc, 9), 
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   118
                     (R, 8), (L, 10), (L, 9), (L, 10), (L, 5), 
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   119
                     (L, 0), (R, 12), (WOc, 13), (L, 14), (R, 12), 
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   120
                     (R, 12), (L, 15), (WBk, 14), (R, 0), (L, 15)))
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   121
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   122
def TMFindnth(n: Int) : TM = n match {
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   123
  case 0 => TM(Nil)
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   124
  case n => TMFindnth(n - 1) ++ TM(List((WOc, 2 * n - 1), (R, 2 * n), (R, 2 * n + 1), (R, 2 * n)))
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   125
}
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   126
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   127
def TMMopup(n: Int) = {
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   128
  def TMMopup1(n: Int) : TM = n match {
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   129
    case 0 => TM(Nil)
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   130
    case n => TMMopup1(n - 1) ++ TM(List((R, 2 * n + 1), (WBk, 2 * n), (R, 2 * n - 1), (WOc, 2 * n)))
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   131
  }
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   132
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   133
  val TMMopup2 = TM(List((R, 2), (R, 1), (L, 5), (WBk, 3), (R, 4), (WBk, 3),
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   134
                         (R, 2), (WBk, 3), (L, 5), (L, 6), (R, 0), (L, 6)))
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   135
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   136
  TMMopup1(n) ++ TMMopup2.shift(2 * n)
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   137
}
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   138
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   139
178
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   140
println("TMCopy:    " + (TMCopy.run(new STape(3))))
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   141
println("TMfindnth: " + (TMFindnth(3).run(new STape(1,2,3,4,5))))
8248f8adf17d added some TM machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 177
diff changeset
   142
println("TMMopup: "   + (TMMopup(3).run(new STape(1,2,3,4,5))))
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   143
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   144
183
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   145
// Abacus machines
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   146
abstract class AInst 
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   147
case class Inc(n: Int) extends AInst
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   148
case class Dec(n: Int, l: Int) extends AInst
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   149
case class Goto(l: Int) extends AInst
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   150
183
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   151
// shifting and adjusting labels
180
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   152
def ashift(ai: AInst, offset: Int, jump: Int) = ai match {
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   153
  case Inc(n) => Inc(n)
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   154
  case Dec(n, l) => if (l == jump) Dec(n, l) else Dec(n, l + offset)
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   155
  case Goto(l) => if (l == jump) Goto(l) else Goto(l + offset)
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   156
}
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   157
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   158
def aadjust(ai: AInst, old_jump: Int, jump: Int) = ai match {
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   159
  case Inc(n) => Inc(n)
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   160
  case Dec(n, l) => if (l == old_jump) Dec(n, jump) else Dec(n, l)
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   161
  case Goto(l) => if (l == old_jump) Goto(jump) else Goto(l)
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   162
}
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   163
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   164
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   165
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   166
type AProg = List[AInst]
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   167
type Regs = Map[Int, Int]
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   168
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   169
case class AConfig(s: Int, regs: Regs)  
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   171
case class Abacus(p: AProg) {
180
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   172
189
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   173
   def ++ (that: Abacus) = Abacus(this.p ::: that.p)
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   174
180
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   175
  def shift(offset: Int, jump: Int) = Abacus(p.map(ashift(_, offset, jump)))
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   176
  def adjust(old_jump: Int, jump: Int) = Abacus(p.map(aadjust(_, old_jump, jump)))
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   177
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   178
  def step(cf: AConfig) : AConfig = (nth_of(p, cf.s), cf.s) match {
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   179
    case (None, _) => cf
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   180
    case (Some(Inc(n)), s) => AConfig(s + 1, cf.regs + (n -> (dget(cf.regs, n) + 1)))
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   181
    case (Some(Dec(n, l)), s) => {
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   182
      if (dget(cf.regs, n) == 0) AConfig(l, cf.regs)
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   183
      else AConfig(s + 1, cf.regs + (n -> (dget(cf.regs, n) - 1)))
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   184
    }
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   185
    case (Some(Goto(l)), _) => AConfig(l, cf.regs)
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   186
  }  
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   187
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   188
  def steps(cf: AConfig, n: Int) : AConfig = n match {
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   189
    case 0 => cf
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   190
    case n => steps(step(cf), n - 1)
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   191
  } 
176
d2c85556d290 added scala file
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   193
  def steps(regs: Regs, n: Int) : AConfig = steps(AConfig(0, regs), n)
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   194
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   195
  def run(cf: AConfig) : AConfig = {
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   196
    if (cf.s >= p.length || cf.s < 0) cf else run(step(cf))
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   197
  }
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   198
 
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   199
  def run(regs: Regs): Regs = run(AConfig(0, regs)).regs
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   200
}
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   201
183
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   202
// Abacus examples
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   203
def Copy(in: Int, out: Int, jump: Int) = 
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   204
  Abacus(List(Dec(in, jump), Inc(out), Goto(0))) 
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   205
180
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   206
def Plus(m: Int, n: Int, tmp: Int, jump: Int) =
189
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   207
  Abacus(List(Dec(m, 4), Inc(n), Inc(tmp), Goto(0), Dec(tmp, jump), Inc(m), Goto(4))) 
180
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   208
189
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   209
def Mult(in1: Int, in2: Int, out: Int, tmp: Int, jump: Int) = 
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   210
  Abacus(List(Dec(in1, jump))) ++ Plus(in2, out, tmp, -1).shift(1, -1).adjust(-1, 0)
180
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   211
183
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   212
def Expo(in1: Int, in2: Int, out: Int, tmp1: Int, tmp2: Int, jump: Int) = {
189
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   213
  Abacus(List(Inc(out), Dec(in1, jump))) ++ 
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   214
  Mult(out, in2, tmp2, tmp1, -1).shift(2, -1).adjust(-1, 10) ++
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   215
  Copy(tmp2, out, -1).shift(10, -1). adjust(-1, 1)
180
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   216
}
177
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   217
1c2e639d4e54 added abacus programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 176
diff changeset
   218
183
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   219
println("Copy: " + (Copy(0, 1, -1).run(Map(0 -> 3, 1 -> 0))))
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   220
println("Plus: 3 + 4 " + (Plus(0, 1, 2, -1).run(Map(0 -> 3, 1 -> 4, 2 -> 0))))
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   221
println("Mult: 3 * 5 " + (Mult(0, 1, 2, 3, -1).run(Map(0 -> 3, 1 -> 5, 2 -> 0, 3 -> 0))))
4cf023ee2f4c updated exponent program
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 182
diff changeset
   222
println("Expo: 3 ^ 4 " + (Expo(0, 1, 2, 3, 4, -1).run(Map(0 -> 4, 1 -> 3, 2 -> 0, 3 -> 0, 4 -> 0))))
179
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   223
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   224
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   225
// Abacus to TM translation
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   226
val TMInc = TM(List((WOc, 1), (R, 2), (WOc, 3), (R, 2), (WOc, 3), (R, 4), 
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   227
                    (L, 7), (WBk, 5), (R, 6), (WBk, 5), (WOc, 3), (R, 6),
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   228
                    (L, 8), (L, 7), (R, 9), (L, 7), (R, 10), (WBk, 9)))
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   229
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   230
val TMDec = TM(List((WOc, 1), (R, 2), (L, 14), (R, 3), (L, 4), (R, 3),
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   231
                    (R, 5), (WBk, 4), (R, 6), (WBk, 5), (L, 7), (L, 8),
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   232
                    (L, 11), (WBk, 7), (WOc, 8), (R, 9), (L, 10), (R, 9),
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   233
                    (R, 5), (WBk, 10), (L, 12), (L, 11), (R, 13), (L, 11),
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   234
                    (R, 17), (WBk, 13), (L, 15), (L, 14), (R, 16), (L, 14),
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   235
                    (R, 0), (WBk, 16)))
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   236
189
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   237
def TMINC(s: Int, n: Int, e: Int) = (TMFindnth(n).shift(s - 1) ++ TMInc.shift(2 * n)).shift(s - 1).adjust(e)
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   238
189
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   239
def TMDEC(s: Int, n: Int, e: Int) = (TMFindnth(n).shift(s - 1) ++ TMInc.shift(2 * n)).shift(s - 1).adjust(e)
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   240
189
5974111de158 parts of the Abacus translation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 188
diff changeset
   241
//def toTM()
188
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   242
8939cc9b14f9 tuned Scala implementation
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 183
diff changeset
   243
179
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   244
//Recursive Functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   245
abstract class Rec {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   246
  def eval(ns: List[Int]) : Int
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   247
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   248
case object Z extends Rec {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   249
  override def eval(ns: List[Int]) = ns match {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   250
    case n::Nil => 0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   251
    case _ => throw new IllegalArgumentException("Z: args")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   252
  }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   253
} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   254
case object S extends Rec {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   255
  override def eval(ns: List[Int]) = ns match {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   256
    case n::Nil => n + 1
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   257
    case _ => throw new IllegalArgumentException("S: args")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   258
  }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   259
} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   260
case class Id(n: Int, m: Int) extends Rec {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   261
  override def eval(ns: List[Int]) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   262
    if (ns.length == n && m < n) ns(m)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   263
    else throw new IllegalArgumentException("Id: args")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   264
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   265
case class Cn(n: Int, f: Rec, gs: List[Rec]) extends Rec {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   266
  override def eval(ns: List[Int]) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   267
    if (ns.length == n) f.eval(gs.map(_.eval(ns)))
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   268
    else throw new IllegalArgumentException("Cn: args")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   269
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   270
case class Pr(n: Int, f: Rec, g: Rec) extends Rec {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   271
  override def eval(ns: List[Int]) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   272
    if (ns.length == n - 1) {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   273
      if (ns.last == 0) f.eval(ns.init)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   274
      else {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   275
        val r = Pr(n, f, g).eval(ns.init ::: List(ns.last - 1))
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   276
        g.eval(ns.init ::: List(ns.last - 1, r))
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   277
      }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   278
    }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   279
    else throw new IllegalArgumentException("Cn: args")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   280
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   281
case class Mn(n: Int, f: Rec) extends Rec {
180
8f443f2ed1f6 added abacus machines
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 179
diff changeset
   282
  override def eval(ns: List[Int]) = 0
179
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   283
    
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   284
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
   285