scala/recs2.scala
author Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
Fri, 21 Dec 2018 12:31:36 +0100
changeset 290 6e1c03614d36
parent 271 4457185b22ef
permissions -rw-r--r--
Gave lemmas names in Abacus.ty
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
270
ccec33db31d4 some tests are commented out
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 269
diff changeset
     1
package object recs {
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
194
fc2a5e9fbb97 updated Scala files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
     3
//Recursive Functions
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
abstract class Rec {
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
  def eval(ns: List[Int]) : Int
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
     7
  def eval(ns: Int*) : Int = eval(ns.toList)
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
     8
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
     9
  //syntactic convenience for composition
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    10
  def o(r: Rec) = Cn(r.arity, this, List(r))
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    11
  def o(r: Rec, f: Rec) = Cn(r.arity, this, List(r, f))
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    12
  def o(r: Rec, f: Rec, g: Rec) = Cn(r.arity, this, List(r, f, g))
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    13
  def o(r: Rec, f: Rec, g: Rec, h: Rec) = Cn(r.arity, this, List(r, f, g, h))
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    14
  def arity : Int
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
    15
  def size : Int
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
}
194
fc2a5e9fbb97 updated Scala files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    17
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
case object Z extends Rec {
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
  override def eval(ns: List[Int]) = ns match {
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
    case n::Nil => 0
198
d93cc4295306 tuned some files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 195
diff changeset
    21
    case _ => throw new IllegalArgumentException("Z args: " + ns)
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
  }
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    23
  override def arity = 1
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
    24
  override def size = 1
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
} 
194
fc2a5e9fbb97 updated Scala files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    26
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
case object S extends Rec {
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  override def eval(ns: List[Int]) = ns match {
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
    case n::Nil => n + 1
198
d93cc4295306 tuned some files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 195
diff changeset
    30
    case _ => throw new IllegalArgumentException("S args: " + ns)
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  }
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
    32
  override def arity = 1
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
    33
  override def size = 1
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
} 
194
fc2a5e9fbb97 updated Scala files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    35
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
case class Id(n: Int, m: Int) extends Rec {
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    37
  require(m < n, println("Id m < n:" + m + " " + n))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    38
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  override def eval(ns: List[Int]) = 
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
    if (ns.length == n && m < n) ns(m)
198
d93cc4295306 tuned some files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 195
diff changeset
    41
    else throw new IllegalArgumentException("Id args: " + ns + "," + n + "," + m)
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    42
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    43
  override def arity = n
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
    44
  override def size = 1
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
}
194
fc2a5e9fbb97 updated Scala files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    46
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
case class Cn(n: Int, f: Rec, gs: List[Rec]) extends Rec {
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    48
  require(f.arity == gs.length, 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    49
          println("CN " + f + "  " + gs.mkString(",") + "\n" + 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    50
                  "f.arity gs.length:" + f.arity + " " + gs.length))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    51
  
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
  override def eval(ns: List[Int]) = 
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    53
    if (ns.length == n && gs.forall(_.arity == n) && f.arity == gs.length) f.eval(gs.map(_.eval(ns)))
239
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    54
    else { 
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    55
      val msg = List("Cn f: " + f, 
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    56
                     "n: " + n,
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    57
                     "f arity: " + f.arity, 
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    58
                     "ns-args: " + ns,
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    59
                     "gs arities: " + gs.map(_.arity).mkString(", "),
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    60
                     "gs: " + gs.mkString(", "),
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    61
                     "ns.length == n " + (ns.length == n).toString,
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    62
                     "gs.forall(_.arity == n) " + (gs.forall(_.arity == n)).toString,
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    63
                     "f.arity == gs.length " + (f.arity == gs.length).toString
239
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    64
                    )
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    65
      throw new IllegalArgumentException(msg.mkString("\n"))
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    66
    }
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    67
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    68
  override def arity = n
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
    69
  override def toString = f.toString + " o " + gs.map(_.toString).mkString ("(",", ", ")")
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
    70
  override def size = 1 + f.size + gs.map(_.size).sum
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    71
}
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    72
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    73
// syntactic convenience
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    74
object Cn {
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    75
  def apply(n: Int, f: Rec, g: Rec) : Rec = new Cn(n, f, List(g))
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
}
194
fc2a5e9fbb97 updated Scala files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
    77
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
case class Pr(n: Int, f: Rec, g: Rec) extends Rec {
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  override def eval(ns: List[Int]) = 
195
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 194
diff changeset
    80
    if (ns.length == n + 1) {
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    81
      if (ns.head == 0) f.eval(ns.tail)
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
      else {
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    83
        val r = Pr(n, f, g).eval(ns.head - 1 :: ns.tail)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
    84
        g.eval(ns.head - 1 :: r :: ns.tail)
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
      }
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
    }
239
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    87
    else {
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    88
      val msg = List("Pr f: " + f, 
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    89
                     "g: " + g,
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    90
                     "n: " + n,
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    91
                     "f arity: " + f.arity,
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    92
                     "g arity: " + g.arity,
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    93
                     "ns-args: " + ns)
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    94
      throw new IllegalArgumentException(msg.mkString("\n"))
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    95
    }
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    96
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
    97
  override def arity = n + 1
239
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
    98
  override def toString = "Pr(" + f.toString + ", " + g.toString + ")"
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
    99
  override def size = 1 + f.size + g.size
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   100
}
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   101
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   102
// syntactic convenience
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   103
object Pr {
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   104
  def apply(r: Rec, f: Rec) : Rec = Pr(r.arity, r, f) 
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
}
194
fc2a5e9fbb97 updated Scala files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 193
diff changeset
   106
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
case class Mn(n: Int, f: Rec) extends Rec {
195
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 194
diff changeset
   108
  def evaln(ns: List[Int], n: Int) : Int = 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   109
    if (f.eval(n :: ns) == 0) n else evaln(ns, n + 1)
195
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 194
diff changeset
   110
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 194
diff changeset
   111
  override def eval(ns: List[Int]) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 194
diff changeset
   112
    if (ns.length == n) evaln(ns, 0) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 194
diff changeset
   113
    else throw new IllegalArgumentException("Mn: args")
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   114
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   115
  override def arity = n
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
   116
  override def size = 1 + f.size
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
}
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   119
object Mn {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   120
  def apply(f: Rec) : Rec = Mn(f.arity - 1, f)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   121
}
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   122
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   123
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   124
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   125
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   126
// Recursive Function examples
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   127
def Const(n: Int) : Rec = n match {
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   128
  case 0 => Z
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   129
  case n => S o Const(n - 1)
193
317a2532c567 split up scala-file into separate components
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
}
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   131
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   132
def Swap(f: Rec) = f o (Id(2, 1), Id(2, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   133
val Add = Pr(Id(1, 0), S o Id(3, 1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   134
val Mult = Pr(Z, Add o (Id(3, 1), Id(3, 2)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   135
val Power = Swap(Pr(Const(1), Mult o (Id(3, 1), Id(3, 2))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   136
val Fact = (Pr (Const(1), Mult o (S o Id(3, 0), Id(3, 1)))) o (Id(1, 0), Id(1, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   137
val Pred = Pr(Z, Id(3, 0)) o (Id(1, 0), Id(1, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   138
val Minus = Swap(Pr(Id(1, 0), Pred o Id(3, 1)))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   139
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   140
val Sign = Minus o (Const(1), Minus o (Const(1), Id(1, 0)))
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   141
val Not = Minus o (Const(1), Id(1, 0))
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   142
val Eq = Minus o (Const(1) o Id(2, 0), Add o (Minus, Swap(Minus))) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   143
val Noteq = Not o Eq 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   144
val Conj = Sign o Mult
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   145
val Disj = Sign o Add 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   146
val Imp = Disj o (Not o Id(2, 0), Id(2, 1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   147
val Ifz = Pr(Id(2, 0), Id(4, 3))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   148
val If = Ifz o (Not o Id(3, 0), Id(3, 1), Id (3, 2))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   149
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   150
val Less = Sign o (Swap(Minus))
239
ac3309722536 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 238
diff changeset
   151
val Le = Disj o (Less, Eq)
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   152
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   153
def Sigma1(f: Rec) = Pr(f o (Z o (Id(1, 0)), Id(1, 0)), 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   154
                        Add o (Id(3, 1), f o (S o Id(3, 0), Id(3, 2))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   155
def Sigma2(f: Rec) = Pr(f o (Z o (Id(2, 0)), Id(2, 0), Id(2, 1)), 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   156
                        Add o (Id(4, 1), f o (S o Id(4, 0), Id(4, 2), Id(4, 3))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   157
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   158
def Accum1(f: Rec) = Pr(f o (Z o (Id(1, 0)), Id(1, 0)), 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   159
                        Mult o (Id(3, 1), f o (S o Id(3, 0), Id(3, 2))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   160
def Accum2(f: Rec) = Pr(f o (Z o (Id(2, 0)), Id(2, 0), Id(2, 1)), 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   161
                        Mult o (Id(4, 1), f o (S o Id(4, 0), Id(4, 2), Id(4, 3))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   162
def Accum3(f: Rec) = Pr(f o (Z o (Id(3, 0)), Id(3, 0), Id(3, 1), Id(3, 2)), 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   163
                        Mult o (Id(5, 1), f o (S o Id(5, 0), Id(5, 2), Id(5, 3), Id(5, 4))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   164
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   165
def All1(f: Rec) = Sign o (Accum1(f))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   166
def All2(f: Rec) = Sign o (Accum2(f))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   167
def All3(f: Rec) = Sign o (Accum3(f))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   168
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   169
def All1_less(f: Rec) = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   170
  val cond1 = Eq o (Id(3, 0), Id(3, 1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   171
  val cond2 = f o (Id(3, 0), Id(3, 2))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   172
  All2(Disj o (cond1, cond2)) o (Id(2, 0), Id(2, 0), Id(2, 1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   173
}
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   174
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   175
def All2_less(f: Rec) = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   176
  val cond1 = Eq o (Id(4, 0), Id(4, 1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   177
  val cond2 = f o (Id(4, 0), Id(4, 2), Id(4, 3))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   178
  All3(Disj o (cond1, cond2)) o (Id(3, 0), Id(3, 0), Id(3, 1), Id(3, 2))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   179
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   180
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   181
def Ex1(f: Rec) = Sign o (Sigma1(f))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   182
def Ex2(f: Rec) = Sign o (Sigma2(f))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   183
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   184
val Quo = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   185
  val lhs = S o (Id(3, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   186
  val rhs = Mult o (Id(3, 2), S o (Id(3, 1)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   187
  val cond = Eq o (lhs, rhs)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   188
  val if_stmt = If o (cond, S o (Id(3, 1)), Id(3, 1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   189
  Pr(Z, if_stmt)
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   190
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   191
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   192
def Iter(f: Rec) = Pr(Id(1, 0), f o (Id(3, 1)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   193
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   194
def Max1(f: Rec) = Pr(Z, Ifz o (f o (S o (Id(3, 0)), Id(3, 2)), S o (Id(3, 0)), Id(3, 1)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   195
def Max2(f: Rec) = Pr(Z, Ifz o (f o (S o (Id(4, 0)), Id(4, 2), Id(4, 3)), S o (Id(4, 0)), Id(4, 1)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   196
 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   197
val Triangle = Quo o (Mult o (Id(1, 0), S), Const(2))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   198
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   199
val MaxTriangle = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   200
  val cond = Not o (Le o (Triangle o (Id(2, 0)), Id(2, 1))) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   201
  Max1(cond) o (Id(1, 0), Id(1, 0))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   202
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   203
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   204
val MaxTriangle2 = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   205
  Pred o Mn(Le o (Triangle o (Id(2, 0)), Id(2, 1)))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   206
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   207
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   208
case object MaxTriangleFast extends Rec {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   209
  def triangle(n: Int) : Int = (n * (n + 1)) / 2
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   210
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   211
  def search(m: Int, n: Int) : Int = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   212
    if (triangle(n) > m) n - 1 else search(m, n + 1)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   213
  }
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   214
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   215
  override def eval(ns: List[Int]) = ns match {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   216
    case n::Nil => search(n, 0)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   217
    case _ => throw new IllegalArgumentException("MT args: " + ns)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   218
  }
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   219
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   220
  override def arity = 1
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
   221
  override def size = MaxTriangle.size
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   222
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   223
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   224
case object TriangleFast extends Rec {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   225
  def triangle(n: Int) : Int = (n * (n + 1)) / 2
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   226
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   227
  override def eval(ns: List[Int]) = ns match {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   228
    case n::Nil => triangle(n)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   229
    case _ => throw new IllegalArgumentException("Tr args: " + ns)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   230
  }
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   231
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   232
  override def arity = 1
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
   233
  override def size = Triangle.size
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   234
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   235
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   236
//(0 until 200).map(MaxTriangleFast.eval(_))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   237
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   238
271
4457185b22ef added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 270
diff changeset
   239
val Penc = Add o (Triangle o (Add o (Id(2, 0), Id(2, 1))), Id(2, 0))
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   240
val Pdec1 = Minus o (Id(1, 0), Triangle o (MaxTriangle o (Id(1, 0)))) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   241
val Pdec2 = Minus o (MaxTriangle o (Id(1, 0)), Pdec1 o (Id(1, 0))) 
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   242
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   243
def Lenc(fs: List[Rec]) : Rec = fs match {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   244
  case Nil => Z
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   245
  case f::fs => Penc o (S o (f), Lenc(fs))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   246
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   247
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   248
val Ldec = Pred o (Pdec1 o (Swap (Iter(Pdec2))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   249
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   250
val Within = Less o (Z o (Id(2, 0)), Swap (Iter(Pdec2)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   251
val Enclen = (Max1(Not o (Within o (Id(2, 1), Pred o (Id(2, 0)))))) o (Id(1, 0), Id(1, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   252
 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   253
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   254
val Read = Ldec o (Id(1, 0), Const(0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   255
val Write = Penc o (S o (Id(2, 0)), Pdec2 o (Id(2, 1)))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   256
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   257
val Newleft = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   258
  val cond0 = Eq o (Id(3, 2), Const(0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   259
  val cond1 = Eq o (Id(3, 2), Const(1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   260
  val cond2 = Eq o (Id(3, 2), Const(2))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   261
  val cond3 = Eq o (Id(3, 2), Const(3))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   262
  val case3 = Penc o (S o (Read o (Id(3, 1))), Id(3, 0)) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   263
  If o (cond0, 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   264
        Id(3, 0),
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   265
        If o (cond1, 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   266
              Id(3, 0),  
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   267
              If o (cond2, 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   268
                    Pdec2 o (Id(3, 0)),
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   269
                    If o (cond3, case3, Id(3, 0)))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   270
}
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   271
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   272
val Newright = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   273
  val cond0 = Eq o (Id(3, 2), Const(0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   274
  val cond1 = Eq o (Id(3, 2), Const(1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   275
  val cond2 = Eq o (Id(3, 2), Const(2))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   276
  val cond3 = Eq o (Id(3, 2), Const(3))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   277
  val case2 = Penc o (S o (Read o (Id(3, 0))), Id(3, 1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   278
  If o (cond0, 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   279
        Write o (Const(0), Id(3, 1)),
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   280
        If o (cond1, 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   281
              Write o (Const(1), Id(3, 1)),  
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   282
              If o (cond2, 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   283
                    case2,
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   284
                    If o (cond3, Pdec2 o (Id(3, 1)), Id(3, 0)))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   285
}
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   286
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   287
val Actn = Swap (Pr(Pdec1 o (Pdec1 o (Id(1, 0))), Pdec1 o (Pdec2 o (Id(3, 2)))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   288
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   289
val Action = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   290
  val cond1 = Noteq o (Id(3, 1), Z)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   291
  val cond2 = Within o (Id(3, 0), Pred o (Id(3, 1)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   292
  val if_branch = Actn o (Ldec o (Id(3, 0), Pred o (Id(3, 1))), Id(3, 2))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   293
  If o (Conj o (cond1, cond2), if_branch, Const(4))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   294
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   295
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   296
val Newstat = Swap (Pr (Pdec2 o (Pdec1 o (Id(1, 0))),
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   297
                        Pdec2 o (Pdec2 o (Id(3, 2)))))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   298
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   299
val Newstate = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   300
  val cond = Noteq o (Id(3, 1), Z)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   301
  val if_branch = Newstat o (Ldec o (Id(3, 0), Pred o (Id(3, 1))), Id(3, 2))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   302
  If o (cond, if_branch, Z)
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   303
}
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   304
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   305
val Conf = Lenc (List(Id(3, 0), Id(3, 1), Id(3, 2)))
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   306
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   307
val State = Ldec o (Id(1, 0), Z)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   308
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   309
val Left = Ldec o (Id(1, 0), Const(1))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   310
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   311
val Right = Ldec o (Id(1, 0), Const(2))
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   312
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   313
val Step = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   314
  val left = Left o (Id(2, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   315
  val right = Right o (Id(2, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   316
  val state = State o (Id(2, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   317
  val read = Read o (right)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   318
  val action = Action o (Id(2, 1), state, read)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   319
  val newstate = Newstate o (Id(2, 1), state, read)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   320
  val newleft = Newleft o (left, right, action)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   321
  val newright = Newright o (left, right, action) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   322
  Conf o (newstate, newleft, newright)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   323
 } 
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   324
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   325
val Steps = Pr (Id(2, 0), Step o (Id(4, 1), Id(4, 3)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   326
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   327
val Stknum = Minus o (Sigma1(Ldec o (Id(2, 1), Id(2, 0))) o (Enclen o (Id(1, 0)), Id(1, 0)),
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   328
                      Ldec o (Id(1, 0), Enclen o (Id(1, 0))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   329
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   330
val Right_std = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   331
  val bound = Enclen o (Id(1, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   332
  val cond1 = Le o (Const(1) o (Id(2, 0)), Id(2, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   333
  val cond2 = All1_less (Eq o (Ldec o (Id(2, 1), Id(2, 0)), Const(1)))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   334
  val bound2 = Minus o (Enclen o (Id(2, 1)), Id(2, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   335
  val cond3 = 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   336
    (All2_less (Eq o (Ldec o (Id(3, 2), Add o (Id(3, 1), Id(3, 0))), Z))) o (bound2, Id(2, 0), Id(2, 1)) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   337
  Ex1(Conj o (Conj o (cond1, cond2), cond3)) o (bound, Id(1, 0))
200
8dde2e46c69d added all recursive functions needed for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 198
diff changeset
   338
}
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   339
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   340
val Left_std = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   341
  val cond = Eq o (Ldec o (Id(2, 1), Id(2, 0)), Z)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   342
  (All1_less(cond)) o (Enclen o (Id(1, 0)), Id(1, 0))
201
09befdf4fc99 syntactic convenience for recursive functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 200
diff changeset
   343
}
238
6ea1062da89a used prime from the library
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   344
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   345
val Std = Conj o (Left_std o (Left o (Id(1, 0))), Right_std o (Right o (Id(1, 0))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   346
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   347
val Final = Eq o (State o (Id(1, 0)), Z)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   348
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   349
val Stop = {
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   350
  val stps = Steps o (Id(3, 2), Id(3, 1), Id(3, 0))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   351
  Conj o (Final o (stps), Std o (stps))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   352
}
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   353
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   354
val Halt = Mn (Not o (Stop o (Id(3, 1), Id(3, 2), Id(3, 0))))
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   355
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 239
diff changeset
   356
val UF = Pred o (Stknum o (Right o (Steps o (Halt o (Id(2, 0), Id(2, 1)), Id(2, 1), Id(2, 0)))))
238
6ea1062da89a used prime from the library
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   357
6ea1062da89a used prime from the library
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 201
diff changeset
   358
}