diff --git a/testcases/synthesis/cav2013/List.scala b/testcases/synthesis/cav2013/List.scala index ce9c60f4ef6ed672f140ae2bd8dfc7e858ddc5be..b7668240194ddcca33f8e1e7b42cb9d37b176ab9 100644 --- a/testcases/synthesis/cav2013/List.scala +++ b/testcases/synthesis/cav2013/List.scala @@ -7,6 +7,8 @@ object List { case class Cons(head: Int, tail: List) extends List case class Nil() extends List + def inv(l: List): Boolean = true + def size(l: List) : Int = (l match { case Nil() => 0 case Cons(_, t) => 1 + size(t) @@ -17,48 +19,23 @@ object List { case Cons(i, t) => Set(i) ++ content(t) } - def isSorted(l: List): Boolean = l match { - case Nil() => true - case Cons(x, Nil()) => true - case Cons(x, Cons(y, ys)) => x <= y && isSorted(Cons(y, ys)) - } - - def isStrictSorted(l: List): Boolean = l match { - case Nil() => true - case Cons(x, Nil()) => true - case Cons(x, Cons(y, ys)) => x < y && isSorted(Cons(y, ys)) - } - def deleteSynth(in: List, v: Int) = choose { - (out: List) => (content(out) == (content(in) -- Set(v))) - } + // To Synthesize: - def deleteSortedSynth(in: List, v: Int) = choose { - (out: List) => isSorted(in) && (content(out) == (content(in) -- Set(v))) && isSorted(out) - } - def insertSynth(in: List, v: Int) = choose { - (out: List) => (content(out) == (content(in) ++ Set(v))) + def insert(in: List, v: Int) = choose { + (out: List) => inv(in) && (content(out) == (content(in) ++ Set(v))) && inv(out) } - def insertSortedSynth(in: List, v: Int) = choose { - (out: List) => isSorted(in) && (content(out) == (content(in) ++ Set(v))) && isSorted(out) + def delete(in: List, v: Int) = choose { + (out: List) => inv(in) && (content(out) == (content(in) -- Set(v))) && inv(out) } - def insertStrictSortedSynth(in: List, v: Int) = choose { - (out: List) => isStrictSorted(in) && (content(out) == (content(in) ++ Set(v))) && isStrictSorted(out) + def union(in1: List, in2: List) = choose { + (out: List) => inv(in1) && inv(in2) && (content(out) == (content(in1) ++ content(in2))) && inv(out) } - def concatSynth(in1: List, in2: List) = choose { - (out : List) => content(out) == content(in1) ++ content(in2) + def intersection(in1: List, in2: List) = choose { + (out: List) => inv(in1) && inv(in2) && (content(out) == (content(in1) & content(in2))) && inv(out) } - - def mergeSynth(in1: List, in2: List) = choose { - (out : List) => isSorted(in1) && isSorted(in2) && (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - - def mergeStrictSynth(in1: List, in2: List) = choose { - (out : List) => isStrictSorted(in1) && isStrictSorted(in2) && (content(out) == content(in1) ++ content(in2)) && isStrictSorted(out) - } - } diff --git a/testcases/synthesis/cav2013/SortedList.scala b/testcases/synthesis/cav2013/SortedList.scala new file mode 100644 index 0000000000000000000000000000000000000000..e07619bffef057b2b203855819a029cf61dc4318 --- /dev/null +++ b/testcases/synthesis/cav2013/SortedList.scala @@ -0,0 +1,45 @@ +import scala.collection.immutable.Set +import leon.Annotations._ +import leon.Utils._ + +object SortedList { + sealed abstract class List + case class Cons(head: Int, tail: List) extends List + case class Nil() extends List + + def isSorted(l: List): Boolean = l match { + case Nil() => true + case Cons(x, Nil()) => true + case Cons(x, Cons(y, ys)) => x <= y && isSorted(Cons(y, ys)) + } + + def inv(l: List): Boolean = isSorted(l) + + def size(l: List) : Int = (l match { + case Nil() => 0 + case Cons(_, t) => 1 + size(t) + }) ensuring(res => res >= 0) + + def content(l: List): Set[Int] = l match { + case Nil() => Set.empty[Int] + case Cons(i, t) => Set(i) ++ content(t) + } + + // To Synthesize: + + def insert(in: List, v: Int) = choose { + (out: List) => inv(in) && (content(out) == (content(in) ++ Set(v))) && inv(out) + } + + def delete(in: List, v: Int) = choose { + (out: List) => inv(in) && (content(out) == (content(in) -- Set(v))) && inv(out) + } + + def union(in1: List, in2: List) = choose { + (out: List) => inv(in1) && inv(in2) && (content(out) == (content(in1) ++ content(in2))) && inv(out) + } + + def intersection(in1: List, in2: List) = choose { + (out: List) => inv(in1) && inv(in2) && (content(out) == (content(in1) & content(in2))) && inv(out) + } +} diff --git a/testcases/synthesis/cav2013/StrictlySortedList.scala b/testcases/synthesis/cav2013/StrictlySortedList.scala new file mode 100644 index 0000000000000000000000000000000000000000..9570df701bd4578b9e2d4db807adc47546b10314 --- /dev/null +++ b/testcases/synthesis/cav2013/StrictlySortedList.scala @@ -0,0 +1,47 @@ +import scala.collection.immutable.Set +import leon.Annotations._ +import leon.Utils._ + +object SortedList { + sealed abstract class List + case class Cons(head: Int, tail: List) extends List + case class Nil() extends List + + def isStrictSorted(l: List): Boolean = l match { + case Nil() => true + case Cons(x, Nil()) => true + case Cons(x, Cons(y, ys)) => x < y && isStrictSorted(Cons(y, ys)) + } + + def inv(l: List): Boolean = isStrictSorted(l) + + def size(l: List) : Int = (l match { + case Nil() => 0 + case Cons(_, t) => 1 + size(t) + }) ensuring(res => res >= 0) + + def content(l: List): Set[Int] = l match { + case Nil() => Set.empty[Int] + case Cons(i, t) => Set(i) ++ content(t) + } + + + // To Synthesize: + + + def insert(in: List, v: Int) = choose { + (out: List) => inv(in) && (content(out) == (content(in) ++ Set(v))) && inv(out) + } + + def delete(in: List, v: Int) = choose { + (out: List) => inv(in) && (content(out) == (content(in) -- Set(v))) && inv(out) + } + + def union(in1: List, in2: List) = choose { + (out: List) => inv(in1) && inv(in2) && (content(out) == (content(in1) ++ content(in2))) && inv(out) + } + + def intersection(in1: List, in2: List) = choose { + (out: List) => inv(in1) && inv(in2) && (content(out) == (content(in1) & content(in2))) && inv(out) + } +}