diff --git a/examples/game2048/build.sbt b/examples/game2048/build.sbt deleted file mode 100644 index e46f51ebeb9542b51e7a327a06b9209a32e1946d..0000000000000000000000000000000000000000 --- a/examples/game2048/build.sbt +++ /dev/null @@ -1,9 +0,0 @@ -enablePlugins(ScalaJSPlugin) - -name := "Leon-2048" - -scalaVersion := "2.11.7" - -libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.0" - -unmanagedSourceDirectories in Compile += (baseDirectory / "../../library/leon/").value diff --git a/examples/game2048/index.html b/examples/game2048/index.html deleted file mode 100644 index 09205fc5f8461884d420ddb55e437767e300f2ef..0000000000000000000000000000000000000000 --- a/examples/game2048/index.html +++ /dev/null @@ -1,17 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="UTF-8"> - <title>The Scala.js Tutorial</title> - </head> - <body> - <canvas id="leon-canvas" width="800" height="800"></canvas> - <!-- Include Scala.js compiled code --> - <script type="text/javascript" src="./target/scala-2.11/leon-2048-fastopt.js"></script> - <!-- Run tutorial.webapp.TutorialApp --> - <script type="text/javascript"> - var c = document.getElementById("leon-canvas"); - leon.game2048.Main().main(c); - </script> - </body> -</html> diff --git a/examples/game2048/project/plugins.sbt b/examples/game2048/project/plugins.sbt deleted file mode 100644 index 40d2df20be6c943f58365f612b351b276a4ae65f..0000000000000000000000000000000000000000 --- a/examples/game2048/project/plugins.sbt +++ /dev/null @@ -1 +0,0 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.9") diff --git a/examples/game2048/src/main/scala/leon/game2048/Game2048.scala b/examples/game2048/src/main/scala/leon/game2048/Game2048.scala deleted file mode 100644 index d59e7929f7206fa8c2538c353a5cfba3138eccde..0000000000000000000000000000000000000000 --- a/examples/game2048/src/main/scala/leon/game2048/Game2048.scala +++ /dev/null @@ -1,418 +0,0 @@ -package leon.game2048 - -import leon.lang._ -import leon.lang.Bag -import leon.annotation._ -import leon.lang.StaticChecks._ - -import leon.util.Random - -object Game2048 { - - case class Cell(var n: Option[BigInt]) { - require(n.forall(v => v >= 0)) - - def points: BigInt = n.getOrElse(0) - - def containsPoints: Boolean = n.nonEmpty - def isEmpty: Boolean = n.isEmpty - - def canMerge(that: Cell): Boolean = that.n.nonEmpty && that.n == this.n - - def emptyAsInt: BigInt = if(n.isEmpty) 1 else 0 - - def contentAsBag: Bag[BigInt] = n match { - case None() => Bag.empty[BigInt] - case Some(m) => Bag(m -> BigInt(1)) - } - def content: Set[BigInt] = n match { - case None() => Set.empty[BigInt] - case Some(m) => Set(m) - } - } - - case class LevelMap( - c11: Cell, c12: Cell, c13: Cell, c14: Cell, - c21: Cell, c22: Cell, c23: Cell, c24: Cell, - c31: Cell, c32: Cell, c33: Cell, c34: Cell, - c41: Cell, c42: Cell, c43: Cell, c44: Cell - ) { - - def content: Set[BigInt] = c11.content ++ c12.content ++ c13.content ++ c14.content ++ - c21.content ++ c22.content ++ c23.content ++ c24.content ++ - c31.content ++ c32.content ++ c33.content ++ c34.content ++ - c41.content ++ c42.content ++ c43.content ++ c44.content - - def contentAsBag: Bag[BigInt] = c11.contentAsBag ++ c12.contentAsBag ++ c13.contentAsBag ++ c14.contentAsBag ++ - c21.contentAsBag ++ c22.contentAsBag ++ c23.contentAsBag ++ c24.contentAsBag ++ - c31.contentAsBag ++ c32.contentAsBag ++ c33.contentAsBag ++ c34.contentAsBag ++ - c41.contentAsBag ++ c42.contentAsBag ++ c43.contentAsBag ++ c44.contentAsBag - - def totalPoints: BigInt = - c11.points + c12.points + c13.points + c14.points + - c21.points + c22.points + c23.points + c24.points + - c31.points + c32.points + c33.points + c34.points + - c41.points + c42.points + c43.points + c44.points - - def existsEmptyCell: Boolean = c11.isEmpty || c12.isEmpty || c13.isEmpty || c14.isEmpty || - c21.isEmpty || c22.isEmpty || c23.isEmpty || c24.isEmpty || - c31.isEmpty || c32.isEmpty || c33.isEmpty || c34.isEmpty || - c41.isEmpty || c42.isEmpty || c43.isEmpty || c44.isEmpty - - def nbEmptyCells: BigInt = c11.emptyAsInt + c12.emptyAsInt + c13.emptyAsInt + c14.emptyAsInt + - c21.emptyAsInt + c22.emptyAsInt + c23.emptyAsInt + c24.emptyAsInt + - c31.emptyAsInt + c32.emptyAsInt + c33.emptyAsInt + c34.emptyAsInt + - c41.emptyAsInt + c42.emptyAsInt + c43.emptyAsInt + c44.emptyAsInt - - - //def canMove: Boolean = nbEmptyCells > 0 || - - def nthFree(n: BigInt): BigInt = { - require(n < nbEmptyCells) - var toSkip = n - var res: BigInt = -1 - - if(c11.isEmpty && toSkip == 0 && res == -1) { - res = 0 - } else if(c11.isEmpty) { - toSkip -= 1 - } - - if(c12.isEmpty && toSkip == 0 && res == -1) { - res = 1 - } else if(c12.isEmpty) { - toSkip -= 1 - } - - if(c13.isEmpty && toSkip == 0 && res == -1) { - res = 2 - } else if(c13.isEmpty) { - toSkip -= 1 - } - - if(c14.isEmpty && toSkip == 0 && res == -1) { - res = 3 - } else if(c14.isEmpty) { - toSkip -= 1 - } - - if(c21.isEmpty && toSkip == 0 && res == -1) { - res = 4 - } else if(c21.isEmpty) { - toSkip -= 1 - } - - if(c22.isEmpty && toSkip == 0 && res == -1) { - res = 5 - } else if(c22.isEmpty) { - toSkip -= 1 - } - - if(c23.isEmpty && toSkip == 0 && res == -1) { - res = 6 - } else if(c23.isEmpty) { - toSkip -= 1 - } - - if(c24.isEmpty && toSkip == 0 && res == -1) { - res = 7 - } else if(c24.isEmpty) { - toSkip -= 1 - } - - if(c31.isEmpty && toSkip == 0 && res == -1) { - res = 8 - } else if(c31.isEmpty) { - toSkip -= 1 - } - - if(c32.isEmpty && toSkip == 0 && res == -1) { - res = 9 - } else if(c32.isEmpty) { - toSkip -= 1 - } - - if(c33.isEmpty && toSkip == 0 && res == -1) { - res = 10 - } else if(c33.isEmpty) { - toSkip -= 1 - } - - if(c34.isEmpty && toSkip == 0 && res == -1) { - res = 11 - } else if(c34.isEmpty) { - toSkip -= 1 - } - - if(c41.isEmpty && toSkip == 0 && res == -1) { - res = 12 - } else if(c41.isEmpty) { - toSkip -= 1 - } - - if(c42.isEmpty && toSkip == 0 && res == -1) { - res = 13 - } else if(c42.isEmpty) { - toSkip -= 1 - } - - if(c43.isEmpty && toSkip == 0 && res == -1) { - res = 14 - } else if(c43.isEmpty) { - toSkip -= 1 - } - - if(c44.isEmpty && toSkip == 0 && res == -1) { - res = 15 - } else if(c44.isEmpty) { - toSkip -= 1 - } - - res - } ensuring(res => res >= n && res < 16) - - @ignore - def cells: Vector[Cell] = Vector(c11, c12, c13, c14, - c21, c22, c23, c24, - c31, c32, c33, c34, - c41, c42, c43, c44) - } - - - /* check that there are no holes in the middle of a row */ - def noHoles(c1: Cell, c2: Cell, c3: Cell, c4: Cell): Boolean = { - if(c1.isEmpty) c2.isEmpty && c3.isEmpty && c4.isEmpty - else if(c2.isEmpty) c3.isEmpty && c4.isEmpty - else if(c3.isEmpty) c4.isEmpty - else true - } - def noMergesOpportunities(c1: Cell, c2: Cell, c3: Cell, c4: Cell): Boolean = { - !c1.canMerge(c2) && !c2.canMerge(c3) && !c3.canMerge(c4) - } - - //slide everything to the left, filling empty spaces - def slideLeft(c1: Cell, c2: Cell, c3: Cell, c4: Cell): Unit = { - if(c3.isEmpty) { - c3.n = c4.n - c4.n = None() - } - if(c2.isEmpty) { - c2.n = c3.n - c3.n = c4.n - c4.n = None() - } - if(c1.isEmpty) { - c1.n = c2.n - c2.n = c3.n - c3.n = c4.n - c4.n = None() - } - } ensuring(_ => - c1.points + c2.points + c3.points + c4.points == old(c1).points + old(c2).points + old(c3).points + old(c4).points && - noHoles(c1, c2, c3, c4) - ) - - - //perform a left slide of the 4 cells. This can be used for any - //4 celles in any direction, as long as the 4 cells are passed - //in a coherent order to slideLeft. Merge any required cells - //together - def mergeLeft(c1: Cell, c2: Cell, c3: Cell, c4: Cell): Unit = { - slideLeft(c1, c2, c3, c4) - if(c3.canMerge(c4)) { - merge(c4, c3) - } - if(c2.canMerge(c3)) { - merge(c3, c2) - } - if(c1.canMerge(c2)) { - merge(c2, c1) - } - slideLeft(c1, c2, c3, c4) - } ensuring(_ => - c1.points + c2.points + c3.points + c4.points == old(c1).points + old(c2).points + old(c3).points + old(c4).points && - noHoles(c1, c2, c3, c4) - //noMergesOpportunities(c1, c2, c3, c4) - ) - - /* check that a left move makes sense (either a hole to fill or a merge opportunity) */ - def canSlideLeft(c1: Cell, c2: Cell, c3: Cell, c4: Cell): Boolean = { - !noHoles(c1, c2, c3, c4) || c1.canMerge(c2) || c2.canMerge(c3) || c3.canMerge(c4) - } - def canMoveLeft(map: LevelMap): Boolean = { - canSlideLeft(map.c11, map.c12, map.c13, map.c14) || - canSlideLeft(map.c21, map.c22, map.c23, map.c24) || - canSlideLeft(map.c31, map.c32, map.c33, map.c34) || - canSlideLeft(map.c41, map.c42, map.c43, map.c44) - } - def canMoveUp(map: LevelMap): Boolean = { - canSlideLeft(map.c11, map.c21, map.c31, map.c41) || - canSlideLeft(map.c12, map.c22, map.c32, map.c42) || - canSlideLeft(map.c13, map.c23, map.c33, map.c43) || - canSlideLeft(map.c14, map.c24, map.c34, map.c44) - } - def canMoveRight(map: LevelMap): Boolean = { - canSlideLeft(map.c14, map.c13, map.c12, map.c11) || - canSlideLeft(map.c24, map.c23, map.c22, map.c21) || - canSlideLeft(map.c34, map.c33, map.c32, map.c31) || - canSlideLeft(map.c44, map.c43, map.c42, map.c41) - } - def canMoveDown(map: LevelMap): Boolean = { - canSlideLeft(map.c41, map.c31, map.c21, map.c11) || - canSlideLeft(map.c42, map.c32, map.c22, map.c12) || - canSlideLeft(map.c43, map.c33, map.c23, map.c13) || - canSlideLeft(map.c44, map.c34, map.c24, map.c14) - } - - //this only merges once, not recursively, thus disprove the final noMergesOpportunities postcondition - //def mergeLeftNoRecursive(c1: Cell, c2: Cell, c3: Cell, c4: Cell): Unit = { - // slideLeft(c1, c2, c3, c4) - // if(c3.canMerge(c4)) { - // merge(c4, c3) - // } - // if(c2.canMerge(c3)) { - // merge(c3, c2) - // } - // if(c1.canMerge(c2)) { - // merge(c2, c1) - // } - // slideLeft(c1, c2, c3, c4) - //} ensuring(_ => - // c1.points + c2.points + c3.points + c4.points == old(c1).points + old(c2).points + old(c3).points + old(c4).points && - // noHoles(c1, c2, c3, c4) && - // noMergesOpportunities(c1, c2, c3, c4) - //) - - def moveLeft(map: LevelMap): Unit = { - require(canMoveLeft(map)) - mergeLeft(map.c11, map.c12, map.c13, map.c14) - mergeLeft(map.c21, map.c22, map.c23, map.c24) - mergeLeft(map.c31, map.c32, map.c33, map.c34) - mergeLeft(map.c41, map.c42, map.c43, map.c44) - } ensuring(_ => - map.totalPoints == old(map).totalPoints && - noHoles(map.c11, map.c12, map.c13, map.c14) && - noHoles(map.c21, map.c22, map.c23, map.c24) && - noHoles(map.c31, map.c32, map.c33, map.c34) && - noHoles(map.c41, map.c42, map.c43, map.c44) - ) - - def moveUp(map: LevelMap): Unit = { - require(canMoveUp(map)) - mergeLeft(map.c11, map.c21, map.c31, map.c41) - mergeLeft(map.c12, map.c22, map.c32, map.c42) - mergeLeft(map.c13, map.c23, map.c33, map.c43) - mergeLeft(map.c14, map.c24, map.c34, map.c44) - } ensuring(_ => - map.totalPoints == old(map).totalPoints && - noHoles(map.c11, map.c21, map.c31, map.c41) && - noHoles(map.c12, map.c22, map.c32, map.c42) && - noHoles(map.c13, map.c23, map.c33, map.c43) && - noHoles(map.c14, map.c24, map.c34, map.c44) - ) - - - def moveRight(map: LevelMap): Unit = { - require(canMoveRight(map)) - mergeLeft(map.c14, map.c13, map.c12, map.c11) - mergeLeft(map.c24, map.c23, map.c22, map.c21) - mergeLeft(map.c34, map.c33, map.c32, map.c31) - mergeLeft(map.c44, map.c43, map.c42, map.c41) - } ensuring(_ => - map.totalPoints == old(map).totalPoints && - noHoles(map.c14, map.c13, map.c12, map.c11) && - noHoles(map.c24, map.c23, map.c22, map.c21) && - noHoles(map.c34, map.c33, map.c32, map.c31) && - noHoles(map.c44, map.c43, map.c42, map.c41) - ) - - def moveDown(map: LevelMap): Unit = { - require(canMoveDown(map)) - mergeLeft(map.c41, map.c31, map.c21, map.c11) - mergeLeft(map.c42, map.c32, map.c22, map.c12) - mergeLeft(map.c43, map.c33, map.c23, map.c13) - mergeLeft(map.c44, map.c34, map.c24, map.c14) - } ensuring(_ => - map.totalPoints == old(map).totalPoints && - noHoles(map.c41, map.c31, map.c21, map.c11) && - noHoles(map.c42, map.c32, map.c22, map.c12) && - noHoles(map.c43, map.c33, map.c23, map.c13) && - noHoles(map.c44, map.c34, map.c24, map.c14) - ) - - - /* - * merge `that` into `into`, clearing `that` and setting `into` to - * the right value. - */ - def merge(that: Cell, into: Cell): Unit = { - require(that.n.nonEmpty && that.n == into.n) - val tmp = that.n.get - that.n = None() - into.n = Some(into.n.get + tmp) - } ensuring(_ => into.points + that.points == old(into).points + old(that).points) - - - - def setRandomCell(map: LevelMap, v: BigInt)(implicit state: Random.State): Unit = { - require(map.existsEmptyCell && (v == 2 || v == 4)) - - val nbEmptyCells = map.nbEmptyCells - val randomIndex = leon.util.Random.nextBigInt(nbEmptyCells) - val realIndex = map.nthFree(randomIndex) - - if(realIndex == 0) { - assert(map.c11.isEmpty) - map.c11.n = Some(v) - } else if(realIndex == 1) { - map.c12.n = Some(v) - } else if(realIndex == 2) { - map.c13.n = Some(v) - } else if(realIndex == 3) { - map.c14.n = Some(v) - } else if(realIndex == 4) { - map.c21.n = Some(v) - } else if(realIndex == 5) { - map.c22.n = Some(v) - } else if(realIndex == 6) { - map.c23.n = Some(v) - } else if(realIndex == 7) { - map.c24.n = Some(v) - } else if(realIndex == 8) { - assert(map.c31.isEmpty) - map.c31.n = Some(v) - } else if(realIndex == 9) { - assert(map.c32.isEmpty) - map.c32.n = Some(v) - } else if(realIndex == 10) { - assert(map.c33.isEmpty) - map.c33.n = Some(v) - } else if(realIndex == 11) { - assert(map.c34.isEmpty) - map.c34.n = Some(v) - } else if(realIndex == 12) { - assert(map.c41.isEmpty) - map.c41.n = Some(v) - } else if(realIndex == 13) { - assert(map.c42.isEmpty) - map.c42.n = Some(v) - } else if(realIndex == 14) { - map.c43.n = Some(v) - } else if(realIndex == 15) { - map.c44.n = Some(v) - } - - } ensuring(_ => { - map.nbEmptyCells == old(map).nbEmptyCells - 1 && - map.totalPoints == old(map).totalPoints + v && - map.content == old(map).content + v - }) - - - def popNumber(m: LevelMap)(implicit state: Random.State): Unit = { - require(m.existsEmptyCell) - val value: BigInt = 2*(1+leon.util.Random.nextBigInt(2)) - setRandomCell(m, value) - } - -} diff --git a/examples/game2048/src/main/scala/leon/game2048/Main.scala b/examples/game2048/src/main/scala/leon/game2048/Main.scala deleted file mode 100644 index 9618f52e4c7d1fd3fab1711ea07cb89681f70ac5..0000000000000000000000000000000000000000 --- a/examples/game2048/src/main/scala/leon/game2048/Main.scala +++ /dev/null @@ -1,157 +0,0 @@ -package leon.game2048 - -import scala.scalajs.js.JSApp -import scala.scalajs.js.annotation.JSExport - -import org.scalajs.dom -import dom.document -import dom.html - -import leon.lang._ -import leon.util.Random -import leon.lang.StaticChecks._ - -@JSExport -object Main { - - import Game2048._ - - type Ctx2D = dom.CanvasRenderingContext2D - - val CellWidth = 200 - val CellHeight = 200 - - - @JSExport - def main(c: html.Canvas): Unit = { - implicit val randomState = Random.newState - println("Hello world!") - - val m = LevelMap(Cell(None()), Cell(None()), Cell(None()), Cell(None()), - Cell(None()), Cell(None()), Cell(None()), Cell(None()), - Cell(None()), Cell(None()), Cell(None()), Cell(None()), - Cell(None()), Cell(None()), Cell(None()), Cell(None())) - - m.c22.n = Some(2) - m.c34.n = Some(4) - renderGame(m)(c) - - document.onkeyup = (e: dom.KeyboardEvent) => { - if(e.keyCode == 37) { - println("left click") - if(canMoveLeft(m)) { - moveLeft(m) - popNumber(m) - renderGame(m)(c) - } - } else if(e.keyCode == 38) { - println("up click") - if(canMoveUp(m)) { - moveUp(m) - popNumber(m) - renderGame(m)(c) - } - } else if(e.keyCode == 39) { - println("right click") - if(canMoveRight(m)) { - moveRight(m) - popNumber(m) - renderGame(m)(c) - } - } else if(e.keyCode == 40) { - println("down click") - if(canMoveDown(m)) { - moveDown(m) - popNumber(m) - renderGame(m)(c) - } - } - } - - } - - def renderGame(map: LevelMap)(c: html.Canvas): Unit = { - val ctx = c.getContext("2d").asInstanceOf[Ctx2D] - - ctx.clearRect(0, 0, 800, 800) - - var x = 0 - var y = 0 - - renderCell(map.c11, x, y)(ctx) - x += CellWidth - renderCell(map.c12, x, y)(ctx) - x += CellWidth - renderCell(map.c13, x, y)(ctx) - x += CellWidth - renderCell(map.c14, x, y)(ctx) - x = 0 - y += CellHeight - - renderCell(map.c21, x, y)(ctx) - x += CellWidth - renderCell(map.c22, x, y)(ctx) - x += CellWidth - renderCell(map.c23, x, y)(ctx) - x += CellWidth - renderCell(map.c24, x, y)(ctx) - x = 0 - y += CellHeight - - renderCell(map.c31, x, y)(ctx) - x += CellWidth - renderCell(map.c32, x, y)(ctx) - x += CellWidth - renderCell(map.c33, x, y)(ctx) - x += CellWidth - renderCell(map.c34, x, y)(ctx) - x = 0 - y += CellHeight - - renderCell(map.c41, x, y)(ctx) - x += CellWidth - renderCell(map.c42, x, y)(ctx) - x += CellWidth - renderCell(map.c43, x, y)(ctx) - x += CellWidth - renderCell(map.c44, x, y)(ctx) - x = 0 - y += CellHeight - - ctx.stroke() - - } - - def renderCell(c: Game2048.Cell, x: Int, y: Int)(ctx: Ctx2D): Unit = { - ctx.strokeStyle = "black" - ctx.lineWidth = 6 - ctx.rect(x, y, CellWidth, CellHeight) - - ctx.font = "120px Georgia" - val cx = (2*x + CellWidth)/2 - 30 - val cy = (2*y + CellHeight)/2 + 40 - ctx.fillText(c.n.map(_.toString).getOrElse(""), cx, cy) - } - - - /* - * TODO: those should be part of the verified core - * One issue is that the code is using aliasing to return the random cell.. - */ - - //def popNumber(m: LevelMap): Unit = { - // val cell = randomEmptyCell(m) - // println("poping number on cell: " + cell) - // cell.n = Some(2*(1+scala.util.Random.nextInt(2))) - //} - - //def randomEmptyCell(m: LevelMap): Cell = { - // val emptyCells: Vector[Cell] = m.cells.filter(_.isEmpty) - // println("empty cells: " + emptyCells) - // val countEmpty = emptyCells.size - // val randomIndex = scala.util.Random.nextInt(countEmpty) - // println("random index: " + randomIndex) - // emptyCells(randomIndex) - //} - -} diff --git a/examples/gametictactoe/build.sbt b/examples/gametictactoe/build.sbt deleted file mode 100644 index 04fc590e7daf7d1673fe1f9234802a566a26cdd3..0000000000000000000000000000000000000000 --- a/examples/gametictactoe/build.sbt +++ /dev/null @@ -1,9 +0,0 @@ -enablePlugins(ScalaJSPlugin) - -name := "Leon-TicTacToe" - -scalaVersion := "2.11.7" - -libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.0" - -unmanagedSourceDirectories in Compile += (baseDirectory / "../../library/leon/").value diff --git a/examples/gametictactoe/index.html b/examples/gametictactoe/index.html deleted file mode 100644 index e84dd4a4ce3313713310be97ba0c635d249382e3..0000000000000000000000000000000000000000 --- a/examples/gametictactoe/index.html +++ /dev/null @@ -1,17 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="UTF-8"> - <title>Leon verified Tic-Tac-Toe</title> - </head> - <body> - <canvas id="leon-canvas" width="900" height="900"></canvas> - <!-- Include Scala.js compiled code --> - <script type="text/javascript" src="./target/scala-2.11/leon-tictactoe-fastopt.js"></script> - <!-- Run tutorial.webapp.TutorialApp --> - <script type="text/javascript"> - var c = document.getElementById("leon-canvas"); - leon.gametictactoe.Main().main(c); - </script> - </body> -</html> diff --git a/examples/gametictactoe/project/plugins.sbt b/examples/gametictactoe/project/plugins.sbt deleted file mode 100644 index 40d2df20be6c943f58365f612b351b276a4ae65f..0000000000000000000000000000000000000000 --- a/examples/gametictactoe/project/plugins.sbt +++ /dev/null @@ -1 +0,0 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.9") diff --git a/examples/gametictactoe/src/main/scala/leon/gametictactoe/GameTicTacToe.scala b/examples/gametictactoe/src/main/scala/leon/gametictactoe/GameTicTacToe.scala deleted file mode 100644 index cb216836e307eb4d4860ee0175be4887172f790f..0000000000000000000000000000000000000000 --- a/examples/gametictactoe/src/main/scala/leon/gametictactoe/GameTicTacToe.scala +++ /dev/null @@ -1,126 +0,0 @@ -package leon.gametictactoe - -import leon.lang._ -import leon.lang.Bag -import leon.annotation._ -import leon.lang.StaticChecks._ - -import leon.util.Random - -object GameTicTacToe { - - abstract class Player { - def isCross: Boolean = this == PlayerCross - def isCircle: Boolean = this == PlayerCircle - - def opponent: Player = this match { - case PlayerCross => PlayerCircle - case PlayerCircle => PlayerCross - } - } - case object PlayerCross extends Player - case object PlayerCircle extends Player - - case class Cell(var n: Option[Player]) { - - def crossAsInt: BigInt = n match { - case Some(PlayerCross) => 1 - case _ => 0 - } - - def emptyAsInt: BigInt = if(n.isEmpty) 1 else 0 - - def containsEntry: Boolean = n.nonEmpty - def isEmpty: Boolean = n.isEmpty - - def matches(that: Cell): Boolean = this.containsEntry && this.n == that.n - - } - - case class LevelMap( - c11: Cell, c12: Cell, c13: Cell, - c21: Cell, c22: Cell, c23: Cell, - c31: Cell, c32: Cell, c33: Cell - ) { - require(totalEntries == totalXEntries + totalOEntries && invariantXAtMostOneMore) - - def invariantXAtMostOneMore: Boolean = - (totalXEntries == totalOEntries+1 || totalXEntries == totalOEntries) - - def totalEntries: BigInt = 9 - nbEmptyCells - - def totalXEntries: BigInt = - c11.crossAsInt + c12.crossAsInt + c13.crossAsInt + - c21.crossAsInt + c22.crossAsInt + c23.crossAsInt + - c31.crossAsInt + c32.crossAsInt + c33.crossAsInt - - def totalOEntries: BigInt = totalEntries - totalXEntries - - def existsEmptyCell: Boolean = c11.isEmpty || c12.isEmpty || c13.isEmpty || - c21.isEmpty || c22.isEmpty || c23.isEmpty || - c31.isEmpty || c32.isEmpty || c33.isEmpty - - def nbEmptyCells: BigInt = c11.emptyAsInt + c12.emptyAsInt + c13.emptyAsInt + - c21.emptyAsInt + c22.emptyAsInt + c23.emptyAsInt + - c31.emptyAsInt + c32.emptyAsInt + c33.emptyAsInt - - def fill(j: BigInt, i: BigInt, player: Player): Unit = { - require(canPlay(player) && canFill(j, i, player)) - if (j == 1 && i == 1) c11.n = Some(player) - else if(j == 1 && i == 2) c12.n = Some(player) - else if(j == 1 && i == 3) c13.n = Some(player) - else if(j == 2 && i == 1) c21.n = Some(player) - else if(j == 2 && i == 2) c22.n = Some(player) - else if(j == 2 && i == 3) c23.n = Some(player) - else if(j == 3 && i == 1) c31.n = Some(player) - else if(j == 3 && i == 2) c32.n = Some(player) - else if(j == 3 && i == 3) c33.n = Some(player) - else () - } - - def canFill(j: BigInt, i: BigInt, player: Player): Boolean = canPlay(player) && isFree(j, i) - - def isFree(j: BigInt, i: BigInt): Boolean = - if (j == 1 && i == 1) c11.isEmpty - else if(j == 1 && i == 2) c12.isEmpty - else if(j == 1 && i == 3) c13.isEmpty - else if(j == 2 && i == 1) c21.isEmpty - else if(j == 2 && i == 2) c22.isEmpty - else if(j == 2 && i == 3) c23.isEmpty - else if(j == 3 && i == 1) c31.isEmpty - else if(j == 3 && i == 2) c32.isEmpty - else if(j == 3 && i == 3) c33.isEmpty - else false - - def canPlay(player: Player): Boolean = player match { - case PlayerCross => totalXEntries == totalOEntries - case PlayerCircle => totalXEntries == totalOEntries + 1 - } - - } - - case class Game(map: LevelMap, var currentPlayer: Player) { - //require(map.canPlay(currentPlayer)) - - - def doPlay(j: BigInt, i: BigInt): Unit = { - require(map.canFill(j, i, currentPlayer) ) - map.fill(j, i, currentPlayer) - currentPlayer = currentPlayer.opponent - } ensuring(_ => map.canPlay(currentPlayer)) - - } - - def checkGameEnded(map: LevelMap): Boolean = { - val r1 = map.c11.matches(map.c12) && map.c12.matches(map.c13) - val r2 = map.c21.matches(map.c22) && map.c22.matches(map.c23) - val r3 = map.c31.matches(map.c32) && map.c32.matches(map.c33) - val c1 = map.c11.matches(map.c21) && map.c21.matches(map.c31) - val c2 = map.c12.matches(map.c22) && map.c22.matches(map.c32) - val c3 = map.c13.matches(map.c23) && map.c23.matches(map.c33) - val d1 = map.c11.matches(map.c22) && map.c22.matches(map.c33) - val d2 = map.c31.matches(map.c22) && map.c22.matches(map.c13) - r1 || r2 || r3 || c1 || c2 || c3 || d1 || d2 - } - -} diff --git a/examples/gametictactoe/src/main/scala/leon/gametictactoe/Main.scala b/examples/gametictactoe/src/main/scala/leon/gametictactoe/Main.scala deleted file mode 100644 index 31f9ba8b71c36431fcc13607115accd5744e9a9f..0000000000000000000000000000000000000000 --- a/examples/gametictactoe/src/main/scala/leon/gametictactoe/Main.scala +++ /dev/null @@ -1,143 +0,0 @@ -package leon.gametictactoe - -import scala.scalajs.js.JSApp -import scala.scalajs.js.annotation.JSExport - -import org.scalajs.dom -import dom.document -import dom.html - -import leon.lang._ -import leon.util.Random -import leon.lang.StaticChecks._ - -@JSExport -object Main { - - import GameTicTacToe._ - - type Ctx2D = dom.CanvasRenderingContext2D - - val CellWidth = 300 - val CellHeight = 300 - - - @JSExport - def main(c: html.Canvas): Unit = { - implicit val randomState = Random.newState - println("Welcome to Tic Tac Toe!") - - val game = Game( - LevelMap(Cell(None()), Cell(None()), Cell(None()), - Cell(None()), Cell(None()), Cell(None()), - Cell(None()), Cell(None()), Cell(None())), - PlayerCross) - - renderGame(game.map, "Start game with X")(c) - - // Mouse click for tictactoe - c.onmousedown = { - (e: dom.MouseEvent) => - (1 to 3).foreach { i => - (1 to 3).foreach { j => - if((e.clientX <= i * CellWidth) && (e.clientX > (i - 1) * CellWidth) && (e.clientY <= j * CellHeight) && (e.clientY > (j - 1) * CellHeight)) { - println(s"at $i, $j") - if(game.map.isFree(j, i)) { - val player = game.currentPlayer - game.doPlay(j, i) - if(player.isCross) { - println("placing cross") - if(checkGameEnded(game.map)) { - renderGameOver("X")(c) - } else { - renderGame(game.map, "O's turn")(c) - } - } else { - println("placing circle") - if(checkGameEnded(game.map)) { - renderGameOver("O")(c) - } else { - renderGame(game.map, "X's turn")(c) - } - } - } - } - } - } - - } - } - - def renderGame(map: LevelMap, msg: String)(c: html.Canvas): Unit = { - val ctx = c.getContext("2d").asInstanceOf[Ctx2D] - - ctx.clearRect(0, 0, 900, 900) - - var x = 0 - var y = 0 - - renderCell(map.c11, x, y)(ctx) - x += CellWidth - renderCell(map.c12, x, y)(ctx) - x += CellWidth - renderCell(map.c13, x, y)(ctx) - x = 0 - y += CellHeight - - renderCell(map.c21, x, y)(ctx) - x += CellWidth - renderCell(map.c22, x, y)(ctx) - x += CellWidth - renderCell(map.c23, x, y)(ctx) - x = 0 - y += CellHeight - - renderCell(map.c31, x, y)(ctx) - x += CellWidth - renderCell(map.c32, x, y)(ctx) - x += CellWidth - renderCell(map.c33, x, y)(ctx) - x = 0 - y += CellHeight - - ctx.stroke() - - ctx.font = "20px Georgia" - y -= 7 - x += 3 - ctx.fillText(msg, x, y) - ctx.stroke() - } - - def renderGameOver(player: String)(c: html.Canvas): Unit = { - val ctx = c.getContext("2d").asInstanceOf[Ctx2D] - - ctx.clearRect(0, 0, 900, 900) - - var x = 0 - var y = CellHeight - - ctx.strokeStyle = "black" - ctx.font = "40px Georgia" - - ctx.fillText(s"GAME OVER, $player wins!\nRefresh to restart!", x, y) - ctx.stroke() - } - - def renderCell(c: GameTicTacToe.Cell, x: Int, y: Int)(ctx: Ctx2D): Unit = { - ctx.strokeStyle = "black" - ctx.lineWidth = 6 - ctx.rect(x, y, CellWidth, CellHeight) - - ctx.font = "120px Georgia" - val cx = (2*x + CellWidth)/2 - 30 - val cy = (2*y + CellHeight)/2 + 40 - val elem = c.n match { - case Some(PlayerCross) => "X" - case Some(PlayerCircle) => "O" - case None() => "" - } - ctx.fillText(elem, cx, cy) - } - -} diff --git a/library/leon/annotation/isabelle.scala b/library/leon/annotation/isabelle.scala deleted file mode 100644 index db1c94cdc0bf0a0c4f8b57501bfa4a14a0173096..0000000000000000000000000000000000000000 --- a/library/leon/annotation/isabelle.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.annotation - -import scala.annotation.StaticAnnotation - -object isabelle { - - @ignore - class typ(name: String) extends StaticAnnotation - - @ignore - class constructor(name: String) extends StaticAnnotation - - @ignore - class function(term: String) extends StaticAnnotation - - @ignore - class script(name: String, source: String) extends StaticAnnotation - - @ignore - class proof(method: String, kind: String = "") extends StaticAnnotation - - @ignore - class fullBody() extends StaticAnnotation - - @ignore - class noBody() extends StaticAnnotation - - @ignore - class lemma(about: String) extends StaticAnnotation - -} diff --git a/library/leon/annotation/package.scala b/library/leon/annotation/package.scala deleted file mode 100644 index fc4012a94417075b0a742bd63b0cb3ce83fc3c02..0000000000000000000000000000000000000000 --- a/library/leon/annotation/package.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon - -import scala.annotation.StaticAnnotation - -package object annotation { - @ignore - class library extends StaticAnnotation - @ignore - class induct extends StaticAnnotation - @ignore - class traceInduct(name: String = "") extends StaticAnnotation - @ignore - class ignore extends StaticAnnotation - @ignore - class extern extends StaticAnnotation - @ignore - class inline extends StaticAnnotation - @ignore - class internal extends StaticAnnotation - - // Orb annotations - @ignore - class monotonic extends StaticAnnotation - @ignore - class compose extends StaticAnnotation - @ignore - class axiom extends StaticAnnotation - @ignore - class invstate extends StaticAnnotation - @ignore - class memoize extends StaticAnnotation - @ignore - class invisibleBody extends StaticAnnotation // do not unfold the body of the function - @ignore - class usePost extends StaticAnnotation // assume the post-condition while proving time bounds - @ignore - class unfoldFactor(f: Int=0) extends StaticAnnotation // 0 implies no bound on unfolding -} \ No newline at end of file diff --git a/library/leon/collection/List.scala b/library/leon/collection/List.scala deleted file mode 100644 index d25ab6413b016b650690622058c2440153f7664b..0000000000000000000000000000000000000000 --- a/library/leon/collection/List.scala +++ /dev/null @@ -1,927 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.collection - -import leon._ -import leon.lang._ -import leon.annotation._ -import leon.math._ -import leon.proof._ - -@library -@isabelle.typ(name = "List.list") -sealed abstract class List[T] { - - @isabelle.function(term = "Int.int o List.length") - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => 1 + t.size - }) ensuring (_ >= 0) - - def length = size - - @isabelle.function(term = "List.list.set") - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - @isabelle.function(term = "List.member") - def contains(v: T): Boolean = (this match { - case Cons(h, t) => h == v || t.contains(v) - case Nil() => false - }) ensuring { _ == (content contains v) } - - @isabelle.function(term = "List.append") - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => - (res.content == this.content ++ that.content) && - (res.size == this.size + that.size) && - (that != Nil[T]() || res == this) - } - - def head: T = { - require(this != Nil[T]()) - val Cons(h, _) = this - h - } - - def tail: List[T] = { - require(this != Nil[T]()) - val Cons(_, t) = this - t - } - - @isabelle.fullBody - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == BigInt(0)) { - head - } else { - tail(index-1) - } - } - - @isabelle.function(term = "%xs x. x # xs") - def ::(t:T): List[T] = Cons(t, this) - - @isabelle.function(term = "%xs x. xs @ [x]") - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - @isabelle.function(term = "List.rev") - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = { (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - if (i <= BigInt(0)) { - Nil[T]() - } else { - Cons(h, t.take(i-1)) - } - }} ensuring { res => - res.content.subsetOf(this.content) && (res.size == ( - if (i <= 0) BigInt(0) - else if (i >= this.size) this.size - else i - )) - } - - def drop(i: BigInt): List[T] = { (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - if (i <= BigInt(0)) { - Cons[T](h, t) - } else { - t.drop(i-1) - } - }} ensuring { res => - res.content.subsetOf(this.content) && (res.size == ( - if (i <= 0) this.size - else if (i >= this.size) BigInt(0) - else this.size - i - )) - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(0 <= from && from <= to && to <= size) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = { this match { - case Nil() => Nil[T]() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - }} ensuring { (res: List[T]) => - res.size == this.size && - res.content == ( - (this.content -- Set(from)) ++ - (if (this.content contains from) Set(to) else Set[T]()) - ) - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = { - require(s > 0 && s0 >= 0) - l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == BigInt(0)) { - chunk0(s, t, Cons(h, Nil()), res :+ acc, s-1) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - @isabelle.function(term = "List.zip") - def zip[B](that: List[B]): List[(T, B)] = { (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case _ => - Nil[(T, B)]() - }} ensuring { _.size == ( - if (this.size <= that.size) this.size else that.size - )} - - @isabelle.function(term = "%xs x. removeAll x xs") - def -(e: T): List[T] = { this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == this.content -- Set(e) - } - - def --(that: List[T]): List[T] = { this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == this.content -- that.content - } - - def &(that: List[T]): List[T] = { this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == (this.content & that.content) - } - - def padTo(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().padTo(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.padTo(s-1, e)) - }} ensuring { res => - if (s <= this.size) - res == this - else - res.size == s && - res.content == this.content ++ Set(e) - } - - def indexOf(elem: T): BigInt = { this match { - case Nil() => BigInt(-1) - case Cons(h, t) if h == elem => BigInt(0) - case Cons(h, t) => - val rec = t.indexOf(elem) - if (rec == BigInt(-1)) BigInt(-1) - else rec + 1 - }} ensuring { res => - (res >= 0) == content.contains(elem) - } - - def init: List[T] = { - require(!isEmpty) - (this : @unchecked) match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - } - } ensuring ( (r: List[T]) => - r.size == this.size - 1 && - r.content.subsetOf(this.content) - ) - - def last: T = { - require(!isEmpty) - (this : @unchecked) match { - case Cons(h, Nil()) => h - case Cons(_, t) => t.last - } - } ensuring { this.contains _ } - - def lastOption: Option[T] = { this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None[T]() - }} ensuring { _.isDefined != this.isEmpty } - - def headOption: Option[T] = { this match { - case Cons(h, t) => - Some(h) - case Nil() => - None[T]() - }} ensuring { _.isDefined != this.isEmpty } - - def tailOption: Option[List[T]] = { this match { - case Cons(h, t) => - Some(t) - case Nil() => - None[List[T]]() - }} ensuring { _.isDefined != this.isEmpty } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def splitAtIndex(index: BigInt) : (List[T], List[T]) = { this match { - case Nil() => (Nil[T](), Nil[T]()) - case Cons(h, rest) => { - if (index <= BigInt(0)) { - (Nil[T](), this) - } else { - val (left,right) = rest.splitAtIndex(index - 1) - (Cons[T](h,left), right) - } - } - }} ensuring { (res:(List[T],List[T])) => - res._1 ++ res._2 == this && - res._1 == take(index) && res._2 == drop(index) - } - - def updated(i: BigInt, y: T): List[T] = { - require(0 <= i && i < this.size) - this match { - case Cons(x, tail) if i == 0 => - Cons[T](y, tail) - case Cons(x, tail) => - Cons[T](x, tail.updated(i - 1, y)) - } - } - - private def insertAtImpl(pos: BigInt, l: List[T]): List[T] = { - require(0 <= pos && pos <= size) - if(pos == BigInt(0)) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAtImpl(pos-1, l)) - case Nil() => - l - } - } - } ensuring { res => - res.size == this.size + l.size && - res.content == this.content ++ l.content - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - require(-pos <= size && pos <= size) - if(pos < 0) { - insertAtImpl(size + pos, l) - } else { - insertAtImpl(pos, l) - } - } ensuring { res => - res.size == this.size + l.size && - res.content == this.content ++ l.content - } - - def insertAt(pos: BigInt, e: T): List[T] = { - require(-pos <= size && pos <= size) - insertAt(pos, Cons[T](e, Nil())) - } ensuring { res => - res.size == this.size + 1 && - res.content == this.content ++ Set(e) - } - - private def replaceAtImpl(pos: BigInt, l: List[T]): List[T] = { - require(0 <= pos && pos <= size) - if (pos == BigInt(0)) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAtImpl(pos-1, l)) - case Nil() => - l - } - } - } ensuring { res => - res.content.subsetOf(l.content ++ this.content) - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - require(-pos <= size && pos <= size) - if(pos < 0) { - replaceAtImpl(size + pos, l) - } else { - replaceAtImpl(pos, l) - } - } ensuring { res => - res.content.subsetOf(l.content ++ this.content) - } - - def rotate(s: BigInt): List[T] = { - if (isEmpty) { - Nil[T]() - } else { - drop(s mod size) ++ take(s mod size) - } - } ensuring { res => - res.size == this.size - } - - @isabelle.function(term = "List.null") - def isEmpty = this match { - case Nil() => true - case _ => false - } - - def nonEmpty = !isEmpty - - // Higher-order API - @isabelle.function(term = "%xs f. List.list.map f xs") - def map[R](f: T => R): List[R] = { this match { - case Nil() => Nil[R]() - case Cons(h, t) => f(h) :: t.map(f) - }} ensuring { _.size == this.size } - - @isabelle.function(term = "%bs a f. List.foldl f a bs") - def foldLeft[R](z: R)(f: (R,T) => R): R = this match { - case Nil() => z - case Cons(h,t) => t.foldLeft(f(z,h))(f) - } - - @isabelle.function(term = "%as b f. List.foldr f as b") - def foldRight[R](z: R)(f: (T,R) => R): R = this match { - case Nil() => z - case Cons(h, t) => f(h, t.foldRight(z)(f)) - } - - def scanLeft[R](z: R)(f: (R,T) => R): List[R] = { this match { - case Nil() => z :: Nil() - case Cons(h,t) => z :: t.scanLeft(f(z,h))(f) - }} ensuring { !_.isEmpty } - - def scanRight[R](z: R)(f: (T,R) => R): List[R] = { this match { - case Nil() => z :: Nil[R]() - case Cons(h, t) => - val rest@Cons(h1,_) = t.scanRight(z)(f) - f(h, h1) :: rest - }} ensuring { !_.isEmpty } - - @isabelle.function(term = "List.bind") - def flatMap[R](f: T => List[R]): List[R] = - ListOps.flatten(this map f) - - def filter(p: T => Boolean): List[T] = { this match { - case Nil() => Nil[T]() - case Cons(h, t) if p(h) => Cons(h, t.filter(p)) - case Cons(_, t) => t.filter(p) - }} ensuring { res => - res.size <= this.size && - res.content.subsetOf(this.content) && - res.forall(p) - } - - def filterNot(p: T => Boolean): List[T] = - filter(!p(_)) ensuring { res => - res.size <= this.size && - res.content.subsetOf(this.content) && - res.forall(!p(_)) - } - - def partition(p: T => Boolean): (List[T], List[T]) = { this match { - case Nil() => (Nil[T](), Nil[T]()) - case Cons(h, t) => - val (l1, l2) = t.partition(p) - if (p(h)) (h :: l1, l2) - else (l1, h :: l2) - }} ensuring { res => - res._1 == filter(p) && - res._2 == filterNot(p) - } - - // In case we implement for-comprehensions - def withFilter(p: T => Boolean) = filter(p) - - @isabelle.function(term = "%xs P. List.list_all P xs") - def forall(p: T => Boolean): Boolean = this match { - case Nil() => true - case Cons(h, t) => p(h) && t.forall(p) - } - - @isabelle.function(term = "%xs P. List.list_ex P xs") - def exists(p: T => Boolean) = !forall(!p(_)) - - @isabelle.function(term = "%xs P. List.find P xs") - def find(p: T => Boolean): Option[T] = { this match { - case Nil() => None[T]() - case Cons(h, t) => if (p(h)) Some(h) else t.find(p) - }} ensuring { res => res match { - case Some(r) => (content contains r) && p(r) - case None() => true - }} - - def groupBy[R](f: T => R): Map[R, List[T]] = this match { - case Nil() => Map.empty[R, List[T]] - case Cons(h, t) => - val key: R = f(h) - val rest: Map[R, List[T]] = t.groupBy(f) - val prev: List[T] = if (rest isDefinedAt key) rest(key) else Nil[T]() - (rest ++ Map((key, h :: prev))) : Map[R, List[T]] - } - - def takeWhile(p: T => Boolean): List[T] = { this match { - case Cons(h,t) if p(h) => Cons(h, t.takeWhile(p)) - case _ => Nil[T]() - }} ensuring { res => - (res forall p) && - (res.size <= this.size) && - (res.content subsetOf this.content) - } - - def dropWhile(p: T => Boolean): List[T] = { this match { - case Cons(h,t) if p(h) => t.dropWhile(p) - case _ => this - }} ensuring { res => - (res.size <= this.size) && - (res.content subsetOf this.content) && - (res.isEmpty || !p(res.head)) - } - - def count(p: T => Boolean): BigInt = { this match { - case Nil() => BigInt(0) - case Cons(h, t) => - (if (p(h)) BigInt(1) else BigInt(0)) + t.count(p) - }} ensuring { - _ == this.filter(p).size - } - - def indexWhere(p: T => Boolean): BigInt = { this match { - case Nil() => BigInt(-1) - case Cons(h, _) if p(h) => BigInt(0) - case Cons(_, t) => - val rec = t.indexWhere(p) - if (rec >= 0) rec + BigInt(1) - else BigInt(-1) - }} ensuring { - _ >= BigInt(0) == (this exists p) - } - - - // Translation to other collections - def toSet: Set[T] = foldLeft(Set[T]()){ - case (current, next) => current ++ Set(next) - } -} - -@isabelle.constructor(name = "List.list.Cons") -case class Cons[T](h: T, t: List[T]) extends List[T] - -@isabelle.constructor(name = "List.list.Nil") -case class Nil[T]() extends List[T] - -object List { - @ignore - def apply[T](elems: T*): List[T] = { - var l: List[T] = Nil[T]() - for (e <- elems) { - l = Cons(e, l) - } - l.reverse - } - - @library - def fill[T](n: BigInt)(x: T) : List[T] = { - if (n <= 0) Nil[T]() - else Cons[T](x, fill[T](n-1)(x)) - } ensuring(res => (res.content == (if (n <= BigInt(0)) Set.empty[T] else Set(x))) && - res.size == (if (n <= BigInt(0)) BigInt(0) else n)) - - /* Range from start (inclusive) to until (exclusive) */ - @library - def range(start: BigInt, until: BigInt): List[BigInt] = { - require(start <= until) - if(until <= start) Nil[BigInt]() else Cons(start, range(start + 1, until)) - } ensuring{(res: List[BigInt]) => res.size == until - start } - - @library - def mkString[A](l: List[A], mid: String, f : A => String) = { - def rec(l: List[A]): String = l match { - case Nil() => "" - case Cons(a, b) => mid + f(a) + rec(b) - } - l match { - case Nil() => "" - case Cons(a, b) => f(a) + rec(b) - } - } -} - -@library -object ListOps { - @isabelle.function(term = "List.concat") - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = { ls match { - case Cons(h, t) => sortedIns(sorted(t), h) - case Nil() => Nil[BigInt]() - }} ensuring { isSorted _ } - - private def sortedIns(ls: List[BigInt], v: BigInt): List[BigInt] = { - require(isSorted(ls)) - ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, sortedIns(t, v)) - } - } - } ensuring { isSorted _ } - - def toMap[K, V](l: List[(K, V)]): Map[K, V] = l.foldLeft(Map[K, V]()){ - case (current, (k, v)) => current ++ Map(k -> v) - } -} - -// 'Cons' Extractor -object :: { - @library - def unapply[A](l: List[A]): Option[(A, List[A])] = l match { - case Nil() => None() - case Cons(x, xs) => Some((x, xs)) - } -} - - -import ListOps._ - -@library -object ListSpecs { - def snocIndex[T](l: List[T], t: T, i: BigInt): Boolean = { - require(0 <= i && i < l.size + 1) - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds because ( - l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - } - ) - - @induct - @isabelle.lemma(about = "leon.collection.List.apply") - def consIndex[T](h: T, t: List[T], i: BigInt): Boolean = { - require(0 <= i && i < t.size + 1) - (h :: t).apply(i) == (if (i == 0) h else t.apply(i - 1)) - }.holds - - def reverseIndex[T](l: List[T], i: BigInt): Boolean = { - require(0 <= i && i < l.size) - l.reverse.apply(i) == l.apply(l.size - 1 - i) - }.holds because( - l match { - case Nil() => true - case Cons(x,xs) => snocIndex(xs.reverse, x, i) && (if (i < xs.size) consIndex(x, xs, l.size - 1 - i) && reverseIndex[T](xs, i) else true) - } - ) - - def snocLast[T](l: List[T], x: T): Boolean = { - ((l :+ x).last == x) - }.holds because { - l match { - case Nil() => true - case Cons(y, ys) => { - ((y :: ys) :+ x).last ==| trivial | - (y :: (ys :+ x)).last ==| trivial | - (ys :+ x).last ==| snocLast(ys, x) | - x - }.qed - } - } - - def headReverseLast[T](l: List[T]): Boolean = { - require (!l.isEmpty) - (l.head == l.reverse.last) - }.holds because { - val Cons(x, xs) = l; - { - (x :: xs).head ==| trivial | - x ==| snocLast(xs.reverse, x) | - (xs.reverse :+ x).last ==| trivial | - (x :: xs).reverse.last - }.qed - } - - def appendIndex[T](l1: List[T], l2: List[T], i: BigInt): Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size)) - }.holds because { - l1 match { - case Nil() => true - case Cons(x,xs) => - (i != BigInt(0)) ==> appendIndex[T](xs, l2, i - 1) - } - } - - @induct - def appendAssoc[T](l1: List[T], l2: List[T], l3: List[T]): Boolean = { - (l1 ++ l2) ++ l3 == l1 ++ (l2 ++ l3) - }.holds - - @induct - def rightUnitAppend[T](l1: List[T]): Boolean = { - l1 ++ Nil() == l1 - }.holds - - // This follows immediately from the definition of `++` but we - // include it here anyway for completeness. - def leftUnitAppend[T](l1: List[T]): Boolean = { - Nil() ++ l1 == l1 - }.holds - - def snocIsAppend[T](l: List[T], t: T): Boolean = { - (l :+ t) == l ++ Cons[T](t, Nil()) - }.holds because { - l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - } - } - - def snocAfterAppend[T](l1: List[T], l2: List[T], t: T): Boolean = { - (l1 ++ l2) :+ t == l1 ++ (l2 :+ t) - }.holds because { - l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - } - } - - def snocReverse[T](l: List[T], t: T): Boolean = { - (l :+ t).reverse == Cons(t, l.reverse) - }.holds because { - l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - } - } - - def reverseReverse[T](l: List[T]): Boolean = { - l.reverse.reverse == l - }.holds because { - l match { - case Nil() => trivial - case Cons(x, xs) => { - (xs.reverse :+ x).reverse ==| snocReverse[T](xs.reverse, x) | - x :: xs.reverse.reverse ==| reverseReverse[T](xs) | - (x :: xs) - }.qed - } - } - - def reverseAppend[T](l1: List[T], l2: List[T]): Boolean = { - (l1 ++ l2).reverse == l2.reverse ++ l1.reverse - }.holds because { - l1 match { - case Nil() => { - (Nil() ++ l2).reverse ==| trivial | - l2.reverse ==| rightUnitAppend(l2.reverse) | - l2.reverse ++ Nil() ==| trivial | - l2.reverse ++ Nil().reverse - }.qed - case Cons(x, xs) => { - ((x :: xs) ++ l2).reverse ==| trivial | - (x :: (xs ++ l2)).reverse ==| trivial | - (xs ++ l2).reverse :+ x ==| reverseAppend(xs, l2) | - (l2.reverse ++ xs.reverse) :+ x ==| - snocAfterAppend(l2.reverse, xs.reverse, x) | - l2.reverse ++ (xs.reverse :+ x) ==| trivial | - l2.reverse ++ (x :: xs).reverse - }.qed - } - } - - def snocFoldRight[A, B](xs: List[A], y: A, z: B, f: (A, B) => B): Boolean = { - (xs :+ y).foldRight(z)(f) == xs.foldRight(f(y, z))(f) - }.holds because { - xs match { - case Nil() => true - case Cons(x, xs) => snocFoldRight(xs, y, z, f) - } - } - - def folds[A, B](xs: List[A], z: B, f: (B, A) => B): Boolean = { - val f2 = (x: A, z: B) => f(z, x) - ( xs.foldLeft(z)(f) == xs.reverse.foldRight(z)(f2) ) because { - xs match { - case Nil() => true - case Cons(x, xs) => { - (x :: xs).foldLeft(z)(f) ==| trivial | - xs.foldLeft(f(z, x))(f) ==| folds(xs, f(z, x), f) | - xs.reverse.foldRight(f(z, x))(f2) ==| trivial | - xs.reverse.foldRight(f2(x, z))(f2) ==| - snocFoldRight(xs.reverse, x, z, f2) | - (xs.reverse :+ x).foldRight(z)(f2) ==| trivial | - (x :: xs).reverse.foldRight(z)(f2) - }.qed - } - } - }.holds - - def scanVsFoldLeft[A, B](l: List[A], z: B, f: (B, A) => B): Boolean = { - ( l.scanLeft(z)(f).last == l.foldLeft(z)(f) ) - }.holds because { - l match { - case Nil() => true - case Cons(x, xs) => scanVsFoldLeft(xs, f(z, x), f) - } - } - - //// my hand calculation shows this should work, but it does not seem to be found - //def associative[T,U](l1: List[T], l2: List[T], f: List[T] => U, op: (U,U) => U) = { - // f(l1 ++ l2) == op(f(l1), f(l2)) - //} - // - //def existsAssoc[T](l1: List[T], l2: List[T], p: T => Boolean) = { - // associative[T, Boolean](l1, l2, _.exists(p), _ || _ ) - //}.holds - // - //def forallAssoc[T](l1: List[T], l2: List[T], p: T => Boolean) = { - // associative[T, Boolean](l1, l2, _.exists(p), _ && _ ) - //}.holds - - @induct - def scanVsFoldRight[A,B](l: List[A], z: B, f: (A,B) => B): Boolean = { - l.scanRight(z)(f).head == l.foldRight(z)(f) - }.holds - - def appendContent[A](l1: List[A], l2: List[A]) = { - l1.content ++ l2.content == (l1 ++ l2).content - }.holds - - def flattenPreservesContent[T](ls: List[List[T]]): Boolean = { - val f: (List[T], Set[T]) => Set[T] = _.content ++ _ - ( flatten(ls).content == ls.foldRight(Set[T]())(f) ) because { - ls match { - case Nil() => true - case Cons(h, t) => { - flatten(h :: t).content ==| trivial | - (h ++ flatten(t)).content ==| appendContent(h, flatten(t)) | - h.content ++ flatten(t).content ==| flattenPreservesContent(t) | - h.content ++ t.foldRight(Set[T]())(f) ==| trivial | - f(h, Set[T]()) ++ t.foldRight(Set[T]())(f) ==| trivial | - (h :: t).foldRight(Set[T]())(f) - }.qed - } - } - }.holds - - // A lemma about `append` and `updated` - def appendUpdate[T](l1: List[T], l2: List[T], i: BigInt, y: T): Boolean = { - require(0 <= i && i < l1.size + l2.size) - // lemma - ((l1 ++ l2).updated(i, y) == ( - if (i < l1.size) - l1.updated(i, y) ++ l2 - else - l1 ++ l2.updated(i - l1.size, y))) - }.holds because ( - // induction scheme - l1 match { - case Nil() => true - case Cons(x, xs) => if (i == 0) true else appendUpdate[T](xs, l2, i - 1, y) - } - ) - - // a lemma about `append`, `take` and `drop` - def appendTakeDrop[T](l1: List[T], l2: List[T], n: BigInt): Boolean = { - // lemma - ((l1 ++ l2).take(n) == ( - if (n < l1.size) l1.take(n) - else if (n > l1.size) l1 ++ l2.take(n - l1.size) - else l1)) && - ((l1 ++ l2).drop(n) == ( - if (n < l1.size) l1.drop(n) ++ l2 - else if (n > l1.size) l2.drop(n - l1.size) - else l2)) - }.holds because ( - //induction scheme - l1 match { - case Nil() => true - case Cons(x, xs) => if (n <= 0) true else appendTakeDrop[T](xs, l2, n - 1) - } - ) - - // A lemma about `append` and `insertAt` - def appendInsert[T](l1: List[T], l2: List[T], i: BigInt, y: T): Boolean = { - require(0 <= i && i <= l1.size + l2.size) - // lemma - (l1 ++ l2).insertAt(i, y) == ( - if (i < l1.size) l1.insertAt(i, y) ++ l2 - else l1 ++ l2.insertAt(i - l1.size, y)) - }.holds because ( - l1 match { - case Nil() => true - case Cons(x, xs) => if (i == 0) true else appendInsert[T](xs, l2, i - 1, y) - } - ) - - /** A way to apply the forall axiom */ - def applyForAll[T](l: List[T], i: BigInt, p: T => Boolean): Boolean = { - require(i >= 0 && i < l.length && l.forall(p)) - p(l(i)) - }.holds because ( - l match { - case Nil() => trivial - case Cons(head, tail) => if(i == 0) p(head) else applyForAll(l.tail, i - 1, p) - } - ) -} diff --git a/library/leon/collection/package.scala b/library/leon/collection/package.scala deleted file mode 100644 index db83501a2d41345f3287c0f069c78076863aa753..0000000000000000000000000000000000000000 --- a/library/leon/collection/package.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon - -import leon.annotation._ -import leon.collection.List -import leon.lang._ -import leon.lang.synthesis.choose - -package object collection { - - @internal @library - def setToList[A](set: Set[A]): List[A] = choose { - (x: List[A]) => x.content == set - } - - @library - def setForall[A](set: Set[A], p: A => Boolean): Boolean = - setToList(set).forall(p) - - @library - def setExists[A](set: Set[A], p: A => Boolean): Boolean = - setToList(set).exists(p) - -} diff --git a/library/leon/instrumentation/package.scala b/library/leon/instrumentation/package.scala deleted file mode 100644 index dc8ee71bd3036cbb35f02b30ddc9aa3dd8a0dbfa..0000000000000000000000000000000000000000 --- a/library/leon/instrumentation/package.scala +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon - -import leon.annotation._ -import leon.lang._ -import scala.language.implicitConversions - -package object instrumentation { - @library - def time: BigInt = 0 - - @library - def stack: BigInt = 0 - - @library - def rec: BigInt = 0 - - @library - def depth: BigInt = 0 - - @library - def tpr: BigInt = 0 -} diff --git a/library/leon/invariant/package.scala b/library/leon/invariant/package.scala deleted file mode 100644 index e6534f423733ba430e7383dac1b1f322e3c74523..0000000000000000000000000000000000000000 --- a/library/leon/invariant/package.scala +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon - -import leon.annotation._ -import leon.lang._ -import scala.language.implicitConversions - -package object invariant { - @library - def tmpl(templateFunc: BigInt => Boolean): Boolean = true - @library - def tmpl(templateFunc: (BigInt, BigInt) => Boolean): Boolean = true - @library - def tmpl(templateFunc: (BigInt, BigInt, BigInt) => Boolean): Boolean = true - @library - def tmpl(templateFunc: (BigInt, BigInt, BigInt, BigInt) => Boolean): Boolean = true - @library - def tmpl(templateFunc: (BigInt, BigInt, BigInt, BigInt, BigInt) => Boolean): Boolean = true - - @library - def ? : BigInt = 0 - - @library - def ?(id: BigInt) = id -} diff --git a/library/leon/io/StdIn.scala b/library/leon/io/StdIn.scala deleted file mode 100644 index 57012be57c15f8837310384892c3cf8ee1f6e438..0000000000000000000000000000000000000000 --- a/library/leon/io/StdIn.scala +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.io - -import leon.annotation._ - -object StdIn { - - @library - case class State(var seed: BigInt) - - @library - def newState: State = State(0) - - @library - @isabelle.noBody() - def readInt(implicit state: State): Int = { - state.seed += 1 - nativeReadInt - } - - @library - @extern - @isabelle.noBody() - private def nativeReadInt(implicit state: State): Int = { - scala.io.StdIn.readInt - } ensuring((x: Int) => true) - - @library - @isabelle.noBody() - def readBigInt(implicit state: State): BigInt = { - state.seed += 1 - nativeReadBigInt - } - - @library - @extern - @isabelle.noBody() - private def nativeReadBigInt(implicit state: State): BigInt = { - BigInt(scala.io.StdIn.readInt) - } ensuring((x: BigInt) => true) - - @library - @isabelle.noBody() - def readBoolean(implicit state: State): Boolean = { - state.seed += 1 - nativeReadBoolean - } - - @library - @extern - @isabelle.noBody() - private def nativeReadBoolean(implicit state: State): Boolean = { - scala.io.StdIn.readBoolean - } ensuring((x: Boolean) => true) - -} diff --git a/library/leon/lang/Bag.scala b/library/leon/lang/Bag.scala deleted file mode 100644 index 6a6be20a4a2622d4877872c2c44e91dc6a958270..0000000000000000000000000000000000000000 --- a/library/leon/lang/Bag.scala +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang -import leon.annotation._ - -object Bag { - @library - def empty[T] = Bag[T]() - - @ignore - def apply[T](elems: (T, BigInt)*) = { - new Bag[T](scala.collection.immutable.Map[T, BigInt](elems : _*)) - } - - @extern @library - def mkString[A](bag: Bag[A], infix: String, f: A => String) = { - bag.theBag.flatMap{ case (k, v) => - List.range(1, v.toString.toInt).map(_ => f(k)) - }.toList.sorted.mkString(infix) - } -} - -@ignore -case class Bag[T](theBag: scala.collection.immutable.Map[T, BigInt]) { - def +(a: T): Bag[T] = new Bag(theBag + (a -> (theBag.getOrElse(a, BigInt(0)) + 1))) - def ++(that: Bag[T]): Bag[T] = new Bag[T]((theBag.keys ++ that.theBag.keys).toSet.map { (k: T) => - k -> (theBag.getOrElse(k, BigInt(0)) + that.theBag.getOrElse(k, BigInt(0))) - }.toMap) - - def --(that: Bag[T]): Bag[T] = new Bag[T](theBag.flatMap { case (k,v) => - val res = v - that.get(k) - if (res <= 0) Nil else List(k -> res) - }) - - def &(that: Bag[T]): Bag[T] = new Bag[T](theBag.flatMap { case (k,v) => - val res = v min that.get(k) - if (res <= 0) Nil else List(k -> res) - }) - - def get(a: T): BigInt = theBag.getOrElse(a, BigInt(0)) - def apply(a: T): BigInt = get(a) - def isEmpty: Boolean = theBag.isEmpty -} - diff --git a/library/leon/lang/Dummy.scala b/library/leon/lang/Dummy.scala deleted file mode 100644 index 9c88117962d574654ffe406d5635440bb9236bc2..0000000000000000000000000000000000000000 --- a/library/leon/lang/Dummy.scala +++ /dev/null @@ -1,5 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang - -case class Dummy[T]() diff --git a/library/leon/lang/Either.scala b/library/leon/lang/Either.scala deleted file mode 100644 index 67caad70d7b2aa51fcee7b2c3b47767dd720f5c4..0000000000000000000000000000000000000000 --- a/library/leon/lang/Either.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang - -import leon.annotation._ - -/** - * @author Viktor - */ -@library -sealed abstract class Either[A,B] { - def isLeft : Boolean - def isRight : Boolean - def swap : Either[B,A] -} -@library -case class Left[A,B](content: A) extends Either[A,B] { - def isLeft = true - def isRight = false - def swap = Right[B,A](content) -} -@library -case class Right[A,B](content: B) extends Either[A,B] { - def isLeft = false - def isRight = true - def swap = Left[B,A](content) -} \ No newline at end of file diff --git a/library/leon/lang/Map.scala b/library/leon/lang/Map.scala deleted file mode 100644 index ce66a93d553c068eaf5e3dc66b37e3fbb9abc500..0000000000000000000000000000000000000000 --- a/library/leon/lang/Map.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang -import leon.annotation._ - -object Map { - @library - @isabelle.function(term = "Map.empty") - def empty[A,B] = Map[A,B]() - - @ignore - def apply[A,B](elems: (A,B)*) = { - new Map[A,B](scala.collection.immutable.Map[A,B](elems : _*)) - } - - @extern @library - def mkString[A, B](map: Map[A, B], inkv: String, betweenkv: String, fA : A => String, fB: B => String) = { - map.theMap.map{ case (k, v) => fA(k) + inkv + fB(v)}.toList.sorted.mkString(betweenkv) - } -} - -@ignore -case class Map[A, B] (theMap: scala.collection.immutable.Map[A,B]) { - def apply(k: A): B = theMap.apply(k) - def ++(b: Map[A, B]): Map[A,B] = new Map (theMap ++ b.theMap) - def updated(k: A, v: B): Map[A,B] = new Map(theMap.updated(k, v)) - def contains(a: A): Boolean = theMap.contains(a) - def isDefinedAt(a: A): Boolean = contains(a) - - def +(kv: (A, B)): Map[A,B] = updated(kv._1, kv._2) - def +(k: A, v: B): Map[A,B] = updated(k, v) - - def getOrElse(k: A, default: B): B = get(k).getOrElse(default) - - def get(k: A): Option[B] = if (contains(k)) { - Some[B](apply(k)) - } else { - None[B]() - } -} diff --git a/library/leon/lang/Option.scala b/library/leon/lang/Option.scala deleted file mode 100644 index da3dced3215b93b30098a7739c81db94c078a8e3..0000000000000000000000000000000000000000 --- a/library/leon/lang/Option.scala +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang - -import leon.annotation._ -import leon.collection._ - -@library -@isabelle.typ(name = "Option.option") -sealed abstract class Option[T] { - - def get : T = { - require(this.isDefined) - (this : @unchecked) match { - case Some(x) => x - } - } - - def getOrElse(default: =>T) = this match { - case Some(v) => v - case None() => default - } - - def orElse(or: =>Option[T]) = { this match { - case Some(v) => this - case None() => or - }} ensuring { - _.isDefined == this.isDefined || or.isDefined - } - - def isEmpty = this match { - case Some(v) => false - case None() => true - } - - def nonEmpty = !isEmpty - - def isDefined = !isEmpty - - - // Higher-order API - @isabelle.function(term = "%x f. Option.map_option f x") - def map[R](f: T => R) = { this match { - case None() => None[R]() - case Some(x) => Some(f(x)) - }} ensuring { _.isDefined == this.isDefined } - - @isabelle.function(term = "Option.bind") - def flatMap[R](f: T => Option[R]) = this match { - case None() => None[R]() - case Some(x) => f(x) - } - - def filter(p: T => Boolean) = this match { - case Some(x) if p(x) => Some(x) - case _ => None[T]() - } - - def withFilter(p: T => Boolean) = filter(p) - - def forall(p: T => Boolean) = this match { - case Some(x) if !p(x) => false - case _ => true - } - - def exists(p: T => Boolean) = !forall(!p(_)) - - // Transformation to other collections - def toList: List[T] = this match { - case None() => Nil[T]() - case Some(x) => List(x) - } - - def toSet: Set[T] = this match { - case None() => Set[T]() - case Some(x) => Set(x) - } -} - -@isabelle.constructor(name = "Option.option.Some") -case class Some[T](v: T) extends Option[T] - -@isabelle.constructor(name = "Option.option.None") -case class None[T]() extends Option[T] diff --git a/library/leon/lang/Rational.scala b/library/leon/lang/Rational.scala deleted file mode 100644 index 4699f08bebc3a3c80d1c9f3f7beafd8a8ca5d9ea..0000000000000000000000000000000000000000 --- a/library/leon/lang/Rational.scala +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang - -import leon.annotation._ - -import scala.language.implicitConversions - -@library -case class Rational(numerator: BigInt, denominator: BigInt) { - - require(this.isRational) - - def +(that: Rational): Rational = { - Rational(this.numerator*that.denominator + that.numerator*this.denominator, this.denominator*that.denominator) - } - - def -(that: Rational): Rational = { - Rational(this.numerator*that.denominator - that.numerator*this.denominator, this.denominator*that.denominator) - } - - def unary_- : Rational = { - Rational(-this.numerator, this.denominator) - } - - def *(that: Rational): Rational = { - Rational(this.numerator*that.numerator, this.denominator*that.denominator) - } - - def /(that: Rational): Rational = { - require(that.nonZero) - val newNumerator = this.numerator*that.denominator - val newDenominator = this.denominator*that.numerator - normalize(newNumerator, newDenominator) - } - - def reciprocal: Rational = { - require(this.nonZero) - normalize(this.denominator, this.numerator) - } - - - def ~(that: Rational): Boolean = { - this.numerator*that.denominator == that.numerator*this.denominator - } - - def <(that: Rational): Boolean = { - this.numerator*that.denominator < that.numerator*this.denominator - } - - def <=(that: Rational): Boolean = { - this.numerator*that.denominator <= that.numerator*this.denominator - } - - def >(that: Rational): Boolean = { - this.numerator*that.denominator > that.numerator*this.denominator - } - - def >=(that: Rational): Boolean = { - this.numerator*that.denominator >= that.numerator*this.denominator - } - - def nonZero: Boolean = { - numerator != 0 - } - - private def isRational: Boolean = denominator > 0 - - private def normalize(num: BigInt, den: BigInt): Rational = { - require(den != 0) - if(den < 0) - Rational(-num, -den) - else - Rational(num, den) - } -} - -@library -object Rational { - - implicit def bigIntToRat(n: BigInt): Rational = Rational(n, 1) - - def apply(n: BigInt): Rational = Rational(n, 1) - -} diff --git a/library/leon/lang/Real.scala b/library/leon/lang/Real.scala deleted file mode 100644 index 450cfb246a25d01e9d909dee5fb75ed32a7cdfa1..0000000000000000000000000000000000000000 --- a/library/leon/lang/Real.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang -import leon.annotation._ - -@ignore -class Real { - - def +(a: Real): Real = ??? - def -(a: Real): Real = ??? - def *(a: Real): Real = ??? - def /(a: Real): Real = ??? - - def unary_- : Real = ??? - - def > (a: Real): Boolean = ??? - def >=(a: Real): Boolean = ??? - def < (a: Real): Boolean = ??? - def <=(a: Real): Boolean = ??? - -} - -@ignore -object Real { - def apply(n: BigInt, d: BigInt): Real = ??? - def apply(n: BigInt): Real = ??? -} diff --git a/library/leon/lang/Set.scala b/library/leon/lang/Set.scala deleted file mode 100644 index 6e973258c711aa109822568dbb7cab5a2fe2b23a..0000000000000000000000000000000000000000 --- a/library/leon/lang/Set.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang -import leon.annotation._ - -object Set { - @library - def empty[T] = Set[T]() - - @ignore - def apply[T](elems: T*) = { - new Set[T](scala.collection.immutable.Set[T](elems : _*)) - } - - @extern @library - def mkString[A](map: Set[A], infix: String, fA : A => String) = { - map.theSet.map(fA).toList.sorted.mkString(infix) - } -} - -@ignore -case class Set[T](val theSet: scala.collection.immutable.Set[T]) { - def +(a: T): Set[T] = new Set[T](theSet + a) - def ++(a: Set[T]): Set[T] = new Set[T](theSet ++ a.theSet) - def -(a: T): Set[T] = new Set[T](theSet - a) - def --(a: Set[T]): Set[T] = new Set[T](theSet -- a.theSet) - def size: BigInt = theSet.size - def contains(a: T): Boolean = theSet.contains(a) - def isEmpty: Boolean = theSet.isEmpty - def subsetOf(b: Set[T]): Boolean = theSet.subsetOf(b.theSet) - def &(a: Set[T]): Set[T] = new Set[T](theSet & a.theSet) -} - diff --git a/library/leon/lang/StaticChecks.scala b/library/leon/lang/StaticChecks.scala deleted file mode 100644 index 1b6e20569834f8683a0efd8bfb04d8c489d378b3..0000000000000000000000000000000000000000 --- a/library/leon/lang/StaticChecks.scala +++ /dev/null @@ -1,15 +0,0 @@ -package leon.lang - -import leon.annotation._ -import scala.language.implicitConversions - -object StaticChecks { - - case class Ensuring[A](x: A) { - @library - def ensuring(cond: (A) => Boolean): A = x - } - - implicit def any2Ensuring[A](x: A): Ensuring[A] = Ensuring(x) - -} diff --git a/library/leon/lang/StrOps.scala b/library/leon/lang/StrOps.scala deleted file mode 100644 index 1276a06f3fa67f32746dade7332ea75e4de5f720..0000000000000000000000000000000000000000 --- a/library/leon/lang/StrOps.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang - -import leon.annotation._ - -/** - * @author Mikael - */ -object StrOps { - @ignore - def concat(a: String, b: String): String = { - a + b - } - @ignore - def bigLength(s: String): BigInt = { - BigInt(s.length) - } - @ignore - def bigSubstring(s: String, start: BigInt, end: BigInt): String = { - s.substring(start.toInt, end.toInt) - } - @internal @library - def escape(s: String): String = s // Wrong definition, but it will eventually use StringEscapeUtils.escapeJava(s) at parsing and compile time. -} \ No newline at end of file diff --git a/library/leon/lang/package.scala b/library/leon/lang/package.scala deleted file mode 100644 index 5b49604fb652dd844b68a05a04a1b5016f55b829..0000000000000000000000000000000000000000 --- a/library/leon/lang/package.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon - -import leon.annotation._ -import scala.language.implicitConversions - -package object lang { - import leon.proof._ - - implicit class BooleanDecorations(val underlying: Boolean) { - @inline - def holds : Boolean = { - underlying - } ensuring { - (res: Boolean) => res - } - @inline - def holds(becauseOfThat: Boolean) = { - underlying - } ensuring { - (res: Boolean) => becauseOfThat && res - } - - @inline - def ==>(that: => Boolean): Boolean = { - if (underlying) that else true - } - } - @inline def because(b: Boolean) = b - - @ignore def forall[A](p: A => Boolean): Boolean = sys.error("Can't execute quantified proposition") - @ignore def forall[A,B](p: (A,B) => Boolean): Boolean = sys.error("Can't execute quantified proposition") - @ignore def forall[A,B,C](p: (A,B,C) => Boolean): Boolean = sys.error("Can't execute quantified proposition") - @ignore def forall[A,B,C,D](p: (A,B,C,D) => Boolean): Boolean = sys.error("Can't execute quantified proposition") - @ignore def forall[A,B,C,D,E](p: (A,B,C,D,E) => Boolean): Boolean = sys.error("Can't execute quantified proposition") - - @ignore - object InvariantFunction { - def invariant(x: Boolean): Unit = () - } - - @ignore - implicit def while2Invariant(u: Unit) = InvariantFunction - - @ignore - def error[T](reason: java.lang.String): T = sys.error(reason) - - @ignore - def old[T](value: T): T = value - - @ignore - implicit class Passes[A,B](io : (A,B)) { - val (in, out) = io - def passes(tests : A => B ) : Boolean = - try { tests(in) == out } catch { case _ : MatchError => true } - } - - @ignore - def byExample[A, B](in: A, out: B): Boolean = { - sys.error("Can't execute by example proposition") - } - - implicit class SpecsDecorations[A](val underlying: A) { - @ignore - def computes(target: A) = { - underlying - } ensuring { - res => res == target - } - - @ignore // Programming by example: ???[String] ask input - def ask[I](input : I) = { - underlying - } ensuring { - (res: A) => byExample(input, res) - } - } - - implicit class StringDecorations(val underlying: String) { - @ignore @inline - def bigLength() = BigInt(underlying.length) - @ignore @inline - def bigSubstring(start: BigInt): String = underlying.substring(start.toInt) - @ignore @inline - def bigSubstring(start: BigInt, end: BigInt): String = underlying.substring(start.toInt, end.toInt) - } - - @ignore - object BigInt { - def apply(b: Int): scala.math.BigInt = scala.math.BigInt(b) - def apply(b: String): scala.math.BigInt = scala.math.BigInt(b) - - def unapply(b: scala.math.BigInt): scala.Option[Int] = { - if(b >= Integer.MIN_VALUE && b <= Integer.MAX_VALUE) { - scala.Some(b.intValue()) - } else { - scala.None - } - } - } - - @library - def tupleToString[A, B](t: (A, B), mid: String, f: A => String, g: B => String) = { - f(t._1) + mid + g(t._2) - } - - @extern @library - def print(x: String): Unit = { - scala.Predef.print(x) - } - -} diff --git a/library/leon/lang/synthesis/Oracle.scala b/library/leon/lang/synthesis/Oracle.scala deleted file mode 100644 index 399b52b8d82fc7250d827516596a569e51adebdb..0000000000000000000000000000000000000000 --- a/library/leon/lang/synthesis/Oracle.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang.synthesis - -import leon.annotation._ -import leon.lang._ - -import scala.annotation._ - -@implicitNotFound("No Oracle available for this source of non-determinism, please provide an implicit arg <: Oracle[T]") -@ignore -@library -abstract class Oracle[T] { - def head: T = this match { - case Node(_, h, _) => h - case Leaf(h) => h - } - - def left: Oracle[T] = this match { - case Node(l, _, _) => l - case Leaf(_) => this - } - - def right: Oracle[T] = this match { - case Node(_, _, r) => r - case Leaf(_) => this - } -} - -@ignore -case class Node[T](l: Oracle[T], v: T, r: Oracle[T]) extends Oracle[T]; -@ignore -case class Leaf[T](v: T) extends Oracle[T]; diff --git a/library/leon/lang/synthesis/package.scala b/library/leon/lang/synthesis/package.scala deleted file mode 100644 index 07635f1a69ede6ffacf894bb3438b9bd34555f5a..0000000000000000000000000000000000000000 --- a/library/leon/lang/synthesis/package.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang - -import leon.annotation._ - -import scala.language.implicitConversions -import scala.annotation.implicitNotFound - -package object synthesis { - @ignore - private def noImpl = throw new RuntimeException("Synthesis construct implementation not supported") - - @ignore - def choose[A](predicate: A => Boolean): A = noImpl - @ignore - def choose[A, B](predicate: (A, B) => Boolean): (A, B) = noImpl - @ignore - def choose[A, B, C](predicate: (A, B, C) => Boolean): (A, B, C) = noImpl - @ignore - def choose[A, B, C, D](predicate: (A, B, C, D) => Boolean): (A, B, C, D) = noImpl - @ignore - def choose[A, B, C, D, E](predicate: (A, B, C, D, E) => Boolean): (A, B, C, D, E) = noImpl - - @ignore - def ???[T]: T = noImpl - - @ignore - def ?[T](e1: T): T = if(???[Boolean]) e1 else ???[T] - - @ignore - def ?[T](e1: T, es: T*): T = noImpl - - // Repair with Holes - @ignore - def ?: T = noImpl - - @ignore - def withOracle[A, R](body: Oracle[A] => R): R = noImpl - -} diff --git a/library/leon/lang/xlang/package.scala b/library/leon/lang/xlang/package.scala deleted file mode 100644 index c394f9508238d97ba85d07e0b491f754908d6e4e..0000000000000000000000000000000000000000 --- a/library/leon/lang/xlang/package.scala +++ /dev/null @@ -1,10 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.lang - -import leon.annotation._ - -package object xlang { - @ignore - def epsilon[A](pred: (A) => Boolean): A = throw new RuntimeException("Implementation not supported") -} diff --git a/library/leon/lazy/package.scala b/library/leon/lazy/package.scala deleted file mode 100644 index 7c0f575828c3bd96cb32c069c43e1444373075a5..0000000000000000000000000000000000000000 --- a/library/leon/lazy/package.scala +++ /dev/null @@ -1,90 +0,0 @@ -/* Copyright 2009-2013 EPFL, Lausanne */ - -package leon - -import annotation._ -import lang._ -import scala.language.implicitConversions -import scala.annotation.StaticAnnotation - -package object lazyeval { - - @library - def $[T](f: => T) = Lazy(Unit => f) - //def apply[T](f: => T) = new $(Unit => f) - - @library - def eager[T](x: => T) = Lazy(Unit => x) - - /** - * implicit conversion from eager evaluation to lazy evaluation - */ - @library - @inline - implicit def eagerToLazy[T](x: T) = eager(x) - - /** - * For accessing in and out states. - * Should be used only in ensuring. - */ - @library - @extern - def inState[T]: Set[Lazy[T]] = sys.error("inState method is not executable!") - - @library - @extern - def outState[T]: Set[Lazy[T]] = sys.error("outState method is not executable") - - /** - * Helper class for invoking with a given state instead of the implicit state - */ - @library - case class WithState[T](v: T) { - @extern - def withState[U](u: Set[Lazy[U]]): T = sys.error("withState method is not executable!") - - @extern - def withState[U, V](u: Set[Lazy[U]], v: Set[Lazy[V]]): T = sys.error("withState method is not executable!") - - @extern - def withState[U, V, W](u: Set[Lazy[U]], v: Set[Lazy[V]], w: Set[Lazy[W]]): T = sys.error("withState method is not executable!") - - @extern - def withState[U, V, W, X](u: Set[Lazy[U]], v: Set[Lazy[V]], w: Set[Lazy[W]], x: Set[Lazy[X]]): T = sys.error("withState method is not executable!") - // extend this to more arguments if needed - } - - @library - @inline - implicit def toWithState[T](x: T) = new WithState(x) - - /** - * annotations for monotonicity proofs. - * Note implemented as of now. - * Let foo be the method that has the annotation. - * The given name `methodname` should have the following form: - * m(arg1, ..., argn, substate-Set1,..., substate-Setn, superstate-Set1, ..., superstate-Setn) - */ - @ignore - class monoproof(methodname: String) extends StaticAnnotation - - @library - case class Lazy[T](f: Unit => T) { - @extern - lazy val value = { - val x = f(()) - eval = true - x - } - def * = f(()) - - @ignore - var eval = false // is this thread safe ? - - @extern - def isEvaluated = eval - - @extern - def isSuspension[T](f: T): Boolean = sys.error("isSuspensionOf method is not executable") - } -} \ No newline at end of file diff --git a/library/leon/math/package.scala b/library/leon/math/package.scala deleted file mode 100644 index 51fe7fdb2de334478ec3d98dc5e3937b0dd9a697..0000000000000000000000000000000000000000 --- a/library/leon/math/package.scala +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon -import leon.annotation._ - -package object math { - - @library - def min(i1: Int, i2: Int) = if (i1 <= i2) i1 else i2 - - @library - def max(i1: Int, i2: Int) = if (i1 >= i2) i1 else i2 - - @library - def min(i1: BigInt, i2: BigInt) = if (i1 <= i2) i1 else i2 - - @library - def max(i1: BigInt, i2: BigInt) = if (i1 >= i2) i1 else i2 - -} diff --git a/library/leon/mem/package.scala b/library/leon/mem/package.scala deleted file mode 100644 index 416b737acae9b34287dc0f54ee3e6202fe72721e..0000000000000000000000000000000000000000 --- a/library/leon/mem/package.scala +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright 2009-2013 EPFL, Lausanne */ - -package leon - -import annotation._ -import lang._ -import scala.language.implicitConversions -import scala.annotation.StaticAnnotation - -package object mem { - - @library - @inline - implicit def toMem[T](x: T) = new Mem(x) - - /** - * accessing in and out states of mems - * Should be used only in ensuring. - */ - @library - @extern - def inState[T]: Set[Mem[T]] = sys.error("inState method is not executable!") - - @library - @extern - def outState[T]: Set[Mem[T]] = sys.error("outState method is not executable") - - /** - * Helper class for invoking with a given state instead of the implicit state - */ - @library - case class memWithState[T](v: T) { - @extern - def withState[U](u: Set[Mem[U]]): T = sys.error("withState method is not executable!") - - @extern - def withState[U, V](u: Set[Mem[U]], v: Set[Mem[V]]): T = sys.error("withState method is not executable!") - - @extern - def withState[U, V, W](u: Set[Mem[U]], v: Set[Mem[V]], w: Set[Mem[W]]): T = sys.error("withState method is not executable!") - - @extern - def withState[U, V, W, X](u: Set[Mem[U]], v: Set[Mem[V]], w: Set[Mem[W]], x: Set[Mem[X]]): T = sys.error("withState method is not executable!") - // extend this to more arguments if needed - } - - @library - @inline - implicit def toWithState[T](x: T) = new memWithState(x) - - @library - case class Mem[T](v: T) { - @extern - def isCached: Boolean = sys.error("not implemented!") - } -} \ No newline at end of file diff --git a/library/leon/monads/state/State.scala b/library/leon/monads/state/State.scala deleted file mode 100644 index 7bb12881ca5dce8acc3df59517e624b92e5785c0..0000000000000000000000000000000000000000 --- a/library/leon/monads/state/State.scala +++ /dev/null @@ -1,217 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.monads.state - -import leon.collection._ -import leon.lang._ -import leon.annotation._ -import State._ - - -@library -case class State[S, A](runState: S => (A, S)) { - - /** Basic monadic methods */ - - // Monadic bind - @inline - def flatMap[B](f: A => State[S, B]): State[S, B] = { - State { s => - val (a, newS) = runState(s) - f(a).runState(newS) - } - } - - // All monads are also functors, and they define the map function - @inline - def map[B](f: A => B): State[S, B] = { - State { s => - val (a, newS) = runState(s) - (f(a), newS) - } - } - - @inline - def >>=[B](f: A => State[S, B]): State[S, B] = flatMap(f) - - @inline - def >>[B](that: State[S, B]) = >>= ( _ => that ) - - @inline - // This is unfortunate, but implementing properly would just lead to an error - def withFilter(f: A => Boolean): State[S, A] = this - - @inline - def eval(s: S) = runState(s)._1 - @inline - def exec(s: S) = runState(s)._2 - - // eval with arguments flipped - @inline - def >:: (s: S) = eval(s) - - def apply(s: S) = runState(s) - -} - -@library -object State { - - @inline - def get[A]: State[A, A] = State( a => (a, a) ) - - @inline - def gets[S, A](f: S => A): State[S, A] = for { - s <- get[S] - } yield f(s) - - @inline - def put[S](s: S): State[S, Unit] = State { _ => ((), s) } - - @inline - def modify[S](f: S => S): State[S, Unit] = for { - s <- get[S] - s2 <- put(f(s)) - } yield s2 - - // Monadic unit - @inline - def unit[S, A](a: A): State[S, A] = State { s => (a, s) } - - @inline - def state[S]: State[S, S] = State(s => (s, s)) - - @inline - // Left-to-right Kleisli composition of monads - def >=>[S, A, B, C](f: A => State[S, B], g: B => State[S, C], a: A): State[S, C] = { - for { - b <- f(a) - c <- g(b) - } yield c - } - - /* Monadic-List functions */ - - def mapM[A, B, S](f: A => State[S, B], l: List[A]): State[S, List[B]] = { - l match { - case Nil() => unit(Nil[B]()) - case Cons(x, xs) => for { - mx <- f(x) - mxs <- mapM(f,xs) - } yield mx :: mxs - } - } - - def mapM_ [A, B, S] (f: A => State[S, B], l: List[A]): State[S, Unit] = { - l match { - case Nil() => unit(()) - case Cons(x, xs) => for { - mx <- f(x) - mxs <- mapM_ (f, xs) - } yield () - } - } - - def sequence[S, A](l: List[State[S, A]]): State[S, List[A]] = { - l.foldRight[State[S, List[A]]](unit(Nil[A]())){ - case (x, xs) => for { - v <- x - vs <- xs - } yield v :: vs - } - } - - def filterM[S, A](f: A => State[S, Boolean], l: List[A]): State[S, List[A]] = { - l match { - case Nil() => unit(Nil[A]()) - case Cons(x, xs) => for { - flg <- f(x) - rest <- filterM(f, xs) - } yield (if (flg) x :: rest else rest) - } - } - - //(b -> a -> m b) -> b -> t a -> m b - def foldLeftM[S, A, B](f: (B, A) => State[S, B], z: B, l: List[A]): State[S, B] = { - l match { - case Nil() => unit(z) - case Cons(x, xs) => - f(z, x) >>= ( z0 => foldLeftM(f,z0,xs) ) - } - } - - //(b -> a -> m b) -> b -> t a -> m () - def foldLeftM_ [S, A](f: A => State[S, Unit], l: List[A]): State[S, Unit] = { - l match { - case Nil() => unit(()) - case Cons(x, xs) => - f(x) >> foldLeftM_ (f, xs) - } - } - -} - -@library -object MonadStateLaws { - /* Monadic laws: - * - * return a >>= k = k a - * m >>= return = m - * m >>= (x -> k x >>= h) = (m >>= k) >>= h - * - * Note: We cannot compare State's directly because State contains an anonymous function. - * So we have to run them on an initial state. - */ - - def unitLeftId[A, B, S](a: A, k: A => State[S, B])(s: S): Boolean = { - (unit(a) >>= (k))(s) == k(a)(s) - }.holds - - def unitRightId[S, A](m: State[S,A])(s:S): Boolean = { - (m >>= unit).runState(s) == m.runState(s) - }.holds - - def assoc[S, A, B, C](m: State[S,A], k: A => State[S, B], h: B => State[S, C])(s: S) = { - (m >>= (x => k(x) >>= h)).runState(s) == (m >>= k >>= h).runState(s) - }.holds - - /* This is the same as assoc, but proves in 42sec instead of 50ms! - def assoc2[S, A, B, C](m: State[S,A], k: A => State[S, B], h: B => State[S, C])(s: S) = { - val lhs = for { - x <- m - y <- for { - z <- k(x) - w <- h(z) - } yield w - } yield y - - val rhs = for { - x <- m - y <- k(x) - z <- h(y) - } yield z - - lhs.runState(s) == rhs.runState(s) - }.holds - */ - - - /* The law connecting monad and functor instances: - * - * m >>= (return . f) = m map f - */ - - def mapToFlatMap[S, A, B](m: State[S, A], f: A => B)(s: S): Boolean = { - (m >>= (x => unit(f(x)))).runState(s) == (m map f).runState(s) - }.holds - - - /* Different theorems */ - - //@induct - //def mapMVsSequenceM[S, A, B](f: A => State[S, B], l: List[A])(s: S) = { - // mapM(f, l).runState(s) == sequence(l map f).runState(s) - //}.holds - - -} diff --git a/library/leon/par/package.scala b/library/leon/par/package.scala deleted file mode 100644 index 1c542dd48d64d97daae7b60dee5b8223b21ccc0c..0000000000000000000000000000000000000000 --- a/library/leon/par/package.scala +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon - -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis.choose - -package object par { - - @library - @inline - def parallel[A,B](x: => A, y: => B) : (A,B) = { - (x,y) - } - - @library - case class Task[A](c: A) { - def join: A = c - } - - @library - def task[A](c: A) = Task(c) -} diff --git a/library/leon/proof/Internal.scala b/library/leon/proof/Internal.scala deleted file mode 100644 index 5dcd34867c8c3854425b611b9368e6707536ca96..0000000000000000000000000000000000000000 --- a/library/leon/proof/Internal.scala +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ -package leon.proof - -import leon.lang._ -import leon.annotation._ - -/** Internal helper classes and methods for the 'proof' package. */ -object Internal { - - /*** Helper classes for relational reasoning ***/ - @library - case class WithRel[A, B](x: A, r: (A, B) => Boolean, prop: Boolean) { - - /** Continue with the next relation. */ - def ^^(y: B): RelReasoning[B] = { - require(prop ==> r(x, y)) - RelReasoning(y, prop && r(x, y)) - } - - /** Add a proof. */ - def ^^|(proof: Boolean): WithProof[A, B] = { - require(proof) - WithProof(x, r, proof, prop) - } - - /** Short-hand for equational reasoning. */ - def ==|(proof: Boolean): WithProof[A, A] = { - require(proof) - WithProof(x, _ == _, proof, prop) - } - - def qed: Boolean = prop - } - - @library - case class WithProof[A, B]( - x: A, r: (A, B) => Boolean, proof: Boolean, prop: Boolean) { - - /** Close a proof. */ - def |[C](that: WithProof[B, C]): WithProof[B, C] = { - require(this.prop && this.proof ==> this.r(this.x, that.x)) - WithProof( - that.x, that.r, that.proof, - this.prop && this.proof && this.r(this.x, that.x)) - } - - /** Close a proof. */ - def |[C](that: WithRel[B, C]): WithRel[B, C] = { - require(this.prop && this.proof ==> this.r(this.x, that.x)) - WithRel( - that.x, that.r, - this.prop && this.proof && this.r(this.x, that.x)) - } - - /** Close a proof. */ - def |(that: RelReasoning[B]): RelReasoning[B] = { - require(this.prop && this.proof ==> this.r(this.x, that.x)) - RelReasoning( - that.x, - this.prop && this.proof && this.r(this.x, that.x)) - } - } -} diff --git a/library/leon/proof/package.scala b/library/leon/proof/package.scala deleted file mode 100644 index 46ac1588321e976ec3a9dd0066b29c7032c97d3c..0000000000000000000000000000000000000000 --- a/library/leon/proof/package.scala +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon - -import leon.annotation._ -import leon.lang._ -import scala.language.implicitConversions - -import leon.proof.Internal._ - -package object proof { - - @library - case class ProofOps(prop: Boolean) { - def because(proof: Boolean): Boolean = proof && prop - def neverHolds: Boolean = { - require(!prop) - !prop - } - } - - @library - implicit def boolean2ProofOps(prop: Boolean): ProofOps = ProofOps(prop) - - @library - def trivial: Boolean = true - - @library - def by(proof: Boolean)(prop: Boolean): Boolean = - proof && prop - - @library - def check(prop: Boolean): Boolean = { - require(prop) - prop - } - - /** - * Relational reasoning. - * - * { - * ((y :: ys) :+ x).last ^^ _ == _ ^^| trivial | - * (y :: (ys :+ x)).last ==| trivial | - * (ys :+ x).last ==| snocLast(ys, x) | - * x - * }.qed - */ - @library - case class RelReasoning[A](x: A, prop: Boolean) { - - def ^^[B](r: (A, B) => Boolean): WithRel[A, B] = WithRel(x, r, prop) - - /** Short-hand for equational reasoning. */ - def ==|(proof: Boolean): WithProof[A, A] = { - require(proof) - WithProof(x, _ == _, proof, prop) - } - - def qed: Boolean = prop - } - - @library - implicit def any2RelReasoning[A](x: A): RelReasoning[A] = - RelReasoning(x, true) - -} - diff --git a/library/leon/stats/package.scala b/library/leon/stats/package.scala deleted file mode 100644 index 17d6286b62c3e4de4be5d4c430ea74e26a3abef0..0000000000000000000000000000000000000000 --- a/library/leon/stats/package.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon - -import leon.annotation._ -import java.lang.management._ -import scala.collection.JavaConversions._ - -/** - * A collection of methods that can be used to collect run-time statistics about Leon programs. - * This is mostly used to test the resources properties of Leon programs - */ -package object stats { - @ignore - def timed[T](code: => T)(cont: Long => Unit): T = { - var t1 = System.currentTimeMillis() - val r = code - cont((System.currentTimeMillis() - t1)) - r - } - - @ignore - def withTime[T](code: => T): (T, Long) = { - var t1 = System.currentTimeMillis() - val r = code - (r, (System.currentTimeMillis() - t1)) - } -} diff --git a/library/leon/theories/Bag.scala b/library/leon/theories/Bag.scala deleted file mode 100644 index 53089dcd200b379277feae1c18d7bc98bfbeb581..0000000000000000000000000000000000000000 --- a/library/leon/theories/Bag.scala +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.theories -import leon.lang.forall -import leon.annotation._ - -@library -sealed case class Bag[T](f: T => BigInt) { - def get(x: T): BigInt = f(x) - def add(elem: T): Bag[T] = Bag((x: T) => f(x) + (if (x == elem) 1 else 0)) - def union(that: Bag[T]): Bag[T] = Bag((x: T) => f(x) + that.f(x)) - def difference(that: Bag[T]): Bag[T] = Bag((x: T) => { - val res = f(x) - that.f(x) - if (res < 0) 0 else res - }) - - def intersect(that: Bag[T]): Bag[T] = Bag((x: T) => { - val r1 = f(x) - val r2 = that.f(x) - if (r1 > r2) r2 else r1 - }) - - def equals(that: Bag[T]): Boolean = forall((x: T) => f(x) == that.f(x)) -} diff --git a/library/leon/theories/String.scala b/library/leon/theories/String.scala deleted file mode 100644 index 541e90261057ac0fe321c14dfda3e2d276a108ea..0000000000000000000000000000000000000000 --- a/library/leon/theories/String.scala +++ /dev/null @@ -1,94 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.theories -import leon.annotation._ - -@library -sealed abstract class String { - def size: BigInt = (this match { - case StringCons(_, tail) => 1 + tail.size - case StringNil() => BigInt(0) - }) ensuring (_ >= 0) - - def sizeI: Int = this match { - case StringCons(_, tail) => 1 + tail.sizeI - case StringNil() => 0 - } - - def concat(that: String): String = this match { - case StringCons(head, tail) => StringCons(head, tail concat that) - case StringNil() => that - } - - def take(i: BigInt): String = this match { - case StringCons(head, tail) if i > 0 => StringCons(head, tail take (i - 1)) - case _ => StringNil() - } - - def drop(i: BigInt): String = this match { - case StringCons(head, tail) if i > 0 => tail drop (i - 1) - case _ => this - } - - @isabelle.noBody() - def takeI(i: Int): String = this match { - case StringCons(head, tail) if i > 0 => StringCons(head, tail takeI (i - 1)) - case _ => StringNil() - } - - @isabelle.noBody() - def dropI(i: Int): String = this match { - case StringCons(head, tail) if i > 0 => tail dropI (i - 1) - case _ => this - } - - def slice(from: BigInt, to: BigInt): String = drop(from).take(to - from) - def sliceI(from: Int, to: Int): String = dropI(from).takeI(to - from) -} - -case class StringCons(head: Char, tail: String) extends String -case class StringNil() extends String - -@library -object String { - def fromChar(i: Char): String = { - StringCons(i, StringNil()) - } - - @isabelle.noBody() - def fromBigInt(i: BigInt): String = - if(i < 0) StringCons('-', fromBigInt(-i)) - else if(i == BigInt(0)) StringCons('0', StringNil()) - else if(i == BigInt(1)) StringCons('1', StringNil()) - else if(i == BigInt(2)) StringCons('2', StringNil()) - else if(i == BigInt(3)) StringCons('3', StringNil()) - else if(i == BigInt(4)) StringCons('4', StringNil()) - else if(i == BigInt(5)) StringCons('5', StringNil()) - else if(i == BigInt(6)) StringCons('6', StringNil()) - else if(i == BigInt(7)) StringCons('7', StringNil()) - else if(i == BigInt(8)) StringCons('8', StringNil()) - else if(i == BigInt(9)) StringCons('9', StringNil()) - else fromBigInt(i / 10).concat(fromBigInt(i % 10)) - - @isabelle.noBody() - def fromInt(i: Int): String = i match { - case -2147483648 => StringCons('-', StringCons('2', fromInt(147483648))) - case i if i < 0 => StringCons('-', fromInt(-i)) - case 0 => StringCons('0', StringNil()) - case 1 => StringCons('1', StringNil()) - case 2 => StringCons('2', StringNil()) - case 3 => StringCons('3', StringNil()) - case 4 => StringCons('4', StringNil()) - case 5 => StringCons('5', StringNil()) - case 6 => StringCons('6', StringNil()) - case 7 => StringCons('7', StringNil()) - case 8 => StringCons('8', StringNil()) - case 9 => StringCons('9', StringNil()) - case i => fromInt(i / 10).concat(fromInt(i % 10)) - } - - def fromBoolean(b: Boolean): String = { - if(b) StringCons('t', StringCons('r', StringCons('u', StringCons('e', StringNil())))) - else StringCons('f', StringCons('a', StringCons('l', StringCons('s', StringCons('e', StringNil()))))) - } -} diff --git a/library/leon/util/Random.scala b/library/leon/util/Random.scala deleted file mode 100644 index b6e60aa0ab373f51520b98bbc3ab5a13d9552c9c..0000000000000000000000000000000000000000 --- a/library/leon/util/Random.scala +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright 2009-2016 EPFL, Lausanne */ - -package leon.util - -import leon.annotation._ -import leon.lang.xlang._ - -object Random { - - @library - case class State(var seed: BigInt) - - @library - def newState: State = State(0) - - - @library - @isabelle.noBody() - def nextBoolean(implicit state: State): Boolean = { - state.seed += 1 - nativeNextBoolean - } ensuring((x: Boolean) => true) - - @library - @extern - @isabelle.noBody() - private def nativeNextBoolean(implicit state: State): Boolean = { - scala.util.Random.nextBoolean - } ensuring((x: Boolean) => true) - - - - @library - @isabelle.noBody() - def nextInt(implicit state: State): Int = { - state.seed += 1 - nativeNextInt - } ensuring((x: Int) => true) - - @library - @extern - @isabelle.noBody() - private def nativeNextInt(implicit state: State): Int = { - scala.util.Random.nextInt - } ensuring((x: Int) => true) - - - - @library - @isabelle.noBody() - def nextInt(max: Int)(implicit state: State): Int = { - require(max > 0) - state.seed += 1 - nativeNextInt(max) - } ensuring(res => res >= 0 && res < max) - - @library - @extern - @isabelle.noBody() - def nativeNextInt(max: Int)(implicit state: State): Int = { - scala.util.Random.nextInt(max) - } ensuring(res => res >= 0 && res < max) - - - - @library - @isabelle.noBody() - def nextBigInt(implicit state: State): BigInt = { - state.seed += 1 - nativeNextBigInt - } ensuring((x: BigInt) => true) - - @library - @extern - @isabelle.noBody() - private def nativeNextBigInt(implicit state: State): BigInt = { - BigInt(scala.util.Random.nextInt) - } ensuring((x: BigInt) => true) - - - - @library - @isabelle.noBody() - def nextBigInt(max: BigInt)(implicit state: State): BigInt = { - require(max > 0) - state.seed += 1 - nativeNextBigInt(max) - } ensuring((res: BigInt) => res >= 0 && res < max) - - @library - @extern - @isabelle.noBody() - private def nativeNextBigInt(max: BigInt)(implicit state: State): BigInt = { - BigInt(scala.util.Random.nextInt(max.toInt)) - } ensuring((x: BigInt) => x >= 0 && x < max) - -} diff --git a/library/leon/webDSL/webBuilding/WebBuilder.scala b/library/leon/webDSL/webBuilding/WebBuilder.scala deleted file mode 100644 index 0a96d6464f4769bab1b33d82e066bbd84a4ffb83..0000000000000000000000000000000000000000 --- a/library/leon/webDSL/webBuilding/WebBuilder.scala +++ /dev/null @@ -1,176 +0,0 @@ -package leon.webDSL.webBuilding -import leon.webDSL.webDescription._ -import leon.collection._ -import leon.annotation._ - -@library -case class Acceptor[T](tag: String) { - @isabelle.noBody() @library - def :=(v: String) = WebAttribute(tag, v) -} - -case class CssAcceptor[T](tag: String) { - @isabelle.noBody() @library - def :=(v: String) = WebStyle(tag, v) -} - -@library -object implicits { - @isabelle.noBody() - implicit def toAttribute(e: String): WebTree = TextElement(e) - - /*def extractElements(e: List[WebTree], acc: List[WebElement], acc2: List[WebAttribute], acc3: List[WebStyle]): (List[WebElement], List[WebAttribute], List[WebStyle]) = e match { - case Nil() => (acc.reverse, acc2.reverse, acc3.reverse) - case Cons(e: WebElement, t) => extractElements(t, e::acc, acc2, acc3) - case Cons(p: WebAttribute, t) => extractElements(t, acc, p::acc2, acc3) - case Cons(p: WebStyle, t) => extractElements(t, acc, acc2, p::acc3) - }*/ - @isabelle.noBody() - def extractElements(e: List[WebTree]): (List[WebElement], List[WebAttribute], List[WebStyle]) = e match { - case Nil() => (Nil(), Nil(), Nil()) - case Cons(e: WebElement, t) => - val abc = extractElements(t) - (e::abc._1, abc._2, abc._3) - case Cons(e: WebAttribute, t) => - val abc = extractElements(t) - (abc._1, e::abc._2, abc._3) - case Cons(e: WebStyle, t) => - val abc = extractElements(t) - (abc._1, abc._2, e::abc._3) - } - @isabelle.noBody() - def getStringProperty(tag: String, properties: List[WebAttribute], default: String): String = { - properties.flatMap[String] { e => e match { - case WebAttribute(tag2, e) if tag2 == tag=> e :: Nil[String] - case _ => Nil() - }}.headOption.getOrElse(default) - } - @isabelle.noBody() - def getAllStringProperty(tag: String, properties: List[WebAttribute], default: String): String = { - properties.foldLeft("") { (acc, e) => e match { - case WebAttribute(tag2, e) if tag2 == tag => acc + e - case _ => acc - }} - } -} - -@library -object < { - import implicits._ - @isabelle.noBody() - def extract(tag: String, elems: List[WebTree]): Element = { - val (children, properties, styles) = extractElements(elems) - Element(tag, children, properties, styles) - } - - val div = Element("div", Nil(), Nil(), Nil()) - val input = Element("input", Nil(), Nil(), Nil()) - val label = Element("label", Nil(), Nil(), Nil()) - val span = Element("span", Nil(), Nil(), Nil()) - val h1 = Element("h1", Nil(), Nil(), Nil()) - val h2 = Element("h2", Nil(), Nil(), Nil()) - val h3 = Element("h3", Nil(), Nil(), Nil()) - val h4 = Element("h4", Nil(), Nil(), Nil()) - val h5 = Element("h5", Nil(), Nil(), Nil()) - val h6 = Element("h6", Nil(), Nil(), Nil()) - val p = Element("p", Nil(), Nil(), Nil()) - val table = Element("table", Nil(), Nil(), Nil()) - val tbody = Element("tbody", Nil(), Nil(), Nil()) - val th = Element("th", Nil(), Nil(), Nil()) - val tr = Element("tr", Nil(), Nil(), Nil()) - val td = Element("td", Nil(), Nil(), Nil()) - val br = Element("br", Nil(), Nil(), Nil()) - val ul = Element("ul", Nil(), Nil(), Nil()) - val ol = Element("ol", Nil(), Nil(), Nil()) - val li = Element("li", Nil(), Nil(), Nil()) - val a = Element("a", Nil(), Nil(), Nil()) - val img = Element("img", Nil(), Nil(), Nil()) - - val b = Element("b", Nil(), Nil(), Nil()) - val i = Element("i", Nil(), Nil(), Nil()) - val u = Element("u", Nil(), Nil(), Nil()) -} - -@library -object ^ { - val name = Acceptor[String]("name") - val tpe = Acceptor[String]("type") - val value = Acceptor[String]("value") - val placeholder = Acceptor[String]("placeholder") - val id = Acceptor[String]("id") - val className = Acceptor[String]("class") - val classes = Acceptor[String]("class") - val src = Acceptor[String]("src") - val alt = Acceptor[String]("alt") - val forid = Acceptor[String]("for") - val cellpadding = Acceptor[String]("cellpadding") - val cellspacing = Acceptor[String]("cellspacing") - val colspan = Acceptor[String]("colSpan") - val href = Acceptor[String]("href") - val tabindex = Acceptor[String]("tabindex") - val title = Acceptor[String]("title") - val target = Acceptor[String]("target") - val maxlength = Acceptor[String]("maxlength") - - val position = CssAcceptor[String]("position") - val display = CssAcceptor[String]("display") - - val borderCollapse = CssAcceptor[String]("border-collapse") - val textAlign = CssAcceptor[String]("text-align") - val width = CssAcceptor[String]("width") - val height = CssAcceptor[String]("height") - val color = CssAcceptor[String]("color") - val background = CssAcceptor[String]("background") - val backgroundColor = CssAcceptor[String]("background-color") - val backgroundImage = CssAcceptor[String]("background-image") - - val paddingRight = CssAcceptor[String]("padding-right") - val paddingLeft = CssAcceptor[String]("padding-left") - val paddingTop = CssAcceptor[String]("padding-top") - val paddingBottom = CssAcceptor[String]("padding-bottom") - val padding = CssAcceptor[String]("padding") - - val marginRight = CssAcceptor[String]("margin-right") - val marginLeft = CssAcceptor[String]("margin-left") - val marginTop = CssAcceptor[String]("margin-top") - val marginBottom = CssAcceptor[String]("margin-bottom") - val margin = CssAcceptor[String]("margin") - - val borderRight = CssAcceptor[String]("border-right") - val borderLeft = CssAcceptor[String]("border-left") - val borderTop = CssAcceptor[String]("border-top") - val borderBottom = CssAcceptor[String]("border-bottom") - val border = CssAcceptor[String]("border") - val borderColor = CssAcceptor[String]("border-color") - val borderRadius = CssAcceptor[String]("border-radius") - - val fontSize = CssAcceptor[String]("font-size") - val lineHeight = CssAcceptor[String]("line-height") - val fontWeight = CssAcceptor[String]("font-weight") - val fontFamily = CssAcceptor[String]("font-family") - - val verticalAlign = CssAcceptor[String]("vertical-align") - - val top = CssAcceptor[String]("top") - val bottom = CssAcceptor[String]("bottom") - val left = CssAcceptor[String]("left") - val right = CssAcceptor[String]("right") - - val minWidth = CssAcceptor[String]("min-width") - val maxWidth = CssAcceptor[String]("max-width") - val minHeight = CssAcceptor[String]("min-height") - val maxHeight = CssAcceptor[String]("max-height") - - val whiteSpace = CssAcceptor[String]("whiteSpace") - val overflow = CssAcceptor[String]("overflow") - - def apply(name: String) = Acceptor[String](name) - - def css(name: String) = CssAcceptor[String](name) -} -/* -object svg { - object < { - val path = Element("path", Nil(), Nil(), Nil()) - } -}*/ \ No newline at end of file diff --git a/library/leon/webDSL/webDescription/WebElement.scala b/library/leon/webDSL/webDescription/WebElement.scala deleted file mode 100644 index c6e77fa79d7085973fb3fb6fc630fc0dad2b0c27..0000000000000000000000000000000000000000 --- a/library/leon/webDSL/webDescription/WebElement.scala +++ /dev/null @@ -1,39 +0,0 @@ -package leon.webDSL.webDescription -import leon.collection._ -import leon.lang._ -import leon.annotation._ - -/** - * Created by dupriez on 3/11/16. - * - * All new subclasses of WebElement must also be registered in the pickler - * (see shared/src/main/scala/shared/Picklers (the "webElementPickler" implicit val)) - */ -sealed abstract class WebTree -sealed abstract class WebElement extends WebTree - -@library -case class Element(tag: String, sons: leon.collection.List[WebElement], properties: leon.collection.List[WebAttribute], style: leon.collection.List[WebStyle]) extends WebElement { - @isabelle.noBody() - def attr(attributeName: String): Option[String] = { - (properties.find { we => we.attributeName == attributeName }) map (_.attributeValue) - } - @isabelle.noBody() - def apply(elems: List[WebTree]): Element = { - val (sons2, properties2, style2) = leon.webDSL.webBuilding.implicits.extractElements(elems) - Element(tag, sons ++ sons2, properties ++ properties2, style ++ style2) - } - @ignore - def apply(elems: WebTree*): Element = { - var l: List[WebTree] = Nil[WebTree]() - for (e <- elems) { - l = Cons(e, l) - } - apply(l.reverse) - } -} -case class TextElement(text: String) extends WebElement -case class WebAttribute(attributeName: String, attributeValue: String) extends WebTree -case class WebStyle(attributeName: String, attributeValue: String) extends WebTree - -case class WebElementWithID(we: WebElement, id: Int) extends WebElement diff --git a/library/leon/webDSL/webDescription/WebPage.scala b/library/leon/webDSL/webDescription/WebPage.scala deleted file mode 100644 index 274b75187222e8378efd0700014941416a3d0511..0000000000000000000000000000000000000000 --- a/library/leon/webDSL/webDescription/WebPage.scala +++ /dev/null @@ -1,37 +0,0 @@ -package leon.webDSL.webDescription -/** - * Created by dupriez on 3/1/16. - */ -import leon.annotation._ -import leon.collection._ -import leon.lang._ - -case class StyleRule(target: String, rules: List[WebStyle]) - -@library -case class StyleSheet(elems: List[StyleRule]) { - @library - def apply(l: List[StyleRule]): StyleSheet = { - StyleSheet(elems ++ l) - } - @ignore - def apply(newElems: StyleRule*): StyleSheet = { - var l: List[StyleRule] = Nil[StyleRule]() - for (e <- newElems) { - l = Cons(e, l) - } - StyleSheet(elems ++ l.reverse) - } -} - -object WebPage { - @library - def apply(main: WebElement): WebPage = { - WebPage(main, StyleSheet(Nil())) - } -} - -case class WebPage(main: WebElement, css: StyleSheet) - -case class WebPageWithIDedWebElements(main: WebElementWithID, css: StyleSheet) - diff --git a/library/leon/webDSL/webDescription/WebSite.scala b/library/leon/webDSL/webDescription/WebSite.scala deleted file mode 100644 index 73929e107a246610a1775c59bb6f72821ec67936..0000000000000000000000000000000000000000 --- a/library/leon/webDSL/webDescription/WebSite.scala +++ /dev/null @@ -1,7 +0,0 @@ -package leon.webDSL.webDescription - -/** - * Created by dupriez on 5/2/16. - */ -case class WebSite(main: leon.collection.List[WebPage]) -case class WebSiteWithIDedContent(main: leon.collection.List[WebPageWithIDedWebElements]) \ No newline at end of file diff --git a/library/leon/webDSL/webDescription/package.scala b/library/leon/webDSL/webDescription/package.scala deleted file mode 100644 index ca052d39dea63af443a0e63b3e1640c0fe48ad5b..0000000000000000000000000000000000000000 --- a/library/leon/webDSL/webDescription/package.scala +++ /dev/null @@ -1,25 +0,0 @@ -package leon.webDSL -import leon.collection._ -import leon.lang._ -import leon.annotation._ - -package object webDescription { - @library - val Style = StyleSheet(Nil()) - - @library - case class StyleBuilder(name: String) { - def :=(s: List[WebStyle]) = StyleRule(name, s) - - @ignore - def :=(s: WebStyle*) = { - var l: List[WebStyle] = Nil[WebStyle]() - for (e <- s) { - l = Cons(e, l) - } - StyleRule(name, l.reverse) - } - } - - implicit def toStyleBuilder(s: String): StyleBuilder = StyleBuilder(s) -} \ No newline at end of file diff --git a/scripts/applyLicense.sh b/scripts/applyLicense.sh deleted file mode 100755 index 781901c5cffe8542ed656a479a888b3e36cee64d..0000000000000000000000000000000000000000 --- a/scripts/applyLicense.sh +++ /dev/null @@ -1,17 +0,0 @@ -printf "/* Copyright 2009-2016 EPFL, Lausanne */\n\n" > /tmp/Leon-license - -for f in $(find {src,library} -name "*.java" -o -name "*.scala") ;do - if [ -f $f ]; then - cat "/tmp/Leon-license" > /tmp/newfile - if grep -Fq "EPFL, Lausanne" "$f"; - then - tail -n +3 $f >> /tmp/newfile - else - cat $f >> /tmp/newfile - fi - if ! cmp --silent /tmp/newfile "$f"; then - echo $f - mv /tmp/newfile "$f" - fi - fi -done diff --git a/scripts/leon-gdb b/scripts/leon-gdb deleted file mode 100755 index 70fb686f150fdd3631e77081b4a80ac1220faa88..0000000000000000000000000000000000000000 --- a/scripts/leon-gdb +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash --posix -gdb /opt/oracle-jdk-bin-1.7.0.45/bin/java `ps aux | grep java | grep leon | awk '{ print $2}'` diff --git a/scripts/leon-valgrind b/scripts/leon-valgrind deleted file mode 100755 index d99de40eb41b70fc8378218e5f868687d4e222d5..0000000000000000000000000000000000000000 --- a/scripts/leon-valgrind +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash --posix -SCALACLASSPATH="/home/ekneuss/git/leon/src/main/resources:/home/ekneuss/git/leon/target/scala-2.10/classes:/home/ekneuss/git/leon/unmanaged/64/vanuatoo_2.10-0.1.jar:/home/ekneuss/git/leon/unmanaged/64/scalaz3-unix-64b-2.1.jar:/home/ekneuss/git/leon/unmanaged/64/insynth_2.10-2.1.jar:/home/ekneuss/git/leon/unmanaged/64/cafebabe_2.10-1.2.jar:/home/ekneuss/.sbt/boot/scala-2.10.2/lib/scala-library.jar:/home/ekneuss/.sbt/boot/scala-2.10.2/lib/scala-compiler.jar:/home/ekneuss/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.10.2.jar:/home/ekneuss/.ivy2/cache/com.typesafe.akka/akka-actor_2.10/jars/akka-actor_2.10-2.2.0.jar:/home/ekneuss/.ivy2/cache/com.typesafe/config/bundles/config-1.0.2.jar" - -source /home/ekneuss/git/leon/./setupenv -valgrind --trace-children=yes java -Xmx2G -Xms512M -classpath ${SCALACLASSPATH} -Dscala.home="$SCALA_HOME" -Dscala.usejavacp=true scala.tools.nsc.MainGenericRunner -classpath ${SCALACLASSPATH} leon.Main $@ 2>&1 | tee last.log diff --git a/scripts/sbt-test b/scripts/sbt-test deleted file mode 100755 index 555bfbecaa08fe019687f5158082692585486394..0000000000000000000000000000000000000000 --- a/scripts/sbt-test +++ /dev/null @@ -1,2 +0,0 @@ -sbt test integration:test regression:test 2>&1 | tee regression.log -less -r regression.log diff --git a/scripts/scalacleon b/scripts/scalacleon deleted file mode 100755 index d7c3bd25a97170ac07bbe7ca96bcd957364cd43c..0000000000000000000000000000000000000000 --- a/scripts/scalacleon +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash --posix -# Assumes: -# - Leon home is stored in PATH_TO_LEON -# - we have xargs installed -# - ${SCALA_COMPILER} is on the path -PATH_TO_LEON=".." # assume we run from Leon script directory -PATH_TO_LEON_LIB="${PATH_TO_LEON}/library/" -OUT_CLASSES_DIR="${PATH_TO_LEON}/out-classes" -SCALA_COMPILER="fsc" -mkdir -p ${OUT_CLASSES_DIR} -echo ========= Now invoking: ==================================== -echo ${SCALA_COMPILER} $(find ${PATH_TO_LEON_LIB} -name "*.scala" | xargs) $* -d ${OUT_CLASSES_DIR} -echo ============================================================ -${SCALA_COMPILER} -deprecation $(find ${PATH_TO_LEON_LIB} -name "*.scala" | xargs) $* -d ${OUT_CLASSES_DIR} -echo ========= Done. ============================================ -echo Class files generated in directory: ${OUT_CLASSES_DIR} diff --git a/scripts/scalaleon b/scripts/scalaleon deleted file mode 100755 index 58a164168d933e2777b330aafb9d9f0b240fb2cd..0000000000000000000000000000000000000000 --- a/scripts/scalaleon +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash --posix -# Assumes: -# - ${SCALA_JVM} is on the path -OUT_CLASSES_DIR="../out-classes" # assume we run from scripts directory -SCALA_RUN="scala" -if [[ -d ${OUT_CLASSES_DIR} ]] -then - ${SCALA_RUN} -cp ${OUT_CLASSES_DIR} $* -else - echo Script is designed to run after scalacleon -fi diff --git a/scripts/test-solvers b/scripts/test-solvers deleted file mode 100755 index 058d9069ad5d9cb2e88eeb46a32150aa14862234..0000000000000000000000000000000000000000 --- a/scripts/test-solvers +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -echo "Running Z3:" -T="$(date +%s)" -for f in vcs/z3*; do - z3 -in -smt2 < $f > /dev/null -done -T="$(($(date +%s)-T))" -echo "Time in seconds: ${T}" - - -echo "Testing CVC4" -T="$(date +%s)" -for f in vcs/cvc4*; do - #cvc4-master -q --produce-models --no-incremental --tear-down-incremental --dt-rewrite-error-sel --print-success --lang smt < $f > /dev/null - #cvc4-master -q --dt-binary-split --produce-models --incremental --dt-rewrite-error-sel --print-success --lang smt < $f - cvc4-master -q --decision=internal --produce-models --incremental --dt-rewrite-error-sel --print-success --lang smt < $f -done -T="$(($(date +%s)-T))" -echo "Time in seconds: ${T}" diff --git a/testcases/extern/Editor.scala b/testcases/extern/Editor.scala deleted file mode 100644 index d843697f1c362e0ef33ef4a980a785dc4418d789..0000000000000000000000000000000000000000 --- a/testcases/extern/Editor.scala +++ /dev/null @@ -1,229 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.collection._ -import scala.reflect.runtime.universe._ -import scala.reflect.api.{TypeCreator, Universe, Mirror} - - -import scala.collection.immutable.{List => ScalaList, Nil => ScalaNil} - -object Editor { - abstract class Mode - case object Edit extends Mode - case object Quitted extends Mode - - case class State(line: List[Int], cursor: Int, buffer: List[Int], actions: List[Action], mode: Mode) { - def setLine(l: List[Int]) = State(l, cursor, buffer, actions, mode) - def setCursor(c: Int) = State(line, c, buffer, actions, mode) - def setBuffer(b: List[Int]) = State(line, cursor, b, actions, mode) - def addAction(a: Action) = State(line, cursor, buffer, Cons(a, actions), mode) - def setMode(m: Mode) = State(line, cursor, buffer, actions, m) - } - - sealed abstract class Action - case object Unknown extends Action - case object Write extends Action - case object Quit extends Action - case object Replace extends Action - case object Erase extends Action - case class Content(l: List[Int]) extends Action - - @extern - def getCommand(): List[Int] = { - print("> ") - readLine().toList.map(_.toInt) - } - - @extern - def getOracle(): Oracle[Action] = { - new KeyboardOracle() - } - - def replStep(state: State): State = { - if (state.mode == Quitted) { - state - } else { - implicit val o = getOracle() - val a = { - //val a = withOracle { implicit o: Oracle[Action] => - val i = getCommand() - - getAction(i, state) - } - - val newState = doAction(state, a) - replStep(newState) - } - } - - @extern - def unknown() = { - println("?") - } - - @extern - def display(a: Action, s: State) = { - println(" | Action : "+a) - println(" | Line : "+s.line) - println(" | Curs : "+s.cursor) - println(" | Buff : "+s.buffer) - println(" | A* : "+s.actions.map(_.toString).mkString(", ")) - } - - def getAction(input: List[Int], state: State)(implicit o: Oracle[Action]): Action = { - ??? - } - - def doAction(state: State, action: Action): State = { - val c = state.cursor - val l = state.line - - val tmp = display(action, state) - - val ns = (action, state.actions) match { - case (Content(cnt), Cons(Write, _)) => - val nl = l.take(c) ++ cnt ++ l.drop(c) - state.setLine(nl).setCursor(c + cnt.size) - case (Content(cnt), Cons(Replace, _)) => - val nl = l.take(c) ++ cnt ++ l.drop(c+cnt.size) - state.setLine(nl).setCursor(c + cnt.size) - case (Erase, _) => - state.setLine(Nil()).setCursor(0) - case (Quit, _) => - state.setMode(Quitted) - case _ => - unknown() - state - } - - ns.addAction(action) - } - - @ignore - @extern - class KeyboardOracle[T: TypeTag](lvl: Int = 0) extends Oracle[T] { - var result: T = _ - - val ind = " "*lvl - - lazy val h: T = { - val m = runtimeMirror(getClass.getClassLoader) - val oracleClass = typeOf[KeyboardOracle[T]].typeSymbol.asClass - val refOracle = m.reflectClass(oracleClass) - - val ls = Erase - - val tpeClass = typeOf[T].typeSymbol.asClass - println(s"~${ind} Requesting value for (_ <: ${typeOf[T]}):") - - var askAgain = true - while (askAgain) { - if (tpeClass.isSealed) { - val TypeRef(pre, sym, tpts) = typeOf[T] - val subClasses = tpeClass.knownDirectSubclasses.toSeq.sortBy(_.name.toString) - - for ((sub, i) <- subClasses.zipWithIndex) { - println(f"~${ind} $i%2d: $sub%s") - } - - print(s"~${ind} > ") - val i = readLine().toInt - if (i >= 0 && i < subClasses.size) { - val subClass = subClasses(i).asClass - val subType = TypeRef(pre, subClass, tpts) - - val refClass = m.reflectClass(subClass) - val ctor = subType.declaration(nme.CONSTRUCTOR).asMethod - val refCtor = refClass.reflectConstructor(ctor) - val ctorTpe = ctor.typeSignatureIn(subType).asInstanceOf[MethodType] - - val rargs = for (arg <- ctorTpe.params) yield { - val argTpe = arg.typeSignature - val oracleTpe = typeRef(NoPrefix, oracleClass, List(argTpe)) - val oracleCtor = oracleTpe.declaration(nme.CONSTRUCTOR).asMethod - val refOracleCtor = refOracle.reflectConstructor(oracleCtor) - - val typeTag = TypeTag(m, new TypeCreator { - def apply[U <: Universe with Singleton](m: Mirror[U]): U#Type = { - if (m == runtimeMirror(getClass.getClassLoader)) { - argTpe.asInstanceOf[U#Type] - } else { - sys.error("Unsupported") - } - } - }) - - // Build an instance of this oracle: - val oracle = refOracleCtor(lvl+1, typeTag) - - // We call its `head` method - val head = oracleTpe.declaration(("head": TermName)).asMethod - - m.reflect(oracle).reflectMethod(head)() - } - - result = refCtor(rargs: _*).asInstanceOf[T] - askAgain = false; - } - } else if (tpeClass.name.toString == "Int") { - print(s"~${ind} > ") - try { - result = readLine().toInt.asInstanceOf[T] - askAgain = false - } catch { - case _: Throwable => - } - } else if (tpeClass.name.toString == "Boolean") { - print(s"~${ind} > ") - readLine() match { - case "true" => - result = true.asInstanceOf[T] - askAgain = false - case "false" => - result = false.asInstanceOf[T] - askAgain = false - case _ => - } - } else { - sys.error("Don't know how to generate for non-sealed class") - } - } - - result - } - - - lazy val l = new KeyboardOracle[T]() - lazy val r = new KeyboardOracle[T]() - override def head = h - override def left = l - override def right = r - } - - def repl() = { - val state = State(Nil(), 0, Nil(), Nil(), Edit) - replStep(state) - } - - @ignore - @extern - implicit def scalaToList[T](l: ScalaList[T]): List[T] = { - l.foldLeft[List[T]](Nil())( (l, e) => Cons(e, l) ) - } - - @ignore - @extern - implicit def listToScala[T](l: List[T]): ScalaList[T] = l match { - case Nil() => ScalaNil - case Cons(h, t) => h :: listToScala(t) - } - - @ignore - @extern - implicit def listToString(l: List[Int]): String = { - l.map(_.toChar).mkString("") - } - - -} diff --git a/testcases/extern/EditorSimple.scala b/testcases/extern/EditorSimple.scala deleted file mode 100644 index 888f09debaa25c7223759470105d333b30148746..0000000000000000000000000000000000000000 --- a/testcases/extern/EditorSimple.scala +++ /dev/null @@ -1,170 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.collection._ -import scala.reflect.runtime.universe._ -import scala.reflect.api.{TypeCreator, Universe, Mirror} - - -import scala.collection.immutable.{List => ScalaList, Nil => ScalaNil} - -object Editor { - abstract class Mode - case object Edit extends Mode - case object Quitted extends Mode - - case class State(line: List[Int], cursor: Int, buffer: List[Int], actions: List[Action], mode: Mode) { - def setLine(l: List[Int]) = State(l, cursor, buffer, actions, mode) - def setCursor(c: Int) = State(line, c, buffer, actions, mode) - def setBuffer(b: List[Int]) = State(line, cursor, b, actions, mode) - def addAction(a: Action) = State(line, cursor, buffer, Cons(a, actions), mode) - def setMode(m: Mode) = State(line, cursor, buffer, actions, m) - } - - sealed abstract class Action - case object Unknown extends Action - case object Write extends Action - case object Quit extends Action - case class MoveCursor(to: Int) extends Action - case object Replace extends Action - case object Erase extends Action - case class Content(l: List[Int]) extends Action - - //@extern - //def getCommand(): List[Int] = { - // print("> ") - // readLine().toList.map(_.toInt) - //} - - def getCommand()(implicit o: Oracle[List[Int]]): List[Int] = { - ??? - } - - @extern - def unknown() = { - println("?") - } - - @extern - def displayState(s: State) = { - println(" | Line : "+listToString(s.line)) - println(" | Cursor : "+(" "*s.cursor)+"^") - println(" | Buffer : "+listToString(s.buffer)) - println(" | A* : "+s.actions.collect { - case Content(l) => "Content("+listToString(l)+")" - case a => a.toString - }.mkString(", ")) - } - - @extern - def display(input: List[Int], a: Action, s: State) = { - println(" | Input : "+listToString(input)) - println(" | Action : "+a) - println(" ~~~~~~~~~~~~~~~~~~~") - displayState(s) - } - - def replStep(state: State)(implicit o: Oracle[List[Int]]): State = { - if (state.mode == Quitted) { - state - } else { - val i = getCommand() - val a = getAction(i, state) - - doAction(state, a) - } - } - - def getAction(input: List[Int], state: State): Action = { - if (input == Cons(113, Nil())) { - Quit - } else if (input == Cons(100, Nil())) { - Erase - } else if (input == Cons(94, Nil())) { - MoveCursor(0) - } else if (input == Cons(36, Nil())) { - MoveCursor(-1) - } else if (input == Cons(114, Nil())) { - Replace - } else if (input == Cons(119, Nil())) { - Write - } else if (input.size > 1) { - Content(input) - } else { - Unknown - } - } - - def doAction(state: State, action: Action): State = { - val c = state.cursor - val l = state.line - - - val ns = (action, state.actions) match { - case (Content(cnt), Cons(Write, _)) => - val nl = l.take(c) ++ cnt ++ l.drop(c) - state.setLine(nl).setCursor(c + cnt.size) - case (Content(cnt), Cons(Replace, _)) => - val nl = l.take(c) ++ cnt ++ l.drop(c+cnt.size) - state.setLine(nl).setCursor(c + cnt.size) - case (MoveCursor(i), _) => - if (i < 0) { - state.setCursor(state.line.size+1+i) - } else { - state.setCursor(i) - } - case (Erase, _) => - state.setLine(Nil()).setCursor(0) - case (Quit, _) => - state.setMode(Quitted) - case (Unknown, _) => - //unknown() - state - case _ => - state - } - - ns.addAction(action) - } - - def repl() = { - val finalState = { - withOracle { implicit o: Oracle[List[Int]] => - { - val state = State(Nil(), 0, Nil(), Nil(), Edit) - val res = replStep(replStep(replStep(state)(o.left))(o.right.left))(o.right.right.left) - val tmp = displayState(res) - res - } ensuring { - s => s.line == Cons(97, Cons(97, Cons(97, Nil()))) && s.mode == Quitted - } - } - } - finalState - } - - @ignore - @extern - implicit def scalaToList[T](l: ScalaList[T]): List[T] = { - l.foldRight[List[T]](Nil())( (e, l) => Cons(e, l) ) - } - - @ignore - @extern - implicit def listToScala[T](l: List[T]): ScalaList[T] = l match { - case Nil() => ScalaNil - case Cons(h, t) => h :: listToScala(t) - } - - @ignore - @extern - implicit def listToString(l: List[Int]): String = { - l.map(_.toChar).mkString("") - } - - @ignore - @extern - def asList(l: String): List[Int] = { - l.toList.map(_.toInt) - } -} diff --git a/testcases/extern/Game.scala b/testcases/extern/Game.scala deleted file mode 100644 index fc365d8109711e37a11ba9c5861548ec5f08ca9c..0000000000000000000000000000000000000000 --- a/testcases/extern/Game.scala +++ /dev/null @@ -1,311 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.collection._ - -object Test { - case class Pos(x: Int, y: Int) { - def up = Pos(x, y-1) - def down = Pos(x, y+1) - def left = Pos(x-1, y) - def right = Pos(x+1, y) - - // Simple over aproximation of the distance - def distance(o: Pos) = { - val dx = o.x-x - val dy = o.y-y - - (dx*dx + dy*dy) - } - - def update(a: Action) = a match { - case MoveUp => - up - case MoveDown => - down - case MoveLeft => - left - case MoveRight => - right - case Noop => - this - } - } - - case class Map(walls: Set[Pos], size: Pos) { - // Returns whether a certain position is a valid position to be in given - // the map - def isValidPos(p: Pos): Boolean = { - p.x >= 0 && p.y >= 0 && - p.x < size.x && p.y < size.y && - !(walls contains p) - } - - def allValidPos(lp: List[Pos]): Boolean = lp match { - case Cons(h, t) => isValidPos(h) && allValidPos(t) - case Nil() => true - } - } - - abstract class Action; - case object MoveUp extends Action - case object MoveDown extends Action - case object MoveLeft extends Action - case object MoveRight extends Action - case object Noop extends Action - - case class Game(player: Pos, - monsters: List[Pos], - map: Map) { - - def isValidAction(pos: Pos, action: Action) = { - val np = pos.update(action) - map.isValidPos(np) - } - - def isDead = { - isAtPositions(player, monsters) - } - - def isAtPositions(p: Pos, lp: List[Pos]): Boolean = lp match { - case Cons(h,t) => (h == p) || isAtPositions(p, t) - case _ => false - } - - def isValid = { - map.isValidPos(player) && - map.allValidPos(monsters) - } - - def isRunning = !isDead - } - - def step(g: Game)(implicit o: Oracle[Action]): Game = { - if (g.isDead) { - g - } else { - val g1 = stepPlayer(g) - Game(g1.player, stepMonsters(g1, g1.monsters), g1.map) - } - } - - def steps(g: Game, b: Int)(implicit o: Oracle[Action]): Game = { - if (b <= 0 || g.isDead) { - g - } else { - steps(step(g)(o.left), b-1)(o.right) - } - } - - def gameStep(g: Game)(implicit o: Oracle[Action]): Game = { - val u = display(g) - //withOracle { implicit o: Oracle[Action] => { - steps(g, 1) - //step(step(g)) - // step(step(g)(o.left))(o.right) - //} ensuring { g => !g.isDead }} - } - - def play(g: Game)(implicit o: Oracle[Action]): Game = { - val r = gameStep(g)(o.left) - if (r.isDead) { - r - } else { - play(r)(o.left) - } - } - - def stepMonster(g: Game, oldPos: Pos): Pos = { - val a = choose { a: Action => - bestTowards(g, oldPos, a, g.player) - } - - oldPos.update(a) - } - - def bestTowards(g: Game, old: Pos, action: Action, target: Pos): Boolean = { - def metric(a: Action): Int = { - old.update(a).distance(target) - } - - def betterThan(a: Action, other: Action): Boolean = { - !g.isValidAction(old, other) || (metric(a) <= metric(other)) - } - - g.isValidAction(old, action) && - betterThan(action, MoveUp) && - betterThan(action, MoveDown) && - betterThan(action, MoveLeft) && - betterThan(action, MoveRight) && - betterThan(action, Noop) - } - - def stepMonsters(g: Game, lp: List[Pos]): List[Pos] = lp match { - case Cons(h,t) => Cons(stepMonster(g, h), stepMonsters(g, t)) - case Nil() => Nil() - } - - def stepPlayer(g: Game)(implicit o: Oracle[Action]) = { - val action: Action = ??? - - val np = g.player.update(action) - - Game(if (g.map.isValidPos(np)) np else g.player, g.monsters, g.map) - } - - def stepPlayerTmp(g: Game) = { - val np = withOracle{ implicit o: Oracle[Action] => { - val action: Action = ??? - - g.player.update(action) - } ensuring { g.map.isValidPos(_) }} - - Game(if (g.map.isValidPos(np)) np else g.player, g.monsters, g.map) - } - - @extern - def display(g: Game): Int = { - print("\033[2J\033[1;1H") - print(" ") - for (x <- 0 until g.map.size.x) { - print(x) - } - println - print(" ╔") - for (x <- 0 until g.map.size.x) { - print('═') - } - println('╗') - for (y <- 0 until g.map.size.y) { - print(y+" ║") - for (x <- 0 until g.map.size.x) { - val c = Pos(x,y) - if (g.map.walls contains c) { - print('▒') - } else if (g.player == c) { - if (g.isDead) { - print(Console.RED+Console.BOLD+"☠"+Console.RESET) - } else { - print(Console.GREEN+"☺"+Console.RESET) - } - } else if (g.isAtPositions(c, g.monsters)) { - print(Console.RED+"X"+Console.RESET) - } else { - print(" ") - } - } - println('║') - } - print(" ╚") - for (x <- 0 until g.map.size.x) { - print('═') - } - println('╝') - - 42 - } - - @ignore - def foreach[A](l: List[A], f: A => Unit): Unit = l match { - case Cons(h, t) => f(h); foreach(t, f) - case Nil() => - } - - @extern - abstract class OracleSource[T] extends Oracle[T] { - def branch: OracleSource[T] - def value: T - - lazy val v: T = value - lazy val l: OracleSource[T] = branch - lazy val r: OracleSource[T] = branch - - override def head: T = v - override def left: Oracle[T] = l - override def right: Oracle[T] = r - } - - @extern - class Keyboard extends OracleSource[Action] { - def branch = new Keyboard - def value = { - import scala.tools.jline._ - - var askAgain = false - var action: Action = Noop - - val t = new UnixTerminal() - - try { - t.init() - - do { - if (askAgain) println("?") - askAgain = false - - t.readVirtualKey(System.in) match { - case 16 => - action = MoveUp - case 14 => - action = MoveDown - case 6 => - action = MoveRight - case 2 => - action = MoveLeft - case a => - println("Got "+a) - askAgain = true - } - - } while(askAgain) - - } finally { - t.restore() - } - - action - } - } - - @extern - class Random extends OracleSource[Action] { - def value = { - scala.util.Random.nextInt(4) match { - case 0 => - MoveUp - case 1 => - MoveDown - case 2 => - MoveLeft - case 3 => - MoveRight - case _ => - MoveUp - } - } - - def branch = new Random - } - - @extern - def getOracle(): Oracle[Action] = { - new Keyboard - } - - @extern - def pause(): Unit = { - readLine - } - - def start() = { - val map = Map(Set(Pos(2,2), Pos(2,3), Pos(4,4), Pos(5,5)), Pos(10,10)) - val monsters = Cons(Pos(8,5), Cons(Pos(6,2), Nil())) - val init = Game(Pos(0,0), monsters, map) - - val res = play(init)(getOracle()) - - val tmp = display(res) - - res - } -} diff --git a/testcases/extern/GameDemo.scala b/testcases/extern/GameDemo.scala deleted file mode 100644 index fef85891a44d37b1a29474d505709a7af53ab0c8..0000000000000000000000000000000000000000 --- a/testcases/extern/GameDemo.scala +++ /dev/null @@ -1,294 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.collection._ - -object Test { - case class Pos(x: Int, y: Int) { - def up = Pos(x, y-1) - def down = Pos(x, y+1) - def left = Pos(x-1, y) - def right = Pos(x+1, y) - - // Simple over aproximation of the distance - def distance(o: Pos) = { - val dx = o.x-x - val dy = o.y-y - - (dx*dx + dy*dy) - } - - def update(a: Action) = a match { - case MoveUp => - up - case MoveDown => - down - case MoveLeft => - left - case MoveRight => - right - case Noop => - this - } - } - - case class Map(walls: Set[Pos], size: Pos) { - // Returns whether a certain position is a valid position to be in given - // the map - def isValidPos(p: Pos): Boolean = { - p.x >= 0 && p.y >= 0 && - p.x < size.x && p.y < size.y && - !(walls contains p) - } - - def allValidPos(lp: List[Pos]): Boolean = lp match { - case Cons(h, t) => isValidPos(h) && allValidPos(t) - case Nil() => true - } - } - - abstract class Action; - case object MoveUp extends Action - case object MoveDown extends Action - case object MoveLeft extends Action - case object MoveRight extends Action - case object Noop extends Action - - case class Game(player: Pos, - monsters: List[Pos], - map: Map) { - - def isValidAction(pos: Pos, action: Action) = { - val np = pos.update(action) - map.isValidPos(np) - } - - def isDead = { - isAtPositions(player, monsters) - } - - def isAtPositions(p: Pos, lp: List[Pos]): Boolean = lp match { - case Cons(h,t) => (h == p) || isAtPositions(p, t) - case _ => false - } - - def isValid = { - map.isValidPos(player) && - map.allValidPos(monsters) - } - - def isRunning = !isDead - } - - def step(g: Game)(implicit o: Oracle[Action]): Game = { - if (g.isDead) { - g - } else { - val g1 = stepPlayer(g) - Game(g1.player, stepMonsters(g1, g1.monsters), g1.map) - } - } - - def gameStep(g: Game)(implicit o: Oracle[Action]): Game = { - val u = display(g) - //withOracle { implicit o: Oracle[Action] => { - step(g) - //} ensuring { g => !g.isDead }} - } - - def play(g: Game)(implicit o: Oracle[Action]): Game = { - val r = gameStep(g)(o.left) - if (r.isDead) { - r - } else { - play(r)(o.left) - } - } - - - def stepMonster(g: Game, oldPos: Pos): Pos = { - val a = choose { a: Action => - bestTowards(g, oldPos, a, g.player) - } - - oldPos.update(a) - } - - def stepPlayer(g: Game)(implicit o: Oracle[Action]) = { - //withOracle { implicit o: Oracle[Action] => { - val action: Action = ??? - - val np = g.player.update(action) - - Game(if (g.map.isValidPos(np)) np else g.player, g.monsters, g.map) - //} ensuring { g => !g.isDead }} - } - - def bestTowards(g: Game, old: Pos, action: Action, target: Pos): Boolean = { - def metric(a: Action): Int = { - old.update(a).distance(target) - } - - def betterThan(a: Action, other: Action): Boolean = { - !g.isValidAction(old, other) || (metric(a) <= metric(other)) - } - - g.isValidAction(old, action) && - betterThan(action, MoveUp) && - betterThan(action, MoveDown) && - betterThan(action, MoveLeft) && - betterThan(action, MoveRight) && - betterThan(action, Noop) - } - - def stepMonsters(g: Game, lp: List[Pos]): List[Pos] = lp match { - case Cons(h,t) => Cons(stepMonster(g, h), stepMonsters(g, t)) - case Nil() => Nil() - } - - @extern - def display(g: Game): Int = { - print("\033[2J\033[1;1H") - print(" ") - for (x <- 0 until g.map.size.x) { - print(x) - } - println - print(" ╔") - for (x <- 0 until g.map.size.x) { - print('═') - } - println('╗') - for (y <- 0 until g.map.size.y) { - print(y+" ║") - for (x <- 0 until g.map.size.x) { - val c = Pos(x,y) - if (g.map.walls contains c) { - print('▒') - } else if (g.player == c) { - if (g.isDead) { - print(Console.RED+Console.BOLD+"☠"+Console.RESET) - } else { - print(Console.GREEN+"☺"+Console.RESET) - } - } else if (g.isAtPositions(c, g.monsters)) { - print(Console.RED+"X"+Console.RESET) - } else { - print(" ") - } - } - println('║') - } - print(" ╚") - for (x <- 0 until g.map.size.x) { - print('═') - } - println('╝') - - 42 - } - - @ignore - def foreach[A](l: List[A], f: A => Unit): Unit = l match { - case Cons(h, t) => f(h); foreach(t, f) - case Nil() => - } - - @extern - abstract class OracleSource[T] extends Oracle[T] { - def branch: OracleSource[T] - def value: T - - lazy val v: T = value - lazy val l: OracleSource[T] = branch - lazy val r: OracleSource[T] = branch - - override def head: T = v - override def left: Oracle[T] = l - override def right: Oracle[T] = r - } - - @extern - class Keyboard extends OracleSource[Action] { - def branch = new Keyboard - def value = { - import scala.tools.jline._ - - var askAgain = false - var action: Action = Noop - - val t = new UnixTerminal() - - try { - t.init() - - do { - if (askAgain) println("?") - askAgain = false - - t.readVirtualKey(System.in) match { - case 16 => - action = MoveUp - case 14 => - action = MoveDown - case 6 => - action = MoveRight - case 2 => - action = MoveLeft - case a => - println("Got "+a) - askAgain = true - } - - } while(askAgain) - - } finally { - t.restore() - } - - action - } - } - - @extern - class Random extends OracleSource[Action] { - def value = { - scala.util.Random.nextInt(4) match { - case 0 => - MoveUp - case 1 => - MoveDown - case 2 => - MoveLeft - case 3 => - MoveRight - case _ => - MoveUp - } - } - - def branch = new Random - } - - @extern - def getOracle(): Oracle[Action] = { - new Keyboard - } - - @extern - def pause(): Unit = { - readLine - } - - def start() = { - val map = Map(Set(Pos(2,2), Pos(2,3), Pos(4,4), Pos(5,5)), Pos(10,10)) - val monsters = Cons(Pos(8,5), Cons(Pos(6,2), Nil())) - val init = Game(Pos(0,0), monsters, map) - - val res = play(init)(getOracle()) - - val tmp = display(res) - - res - } -} diff --git a/testcases/extern/GameNoSet.scala b/testcases/extern/GameNoSet.scala deleted file mode 100644 index b167933bfee929eb1f8e39d9135796f436320eef..0000000000000000000000000000000000000000 --- a/testcases/extern/GameNoSet.scala +++ /dev/null @@ -1,312 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.collection._ - -object Test { - case class Pos(x: Int, y: Int) { - def up = Pos(x, y-1) - def down = Pos(x, y+1) - def left = Pos(x-1, y) - def right = Pos(x+1, y) - - // Simple over aproximation of the distance - def distance(o: Pos) = { - val dx = o.x-x - val dy = o.y-y - - (dx*dx + dy*dy) - } - - def update(a: Action) = a match { - case MoveUp => - up - case MoveDown => - down - case MoveLeft => - left - case MoveRight => - right - case Noop => - this - } - - def isAtAny(lp: List[Pos]): Boolean = lp match { - case Cons(h,t) => (h == this) || isAtAny(t) - case _ => false - } - } - - case class Map(walls: List[Pos], size: Pos) { - // Returns whether a certain position is a valid position to be in given - // the map - def isValidPos(p: Pos): Boolean = { - p.x >= 0 && p.y >= 0 && - p.x < size.x && p.y < size.y && - !p.isAtAny(walls) - } - - def allValidPos(lp: List[Pos]): Boolean = lp match { - case Cons(h, t) => isValidPos(h) && allValidPos(t) - case Nil() => true - } - } - - abstract class Action; - case object MoveUp extends Action - case object MoveDown extends Action - case object MoveLeft extends Action - case object MoveRight extends Action - case object Noop extends Action - - case class Game(player: Pos, - monsters: List[Pos], - map: Map) { - - def isValidAction(pos: Pos, action: Action) = { - val np = pos.update(action) - map.isValidPos(np) - } - - def isDead = { - player.isAtAny(monsters) - } - - - def isValid = { - map.isValidPos(player) && - map.allValidPos(monsters) - } - - def isRunning = !isDead - } - - def step(g: Game)(implicit o: Oracle[Action]): Game = { - if (g.isDead) { - g - } else { - val g1 = stepPlayer(g) - Game(g1.player, stepMonsters(g1, g1.monsters), g1.map) - } - } - - def steps(g: Game, b: Int)(implicit o: Oracle[Action]): Game = { - if (b <= 0 || g.isDead) { - g - } else { - steps(step(g)(o.left), b-1)(o.right) - } - } - - def gameStep(g: Game)(implicit o: Oracle[Action]): Game = { - val u = display(g) - //withOracle { implicit o: Oracle[Action] => { - steps(g, 1) - //step(step(g)) - // step(step(g)(o.left))(o.right) - //} ensuring { g => !g.isDead }} - } - - def play(g: Game)(implicit o: Oracle[Action]): Game = { - val r = gameStep(g)(o.left) - if (r.isDead) { - r - } else { - play(r)(o.left) - } - } - - def stepMonster(g: Game, oldPos: Pos): Pos = { - val a = choose { a: Action => - bestTowards(g, oldPos, a, g.player) - } - - oldPos.update(a) - } - - def bestTowards(g: Game, old: Pos, action: Action, target: Pos): Boolean = { - def metric(a: Action): Int = { - old.update(a).distance(target) - } - - def betterThan(a: Action, other: Action): Boolean = { - !g.isValidAction(old, other) || (metric(a) <= metric(other)) - } - - g.isValidAction(old, action) && - betterThan(action, MoveUp) && - betterThan(action, MoveDown) && - betterThan(action, MoveLeft) && - betterThan(action, MoveRight) && - betterThan(action, Noop) - } - - def stepMonsters(g: Game, lp: List[Pos]): List[Pos] = lp match { - case Cons(h,t) => Cons(stepMonster(g, h), stepMonsters(g, t)) - case Nil() => Nil() - } - - def stepPlayer(g: Game)(implicit o: Oracle[Action]) = { - val action: Action = ??? - - val np = g.player.update(action) - - Game(if (g.map.isValidPos(np)) np else g.player, g.monsters, g.map) - } - - def stepPlayerTmp(g: Game) = { - val np = withOracle{ implicit o: Oracle[Action] => { - val action: Action = ??? - - g.player.update(action) - } ensuring { g.map.isValidPos(_) }} - - Game(if (g.map.isValidPos(np)) np else g.player, g.monsters, g.map) - } - - @extern - def display(g: Game): Int = { - print("\033[2J\033[1;1H") - print(" ") - for (x <- 0 until g.map.size.x) { - print(x) - } - println - print(" ╔") - for (x <- 0 until g.map.size.x) { - print('═') - } - println('╗') - for (y <- 0 until g.map.size.y) { - print(y+" ║") - for (x <- 0 until g.map.size.x) { - val c = Pos(x,y) - if (c.isAtAny(g.map.walls)) { - print('▒') - } else if (g.player == c) { - if (g.isDead) { - print(Console.RED+Console.BOLD+"☠"+Console.RESET) - } else { - print(Console.GREEN+"☺"+Console.RESET) - } - } else if (c.isAtAny(g.monsters)) { - print(Console.RED+"X"+Console.RESET) - } else { - print(" ") - } - } - println('║') - } - print(" ╚") - for (x <- 0 until g.map.size.x) { - print('═') - } - println('╝') - - 42 - } - - @ignore - def foreach[A](l: List[A], f: A => Unit): Unit = l match { - case Cons(h, t) => f(h); foreach(t, f) - case Nil() => - } - - @extern - abstract class OracleSource[T] extends Oracle[T] { - def branch: OracleSource[T] - def value: T - - lazy val v: T = value - lazy val l: OracleSource[T] = branch - lazy val r: OracleSource[T] = branch - - override def head: T = v - override def left: Oracle[T] = l - override def right: Oracle[T] = r - } - - @extern - class Keyboard extends OracleSource[Action] { - def branch = new Keyboard - def value = { - import scala.tools.jline._ - - var askAgain = false - var action: Action = Noop - - val t = new UnixTerminal() - - try { - t.init() - - do { - if (askAgain) println("?") - askAgain = false - - t.readVirtualKey(System.in) match { - case 16 => - action = MoveUp - case 14 => - action = MoveDown - case 6 => - action = MoveRight - case 2 => - action = MoveLeft - case a => - println("Got "+a) - askAgain = true - } - - } while(askAgain) - - } finally { - t.restore() - } - - action - } - } - - @extern - class Random extends OracleSource[Action] { - def value = { - scala.util.Random.nextInt(4) match { - case 0 => - MoveUp - case 1 => - MoveDown - case 2 => - MoveLeft - case 3 => - MoveRight - case _ => - MoveUp - } - } - - def branch = new Random - } - - @extern - def getOracle(): Oracle[Action] = { - new Keyboard - } - - @extern - def pause(): Unit = { - readLine - } - - def start() = { - val map = Map(Cons(Pos(2,2), Cons(Pos(2,3), Nil())), Pos(10,10)) - val monsters = Cons(Pos(8,5), Cons(Pos(6,2), Nil())) - val init = Game(Pos(0,0), monsters, map) - - val res = play(init)(getOracle()) - - val tmp = display(res) - - res - } -} diff --git a/testcases/extern/GameSimpler.scala b/testcases/extern/GameSimpler.scala deleted file mode 100644 index 6249ad535ddf00bf061b7ce3b215d1f73dc3de17..0000000000000000000000000000000000000000 --- a/testcases/extern/GameSimpler.scala +++ /dev/null @@ -1,293 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.collection._ - -object Test { - case class Pos(x: Int, y: Int) { - def up = Pos(x, y-1) - def down = Pos(x, y+1) - def left = Pos(x-1, y) - def right = Pos(x+1, y) - - // Simple over aproximation of the distance - def distance(o: Pos) = { - val dx = o.x-x - val dy = o.y-y - - (dx*dx + dy*dy) - } - - def update(a: Action) = a match { - case MoveUp => - up - case MoveDown => - down - case MoveLeft => - left - case MoveRight => - right - case Noop => - this - } - } - - case class Map(size: Pos) { - // Returns whether a certain position is a valid position to be in given - // the map - def isValidPos(p: Pos): Boolean = { - p.x >= 0 && p.y >= 0 && - p.x < size.x && p.y < size.y - } - } - - abstract class Action; - case object MoveUp extends Action - case object MoveDown extends Action - case object MoveLeft extends Action - case object MoveRight extends Action - case object Noop extends Action - - case class Game(player: Pos, - monster: Pos, - map: Map) { - - def isValidAction(pos: Pos, action: Action) = { - val np = pos.update(action) - map.isValidPos(np) - } - - def isDead = { - player == monster - } - - def isValid = { - map.isValidPos(player) && - map.isValidPos(monster) - } - - def isRunning = !isDead - } - - def step(g: Game)(implicit o: Oracle[Action]): Game = { - if (g.isDead) { - g - } else { - val g1 = stepPlayer(g) - Game(g1.player, stepMonster(g1, g1.monster), g1.map) - } - } - - def steps(g: Game, b: Int)(implicit o: Oracle[Action]): Game = { - if (b <= 0 || g.isDead) { - g - } else { - steps(step(g)(o.left), b-1)(o.right) - } - } - - def gameStep(g: Game)(implicit o: Oracle[Action]): Game = { - val u = display(g) - withOracle { implicit o: Oracle[Action] => { - steps(g, 2) - //step(step(g)) - // step(step(g)(o.left))(o.right) - } ensuring { g => !g.isDead }} - } - - def play(g: Game)(implicit o: Oracle[Action]): Game = { - val r = gameStep(g)(o.left) - if (r.isDead) { - r - } else { - play(r)(o.left) - } - } - - def stepMonster(g: Game, oldPos: Pos): Pos = { - val a = choose { a: Action => - bestTowards(g, oldPos, a, g.player) - } - - oldPos.update(a) - } - - def bestTowards(g: Game, old: Pos, action: Action, target: Pos): Boolean = { - def metric(a: Action): Int = { - old.update(a).distance(target) - } - - def betterThan(a: Action, other: Action): Boolean = { - !g.isValidAction(old, other) || (metric(a) <= metric(other)) - } - - g.isValidAction(old, action) && - betterThan(action, MoveUp) && - betterThan(action, MoveDown) && - betterThan(action, MoveLeft) && - betterThan(action, MoveRight) && - betterThan(action, Noop) - } - - - def stepPlayer(g: Game)(implicit o: Oracle[Action]) = { - val action: Action = ??? - - val np = g.player.update(action) - - Game(if (g.map.isValidPos(np)) np else g.player, g.monster, g.map) - } - - def stepPlayerTmp(g: Game) = { - val np = withOracle{ implicit o: Oracle[Action] => { - val action: Action = ??? - - g.player.update(action) - } ensuring { g.map.isValidPos(_) }} - - Game(if (g.map.isValidPos(np)) np else g.player, g.monster, g.map) - } - - @extern - def display(g: Game): Int = { - print("\033[2J\033[1;1H") - print(" ") - for (x <- 0 until g.map.size.x) { - print(x) - } - println - print(" ╔") - for (x <- 0 until g.map.size.x) { - print('═') - } - println('╗') - for (y <- 0 until g.map.size.y) { - print(y+" ║") - for (x <- 0 until g.map.size.x) { - val c = Pos(x,y) - if (g.player == c) { - if (g.isDead) { - print(Console.RED+Console.BOLD+"☠"+Console.RESET) - } else { - print(Console.GREEN+"☺"+Console.RESET) - } - } else if (c == g.monster) { - print(Console.RED+"X"+Console.RESET) - } else { - print(" ") - } - } - println('║') - } - print(" ╚") - for (x <- 0 until g.map.size.x) { - print('═') - } - println('╝') - - 42 - } - - @ignore - def foreach[A](l: List[A], f: A => Unit): Unit = l match { - case Cons(h, t) => f(h); foreach(t, f) - case Nil() => - } - - @extern - abstract class OracleSource[T] extends Oracle[T] { - def branch: OracleSource[T] - def value: T - - lazy val v: T = value - lazy val l: OracleSource[T] = branch - lazy val r: OracleSource[T] = branch - - override def head: T = v - override def left: Oracle[T] = l - override def right: Oracle[T] = r - } - - @extern - class Keyboard extends OracleSource[Action] { - def branch = new Keyboard - def value = { - import scala.tools.jline._ - - var askAgain = false - var action: Action = Noop - - val t = new UnixTerminal() - - try { - t.init() - - do { - if (askAgain) println("?") - askAgain = false - - t.readVirtualKey(System.in) match { - case 16 => - action = MoveUp - case 14 => - action = MoveDown - case 6 => - action = MoveRight - case 2 => - action = MoveLeft - case a => - println("Got "+a) - askAgain = true - } - - } while(askAgain) - - } finally { - t.restore() - } - - action - } - } - - @extern - class Random extends OracleSource[Action] { - def value = { - scala.util.Random.nextInt(4) match { - case 0 => - MoveUp - case 1 => - MoveDown - case 2 => - MoveLeft - case 3 => - MoveRight - case _ => - MoveUp - } - } - - def branch = new Random - } - - @extern - def getOracle(): Oracle[Action] = { - new Keyboard - } - - @extern - def pause(): Unit = { - readLine - } - - def start() = { - val map = Map(Pos(10,10)) - val init = Game(Pos(0,0), Pos(3, 3), map) - - val res = play(init)(getOracle()) - - val tmp = display(res) - - res - } -} diff --git a/testcases/extern/features.scala b/testcases/extern/features.scala deleted file mode 100644 index 6b3db19119aed089997bcec2592e8147e8222a19..0000000000000000000000000000000000000000 --- a/testcases/extern/features.scala +++ /dev/null @@ -1,102 +0,0 @@ -package testextern - -import leon.lang._ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.collection._ - -object ExternTest { - // All types 1 - def test1() = { - allTypes1(false, (1,2), ExternFoo(12), Bar(false)) - } - - // All types 2 - def test2() = { - allTypes2(Set(1,2,3), Map(1->2)) - } - - // External function calling back - def test3() = { - testCallBack(51); - } - - // External method - def test4() = { - Test(12).bar(21) - } - - // Generics - def test5() = { - id(List[BigInt](1,2,3)).tail.head == 2 - } - - // Name encoding - def test6() = { - +*/!(1,2) - } - - // Unit1 - def test7() = { - testUnit(1, (), ((), 3)) - } - - - def leonFun(a: BigInt): BigInt = { - choose((x: BigInt) => x > a && x <= a+1) - } - - - - // External functions - - @extern - def testCallBack(a: BigInt): BigInt = { - val f = new scala.collection.mutable.ArrayBuffer[BigInt]() - leonFun(a+1) - } - - @extern - def +*/!(a: Int, b: BigInt): BigInt = { - println("asd") - b+b - } - - @extern - def allTypes1(a: Boolean, b: (BigInt, BigInt), c: ExternFoo, d: Bar): (Boolean, (BigInt, BigInt), ExternFoo, Bar) = { - println("asd") - (a,b,c,d) - } - - @extern - def allTypes2(s: Set[Int], m: Map[Int, Int]): (Set[Int], Map[Int, Int]) = { - println("asd") - (s,m) - } - - @extern - def id[T](a: T): T = { - println("asd") - a - } - - @extern - def testUnit(a: Int, b: Unit, c: (Unit, Int)): Unit = { - println("asd") - b - } - - case class Test(a: Int) { - @extern - def bar(b: BigInt): BigInt = { - println("asd") - b*4+a - } - } - - case class Bar(b: Boolean); -} - -case class ExternFoo(a: BigInt) { - def leonMethod(z: Int): Int = z -} diff --git a/testcases/graveyard/BinarySearchTree.scala b/testcases/graveyard/BinarySearchTree.scala deleted file mode 100644 index 452e21a260f16cba9361f10effded80aa7738ce6..0000000000000000000000000000000000000000 --- a/testcases/graveyard/BinarySearchTree.scala +++ /dev/null @@ -1,187 +0,0 @@ -import scala.collection.immutable.Set -//import scala.collection.immutable.Multiset - -object BinarySearchTree { - sealed abstract class Tree - case class Node(left: Tree, value: Int, right: Tree) extends Tree - case class Leaf() extends Tree - - def emptySet(): Tree = Leaf() - - sealed abstract class Option - case class None() extends Option - case class Some(value: Int) extends Option - - sealed abstract class Triple - case class SortedTriple(min: Option, max: Option, sorted: Boolean) extends Triple - - def isSorted(tree: Tree): SortedTriple = (tree match { - case Leaf() => SortedTriple(None(), None(), true) - case Node(l, v, r) => isSorted(l) match { - case SortedTriple(minl, maxl, sortl) => if (!sortl) SortedTriple(None(), None(), false) - else minl match { - case None() => maxl match { - case None() => isSorted(r) match { - case SortedTriple(minr, maxr, sortr) => if (!sortr) SortedTriple(None(), None(), false) - else minr match { - case None() => maxr match { - case None() => SortedTriple(Some(v), Some(v), true) - case Some(maxrv) => SortedTriple(None(), None(), false) - } - case Some(minrv) => maxr match { - case Some(maxrv) => if (minrv > v) SortedTriple(Some(v), Some(maxrv), true) else SortedTriple(None(), None(), false) - case None() => SortedTriple(None(), None(), false) - } - } - } - case Some(maxlv) => SortedTriple(None(), None(), false) - } - case Some(minlv) => maxl match { - case Some(maxlv) => isSorted(r) match { - case SortedTriple(minr, maxr, sortr) => if (!sortr) SortedTriple(None(), None(), false) - else minr match { - case None() => maxr match { - case None() => if (maxlv <= v) SortedTriple(Some(minlv), Some(v), true) else SortedTriple(None(), None(), false) - case Some(maxrv) => SortedTriple(None(), None(), false) - } - case Some(minrv) => maxr match { - case Some(maxrv) => if (maxlv <= v && minrv > v) SortedTriple(Some(minlv), Some(maxrv), true) else SortedTriple(None(), None(), false) - case None() => SortedTriple(None(), None(), false) - } - } - } - case None() => SortedTriple(None(), None(), false) - } - } - } - }) ensuring (res => res match { case SortedTriple(min,max,sort) => min match { - case None() => res == SortedTriple(None(),None(),sort) - case Some(minv) => max match { - case None() => false - case Some(maxv) => sort && minv <= maxv}}}) - - def treeMin(tree: Node): Int = { - require(isSorted(tree).sorted) - tree match { - case Node(left, v, _) => left match { - case Leaf() => v - case n@Node(_, _, _) => treeMin(n) - } - } - } ensuring (_ == contents(tree).min) - - def treeMax(tree: Node): Int = { - require(isSorted(tree).sorted) - tree match { - case Node(_, v, right) => right match { - case Leaf() => v - case n@Node(_, _, _) => treeMax(n) - } - } - } ensuring (_ == contents(tree).max) - - def insert(tree: Tree, value: Int): Node = { - tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case n@Node(l, v, r) => if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - n - } - } - } ensuring (contents(_) == contents(tree) ++ Set(value)) - - def cleanInsert(tree: Tree, value: Int) : Tree = (tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case Node(l, v, r) if v < value => Node(l, v, cleanInsert(r, value)) - case Node(l, v, r) if v > value => Node(cleanInsert(l, value), v, r) - case n @ Node(l, v, r) if v == value => n - }) ensuring(contents(_) == contents(tree) ++ Set(value)) - - def insertSorted(tree: Tree, value: Int): Node = { - require(isSorted(tree).sorted) - tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case n@Node(l, v, r) => if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - n - } - } - } ensuring (res => contents(res) == contents(tree) ++ Set(value) && isSorted(res).sorted) - - def dumbInsert(tree: Tree): Node = { - tree match { - case Leaf() => Node(Leaf(), 0, Leaf()) - case Node(l, e, r) => Node(dumbInsert(l), e, r) - } - } ensuring (contents(_) == contents(tree) ++ Set(0)) - - /* - def remove(tree: Tree, value: Int) : Node = (tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case n @ Node(l, v, r) => if(v < value) { - Node(l, v, insert(r, value)) - } else if(v > value) { - Node(insert(l, value), v, r) - } else { - n - } - }) ensuring (contents(_) == contents(tree) -- Set(value)) - */ - - def dumbInsertWithOrder(tree: Tree): Node = { - tree match { - case Leaf() => Node(Leaf(), 0, Leaf()) - case Node(l, e, r) => Node(dumbInsert(l), e, r) - } - } ensuring (res => {val S = contents(res); S == contents(tree) ++ Set(0) && S.min <= 0 && S.max >= 0}) - - - def createRoot(v: Int): Node = { - Node(Leaf(), v, Leaf()) - } ensuring (contents(_) == Set(v)) - - /* - def remove(tree: Tree, value: Int) : Node = (tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case n @ Node(l, v, r) => if(v < value) { - Node(l, v, insert(r, value)) - } else if(v > value) { - Node(insert(l, value), v, r) - } else { - n - } - }) ensuring (contents(_) == contents(tree) -- Set(value)) - */ - - def mkInfiniteTree(x: Int): Node = { - Node(mkInfiniteTree(x), x, mkInfiniteTree(x)) - } ensuring (res => - res.left != Leaf() && res.right != Leaf() - ) - - def contains(tree: Tree, value: Int): Boolean = { - require(isSorted(tree).sorted) - tree match { - case Leaf() => false - case n@Node(l, v, r) => if (v < value) { - contains(r, value) - } else if (v > value) { - contains(l, value) - } else { - true - } - } - } ensuring (_ || !(contents(tree) == contents(tree) ++ Set(value))) - - def contents(tree: Tree): Set[Int] = tree match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => contents(l) ++ Set(v) ++ contents(r) - } -} - diff --git a/testcases/graveyard/Choose.scala b/testcases/graveyard/Choose.scala deleted file mode 100644 index 7e69f6d92c7008ad29d76fae9dbf9cc4e489e4e2..0000000000000000000000000000000000000000 --- a/testcases/graveyard/Choose.scala +++ /dev/null @@ -1,19 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChooseTest { - - def c0(): Int = choose{ (x1: Int) => x1 > 13 } - def b0(): Int = choose{ (x1: Int) => x1 > 13 && x1 < 2 } - - def t0(a: Int): Int = choose{ (x1: Int) => (a > 13 && x1 == 2) || (a < 2 && x1 == 0) } - - def c1(a: Int): Int = choose{ (x1: Int) => x1 > a } - def c2(a: Int): (Int, Int) = choose{ (x1: Int, x2: Int) => x1 > a && x2 > a } - def c3(a: Int): (Int, Int, Int) = choose{ (x1: Int, x2: Int, x3: Int) => x1 > a && x2 > a } - def c4(a: Int): (Int, Int, Int, Int) = choose{ (x1: Int, x2: Int, x3: Int, x4: Int) => x1 > a && x2 > a } - def c5(a: Int): (Int, Int, Int, Int, Int) = choose{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1 > a && x2 > a } - - def z0(a: Int): (Int, Int, List) = choose{ (x1: Int, x2: Int, x3: List) => x1 > a && x2 > a } - -} diff --git a/testcases/graveyard/ConnectedTest.scala b/testcases/graveyard/ConnectedTest.scala deleted file mode 100644 index f67ebb8cbff8a6cb4c49037101857a99ac29d3b5..0000000000000000000000000000000000000000 --- a/testcases/graveyard/ConnectedTest.scala +++ /dev/null @@ -1,34 +0,0 @@ -import scala.collection.immutable.Set -import leon.lang._ -import leon.annotation._ - -object VerySimple { - sealed abstract class L0 - case class Adad( a: L3) extends L0 - - sealed abstract class L1 - case class Cons(a : L2, b : L3) extends L1 - case class Nil() extends L1 - - sealed abstract class L6 - case class Adadasdad(b : L5) extends L6 - - - - sealed abstract class L2 - case class IPCons(a : L4) extends L2 - case class IPNil() extends L2 - - - sealed abstract class L5 - case class sada55( a: L2, b : L6) extends L5 - - - - sealed abstract class L3 - case class IP(a : L0) extends L3 - - sealed abstract class L4 - case class Hopa(mizerie: L3 , a : L1) extends L4 - -} diff --git a/testcases/graveyard/Expr2Comp.scala b/testcases/graveyard/Expr2Comp.scala deleted file mode 100644 index 1f3afbb930cc205d70f7e3c80e68548a5d74fd07..0000000000000000000000000000000000000000 --- a/testcases/graveyard/Expr2Comp.scala +++ /dev/null @@ -1,124 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object ExprComp { - // Lists - - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - // Operations - sealed abstract class BinOp - case class Plus() extends BinOp - case class Times() extends BinOp - - // Expressions - sealed abstract class Expr - case class Constant(v : Int) extends Expr - case class Binary(exp1 : Expr, op : BinOp, exp2 : Expr) extends Expr - - def exprSize(e: Expr) : Int = (e match { - case Constant(_) => 1 - case Binary(e1, _, e2) => 1 + exprSize(e1) + exprSize(e2) - }) ensuring(_ >= 1) - - def evalOp(v1 : Int, op : BinOp, v2 : Int) : Int = op match { - case Plus() => v1 + v2 - case Times() => v1 * v2 - } - - // Expression evaluation - - def eval(e : Expr) : Int = e match { - case Constant(v) => v - case Binary(e1,op,e2) => evalOp(eval(e1),op,eval(e2)) - } - - // Instructions - - sealed abstract class Instruction - case class PushVal(v : Int) extends Instruction - case class ApplyBinOp(op : BinOp) extends Instruction - - // Programs - - sealed abstract class Program - case class EProgram() extends Program - case class NProgram(first : Instruction, rest : Program) extends Program - - def progSize(p: Program) : Int = (p match { - case EProgram() => 0 - case NProgram(_, r) => 1 + progSize(r) - }) ensuring(_ >= 0) - - // Running programs on a given initial stack - - def run(p : Program, vs : List) : Int = p match { - case EProgram() => vs match { - case Nil() => -1 - case Cons(top,_) => top - } - case NProgram(PushVal(v),rest) => run(rest, Cons(v,vs)) - case NProgram(ApplyBinOp(op),rest) => vs match { - case Cons(v1, Cons(v2, vs1)) => run(rest, Cons(evalOp(v1, op, v2),vs1)) - case Cons(_,Nil()) => -1 - case Nil() => -1 - } - } - - // Compiling expressions to programs - - def compile(e : Expr, acc : Program) : Program = e match { - case Constant(v) => NProgram(PushVal(v), acc) - case Binary(e1,op,e2) => compile(e1,compile(e2,NProgram(ApplyBinOp(op),acc))) - } - -/* -) ensuring (res => { - val rv = run(res, Nil()) - val ev = run(acc, Cons(eval(e),Nil())) - if (rv != ev) { println(" e = " + e + "\n res = " + res + ",\n rv = " + rv + ",\n ev = " + ev); false } else true - }) -*/ - - def compile0(e : Expr) : Program = compile(e, EProgram()) - -/* - def property(e : Expr, acc : Program, vs : IntStack) : Boolean = { - require(exprSize(e) <= 1 && progSize(acc) <= 1 && stackSize(vs) <= 1) - run(compile(e, acc), vs) == Ok(NStack(eval(e), vs)) - } holds - - def property0() : Boolean = { - val e = Binary(Constant(3), Plus(), Constant(5)) - val vs = EStack() - val acc = EProgram() - run(compile(e, acc), vs) == Ok(NStack(eval(e), vs)) - } holds - -*/ - - @induct - def property(e: Expr, acc : Program, vs : List) : Boolean = { - run(compile(e, acc), vs) == run(acc, Cons(eval(e), vs)) - } holds - - def propertyBounded(e: Expr) : Boolean = { - require(exprSize(e) <= 3) - run(compile(e, EProgram()), Nil()) == eval(e) - } holds - - def main(args : Array[String]) = { - val e1 = Binary(Constant(100), Times(), Binary(Constant(3), Plus(), Constant(5))) - // thanks to Leon: - val e = Binary(Binary(Binary(Binary(Constant(75), Plus(), Constant(69)), Times(), Binary(Constant(73), Plus(), Constant(71))), Times(), Binary(Binary(Constant(70), Plus(), Constant(77)), Times(), Binary(Constant(68), Plus(), Constant(66)))), Plus(), Binary(Constant(1), Plus(), Binary(Constant(0), Times(), Binary(Constant(65), Plus(), Constant(72))))) - val acc = EProgram() - val vs = Cons(42,Nil()) - val ev = eval(e) - val code = compile(e,acc) - val cv = run(code, vs) - println(ev) - println(cv) - } -} diff --git a/testcases/graveyard/ExprComp.scala b/testcases/graveyard/ExprComp.scala deleted file mode 100644 index 5309935d66cd08ce8b9d9068fbe6f71f57a81e43..0000000000000000000000000000000000000000 --- a/testcases/graveyard/ExprComp.scala +++ /dev/null @@ -1,168 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object ExprComp { - - // Values - sealed abstract class Whatever - case class Value(v : Int) extends Whatever - - // Operations - sealed abstract class BinOp - case class Plus() extends BinOp - case class Times() extends BinOp - - // Expressions - sealed abstract class Expr - case class Constant(v : Value) extends Expr - case class Binary(exp1 : Expr, op : BinOp, exp2 : Expr) extends Expr - - def exprSize(e: Expr) : Int = (e match { - case Constant(_) => 1 - case Binary(e1, _, e2) => 1 + exprSize(e1) + exprSize(e2) - }) ensuring(_ >= 1) - - def evalOp(v1 : Value, op : BinOp, v2 : Value) : Value = op match { - case Plus() => Value(v1.v + v2.v) - case Times() => Value(v1.v * v2.v) - } - - // Expression evaluation - - def eval(e : Expr) : Value = e match { - case Constant(v) => v - case Binary(e1,op,e2) => evalOp(eval(e1),op,eval(e2)) - } - - // Instructions - - sealed abstract class Instruction - case class PushVal(v : Value) extends Instruction - case class ApplyBinOp(op : BinOp) extends Instruction - - // Programs - - sealed abstract class Program - case class EProgram() extends Program - case class NProgram(first : Instruction, rest : Program) extends Program - - def progSize(p: Program) : Int = (p match { - case EProgram() => 0 - case NProgram(_, r) => 1 + progSize(r) - }) ensuring(_ >= 0) - - // Value stack - - sealed abstract class ValueStack - case class EStack() extends ValueStack - case class NStack(v : Value, rest : ValueStack) extends ValueStack - - def stackSize(vs: ValueStack) : Int = (vs match { - case EStack() => 0 - case NStack(_, r) => 1 + stackSize(r) - }) ensuring(_ >= 0) - - // Outcomes of running the program - - sealed abstract class Outcome - case class Ok(v : ValueStack) extends Outcome - case class Fail(v : ValueStack, i : Instruction) extends Outcome - - - // Running programs on a given initial stack - def run(p : Program, vs : ValueStack) : Outcome = p match { - case EProgram() => Ok(vs) - case NProgram(i,rest) => - val oRest = run(rest, vs) - oRest match { - case Fail(_,_) => oRest - case Ok(vRest) => - i match { - case PushVal(v) => Ok(NStack(v,vRest)) - case ApplyBinOp(op) => vRest match { - case EStack() => Fail(vRest, i) - case NStack(v1,vs1) => vs1 match { - case EStack() => Fail(vRest, i) - case NStack(v2,vs2) => Ok(NStack(evalOp(v1,op,v2),vs2)) - } - } - } - } - - } - - -// --- this does not work; do not know why - def property_trivial() : Boolean = { - run(EProgram() , EStack() ) == Ok(EStack()) - } holds - - - - def run0(p : Program) = run(p, EStack()) - - // Compiling expressions to programs - - def compile(e : Expr, acc : Program) : Program = (e match { - case Constant(v) => NProgram(PushVal(v), acc) - case Binary(e1,op,e2) => NProgram(ApplyBinOp(op),compile(e2,compile(e1,acc))) - }) // ensuring (res => (run(res, EStack()) == Ok(NStack(eval(e), EStack())))) - // should be forall vs. ... vs ... instead of EStack() above. - - def compile0(e : Expr) : Program = compile(e, EProgram()) - -/* - def property(e : Expr, acc : Program, vs : ValueStack) : Boolean = { - require(exprSize(e) <= 1 && progSize(acc) <= 1 && stackSize(vs) <= 1) - run(compile(e, acc), vs) == Ok(NStack(eval(e), vs)) - } holds - -*/ - - - -/// --- here it goes bad - def property0() : Boolean = { - val e = Binary(Constant(Value(3)), Plus(), Constant(Value(5))) - val vs = EStack() - val acc = EProgram() - run(compile(e, acc), vs) == Ok(NStack(eval(e), vs)) - } //holds - - -//this induction should work (at least on paper it goes ok) - @induct - def property_general(e: Expr, prog:Program) : Boolean = { - val vs = EStack() - val result = run(prog, vs) - result match{ - case Ok(vv) => run(compile(e, prog), vs) == Ok(NStack(eval(e), vv)) - case _ => true - } - } holds - - - - - @induct - def property1(e: Expr) : Boolean = { - val vs = EStack() - run(compile(e, EProgram()), vs) == Ok(NStack(eval(e), vs)) - } holds - -// def property2(e: Expr, vs: ValueStack) : Boolean = { -// run(compile(e, EProgram()), vs) == Ok(NStack(eval(e), vs)) -// } holds -/* - def main(args : Array[String]) = { - val e = Binary(Constant(Value(100)), Times(), Binary(Constant(Value(3)), Plus(), Constant(Value(5)))) - val vs = EStack() - val acc = EProgram() - println(compile(e,acc)) - println(run(compile(e, acc), vs)) - println(Ok(NStack(eval(e), vs))) - assert(property(e,acc,vs)) - } - */ - -} diff --git a/testcases/graveyard/PaperDemoExample.scala b/testcases/graveyard/PaperDemoExample.scala deleted file mode 100644 index a55c26f48814b811bc42c157b1b7a117c9367c7f..0000000000000000000000000000000000000000 --- a/testcases/graveyard/PaperDemoExample.scala +++ /dev/null @@ -1,19 +0,0 @@ -object PaperDemoexample { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def size(l: List) : Int = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def sizeTailRec(l: List) : Int = sizeAcc(l, 0) - def sizeAcc(l: List, acc: Int) : Int = { - require(acc >= 0) - l match { - case Nil() => acc - case Cons(_, xs) => sizeAcc(xs, acc+1) - } - } ensuring(res => res == size(l) + acc) -} diff --git a/testcases/graveyard/Sat.scala b/testcases/graveyard/Sat.scala deleted file mode 100644 index 9e19d46667ad7dce612407248ce5a8f7bd182377..0000000000000000000000000000000000000000 --- a/testcases/graveyard/Sat.scala +++ /dev/null @@ -1,322 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object Sat { - - sealed abstract class Formula - case class And(f1: Formula, f2: Formula) extends Formula - case class Or(f1: Formula, f2: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Var(i: Int) extends Formula - - //vars are numbered from 2 to n+1, and Not(Var(n)) is represented as -n. 1 is true and -1 is false - sealed abstract class VarList - case class VarCons(head: Int, tail: VarList) extends VarList - case class VarNil() extends VarList - case class VarLit(value: Boolean) extends VarList - - sealed abstract class ClauseList - case class ClauseCons(head: VarList, tail: ClauseList) extends ClauseList - case class ClauseNil() extends ClauseList - case class ClauseLit(value: Boolean) extends ClauseList - - def eval(formula: Formula, trueVars: Set[Int]): Boolean = formula match { - case Var(n) => if(n == 1) true else if(n == -1) false else trueVars.contains(n) - case Not(f) => !eval(f, trueVars) - case And(f1, f2) => eval(f1, trueVars) && eval(f2, trueVars) - case Or(f1, f2) => eval(f1, trueVars) || eval(f2, trueVars) - } - - //buggy version of eval - def evalWrong(formula: Formula, trueVars: Set[Int]): Boolean = formula match { - case Var(n) => trueVars.contains(n) //bug - case Not(f) => !eval(f, trueVars) - case And(f1, f2) => eval(f1, trueVars) && eval(f2, trueVars) - case Or(f1, f2) => eval(f1, trueVars) || eval(f2, trueVars) - } - - def evalCnf(clauses: ClauseList, trueVars: Set[Int]): Boolean = clauses match { - case ClauseCons(cl, cls) => evalClauseCnf(cl, trueVars) && evalCnf(cls, trueVars) - case ClauseNil() => true - case ClauseLit(b) => b - } - def evalDnf(clauses: ClauseList, trueVars: Set[Int]): Boolean = clauses match { - case ClauseCons(cl, cls) => evalClauseDnf(cl, trueVars) || evalDnf(cls, trueVars) - case ClauseNil() => false - case ClauseLit(b) => b - } - - //buggy version of evalCnf/Dnf - def evalCnfWrong(clauses: ClauseList, trueVars: Set[Int]): Boolean = clauses match { - case ClauseCons(cl, cls) => evalClauseCnf(cl, trueVars) && evalCnf(cls, trueVars) - case ClauseNil() => false //bug - case ClauseLit(b) => b - } - def evalDnfWrong(clauses: ClauseList, trueVars: Set[Int]): Boolean = clauses match { - case ClauseCons(cl, cls) => evalClauseDnf(cl, trueVars) || evalDnf(cls, trueVars) - case ClauseNil() => true //bug - case ClauseLit(b) => b - } - - def evalClauseCnf(clause: VarList, trueVars: Set[Int]): Boolean = clause match { - case VarCons(v, vs) => (if(v < 0) trueVars.contains(-v) else trueVars.contains(v)) || evalClauseCnf(vs, trueVars) - if(v == 1) true - else if(v == -1) evalClauseCnf(vs, trueVars) - else if(v < -1) !trueVars.contains(-v) || evalClauseCnf(vs, trueVars) - else if(v > 1) trueVars.contains(v) || evalClauseCnf(vs, trueVars) - else false - case VarNil() => false - case VarLit(b) => b - } - def evalClauseDnf(clause: VarList, trueVars: Set[Int]): Boolean = clause match { - case VarCons(v, vs) => { - if(v == 1) evalClauseDnf(vs, trueVars) - else if(v == -1) false - else if(v < -1) !trueVars.contains(-v) && evalClauseDnf(vs, trueVars) - else if(v > 1) trueVars.contains(v) && evalClauseDnf(vs, trueVars) - else false - } - case VarNil() => true - case VarLit(b) => b - } - - //buggy version of evalClauses - def evalClauseCnfWrong(clause: VarList, trueVars: Set[Int]): Boolean = clause match { - case VarCons(v, vs) => (if(v < 0) trueVars.contains(-v) else trueVars.contains(v)) || evalClauseCnf(vs, trueVars) - if(v == 1) true - else if(v == -1) evalClauseCnf(vs, trueVars) - else if(v < -1) trueVars.contains(-v) || evalClauseCnf(vs, trueVars) //bug - else if(v > 1) trueVars.contains(v) || evalClauseCnf(vs, trueVars) - else false - case VarNil() => false - case VarLit(b) => b - } - def evalClauseDnfWrong(clause: VarList, trueVars: Set[Int]): Boolean = clause match { - case VarCons(v, vs) => { - if(v == 1) evalClauseDnf(vs, trueVars) - else if(v == -1) false - else if(v < -1) trueVars.contains(-v) && evalClauseDnf(vs, trueVars) //bug - else if(v > 1) trueVars.contains(v) && evalClauseDnf(vs, trueVars) - else false - } - case VarNil() => true - case VarLit(b) => b - } - - def concatClauses(cll1: ClauseList, cll2: ClauseList): ClauseList = cll1 match { - case ClauseCons(cl, tail) => ClauseCons(cl, concatClauses(tail, cll2)) - case ClauseNil() => cll2 - case ClauseLit(b) => ClauseCons(VarLit(b), cll2) - } - - def concatVars(l1: VarList, l2: VarList): VarList = l1 match { - case VarCons(v, vs) => VarCons(v, concatVars(vs, l2)) - case VarNil() => l2 - case VarLit(b) => if(b) VarCons(1, l2) else VarCons(-1, l2) - } - - def distributeClause(cl: VarList, cll: ClauseList): ClauseList = cll match { - case ClauseCons(cl2, cl2s) => ClauseCons(concatVars(cl, cl2), distributeClause(cl, cl2s)) - case ClauseNil() => ClauseNil() - case ClauseLit(b) => if(b) ClauseCons(VarCons(1, cl), ClauseNil()) else ClauseCons(VarCons(-1, cl), ClauseNil()) - } - - def distribute(cll1: ClauseList, cll2: ClauseList): ClauseList = cll1 match { - case ClauseCons(cl, cls) => concatClauses(distributeClause(cl, cll2), distribute(cls, cll2)) - case ClauseNil() => cll2 - case ClauseLit(b) => distributeClause(VarLit(b), cll2) - } - - def negateClauses(cll: ClauseList): ClauseList = cll match { - case ClauseCons(cl, cls) => ClauseCons(negateVars(cl), negateClauses(cls)) - case ClauseNil() => ClauseNil() - case ClauseLit(b) => ClauseLit(!b) - } - - def negateVars(lst: VarList): VarList = lst match { - case VarCons(v, vs) => VarCons(-v, negateVars(vs)) - case VarNil() => VarNil() - case VarLit(b) => VarLit(!b) - } - - def cnfNaive(formula: Formula): ClauseList = formula match { - case And(f1, f2) => { - val cnf1 = cnfNaive(f1) - val cnf2 = cnfNaive(f2) - concatClauses(cnf1, cnf2) - } - case Or(f1, f2) => { - val cnf1 = cnfNaive(f1) - val cnf2 = cnfNaive(f2) - distribute(cnf1, cnf2) - } - case Not(And(f1, f2)) => cnfNaive(Or(Not(f1), Not(f2))) - case Not(Or(f1, f2)) => cnfNaive(And(Not(f1), Not(f2))) - case Not(Not(f)) => cnfNaive(f) - case Not(Var(n)) => ClauseCons(VarCons(-n, VarNil()), ClauseNil()) - case Var(n) => ClauseCons(VarCons(n, VarNil()), ClauseNil()) - } - def dnfNaive(formula: Formula): ClauseList = formula match { - case And(f1, f2) => { - val dnf1 = dnfNaive(f1) - val dnf2 = dnfNaive(f2) - distribute(dnf1, dnf2) - } - case Or(f1, f2) => { - val dnf1 = dnfNaive(f1) - val dnf2 = dnfNaive(f2) - concatClauses(dnf1, dnf2) - } - case Not(And(f1, f2)) => dnfNaive(Or(Not(f1), Not(f2))) - case Not(Or(f1, f2)) => dnfNaive(And(Not(f1), Not(f2))) - case Not(Not(f)) => dnfNaive(f) - case Not(Var(n)) => ClauseCons(VarCons(-n, VarNil()), ClauseNil()) - case Var(n) => ClauseCons(VarCons(n, VarNil()), ClauseNil()) - } - - def vars(formula: Formula): Set[Int] = formula match { - case Var(n) => Set(n) - case Not(f) => vars(f) - case And(f1, f2) => vars(f1) ++ vars(f2) - case Or(f1, f2) => vars(f1) ++ vars(f2) - } - def isContradictory(clause: VarList, vars: Set[Int]): Boolean = clause match { - case VarCons(v, vs) => vars.contains(-v) || vars.contains(-1) || isContradictory(vs, vars ++ Set(v)) - case VarNil() => false - case VarLit(b) => !b - } - def isSatDnf(clauses: ClauseList): Boolean = clauses match { - case ClauseCons(cl, cls) => !isContradictory(cl, Set.empty) || isSatDnf(cls) - case ClauseNil() => false - case ClauseLit(b) => b - } - - def simplify(formula: ClauseList): ClauseList = formula match { - case ClauseNil() => ClauseNil() - case ClauseCons(cl, cls) => simplify(cl) match { - case VarNil() => ClauseLit(false) - case VarLit(b) => if(!b) ClauseLit(false) else ClauseCons(VarLit(b), simplify(cls)) - case vs => ClauseCons(vs, simplify(cls)) - } - case ClauseLit(b) => ClauseLit(b) - } - - def simplify(vars: VarList): VarList = vars match { - case VarNil() => VarLit(false) - case VarLit(b) => VarLit(b) - case VarCons(1, vs) => VarLit(true) - case VarCons(-1, vs) => simplify(vs) - case VarCons(v, vs) => VarCons(v, simplify(vs)) - } - - //for substitute we assume we are dealing with a cnf formula - def substitute(formula: ClauseList, variable: Int, value: Boolean): ClauseList = formula match { - case ClauseNil() => ClauseNil() - case ClauseCons(cl, cls) => ClauseCons(substitute(cl, variable, value), substitute(cls, variable, value)) - case ClauseLit(b) => ClauseLit(b) - } - - def substitute(vars: VarList, variable: Int, value: Boolean): VarList = vars match { - case VarNil() => VarNil() - case VarLit(b) => VarLit(b) - case VarCons(v, vs) => - if (v == variable && value) VarLit(true) - else if(v == variable && !value) VarCons(-1, substitute(vs, variable, value)) - else if(v == -variable && value) VarCons(-1, substitute(vs, variable, value)) - else if(v == -variable && !value) VarLit(true) - else VarCons(v, substitute(vs, variable, value)) - } - - def choose(formula: ClauseList): Int = formula match { - case ClauseCons(varList, cls) => varList match { - case VarCons(head, vs) => head - case VarNil() => 0 - case VarLit(b) => 0 - } - case ClauseNil() => 0 - case ClauseLit(b) => 0 - } - - def dpll(formula: ClauseList): Boolean = formula match { - case ClauseNil() => true - case ClauseLit(b) => b - case _ => { - val chosenVar = choose(formula) - val lhs = dpll(simplify(substitute(formula, chosenVar, true))) - val rhs = dpll(simplify(substitute(formula, chosenVar, false))) - lhs || rhs - } - } - - - - def property1(formula: Formula, trueVars: Set[Int]): Boolean = { - val dnfFormula = dnfNaive(formula) - eval(formula, trueVars) == evalDnf(dnfFormula, trueVars) - } holds - - def property2(formula: Formula, trueVars: Set[Int]): Boolean = { - val cnfFormula = cnfNaive(formula) - eval(formula, trueVars) == evalCnf(cnfFormula, trueVars) - } holds - - def propertyWrong1(formula: Formula, trueVars: Set[Int]): Boolean = { - val dnfFormula = dnfNaive(formula) - isSatDnf(dnfFormula) - } holds - - def property3(formula: Formula, trueVars: Set[Int]): Boolean = { - val dnfFormula = dnfNaive(formula) - if(!isSatDnf(dnfFormula)) eval(formula, trueVars) else true - } holds - - def property4(formula: Formula): Boolean = { - val cnfFormula = cnfNaive(formula) - val dnfFormula = dnfNaive(formula) - isSatDnf(dnfFormula) == dpll(cnfFormula) - } - - - def main(args: Array[String]) { - val f1 = And(Var(1), Or(Var(1), Not(Var(2)), Var(3)), Var(2), Not(Var(3))) - val dnff1 = clauses2list(dnfNaive(f1)) - val vars1 = vars(f1) - //vars.foreach(v => { - - - //}) - println(f1 + " translated in dnf as:\n\t" + dnff1.mkString("\n\t")) - } - -//some non-leon functions to test the program with scala - object False { - def apply(): Formula = And(Var(1), Not(Var(1))) - } - object True { - def apply(): Formula = Or(Var(1), Not(Var(1))) - } - object Or { - def apply(fs: Formula*): Formula = fs match { - case Seq() => False() - case Seq(f) => f - case fs => fs.reduceLeft((f1, f2) => Or(f1, f2)) - } - } - object And { - def apply(fs: Formula*): Formula = fs match { - case Seq() => True() - case Seq(f) => f - case fs => fs.reduceLeft((f1, f2) => And(f1, f2)) - } - } - def clause2list(cl: VarList): List[Int] = cl match { - case VarCons(v, vs) => v :: clause2list(vs) - case VarNil() => Nil - case VarLit(b) => if(b) List(1) else List(-1) - } - def clauses2list(cll: ClauseList): List[List[Int]] = cll match { - case ClauseCons(cl, cls) => clause2list(cl) :: clauses2list(cls) - case ClauseNil() => Nil - case ClauseLit(b) => if(b) List(List(1)) else List(List(-1)) - } -} diff --git a/testcases/graveyard/SetOperations.scala b/testcases/graveyard/SetOperations.scala deleted file mode 100644 index 6037867bde779e08be6e0c3ccdff57e4dd021ced..0000000000000000000000000000000000000000 --- a/testcases/graveyard/SetOperations.scala +++ /dev/null @@ -1,64 +0,0 @@ -import scala.collection.immutable.Set - -// Cardinalities not supported yet. -// Pre/Post conditions commented out. - -object SetOperations { - - /* Sets of type Set[Int] */ - - def wrongAdd(a : Set[Int], b: Int) : Set[Int] = { - a ++ Set(b) - } ensuring (_ == a) - - // Pure BAPA verification condition - def vennRegions(a: Set[Int], b: Set[Int], c: Set[Int]) = { - a ++ b ++ c - } ensuring { - _.size == - a.size + b.size + c.size - - (a ** b).size - (b ** c).size - (c ** a).size + - (a ** b ** c).size - } - - // Ordered BAPA verification condition - def add(a: Set[Int], b: Int): Set[Int] = { - require(a.size >= 0) - a ++ Set(b) - } ensuring ((x: Set[Int]) => x.size >= a.size) - - /* Sets of type Set[Set[Int]] */ - - // This still works .. - def vennRegions2(a: Set[Set[Int]], b: Set[Set[Int]], c: Set[Set[Int]]) = { - a ++ b ++ c - } ensuring { - _.size == - a.size + b.size + c.size - - (a ** b).size - (b ** c).size - (c ** a).size + - (a ** b ** c).size - } - - // OrderedBAPA verification with Min and Max - def expandSet(a: Set[Int]) : Set[Int] = { - require(a.size >= 1) - val x = a.min - 1 - val y = a.max + 1 - Set(x) ++ Set(y) ++ a - } ensuring (res => res.max > a.max && res.min < a.min) - - // .. but this can no longer be proved by the OrderedBAPA solver, - // because "Set(b)" is neither a set of uninterpreted elements (pure BAPA) - // nor it is a set of integers (ordered BAPA). - // - // Perhaps "Set(b)" can be approximated by a fresh set variable S, - // with |S| = 1 ? More general, we can approximate "FiniteSet(elems)" - // by a fresh set variable S with |S| <= [# of elems]. - // (Though, there is a problem with min/max expressions appearing recursively - // in the FiniteSet.) - def add2(a: Set[Set[Int]], b: Set[Int]): Set[Set[Int]] = { - require(a.size >= 0) - a ++ Set(b) - } ensuring ((x: Set[Set[Int]]) => x.size >= a.size) - -} diff --git a/testcases/graveyard/SortedTree.scala b/testcases/graveyard/SortedTree.scala deleted file mode 100644 index fbee8f182a78a74494d7f10bde03759e6d1e1d28..0000000000000000000000000000000000000000 --- a/testcases/graveyard/SortedTree.scala +++ /dev/null @@ -1,286 +0,0 @@ -import scala.collection.immutable.Set -import leon.annotation._ -import leon.lang._ - -object SortedTree { - sealed abstract class Tree - case class Node(v: Int, left: Tree, right: Tree) extends Tree - case class Leaf() extends Tree - - def depth(t: Tree) : Int = (t match { - case Leaf() => 0 - case Node(_, l, r) => - if (depth(l) > depth(r)) { - depth(l)+1 - } else { - depth(r)+1 - } - }) ensuring(res => res >= 0) - - def size(t: Tree) : Int = (t match { - case Leaf() => 0 - case Node(_, l, r) => 1 + size(l) + size(r) - }) ensuring(res => res >= 0) - - def content(t: Tree): Set[Int] = t match { - case Leaf() => Set.empty[Int] - case Node(v, l, r) => Set(v) ++ content(l) ++ content(r) - } - - @induct - def sizeDepthLemma(t: Tree) = ( - (depth(t) <= size(t)) - ).holds - - def isMostlySorted(t: Tree): Boolean = (t match { - case Node(v, l @ Node(v1, l1, r1), r @ Node(v2, l2, r2)) => - isMostlySorted(l) && - isMostlySorted(r) && - v1 < v && - v2 > v - case Node(v, Leaf(), r @ Node(v2, l2, r2)) => - isMostlySorted(r) && - v2 > v - case Node(v, l @ Node(v1, l1, r1), Leaf()) => - isMostlySorted(l) && - v1 < v - case _ => true - }) - - def isSortedMinMax(t: Tree, min: Int, max: Int): Boolean = (t match { - case Node(v, l, r) => - if(isSortedMinMax(l, min, v) && - isSortedMinMax(r, v, max) && - v < max && v > min) { - ltLemma(l, v, max) && - gtLemma(r, v, min) - } else false - case _ => true - }) ensuring ( _ == (allGreaterThan(t, min) && allLessThan(t, max) && isSorted(t))) - - def isSortedMin(t: Tree, min: Int): Boolean = (t match { - case Node(v, l, r) => - if(isSortedMinMax(l, min, v) && - isSortedMin(r, v) && - v > min) { - gtLemma(r, v, min) - } else false - case _ => true - }) ensuring ( _ == (allGreaterThan(t, min) && isSorted(t))) - - def isSortedMax(t: Tree, max: Int): Boolean = (t match { - case Node(v, l, r) => - if(isSortedMax(l, v) && - isSortedMinMax(r, v, max) && - v < max) { - ltLemma(l, v, max) - } else false - case _ => true - }) ensuring ( _ == (allLessThan(t, max) && isSorted(t))) - - def isSorted(t: Tree): Boolean = (t match { - case Node(v, l, r) => - isSortedMin(r, v) && - isSortedMax(l, v) - case _ => true - }) ensuring ( res => !res || (t match { - case Node(v, l, r) => - isSorted(l) && - isSorted(r) && - allLessThan(l, v) && - allGreaterThan(r, v) && - !(content(l) contains v) && - !(content(r) contains v) - case Leaf() => true - })) - - def sortedLemma(v : Int, l : Tree, r : Tree) : Boolean = { - require(isSorted(l) && isSorted(r) && allLessThan(l, v) && allGreaterThan(r, v)) - isSorted(Node(v, l, r)) - } holds - - def allLessThan(t: Tree, max: Int): Boolean = (t match { - case Node(v, l, r) => - allLessThan(l, max) && - allLessThan(r, max) && - v < max - case Leaf() => true - }) ensuring (!_ || !(content(t) contains max)) - - def allGreaterThan(t: Tree, min: Int): Boolean = (t match { - case Node(v, l, r) => - allGreaterThan(l, min) && - allGreaterThan(r, min) && - v > min - case Leaf() => true - }) ensuring (res => !res || !(content(t) contains min)) - - @induct - def ltLemma(t : Tree, v1 : Int, v2 : Int) : Boolean = { - require(v1 <= v2 && allLessThan(t, v1)) - allLessThan(t, v2) - } holds - - @induct - def gtLemma(t : Tree, v1 : Int, v2 : Int) : Boolean = { - require(v1 >= v2 && allGreaterThan(t, v1)) - allGreaterThan(t, v2) - } holds - - @induct - def sortedLemma1(t: Tree) = ({ - require(isSorted(t)) - - t match { - case Node(v, l, r) => - allGreaterThan(r, v) && - allLessThan(l, v) - case Leaf() => true - } - }).holds - - @induct - def sortedLemma2(t: Tree) = ({ - require(isSorted(t)) - - t match { - case Node(v, l, r) => - !(content(l) contains v) && - !(content(r) contains v) - case Leaf() => true - } - }).holds - - def sortedLemma3(v: Int, l: Tree, r: Tree) = { - require(isSorted(Node(v, l, r))) - - !((content(l) ++ content(r)) contains v) - } holds - - // Proving is apparently difficult. Who knew. - @induct - def allLessThanAllOf(t: Tree, top: Int, of: Tree): Boolean = { - require(isSorted(Node(top, t, of))) - - t match { - case Node(v, l, r) => - top > v && - allLessThanAllOf(l, v, of) && - allLessThanAllOf(r, v, of) && - allGreaterThan(of, v) - case Leaf() => - true - } - } ensuring {res => !res || (allLessThan(t, top) && allGreaterThan(of, top))} - - // Ne marche pas encore vraiment... c'est difficile ce truc :( - // PS - def separation(v : Int, l : Tree, r : Tree) : Boolean = { - require(isSorted(Node(v, l, r))) - - (l match { - case Leaf() => true - case Node(vl, ll, rl) => separation(vl, ll, rl) - }) && (r match { - case Leaf() => true - case Node(vr, lr, rr) => separation(vr, lr, rr) - }) - } ensuring(res => !res || (content(l) ** content(r)) == Set.empty[Int]) - - - // - // OPERATIONS: - // - - def insert1(t: Tree, newV: Int): Tree = (t match { - case Leaf() => Node(newV, Leaf(), Leaf()) - case Node(v, l, r) => Node(v, insert1(l, newV), r) - }) ensuring(res => content(res) == content(t) ++ Set(newV)) - - def insert2(t: Tree, newV: Int): Tree = (t match { - case Leaf() => Node(newV, Leaf(), Leaf()) - case Node(v, l, r) => - if (v == newV) - t - else - Node(v, insert2(l, newV), r) - }) ensuring(res => content(res) == content(t) ++ Set(newV)) - - def insert3(t: Tree, newV: Int): Tree = (t match { - case Leaf() => Node(newV, Leaf(), Leaf()) - case Node(v, l, r) => - if (v == newV) - t - else if (newV > v) - Node(v, l, insert3(r, newV)) - else - Node(v, insert3(l, newV), r) - }) ensuring(res => content(res) == content(t) ++ Set(newV) && ((content(t) contains newV) || (size(res) > size(t)))) - - def insert4(t: Tree, newV: Int): Tree = { - require(isMostlySorted(t)); - - (t match { - case Leaf() => Node(newV, Leaf(), Leaf()) - case Node(v, l, r) => - if (v == newV) - t - else if (newV > v) - Node(v, l, insert4(r, newV)) - else - Node(v, insert4(l, newV), r) - })} ensuring(res => content(res) == content(t) ++ Set(newV) && ((content(t) contains newV) || (size(res) > size(t))) && isMostlySorted(res)) - - def contains1(t: Tree, searchV: Int): Boolean = (t match { - case Leaf() => false - case Node(v, l, r) => - (v == searchV) || - contains1(l, searchV) || - contains1(r, searchV) - }) ensuring(_ == (content(t) contains searchV)) - - def contains2(t: Tree, searchV: Int): Boolean = { - require(isMostlySorted(t)) - - (t match { - case Leaf() => false - case Node(v, l, r) => - if (searchV > v) { - contains2(r, searchV) - } else if (searchV < v) { - contains2(l, searchV) - } else { - true - } - })} ensuring(_ == (content(t) contains searchV)) - - def containsInvalid(t: Tree, searchV: Int): Boolean = { - require(isSorted(t)) - - (t match { - case Leaf() => false - case Node(v, l, r) => - if (searchV > v) { - containsInvalid(r, searchV) - } else if (searchV < v) { - containsInvalid(l, searchV) - } else { - true - } - })} ensuring(!_ || (content(t) contains searchV)) - - def contains4(t: Tree, searchV: Int): Boolean = { - require(isSorted(t)) - - (t match { - case Leaf() => false - case Node(v, l, r) => - if (searchV > v) { - contains4(r, searchV) - } else if (searchV < v) { - contains4(l, searchV) - } else { - true - } - })} ensuring(_ == (content(t) contains searchV)) -} diff --git a/testcases/graveyard/Test.scala b/testcases/graveyard/Test.scala deleted file mode 100644 index d3c5db95b535c4d250150d5527bdbb7c017192bb..0000000000000000000000000000000000000000 --- a/testcases/graveyard/Test.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object Test { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - @axiomatize - def size(l: List) : Int = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - // @axiomatize - // def isSorted(l : List) : Boolean = l match { - // case Nil() => true - // case Cons(x, xs) => xs match { - // case Nil() => true - // case Cons(y, _) => x <= y && isSorted(xs) - // } - // } - - @axiomatize - def content(l : List) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - - // def valuesWithin(l: List, lower: Int, upper: Int) : Boolean = l match { - // case Nil() => true - // case Cons(x, xs) => x >= lower && x <= upper && valuesWithin(xs, lower, upper) - // } - - def findOne(l1 : List, l2 : List) : Boolean = { - size(l1) == 2 && - l2 != Nil() && - content(l1) == content(l2) - } //ensuring(res => !res) - - def sets(s1 : Set[Int], s2 : Set[Int], s3 : Set[Int]) : Boolean = { - s1 != Set.empty[Int] && s2 != Set.empty[Int] && - s1 ++ s2 == s3 - } ensuring(res => !res) - -} diff --git a/testcases/graveyard/UnificationTest.scala b/testcases/graveyard/UnificationTest.scala deleted file mode 100644 index f4471492339d5669827f57eaf0eba5fe285e83be..0000000000000000000000000000000000000000 --- a/testcases/graveyard/UnificationTest.scala +++ /dev/null @@ -1,58 +0,0 @@ -package testcases - - -object UnificationTest { - - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(left: Tree, value: Int, right: Tree) extends Tree - - // Proved by unifier - def mkTree(a: Int, b: Int, c: Int) = { - Node(Node(Leaf(), a, Leaf()), b, Node(Leaf(), c, Leaf())) - //Node(Leaf(), b, Node(Leaf(), c, Leaf())) - } ensuring ( res => { - res.left != Leaf() && - res.value == b && - res.right == Node(Leaf(), c, Leaf()) - }) - - - - sealed abstract class Term - case class F(t1: Term, t2: Term, t3: Term, t4: Term) extends Term - case class G(s1: Term, s2: Term) extends Term - case class H(r1: Term, r2: Term) extends Term - case class A extends Term - case class B extends Term - - def examplePage268(x1: Term, x2: Term, x3: Term, x4: Term, x5: Term) = { - F(G(H(A(), x5), x2), x1, H(A(), x4), x4) - } //ensuring ( _ == F(x1, G(x2, x3), x2, B()) ) - - - - case class Tuple3(_1: Term, _2: Term, _3: Term) - - def examplePage269(x1: Term, x2: Term, x3: Term, x4: Term) = { - Tuple3(H(x1, x1), H(x2, x2), H(x3, x3)) - } /*ensuring ( res => { - x2 == res._1 && - x3 == res._2 && - x4 == res._3 - })*/ - - - // Cannot be solved yet, due to the presence of an if expression - def insert(tree: Tree, value: Int) : Node = (tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case n @ Node(l, v, r) => if(v < value) { - Node(l, v, insert(r, value)) - } else if(v > value) { - Node(insert(l, value), v, r) - } else { - n - } - }) ensuring(_ != Leaf()) - -} diff --git a/testcases/graveyard/UseContradictoryLemma.scala b/testcases/graveyard/UseContradictoryLemma.scala deleted file mode 100644 index 65ba4ea582fb219bc0287dc1a96fe1a17f3de5d6..0000000000000000000000000000000000000000 --- a/testcases/graveyard/UseContradictoryLemma.scala +++ /dev/null @@ -1,15 +0,0 @@ -import scala.collection.immutable.Set -import leon.lang._ -import leon.annotation._ - -object UseContradictoryLemma { - - def lemma1(x : Int) : Boolean = { - x == 1 - } holds - - def f(x : Int) : Int = { - 5 - } ensuring (x => lemma1(x) && x == 1) - -} diff --git a/testcases/graveyard/VerySimple.scala b/testcases/graveyard/VerySimple.scala deleted file mode 100644 index 7dc3c05b67b6d35b4ff003e0624a95dad8549d79..0000000000000000000000000000000000000000 --- a/testcases/graveyard/VerySimple.scala +++ /dev/null @@ -1,58 +0,0 @@ -import scala.collection.immutable.Set -import leon.lang._ -import leon.annotation._ - -object VerySimple { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def size(l: List) : Int = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) ensuring(_ >= 0) - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def sizeAndContent(l: List) : Boolean = { - size(l) == 0 || content(l) != Set.empty[Int] - } holds - - sealed abstract class IntPairList - case class IPCons(head: IntPair, tail: IntPairList) extends IntPairList - case class IPNil() extends IntPairList - - sealed abstract class IntPair - case class IP(fst: Int, snd: Int) extends IntPair - - def iplSize(l: IntPairList) : Int = (l match { - case IPNil() => 0 - case IPCons(_, xs) => 1 + iplSize(xs) - }) ensuring(_ >= 0) - - def zip(l1: List, l2: List) : IntPairList = { - // try to comment this and see how pattern-matching becomes - // non-exhaustive and post-condition fails - require(size(l1) == size(l2)) - - l1 match { - case Nil() => IPNil() - case Cons(x, xs) => l2 match { - case Cons(y, ys) => IPCons(IP(x, y), zip(xs, ys)) - } - } - } ensuring(iplSize(_) == size(l1)) - - def usesPrec(l1: List, l2: List, l3: List, flag: Boolean) : IntPairList = { - require(size(l1) == size(l2)) - - if(flag) { - zip(l1, l2) - } else { - zip(l2, l3) - } - } -} diff --git a/testcases/graveyard/Viktor.scala b/testcases/graveyard/Viktor.scala deleted file mode 100644 index 11b013dc475ccaefa4da7cec19f536919b828098..0000000000000000000000000000000000000000 --- a/testcases/graveyard/Viktor.scala +++ /dev/null @@ -1,11 +0,0 @@ -import leon.lang._ - -object Viktor { - def transitive(x: Boolean, y: Boolean, z: Boolean) : Boolean = { - !(x == y && y == z) || x == z - } holds - - def doesNotHold1(x: Int, y: Int) : Boolean = { - x + 2 > y * 2 - } holds -} diff --git a/testcases/graveyard/etaps2011-testcases/FromReport.scala b/testcases/graveyard/etaps2011-testcases/FromReport.scala deleted file mode 100644 index 338e057ffa3f253b0d36a596d2c3a58d9b6c6568..0000000000000000000000000000000000000000 --- a/testcases/graveyard/etaps2011-testcases/FromReport.scala +++ /dev/null @@ -1,43 +0,0 @@ -import scala.collection.immutable.Set - -object FromReport { - - def triPart_I(a: Set[Int], b1: Set[Int], b2: Set[Int], b3: Set[Int]) : Boolean = { - require( - (a == (b1 ++ b2 ++ b3)) && - (b1.max < b2.min) && - (b2.max < b3.min) && - (b1.size == b2.size) && - (b2.size == b3.size) && - (a.size == 12) && - (a.min == 1) - ) - (a.max != 12) - } ensuring(_ == true) - - def binFind_V(left: Set[Int], right: Set[Int], v: Int, e: Int) : Boolean = { - require( - (left.max < v) && - (v < right.min) && - (e < v) - ) - ((left ++ Set(v) ++ right).contains(e) == left.contains(e)) - } ensuring(_ == true) - - def pivot_V(oldAbove: Set[Int], pivot: Int, e: Int, newAbove: Set[Int]) : Boolean = { - require( - (oldAbove == Set.empty[Int] || pivot < oldAbove.min) && - (e > pivot) && - (newAbove == oldAbove ++ Set(e)) - ) - pivot < newAbove.min - } ensuring(_ == true) - - def addSup_V(newSet: Set[Int], oldSet: Set[Int], large: Int) : Boolean = { - require( - (newSet == oldSet ++ Set(large)) && - (large >= oldSet.max) - ) - newSet.max == large - } ensuring(_ == true) -} diff --git a/testcases/graveyard/etaps2011-testcases/HeapSort.scala b/testcases/graveyard/etaps2011-testcases/HeapSort.scala deleted file mode 100644 index 15ab85737cb28ec25730dadcefcb01342e2762c8..0000000000000000000000000000000000000000 --- a/testcases/graveyard/etaps2011-testcases/HeapSort.scala +++ /dev/null @@ -1,74 +0,0 @@ -import scala.collection.immutable.Set - -object HeapSort { - // This first part is concerned with simulating a heap - sealed abstract class Heap - case class DummyHeap(i: Int) extends Heap - - def emptyHeap() : Heap = { - throw new Exception("Unimplemented") - (DummyHeap(0) : Heap) - } ensuring(heapContent(_) == Set.empty[Int]) - - def isHeapEmpty(h: Heap) : Boolean = { - throw new Exception("Unimplemented") - false - } ensuring(res => res == (heapContent(h) == Set.empty[Int])) - - def heapContent(h: Heap) : Set[Int] = { - throw new Exception("Unimplemented") - Set.empty[Int] - } - - def findMax(h: Heap) : Int = { - require(!isHeapEmpty(h)) - throw new Exception("Unimplemented") - 0 - } ensuring(_ == heapContent(h).max) - - def removeMax(h: Heap) : Heap = { - require(!isHeapEmpty(h)) - throw new Exception("Unimplemented") - (DummyHeap(0) : Heap) - } ensuring(res => { - val cOld = heapContent(h) - val cNew = heapContent(res) - (cNew == Set.empty[Int] || cNew.max <= cOld.max) && - (cNew subsetOf cOld) && - (cOld.size - cNew.size <= 1) - }) - - // The rest is concerned with heapsort - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def listContent(l: List) : Set[Int] = (l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ listContent(xs) - }) - - def isSorted(l: List) : Boolean = (l match { - case Nil() => true - case Cons(x, xs) => isSorted(xs) && (listContent(xs) == Set.empty[Int] || x <= listContent(xs).min) - }) - - def listToHeap(l: List) : Heap = { - throw new Exception("Unimplemented") - (DummyHeap(0) : Heap) - } ensuring(heapContent(_) == listContent(l)) - - def heapToList(h: Heap, acc: List) : List = { - require(isSorted(acc) && (listContent(acc) == Set.empty[Int] || heapContent(h) == Set.empty[Int] || listContent(acc).min >= heapContent(h).max)) - if(isHeapEmpty(h)) { - acc - } else { - heapToList(removeMax(h), Cons(findMax(h), acc)) - } - } ensuring(res => listContent(res) == heapContent(h) ++ listContent(acc) && isSorted(res)) - - // note that this does not ensure that the multiplicity of repeated elements is preserved - def sort(l: List) : List = { - heapToList(listToHeap(l), Nil()) - } ensuring(res => isSorted(res) && listContent(res) == listContent(l)) -} diff --git a/testcases/graveyard/etaps2011-testcases/LeftistHeap.scala b/testcases/graveyard/etaps2011-testcases/LeftistHeap.scala deleted file mode 100644 index 860e694e60df3b7e7d6240140cc4fe695c3bcb7f..0000000000000000000000000000000000000000 --- a/testcases/graveyard/etaps2011-testcases/LeftistHeap.scala +++ /dev/null @@ -1,115 +0,0 @@ -import scala.collection.immutable.Set - -object LeftistHeap { - sealed abstract class Heap - case class Leaf() extends Heap - case class Node(rank: Int, value: Int, left: Heap, right: Heap) extends Heap - - sealed abstract class HP - case class HeapPair(heap1: Heap, heap2: Heap) extends HP - - private def rank(h: Heap) : Int = h match { - case Leaf() => 0 - case Node(r,_,_,_) => r - } - - def emptyHeap() : Heap = { - Leaf() - } ensuring(heapContent(_) == Set.empty[Int]) - - def isHeapEmpty(h: Heap) : Boolean = (h match { - case Leaf() => true - case Node(_,_,_,_) => false - }) ensuring(_ == (heapContent(h) == Set.empty[Int])) - - private def hasLeftistProperty(h: Heap) : Boolean = (h match { - case Leaf() => true - case Node(_,_,l,r) => rank(l) >= rank(r) - }) - - def heapContent(h: Heap) : Set[Int] = h match { - case Leaf() => Set.empty[Int] - case Node(_,v,l,r) => Set(v) ++ heapContent(l) ++ heapContent(r) - } - - def findMax(h: Heap) : Int = { - require(!isHeapEmpty(h) && hasLeftistProperty(h)) - h match { - case Node(_,m,_,_) => m - case Leaf() => -1000 - } - } ensuring(_ == heapContent(h).max) - - def removeMax(h: Heap) : Heap = { - require(!isHeapEmpty(h) && hasLeftistProperty(h)) - h match { - case Node(_,_,l,r) => merge(l, r) - case l @ Leaf() => l - } - } ensuring(res => { - val cOld = heapContent(h) - val cNew = heapContent(res) - (cNew == Set.empty[Int] || cNew.max <= cOld.max) && - (cNew subsetOf cOld) && - (cOld.size - cNew.size <= 1) && - hasLeftistProperty(res) - }) - - //private def merge(h1: Heap, h2: Heap) : Heap = (HeapPair(h1, h2) match { - // case HeapPair(Leaf(), h2) => h2 - // case HeapPair(h1, Leaf()) => h1 - // case HeapPair(Node(_, v1, l1, r1), Node(_, v2, l2, r2)) => - // if(v1 > v2) - // makeT(v1, l1, merge(r1, h2)) - // else - // makeT(v2, l2, merge(h1, r2)) - //}) ensuring(heapContent(_) == heapContent(h1) ++ heapContent(h2)) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2)) - h1 match { - case Leaf() => h2 - case Node(_, v1, l1, r1) => h2 match { - case Leaf() => h1 - case Node(_, v2, l2, r2) => - if(v1 > v2) - makeT(v1, l1, merge(r1, h2)) - else - makeT(v2, l2, merge(h1, r2)) - } - } - } ensuring(res => { - (heapContent(res) == heapContent(h1) ++ heapContent(h2)) && - hasLeftistProperty(res) - }) - - private def makeT(value: Int, left: Heap, right: Heap) : Heap = { - if(rank(left) >= rank(right)) - Node(rank(right) + 1, value, left, right) - else - Node(rank(left) + 1, value, right, left) - } ensuring(res => { - heapContent(res) == Set(value) ++ heapContent(left) ++ heapContent(right) && - hasLeftistProperty(res) - }) - - def insert(element: Int, heap: Heap) : Heap = { - merge(Node(1, element, Leaf(), Leaf()), heap) - } ensuring(res => { - val cNew = heapContent(res) - val cOld = heapContent(heap) - cNew == Set(element) ++ heapContent(heap) && - hasLeftistProperty(res) - }) - - def main(args: Array[String]) : Unit = { - val h1 = emptyHeap() - val h2 = insert(8, insert(0, insert(8, insert(24, insert(41, insert(13, h1)))))) - var h3 = h2 - while(!isHeapEmpty(h3)) { - println(h3) - println(findMax(h3)) - h3 = removeMax(h3) - } - } -} diff --git a/testcases/graveyard/etaps2011-testcases/VCs.scala b/testcases/graveyard/etaps2011-testcases/VCs.scala deleted file mode 100644 index ed3d6adeb8a55deb11e8fe6f6642a8f3fb8eb3a8..0000000000000000000000000000000000000000 --- a/testcases/graveyard/etaps2011-testcases/VCs.scala +++ /dev/null @@ -1,70 +0,0 @@ -import scala.collection.immutable.Set - -object VCs { - def forFun1_V(a: Set[Int], b: Set[Int], n: Int) : Boolean = { - require( - (a != Set.empty[Int]) - && (a.min == 0) - && (a.max == n - 1) - && (a.size == n) - && (b subsetOf a) - && (b != a) - ) - a.contains(b.size) - } ensuring(_ == true) - - def forFun2_V(a: Set[Int], b: Set[Int], n: Int) : Boolean = { - require( - (a != Set.empty[Int]) - && (a.min == 1) - && (a.max == n) - && (a.size == n) - && (b subsetOf a) - && (b != Set.empty[Int]) - ) - a.contains(b.size) - } ensuring(_ == true) - - def theJacobsLemma_V(s: Set[Int], a: Set[Int], b: Set[Int], c: Set[Int], d: Set[Int]) : Boolean = { - require( - (s == a ++ b) - && (s == c ++ d) - && (a.max < b.min) - && (c.max < d.min) - ) - (((a subsetOf c) && (d subsetOf b)) - || ((c subsetOf a) && (b subsetOf d))) - } ensuring(_ == true) - - def paperPartitionPivot_V(above: Set[Int], pivot: Int, e: Int, abovePrime: Set[Int]) : Boolean = { - require( - (above == Set.empty[Int] || pivot < above.min) - && !(e <= pivot) - && (abovePrime == above ++ Set(e)) - ) - pivot < abovePrime.min - } ensuring(_ == true) - - def heapSortNoRepeat1_V(hContent: Set[Int], hMinusMaxContent: Set[Int], recListContent: Set[Int]) : Boolean = { - require( - (hContent != Set.empty[Int]) - && (hMinusMaxContent == hContent -- Set(hContent.max)) - && (recListContent == hMinusMaxContent ++ Set(hContent.max)) - ) - ((recListContent == hContent) - && (hMinusMaxContent == Set.empty[Int] || hContent.max > hMinusMaxContent.max)) - } ensuring(_ == true) - - def heapSortNoRepeat2_V(accContent: Set[Int], hContent: Set[Int], hMinusMaxContent: Set[Int], recListContent: Set[Int]) = { - require( - (accContent != Set.empty[Int]) - && (hContent != Set.empty[Int]) - && (accContent.min > hContent.max) - && (hMinusMaxContent == hContent -- Set(hContent.max)) - && (recListContent == hMinusMaxContent ++ Set(hContent.max) ++ accContent) - ) - ((recListContent == hContent ++ accContent) - && (hContent.max < accContent.min) - && ((Set(hContent.max) ++ accContent).min > hMinusMaxContent.max)) - } ensuring(_ == true) -} diff --git a/testcases/graveyard/etaps2011-testcases/VCsHARD.scala b/testcases/graveyard/etaps2011-testcases/VCsHARD.scala deleted file mode 100644 index 7114db24f99a3be59647a6aa5e6f6025e5c6d428..0000000000000000000000000000000000000000 --- a/testcases/graveyard/etaps2011-testcases/VCsHARD.scala +++ /dev/null @@ -1,37 +0,0 @@ -import scala.collection.immutable.Set - -object VCs { - // could solve this one in a little more than 2 minutes on my desktop machine - def thePiskacLemma(s: Set[Int], a: Set[Int], b: Set[Int], c: Set[Int], d: Set[Int], e: Set[Int], f: Set[Int]) : Boolean = { - require( - (s == a ++ b ++ c) - && (s == d ++ e ++ f) - && (a.max < b.min) - && (b.max < c.min) - && (d.max < e.min) - && (e.max < f.min) - ) - (((a subsetOf d) || (d subsetOf a)) - && ((c subsetOf f) || (f subsetOf c))) - } ensuring(_ == true) - - // never solved this one. - def paperBSTFind_V(c: Set[Int], l: Set[Int], r: Set[Int], v: Int, range1: Set[Int], range2: Set[Int], range3: Set[Int]) : Boolean = { - require( - (c == l ++ Set(v) ++ r) - && (l.max < v) - && (v < r.min) - && (range1 ++ range2 ++ range3 == c) - && (range1.max < range2.min) - && (range2.min < range3.max) - && (range1.size == l.size) - && (range2.size == 1) - && (range3.size == c.size - l.size - 1) - // The following lines are an application of the Piskac Lemma - // && ((l subsetOf range1) || (range1 subsetOf l)) - // && ((r subsetOf range3) || (range3 subsetOf r)) - ) - Set(v) == range2 - // v == range2.min // this should be equivalent, right? - } ensuring(_ == true) -} diff --git a/testcases/graveyard/etaps2011-testcases/manual b/testcases/graveyard/etaps2011-testcases/manual deleted file mode 100644 index 732a812e565a6f0f86cf693f63531820155729bf..0000000000000000000000000000000000000000 --- a/testcases/graveyard/etaps2011-testcases/manual +++ /dev/null @@ -1,48 +0,0 @@ -The original problem: -********************* - isSorted(acc) - && lContent(acc).min > hContent(h).max - && isEmpty(h) <=> hContent(h) = ø - && hContent(removeMax(h)) = hContent(h) \ { hContent(h).max } - && findMax(h) = hContent(h).max - && lContent(heapToList(removeMax(h), findMax(h) :: acc)) = hContent(removeMax(h)) U lContent(findMax(h) :: acc) - && isSorted(heapToList(removeMax(h), findMax(h) :: acc)) - ==> - lContent(if(isEmpty(h)) acc else heapToList(removeMax(h), findMax(h) :: acc)) = hContent(h) U lContent(acc) - && isSorted(if(isEmpty(h)) acc else heapToList(removeMax(h), findMax(h) :: acc)) - && isSorted(findMax(h) :: acc) - && lContent(findMax(h) :: acc).min > hContent(removeMax(h)).max - -Now, assuming h is empty: -************************* - isSortedAcc - ==> - lContentAcc = Ø U lContentAcc - && isSortedAcc - -Assuming h non-empty and acc empty: -*********************************** - hContent != ø - && hMinusMaxContent = hContent \ { hContent.max } - && recListContent = hMinusMaxContent U { hContent.max } - && isSortedRecList - ==> - recListContent = hContent U Ø - && isSortedRecList - && hContent.max > hMinusMaxContent.max - -Assuming both non-empty: -************************ - isSortedAcc - && accContent != ø - && hContent != ø - && accContent.min > hContent.max - && hMinusMaxContent = hContent \ { hContent.max } - && recListContent = hMinusMaxContent U { hContent.max } U accContent - && isSortedRecList - ==> - recListContent = hContent U accContent - && isSortedRecList - && hContent.max < accContent.min - && isSortedAcc - && ({ hContent.max } U accContent).min > hMinusMaxContent.max diff --git a/testcases/graveyard/insynth-leon-tests/BubbleSortBug.scala b/testcases/graveyard/insynth-leon-tests/BubbleSortBug.scala deleted file mode 100644 index 2f76a450d3e4622e111bed74fa7dca56e4c9dfae..0000000000000000000000000000000000000000 --- a/testcases/graveyard/insynth-leon-tests/BubbleSortBug.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ - -/* The calculus of Computation textbook */ - -object BubbleSortBug { - - def sort(a: Array[Int]): Array[Int] = ({ - require(a.length >= 1) - var i = a.length - 1 - var j = 0 - val sa = a.clone - (while(i > 0) { - j = 0 - (while(j < i) { - if(sa(j) < sa(j+1)) { - val tmp = sa(j) - sa(j) = sa(j+1) - - hole(0) - - sa(j+1) = tmp - } - j = j + 1 - }) invariant(j >= 0 && j <= i && i < sa.length) - i = i - 1 - }) invariant(i >= 0 && i < sa.length) - sa - }) ensuring(res => true) - -} diff --git a/testcases/graveyard/insynth-leon-tests/CaseClassSelectExample.scala b/testcases/graveyard/insynth-leon-tests/CaseClassSelectExample.scala deleted file mode 100644 index a4c127f0e701cf097b48e6d7cfba7cf3b013300f..0000000000000000000000000000000000000000 --- a/testcases/graveyard/insynth-leon-tests/CaseClassSelectExample.scala +++ /dev/null @@ -1,24 +0,0 @@ -import scala.collection.immutable.Set -import leon.annotation._ -import leon.lang._ - -object CaseClassSelectExample { - - sealed abstract class OptionInt - case class Some(v : Int) extends OptionInt - case class None() extends OptionInt - - // this won't work -// sealed abstract class AbsHasVal(v: Int) -// case class Concrete(x: Int) extends AbsHasVal(x) - - def selectIntFromSome(some: Some) = { - some.v - } - - // this won't work -// def selectIntFromSome(a: Concrete) = { -// a.v -// } - -} diff --git a/testcases/graveyard/insynth-leon-tests/Hole.scala b/testcases/graveyard/insynth-leon-tests/Hole.scala deleted file mode 100644 index 5bccc38daba02bdf7e79b561f57c7e7f71cd4015..0000000000000000000000000000000000000000 --- a/testcases/graveyard/insynth-leon-tests/Hole.scala +++ /dev/null @@ -1,13 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Hole { - - def method(t: Int) : Int = ({ - if (t > 5) - hole(5) - else - t - }) ensuring ( _ > 0 ) - -} diff --git a/testcases/graveyard/insynth-leon-tests/ListOperationsHole.scala b/testcases/graveyard/insynth-leon-tests/ListOperationsHole.scala deleted file mode 100644 index e0587425d1d581553d3804d19d11fdbc6cdf51d0..0000000000000000000000000000000000000000 --- a/testcases/graveyard/insynth-leon-tests/ListOperationsHole.scala +++ /dev/null @@ -1,24 +0,0 @@ -import scala.collection.immutable.Set - -import leon.lang._ - -object ListOperations { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - -// def isEmpty(l: List) = l match { -// case Nil() => true -// case Cons(_, _) => false -// } - - def concat(l1: List, l2: List) : List = ({ - hole(l1) - }) ensuring(res => content(res) == content(l1) ++ content(l2)) - -} diff --git a/testcases/graveyard/insynth-leon-tests/RedBlackTreeFull.scala b/testcases/graveyard/insynth-leon-tests/RedBlackTreeFull.scala deleted file mode 100644 index 11daef0b03ee0e4eae57db7735128456e3844649..0000000000000000000000000000000000000000 --- a/testcases/graveyard/insynth-leon-tests/RedBlackTreeFull.scala +++ /dev/null @@ -1,117 +0,0 @@ -import scala.collection.immutable.Set -import leon.annotation._ -import leon.lang._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - sealed abstract class OptionInt - case class Some(v : Int) extends OptionInt - case class None() extends OptionInt - - def content(t: Tree) : Set[Int] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : Int = (t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - }) ensuring(_ >= 0) - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t : Tree) : Int = t match { - case Empty() => 1 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if (x < y) balance(c, ins(x, a), y, b) - else if (x == y) Node(c,a,y,b) - else balance(c,a,y,ins(x, b)) - } - } ensuring (res => content(res) == content(t) ++ Set(x) - && size(t) <= size(res) && size(res) <= size(t) + 1 - && redDescHaveBlackChildren(res) - && blackBalanced(res)) - - def makeBlack(n: Tree): Tree = { - require(redDescHaveBlackChildren(n) && blackBalanced(n)) - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } ensuring(res => redNodesHaveBlackChildren(res) && blackBalanced(res)) - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - makeBlack(ins(x, t)) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res) && blackBalanced(res)) - - def buggyAdd(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t)) - ins(x, t) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res)) - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b)))// && redDescHaveBlackChildren(res)) - - def buggyBalance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - // case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b)))// && redDescHaveBlackChildren(res)) -} diff --git a/testcases/graveyard/insynth-synthesis-tests/Hole.scala b/testcases/graveyard/insynth-synthesis-tests/Hole.scala deleted file mode 100644 index 933825e2f3b608cd66dc83e256a30e1257b0591f..0000000000000000000000000000000000000000 --- a/testcases/graveyard/insynth-synthesis-tests/Hole.scala +++ /dev/null @@ -1,13 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Hole { - - def method(t: Int) : Int = ({ - if (t > 5) - hole(5) - else - t - })// ensuring ( _ > 0 ) - -} diff --git a/testcases/graveyard/insynth-synthesis-tests/LocalScope.scala b/testcases/graveyard/insynth-synthesis-tests/LocalScope.scala deleted file mode 100644 index 5b747616213aec2263423fcc80751856e8f2b0cc..0000000000000000000000000000000000000000 --- a/testcases/graveyard/insynth-synthesis-tests/LocalScope.scala +++ /dev/null @@ -1,31 +0,0 @@ -import leon.lang._ - -object LocalScope { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - sealed abstract class OptionInt - case class Some(v : Int) extends OptionInt - case class None() extends OptionInt - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_, l, v, r) => { - // hide r - val r: Int = 5 - //val f: ((Int, Int) => Boolean) = (x: Int, y: Int) => false - - Some(5) match { - case Some(newInt) => hole(0) - } - - false - } - - case Empty() => true - } -} diff --git a/testcases/graveyard/malkis/Hardest.scala b/testcases/graveyard/malkis/Hardest.scala deleted file mode 100644 index 2417f7db328157f3ed7a4d91b2280b72eb0702f1..0000000000000000000000000000000000000000 --- a/testcases/graveyard/malkis/Hardest.scala +++ /dev/null @@ -1,32 +0,0 @@ -import scala.collection.immutable.Set - -object Hardest { - def vc( - thread : Set[Int], - thread_A : Set[Int], - thread_A_2 : Set[Int], - thread_B_3 : Set[Int], - thread_C_2 : Set[Int], - thread_count : Int, - thread_count_2 : Int, - thread_t : Int, - thread_t_1 : Int, - nulll : Int - ) : Boolean = { - require( - thread_B_3.contains(thread_t_1) - && (thread_C_2 == Set.empty[Int] || 0 == 0) - && (thread_B_3 ** thread_C_2) == Set.empty[Int] - && (thread_A_2 ** thread_C_2) == Set.empty[Int] - && (thread_A_2 ** thread_B_3) == Set.empty[Int] - && ((thread_A_2 ++ thread_B_3 ++ thread_C_2) subsetOf thread) - && (thread_A_2.size <= 0) - && !thread.contains(nulll) - && (thread_A subsetOf thread) - && (thread_A.size <= thread_count) - && thread.contains(thread_t) - ) - ((thread_A_2 ++ (thread_B_3 -- Set(thread_t_1))) ++ - (thread_C_2 ++ Set(thread_t_1))) subsetOf thread - } ensuring(res => res) -} diff --git a/testcases/graveyard/multisets/MultiBug.scala b/testcases/graveyard/multisets/MultiBug.scala deleted file mode 100644 index 1336fa8f59081048c935298033ac2316ee1155d5..0000000000000000000000000000000000000000 --- a/testcases/graveyard/multisets/MultiBug.scala +++ /dev/null @@ -1,10 +0,0 @@ -import scala.collection.immutable.Set -import scala.collection.immutable.Multiset - -object MultisetOperations { - - def disjointUnion2(a: Multiset[Int], b: Multiset[Int]) : Multiset[Int] = { - a +++ b - } ensuring(res => res.toSet == (a.toSet ++ b.toSet)) - -} diff --git a/testcases/graveyard/multisets/MultiExample.scala b/testcases/graveyard/multisets/MultiExample.scala deleted file mode 100644 index dd9498c10fec86dd549501979d7113d70996aa58..0000000000000000000000000000000000000000 --- a/testcases/graveyard/multisets/MultiExample.scala +++ /dev/null @@ -1,18 +0,0 @@ -import scala.collection.immutable.Set -import scala.collection.immutable.Multiset - -object MultisetOperations { - - def disjointUnion1(a: Multiset[Int], b: Multiset[Int]) : Multiset[Int] = { - a +++ b - } ensuring(res => res.size == a.size + b.size) - - def preservedUnderToSet1(a: Multiset[Int], b: Multiset[Int]) : Multiset[Int] = { - a ++ b - } ensuring(res => res.toSet == a.toSet ++ b.toSet) - - def preservedUnderToSet2(a: Multiset[Int], b: Multiset[Int]) : Multiset[Int] = { - a ** b - } ensuring(res => res.toSet == a.toSet ** b.toSet) - -} diff --git a/testcases/graveyard/multisets/MultisetOperations.scala b/testcases/graveyard/multisets/MultisetOperations.scala deleted file mode 100644 index c59d2a85fea1909954b03c9b9b7ee9ab736a31a3..0000000000000000000000000000000000000000 --- a/testcases/graveyard/multisets/MultisetOperations.scala +++ /dev/null @@ -1,13 +0,0 @@ -import scala.collection.immutable.Set -import scala.collection.immutable.Multiset - -object MultisetOperations { - def preservedUnderToSet(a: Multiset[Int], b: Multiset[Int]) : Boolean = { - ((a ++ b).toSet.size == (a.toSet ++ b.toSet).size) && - ((a ** b).toSet.size == (a.toSet ** b.toSet).size) - } ensuring(res => res) - - def sumPreservesSizes(a: Multiset[Int], b: Multiset[Int]) : Boolean = { - ((a +++ b).size == a.size + b.size) - } ensuring(res => res) -} diff --git a/testcases/graveyard/testgen/Abs.scala b/testcases/graveyard/testgen/Abs.scala deleted file mode 100644 index 5d98e69490ede4eb2d2ed7ccab4f4287efe0de19..0000000000000000000000000000000000000000 --- a/testcases/graveyard/testgen/Abs.scala +++ /dev/null @@ -1,11 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object Abs { - - @main - def abs(x: Int): Int = { - if(x < 0) -x else x - } ensuring(_ >= 0) - -} diff --git a/testcases/graveyard/testgen/Abs2.scala b/testcases/graveyard/testgen/Abs2.scala deleted file mode 100644 index 63d9afcb2ed9aa664811b53466475d5266c29918..0000000000000000000000000000000000000000 --- a/testcases/graveyard/testgen/Abs2.scala +++ /dev/null @@ -1,11 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object Abs2 { - - @main - def f(x: Int): Int = if(x < 0) g(-x) else g(x) - - def g(y: Int): Int = if(y < 0) -y else y - -} diff --git a/testcases/graveyard/testgen/Diamond.scala b/testcases/graveyard/testgen/Diamond.scala deleted file mode 100644 index bc2ddb9da5e5dd668710aeaf755c0fcef09b2ca7..0000000000000000000000000000000000000000 --- a/testcases/graveyard/testgen/Diamond.scala +++ /dev/null @@ -1,9 +0,0 @@ -import leon.lang._ - -object Diamond { - - def foo(x: Int): Int = waypoint(1, if(x < 0) bar(x) else bar(x)) - - def bar(y: Int): Int = if(y > 5) y else -y - -} diff --git a/testcases/graveyard/testgen/Imp.scala b/testcases/graveyard/testgen/Imp.scala deleted file mode 100644 index e3b94180174bf3ded622bae42c51f78f87f73ad8..0000000000000000000000000000000000000000 --- a/testcases/graveyard/testgen/Imp.scala +++ /dev/null @@ -1,17 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object Imp { - - @main - def foo(i: Int): Int = { - var a = 0 - a = a + 3 - if(i < a) - a = a + 1 - else - a = a - 1 - a - } ensuring(_ >= 0) - -} diff --git a/testcases/graveyard/testgen/ImpWaypoint.scala b/testcases/graveyard/testgen/ImpWaypoint.scala deleted file mode 100644 index 08a1eed00456650e2edc452aac13c10a6a9916a3..0000000000000000000000000000000000000000 --- a/testcases/graveyard/testgen/ImpWaypoint.scala +++ /dev/null @@ -1,20 +0,0 @@ - -import leon.lang._ -import leon.annotation._ - -object Imp { - - @main - def foo(i: Int): Int = { - var a = 0 - a = a + 3 - if(i < a) - waypoint(1, a = a + 1) - else - a = a - 1 - a - } ensuring(_ >= 0) - -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/graveyard/testgen/List.scala b/testcases/graveyard/testgen/List.scala deleted file mode 100644 index 6960157a1eec2b3adcdb46c48ae2c224f061d89a..0000000000000000000000000000000000000000 --- a/testcases/graveyard/testgen/List.scala +++ /dev/null @@ -1,20 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object List { - - abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - @main - def size(l: List): Int = (l match { - case Cons(_, tail) => sizeTail(tail, 1) - case Nil() => 0 - }) ensuring(_ >= 0) - - def sizeTail(l2: List, acc: Int): Int = l2 match { - case Cons(_, tail) => sizeTail(tail, acc+1) - case Nil() => acc - } -} diff --git a/testcases/graveyard/testgen/MultiCall.scala b/testcases/graveyard/testgen/MultiCall.scala deleted file mode 100644 index cdbc3c18c443fedafca039ff41d9d5783411258e..0000000000000000000000000000000000000000 --- a/testcases/graveyard/testgen/MultiCall.scala +++ /dev/null @@ -1,15 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object MultiCall { - - @main - def a(i: Int): Int = if(i < 0) b(i) else c(i) - - def b(j: Int): Int = if(j == -5) d(j) else e(j) - def c(k: Int): Int = if(k == 5) d(k) else e(k) - - def d(l: Int): Int = l - def e(m: Int): Int = m - -} diff --git a/testcases/graveyard/testgen/Sum.scala b/testcases/graveyard/testgen/Sum.scala deleted file mode 100644 index b08741e448eb2f8fa85ce868df6f6286d6ddfe94..0000000000000000000000000000000000000000 --- a/testcases/graveyard/testgen/Sum.scala +++ /dev/null @@ -1,11 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object Sum { - - @main - def sum(n: Int): Int = { - if(n <= 0) waypoint(4, 0) else waypoint(3, waypoint(2, n + sum(n-1))) - } ensuring(_ >= 0) - -} diff --git a/testcases/graveyard/tutorials/01_Introduction.scala b/testcases/graveyard/tutorials/01_Introduction.scala deleted file mode 100644 index ffe5264617df6bdf3a019c3afd197b4b2d6f5093..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/01_Introduction.scala +++ /dev/null @@ -1,94 +0,0 @@ -import leon.Utils._ - -/** - * Code should be contained in a single top-level object - */ -object Introduction { - - /** - * You can define Algebraic Data Types using abstract classes and case classes. - */ - abstract class Tree - case class Node(left: Tree, v: BigInt, right: Tree) extends Tree - case object Leaf extends Tree - - - /** - * You can define functions. Functions should be purely functionnal. Note - * that some imperative constructs such as 'var' or while loops will be handled. - */ - def content(t: Tree): Set[BigInt] = t match { - case Node(l, v, r) => content(l) ++ content(r) ++ Set(v) - case Leaf => Set() - } - - /** - * You can specify pre-conditions to a function using the "require" construct. - * You can use previously-defined functions in your precondition - */ - def head(t: Tree) = { - require(t != Leaf) - - val Node(_, v, _) = t - - v - } - - - /** - * The following function uses head in unsafe ways: - * - * To verify a function, click on its name and select "verify". You can also - * hit Alt+v while within the body of a function. - * - * Verify whether test1, test2 and test3 are safe. - */ - - def simpleSorted(t: Tree) = { - require(t != Leaf) - - val Node(l, v, r) = t - - (head(l) < v) && (v < head(r)) - } - - /** - * You can specify post-conditions using "ensuring". - */ - def contains(what: BigInt, t: Tree): Boolean = (t match { - case Leaf => - false - - case Node(l, v, r) => - (v == what) || contains(what, l) || contains(what, r) - - }) ensuring { res => res == (content(t) contains what) } - - /** - * Can you spot the bug in this implementation of contains? Leon can. - */ - def containsBuggy(what: BigInt, t: Tree): Boolean = (t match { - case Leaf => - false - - case Node(l, v, r) => - (v == what) || contains(what, l) || contains(v, r) - - }) ensuring { res => res == (content(t) contains what) } - - - /** - * Leon can also verify the completeness of the pattern matching: - */ - def unsafeMatch(t: Tree) = t match { - case Node(l, v, r) if v == 0 => - case Leaf => - } - - def unsafeHead(t: Tree) = { - val Node(_, v, _) = t // This translates to pattern matching - - v - } - -} diff --git a/testcases/graveyard/tutorials/02_Ex1_Account.scala b/testcases/graveyard/tutorials/02_Ex1_Account.scala deleted file mode 100644 index 2001180737f5d0732fefb90ee8192d26165b6697..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/02_Ex1_Account.scala +++ /dev/null @@ -1,23 +0,0 @@ -/* - Try to verify the toSavings function. - Use the returned counter-example to fix the precondition such that - Leon succeeds in showing the function correct. -*/ - -object Account2 { - sealed abstract class AccLike - case class Acc(checking : BigInt, savings : BigInt) extends AccLike - - def toSavings(x : BigInt, a : Acc) : Acc = { - require (notRed(a) && a.checking >= x) - Acc(a.checking - x, a.savings + x) - } ensuring (res => (notRed(res) && sameTotal(a, res))) - - - def sameTotal(a1 : Acc, a2 : Acc) : Boolean = { - a1.checking + a1.savings == a2.checking + a2.savings - } - def notRed(a : Acc) : Boolean = { - a.checking >= 0 && a.savings >= 0 - } -} diff --git a/testcases/graveyard/tutorials/03_Ex2_Propositional_Logic.scala b/testcases/graveyard/tutorials/03_Ex2_Propositional_Logic.scala deleted file mode 100644 index f5f1dd8eda867ec12166c5f461be928218d43a6a..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/03_Ex2_Propositional_Logic.scala +++ /dev/null @@ -1,74 +0,0 @@ -import leon.Utils._ -import leon.Annotations._ - - -/* - Complete the two function stubs so that the simplify and nnf functions verify. -*/ - -object PropositionalLogic { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Implies(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Literal(id: BigInt) extends Formula - - - def simplify(f: Formula): Formula = (f match { - case And(lhs, rhs) => And(simplify(lhs), simplify(rhs)) - case Or(lhs, rhs) => Or(simplify(lhs), simplify(rhs)) - case Implies(lhs, rhs) => Or(Not(simplify(lhs)), simplify(rhs)) - case Not(f) => Not(simplify(f)) - case Literal(_) => f - }) ensuring(isSimplified(_)) - - def isSimplified(f: Formula): Boolean = f match { - - } - - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Implies(lhs, rhs) => Implies(nnf(lhs), nnf(rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Implies(lhs, rhs)) => And(nnf(lhs), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case Not(Literal(_)) => formula - case Literal(_) => formula - }) ensuring(isNNF(_)) - - def isNNF(f: Formula): Boolean = f match { - - } - - def evalLit(id : BigInt) : Boolean = (id == 42) // could be any function - def eval(f: Formula) : Boolean = f match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Implies(lhs, rhs) => !eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Literal(id) => evalLit(id) - } - - @induct - def simplifySemantics(f: Formula) : Boolean = { - eval(f) == eval(simplify(f)) - } holds - - // Note that matching is exhaustive due to precondition. - def vars(f: Formula): Set[BigInt] = { - require(isNNF(f)) - f match { - case And(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Or(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Implies(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Not(Literal(i)) => Set[BigInt](i) - case Literal(i) => Set[BigInt](i) - } - } - - -} diff --git a/testcases/graveyard/tutorials/04_Ex3_List.scala b/testcases/graveyard/tutorials/04_Ex3_List.scala deleted file mode 100644 index a49eba2cc66c1339a0d8e7a45448be801cb0ceed..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/04_Ex3_List.scala +++ /dev/null @@ -1,123 +0,0 @@ -import leon.Annotations._ -import leon.Utils._ - -/* - 1) Add pre- and postconditions, or fix the code such that the following - functions verify: - zip, sizesAreEquiv, reverse, concat0 - The postconditions on these functions give what should be checked, i.e. - they should not be changed. - - 2) find out what the function drunk does, and check provide a correct - postcondition that relates the sizes of the input list with the output list - - 3) the function appendAssoc is meant to prove that the appending lists is - associative. Formulate this predicate and make sure Leon can verify it. -*/ - -object ListWithSize { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - sealed abstract class IntPairList - case class IPCons(head: IntPair, tail: IntPairList) extends IntPairList - case class IPNil() extends IntPairList - - sealed abstract class IntPair - case class IP(fst: BigInt, snd: BigInt) extends IntPair - - - def size(l: List) : BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def iplSize(l: IntPairList) : BigInt = (l match { - case IPNil() => 0 - case IPCons(_, xs) => 1 + iplSize(xs) - }) - - // Verify - def zip(l1: List, l2: List) : IntPairList = { - l1 match { - case Nil() => IPNil() - case Cons(x, xs) => l2 match { - case Cons(y, ys) => IPCons(IP(x, y), zip(xs, ys)) - } - } - } ensuring(iplSize(_) == size(l1)) - - def sizeTailRec(l: List) : BigInt = sizeTailRecAcc(l, 0) - def sizeTailRecAcc(l: List, acc: BigInt) : BigInt = { - l match { - case Nil() => acc - case Cons(_, xs) => sizeTailRecAcc(xs, acc+1) - } - } - - // Verify - def sizesAreEquiv(l: List) : Boolean = { - size(l) == sizeTailRec(l) - } holds - - def content(l: List) : Set[BigInt] = l match { - case Nil() => Set.empty[BigInt] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def sizeAndContent(l: List) : Boolean = { - size(l) == 0 || content(l) != Set.empty[BigInt] - } holds - - def drunk(l : List) : List = (l match { - case Nil() => Nil() - case Cons(x,l1) => Cons(x,Cons(x,drunk(l1))) - }) // TODO: find postcondition - - - def funnyCons(x: BigInt, l: List) : List = (l match { - case Nil() => Cons(x, Nil()) - case c @ Cons(_,_) => Cons(x, c) - }) ensuring(size(_) > 0) - - // Verify - def reverse(l: List) : List = reverse0(l, Nil()) ensuring(content(_) == content(l)) - def reverse0(l1: List, l2: List) : List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverse0(xs, Cons(x, l2)) - }) - - def append(l1 : List, l2 : List) : List = (l1 match { - case Nil() => l2 - case Cons(x,xs) => Cons(x, append(xs, l2)) - }) ensuring(content(_) == content(l1) ++ content(l2)) - - @induct - def nilAppend(l : List) : Boolean = (append(l, Nil()) == l) holds - - // TODO: find predicate - //@induct - //def appendAssoc(xs : List, ys : List, zs : List) : Boolean = - // (...) holds - - @induct - def sizeAppend(l1 : List, l2 : List) : Boolean = - (size(append(l1, l2)) == size(l1) + size(l2)) holds - - @induct - def concat(l1: List, l2: List) : List = - concat0(l1, l2, Nil()) ensuring(content(_) == content(l1) ++ content(l2)) - - @induct - def concat0(l1: List, l2: List, l3: List) : List = (l1 match { - case Nil() => l2 match { - case Nil() => reverse(l2) - case Cons(y, ys) => { - concat0(Nil(), ys, Cons(y, l3)) - } - } - case Cons(x, xs) => concat0(xs, l2, Cons(x, l3)) - }) ensuring(content(_) == content(l1) ++ content(l2) ++ content(l3)) - -} diff --git a/testcases/graveyard/tutorials/05_Ex4_InsertionSort.scala b/testcases/graveyard/tutorials/05_Ex4_InsertionSort.scala deleted file mode 100644 index 4ce5d723fa283cb31b790476203d15701e67cadf..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/05_Ex4_InsertionSort.scala +++ /dev/null @@ -1,62 +0,0 @@ -import leon.Annotations._ -import leon.Utils._ - -/* - Complete the code such that the sort function verifies. -*/ - -object InsertionSort { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case class Nil() extends List - - sealed abstract class OptInt - case class Some(value: BigInt) extends OptInt - case class None() extends OptInt - - def size(l : List) : BigInt = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) - - def contents(l: List): Set[BigInt] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def min(l : List) : OptInt = l match { - case Nil() => None() - case Cons(x, xs) => min(xs) match { - case None() => Some(x) - case Some(x2) => if(x < x2) Some(x) else Some(x2) - } - } - - 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)) - } - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def sortedIns(e: BigInt, l: List): List = { - require(isSorted(l)) - l match { - case Nil() => Cons(e,Nil()) - case Cons(x,xs) => if (x <= e) Cons(x,sortedIns(e, xs)) else Cons(e, l) - } - } - - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort(l: List): List = (l match { - case Nil() => Nil() - case Cons(x,xs) => sortedIns(x, sort(xs)) - }) ensuring(res => contents(res) == contents(l) - && isSorted(res) - && size(res) == size(l) - ) - -} diff --git a/testcases/graveyard/tutorials/06_Ex5_Add.scala b/testcases/graveyard/tutorials/06_Ex5_Add.scala deleted file mode 100644 index e7245480c10733d5b7148b351e815b3f0f5a9681..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/06_Ex5_Add.scala +++ /dev/null @@ -1,29 +0,0 @@ -import leon.Utils._ - -/* VSTTE 2008 - Dafny paper */ - -/* - Add the loop invariants so that Leon can verify this function. -*/ - -object Add { - - def add(x : BigInt, y : BigInt): BigInt = ({ - var r = x - if(y < 0) { - var n = y - (while(n != 0) { - r = r - 1 - n = n + 1 - }) //invariant(...) - } else { - var n = y - (while(n != 0) { - r = r + 1 - n = n - 1 - }) //invariant(...) - } - r - }) ensuring(_ == x+y) - -} diff --git a/testcases/graveyard/tutorials/07_Ex6_Mult.scala b/testcases/graveyard/tutorials/07_Ex6_Mult.scala deleted file mode 100644 index 04bbcae47f23975bbc1137e385a2d1a2d3b9687e..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/07_Ex6_Mult.scala +++ /dev/null @@ -1,31 +0,0 @@ -import leon.Utils._ - -/* VSTTE 2008 - Dafny paper */ - -/* - Add the loop invariants so that Leon can verify this function. -*/ - -object Mult { - - def mult(x : BigInt, y : BigInt): BigInt = ({ - var r = 0 - if(y < 0) { - var n = y - (while(n != 0) { - r = r - x - n = n + 1 - }) //invariant(...) - } else { - var n = y - (while(n != 0) { - r = r + x - n = n - 1 - }) //invariant(...) - } - r - }) ensuring(_ == x*y) - -} - - diff --git a/testcases/graveyard/tutorials/08_Ex7_MaxSum.scala b/testcases/graveyard/tutorials/08_Ex7_MaxSum.scala deleted file mode 100644 index 272dcc56adbf1673f5c6f38891744085801d3e9b..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/08_Ex7_MaxSum.scala +++ /dev/null @@ -1,43 +0,0 @@ -import leon.Utils._ - -/* VSTTE 2010 challenge 1 */ - -/* - Find the loop invariant. -*/ - - -object MaxSum { - - def maxSum(a: Array[BigInt]): (BigInt, BigInt) = ({ - require(a.length >= 0 && isPositive(a)) - var sum = 0 - var max = 0 - var i = 0 - (while(i < a.length) { - if(max < a(i)) - max = a(i) - sum = sum + a(i) - i = i + 1 - }) //invariant (...) - (sum, max) - }) ensuring(res => res._1 <= a.length * res._2) - - - def isPositive(a: Array[BigInt]): Boolean = { - require(a.length >= 0) - def rec(i: BigInt): Boolean = { - require(i >= 0) - if(i >= a.length) - true - else { - if(a(i) < 0) - false - else - rec(i+1) - } - } - rec(0) - } - -} diff --git a/testcases/graveyard/tutorials/09_Ex8_ListImp.scala b/testcases/graveyard/tutorials/09_Ex8_ListImp.scala deleted file mode 100644 index 4c10f9be1421f7c743d979ecb6b6163fdbc40371..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/09_Ex8_ListImp.scala +++ /dev/null @@ -1,53 +0,0 @@ -import leon.Utils._ - -/* - Find the loop invariants. -*/ - -object ListImp { - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def content(l: List) : Set[BigInt] = l match { - case Nil() => Set.empty[BigInt] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def size(l: List) : BigInt = { - var r = 0 - (while(!l.isInstanceOf[Nil]) { - r = r+1 - }) //invariant(...) - r - } ensuring(res => res >= 0) - - def reverse(l: List): List = { - var r: List = Nil() - var l2: List = l - - (while(!l2.isInstanceOf[Nil]) { - val Cons(head, tail) = l2 - l2 = tail - r = Cons(head, r) - }) //invariant(...) - - r - } ensuring(res => content(res) == content(l)) - - def append(l1 : List, l2 : List) : List = { - var r: List = l2 - var tmp: List = reverse(l1) - - (while(!tmp.isInstanceOf[Nil]) { - val Cons(head, tail) = tmp - tmp = tail - r = Cons(head, r) - }) //invariant(...) - - r - } ensuring(content(_) == content(l1) ++ content(l2)) - - -} diff --git a/testcases/graveyard/tutorials/10_Ex9_RedBlackTree.scala b/testcases/graveyard/tutorials/10_Ex9_RedBlackTree.scala deleted file mode 100644 index 9dd7ad92bfbcfd18fc629468cab0aa81b05baa06..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/10_Ex9_RedBlackTree.scala +++ /dev/null @@ -1,100 +0,0 @@ -import leon.Annotations._ -import leon.Utils._ - -/* - You found an implementation of a Red-black tree and you want to verify that - the add method does the correct thing. - The only additional specification you should need is for the ins method. -*/ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: BigInt, right: Tree) extends Tree - - sealed abstract class OptionInt - case class Some(v : BigInt) extends OptionInt - case class None() extends OptionInt - - def content(t: Tree) : Set[BigInt] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : BigInt = t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t : Tree) : BigInt = t match { - case Empty() => 1 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - // <<insert element x into the tree t>> - def ins(x: BigInt, t: Tree): Tree = { - //require(...) - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if (x < y) balance(c, ins(x, a), y, b) - else if (x == y) Node(c,a,y,b) - else balance(c,a,y,ins(x, b)) - } - } /*ensuring (res => )*/ - - def makeBlack(n: Tree): Tree = { - require(redDescHaveBlackChildren(n) && blackBalanced(n)) - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } ensuring(res => redNodesHaveBlackChildren(res) && blackBalanced(res)) - - def add(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - makeBlack(ins(x, t)) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res) && blackBalanced(res)) - - - def balance(c: Color, a: Tree, x: BigInt, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - } - } ensuring (res => content(res) == content(Node(c,a,x,b))) -} diff --git a/testcases/graveyard/tutorials/11_Ex10_SearchLinkedList.scala b/testcases/graveyard/tutorials/11_Ex10_SearchLinkedList.scala deleted file mode 100644 index f8ca2076af6f8803c986f1aaf0ef53e27fb15ea9..0000000000000000000000000000000000000000 --- a/testcases/graveyard/tutorials/11_Ex10_SearchLinkedList.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.Utils._ -import leon.Annotations._ - -/* - Add the missing postcondition. -*/ - - -object SearchLinkedList { - sealed abstract class List - case class Cons(head : BigInt, tail : List) extends List - case class Nil() extends List - - def size(list : List) : BigInt = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contains(list : List, elem : BigInt) : Boolean = (list match { - case Nil() => false - case Cons(x, xs) => x == elem || contains(xs, elem) - }) - - def firstZero(list : List) : BigInt = (list match { - case Nil() => 0 - case Cons(x, xs) => if (x == 0) 0 else firstZero(xs) + 1 - }) /*ensuring (res => )*/ - - def firstZeroAtPos(list : List, pos : BigInt) : Boolean = { - list match { - case Nil() => false - case Cons(x, xs) => if (pos == 0) x == 0 else x != 0 && firstZeroAtPos(xs, pos - 1) - } - } - - def goal(list : List, i : BigInt) : Boolean = { - if(firstZero(list) == i) { - if(contains(list, 0)) { - firstZeroAtPos(list, i) - } else { - i == size(list) - } - } else { - true - } - } holds -} diff --git a/testcases/graveyard/verification/graph/MST/SpanningTree.scala b/testcases/graveyard/verification/graph/MST/SpanningTree.scala deleted file mode 100644 index 3d421f6dc46c5dd8e77a9e38c5de603ff1d0b356..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/graph/MST/SpanningTree.scala +++ /dev/null @@ -1,206 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object SpanningTree { - case class Graph(nVertices : Int, edges : Set[(Int,Int)]) - - // Kruskal on unweighted graphs (thus not spanning tree of minimum weight) - def getSpanningTree(g : Graph) : Set[(Int, Int)] = { - require(invariant(g) && isUndirected(g) && isConnected(g.edges, - g.nVertices) && g.nVertices <= 3) - - var uf_map = Map.empty[Int, Int] //map to represent parent - //relationship to model union find - - var spanningSet = Set.empty[(Int,Int)] - var remainingEdges = g.edges - - (while(!isConnected(spanningSet, g.nVertices)) { - val next_edge = epsilon( (i : (Int, Int)) => - remainingEdges.contains(i) ) - - val p1 = uFind(next_edge._1, uf_map) - val p2 = uFind(next_edge._2, uf_map) - if(p1 != p2) { - spanningSet = spanningSet ++ Set(next_edge) ++ - Set((next_edge._2, next_edge._1)) - - uf_map = union(p1, p2, uf_map) - } - - remainingEdges = remainingEdges -- Set(next_edge) -- Set((next_edge._2, next_edge._1)) - - }) invariant(isAcyclic(spanningSet, g.nVertices)) - - spanningSet - } ensuring(x => isAcyclic(x, g.nVertices)) - - def getSpanningTreeBogus(g : Graph) : Set[(Int, Int)] = { - require(invariant(g) && isUndirected(g) && isConnected(g.edges, - g.nVertices) && g.nVertices <= 4) - - var spanningSet = Set.empty[(Int,Int)] - var remainingEdges = g.edges - - (while(!isConnected(spanningSet, g.nVertices)) { - val next_edge = epsilon( (i : (Int, Int)) => remainingEdges.contains(i) ) - remainingEdges = remainingEdges -- Set(next_edge) -- Set((next_edge._2, next_edge._1)) - - spanningSet = spanningSet ++ Set(next_edge) ++ Set((next_edge._2, next_edge._1)) - }) invariant(isAcyclic(spanningSet, g.nVertices)) - - spanningSet - } ensuring(x => isAcyclic(x, g.nVertices)) - - - def invariant(g : Graph) = { - def noSelfLoops(i : Int) : Boolean = { - if(i >= g.nVertices) true - else if(g.edges.contains(i,i)) - false - else - noSelfLoops(i+1) - } - - g.nVertices >= 0 // && noSelfLoops(0) - } - - /* - Smarter version of doing it? - */ - def isUndirected(g : Graph) : Boolean = { - def isUndirected0(s : Set[(Int, Int)]) : Boolean= { - if(s == Set.empty[(Int,Int)]) true - else { - val e = epsilon( (p : (Int,Int)) => s.contains(p) ) - if(g.edges.contains(e)) - isUndirected0(s -- Set(e)) - else - false - } - } - - isUndirected0(g.edges) - } - - /* - * Tests, whether the subgraph induced by edges is cycle-free. - */ - def isAcyclic(edges : Set[(Int,Int)], nVertices : Int) : Boolean = { - require(nVertices >= 0 && isUndirected(Graph(nVertices, edges))) - !calculateUF(edges, nVertices)._2 - } - - /* - * Does union-find on edgeSet. - * Returns the union-find tree and a boolean set to true if a cycle was found - */ - def calculateUF(edgeSet : Set[(Int,Int)], nVertices : Int) : - (Map[Int, Int], Boolean)= { - require(nVertices >= 0) - - var i = 0 - var uf = Map.empty[Int, Int] - var cycle = false - var edges = edgeSet - while(i < nVertices) { - var j = 0 - while(j < i) { - if(edges.contains((i,j))) { - val p1 = uFind(i, uf) - val p2 = uFind(j, uf) - if(p1 == p2) - cycle = true - else - uf = union(p1, p2, uf) - } - - j += 1 - } - i += 1 - } - - (uf, cycle) - } - - def isConnected(edges : Set[(Int,Int)], nVertices : Int) : Boolean - = { - require(nVertices >= 0) - val uf = calculateUF(edges, nVertices)._1 - - val p = uFind(0, uf) - var i = 1 - - var ret = true - while(i < nVertices && ret) { - if(uFind(i, uf) != p) - ret = false // 0, i are not connected - i += 1 - } - - ret - } - - /* - * Does union-find on edgeSet. - * Returns the union-find tree and a boolean set to true if a cycle was found - */ - def calculateUF(edgeSet : Map[(Int,Int), Int], nVertices : Int) : - (Map[Int, Int], Boolean)= { - require(nVertices >= 0) - - var i = 0 - var uf = Map.empty[Int, Int] - var cycle = false - var edges = edgeSet - while(i < nVertices) { - var j = 0 - while(j < nVertices) { - if(edges.isDefinedAt((i,j))) { - if(edges(i, j) != -1) { - val p1 = uFind(i, uf) - val p2 = uFind(j, uf) - if(p1 == p2) - cycle = true - else - uf = union(p1, p2, uf) - - //"remove" twin edge - edges = edges.updated((j,i), -1) - } - } - j += 1 - } - i += 1 - } - - (uf, cycle) - } - - /* ************************************* - Union find - *************************************** */ - def uFind(e : Int, s : Map[Int, Int]) : Int = { - if(!s.isDefinedAt(e)) e - else if(s(e) == e) e - else uFind(s(e), s) - } - - def union(e1 : Int, e2 : Int, s : Map[Int,Int]) : Map[Int, Int] = { - // naive union - val p1 = uFind(e1,s) - val p2 = uFind(e2, s) - - if(p1 != p2) - //naive union - s.updated(p1, p2) //only union if theiy are really in different trees - else - s - } - - def testUndirected() : Boolean = { - val e = Set.empty[(Int, Int)] ++ Set((1,2)) ++ Set((2,1)) ++ Set((1,3)) - isUndirected(Graph(4, e)) - } holds - -} diff --git a/testcases/graveyard/verification/graph/SetIteration.scala b/testcases/graveyard/verification/graph/SetIteration.scala deleted file mode 100644 index 47eb20aa7067aa8ac45a15190ebdf979175be85b..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/graph/SetIteration.scala +++ /dev/null @@ -1,76 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -/** Examples of iteration over set elements using 'epsilon'. - * - * First we implement a test for containment. This can easily be verified - * correct by Leon — because the post-condition can be specified concisely in - * concepts Leon understands. - * - * Next we implement a test for wether all values are at least some minimum, - * and try to prove that (∀x. x≥5) → (∀x. x≥2). Leon fails to prove this, - * despite proving an equivalent formulation using linked lists instead of sets - * (SimpleInduction.scala). - * - * Finally, we implement a method to find the cardinality of a set. Leon can - * prove things with this on concrete sets, as seen in sizeTest1(), but not on - * arbitrary sets, as in sizeTest2(). - */ -object SetIteration { - def iterateContains(set: Set[Int], v : Int) : Boolean ={ - if (set == Set.empty[Int]) - false - else { - val elt = epsilon( (i : Int) => set.contains(i) ) - if (elt==v) - true - else - iterateContains(set -- Set(elt), v) - } - } ensuring (_ == set.contains(v)) - - def contTest(set : Set[Int], v : Int) : Boolean = { - set.contains(v) == iterateContains(set, v) - } holds - - - def iterateMinVal(set: Set[Int], v : Int) : Boolean ={ - if (set == Set.empty[Int]) - true - else { - val elt = epsilon( (i : Int) => set.contains(i) ) - if (elt >= v) - iterateMinVal(set -- Set(elt), v) - else - false - } - } - - def sizeMinVal(set : Set[Int]) : Boolean = { - !iterateMinVal(set, 5) || iterateMinVal(set, 2) - } holds // proof fails - - - def iterateSize(set: Set[Int]) : Int ={ - if (set == Set.empty[Int]) - 0 - else { - val elt = epsilon( (i : Int) => set.contains(i) ) - 1 + iterateSize(set -- Set(elt)) - } - }ensuring (_ >= 0) - - def sizeTest1() : Boolean = { - iterateSize(Set.empty)+3 == iterateSize(Set(4,8,22)) - } holds - def sizeTestFalse(set : Set[Int]) : Boolean = { - val size1 = iterateSize(set) - val size2 = iterateSize(set ++ Set(32)) - size1+1 == size2 - } holds // gives correct counter example: set=Set(32) - def sizeTest2(set : Set[Int]) : Boolean = { - val size1 = iterateSize(set) - val size2 = iterateSize(set ++ Set(32)) - size1+1 == size2 || size1 == size2 - } holds // proof fails -} diff --git a/testcases/graveyard/verification/graph/dijkstras/DijkstrasSet.scala b/testcases/graveyard/verification/graph/dijkstras/DijkstrasSet.scala deleted file mode 100644 index 96571c95f46a39f2d06abcfc3547f6587a67eee7..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/graph/dijkstras/DijkstrasSet.scala +++ /dev/null @@ -1,152 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -/** Implementation of Dijkstra's algorithm. Iterates over vertex IDs, looking - * distances up in a map, to find the nearest unvisited node. - */ -object DijkstrasSet { - /*************************************************************************** - * Graph representation and algorithms - **************************************************************************/ - case class Graph(nVertices : Int, edges : Map[(Int,Int), Int]) - - // TODO: disallow self edges? - def invariant(g : Graph) = g.nVertices >= 0 - - // true if x & y have same number of nodes and y has all x's edges - def isSubGraph(x : Graph, y : Graph) : Boolean = { - require(invariant(x) && invariant(y)) - - var ret : Boolean = (x.nVertices == y.nVertices) - if (ret){ - var i = 0 - while(i<x.nVertices) { - var j = 0; - while(j < x.nVertices) { - ret &&= !x.edges.isDefinedAt((i,j)) || y.edges.isDefinedAt((i,j)) - j += 1 - } - i += 1 - } - } - ret - } - - // true if every edge has a weight of at least 0 - def nonnegativeWeights(g : Graph) : Boolean = { - require(invariant(g)) - - var ret : Boolean = true - var i = 0 - while(i<g.nVertices) { - var j = 0; - while(j < g.nVertices) { - ret = if (g.edges.isDefinedAt((i,j))){ - if (g.edges((i,j)) >= 0) ret - else false - } else ret - j += 1 - } - i += 1 - } - ret - } - - - /*************************************************************************** - * Dijkstra's algorithm - **************************************************************************/ - - def mapDefinedFor(map:Map[Int,Int], set:Set[Int]) : Boolean = { - if (set == Set.empty[Int]) - true - else{ - val i = epsilon( (i:Int) => set.contains(i) ) - if (map.isDefinedAt(i)) - mapDefinedFor(map, set -- Set(i)) - else - false - } - } - - /** Find the unvisited node with lowest distance. - * - * @param visited List of visited nodes - * @param distances Map of nodes to distances. Should be defined for all - * elements in toVisit. - * @return Best node, best distance, or (-1, Int.MaxValue) if no nodes. - */ - def smallestUnvisited( nVertices:Int, visited:Set[Int], distances:Map[Int,Int] ) : (Int,Int) ={ - require(mapDefinedFor(distances, visited)) -// println("smallestUnvisited: "+nVertices+", "+visited+", "+distances) - var bestNode = -1 - var bestDist = Int.MaxValue - var node = 0 - while (node<nVertices){ - if (!visited.contains(node) && distances(node)<bestDist){ - bestNode = node - bestDist = distances(node) - } - node += 1 - } -// println("result: "+bestNode, bestDist) - (bestNode, bestDist) - } ensuring (ret => (ret._1== -1 && ret._2==Int.MaxValue) || - (0<=ret._1 && ret._1<nVertices && !visited.contains(ret._1) && distances(ret._1) == ret._2)) - - - // common precondition: g is a valid graph and a and b are valid nodes - def bounds(g : Graph, a : Int, b : Int) : Boolean = - invariant(g) && 0 <= a && a < g.nVertices && 0 <= b && b < g.nVertices - - def min(a:Int, b:Int) = if (a<b) a else b - // Generate map of "inf" distances for each node. "Inf" is Int.MaxValue. - def infDistances(n:Int) : Map[Int,Int] ={ - if (n < 0) Map.empty[Int,Int] - else infDistances(n-1).updated(n,Int.MaxValue) - } - - // find the shortest path from a to b in g, and return its distance - // return -1 if the two aren't connected - def shortestPath(g : Graph, a : Int, b : Int) : Int = { - require(bounds(g,a,b) && nonnegativeWeights(g)) - - // We should always have at least some node if we haven't reached b (so - // long as b is in the graph and connected to a). - def spVisit (visited:Set[Int], distances:Map[Int,Int]) : Int = { - require(bounds(g,a,b)) -// println("spVisit: "+visited+", "+distances) - - val (node,dist) = smallestUnvisited(g.nVertices, visited, distances) - if (node == b || node < 0) - dist - else { - var newDistances = distances - var n = 0 - - (while (n < g.nVertices){ - if (n != node && !visited.contains(n) && g.edges.isDefinedAt((node,n))){ - newDistances = newDistances.updated(n, - min(newDistances(n), dist+g.edges((node,n)))) - } - n = n + 1 - }) invariant(/*TODO: and that all elements in newVisitable are defined in newDistances*/ n >= 0 && n <= g.nVertices) - - spVisit(visited ++ Set(node), newDistances) - } - } - - // We start from a, which has distance 0. All other nodes are unreachable. - spVisit(Set.empty, infDistances(g.nVertices).updated(a,0)) - } // TODO ensuring (res => res >= -1 /*(if (isReachable(g,a,b)) res>=0 else res== -1)*/) - - def main(args: Array[String]) { - val spanningTreeE = Map((0,1) -> 1, (0,2) -> 2, (2,3) -> 5, (0,3) -> 10, (3,2) -> 0) - val spanningTree = Graph(4, spanningTreeE) - val singleGraph = Graph(1, Map.empty) - - println(spanningTree) - println("from 0 to 3 (should be 7): "+shortestPath(spanningTree,0,3)) - println("from 3 to 1 (no path): "+shortestPath(spanningTree,3,1)) - } -} diff --git a/testcases/graveyard/verification/graph/dijkstras/DijkstrasSetToVisit.scala b/testcases/graveyard/verification/graph/dijkstras/DijkstrasSetToVisit.scala deleted file mode 100644 index 3664d99da6e04a8c1ad916d5dc0493e8b4f60b75..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/graph/dijkstras/DijkstrasSetToVisit.scala +++ /dev/null @@ -1,147 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -/** Implementation of Dijkstra's algorithm. Maintains a list of visitable - * vertices, and iterates over this, looking distances up in a map. - */ -object DijkstrasSetToVisit { - /*************************************************************************** - * Graph representation and algorithms - **************************************************************************/ - case class Graph(nVertices : Int, edges : Map[(Int,Int), Int]) - - // TODO: disallow self edges? - def invariant(g : Graph) = g.nVertices >= 0 - - // true if x & y have same number of nodes and y has all x's edges - def isSubGraph(x : Graph, y : Graph) : Boolean = { - require(invariant(x) && invariant(y)) - - var ret : Boolean = (x.nVertices == y.nVertices) - if (ret){ - var i = 0 - while(i<x.nVertices) { - var j = 0; - while(j < x.nVertices) { - ret &&= !x.edges.isDefinedAt((i,j)) || y.edges.isDefinedAt((i,j)) - j += 1 - } - i += 1 - } - } - ret - } - - // true if every edge has a weight of at least 0 - def nonnegativeWeights(g : Graph) : Boolean = { - require(invariant(g)) - - var ret : Boolean = true - var i = 0 - while(i<g.nVertices) { - var j = 0; - while(j < g.nVertices) { - ret = if (g.edges.isDefinedAt((i,j))){ - if (g.edges((i,j)) >= 0) ret - else false - } else ret - j += 1 - } - i += 1 - } - ret - } - - - /*************************************************************************** - * Dijkstra's algorithm - **************************************************************************/ - - /** Find the unvisited node with lowest distance. - * - * @param toVisit List of nodes to visit - * @param distances Map of nodes to distances. Should be defined for all - * elements in toVisit. - * @param best Best node, distance so far, or -1, Int.MaxValue - * @return Best node, best distance, or best if no nodes. - */ - def smallestUnvisited0( toVisit:Set[Int], distances:Map[Int,Int], best:(Int,Int) ) : (Int,Int) ={ - if (toVisit == Set.empty[Int]) - best - else{ - val node = epsilon( (x:Int) => toVisit.contains(x) ) - val dist = distances(node) - val next:(Int,Int) = - if (dist < best._2) (node,dist) - else best - smallestUnvisited0(toVisit -- Set(node), distances, next) - } - } - /** Find the unvisited node with lowest distance. - * - * @param toVisit List of nodes to visit - * @param distances Map of nodes to distances. Should be defined for all - * elements in toVisit. - * @return Best node, best distance, or (-1, Int.MaxValue) if no nodes. - */ - def smallestUnvisited( toVisit:Set[Int], distances:Map[Int,Int] ) : (Int,Int) ={ - smallestUnvisited0(toVisit, distances, (-1, Int.MaxValue)) - } ensuring (ret => (ret._1== -1 && ret._2==Int.MaxValue) || (toVisit.contains(ret._1) && distances(ret._1) == ret._2)) - - - // common precondition: g is a valid graph and a and b are valid nodes - def bounds(g : Graph, a : Int, b : Int) : Boolean = - invariant(g) && 0 <= a && a < g.nVertices && 0 <= b && b < g.nVertices - - def min(a:Int, b:Int) = if (a<b) a else b - // Generate map of "inf" distances for each node. "Inf" is Int.MaxValue. - def infDistances(n:Int) : Map[Int,Int] ={ - if (n < 0) Map.empty[Int,Int] - else infDistances(n-1).updated(n,Int.MaxValue) - } - - // find the shortest path from a to b in g, and return its distance - // return -1 if the two aren't connected - def shortestPath(g : Graph, a : Int, b : Int) : Int = { - require(bounds(g,a,b) && nonnegativeWeights(g)) - - // We should always have at least some node if we haven't reached b (so - // long as b is in the graph and connected to a). - def spVisit (visited:Set[Int], toVisit:Set[Int], distances:Map[Int,Int]) : Int = { - require(bounds(g,a,b) && toVisit.contains(b)) - - val (node,dist) = smallestUnvisited(toVisit, distances) - if (node == b || node < 0) - dist - else { - var newVisitable = toVisit - var newDistances = distances - var n = 0 - - (while (n < g.nVertices){ - if (n != node && !visited.contains(n) && g.edges.isDefinedAt((node,n))){ - newVisitable = newVisitable++Set(n) - newDistances = newDistances.updated(n, - min(newDistances(n), dist+g.edges((node,n)))) - } - n = n + 1 - }) invariant(/*TODO: and that all elements in newVisitable are defined in newDistances*/ n >= 0 && n <= g.nVertices) - - spVisit(visited ++ Set(node), newVisitable, newDistances) - } - } - - // We start from a, which has distance 0. All other nodes are unreachable. - spVisit(Set.empty, Set(a), infDistances(g.nVertices).updated(a,0)) - } // TODO ensuring (res => res >= -1 /*(if (isReachable(g,a,b)) res>=0 else res== -1)*/) - - def main(args: Array[String]) { - val spanningTreeE = Map((0,1) -> 1, (0,2) -> 2, (2,3) -> 5, (0,3) -> 10, (3,2) -> 0) - val spanningTree = Graph(4, spanningTreeE) - val singleGraph = Graph(1, Map.empty) - - println(spanningTree) - println("from 0 to 3 (should be 7): "+shortestPath(spanningTree,0,3)) - println("from 3 to 1 (no path): "+shortestPath(spanningTree,3,1)) - } -} diff --git a/testcases/graveyard/verification/vmcai2011-testcases/CADE07.scala b/testcases/graveyard/verification/vmcai2011-testcases/CADE07.scala deleted file mode 100644 index 0af2fdd4980d2051fa6a5a34950fe236546b1bb4..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/vmcai2011-testcases/CADE07.scala +++ /dev/null @@ -1,205 +0,0 @@ -import leon.lang._ - -object CADE07 { - def vc1(listContent: Set[Int]) : Boolean = { - (listContent.size == 0) == (listContent == Set.empty[Int]) - } ensuring(_ == true) - - def vc2(x: Int, listContent: Set[Int]) : Set[Int] = { - require(!listContent.contains(x)) - listContent ++ Set(x) - } ensuring(_.size == listContent.size + 1) - - def vc2a(listRoot: Int, list: Set[Int], x: Int, listContent: Set[Int], objectAlloc: Set[Int], objct: Set[Int]) : Set[Int] = { - require( - list.contains(listRoot) - && !listContent.contains(x) - && listContent.subsetOf(objectAlloc) - && objct.contains(x) - && objectAlloc.contains(x)) - - listContent ++ Set(x) - } ensuring(_.size == listContent.size + 1) - - def vc2b(listRoot: Int, list: Set[Int], x: Int, listContent: Set[Int], objectAlloc: Set[Int], objct: Set[Int]) : Set[Int] = { - require( - list.contains(listRoot) - && listContent.subsetOf(objectAlloc) - && objct.contains(x) - && objectAlloc.contains(x)) - - listContent ++ Set(x) - } ensuring(_.size == listContent.size + 1) - - def vc3(x: Int, listContent: Set[Int]) : Set[Int] = { - listContent ++ Set(x) - } ensuring(_.size <= listContent.size + 1) - - def vc3a(x: Int, a: Int, b: Int, alloc: Set[Int], listContent: Set[Int]) : Set[Int] = { - require( - listContent.subsetOf(alloc) - && alloc.contains(a) - && alloc.contains(b) - ) - listContent ++ Set(x) - } ensuring(_.size <= listContent.size + 1) - - def vc3b(x: Int, a: Int, b: Int, alloc: Set[Int], listContent: Set[Int]) : Set[Int] = { - require( - listContent.subsetOf(alloc) - && alloc.contains(a) - && alloc.contains(b) - ) - listContent ++ Set(x) - } ensuring(_.size == listContent.size + 1) - - def vc4(content: Set[Int], alloc: Set[Int], x1: Int, x2: Int, x3: Int) : Set[Int] = { - require( - content.subsetOf(alloc) - && !alloc.contains(x1) - && !(alloc ++ Set(x1)).contains(x2) - && !(alloc ++ Set(x1, x2)).contains(x3) - ) - content ++ Set(x1, x2, x3) - } ensuring(_.size == content.size + 3) - - def vc4b(content: Set[Int], alloc: Set[Int], x1: Int, x2: Int, x3: Int) : Set[Int] = { - require( - content.subsetOf(alloc) - && !alloc.contains(x1) - && !alloc.contains(x2) - && !(alloc ++ Set(x1, x2)).contains(x3) - ) - content ++ Set(x1, x2, x3) - } ensuring(_.size == content.size + 3) - - def vc5(content: Set[Int], alloc0: Set[Int], x1: Int, alloc1: Set[Int], x2: Int, alloc2: Set[Int], x3: Int) : Set[Int] = { - require( - content.subsetOf(alloc0) - && !alloc0.contains(x1) - && (alloc0 ++ Set(x1)).subsetOf(alloc1) - && !alloc1.contains(x2) - && (alloc1 ++ Set(x2)).subsetOf(alloc2) - && !alloc2.contains(x3) - ) - content ++ Set(x1, x2, x3) - } ensuring(_.size == content.size + 3) - - def vc5b(content: Set[Int], alloc0: Set[Int], x1: Int, alloc1: Set[Int], x2: Int, alloc2: Set[Int], x3: Int) : Set[Int] = { - require( - content.subsetOf(alloc0) - && (alloc0 ++ Set(x1)).subsetOf(alloc1) - && !alloc1.contains(x2) - && (alloc1 ++ Set(x2)).subsetOf(alloc2) - && !alloc2.contains(x3) - ) - content ++ Set(x1, x2, x3) - } ensuring(_.size == content.size + 3) - - def vc6(x: Int, c: Set[Int], c1: Set[Int], alloc0: Set[Int], alloc1: Set[Int], alloc2: Set[Int]) : Set[Int] = { - require( - c.contains(x) - && c1 == c -- Set(x) - && (alloc1 -- alloc0).size <= 1 - && (alloc2 -- alloc1).size <= c1.size - ) - - alloc2 -- alloc0 - } ensuring(_.size <= c.size) - - def vc6a(l1 : Int, nul : Int, ths : Int, tmp357 : Int, list : Set[Int], objct : Set[Int], objAlloc : Set[Int], objAlloc16 : Set[Int], objAlloc30 : Set[Int], objAlloc45 : Set[Int], objAlloc60 : Set[Int], objAlloc74 : Set[Int], listContent : Set[Int], listContent59 : Set[Int], listContent73 : Set[Int], s241 : Set[Int], s142 : Set[Int], tmp171 : Boolean) : Set[Int] = { - require( - l1 != nul - && l1 != ths - && ths != nul - && list.contains(ths) - && objAlloc.contains(ths) - && list.contains(l1) - && objAlloc.contains(l1) - && objAlloc74 == objAlloc - && listContent73 == listContent - && (objAlloc subsetOf objAlloc74) - && !tmp171 - && objAlloc60 == objAlloc74 - && listContent59 == listContent73 - && (objAlloc74 subsetOf objAlloc60) - && objct.contains(tmp357) - && objAlloc60.contains(tmp357) - && objAlloc45 == objAlloc60 - && (objAlloc60 subsetOf objAlloc45) - && objAlloc45 == objAlloc - && s142.contains(tmp357) - && s241 == s142 -- Set(tmp357) - && (objAlloc30 -- objAlloc45).size <= 1 - && (objAlloc45 subsetOf objAlloc30) - && (objAlloc30 -- objAlloc).size <= 1 - && (objAlloc30 subsetOf objAlloc16) - && (objAlloc16 -- objAlloc30).size <= s241.size - ) - objAlloc16 -- objAlloc - } ensuring(_.size <= s142.size) - - def vc6b(l1 : Int, nul : Int, ths : Int, tmp357 : Int, list : Set[Int], objct : Set[Int], objAlloc : Set[Int], objAlloc16 : Set[Int], objAlloc30 : Set[Int], objAlloc45 : Set[Int], objAlloc60 : Set[Int], objAlloc74 : Set[Int], listContent : Set[Int], listContent59 : Set[Int], listContent73 : Set[Int], s241 : Set[Int], s142 : Set[Int], tmp171 : Boolean) : Set[Int] = { - require( - l1 != nul - && l1 != ths - && ths != nul - && list.contains(ths) - && objAlloc.contains(ths) - && list.contains(l1) - && objAlloc.contains(l1) - && objAlloc74 == objAlloc - && listContent73 == listContent - && (objAlloc subsetOf objAlloc74) - && !tmp171 - && objAlloc60 == objAlloc74 - && listContent59 == listContent73 - && (objAlloc74 subsetOf objAlloc60) - && objct.contains(tmp357) - && objAlloc60.contains(tmp357) - && objAlloc45 == objAlloc60 - && (objAlloc60 subsetOf objAlloc45) - && objAlloc45 == objAlloc - && s142.contains(tmp357) - && s241 == s142 -- Set(tmp357) - && (objAlloc30 -- objAlloc45).size <= 1 - && (objAlloc45 subsetOf objAlloc30) - && (objAlloc30 -- objAlloc).size <= 1 - && (objAlloc30 subsetOf objAlloc16) - && (objAlloc16 -- objAlloc30).size <= s241.size - ) - objAlloc16 -- objAlloc - } ensuring(_.size < s142.size) - - def vc6c(l1 : Int, nul : Int, ths : Int, tmp357 : Int, list : Set[Int], objct : Set[Int], objAlloc : Set[Int], objAlloc16 : Set[Int], objAlloc30 : Set[Int], objAlloc45 : Set[Int], objAlloc60 : Set[Int], objAlloc74 : Set[Int], listContent : Set[Int], listContent59 : Set[Int], listContent73 : Set[Int], s241 : Set[Int], s142 : Set[Int], tmp171 : Boolean) : Set[Int] = { - require( - l1 != nul - && l1 != ths - && ths != nul - && list.contains(ths) - && objAlloc.contains(ths) - && list.contains(l1) - && objAlloc.contains(l1) - && objAlloc74 == objAlloc - && listContent73 == listContent - && (objAlloc subsetOf objAlloc74) - && !tmp171 - && objAlloc60 == objAlloc74 - && listContent59 == listContent73 - && (objAlloc74 subsetOf objAlloc60) - && objct.contains(tmp357) - && objAlloc60.contains(tmp357) - && objAlloc45 == objAlloc60 - && (objAlloc60 subsetOf objAlloc45) - && objAlloc45 == objAlloc -// && s142.contains(tmp357) - && s241 == s142 -- Set(tmp357) - && (objAlloc30 -- objAlloc45).size <= 1 - && (objAlloc45 subsetOf objAlloc30) - && (objAlloc30 -- objAlloc).size <= 1 - && (objAlloc30 subsetOf objAlloc16) - && (objAlloc16 -- objAlloc30).size <= s241.size - ) - objAlloc16 -- objAlloc - } ensuring(_.size <= s142.size) -} diff --git a/testcases/graveyard/verification/vmcai2011-testcases/CADE07Hard.scala b/testcases/graveyard/verification/vmcai2011-testcases/CADE07Hard.scala deleted file mode 100644 index e6e9aa0622465ad1eb4a5437d814ed8fedad2466..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/vmcai2011-testcases/CADE07Hard.scala +++ /dev/null @@ -1,99 +0,0 @@ -import leon.lang._ - -object CADE07Hard { - def vc6a(l1 : Int, nul : Int, ths : Int, tmp357 : Int, list : Set[Int], objct : Set[Int], objAlloc : Set[Int], objAlloc16 : Set[Int], objAlloc30 : Set[Int], objAlloc45 : Set[Int], objAlloc60 : Set[Int], objAlloc74 : Set[Int], listContent : Set[Int], listContent59 : Set[Int], listContent73 : Set[Int], s241 : Set[Int], s142 : Set[Int], tmp171 : Boolean) : Set[Int] = { - require( - l1 != nul - && l1 != ths - && ths != nul - && list.contains(ths) - && objAlloc.contains(ths) - && list.contains(l1) - && objAlloc.contains(l1) - && objAlloc74 == objAlloc - && listContent73 == listContent - && (objAlloc subsetOf objAlloc74) - && !tmp171 - && objAlloc60 == objAlloc74 - && listContent59 == listContent73 - && (objAlloc74 subsetOf objAlloc60) - && objct.contains(tmp357) - && objAlloc60.contains(tmp357) - && objAlloc45 == objAlloc60 - && (objAlloc60 subsetOf objAlloc45) - && objAlloc45 == objAlloc - && s142.contains(tmp357) - && s241 == s142 -- Set(tmp357) - && (objAlloc30 -- objAlloc45).size <= 1 - && (objAlloc45 subsetOf objAlloc30) - && (objAlloc30 -- objAlloc).size <= 1 - && (objAlloc30 subsetOf objAlloc16) - && (objAlloc16 -- objAlloc30).size <= s241.size - ) - objAlloc16 -- objAlloc - } ensuring(_.size <= s142.size) - - def vc6b(l1 : Int, nul : Int, ths : Int, tmp357 : Int, list : Set[Int], objct : Set[Int], objAlloc : Set[Int], objAlloc16 : Set[Int], objAlloc30 : Set[Int], objAlloc45 : Set[Int], objAlloc60 : Set[Int], objAlloc74 : Set[Int], listContent : Set[Int], listContent59 : Set[Int], listContent73 : Set[Int], s241 : Set[Int], s142 : Set[Int], tmp171 : Boolean) : Set[Int] = { - require( - l1 != nul - && l1 != ths - && ths != nul - && list.contains(ths) - && objAlloc.contains(ths) - && list.contains(l1) - && objAlloc.contains(l1) - && objAlloc74 == objAlloc - && listContent73 == listContent - && (objAlloc subsetOf objAlloc74) - && !tmp171 - && objAlloc60 == objAlloc74 - && listContent59 == listContent73 - && (objAlloc74 subsetOf objAlloc60) - && objct.contains(tmp357) - && objAlloc60.contains(tmp357) - && objAlloc45 == objAlloc60 - && (objAlloc60 subsetOf objAlloc45) - && objAlloc45 == objAlloc - && s142.contains(tmp357) - && s241 == s142 -- Set(tmp357) - && (objAlloc30 -- objAlloc45).size <= 1 - && (objAlloc45 subsetOf objAlloc30) - && (objAlloc30 -- objAlloc).size <= 1 - && (objAlloc30 subsetOf objAlloc16) - && (objAlloc16 -- objAlloc30).size <= s241.size - ) - objAlloc16 -- objAlloc - } ensuring(_.size < s142.size) - - def vc6c(l1 : Int, nul : Int, ths : Int, tmp357 : Int, list : Set[Int], objct : Set[Int], objAlloc : Set[Int], objAlloc16 : Set[Int], objAlloc30 : Set[Int], objAlloc45 : Set[Int], objAlloc60 : Set[Int], objAlloc74 : Set[Int], listContent : Set[Int], listContent59 : Set[Int], listContent73 : Set[Int], s241 : Set[Int], s142 : Set[Int], tmp171 : Boolean) : Set[Int] = { - require( - l1 != nul - && l1 != ths - && ths != nul - && list.contains(ths) - && objAlloc.contains(ths) - && list.contains(l1) - && objAlloc.contains(l1) - && objAlloc74 == objAlloc - && listContent73 == listContent - && (objAlloc subsetOf objAlloc74) - && !tmp171 - && objAlloc60 == objAlloc74 - && listContent59 == listContent73 - && (objAlloc74 subsetOf objAlloc60) - && objct.contains(tmp357) - && objAlloc60.contains(tmp357) - && objAlloc45 == objAlloc60 - && (objAlloc60 subsetOf objAlloc45) - && objAlloc45 == objAlloc -// && s142.contains(tmp357) - && s241 == s142 -- Set(tmp357) - && (objAlloc30 -- objAlloc45).size <= 1 - && (objAlloc45 subsetOf objAlloc30) - && (objAlloc30 -- objAlloc).size <= 1 - && (objAlloc30 subsetOf objAlloc16) - && (objAlloc16 -- objAlloc30).size <= s241.size - ) - objAlloc16 -- objAlloc - } ensuring(_.size <= s142.size) -} diff --git a/testcases/graveyard/verification/vmcai2011-testcases/Giuliano.scala b/testcases/graveyard/verification/vmcai2011-testcases/Giuliano.scala deleted file mode 100644 index b69f0948506235e380c2ead20b688adddce93b25..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/vmcai2011-testcases/Giuliano.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ - -object Giuliano { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def f(x: Int) : Int = { throw new Exception("...") } - - def form1(x: Int, y: Set[Int]) : Boolean = { - // y.contains(x.head) && y.size == x.head - x != f(x) || f(x) == f(f(x)) - } // ensuring(_ == true) - - def form2(f: Int, n: Int, servers: Set[Int], bizServers: Set[Int], corrServers: Set[Int], s: Set[Int]) : Boolean = { - require( - s.subsetOf(servers) - && s.size > f - && servers == corrServers ++ bizServers - && bizServers.size == f - && servers.size == n - && n > 3 - && f > 0 - && 3 * f < n - ) - (corrServers ** s).size >= 1 - } ensuring(_ == true) -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/graveyard/verification/vmcai2011-testcases/JustFormulas.scala b/testcases/graveyard/verification/vmcai2011-testcases/JustFormulas.scala deleted file mode 100644 index f8c9b84a011e9cae15c799b03739a5815ce428d8..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/vmcai2011-testcases/JustFormulas.scala +++ /dev/null @@ -1,65 +0,0 @@ -import leon.lang._ - -object JustFormulas { - // These are just to provide some "uninterpreted function symbols" - // Use the option -P:leon:tolerant to avoid warnings about it. - def f1(x: Int) : Int = { throw new Exception("Not implemented") } - def f2(s: Set[Int]) : Set[Int] = { throw new Exception("Not implemented") } - def f3(x: Int) : Set[Int] = { throw new Exception("Not implemented") } - def f4(s: Set[Int]) : Int = { throw new Exception("Not implemented") } - - def vc1_V(x: Set[Int]) : Boolean = { - (x.size == 0) == (x == Set.empty[Int]) - } ensuring(_ == true) - - def vc2_V(x: Set[Int], y: Set[Int]) : Boolean = { - (x == y) == (x -- y == Set.empty[Int] && y -- x == Set.empty[Int]) - } ensuring(_ == true) - - def vc3_I(x: Set[Int], y: Set[Int]) : Boolean = { - (x ++ y).size > x.size + y.size - (x ** y).size - } ensuring(_ == true) - - def vc4_V(x: Set[Int], y: Set[Int], z: Set[Int]) : Boolean = { - (x ++ y ++ z).size == x.size + y.size + z.size + (x ** y ** z).size - (x ** y).size - (x ** z).size - (y ** z).size - } ensuring(_ == true) - - def vc5_V(x: Int, y: Int, a: Set[Int], b: Set[Int]) : Boolean = { - require( - a.contains(f1(x)) - && b.contains(f1(y)) - && x < y + 1 - && 2*y - 1 < 2*x - ) - (a ++ b).size == a.size + b.size - } ensuring(!_) - - def vc6_V(x: Int, y: Int, a: Set[Int], b: Set[Int]) : Boolean = { - require( - (!((a -- b).size == 0 && (b -- a).size == 0) || a == b) - && f2(a).contains(x) - && f2(b).contains(y) - && (a -- b) == Set.empty[Int] - && (b -- a) == Set.empty[Int] - && f2(b).size < 2 - ) - x != y - } ensuring(!_) - - def vc7_I(a: Set[Int], b: Set[Int]) : Boolean = { - require( - a == Set(1, 2, 3) - && (b subsetOf a) - ) - a.contains(b.size) - } ensuring(_ == true) - - def vc8_V(a: Set[Int], b: Set[Int]) : Boolean = { - require( - a == Set(1, 2, 3) - && (b subsetOf a) - && b != Set.empty[Int] - ) - a.contains(b.size) - } ensuring(_ == true) -} diff --git a/testcases/graveyard/verification/vmcai2011-testcases/ListProperties.scala b/testcases/graveyard/verification/vmcai2011-testcases/ListProperties.scala deleted file mode 100644 index aaa830d37894bf0a8979d76dc6690351a813d11c..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/vmcai2011-testcases/ListProperties.scala +++ /dev/null @@ -1,97 +0,0 @@ -import leon.lang._ - -object IntListProperties { - sealed abstract class IntList - case class Cons(head: Int, tail: IntList) extends IntList - case class Nil() extends IntList - - def size(list: IntList) : Int = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - sealed abstract class IntTree - case class Node(left: IntTree, value: Int, right: IntTree) extends IntTree - case class Leaf() extends IntTree - - def size(tree: IntTree) : Int = (tree match { - case Leaf() => 0 - case Node(l,_,r) => 1 + size(l) + size(r) - }) ensuring(_ >= 0) - - def height(tree: IntTree) : Int = (tree match { - case Leaf() => 0 - case Node(l,_,r) => { - val hl = height(l) - val hr = height(r) - (if(hl > hr) hl else hr) + 1 - } - }) ensuring(res => res >= 0 && res <= size(tree)) - - def pickOne(s: Set[Int]) : Int = { - require(s != Set.empty[Int]) - throw new Exception("Uninterpreted.") - 0 - } ensuring(s.contains(_)) - - def listContent(list: IntList) : Set[Int] = (list match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ listContent(xs) - }) ensuring(_.size <= size(list)) - - def treeContent(tree: IntTree) : Set[Int] = (tree match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => treeContent(l) ++ Set(v) ++ treeContent(r) - }) ensuring(_.size <= size(tree)) - - def listReverse(list: IntList, tsil: IntList) : IntList = { - list match { - case Nil() => tsil - case Cons(x, xs) => listReverse(xs, Cons(x, tsil)) - } - } ensuring(res => listContent(res) == listContent(list) ++ listContent(tsil)) - - def treeMirror(tree: IntTree) : IntTree = (tree match { - case Leaf() => Leaf() - case Node(l, v, r) => Node(treeMirror(r), v, treeMirror(l)) - }) ensuring(res => treeContent(res) == treeContent(tree)) - - def listFromSet(s: Set[Int]) : IntList = listFromSet0(s, Nil()) ensuring(res => - listContent(res) == s - && size(res) == s.size - ) - def listFromSet0(s: Set[Int], acc: IntList) : IntList = { - require(listContent(acc) ** s == Set.empty[Int]) - if(s == Set.empty[Int]) { - acc - } else { - val e = pickOne(s) - listFromSet0(s -- Set(e), Cons(e, acc)) - } - } ensuring(res => - listContent(res) == listContent(acc) ++ s - && size(res) == size(acc) + s.size - ) - - def treeToList0(tree: IntTree, acc: IntList) : IntList = { - tree match { - case Leaf() => acc - case Node(l,v,r) => l match { - case Leaf() => treeToList0(r, Cons(v, acc)) - case Node(l2,v2,r2) => treeToList0(Node(l2, v2, Node(r2, v, r)), acc) - } - } - } ensuring(listContent(_).size == treeContent(tree).size + listContent(acc).size) - - def concatReverse(l1: IntList, l2: IntList) : IntList = concatReverse0(l1, l2, Nil()) - def concatReverse0(l1: IntList, l2: IntList, acc: IntList) : IntList = { - l1 match { - case Nil() => l2 match { - case Nil() => acc - case Cons(y, ys) => concatReverse0(Nil(), ys, Cons(y, acc)) - } - case Cons(x, xs) => concatReverse0(xs, l2, Cons(x, acc)) - } - //} ensuring(res => listContent(res).size <= listContent(l1).size + listContent(l2).size + listContent(acc).size) - } ensuring(res => listContent(res) == listContent(l1) ++ listContent(l2) ++ listContent(acc)) -} diff --git a/testcases/graveyard/verification/vmcai2011-testcases/PaperExamples.scala b/testcases/graveyard/verification/vmcai2011-testcases/PaperExamples.scala deleted file mode 100644 index 9ee07e0b4c58ef77a7a76b7aab26493f210612f4..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/vmcai2011-testcases/PaperExamples.scala +++ /dev/null @@ -1,36 +0,0 @@ -import leon.lang._ - -object PaperExamples { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def usize(list: List) : Int = { throw new Exception("uninterpreted") } - def ucont(list: List) : Set[Int] = { throw new Exception("uninterpreted") } - - def intro_V(list: List, x: Int, xs: List) : Boolean = { - require( - (list == Nil() || list == Cons(x, xs)) - && (usize(Nil()) == 0 && usize(Cons(x, xs)) == 1 + usize(xs)) - && (ucont(Nil()) == Set.empty[Int] && ucont(Cons(x, xs)) == Set(x) ++ ucont(xs)) - && ucont(xs).size <= usize(xs) - ) - ucont(list).size <= usize(list) - } ensuring(_ == true) - - def naive_I(a: Set[Int], b: Set[Int], c: Set[Int]) : Boolean = { - require( - a.size > 1 - && a.subsetOf(b) - ) - (b ** c).size > 2 - } ensuring(_ == true) - - def decomposition_I(a: Set[Int], b: Set[Int], c: Set[Int], d: Set[Int]) : Boolean = { - require( - (a -- b).size > (a ** b).size - && (b ** c ** d) == Set.empty[Int] - ) - (b -- d).size <= (b -- c).size - } ensuring(_ == true) -} diff --git a/testcases/graveyard/verification/vmcai2011-testcases/SanityChecks.scala b/testcases/graveyard/verification/vmcai2011-testcases/SanityChecks.scala deleted file mode 100644 index df1f6582ce55368da4bc0d59a3c4b62410e33154..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/vmcai2011-testcases/SanityChecks.scala +++ /dev/null @@ -1,93 +0,0 @@ -import leon.lang._ - -object SanityChecks { - // These are just to provide some "uninterpreted function symbols" - // Use the option -P:leon:tolerant to avoid warnings about it. - def f1(x: Int) : Int = { throw new Exception("Not implemented") } - def f2(s: Set[Int]) : Set[Int] = { throw new Exception("Not implemented") } - def f3(x: Int) : Set[Int] = { throw new Exception("Not implemented") } - def f4(s: Set[Int]) : Int = { throw new Exception("Not implemented") } - - def vc01(x: Int, y: Int) = { - require (x != y) - Set(x, y) - } ensuring {_.size == 2} - - def vc02(x: Int, y: Int) = { - require (x == y) - Set(x, y) - } ensuring {_.size == 1} - - def vc03(A: Set[Int], B: Set[Int]) = { - require( - (A -- B).size == 0 && - (B -- A).size == 0 - ) - f2(A) - } ensuring {_ == f2(B)} - - def vc04(A: Set[Int], B: Set[Int]) = { - require( - (A -- B).size == 0 && - (B -- A).size == 0 - ) - f4(A) - } ensuring {_ == f4(B)} - - def vc05(x: Int, y: Int) = { - require( - (f3(x) -- f3(y)).size > 0 || - (f3(y) -- f3(x)).size > 0 - ) - x - } ensuring {_ != y} - - def vc06(A: Set[Int], B: Set[Int]) = { - require( - (f2(A) -- f2(B)).size > 0 || - (f2(B) -- f2(A)).size > 0 - ) - A - } ensuring {_ != B} - - def vc07(A: Set[Int], B: Set[Int], C: Set[Int]) = { - require( - A.size == 1 - && B.size == 1 - && C.size == 1 - && (C -- A).size == 0 - && (C -- B).size == 0 - ) - A ** B - } ensuring(_.size == 1) - - def vc08(a: Set[Int], b: Set[Int]) : Boolean = { - require( - a.size == 0 - && b.size == 0 - ) - f4(a) == f4(b) - } ensuring(_ == true) - - def vc09(x: Int, a: Set[Int], b: Set[Int]) : Boolean = { - require( - a.size == 1 - && b.size == 1 - && a.contains(x) - && b.contains(x) - ) - f4(a) == f4(b) - } ensuring(_ == true) - - def vc10_broken(a: Set[Int], b: Set[Int]) : Boolean = { - f4(a ++ b) == f4(b ++ a) - } ensuring(_ == true) - - def vc11_broken(a: Int, b: Int, c: Int, S: Set[Int]) : Int = { - require ( - f1(a) != f1(b) && (b + 1) != (c + 1) && (c * 2) != (a * 2) && - (S contains a) && (S contains b) && (S contains c) - ) - S.size - } ensuring(_ > 2) -} diff --git a/testcases/graveyard/verification/xlang/BubbleSort.scala b/testcases/graveyard/verification/xlang/BubbleSort.scala deleted file mode 100644 index 4f29a00b0ecefdc4e7a8a9757102e32281738394..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/xlang/BubbleSort.scala +++ /dev/null @@ -1,74 +0,0 @@ -import leon.lang._ - -/* The calculus of Computation textbook */ - -object BubbleSort { - - def sort(a: Array[Int]): Array[Int] = ({ - require(a.length >= 1) - var i = a.length - 1 - var j = 0 - val sa = a.clone - (while(i > 0) { - j = 0 - (while(j < i) { - if(sa(j) > sa(j+1)) { - val tmp = sa(j) - sa(j) = sa(j+1) - sa(j+1) = tmp - } - j = j + 1 - }) invariant( - j >= 0 && - j <= i && - i < sa.length && - sa.length >= 0 && - partitioned(sa, 0, i, i+1, sa.length-1) && - sorted(sa, i, sa.length-1) && - partitioned(sa, 0, j-1, j, j) - ) - i = i - 1 - }) invariant( - i >= 0 && - i < sa.length && - sa.length >= 0 && - partitioned(sa, 0, i, i+1, sa.length-1) && - sorted(sa, i, sa.length-1) - ) - sa - }) ensuring(res => sorted(res, 0, a.length-1)) - - def sorted(a: Array[Int], l: Int, u: Int): Boolean = { - require(a.length >= 0 && l >= 0 && u < a.length && l <= u) - var k = l - var isSorted = true - (while(k < u) { - if(a(k) > a(k+1)) - isSorted = false - k = k + 1 - }) invariant(k <= u && k >= l) - isSorted - } - - def partitioned(a: Array[Int], l1: Int, u1: Int, l2: Int, u2: Int): Boolean = { - require(a.length >= 0 && l1 >= 0 && u1 < l2 && u2 < a.length) - if(l2 > u2 || l1 > u1) - true - else { - var i = l1 - var j = l2 - var isPartitionned = true - (while(i <= u1) { - j = l2 - (while(j <= u2) { - if(a(i) > a(j)) - isPartitionned = false - j = j + 1 - }) invariant(j >= l2 && i <= u1) - i = i + 1 - }) invariant(i >= l1) - isPartitionned - } - } - -} diff --git a/testcases/graveyard/verification/xlang/NonDeterministicList.scala b/testcases/graveyard/verification/xlang/NonDeterministicList.scala deleted file mode 100644 index 370198b53d6b42d4fd1d7aa8df5970b6e625528f..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/xlang/NonDeterministicList.scala +++ /dev/null @@ -1,53 +0,0 @@ -import leon.lang._ - -object NonDeterminism { - - abstract class IntList - case class Cons(h: Int, tail: IntList) extends IntList - case class Nil() extends IntList - - def insert(l: IntList, el: Int): IntList = Cons(el, l) - def remove(l: IntList, el: Int): IntList = l match { - case Cons(x, xs) => - if(x < el) Cons(x, remove(xs, x)) - else if(x == el) remove(xs, x) - else xs - case Nil() => Nil() - } - - def content(l: IntList) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def nonDeterministicExecution(): Boolean = { - - var list: IntList = Cons(42, Nil()) - var error: Boolean = false - - val b1 = epsilon((x: Boolean) => true) - val n1 = epsilon((x: Int) => true) - if(b1) - list = insert(list, n1) - else { - list = remove(list, n1) - if(content(list).contains(n1)) { - error = true - } - } - - val b2 = epsilon((x: Boolean) => true) - val n2 = epsilon((x: Int) => true) - if(b2) - list = insert(list, n2) - else { - list = remove(list, n2) - if(content(list).contains(n2)) { - error = true - } - } - - !error - } holds - -} diff --git a/testcases/graveyard/verification/xlang/QuickSortImp.scala b/testcases/graveyard/verification/xlang/QuickSortImp.scala deleted file mode 100644 index 6c721f532c14ac4244d900a4e3457a1148a21b12..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/xlang/QuickSortImp.scala +++ /dev/null @@ -1,79 +0,0 @@ -import leon.lang._ - -object QuickSortImp { - - - def quicksort(array: Array[Int]): Array[Int] = { - require(array.length > 0) - - def quicksort0(array: Array[Int], left: Int, right: Int): Array[Int] = { - require(array.length > 0 && left >= 0 && right < array.length) - - def partition(array: Array[Int], left: Int, right: Int, pivotIndex: Int): (Array[Int], Int) = { - require(array.length > 0 && left >= 0 && left < right && right < array.length && - pivotIndex >= left && pivotIndex <= right) - val pivotValue = array(pivotIndex) - val sa: Array[Int] = array.clone - val tmp = array(pivotIndex) - sa(pivotIndex) = sa(right) - sa(right) = tmp - var storeIndex = left - var i = left - (while(i < right) { - if(sa(i) < pivotValue) { - val tmp = sa(i) - sa(i) = sa(storeIndex) - sa(storeIndex) = tmp - storeIndex = storeIndex + 1 - } - i += 1 - }) invariant( - sa.length >= 0 && right < sa.length && sa.length == array.length && - storeIndex >= left && - i >= left && - storeIndex <= i && - storeIndex <= right && - i <= right - ) - - val tmp2 = array(storeIndex) - //sa(storeIndex) = sa(right) - sa(pivotIndex) = sa(right) - sa(right) = tmp2 - - (sa, storeIndex) - } ensuring(res => res._2 >= left && res._2 <= right && - res._1.length == array.length && res._1.length >= 0) - - - // If the list has 2 or more items - if(left < right) { - val pivotIndex = left - - val (as1, pivotNewIndex) = partition(array, left, right, pivotIndex) - - // Recursively sort elements smaller than the pivot - val as2 = quicksort0(as1, left, pivotNewIndex - 1) - - // Recursively sort elements at least as big as the pivot - quicksort0(as2, pivotNewIndex + 1, right) - } else array - } ensuring(res => res.length == array.length && res.length >= 0) - - quicksort0(array, 0, array.length-1) - } ensuring(res => sorted(res, 0, res.length-1)) - - def sorted(a: Array[Int], l: Int, u: Int): Boolean = { - require(a.length >= 0 && l >= 0 && u < a.length && l <= u) - var k = l - var isSorted = true - (while(k < u) { - if(a(k) > a(k+1)) - isSorted = false - k = k + 1 - }) invariant(k <= u && k >= l) - isSorted - } - - -} diff --git a/testcases/graveyard/verification/xlang/buggyEpsilon.scala b/testcases/graveyard/verification/xlang/buggyEpsilon.scala deleted file mode 100644 index ed47c0bed2702a9f35445ae16587b815e7507f7a..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/xlang/buggyEpsilon.scala +++ /dev/null @@ -1,81 +0,0 @@ -import leon.lang._ - -object Test { - - abstract class SortedList - case class Cons(head: Int, tail: SortedList) extends SortedList - case class Nil() extends SortedList - - def content(l: SortedList): Set[Int] = l match { - case Cons(head, tail) => content(tail) ++ Set(head) - case Nil() => Set() - } - - def insert(x: Int, l: SortedList): SortedList = Cons(x, l) - - def remove(x: Int, l: SortedList): SortedList = { - //require(pos(l) && sorted(l, 0)) - l match { - case Cons(head, tail) => if(head == x) remove(x, tail) else if(head < x) Cons(head, remove(x, tail)) else l - case Nil() => Nil() - } - } //ensuring(res => !content(res).contains(x)) - - def sorted(l: SortedList, prec: Int): Boolean = l match { - case Cons(head, tail) => if(prec <= head) sorted(tail, head) else false - case Nil() => true - } - def pos(l: SortedList): Boolean = l match { - case Cons(head, tail) => if(head < 0) false else pos(tail) - case Nil() => true - } - - - - def nonDeterministicList(): Boolean = { - var i = 0 - var b = epsilon((x: Boolean) => i==i) - var b2 = false - var n = 0 - var list: SortedList = Nil() - var error = false - - //(while(b) { - i = i + 1 - b = epsilon((x: Boolean) => i==i) - b2 = epsilon((x: Boolean) => i==i) - n = epsilon((x: Int) => x >= 0) - if(b2) - list = insert(n, list) - else { - list = remove(n, list) - if(content(list).contains(n)) - error = true - } - i = i + 1 - b = epsilon((x: Boolean) => i==i) - b2 = epsilon((x: Boolean) => i==i) - n = epsilon((x: Int) => x >= 0) - if(b2) - list = insert(n, list) - else { - list = remove(n, list) - if(content(list).contains(n)) - error = true - } - i = i + 1 - b = epsilon((x: Boolean) => i==i) - b2 = epsilon((x: Boolean) => i==i) - n = epsilon((x: Int) => x >= 0) - if(b2) - list = insert(n, list) - else { - list = remove(n, list) - if(content(list).contains(n)) - error = true - } - //}) //invariant(pos(list) && sorted(list, 0)) - error - } ensuring(err => !err) //ensuring(_ == Nil()) - -} diff --git a/testcases/graveyard/verification/xlang/master-thesis-regis/ArrayBubbleSort.scala b/testcases/graveyard/verification/xlang/master-thesis-regis/ArrayBubbleSort.scala deleted file mode 100644 index 941244b39b7f19ac3ee1f37ebf3f7b9a0d49f30f..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/xlang/master-thesis-regis/ArrayBubbleSort.scala +++ /dev/null @@ -1,81 +0,0 @@ -import leon.lang._ - -object ArrayBubbleSort { - def sorted(a: Array[Int], l: Int, u: Int): Boolean = { - require(a.length >= 0 && l >= 0 && u < a.length && l <= u) - if (l==u) true else a(l) <= a(l+1) && sorted(a,l+1,u) - } - - /* The calculus of Computation textbook */ - def bubbleSort(a: Array[Int]): Array[Int] = ({ - require(a.length >= 1) - var i = a.length - 1 - var j = 0 - val sa = a.clone - (while(i > 0) { - j = 0 - (while(j < i) { - if(sa(j) > sa(j+1)) { - val tmp = sa(j) - sa(j) = sa(j+1) - sa(j+1) = tmp - } - j = j + 1 - }) invariant( - j >= 0 && - j <= i && - i < sa.length && - sa.length >= 0 && - partitioned(sa, 0, i, i+1, sa.length-1) && - sorted(sa, i, sa.length-1) && - partitioned(sa, 0, j-1, j, j) - ) - i = i - 1 - }) invariant( - i >= 0 && - i < sa.length && - sa.length >= 0 && - partitioned(sa, 0, i, i+1, sa.length-1) && - sorted(sa, i, sa.length-1) - && sa.length == a.length // necessary - ) - sa - }) ensuring(res => sorted(res, 0, a.length-1)) - - def partitioned(a: Array[Int], l1: Int, u1: Int, l2: Int, u2: Int): Boolean = { - require(a.length >= 0 && l1 >= 0 && u1 < l2 && u2 < a.length) - if(l2 > u2 || l1 > u1) - true - else { - var i = l1 - var j = l2 - var isPartitionned = true - (while(i <= u1) { - j = l2 - (while(j <= u2) { - if(a(i) > a(j)) - isPartitionned = false - j = j + 1 - }) invariant(j >= l2 && i <= u1) - i = i + 1 - }) invariant(i >= l1) - isPartitionned - } - } - -/* // This also work as the definition of sorted and partitioned, and verifies: - - def sorted(a: Array[Int], l: Int, u: Int): Boolean = { - require(a.length >= 0 && l >= 0 && u < a.length && l <= u) - var k = l - var isSorted = true - (while(k < u) { - if(a(k) > a(k+1)) - isSorted = false - k = k + 1 - }) invariant(k <= u && k >= l) - isSorted - } - -*/ -} diff --git a/testcases/graveyard/verification/xlang/master-thesis-regis/ArrayOperations.scala b/testcases/graveyard/verification/xlang/master-thesis-regis/ArrayOperations.scala deleted file mode 100644 index d75d04c048c88a44722f1a6470e41df4bf8af665..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/xlang/master-thesis-regis/ArrayOperations.scala +++ /dev/null @@ -1,207 +0,0 @@ -import leon.lang._ - -object ArrayOperations { - - /* VSTTE 2008 - Dafny paper */ - def binarySearch(a: Array[Int], key: Int): Int = ({ - require(a.length > 0 && sorted(a, 0, a.length - 1)) - var low = 0 - var high = a.length - 1 - var res = -1 - - (while(low <= high && res == -1) { - val i = (high + low) / 2 - val v = a(i) - - if(v == key) - res = i - - if(v > key) - high = i - 1 - else if(v < key) - low = i + 1 - }) invariant( - res >= -1 && - res < a.length && - 0 <= low && - low <= high + 1 && - high >= -1 && - high < a.length && - (if (res >= 0) - a(res) == key else - (!occurs(a, 0, low, key) && !occurs(a, high + 1, a.length, key)) - ) - ) - res - }) ensuring(res => - res >= -1 && - res < a.length && - (if(res >= 0) a(res) == key else !occurs(a, 0, a.length, key))) - - - def occurs(a: Array[Int], from: Int, to: Int, key: Int): Boolean = { - require(a.length >= 0 && to <= a.length && from >= 0) - def rec(i: Int): Boolean = { - require(i >= 0) - if(i >= to) - false - else { - if(a(i) == key) true else rec(i+1) - } - } - if(from >= to) - false - else - rec(from) - } - - def sorted(a: Array[Int], l: Int, u: Int): Boolean = { - require(a.length >= 0 && l >= 0 && u < a.length && l <= u) - var k = l - var isSorted = true - (while(k < u) { - if(a(k) > a(k+1)) - isSorted = false - k = k + 1 - }) invariant(k <= u && k >= l) - isSorted - } - - /* The calculus of Computation textbook */ - def bubbleSort(a: Array[Int]): Array[Int] = ({ - require(a.length >= 1) - var i = a.length - 1 - var j = 0 - val sa = a.clone - (while(i > 0) { - j = 0 - (while(j < i) { - if(sa(j) > sa(j+1)) { - val tmp = sa(j) - sa(j) = sa(j+1) - sa(j+1) = tmp - } - j = j + 1 - }) invariant( - j >= 0 && - j <= i && - i < sa.length && - sa.length >= 0 && - partitioned(sa, 0, i, i+1, sa.length-1) && - sorted(sa, i, sa.length-1) && - partitioned(sa, 0, j-1, j, j) - ) - i = i - 1 - }) invariant( - i >= 0 && - i < sa.length && - sa.length >= 0 && - partitioned(sa, 0, i, i+1, sa.length-1) && - sorted(sa, i, sa.length-1) - ) - sa - }) ensuring(res => sorted(res, 0, a.length-1)) - - def partitioned(a: Array[Int], l1: Int, u1: Int, l2: Int, u2: Int): Boolean = { - require(a.length >= 0 && l1 >= 0 && u1 < l2 && u2 < a.length) - if(l2 > u2 || l1 > u1) - true - else { - var i = l1 - var j = l2 - var isPartitionned = true - (while(i <= u1) { - j = l2 - (while(j <= u2) { - if(a(i) > a(j)) - isPartitionned = false - j = j + 1 - }) invariant(j >= l2 && i <= u1) - i = i + 1 - }) invariant(i >= l1) - isPartitionned - } - } - - /* The calculus of Computation textbook */ - def linearSearch(a: Array[Int], c: Int): Boolean = ({ - require(a.length >= 0) - var i = 0 - var found = false - (while(i < a.length) { - if(a(i) == c) - found = true - i = i + 1 - }) invariant( - i <= a.length && - i >= 0 && - (if(found) contains(a, i, c) else !contains(a, i, c)) - ) - found - }) ensuring(res => if(res) contains(a, a.length, c) else !contains(a, a.length, c)) - - def contains(a: Array[Int], size: Int, c: Int): Boolean = { - require(a.length >= 0 && size >= 0 && size <= a.length) - content(a, size).contains(c) - } - - def content(a: Array[Int], size: Int): Set[Int] = { - require(a.length >= 0 && size >= 0 && size <= a.length) - var set = Set.empty[Int] - var i = 0 - (while(i < size) { - set = set ++ Set(a(i)) - i = i + 1 - }) invariant(i >= 0 && i <= size) - set - } - - def abs(tab: Array[Int]): Array[Int] = ({ - require(tab.length >= 0) - var k = 0 - val tabres = Array.fill(tab.length)(0) - (while(k < tab.length) { - if(tab(k) < 0) - tabres(k) = -tab(k) - else - tabres(k) = tab(k) - k = k + 1 - }) invariant( - tabres.length == tab.length && - k >= 0 && k <= tab.length && - isPositive(tabres, k)) - tabres - }) ensuring(res => isPositive(res, res.length)) - - def isPositive(a: Array[Int], size: Int): Boolean = { - require(a.length >= 0 && size <= a.length) - def rec(i: Int): Boolean = { - require(i >= 0) - if(i >= size) - true - else { - if(a(i) < 0) - false - else - rec(i+1) - } - } - rec(0) - } - - /* VSTTE 2010 challenge 1 */ - def maxSum(a: Array[Int]): (Int, Int) = ({ - require(a.length >= 0 && isPositive(a, a.length)) - var sum = 0 - var max = 0 - var i = 0 - (while(i < a.length) { - if(max < a(i)) - max = a(i) - sum = sum + a(i) - i = i + 1 - }) invariant (sum <= i * max && i >= 0 && i <= a.length) - (sum, max) - }) ensuring(res => res._1 <= a.length * res._2) - -} diff --git a/testcases/graveyard/verification/xlang/master-thesis-regis/Constraints.scala b/testcases/graveyard/verification/xlang/master-thesis-regis/Constraints.scala deleted file mode 100644 index 0df85e14fccc73e0fb90d0eec1c7d52e11c4d215..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/xlang/master-thesis-regis/Constraints.scala +++ /dev/null @@ -1,77 +0,0 @@ -import leon.lang._ - -object Epsilon4 { - - sealed abstract class MyList - case class MyCons(head: Int, tail: MyList) extends MyList - case class MyNil() extends MyList - - def size(lst: MyList): Int = lst match { - case MyNil() => 0 - case MyCons(_, xs) => 1 + size(xs) - } - - def setSize(set: Set[Int]): Int = { - if(set == Set.empty[Int]) - 0 - else { - val elem = epsilon((x : Int) => set contains x) - 1 + setSize(set -- Set[Int](elem)) - } - } ensuring(_ >= 0) - - - def toSet(lst: MyList): Set[Int] = lst match { - case MyCons(x, xs) => toSet(xs) ++ Set(x) - case MyNil() => Set[Int]() - } - - def toList(set: Set[Int]): MyList = { - if(set == Set.empty[Int]) - MyNil() - else { - val elem = epsilon((x : Int) => set contains x) - MyCons(elem, toList(set -- Set[Int](elem))) - } - } - - def sizeToListEq(lst: MyList): Boolean = { - size(toList(toSet(lst))) == size(lst) - } holds - - //cannot prove - //def sizeToListLessEq(lst: MyList): Boolean = { - // size(toList(toSet(lst))) <= size(lst) - //} holds - - def toListEq(lst: MyList): Boolean = { - toList(toSet(lst)) == lst - } holds - - def positiveNum(): Int = { - epsilon((x: Int) => x > 0) - } ensuring(_ > 0) - - def negativeNum(): Int = { - epsilon((x: Int) => x < 0) - } ensuring(_ < 0) - - def linearEquation(): (Int, Int) = { - val sol = epsilon((t: (Int, Int)) => - 2*t._1 + 3*t._2 == 10 && t._1 >= 0 && t._2 >= 0) - sol - } ensuring(res => res == (2, 2) || res == (5, 0)) - - - def nonDeterministicExecution(): Int = { - var i = 0 - var b = epsilon((x: Boolean) => true) - while(b) { - i = i + 1 - b = epsilon((x: Boolean) => true) - } - i - } ensuring(_ <= 10) - - -} diff --git a/testcases/graveyard/verification/xlang/xplusone.scala b/testcases/graveyard/verification/xlang/xplusone.scala deleted file mode 100644 index baa96abcd2f29dba741b436859fc96f3e1ed1806..0000000000000000000000000000000000000000 --- a/testcases/graveyard/verification/xlang/xplusone.scala +++ /dev/null @@ -1,21 +0,0 @@ -import leon.lang._ - -object xplusone { - - def f(n : Int) : Int = { - if (n > 0) { - f(n-1) + 1 - } else 1 - } ensuring (rec => rec == n + 1) - - def Sf(n : Int, rec : Int) : Boolean = { - if (n > 0) { - val res = epsilon((x:Int) => true) - Sf(n - 1, res) - (rec == res + 1) - } else { - rec == 1 - } - } ensuring (_ == (rec == n + 1)) - -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/Conqueue-Manual.scala b/testcases/lazy-datastructures/ManualnOutdated/Conqueue-Manual.scala deleted file mode 100644 index e3e455a2ac3aca5dea8cef095054d0eb49c513d0..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/Conqueue-Manual.scala +++ /dev/null @@ -1,279 +0,0 @@ -import leon.instrumentation._ -import leon.collection._ -import leon.lang._ -import ListSpecs._ -import leon.annotation._ -import conctrees.ConcTrees._ - -object Conqueue { - - def max(x: BigInt, y: BigInt): BigInt = if (x >= y) x else y - def abs(x: BigInt): BigInt = if (x < 0) -x else x - - sealed abstract class ConQ[T] { - - val isLazy: Boolean = this match { - case PushLazy(_, _) => true - case _ => false - } - - val isSpine: Boolean = this match { - case Spine(_, _) => true - case _ => false - } - - val pushLazyInv: Boolean = this match { - case PushLazy(ys, xs) => - !ys.isEmpty && (xs match { - case Spine(h, rear) => - !h.isEmpty && rear.pushLazyInv //note: head cannot be empty for a lazy closure - //h.level == ys.level (omitting this for now) - case _ => false - }) - case Spine(_, rear) => rear.pushLazyInv - case _ => true - } - - val zeroPreceedsLazy: Boolean = { - this match { - case Spine(h, PushLazy(_, q)) => - (h == Empty[T]()) && q.zeroPreceedsLazy // the position before pushlazy is Empty - case Spine(Empty(), rear) => - rear.weakZeroPreceedsLazy // here we have seen a zero - case Spine(h, rear) => - rear.zeroPreceedsLazy //here we have not seen a zero - case Tip(_) => true - case _ => false // this implies that a ConQ cannot start with a lazy closure - } - } ensuring (res => !res || weakZeroPreceedsLazy) //zeroPreceedsLazy is a stronger property - - val weakZeroPreceedsLazy: Boolean = { - this match { - case Spine(h, PushLazy(_, q)) => - q.zeroPreceedsLazy - case Spine(_, rear) => - rear.weakZeroPreceedsLazy - case Tip(_) => true - case _ => false // this implies that a ConQ cannot start with a lazy closure - } - } - - val valid = { - zeroPreceedsLazy && pushLazyInv - } - - val weakValid = { - weakZeroPreceedsLazy && pushLazyInv - } - - val isConcrete: Boolean = { - this match { - case Spine(_, rear) => - rear.isConcrete - case Tip(_) => - true - case _ => false - } - } ensuring (res => !res || valid) - - val firstLazyClosure: ConQ[T] = { - require(this.pushLazyInv) - this match { - case Spine(_, pl: PushLazy[T]) => pl - case Spine(_, tail) => - tail.firstLazyClosure - case _ => - this - } - } ensuring (res => !res.isSpine && res.pushLazyInv) - - def suffix(sch: ConQ[T]): Boolean = { //checks if sch is a suffix of 'this' - (this == sch) || { - this match { - case Spine(_, rear) => - rear.suffix(sch) - case _ => - false - } - } - } ensuring (res => sch match { - case Spine(_, rear) => - !res || suffix(rear) - case _ => true - }) - } - - case class Tip[T](t: Conc[T]) extends ConQ[T] - case class Spine[T](head: Conc[T], rear: ConQ[T]) extends ConQ[T] - // a closure corresponding to 'push' operations - case class PushLazy[T](ys: Conc[T], xs: Spine[T]) extends ConQ[T] - - def queueScheduleProperty[T](xs: ConQ[T], sch: PushLazy[T]) = { - sch match { - case PushLazy(_, _) => - xs.valid && xs.firstLazyClosure == sch //sch is the first lazy closure of 's' - case _ => false - } - } - - def weakScheduleProperty[T](xs: ConQ[T], sch: PushLazy[T]) = { - sch match { - case PushLazy(_, _) => - xs.weakValid && xs.firstLazyClosure == sch //sch is the first lazy closure of 's' - case _ => false - } - } - - def schedulesProperty[T](q: ConQ[T], schs: List[ConQ[T]]): Boolean = { - schs match { - case Cons(pl @ PushLazy(_, nestq), tail) => - queueScheduleProperty(q, pl) && - schedulesProperty(nestq, tail) - case Nil() => - //q.valid // here, for now we do not enforce that q should not have any closures. - q.isConcrete - case _ => - false // other cases are not valid - } - } - - def weakSchedulesProperty[T](q: ConQ[T], schs: List[ConQ[T]]): Boolean = { - schs match { - case Cons(pl @ PushLazy(_, nestq), tail) => - weakScheduleProperty(q, pl) && - schedulesProperty(nestq, tail) - case Nil() => - //q.valid - q.isConcrete - case _ => - false - } - } - - case class Wrapper[T](queue: ConQ[T], schedule: List[ConQ[T]]) { - val valid: Boolean = { - schedulesProperty(queue, schedule) - } - } - - def pushLeft[T](ys: Single[T], xs: ConQ[T]): (ConQ[T], BigInt) = { - require(xs.valid) - xs match { - case Tip(CC(_, _)) => - (Spine(ys, xs), 1) - case Tip(Empty()) => - (Tip(ys), 1) - case Tip(t @ Single(_)) => - (Tip(CC(ys, t)), 1) - case s @ Spine(_, _) => - val (r, t) = pushLeftLazy(ys, s) //ensure precondition here - (r, t + 1) - } - } ensuring (res => !res._1.isLazy && res._2 <= 2) - - def pushLeftLazy[T](ys: Conc[T], xs: Spine[T]): (Spine[T], BigInt) = { - require(!ys.isEmpty && xs.valid) // && - //(xs.head.isEmpty || xs.head.level == ys.level)) - - xs match { - case Spine(Empty(), rear) => //note: 'rear' is not materialized here - (Spine(ys, rear), 1) // if rear was 'PushLazy', this would temporarily break the 'zeroPreceedsLazy' invariant - case Spine(head, rear) => - val carry = CC(head, ys) //here, head and ys are of the same level - rear match { //here, rear cannot be 'PushLazy' by the 'zeroPreceedsLazy' invariant - case s @ Spine(Empty(), srear) => - (Spine(Empty(), Spine(carry, srear)), 1) - - case s @ Spine(_, _) => - (Spine(Empty(), PushLazy(carry, s)), 1) - - case t @ Tip(tree) if tree.level > carry.level => // can this happen ? this means tree is of level at least two greater than rear ? - (Spine(Empty(), Spine(carry, t)), 1) - - case Tip(tree) => - // here tree level and carry level are equal - (Spine(Empty(), Spine(Empty(), Tip(CC(tree, carry)))), 1) - } - } - } ensuring (res => res._1.isSpine && res._1.weakValid && res._2 <= 1) - - /** - * Materialize will evaluate ps and update the references to - * ps in xs. Ideally, the second argument should include every - * structure that may contain 'pl'. - */ - def materialize[T](mat: ConQ[T], xs: ConQ[T], schs: Cons[ConQ[T]]): (Spine[T], ConQ[T], BigInt) = { - require(weakSchedulesProperty(xs, schs) && schs.head == mat) - mat match { - case PushLazy(elem, q) => - val (nr, t) = pushLeftLazy(elem, q) - (nr, updateReferences(xs, mat, schs), t + 1) - } - } ensuring (res => (res._1 match { - case Spine(_, pl @ PushLazy(_, _)) => - schedulesProperty(res._2, Cons(pl, schs.tail)) - case _ => - schedulesProperty(res._2, schs.tail) - }) && - res._3 <= 2) - - /** - * This does not take any time, by the definition of laziness - */ - def updateReferences[T](xs: ConQ[T], mat: ConQ[T], schs: Cons[ConQ[T]]): ConQ[T] = { - require(weakSchedulesProperty(xs, schs) && schs.head == mat) - xs match { - case Spine(h, pl @ PushLazy(elem, q)) if (pl == mat) => - //ADT property implies that we need not search in the sub-structure 'q'. - Spine(h, pushLeftLazy(elem, q)._1) //here, we can ignore the time, this only captures the semantics - case Spine(h, rear) => //here mat and xs cannot be equal, so look in the substructures - Spine(h, updateReferences(rear, mat, schs)) - } - } ensuring (res => mat match { - case PushLazy(elem, q) => - pushLeftLazy(elem, q)._1 match { - case Spine(_, pl @ PushLazy(_, _)) => - schedulesProperty(res, Cons(pl, schs.tail)) - case _ => - schedulesProperty(res, schs.tail) - } - }) - - def pushLeftAndPay[T](ys: Single[T], w: Wrapper[T]): (Wrapper[T], BigInt) = { - require(w.valid) - val (nq, t1) = pushLeft(ys, w.queue) // the queue invariant could be temporarily broken - // update the schedule - val nschs = nq match { - case Spine(_, pl @ PushLazy(_, nest)) => - w.queue match { - case Spine(head, rear) if !head.isEmpty => - Cons[ConQ[T]](pl, w.schedule) - case _ => - w.schedule - } - case Tip(_) => - w.schedule - case Spine(_, rear) => - w.schedule - } - val (fschs, fq, t2) = pay(nschs, nq) - (Wrapper(fq, fschs), t1 + t2 + 1) - } ensuring (res => res._1.valid && res._2 <= 6) - - def pay[T](schs: List[ConQ[T]], xs: ConQ[T]): (List[ConQ[T]], ConQ[T], BigInt) = { - require(weakSchedulesProperty(xs, schs)) - schs match { - case c @ Cons(pl @ PushLazy(_, nestq), rest) => - val (matr, nxs, matt) = materialize(pl, xs, c) - matr match { - case Spine(_, pl @ PushLazy(_, _)) => - (Cons(pl, rest), nxs, matt + 1) - case _ => - (rest, nxs, matt + 1) - } - case Nil() => - (Nil(), xs, 1) // here every thing is concretized - } - } ensuring (res => schedulesProperty(res._2, res._1) && - res._3 <= 3) -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy1-with-uniqueness.scala b/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy1-with-uniqueness.scala deleted file mode 100644 index d2f6521265f119a958883f5b57aa57975dfd222d..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy1-with-uniqueness.scala +++ /dev/null @@ -1,493 +0,0 @@ -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.lang.synthesis._ -import ConcTrees._ -import ConQ._ -import Conqueue._ - -object ConcTrees { - abstract class Conc[T] { - def isEmpty: Boolean = this == Empty[T]() - - def level: BigInt = { - this match { - case Empty() => - BigInt(0) - case Single(x) => - BigInt(0) - case CC(l, r) => - BigInt(1) + max(l.level, r.level) - } - } ensuring { - (x$1: BigInt) => x$1 >= BigInt(0) - } - } - - case class Empty[T]() extends Conc[T] - - case class Single[T](x: T) extends Conc[T] - - case class CC[T](left: Conc[T], right: Conc[T]) extends Conc[T] - - def max(x: BigInt, y: BigInt): BigInt = if (x >= y) { - x - } else { - y - } - - def abs(x: BigInt): BigInt = if (x < BigInt(0)) { - -x - } else { - x - } -} - -object Conqueue { - abstract class ConQ[T] { - def isSpine: Boolean = this match { - case Spine(_, _, _) => - true - case _ => - false - } - def isTip: Boolean = !this.isSpine - } - - case class Tip[T](t: Conc[T]) extends ConQ[T] - - case class Spine[T](head: Conc[T], createdWithSusp: Bool, rear: LazyConQ[T]) extends ConQ[T] - - sealed abstract class Bool - case class True() extends Bool - case class False() extends Bool - - abstract class Scheds[T] - - case class Cons[T](h: LazyConQ[T], tail: Scheds[T]) extends Scheds[T] - - case class Nil[T]() extends Scheds[T] - - case class Wrapper[T](queue: LazyConQ[T], schedule: Scheds[T]) { - def valid(st: Set[LazyConQ[T]]): Boolean = zeroPreceedsLazy[T](this.queue, st) && schedulesProperty(this.queue, this.schedule, st) - } - - def zeroPreceedsLazy[T](q: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - if (isEvaluated(q, st)) { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear) => true - case Spine(_, _, rear) => - zeroPreceedsLazy[T](rear, st) - case Tip(_) => true - } - } else false - } - - def zeroPredLazyMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], q: LazyConQ[T]): Boolean = { - require(st1.subsetOf(st2) && zeroPreceedsLazy(q, st1)) - zeroPreceedsLazy(q, st2) && - //induction scheme - (evalLazyConQS[T](q) match { - case Spine(Empty(), _, _) => - true - case Spine(h, _, rear) => - zeroPredLazyMonotone(st1, st2, rear) - case Tip(_) => - true - }) - } holds - - def weakZeroPreceedsLazy[T](q: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear10) => - true - case Spine(h, _, rear11) => - zeroPreceedsLazy[T](rear11, st) - case Tip(_) => - true - } - } - - def firstUnevaluated[T](l: LazyConQ[T], st: Set[LazyConQ[T]]): LazyConQ[T] = { - if (isEvaluated(l, st)) { - evalLazyConQS[T](l) match { - case Spine(_, _, tail15) => - firstUnevaluated[T](tail15, st) - case _ => - l - } - } else { - l - } - } ensuring { - (res65: LazyConQ[T]) => - (evalLazyConQS[T](res65).isTip || !st.contains(res65)) /*&& - { - val dres4 = evalLazyConQ[T](res65, st) - dres4._1 match { - case Spine(_, _, tail16) => - firstUnevaluated[T](l, dres4._2) == firstUnevaluated[T](tail16, dres4._2) - case _ => - true - } - }*/ - } - - def nextUnevaluatedLemma[T](l: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - val (res, nst) = evalLazyConQ[T](firstUnevaluated(l, st), st) - (res match { - case Spine(_, _, tail) => - firstUnevaluated[T](l, nst) == firstUnevaluated[T](tail, nst) - case _ => - true - }) && - // induction scheme - (evalLazyConQS[T](l) match { - case Spine(_, _, tail) => - nextUnevaluatedLemma(tail, st) - case _ => true - }) - } holds - - def schedulesProperty[T](q: LazyConQ[T], schs: Scheds[T], st: Set[LazyConQ[T]]): Boolean = { - val x = firstUnevaluated(q, st) - val y = evalLazyConQS(x) - schs match { - case Cons(head, tail) => - y.isSpine && x == head && schedulesProperty[T](pushUntilZero[T](head), tail, st) && - weakZeroPreceedsLazy(head, st) - case Nil() => - y.isTip - } - } - - def pushUntilZero[T](q: LazyConQ[T]): LazyConQ[T] = evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear12) => - pushUntilZero[T](rear12) - case Spine(h, _, rear13) => - rear13 - case Tip(_) => - q - } - - def pushLeft[T](ys: Single[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - require(zeroPreceedsLazy[T](xs, st) && ys.isInstanceOf[Single[T]]) - val dres5 = evalLazyConQ[T](xs, st) - dres5._1 match { - case Tip(CC(_, _)) => - (Spine[T](ys, False(), xs), dres5._2) - case Tip(Empty()) => - (Tip[T](ys), dres5._2) - case Tip(t @ Single(_)) => - (Tip[T](CC[T](ys, t)), dres5._2) - case s @ Spine(Empty(), _, rear) => - (Spine[T](ys, False(), rear), dres5._2) // in this case firstUnevaluated[T](rear, st) == firstUnevaluated[T](xs, st) - case s @ Spine(_, _, _) => - pushLeftLazy[T](ys, xs, dres5._2) - } - } ensuring { res => - true - } - - def dummyFun[T]() = ???[(ConQ[T], Set[LazyConQ[T]])] - - @library - def pushLeftLazyUI[T](ys: Conc[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - dummyFun() - } ensuring (res => res._2 == st && (res._1 match { - case Spine(Empty(), createdWithSusp, rear) => - val (rearval, _) = evalLazyConQ[T](rear, st) // this is necessary to assert properties on the state in the recursive invocation - val p = pushUntilZero[T](rear) - val fr = firstUnevaluated[T](p, st) - rearval.isSpine && { - if (createdWithSusp == False()) { - fr == firstUnevaluated[T](rear, st) - } else - !isEvaluated(rear, st) - } && - { - val f = firstUnevaluated[T](xs, st) - ((evalLazyConQS[T](f).isTip && - evalLazyConQS[T](fr).isTip) || fr == f) - } && - weakZeroPreceedsLazy(rear, st) - case _ => false - })) - - def pushLeftLazy[T](ys: Conc[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - require(!ys.isEmpty && zeroPreceedsLazy[T](xs, st) && - (evalLazyConQS[T](xs) match { - case Spine(h, _, _) => h != Empty[T]() - case _ => false - })) - val dres = evalLazyConQ[T](xs, st) - dres._1 match { - case Spine(head, _, rear15) => - val carry = CC[T](head, ys) - val dres2 = evalLazyConQ[T](rear15, dres._2) - dres2._1 match { - case s @ Spine(Empty(), _, _) => - (Spine[T](Empty[T](), False(), Eager(Spine(carry, False(), rear15))), dres2._2) - case s @ Spine(_, _, _) => - (Spine[T](Empty[T](), True(), newConQ[T](PushLeftLazy[T](carry, rear15), dres2._2)), dres2._2) - case t @ Tip(tree) => - if (tree.level > carry.level) { // can this happen ? this means tree is of level at least two greater than rear ? - val x: ConQ[T] = t - (Spine[T](Empty[T](), False(), Eager(Spine(carry, False(), rear15))), dres2._2) - } else { // here tree level and carry level are equal - val x: ConQ[T] = Tip[T](CC[T](tree, carry)) - (Spine[T](Empty[T](), False(), Eager(Spine(Empty[T](), False(), Eager[T](x)))), dres2._2) - } - } - } - } ensuring { - (res66: (Spine[T], Set[LazyConQ[T]])) => - (res66._2 == st) && (res66._1 match { - case Spine(Empty(), createdWithSusp, rear) => - val (rearval, _) = evalLazyConQ[T](rear, st) // this is necessary to assert properties on the state in the recursive invocation - val p = pushUntilZero[T](rear) - val fr = firstUnevaluated[T](p, st) - rearval.isSpine && { - if (createdWithSusp == False()) { - fr == firstUnevaluated[T](rear, st) - } else - !isEvaluated(rear, st) - } && - { - val f = firstUnevaluated[T](xs, st) - ((evalLazyConQS[T](f).isTip && - evalLazyConQS[T](fr).isTip) || fr == f) - } && - weakZeroPreceedsLazy(rear, st) - case _ => - false - }) - } - - def pushLeftWrapper[T](ys: Single[T], w: Wrapper[T], st: Set[LazyConQ[T]]) = { - require(w.valid(st) && ys.isInstanceOf[Single[T]]) - val (nq, nst) = pushLeft[T](ys, w.queue, st) - val nsched = nq match { - case Spine(Empty(), createdWithSusp, rear18) if createdWithSusp == True() => - Cons[T](rear18, w.schedule) // this is the only case where we create a new lazy closure - case _ => - w.schedule - } - (Eager(nq), nsched, nst) - } ensuring { res => schedulesProperty(res._1, res._2, res._3) } - - /*def PushLeftLazypushLeftLazyLem[T](rear15 : LazyConQ[T], head : Conc[T], dres : (ConQ[T], Set[LazyConQ[T]]), st : Set[LazyConQ[T]], xs : LazyConQ[T], s : Spine[T], dres : (ConQ[T], Set[LazyConQ[T]]), carry : CC[T], ys : Conc[T]): Boolean = { - (!ys.isEmpty && zeroPreceedsLazy[T](xs, st) && evalLazyConQS[T](xs).isSpine && dres == evalLazyConQ[T](xs, st) && (!dres._1.isInstanceOf[Spine[T]] || !dres._1.head.isInstanceOf[Empty[T]]) && dres._1.isInstanceOf[Spine[T]] && head == dres._1.head && rear15 == dres._1.rear && carry == CC[T](head, ys) && dres == evalLazyConQ[T](rear15, dres._2) && (!dres._1.isInstanceOf[Spine[T]] || !dres._1.head.isInstanceOf[Empty[T]]) && dres._1.isInstanceOf[Spine[T]] && s == dres._1) ==> (!carry.isEmpty && zeroPreceedsLazy[T](rear15, dres._2) && evalLazyConQS[T](rear15).isSpine) - } ensuring { - (holds : Boolean) => holds - }*/ - - def streamContains[T](l: LazyConQ[T], newl: LazyConQ[T]): Boolean = { - (l == newl) || (evalLazyConQS[T](l) match { - case Spine(_, _, tail) => - streamContains(tail, newl) - case _ => false - }) - } - - // monotonicity of fune - def funeMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], l: LazyConQ[T], newl: LazyConQ[T]): Boolean = { - require(st2 == st1 ++ Set(newl) && - !streamContains(l, newl)) - (firstUnevaluated(l, st1) == firstUnevaluated(l, st2)) && //property - //induction scheme - (evalLazyConQS[T](l) match { - case Spine(_, _, tail) => - funeMonotone(st1, st2, tail, newl) - case _ => - true - }) - } holds - - @library // To be proven - def schedMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], scheds: Scheds[T], l: LazyConQ[T], newl: LazyConQ[T]): Boolean = { - require((st2 == st1 ++ Set(newl)) && - !streamContains(l, newl) && // newl is not contained in 'l' - schedulesProperty(l, scheds, st1)) - - funeMonotone(st1, st2, l, newl) && //instantiations - schedulesProperty(l, scheds, st2) && //property - //induction scheme - (scheds match { - case Cons(head, tail) => - (evalLazyConQS[T](head) match { - case Spine(h, _, rear11) if h != Empty[T]()=> - zeroPredLazyMonotone(st1, st2, rear11) - case _ => true - }) && - schedMonotone(st1, st2, tail, pushUntilZero(head), newl) - case Nil() => true - }) - } holds - - @library - def dummyAxiom[T](l: LazyConQ[T], nl: LazyConQ[T]): Boolean = { - !streamContains(l, nl) - } holds - - def funeCompose[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], q: LazyConQ[T]): Boolean = { - require(st1.subsetOf(st2)) - (firstUnevaluated(firstUnevaluated(q, st1), st2) == firstUnevaluated(q, st2)) && //property - //induction scheme - (evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - funeCompose(st1, st2, tail) - case _ => - true - }) - } holds - - // induction following the structure of zeroPredLazy - def funeZeroProp[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], q: LazyConQ[T]): Boolean = { - require(st1.subsetOf(st2) && { - val x = firstUnevaluated(q, st1) - st2.contains(x) && weakZeroPreceedsLazy(x, st1) - }) - zeroPreceedsLazy(q, st2) && //property - //induction scheme - (evalLazyConQS[T](q) match { - case Spine(Empty(), _, tail) => - true - case Spine(_, _, tail) => - (if (isEvaluated(q, st1)) - funeZeroProp(st1, st2, tail) - else true) - case _ => - true - }) - } holds - - // induction following the structure of zeroPredLazy - def funeZeroProp2[T](st: Set[LazyConQ[T]], q: LazyConQ[T]): Boolean = { - require(evalLazyConQS(firstUnevaluated(q, st)).isTip) - zeroPreceedsLazy(q, st) && //property - //induction scheme - (evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - funeZeroProp2(st, tail) - case _ => - true - }) - } holds - - def Pay[T](q: LazyConQ[T], scheds: Scheds[T], st: Set[LazyConQ[T]]): (Scheds[T], Set[LazyConQ[T]]) = { - require(schedulesProperty(q, scheds, st) && isEvaluated(q, st)) - val (nschs, rst) = scheds match { - case c @ Cons(head, rest) => - val (headval, st2) = evalLazyConQ(head, st) - (headval match { - case Spine(Empty(), createdWithSusp, rear) => - if (createdWithSusp == True()) { - Cons(rear, rest) - } else - rest -// In this case, -// val p = pushUntilZero(rear) -// firstUnevaluated(q, res._2) == firstUnevaluated(rear, res._2) && -// firstUnevaluated(p, st) == rhead && -// rhead == firstUnevaluated(rear, st) && - case _ => - rest - // Note: head has to be spine since scheds is not empty - // in this case: firstUnevaluated[T](headval.rear, st) == rhead && firstUnevaluated[T](q, res._2) == rhead by funeCompose - //firstUnevaluated(rear, st) == rhead && - //schedulesProperty(pushUntilZero(head), res._1, st) && - //schedulesProperty(pushUntilZero(rhead), rtail, st) - // schedMonotone(st, res._2, rtail, pushUntilZero(rhead), head) - }, st2) - case Nil() => - (scheds, st) - } - (nschs, rst) - } ensuring { res => - zeroPreceedsLazy(q, res._2) && - schedulesProperty(q, res._1, res._2) && - // instantiations (relating rhead and head) - funeCompose(st, res._2, q) && - (scheds match { - case Cons(head, rest) => - (res._1 match { - case Cons(rhead, rtail) => - val p = pushUntilZero(rhead) - dummyAxiom(p, head) && - schedMonotone(st, res._2, rtail, p, head) && - { - // an instantiation that could be packed into schedMonotone - evalLazyConQS(rhead) match { - case Spine(h, _, rear11) if h != Empty[T]()=> - zeroPredLazyMonotone(st, res._2, rear11) - case _ => true - } - } - case _ => true - }) && - (evalLazyConQS(head) match { - case Spine(Empty(), cws, rear) => - dummyAxiom(rear, head) && - funeMonotone(st, res._2, rear, head) && - nextUnevaluatedLemma(q, st) - case _ => true - }) - case _ => true - }) && - // instantiations for proving zeroPreceedsLazy property - (scheds match { - case Cons(head, rest) => - // establishing the zeroPreceedsLazy Property (on this case) - //fune(q, st) == head && weakZero(head, st) && res._2 == st ++ { head } - funeZeroProp(st, res._2, q) //instantiation - case _ => - funeZeroProp2(st, q) - }) - } - - def pushLeftAndPay[T](ys: Single[T], w: Wrapper[T], st: Set[LazyConQ[T]]) = { - require(w.valid(st) && ys.isInstanceOf[Single[T]]) - val (q, scheds, nst) = pushLeftWrapper(ys, w, st) - val (nscheds, fst) = Pay(q, scheds, nst) - (Wrapper(q, nscheds), fst) - } ensuring { res => res._1.valid(res._2) } - - def lazyarg1[T](x: ConQ[T]): ConQ[T] = x -} - -object ConQ { - - abstract class LazyConQ[T1] - - case class Eager[T](x: ConQ[T]) extends LazyConQ[T] - - case class PushLeftLazy[T](ys: Conc[T], xs: LazyConQ[T]) extends LazyConQ[T] - - @library - def newConQ[T1](cc: LazyConQ[T1], st: Set[LazyConQ[T1]]): LazyConQ[T1] = { - cc - } ensuring { - (res: LazyConQ[T1]) => !st.contains(res) - } - - @library - def evalLazyConQ[T](cl: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - cl match { - case t: Eager[T] => - (t.x, st) - case t: PushLeftLazy[T] => - val plres = pushLeftLazyUI[T](t.ys, t.xs, uiState())._1 - val plst = pushLeftLazyUI[T](t.ys, t.xs, st)._2 - (plres, (plst ++ Set[LazyConQ[T]](t))) - } - } - - def isEvaluated[T](cl: LazyConQ[T], st: Set[LazyConQ[T]]) = st.contains(cl) || cl.isInstanceOf[Eager[T]] - - def uiState[T](): Set[LazyConQ[T]] = ???[Set[LazyConQ[T]]] - - def evalLazyConQS[T](cl: LazyConQ[T]): ConQ[T] = evalLazyConQ[T](cl, uiState())._1 - -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy2.scala b/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy2.scala deleted file mode 100644 index ab1e7d0cba96fc7408432fdc580ce65e66dc22dd..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy2.scala +++ /dev/null @@ -1,701 +0,0 @@ -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.lang.synthesis._ -import ConcTrees._ -import ConQ._ -import Conqueue._ - -object ConcTrees { - abstract class Conc[T] { - def isEmpty: Boolean = this == Empty[T]() - - def level: BigInt = { - this match { - case Empty() => - BigInt(0) - case Single(x) => - BigInt(0) - case CC(l, r) => - BigInt(1) + max(l.level, r.level) - } - } ensuring { - (x$1: BigInt) => x$1 >= BigInt(0) - } - } - - case class Empty[T]() extends Conc[T] - - case class Single[T](x: T) extends Conc[T] - - case class CC[T](left: Conc[T], right: Conc[T]) extends Conc[T] - - def max(x: BigInt, y: BigInt): BigInt = if (x >= y) { - x - } else { - y - } - - def abs(x: BigInt): BigInt = if (x < BigInt(0)) { - -x - } else { - x - } -} - -object Conqueue { - abstract class ConQ[T] { - def isSpine: Boolean = this match { - case Spine(_, _, _) => - true - case _ => - false - } - def isTip: Boolean = !this.isSpine - } - - case class Tip[T](t: Conc[T]) extends ConQ[T] - - case class Spine[T](head: Conc[T], createdWithSusp: Bool, rear: LazyConQ[T]) extends ConQ[T] - - sealed abstract class Bool - case class True() extends Bool - case class False() extends Bool - - abstract class Scheds[T] - - case class Cons[T](h: LazyConQ[T], tail: Scheds[T]) extends Scheds[T] - - case class Nil[T]() extends Scheds[T] - - case class Wrapper[T](queue: LazyConQ[T], schedule: Scheds[T]) { - def valid(st: Set[LazyConQ[T]]): Boolean = zeroPreceedsLazy[T](this.queue, st) && - // schedulesProperty(this.queue, this.schedule, st) - strongSchedsProp(this.queue, this.schedule, 2, st) // head of the schedule should start after the first two elements - } - - def zeroPreceedsLazy[T](q: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - if (isEvaluated(q, st)) { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear) => true - case Spine(_, _, rear) => - zeroPreceedsLazy[T](rear, st) - case Tip(_) => true - } - } else false - } - - // not used, but still interesting - def zeroPredLazyMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], q: LazyConQ[T]): Boolean = { - require(st1.subsetOf(st2) && zeroPreceedsLazy(q, st1)) - zeroPreceedsLazy(q, st2) && - //induction scheme - (evalLazyConQS[T](q) match { - case Spine(Empty(), _, _) => - true - case Spine(h, _, rear) => - zeroPredLazyMonotone(st1, st2, rear) - case Tip(_) => - true - }) - } holds - - def weakZeroPreceedsLazy[T](q: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear10) => - true - case Spine(h, _, rear11) => - zeroPreceedsLazy[T](rear11, st) - case Tip(_) => - true - } - } - - def firstUnevaluated[T](l: LazyConQ[T], st: Set[LazyConQ[T]]): LazyConQ[T] = { - if (isEvaluated(l, st)) { - evalLazyConQS[T](l) match { - case Spine(_, _, tail15) => - firstUnevaluated[T](tail15, st) - case _ => - l - } - } else { - l - } - } ensuring { - (res65: LazyConQ[T]) => - (evalLazyConQS[T](res65).isTip || !st.contains(res65)) && - concreteUntil(l, res65, st) - } - - def nextUnevaluatedLemma[T](l: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - val (res, nst) = evalLazyConQ[T](firstUnevaluated(l, st), st) - (res match { - case Spine(_, _, tail) => - firstUnevaluated[T](l, nst) == firstUnevaluated[T](tail, nst) - case _ => - true - }) && - // induction scheme - (evalLazyConQS[T](l) match { - case Spine(_, _, tail) => - nextUnevaluatedLemma(tail, st) - case _ => true - }) - } holds - - /** - * Everything until suf is evaluated - */ - def concreteUntil[T](l: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - if (l != suf) { - isEvaluated(l, st) && (evalLazyConQS[T](l) match { - case Spine(_, cws, tail15) => - concreteUntil(tail15, suf, st) - case _ => - true - }) - } else true - } - - def isConcrete[T](l: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = isEvaluated(l, st) && (evalLazyConQS[T](l) match { - case Spine(_, _, tail13) => - isConcrete[T](tail13, st) - case _ => - true - }) - - def schedulesProperty[T](q: LazyConQ[T], schs: Scheds[T], st: Set[LazyConQ[T]]): Boolean = { - schs match { - case Cons(head, tail) => - evalLazyConQS[T](head) match { - case Spine(Empty(), _, _) => - !head.isInstanceOf[Eager[T]] && - concreteUntil(q, head, st) && schedulesProperty[T](pushUntilZero[T](head), tail, st) - case _ => - false - } - case Nil() => - isConcrete(q, st) - } - } - - /*def strongSchedsProp[T](q: LazyConQ[T], schs: Scheds[T], st: Set[LazyConQ[T]]) = { - isEvaluated(q, st) && { - val l = evalLazyConQS[T](q) match { - case Spine(_, _, rear) => - rear - case _ => q - } - schedulesProperty(l, schs, st) - } - }*/ - - /** - * Goes at most two steps - */ - def nthTail[T](q: LazyConQ[T], n: BigInt): LazyConQ[T] = { - evalLazyConQS[T](q) match { - case Spine(_, _, rear) if n > 1 => - evalLazyConQS[T](rear) match { - case Spine(_, _, srear) => srear - case _ => rear - } - case Spine(_, _, rear) if n == 1 => - rear - case _ => - q - } - } - - def strongSchedsProp[T](q: LazyConQ[T], schs: Scheds[T], sufOffset : BigInt, st: Set[LazyConQ[T]]) : Boolean = { - isEvaluated(q, st) && { - evalLazyConQS[T](q) match { - case Spine(_, _, rear) if sufOffset > 1 => - isEvaluated(rear, st) - case _ => true - } - } && - schedulesProperty(nthTail(q, sufOffset), schs, st) - } - - // pushes a carry until there is a one - // TODO: rename this to pushUntilCarry - def pushUntilZero[T](q: LazyConQ[T]): LazyConQ[T] = evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear12) => - pushUntilZero[T](rear12) - case Spine(h, _, rear13) => - rear13 - case Tip(_) => - q - } - - def pushLeft[T](ys: Single[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - require(zeroPreceedsLazy[T](xs, st) && ys.isInstanceOf[Single[T]]) - - val dres5 = evalLazyConQ[T](xs, st) - dres5._1 match { - case Tip(CC(_, _)) => - (Spine[T](ys, False(), xs), dres5._2) - case Tip(Empty()) => - (Tip[T](ys), dres5._2) - case Tip(t @ Single(_)) => - (Tip[T](CC[T](ys, t)), dres5._2) - case s @ Spine(Empty(), _, rear) => - (Spine[T](ys, False(), rear), dres5._2) // in this case firstUnevaluated[T](rear, st) == firstUnevaluated[T](xs, st) - case s @ Spine(_, _, _) => - pushLeftLazy[T](ys, xs, dres5._2) - } - } - -/* def dummyFun[T]() = ???[(ConQ[T], Set[LazyConQ[T]])] - - @library - def pushLeftLazyUI[T](ys: Conc[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - dummyFun() - } ensuring (res => res._2 == st && (res._1 match { - case Spine(Empty(), createdWithSusp, rear) => - true - case _ => false - }))*/ - - def pushLeftLazyVal[T](ys: Conc[T], xs: LazyConQ[T]) : ConQ[T] = ???[ConQ[T]] - - @library - def resSpec[T](ys: Conc[T], xs: LazyConQ[T], res : ConQ[T]) = { - res == pushLeftLazyVal(ys, xs) - } holds - - def pushLeftLazy[T](ys: Conc[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - require(!ys.isEmpty && zeroPreceedsLazy[T](xs, st) && - (evalLazyConQS(xs) match { - case Spine(h, _, _) => h != Empty[T]() - case _ => false - })) - val dres = evalLazyConQ[T](xs, st) - val res = dres._1 match { - case Spine(head, _, rear15) => - val carry = CC[T](head, ys) - val dres2 = evalLazyConQ[T](rear15, dres._2) - dres2._1 match { - case s @ Spine(Empty(), _, srear) => - (Spine[T](Empty[T](), False(), Eager(Spine(carry, False(), srear))), dres2._2) - case s @ Spine(_, _, _) => - (Spine[T](Empty[T](), True(), PushLeftLazy[T](carry, rear15)), dres2._2) - case t @ Tip(tree) => - if (tree.level > carry.level) { // this case may not even be possible given additional preconditions - val x: ConQ[T] = t - (Spine[T](Empty[T](), False(), Eager(Spine(carry, False(), rear15))), dres2._2) - } else { // here tree level and carry level are equal - val x: ConQ[T] = Tip[T](CC[T](tree, carry)) - (Spine[T](Empty[T](), False(), Eager(Spine(Empty[T](), False(), Eager[T](x)))), dres2._2) - } - } - } - res - } ensuring { - (res66: (Spine[T], Set[LazyConQ[T]])) => - resSpec(ys, xs, res66._1) && // asserts that the result is a function of inputs excluding state - (res66._2 == st) && (res66._1 match { - case Spine(Empty(), createdWithSusp, rear) => - val (rearval, _) = evalLazyConQ[T](rear, st) // this is necessary to assert properties on the state in the recursive invocation - (!isConcrete(xs, st) || isConcrete(pushUntilZero(rear), st)) - //true - case _ => - false - }) - } - - def pushLeftLazyLemma[T](ys: Conc[T], xs: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(!ys.isEmpty && zeroPreceedsLazy[T](xs, st) && - (evalLazyConQS(xs) match { - case Spine(h, _, _) => h != Empty[T]() // this implie xs.rear is also evaluated - case _ => false - }) && - (evalLazyConQS(suf) match { - case Spine(Empty(), _, _) => - concreteUntil(nthTail(xs, 2), suf, st) - case _ => false - })) - // property - (pushLeftLazy(ys, xs, st)._1 match { - case Spine(Empty(), createdWithSusp, rear) => - // forall suf. suf*.head == Empty() ^ concUntil(xs, suf, st) => concUntil(push(rear), suf, st) - val p = pushUntilZero[T](rear) - concreteUntil(p, suf, st) - }) && - // induction scheme - (evalLazyConQS(xs) match { - case Spine(head, _, rear15) => - val carry = CC[T](head, ys) - evalLazyConQS(rear15) match { - case s @ Spine(h, _, _) if h != Empty[T]() => - pushLeftLazyLemma(carry, rear15, suf, st) - case _ => true - } - }) - } holds - - def pushLeftWrapper[T](ys: Single[T], w: Wrapper[T], st: Set[LazyConQ[T]]) = { - require(w.valid(st) && ys.isInstanceOf[Single[T]]) - val (nq, nst) = pushLeft[T](ys, w.queue, st) - val nsched = nq match { - case Spine(Empty(), createdWithSusp, rear18) if createdWithSusp == True() => - Cons[T](rear18, w.schedule) // this is the only case where we create a new lazy closure - case _ => - w.schedule - } - (Eager(nq), nsched, nst) - } ensuring { res => - strongSchedsProp(res._1, res._2, 1, res._3) && // head of the schedule may start after the first element - // lemma instantiations - (w.schedule match { - case Cons(head, tail) => - evalLazyConQS(w.queue) match { - case Spine(h, _, _) if h != Empty[T]() => - pushLeftLazyLemma(ys, w.queue, head, st) - case _ => true - } - case _ => true - }) - } - - /*def PushLeftLazypushLeftLazyLem[T](rear15 : LazyConQ[T], head : Conc[T], dres : (ConQ[T], Set[LazyConQ[T]]), st : Set[LazyConQ[T]], xs : LazyConQ[T], s : Spine[T], dres : (ConQ[T], Set[LazyConQ[T]]), carry : CC[T], ys : Conc[T]): Boolean = { - (!ys.isEmpty && zeroPreceedsLazy[T](xs, st) && evalLazyConQS[T](xs).isSpine && dres == evalLazyConQ[T](xs, st) && (!dres._1.isInstanceOf[Spine[T]] || !dres._1.head.isInstanceOf[Empty[T]]) && dres._1.isInstanceOf[Spine[T]] && head == dres._1.head && rear15 == dres._1.rear && carry == CC[T](head, ys) && dres == evalLazyConQ[T](rear15, dres._2) && (!dres._1.isInstanceOf[Spine[T]] || !dres._1.head.isInstanceOf[Empty[T]]) && dres._1.isInstanceOf[Spine[T]] && s == dres._1) ==> (!carry.isEmpty && zeroPreceedsLazy[T](rear15, dres._2) && evalLazyConQS[T](rear15).isSpine) - } ensuring { - (holds : Boolean) => holds - }*/ - - def schedMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], scheds: Scheds[T], l: LazyConQ[T]): Boolean = { - require(st1.subsetOf(st2) && schedulesProperty(l, scheds, st1)) - schedulesProperty(l, scheds, st2) && //property - //induction scheme - (scheds match { - case Cons(head, tail) => - evalLazyConQS[T](head) match { - case Spine(_, _, rear) => - concUntilMonotone(l, head, st1, st2) && - schedMonotone(st1, st2, tail, pushUntilZero(head)) - case _ => true - } - case Nil() => - concreteMonotone(st1, st2, l) - }) - } holds - - def concreteMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], l: LazyConQ[T]): Boolean = { - require(isConcrete(l, st1) && st1.subsetOf(st2)) - isConcrete(l, st2) && { - // induction scheme - evalLazyConQS[T](l) match { - case Spine(_, _, tail) => - concreteMonotone[T](st1, st2, tail) - case _ => - true - } - } - } holds - - def concUntilExtenLemma[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st)) - val (next, nst) = evalLazyConQ[T](suf, st) - (next match { - case Spine(_, _, rear) => - concreteUntil(q, rear, nst) - case _ => true - }) && - (if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilExtenLemma(tail, suf, st) - case _ => - true - } - } else true) - } holds - - def concUntilExtenLemma2[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st) && isConcrete(suf, st)) - isConcrete(q, st) && - (if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilExtenLemma2(tail, suf, st) - case _ => - true - } - } else true) - } ensuring (_ == true) - - def concUntilCompose[T](q: LazyConQ[T], suf1: LazyConQ[T], suf2: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf1, st) && concreteUntil(suf1, suf2, st)) - concreteUntil(q, suf2, st) && - (if (q != suf1) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilCompose(tail, suf1, suf2, st) - case _ => - true - } - } else true) - } ensuring (_ == true) - - def concUntilMonotone[T](q: LazyConQ[T], suf: LazyConQ[T], st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st1) && st1.subsetOf(st2)) - concreteUntil(q, suf, st2) && - (if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilMonotone(tail, suf, st1, st2) - case _ => - true - } - } else true) - } ensuring (_ == true) - - def concUntilZeroPredLemma[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st) && (evalLazyConQS(suf) match { - case Spine(Empty(), _, _) => true - case _ => false - })) - val (next, nst) = evalLazyConQ[T](suf, st) - zeroPreceedsLazy(q, nst) && - (if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilZeroPredLemma(tail, suf, st) - case _ => - true - } - } else true) - } holds - - def concreteZeroPredLemma[T](q: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(isConcrete(q, st)) - zeroPreceedsLazy(q, st) && { - // induction scheme - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concreteZeroPredLemma[T](tail, st) - case _ => - true - } - } - } holds - - def zeroPreceedsSuf[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear) => true - case Spine(_, _, rear) => - zeroPreceedsSuf(rear, suf, st) - case Tip(_) => true - } - } else false - } - - def zeroPredSufConcreteUntilLemma[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st) && zeroPreceedsSuf(q, suf, st)) - zeroPreceedsLazy(q, st) && { - // induction scheme - if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, _) => true - case Spine(_, _, tail) => - zeroPredSufConcreteUntilLemma(tail, suf, st) - case _ => - true - } - } else true - } - } holds - - def Pay[T](q: LazyConQ[T], scheds: Scheds[T], st: Set[LazyConQ[T]]): (Scheds[T], Set[LazyConQ[T]]) = { - require(strongSchedsProp(q, scheds, 1, st) && isEvaluated(q, st)) - val (nschs, rst) = scheds match { - case c @ Cons(head, rest) => - val (headval, st2) = evalLazyConQ(head, st) - (headval match { - case Spine(Empty(), createdWithSusp, rear) => // note: no other case is possible - if (createdWithSusp == True()) { - Cons(rear, rest) - } else - rest - // In this case, - // val prear = pushUntilZero(rear) - // concreteUntil(q, rhead, res._2) && concreteUntil(prear, rhead, st) && concreteUntil(rear, rhead, st) && schedulesProperty(prhead, rtail, st) - }, st2) - case Nil() => - (scheds, st) - } - (nschs, rst) - } ensuring { res => - val l = evalLazyConQS[T](q) match { - case Spine(_, _, rear) => - rear - case _ => q - } - strongSchedsProp(q, res._1, 2, res._2) && // head of the schedule must start's after first 2 - zeroPreceedsLazy(q, res._2) && - (scheds match { - case Cons(head, rest) => - concUntilExtenLemma(l, head, st) && - (res._1 match { - case Cons(rhead, rtail) => - val prhead = pushUntilZero(rhead) - schedMonotone(st, res._2, rtail, prhead) && - (evalLazyConQS(head) match { - case Spine(Empty(), cws, rear) => - if (cws == False()) { - concUntilMonotone(rear, rhead, st, res._2) && - concUntilCompose(l, rear, rhead, res._2) - } else true - }) - case _ => - evalLazyConQS(head) match { - case Spine(Empty(), _, rear) => - concreteMonotone(st, res._2, rear) && - concUntilExtenLemma2(l, rear, res._2) - } - }) - case _ => true - }) && - // instantiations for zeroPreceedsLazy - (scheds match { - case Cons(head, rest) => - //concUntil(l, head, st) == head && head* == Spine(Empty(), _) && res._2.subsetOf(st ++ { head }) - concUntilZeroPredLemma(l, head, st) - case _ => - concreteZeroPredLemma(q, res._2) - }) - } - - def pushLeftAndPay[T](ys: Single[T], w: Wrapper[T], st: Set[LazyConQ[T]]) = { - require(w.valid(st) && ys.isInstanceOf[Single[T]]) - val (q, scheds, nst) = pushLeftWrapper(ys, w, st) - val (nscheds, fst) = Pay(q, scheds, nst) - (Wrapper(q, nscheds), fst) - } ensuring { res => res._1.valid(res._2) } - - def lazyarg1[T](x: ConQ[T]): ConQ[T] = x -} - -object ConQ { - - abstract class LazyConQ[T1] - - case class Eager[T](x: ConQ[T]) extends LazyConQ[T] - - case class PushLeftLazy[T](ys: Conc[T], xs: LazyConQ[T] /*, suf: LazyConQ[T]*/ ) extends LazyConQ[T] - - @library - def evalLazyConQ[T](cl: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - cl match { - case t: Eager[T] => - (t.x, st) - case t: PushLeftLazy[T] => - val (plres, plst) = pushLeftLazy[T](t.ys, t.xs, st) - //val plres = pushLeftLazy[T](t.ys, t.xs, uiState())._1 - //val plst = pushLeftLazy[T](t.ys, t.xs, st)._2 - //val plres = pushLeftLazyUI[T](t.ys, t.xs, uiState())._1 - //val plst = pushLeftLazyUI[T](t.ys, t.xs, st)._2 - (plres, (plst ++ Set[LazyConQ[T]](t))) - } - } ensuring { res => - cl match { - case t : PushLeftLazy[T] => - res._1 == pushLeftLazyVal(t.ys, t.xs) - case _ => true - } - } - - def simpLemma[T](cl : LazyConQ[T], st: Set[LazyConQ[T]]) : Boolean = { - evalLazyConQ(cl, st)._1 == evalLazyConQS(cl) - } holds - - def isEvaluated[T](cl: LazyConQ[T], st: Set[LazyConQ[T]]) = st.contains(cl) || cl.isInstanceOf[Eager[T]] - - def uiState[T](): Set[LazyConQ[T]] = ???[Set[LazyConQ[T]]] - - def evalLazyConQS[T](cl: LazyConQ[T]): ConQ[T] = evalLazyConQ[T](cl, uiState())._1 - -} - -// Cases that had to be considered for pushLeftWrapper - /*(w.schedule match { - case Cons(head, tail) => true - //strongSchedsProp(res._1, res._2, res._3) - case _ => - res._2 match { - case Nil() => true - //strongSchedsProp(res._1, res._2, res._3) - case _ => - strongSchedsProp(res._1, res._2, res._3) - } - }) &&*/ - /*(//pushLeft(ys, w.queue, st)._1 match { - //case Spine(Empty(), createdWithSusp, _) if createdWithSusp == True() => true - /*(w.schedule match { - case Cons(head, tail) => - schedulesProperty(res._1, res._2, res._3) - case _ => true - })*/ - //case Spine(Empty(), _, _) => true - /*(w.schedule match { - case Cons(head, tail) => - schedulesProperty(res._1, res._2, res._3) - case _ => true - })*/ - //case Spine(_, _, _) => - /*(w.schedule match { - case Cons(head, tail) => - schedulesProperty(res._1, res._2, res._3) - case _ => true - })*/ - //case _ => true - //schedulesProperty(res._1, res._2, res._3) - })*/ - - /*def payLemma[T](q: LazyConQ[T], scheds: Scheds[T], st: Set[LazyConQ[T]]) = { - require(strongSchedsProp(q, scheds, st) && isEvaluated(q, st)) - val res = Pay(q, scheds, st) - val l = evalLazyConQS[T](q) match { - case Spine(_, _, rear) => - rear - case _ => q - } - strongSchedsProp(q, res._1, res._2) && - zeroPreceedsLazy(q, res._2) && - (scheds match { - case Cons(head, rest) => - concUntilExtenLemma(l, head, st) && - (res._1 match { - case Cons(rhead, rtail) => - val prhead = pushUntilZero(rhead) - schedMonotone(st, res._2, rtail, prhead) && - (evalLazyConQS(head) match { - case Spine(Empty(), cws, rear) => - if (cws == False()) { - concUntilMonotone(rear, rhead, st, res._2) && - concUntilCompose(l, rear, rhead, res._2) - } else true - }) - case _ => - evalLazyConQS(head) match { - case Spine(Empty(), _, rear) => - concreteMonotone(st, res._2, rear) && - concUntilExtenLemma2(l, rear, res._2) - } - }) - case _ => true - }) && - // instantiations for zeroPreceedsLazy - (scheds match { - case Cons(head, rest) => - //concUntil(l, head, st) == head && head* == Spine(Empty(), _) && res._2.subsetOf(st ++ { head }) - concUntilZeroPredLemma(l, head, st) - case _ => - concreteZeroPredLemma(q, res._2) - }) - } ensuring (_ == true)*/ diff --git a/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy3.scala b/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy3.scala deleted file mode 100644 index 5b26aec2326840a822708fa2f944d9015f9736a2..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/Conqueue-strategy3.scala +++ /dev/null @@ -1,698 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.lang.synthesis._ -import ConcTrees._ -import ConQ._ -import Conqueue._ - -object ConcTrees { - abstract class Conc[T] { - def isEmpty: Boolean = this == Empty[T]() - - def level: BigInt = { - this match { - case Empty() => - BigInt(0) - case Single(x) => - BigInt(0) - case CC(l, r) => - BigInt(1) + max(l.level, r.level) - } - } ensuring { - (x$1: BigInt) => x$1 >= BigInt(0) - } - } - - case class Empty[T]() extends Conc[T] - - case class Single[T](x: T) extends Conc[T] - - case class CC[T](left: Conc[T], right: Conc[T]) extends Conc[T] - - def max(x: BigInt, y: BigInt): BigInt = if (x >= y) { - x - } else { - y - } - - def abs(x: BigInt): BigInt = if (x < BigInt(0)) { - -x - } else { - x - } -} - -object Conqueue { - abstract class ConQ[T] { - def isSpine: Boolean = this match { - case Spine(_, _, _) => - true - case _ => - false - } - def isTip: Boolean = !this.isSpine - } - - case class Tip[T](t: Conc[T]) extends ConQ[T] - - case class Spine[T](head: Conc[T], createdWithSusp: Bool, rear: LazyConQ[T]) extends ConQ[T] - - sealed abstract class Bool - case class True() extends Bool - case class False() extends Bool - - abstract class Scheds[T] - - case class Cons[T](h: LazyConQ[T], tail: Scheds[T]) extends Scheds[T] - - case class Nil[T]() extends Scheds[T] - - case class Wrapper[T](queue: LazyConQ[T], schedule: Scheds[T]) { - def valid(st: Set[LazyConQ[T]]): Boolean = - strongSchedsProp(this.queue, this.schedule, st) - } - - def zeroPreceedsLazy[T](q: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - if (isEvaluated(q, st)) { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear) => true - case Spine(_, _, rear) => - zeroPreceedsLazy[T](rear, st) - case Tip(_) => true - } - } else false - } - - // not used, but still interesting - def zeroPredLazyMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], q: LazyConQ[T]): Boolean = { - require(st1.subsetOf(st2) && zeroPreceedsLazy(q, st1)) - zeroPreceedsLazy(q, st2) && - //induction scheme - (evalLazyConQS[T](q) match { - case Spine(Empty(), _, _) => - true - case Spine(h, _, rear) => - zeroPredLazyMonotone(st1, st2, rear) - case Tip(_) => - true - }) - } holds - - def weakZeroPreceedsLazy[T](q: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear10) => - true - case Spine(h, _, rear11) => - zeroPreceedsLazy[T](rear11, st) - case Tip(_) => - true - } - } - - def firstUnevaluated[T](l: LazyConQ[T], st: Set[LazyConQ[T]]): LazyConQ[T] = { - if (isEvaluated(l, st)) { - evalLazyConQS[T](l) match { - case Spine(_, _, tail15) => - firstUnevaluated[T](tail15, st) - case _ => - l - } - } else { - l - } - } ensuring { - (res65: LazyConQ[T]) => - (evalLazyConQS[T](res65).isTip || !st.contains(res65)) && - concreteUntil(l, res65, st) - } - - def nextUnevaluatedLemma[T](l: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - val (res, nst) = evalLazyConQ[T](firstUnevaluated(l, st), st) - (res match { - case Spine(_, _, tail) => - firstUnevaluated[T](l, nst) == firstUnevaluated[T](tail, nst) - case _ => - true - }) && - // induction scheme - (evalLazyConQS[T](l) match { - case Spine(_, _, tail) => - nextUnevaluatedLemma(tail, st) - case _ => true - }) - } holds - - /** - * Everything until suf is evaluated - */ - def concreteUntil[T](l: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - if (l != suf) { - isEvaluated(l, st) && (evalLazyConQS[T](l) match { - case Spine(_, cws, tail15) => - concreteUntil(tail15, suf, st) - case _ => - false // suf should in the queue - }) - } else true - } - - def concreteUntilIsSuffix[T](l: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(l, suf, st)) - suffix(l, suf) && - // induction scheme - (if (l != suf) { - (evalLazyConQS[T](l) match { - case Spine(_, cws, tail15) => - concreteUntilIsSuffix(tail15, suf, st) - case _ => - true - }) - } else true) - }.holds - - def isConcrete[T](l: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = isEvaluated(l, st) && (evalLazyConQS[T](l) match { - case Spine(_, _, tail13) => - isConcrete[T](tail13, st) - case _ => - true - }) - - def schedulesProperty[T](q: LazyConQ[T], schs: Scheds[T], st: Set[LazyConQ[T]]): Boolean = { - schs match { - case Cons(head, tail) => - evalLazyConQS[T](head) match { - case Spine(Empty(), _, _) => - !head.isInstanceOf[Eager[T]] && - concreteUntil(q, head, st) && schedulesProperty[T](pushUntilZero[T](head), tail, st) - case _ => - false - } - case Nil() => - isConcrete(q, st) - } - } - - def strongSchedsProp[T](q: LazyConQ[T], schs: Scheds[T], st: Set[LazyConQ[T]]): Boolean = { - isEvaluated(q, st) && { - schs match { - case Cons(head, tail) => - zeroPreceedsSuf(q, head) // zeroPreceedsSuf holds initially - case Nil() => true - } - } && - schedulesProperty(q, schs, st) - } - - // pushes a carry until there is a one - // TODO: rename this to pushUntilCarry - def pushUntilZero[T](q: LazyConQ[T]): LazyConQ[T] = evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear12) => - pushUntilZero[T](rear12) - case Spine(h, _, rear13) => - rear13 - case Tip(_) => - q - } - - // not used as of now - def pushUntilZeroIsSuffix[T](q: LazyConQ[T]): Boolean = { - suffix(q, pushUntilZero(q)) && - (evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear12) => - pushUntilZeroIsSuffix(rear12) - case Spine(h, _, rear13) => - true - case Tip(_) => - true - }) - }.holds - - def pushLeft[T](ys: Single[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - require(zeroPreceedsLazy[T](xs, st) && ys.isInstanceOf[Single[T]]) - - val dres5 = evalLazyConQ[T](xs, st) - dres5._1 match { - case Tip(CC(_, _)) => - (Spine[T](ys, False(), xs), dres5._2) - case Tip(Empty()) => - (Tip[T](ys), dres5._2) - case Tip(t @ Single(_)) => - (Tip[T](CC[T](ys, t)), dres5._2) - case s @ Spine(Empty(), _, rear) => - (Spine[T](ys, False(), rear), dres5._2) // in this case firstUnevaluated[T](rear, st) == firstUnevaluated[T](xs, st) - case s @ Spine(_, _, _) => - pushLeftLazy[T](ys, xs, dres5._2) - } - } - -/* def dummyFun[T]() = ???[(ConQ[T], Set[LazyConQ[T]])] - - @library - def pushLeftLazyUI[T](ys: Conc[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - dummyFun() - } ensuring (res => res._2 == st && (res._1 match { - case Spine(Empty(), createdWithSusp, rear) => - true - case _ => false - }))*/ - - def pushLeftLazyVal[T](ys: Conc[T], xs: LazyConQ[T]) : ConQ[T] = ???[ConQ[T]] - - @library - def resSpec[T](ys: Conc[T], xs: LazyConQ[T], res : ConQ[T]) = { - res == pushLeftLazyVal(ys, xs) - } holds - - def pushLeftLazy[T](ys: Conc[T], xs: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - require(!ys.isEmpty && zeroPreceedsLazy[T](xs, st) && - (evalLazyConQS(xs) match { - case Spine(h, _, _) => h != Empty[T]() - case _ => false - })) - val dres = evalLazyConQ[T](xs, st) - val res = dres._1 match { - case Spine(head, _, rear15) => - val carry = CC[T](head, ys) - val dres2 = evalLazyConQ[T](rear15, dres._2) - dres2._1 match { - case s @ Spine(Empty(), _, srear) => - (Spine[T](Empty[T](), False(), Eager(Spine(carry, False(), srear))), dres2._2) - case s @ Spine(_, _, _) => - (Spine[T](Empty[T](), True(), PushLeftLazy[T](carry, rear15)), dres2._2) - case t @ Tip(tree) => - if (tree.level > carry.level) { // this case may not even be possible given additional preconditions - val x: ConQ[T] = t - (Spine[T](Empty[T](), False(), Eager(Spine(carry, False(), rear15))), dres2._2) - } else { // here tree level and carry level are equal - val x: ConQ[T] = Tip[T](CC[T](tree, carry)) - (Spine[T](Empty[T](), False(), Eager(Spine(Empty[T](), False(), Eager[T](x)))), dres2._2) - } - } - } - res - } ensuring { - (res66: (Spine[T], Set[LazyConQ[T]])) => - resSpec(ys, xs, res66._1) && // asserts that the result is a function of inputs excluding state - (res66._2 == st) && (res66._1 match { - case Spine(Empty(), createdWithSusp, rear) => - val (rearval, _) = evalLazyConQ[T](rear, st) // this is necessary to assert properties on the state in the recursive invocation - (!isConcrete(xs, st) || isConcrete(pushUntilZero(rear), st)) - //true - case _ => - false - }) - } - - def pushLeftLazyLemma[T](ys: Conc[T], xs: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(!ys.isEmpty && zeroPreceedsSuf(xs, suf) && - (evalLazyConQS(xs) match { - case Spine(h, _, _) => h != Empty[T]() // this implies xs.rear is also evaluated - case _ => false - }) && - (evalLazyConQS(suf) match { - case Spine(Empty(), _, _) => - concreteUntil(xs, suf, st) - case _ => false - })) - // instantiate the lemma - zeroPredSufConcreteUntilLemma(xs, suf, st) && - // property - (pushLeftLazy(ys, xs, st)._1 match { - case Spine(Empty(), createdWithSusp, rear) => - // forall suf. suf*.head == Empty() ^ concUntil(xs, suf, st) => concUntil(push(rear), suf, st) - val p = pushUntilZero[T](rear) - concreteUntil(p, suf, st) - }) && - // induction scheme - (evalLazyConQS(xs) match { - case Spine(head, _, rear15) => - val carry = CC[T](head, ys) - evalLazyConQS(rear15) match { - case s @ Spine(h, _, _) if h != Empty[T]() => - pushLeftLazyLemma(carry, rear15, suf, st) - case _ => true - } - }) - } holds - - def pushLeftWrapper[T](ys: Single[T], w: Wrapper[T], st: Set[LazyConQ[T]]) = { - require(w.valid(st) && ys.isInstanceOf[Single[T]] && - // instantiate the lemma that implies zeroPreceedsLazy - { w.schedule match { - case Cons(h, _) => - zeroPredSufConcreteUntilLemma(w.queue, h, st) - case _ => - concreteZeroPredLemma(w.queue, st) - }}) - val (nq, nst) = pushLeft[T](ys, w.queue, st) - val nsched = nq match { - case Spine(Empty(), createdWithSusp, rear18) if createdWithSusp == True() => - Cons[T](rear18, w.schedule) // this is the only case where we create a new lazy closure - case _ => - w.schedule - } - (Eager(nq), nsched, nst) - } ensuring { res => - // lemma instantiations - (w.schedule match { - case Cons(head, tail) => - evalLazyConQS(w.queue) match { - case Spine(h, _, _) if h != Empty[T]() => - pushLeftLazyLemma(ys, w.queue, head, st) - case _ => true - } - case _ => true - }) && - //isEvaluated(res._1, res._3) && - schedulesProperty(res._1, res._2, res._3) // head of the schedule may start after the first element - } - - /*def PushLeftLazypushLeftLazyLem[T](rear15 : LazyConQ[T], head : Conc[T], dres : (ConQ[T], Set[LazyConQ[T]]), st : Set[LazyConQ[T]], xs : LazyConQ[T], s : Spine[T], dres : (ConQ[T], Set[LazyConQ[T]]), carry : CC[T], ys : Conc[T]): Boolean = { - (!ys.isEmpty && zeroPreceedsLazy[T](xs, st) && evalLazyConQS[T](xs).isSpine && dres == evalLazyConQ[T](xs, st) && (!dres._1.isInstanceOf[Spine[T]] || !dres._1.head.isInstanceOf[Empty[T]]) && dres._1.isInstanceOf[Spine[T]] && head == dres._1.head && rear15 == dres._1.rear && carry == CC[T](head, ys) && dres == evalLazyConQ[T](rear15, dres._2) && (!dres._1.isInstanceOf[Spine[T]] || !dres._1.head.isInstanceOf[Empty[T]]) && dres._1.isInstanceOf[Spine[T]] && s == dres._1) ==> (!carry.isEmpty && zeroPreceedsLazy[T](rear15, dres._2) && evalLazyConQS[T](rear15).isSpine) - } ensuring { - (holds : Boolean) => holds - }*/ - - def schedMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], scheds: Scheds[T], l: LazyConQ[T]): Boolean = { - require(st1.subsetOf(st2) && schedulesProperty(l, scheds, st1)) - schedulesProperty(l, scheds, st2) && //property - //induction scheme - (scheds match { - case Cons(head, tail) => - evalLazyConQS[T](head) match { - case Spine(_, _, rear) => - concUntilMonotone(l, head, st1, st2) && - schedMonotone(st1, st2, tail, pushUntilZero(head)) - case _ => true - } - case Nil() => - concreteMonotone(st1, st2, l) - }) - } holds - - def concreteMonotone[T](st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]], l: LazyConQ[T]): Boolean = { - require(isConcrete(l, st1) && st1.subsetOf(st2)) - isConcrete(l, st2) && { - // induction scheme - evalLazyConQS[T](l) match { - case Spine(_, _, tail) => - concreteMonotone[T](st1, st2, tail) - case _ => - true - } - } - } holds - - def concUntilExtenLemma[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st)) - val (next, nst) = evalLazyConQ[T](suf, st) - (next match { - case Spine(_, _, rear) => - concreteUntil(q, rear, nst) - case _ => true - }) && - (if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilExtenLemma(tail, suf, st) - case _ => - true - } - } else true) - } holds - - def concUntilExtenLemma2[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st) && isConcrete(suf, st)) - isConcrete(q, st) && - (if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilExtenLemma2(tail, suf, st) - case _ => - true - } - } else true) - } ensuring (_ == true) - - def concUntilCompose[T](q: LazyConQ[T], suf1: LazyConQ[T], suf2: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf1, st) && concreteUntil(suf1, suf2, st)) - concreteUntil(q, suf2, st) && - (if (q != suf1) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilCompose(tail, suf1, suf2, st) - case _ => - true - } - } else true) - } ensuring (_ == true) - - def concUntilMonotone[T](q: LazyConQ[T], suf: LazyConQ[T], st1: Set[LazyConQ[T]], st2: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st1) && st1.subsetOf(st2)) - concreteUntil(q, suf, st2) && - (if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilMonotone(tail, suf, st1, st2) - case _ => - true - } - } else true) - } ensuring (_ == true) - - /** - * Not used in the proof - */ - def concUntilZeroPredLemma[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st) && (evalLazyConQS(suf) match { - case Spine(Empty(), _, _) => true - case _ => false - })) - val (next, nst) = evalLazyConQ[T](suf, st) - zeroPreceedsLazy(q, nst) && - (if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concUntilZeroPredLemma(tail, suf, st) - case _ => - true - } - } else true) - } holds - - def concreteZeroPredLemma[T](q: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(isConcrete(q, st)) - zeroPreceedsLazy(q, st) && { - // induction scheme - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - concreteZeroPredLemma[T](tail, st) - case _ => - true - } - } - } holds - - def zeroPreceedsSuf[T](q: LazyConQ[T], suf: LazyConQ[T]): Boolean = { - if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, rear) => true - case Spine(_, _, rear) => - zeroPreceedsSuf(rear, suf) - case Tip(_) => false - } - } else false - } - - def zeroPredSufConcreteUntilLemma[T](q: LazyConQ[T], suf: LazyConQ[T], st: Set[LazyConQ[T]]): Boolean = { - require(concreteUntil(q, suf, st) && zeroPreceedsSuf(q, suf)) - zeroPreceedsLazy(q, st) && { - // induction scheme - if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(Empty(), _, _) => true - case Spine(_, _, tail) => - zeroPredSufConcreteUntilLemma(tail, suf, st) - case _ => - true - } - } else true - } - } holds - - def Pay[T](q: LazyConQ[T], scheds: Scheds[T], st: Set[LazyConQ[T]]): (Scheds[T], Set[LazyConQ[T]]) = { - require(schedulesProperty(q, scheds, st) && isEvaluated(q, st)) - val (nschs, rst) = scheds match { - case c @ Cons(head, rest) => - val (headval, st2) = evalLazyConQ(head, st) - (headval match { - case Spine(Empty(), createdWithSusp, rear) => // note: no other case is possible - if (createdWithSusp == True()) { - Cons(rear, rest) - } else - rest - // In this case, - // val prear = pushUntilZero(rear) - // concreteUntil(q, rhead, res._2) && concreteUntil(prear, rhead, st) && concreteUntil(rear, rhead, st) && schedulesProperty(prhead, rtail, st) - }, st2) - case Nil() => - (scheds, st) - } - (nschs, rst) - } ensuring { res => - schedulesProperty(q, res._1, res._2) && - //strongSchedsProp(q, res._1, res._2) && - (scheds match { - case Cons(head, rest) => - concUntilExtenLemma(q, head, st) && - (res._1 match { - case Cons(rhead, rtail) => - val prhead = pushUntilZero(rhead) - schedMonotone(st, res._2, rtail, prhead) && - (evalLazyConQS(head) match { - case Spine(Empty(), cws, rear) => - if (cws == False()) { - concUntilMonotone(rear, rhead, st, res._2) && - concUntilCompose(q, rear, rhead, res._2) - } else true - }) - case _ => - evalLazyConQS(head) match { - case Spine(Empty(), _, rear) => - concreteMonotone(st, res._2, rear) && - concUntilExtenLemma2(q, rear, res._2) - } - }) - case _ => true - }) && - // instantiations for zeroPreceedsSuf - (scheds match { - case Cons(head, rest) => - val phead = pushUntilZero(head) - concreteUntilIsSuffix(q, head, st) && - (res._1 match { - case Cons(rhead, rtail) => - concreteUntilIsSuffix(phead, rhead, st) && - suffixZeroLemma(q, head, rhead) && - zeroPreceedsSuf(q, rhead) - //suffix(l, head) && head* == Spine(Empty(), _) && suffix(head, rhead) ==> zeroPreceedsSuf(l, rhead) - case _ => - true - }) - case _ => - true - }) - } - - def suffix[T](q: LazyConQ[T], suf: LazyConQ[T]): Boolean = { - if(q == suf) true - else { - evalLazyConQS(q) match { - case Spine(_, _, rear) => - suffix(rear, suf) - case Tip(_) => false - } - } - } - - def suffixCompose[T](q: LazyConQ[T], suf1: LazyConQ[T], suf2: LazyConQ[T]): Boolean = { - require(suffix(q,suf1) && properSuffix(suf1, suf2)) - properSuffix(q, suf2) && - // induction over suffix(q, suf1) - (if(q == suf1) true - else { - evalLazyConQS(q) match { - case Spine(_, _, rear) => - suffixCompose(rear, suf1, suf2) - case Tip(_) => false - } - }) - }.holds - - // TODO: this should be inferrable from the model - @library - def properSuffix[T](l: LazyConQ[T], suf: LazyConQ[T]) : Boolean = { - evalLazyConQS(l) match { - case Spine(_, _, rear) => - suffix(rear, suf) - case _ => false - } - } ensuring(res => !res || suf != l) - - // uncomment this once the model is fixed - /*def suffixInEquality[T](l: LazyConQ[T], suf: LazyConQ[T], suf2: ) : Boolean = { - require(properSuffix(l, suf)) - (l != suf) && ( - evalLazyConQS(l) match { - case Spine(_, _, rear) => - suffixInEquality(rear, suf) - case _ => false - }) - }.holds*/ - - def suffixZeroLemma[T](q: LazyConQ[T], suf: LazyConQ[T], suf2: LazyConQ[T]): Boolean = { - require(evalLazyConQS(suf) match { - case Spine(Empty(), _, _) => - suffix(q, suf) && properSuffix(suf, suf2) - case _ => false - }) - suffixCompose(q, suf, suf2) && - zeroPreceedsSuf(q, suf2) && ( - // induction scheme - if (q != suf) { - evalLazyConQS[T](q) match { - case Spine(_, _, tail) => - suffixZeroLemma(tail, suf, suf2) - case _ => - true - } - } else true) - }.holds - - def pushLeftAndPay[T](ys: Single[T], w: Wrapper[T], st: Set[LazyConQ[T]]) = { - require(w.valid(st) && ys.isInstanceOf[Single[T]]) - val (q, scheds, nst) = pushLeftWrapper(ys, w, st) - val (nscheds, fst) = Pay(q, scheds, nst) - (Wrapper(q, nscheds), fst) - } ensuring { res => res._1.valid(res._2) } - - def lazyarg1[T](x: ConQ[T]): ConQ[T] = x -} - -object ConQ { - - abstract class LazyConQ[T1] - - case class Eager[T](x: ConQ[T]) extends LazyConQ[T] - - case class PushLeftLazy[T](ys: Conc[T], xs: LazyConQ[T] /*, suf: LazyConQ[T]*/ ) extends LazyConQ[T] - - @library - def evalLazyConQ[T](cl: LazyConQ[T], st: Set[LazyConQ[T]]): (ConQ[T], Set[LazyConQ[T]]) = { - cl match { - case t: Eager[T] => - (t.x, st) - case t: PushLeftLazy[T] => - val (plres, plst) = pushLeftLazy[T](t.ys, t.xs, st) - (plres, (plst ++ Set[LazyConQ[T]](t))) - } - } ensuring { res => - (cl match { - case t : PushLeftLazy[T] => - res._1 == pushLeftLazyVal(t.ys, t.xs) - case _ => true - }) - } - - def simpLemma[T](cl : LazyConQ[T], st: Set[LazyConQ[T]]) : Boolean = { - evalLazyConQ(cl, st)._1 == evalLazyConQS(cl) - }.holds - - def isEvaluated[T](cl: LazyConQ[T], st: Set[LazyConQ[T]]) = st.contains(cl) || cl.isInstanceOf[Eager[T]] - - def uiState[T](): Set[LazyConQ[T]] = ???[Set[LazyConQ[T]]] - - def evalLazyConQS[T](cl: LazyConQ[T]): ConQ[T] = evalLazyConQ[T](cl, uiState())._1 - -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/Conqueue.scala b/testcases/lazy-datastructures/ManualnOutdated/Conqueue.scala deleted file mode 100644 index 80d77d21de300f6b0b2bd71f1ec6aa1e777058c3..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/Conqueue.scala +++ /dev/null @@ -1,585 +0,0 @@ -package conc - -import leon.lazyeval._ -import leon.lang._ -import leon.math._ -import leon.annotation._ -import leon.instrumentation._ -import leon.lazyeval.$._ - -import ConcTrees._ -import scala.math.BigInt.int2bigInt - -object ConcTrees { - - sealed abstract class Conc[T] { - def isEmpty: Boolean = { - this == Empty[T]() - } - - // Note: instrumentation phase is unsound in the handling of fields as it does not its cost in object construction. - // Fix this. - val level: BigInt = { - this match { - case Empty() => BigInt(0) - case Single(x) => BigInt(0) - case CC(l, r) => - BigInt(1) + max(l.level, r.level) - } - } ensuring (_ >= 0) - } - - case class Empty[T]() extends Conc[T] - case class Single[T](x: T) extends Conc[T] - case class CC[T](left: Conc[T], right: Conc[T]) extends Conc[T] -} -object Conqueue { - - sealed abstract class ConQ[T] { - val isSpine: Boolean = this match { - case Spine(_, _, _) => true - case _ => false - } - val isTip = !isSpine - } - - case class Tip[T](t: Conc[T]) extends ConQ[T] - case class Spine[T](head: Conc[T], createdWithSuspension: Bool, rear: $[ConQ[T]]) extends ConQ[T] - - sealed abstract class Bool - case class True() extends Bool - case class False() extends Bool - - /** - * Checks whether there is a zero before an unevaluated closure - */ - def zeroPreceedsLazy[T](q: $[ConQ[T]]): Boolean = { - if (q.isEvaluated) { - q* match { - case Spine(Empty(), _, rear) => - true // here we have seen a zero - case Spine(h, _, rear) => - zeroPreceedsLazy(rear) //here we have not seen a zero - case Tip(_) => true - } - } else false - } - - /** - * Checks whether there is a zero before a given suffix - */ - def zeroPreceedsSuf[T](q: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - if (q != suf) { - q* match { - case Spine(Empty(), _, rear) => true - case Spine(_, _, rear) => - zeroPreceedsSuf(rear, suf) - case Tip(_) => false - } - } else false - } - - /** - * Everything until suf is evaluated. This - * also asserts that suf should be a suffix of the list - */ - def concreteUntil[T](l: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - if (l != suf) { - l.isEvaluated && (l* match { - case Spine(_, cws, tail) => - concreteUntil(tail, suf) - case _ => - false - }) - } else true - } - - def isConcrete[T](l: $[ConQ[T]]): Boolean = { - l.isEvaluated && (l* match { - case Spine(_, _, tail) => - isConcrete(tail) - case _ => true - }) - } - - sealed abstract class Scheds[T] - case class Cons[T](h: $[ConQ[T]], tail: Scheds[T]) extends Scheds[T] - case class Nil[T]() extends Scheds[T] - - def schedulesProperty[T](q: $[ConQ[T]], schs: Scheds[T]): Boolean = { - schs match { - case Cons(head, tail) => - head* match { - case Spine(Empty(), _, _) => - head.isSuspension(pushLeftLazy[T] _) && - concreteUntil(q, head) && - schedulesProperty(pushUntilCarry(head), tail) - case _ => - false - } - case Nil() => - isConcrete(q) - } - } - - def strongSchedsProp[T](q: $[ConQ[T]], schs: Scheds[T]) = { - q.isEvaluated && { - schs match { - case Cons(head, tail) => - zeroPreceedsSuf(q, head) // zeroPreceedsSuf holds initially - case Nil() => true - } - } && - schedulesProperty(q, schs) - } - - /** - * Note: if 'q' has a suspension then it would have a carry. - */ - def pushUntilCarry[T](q: $[ConQ[T]]): $[ConQ[T]] = { - q* match { - case Spine(Empty(), _, rear) => // if we push a carry and get back 0 then there is a new carry - pushUntilCarry(rear) - case Spine(h, _, rear) => // if we push a carry and get back 1 then there the carry has been fully pushed - rear - case Tip(_) => - q - } - } - - case class Queue[T](queue: $[ConQ[T]], schedule: Scheds[T]) { - val valid = strongSchedsProp(queue, schedule) - } - - def pushLeft[T](ys: Single[T], xs: $[ConQ[T]]): ConQ[T] = { - require(zeroPreceedsLazy(xs)) - xs.value match { - case Tip(CC(_, _)) => - Spine(ys, False(), xs) - case Tip(Empty()) => - Tip(ys) - case Tip(t @ Single(_)) => - Tip(CC(ys, t)) - case s @ Spine(Empty(), _, rear) => - Spine[T](ys, False(), rear) - case s @ Spine(_, _, _) => - pushLeftLazy(ys, xs) - } - } ensuring (_ => time <= 70) - - // this procedure does not change state - // TODO: can `invstate` annotations be automatically inferred - @invstate - def pushLeftLazy[T](ys: Conc[T], xs: $[ConQ[T]]): ConQ[T] = { - require(!ys.isEmpty && zeroPreceedsLazy(xs) && - (xs* match { - case Spine(h, _, _) => h != Empty[T]() - case _ => false - })) - //an additional precondition that is necessary for correctness: xs.head.level == ys.level - xs.value match { - case Spine(head, _, rear) => // here, rear is guaranteed to be evaluated by 'zeroPreceedsLazy' invariant - val carry = CC(head, ys) //here, head and ys are of the same level - rear.value match { - case s @ Spine(Empty(), _, srear) => - val tail: ConQ[T] = Spine(carry, False(), srear) - Spine(Empty(), False(), tail) - - case s @ Spine(_, _, _) => - Spine(Empty(), True(), $(pushLeftLazy(carry, rear))) - - case t @ Tip(tree) => - if (tree.level > carry.level) { // can this happen ? this means tree is of level at least two greater than rear ? - val y: ConQ[T] = Spine(carry, False(), rear) - Spine(Empty(), False(), y) - } else { // here tree level and carry level are equal - val x: ConQ[T] = Tip(CC(tree, carry)) - val y: ConQ[T] = Spine(Empty(), False(), x) - Spine(Empty(), False(), y) - } - } - } - } ensuring { res => - (res match { - case Spine(Empty(), _, rear) => - (!isConcrete(xs) || isConcrete(pushUntilCarry(rear))) && - { - val _ = rear.value // this is necessary to assert properties on the state in the recursive invocation (and note this cannot go first) - rear.isEvaluated // this is a tautology - } - case _ => - false - }) && - time <= 40 - } - - /** - * Lemma: - * forall suf. suf*.head != Empty() ^ zeroPredsSuf(xs, suf) ^ concUntil(xs.tail.tail, suf) => concUntil(push(rear), suf) - */ - @invstate - def pushLeftLazyLemma[T](ys: Conc[T], xs: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - require(!ys.isEmpty && zeroPreceedsSuf(xs, suf) && - (xs* match { - case Spine(h, _, _) => h != Empty[T]() - case _ => false - }) && - (suf* match { - case Spine(Empty(), _, _) => - concreteUntil(xs, suf) - case _ => false - })) - // induction scheme - (xs* match { - case Spine(head, _, rear) => - val carry = CC[T](head, ys) - rear* match { - case s @ Spine(h, _, _) => - if (h != Empty[T]()) - pushLeftLazyLemma(carry, rear, suf) - else true - case _ => true - } - }) && - // instantiate the lemma that implies zeroPreceedsLazy - (if (zeroPredSufConcreteUntilLemma(xs, suf)) { - // property - (pushLeftLazy(ys, xs) match { - case Spine(Empty(), _, rear) => - concreteUntil(pushUntilCarry(rear), suf) - }) - } else false) - } holds - - // verifies in 300 secs - def pushLeftWrapper[T](ys: Single[T], w: Queue[T]) = { - require(w.valid && - // instantiate the lemma that implies zeroPreceedsLazy - (w.schedule match { - case Cons(h, _) => - zeroPredSufConcreteUntilLemma(w.queue, h) - case _ => - concreteZeroPredLemma(w.queue) - })) - val nq = pushLeft(ys, w.queue) - val nsched = nq match { - case Spine(Empty(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons[T](rear, w.schedule) // this is the only case where we create a new lazy closure - else - w.schedule - case _ => - w.schedule - } - val lq: $[ConQ[T]] = nq - (lq, nsched) - } ensuring { res => - // lemma instantiations - (w.schedule match { - case Cons(head, tail) => - w.queue* match { - case Spine(h, _, _) => - if (h != Empty[T]()) - pushLeftLazyLemma(ys, w.queue, head) - else true - case _ => true - } - case _ => true - }) && - schedulesProperty(res._1, res._2) && - time <= 80 - } - - def Pay[T](q: $[ConQ[T]], scheds: Scheds[T]): Scheds[T] = { - require(schedulesProperty(q, scheds) && q.isEvaluated) - scheds match { - case c @ Cons(head, rest) => - head.value match { - case Spine(Empty(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons(rear, rest) - else - rest - } - case Nil() => scheds - } - } ensuring { res => - { - val in = inState[ConQ[T]] - val out = outState[ConQ[T]] - // instantiations for proving the scheds property - (scheds match { - case Cons(head, rest) => - concUntilExtenLemma(q, head, in, out) && - (head* match { - case Spine(Empty(), _, rear) => - res match { - case Cons(rhead, rtail) => - schedMonotone(in, out, rtail, pushUntilCarry(rhead)) && - concUntilMonotone(rear, rhead, in, out) && - concUntilCompose(q, rear, rhead) - case _ => - concreteMonotone(in, out, rear) && - concUntilConcreteExten(q, rear) - } - }) - case _ => true - }) && - // instantiations for zeroPreceedsSuf property - (scheds match { - case Cons(head, rest) => - concreteUntilIsSuffix(q, head) && - (res match { - case Cons(rhead, rtail) => - concreteUntilIsSuffix(pushUntilCarry(head), rhead) && - suffixZeroLemma(q, head, rhead) && - zeroPreceedsSuf(q, rhead) - case _ => - true - }) - case _ => - true - }) - } && // properties - schedulesProperty(q, res) && - time <= 70 - } - - // monotonicity lemmas - def schedMonotone[T](st1: Set[$[ConQ[T]]], st2: Set[$[ConQ[T]]], scheds: Scheds[T], l: $[ConQ[T]]): Boolean = { - require(st1.subsetOf(st2) && - (schedulesProperty(l, scheds) withState st1)) // here the input state is fixed as 'st1' - //induction scheme - (scheds match { - case Cons(head, tail) => - head* match { - case Spine(_, _, rear) => - concUntilMonotone(l, head, st1, st2) && - schedMonotone(st1, st2, tail, pushUntilCarry(head)) - case _ => true - } - case Nil() => - concreteMonotone(st1, st2, l) - }) && (schedulesProperty(l, scheds) withState st2) //property - } holds - - def concreteMonotone[T](st1: Set[$[ConQ[T]]], st2: Set[$[ConQ[T]]], l: $[ConQ[T]]): Boolean = { - require((isConcrete(l) withState st1) && st1.subsetOf(st2)) - // induction scheme - (l* match { - case Spine(_, _, tail) => - concreteMonotone[T](st1, st2, tail) - case _ => - true - }) && (isConcrete(l) withState st2) - } holds - - def concUntilMonotone[T](q: $[ConQ[T]], suf: $[ConQ[T]], st1: Set[$[ConQ[T]]], st2: Set[$[ConQ[T]]]): Boolean = { - require((concreteUntil(q, suf) withState st1) && st1.subsetOf(st2)) - (if (q != suf) { - q* match { - case Spine(_, _, tail) => - concUntilMonotone(tail, suf, st1, st2) - case _ => - true - } - } else true) && - (concreteUntil(q, suf) withState st2) - } holds - - // suffix predicates and their properties (this should be generalizable) - - def suffix[T](q: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - if (q == suf) true - else { - q* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case Tip(_) => false - } - } - } - - def properSuffix[T](l: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - l* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case _ => false - } - } ensuring (res => !res || (suffixDisequality(l, suf) && suf != l)) - - /** - * suf(q, suf) ==> suf(q.rear, suf.rear) - */ - def suffixTrans[T](q: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - require(suffix(q, suf)) - // induction scheme - (if (q == suf) true - else { - q* match { - case Spine(_, _, rear) => - suffixTrans(rear, suf) - case Tip(_) => true - } - }) && // property - ((q*, suf*) match { - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffix(rear, sufRear) - case _ => true - }) - }.holds - - /** - * properSuf(l, suf) ==> l != suf - */ - def suffixDisequality[T](l: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - require(properSuffix(l, suf)) - suffixTrans(l, suf) && // lemma instantiation - ((l*, suf*) match { // induction scheme - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffixDisequality(rear, sufRear) - case _ => true - }) && l != suf // property - }.holds - - def suffixCompose[T](q: $[ConQ[T]], suf1: $[ConQ[T]], suf2: $[ConQ[T]]): Boolean = { - require(suffix(q, suf1) && properSuffix(suf1, suf2)) - // induction over suffix(q, suf1) - (if (q == suf1) true - else { - q* match { - case Spine(_, _, rear) => - suffixCompose(rear, suf1, suf2) - case Tip(_) => false - } - }) && properSuffix(q, suf2) - } holds - - // properties of 'concUntil' - - def concreteUntilIsSuffix[T](l: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - require(concreteUntil(l, suf)) - // induction scheme - (if (l != suf) { - (l* match { - case Spine(_, cws, tail) => - concreteUntilIsSuffix(tail, suf) - case _ => - true - }) - } else true) && suffix(l, suf) - }.holds - - // properties that extend `concUntil` to larger portions of the queue - - def concUntilExtenLemma[T](q: $[ConQ[T]], suf: $[ConQ[T]], st1: Set[$[ConQ[T]]], st2: Set[$[ConQ[T]]]): Boolean = { - require((concreteUntil(q, suf) withState st1) && st2 == st1 ++ Set(suf)) - // induction scheme - (if (q != suf) { - q* match { - case Spine(_, _, tail) => - concUntilExtenLemma(tail, suf, st1, st2) - case _ => - true - } - } else true) && - (suf* match { - case Spine(_, _, rear) => - concreteUntil(q, rear) withState st2 - case _ => true - }) - } holds - - def concUntilConcreteExten[T](q: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - require(concreteUntil(q, suf) && isConcrete(suf)) - (if (q != suf) { - q* match { - case Spine(_, _, tail) => - concUntilConcreteExten(tail, suf) - case _ => - true - } - } else true) && isConcrete(q) - } holds - - def concUntilCompose[T](q: $[ConQ[T]], suf1: $[ConQ[T]], suf2: $[ConQ[T]]): Boolean = { - require(concreteUntil(q, suf1) && concreteUntil(suf1, suf2)) - (if (q != suf1) { - q* match { - case Spine(_, _, tail) => - concUntilCompose(tail, suf1, suf2) - case _ => - true - } - } else true) && - concreteUntil(q, suf2) - } holds - - // properties that relate `concUntil`, `concrete`, `zeroPreceedsSuf` with `zeroPreceedsLazy` - // - these are used in preconditions to derive the `zeroPreceedsLazy` property - - def zeroPredSufConcreteUntilLemma[T](q: $[ConQ[T]], suf: $[ConQ[T]]): Boolean = { - require(concreteUntil(q, suf) && zeroPreceedsSuf(q, suf)) - // induction scheme - (if (q != suf) { - q* match { - case Spine(Empty(), _, _) => true - case Spine(_, _, tail) => - zeroPredSufConcreteUntilLemma(tail, suf) - case _ => - true - } - } else true) && - zeroPreceedsLazy(q) - } holds - - def concreteZeroPredLemma[T](q: $[ConQ[T]]): Boolean = { - require(isConcrete(q)) - // induction scheme - (q* match { - case Spine(_, _, tail) => - concreteZeroPredLemma(tail) - case _ => - true - }) && - zeroPreceedsLazy(q) - } holds - - // properties relating `suffix` an `zeroPreceedsSuf` - - def suffixZeroLemma[T](q: $[ConQ[T]], suf: $[ConQ[T]], suf2: $[ConQ[T]]): Boolean = { - require(suf* match { - case Spine(Empty(), _, _) => - suffix(q, suf) && properSuffix(suf, suf2) - case _ => false - }) - suffixCompose(q, suf, suf2) && ( - // induction scheme - if (q != suf) { - q* match { - case Spine(_, _, tail) => - suffixZeroLemma(tail, suf, suf2) - case _ => - true - } - } else true) && - zeroPreceedsSuf(q, suf2) // property - }.holds - - /** - * Pushing an element to the left of the queue preserves the data-structure invariants - */ - def pushLeftAndPay[T](ys: Single[T], w: Queue[T]) = { - require(w.valid) - - val (q, scheds) = pushLeftWrapper(ys, w) - val nscheds = Pay(q, scheds) - Queue(q, nscheds) - - } ensuring { res => - res.valid && - time <= 200 - } -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/LazyMegeSort-edited.scala b/testcases/lazy-datastructures/ManualnOutdated/LazyMegeSort-edited.scala deleted file mode 100644 index f11476bd1eb3d9b1924c8e7aee00903fa3b6c055..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/LazyMegeSort-edited.scala +++ /dev/null @@ -1,230 +0,0 @@ -package output -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.invariant._ - -object MergeSort { - - case class Set1[T]() - - abstract class IList { - def size: BigInt = { - this match { - case ICons(_, xs) => - BigInt(1) + xs.size - case _ => - BigInt(0) - } - } ensuring { - (x$1: BigInt) => x$1 >= BigInt(0) - } - } - - case class ICons(x: BigInt, tail: IList) extends IList - - case class INil() extends IList - - abstract class ILList { - /*def size: BigInt = { - this match { - case LCons(_, xs37) => - BigInt(1) + ssize(xs37) - case _ => - BigInt(0) - } - } ensuring { - (x$218: BigInt) => x$218 >= BigInt(0) - }*/ - } - - case class LCons(x: BigInt, tail: LazyILList) extends ILList - - case class LNil() extends ILList - - abstract class LList { - def size: BigInt = { - this match { - case SNil() => - BigInt(0) - case SCons(_, t) => - BigInt(1) + t.size - } - } ensuring { - (x$3: BigInt) => x$3 >= BigInt(0) - } - } - - case class SCons(x: LazyILList, tail: LList) extends LList - - case class SNil() extends LList - - /* def ssize(l: LazyILList): BigInt = { - evalLazyILList2(l).size - } ensuring { - (res: BigInt) => true - } - - def fullSize(l: LList): BigInt = { - l match { - case SNil() => - BigInt(0) - case SCons(l49, t) => - ssize(l49) + fullSize(t) - } - } ensuring { - (x$46: BigInt) => x$46 >= BigInt(0) - }*/ - - /*def pairs(l: LList, st: Set1[LazyILList]): (LList, Set1[LazyILList]) = { - l match { - case SNil() => - (SNil(), st) - case SCons(_, SNil()) => - (l, st) - case SCons(l118, SCons(l215, rest)) => - val a77 = pairs(rest, st) - (SCons(newILList(Merge(l118, l215), st), a77._1), a77._2) - } - } ensuring { - (res69: (LList, Set1[LazyILList])) => - res69._1.size <= (l.size + BigInt(1)) / BigInt(2) && - fullSize(l) == fullSize(res69._1) && - time <= 10 * l.size + 4 - }*/ - - abstract class LazyILList - - case class Merge(a: LazyILList, b: LazyILList) extends LazyILList - - case class Lsingle(x: BigInt) extends LazyILList - - case class Lempty() extends LazyILList - - //@library - def newILList(cc: LazyILList, st: Set1[LazyILList]): LazyILList = { - cc - } /*ensuring { - (res: LazyILList) => !st.contains(res) - }*/ - - //@library - /*def evalLazyILList(cl: LazyILList, st: Set1[LazyILList]): (ILList, Set1[LazyILList]) = { - cl match { - case t: Merge => - (merge(t.a, t.b, Set1[LazyILList]()), Set1[LazyILList]()) - case t: Lsingle => - (lsingle(t.x, Set1[LazyILList]()), Set1[LazyILList]()) - case t: Lempty => - (lempty, Set1[LazyILList]()) - } - } ensuring { - (res: (ILList, Set1[LazyILList])) => - cl match { - case t: Merge => - ssize(t.a) + ssize(t.b) == res._1.size && - time <= 300 * res._1.size - 100 - case t: Lsingle => - true - case t: Lempty => - true - } - } - - def evalLazyILList2(cl: LazyILList): ILList = { - evalLazyILList(cl, Set1[LazyILList]())._1 - } ensuring { - (res: ILList) => true - }*/ - -/* def constructMergeTree(l: LList, st: Set1[LazyILList]): (LList, Set1[LazyILList]) = { - l match { - case SNil() => - (SNil(), st) - case SCons(_, SNil()) => - (l, st) - case _ => - val a76 = pairs(l, st) - constructMergeTree(a76._1, a76._2) - } - } ensuring { - (res: (LList, Set1[LazyILList])) => - res._1.size <= BigInt(1) && fullSize(res._1) == fullSize(l) && (res._1 match { - case SCons(il1, SNil()) => - fullSize(res._1) == ssize(il1) - case _ => - true - }) && - time <= 42 * l.size + 4 - }*/ - - /* def merge(a: LazyILList, b: LazyILList, st: Set1[LazyILList]): ILList = { - require(evalLazyILList2(a) != LNil() && evalLazyILList2(b) != LNil()) - evalLazyILList(b, st)._1 match { - case LNil() => - evalLazyILList(a, st)._1 - case bl @ LCons(x, xs36) => - evalLazyILList(a, st)._1 match { - case LNil() => - bl - case LCons(y, ys2) => - if (y < x) { - LCons(y, Merge(ys2, b)) - } else { - LCons(x, Merge(a, xs36)) - } - } - } - } ensuring { - (res70 : ILList) => ssize(a) + ssize(b) == res70.size && - time <= 300 * res70.size - 100 -// (res70 match { -// case _ if res70.size == 1 => -// time <= 300 * res70.size + 100 -// case _ => -// time <= 300 * res70.size - 100 -// }) - }*/ - - def IListToLList(l: IList, st: Set1[LazyILList]): LList = { - l match { - case INil() => - SNil() - case ICons(x, xs) => - SCons(newILList(Lsingle(x), st), IListToLList(xs, st)) - } - } ensuring { - (res: LList) => - //fullSize(res) == l.size && res.size == l.size && - time <= 9 * l.size + 3 - } - -// def mergeSort(l: IList, st: Set1[LazyILList]): (ILList, Set1[LazyILList]) = { -// l match { -// case INil() => -// (LNil(), st) -// case _ => -// val scr = constructMergeTree(IListToLList(l, st), st) -// scr._1 match { -// case SCons(r13, SNil()) => -// val dres = evalLazyILList(r13, scr._2) -// (dres._1, dres._2) -// } -// } -// } ensuring { -// (res: (ILList, Set1[LazyILList])) => true -// } - - def lempty(): ILList = { - LNil() - } ensuring { - (res: ILList) => true - } - - def lsingle(x: BigInt, st: Set1[LazyILList]): ILList = { - LCons(x, newILList(Lempty(), st)) - } ensuring { - (res: ILList) => true - } -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/LazyMegeSort1-Time.scala b/testcases/lazy-datastructures/ManualnOutdated/LazyMegeSort1-Time.scala deleted file mode 100644 index 119e95040f7b02ce9b2bb6a8d7b1da3a8d729ab6..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/LazyMegeSort1-Time.scala +++ /dev/null @@ -1,92 +0,0 @@ -package lazybenchmarks - -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -//import leon.invariant._ - -object MergeSort1 { - - // TODO: making this parametric will break many things. Fix them - sealed abstract class LList { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + ssize(t) - } - } ensuring (_ >= 0) - } - case class SCons(x: BigInt, tail: $[LList]) extends LList - case class SNil() extends LList - def ssize(l: $[LList]): BigInt = (l*).size - - sealed abstract class List { - def size: BigInt = { - this match { - case Cons(_, xs) => 1 + xs.size - case _ => BigInt(0) - } - } ensuring (_ >= 0) - } - case class Cons(x: BigInt, tail: List) extends List - case class Nil() extends List - - def length(l: List): BigInt = { - l match { - case Nil() => BigInt(0) - case Cons(x, xs) => 1 + length(xs) - } - } ensuring (res => res >= 0 && res == l.size) - - def split(l: List, n: BigInt): (List, List) = { - require(n > 0 && n < l.size) - l match { - case Nil() => (Nil(), l) - case Cons(x, xs) => - if (n == 1) { - (Cons(x, Nil()), xs) - } else { - val (fst, snd) = split(xs, n - 1) - (Cons(x, fst), snd) - } - } - } ensuring (res => res._2.size == l.size - n && res._1.size == n && stack <= 25 * l.size - 1) - - /* - * Note: merge is not recursive due to closures. - * However, concretizing merge may invoke merge or msort recursively. - * So proving standalone bound for merge requires preconditions. - */ - def merge(a: $[LList], b: $[LList]): LList = (b.value match { - case SNil() => a.value - case bl @ SCons(x, xs) => - a.value match { - case SNil() => bl - case SCons(y, ys) => - if (y < x) - SCons(y, $(merge(ys, b))) - else - SCons(x, $(merge(a, xs))) - } - }) //ensuring (res => ssize(a) + ssize(b) == res.size) - - /** - * For proving time, we need a term of order \Omega(n) with strict - * inverse triangle inequality i.e, f(a + b) > f(a) + f(b) - * Log satisfies this but it is very expensive. Is there another function ? - */ - def mergeSort(l: List): LList = (l match { - case Nil() => SNil() - case Cons(x, Nil()) => SCons(x, $(empty)) - case _ => - val (fst, snd) = split(l, length(l) / 2) - merge($(mergeSort(fst)), $(mergeSort(snd))) - - }) ensuring (res => stack <= 81 * l.size + 35) // res.size == l.size - - // TODO: inlining this creates problems. why ? - def empty: LList = { - SNil() - } -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/LazyNumericalRep.scala b/testcases/lazy-datastructures/ManualnOutdated/LazyNumericalRep.scala deleted file mode 100644 index d21bc2e9eb6627b77c226943660a09838b3aa08c..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/LazyNumericalRep.scala +++ /dev/null @@ -1,552 +0,0 @@ -package lazybenchmarks - -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.lazyeval.$._ - -object DigitObject { - sealed abstract class Digit - case class Zero() extends Digit - case class One() extends Digit -} - -import DigitObject._ -object LazyNumericalRep { - - sealed abstract class NumStream { - val isSpine: Boolean = this match { - case Spine(_, _, _) => true - case _ => false - } - val isTip = !isSpine - } - - case class Tip() extends NumStream - case class Spine(head: Digit, createdWithSuspension: Bool, rear: $[NumStream]) extends NumStream - - sealed abstract class Bool - case class True() extends Bool - case class False() extends Bool - - /** - * Checks whether there is a zero before an unevaluated closure - */ - def zeroPreceedsLazy[T](q: $[NumStream]): Boolean = { - if (q.isEvaluated) { - q* match { - case Spine(Zero(), _, rear) => - true // here we have seen a zero - case Spine(_, _, rear) => - zeroPreceedsLazy(rear) //here we have not seen a zero - case Tip() => true - } - } else false - } - - /** - * Checks whether there is a zero before a given suffix - */ - def zeroPreceedsSuf[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - if (q != suf) { - q* match { - case Spine(Zero(), _, rear) => true - case Spine(_, _, rear) => - zeroPreceedsSuf(rear, suf) - case Tip() => false - } - } else false - } - - /** - * Everything until suf is evaluated. This - * also asserts that suf should be a suffix of the list - */ - def concreteUntil[T](l: $[NumStream], suf: $[NumStream]): Boolean = { - if (l != suf) { - l.isEvaluated && (l* match { - case Spine(_, cws, tail) => - concreteUntil(tail, suf) - case _ => - false - }) - } else true - } - - def isConcrete[T](l: $[NumStream]): Boolean = { - l.isEvaluated && (l* match { - case Spine(_, _, tail) => - isConcrete(tail) - case _ => true - }) - } - - sealed abstract class Scheds - case class Cons(h: $[NumStream], tail: Scheds) extends Scheds - case class Nil() extends Scheds - - def schedulesProperty[T](q: $[NumStream], schs: Scheds): Boolean = { - schs match { - case Cons(head, tail) => - head* match { - case Spine(Zero(), _, _) => // head starts with zero - head.isSuspension(incLazy _) && - concreteUntil(q, head) && - schedulesProperty(pushUntilCarry(head), tail) - case _ => - false - } - case Nil() => - isConcrete(q) - } - } - - def strongSchedsProp[T](q: $[NumStream], schs: Scheds) = { - q.isEvaluated && { - schs match { - case Cons(head, tail) => - zeroPreceedsSuf(q, head) // zeroPreceedsSuf holds initially - case Nil() => true - } - } && - schedulesProperty(q, schs) - } - - /** - * Note: if 'q' has a suspension then it would have a carry. - */ - def pushUntilCarry[T](q: $[NumStream]): $[NumStream] = { - q* match { - case Spine(Zero(), _, rear) => // if we push a carry and get back 0 then there is a new carry - pushUntilCarry(rear) - case Spine(_, _, rear) => // if we push a carry and get back 1 then there the carry has been fully pushed - rear - case Tip() => - q - } - } - - case class Number(digs: $[NumStream], schedule: Scheds) { - val valid = strongSchedsProp(digs, schedule) - } - - def inc(xs: $[NumStream]): NumStream = { - require(zeroPreceedsLazy(xs)) - xs.value match { - case Tip() => - Spine(One(), False(), xs) - case s @ Spine(Zero(), _, rear) => - Spine(One(), False(), rear) - case s @ Spine(_, _, _) => - incLazy(xs) - } - } ensuring (_ => time <= 70) - - // this procedure does not change state - // TODO: can `invstate` annotations be automatically inferred - @invstate - def incLazy(xs: $[NumStream]): NumStream = { - require(zeroPreceedsLazy(xs) && - (xs* match { - case Spine(h, _, _) => h != Zero() // xs doesn't start with a zero - case _ => false - })) - xs.value match { - case Spine(head, _, rear) => // here, rear is guaranteed to be evaluated by 'zeroPreceedsLazy' invariant - val carry = One() - rear.value match { - case s @ Spine(Zero(), _, srear) => - val tail: NumStream = Spine(carry, False(), srear) - Spine(Zero(), False(), tail) - - case s @ Spine(_, _, _) => - Spine(Zero(), True(), $(incLazy(rear))) - - case t @ Tip() => - val y: NumStream = Spine(carry, False(), rear) - Spine(Zero(), False(), y) - } - } - } ensuring { res => - (res match { - case Spine(Zero(), _, rear) => - (!isConcrete(xs) || isConcrete(pushUntilCarry(rear))) && - { - val _ = rear.value // this is necessary to assert properties on the state in the recursive invocation (and note this cannot go first) - rear.isEvaluated // this is a tautology - } - case _ => - false - }) && - time <= 40 - } - - /** - * Lemma: - * forall suf. suf*.head != Zero() ^ zeroPredsSuf(xs, suf) ^ concUntil(xs.tail.tail, suf) => concUntil(push(rear), suf) - */ - @invstate - def incLazyLemma[T](xs: $[NumStream], suf: $[NumStream]): Boolean = { - require(zeroPreceedsSuf(xs, suf) && - (xs* match { - case Spine(h, _, _) => h != Zero() - case _ => false - }) && - (suf* match { - case Spine(Zero(), _, _) => - concreteUntil(xs, suf) - case _ => false - })) - // induction scheme - (xs* match { - case Spine(head, _, rear) => - rear* match { - case s @ Spine(h, _, _) => - if (h != Zero()) - incLazyLemma(rear, suf) - else true - case _ => true - } - }) && - // instantiate the lemma that implies zeroPreceedsLazy - (if (zeroPredSufConcreteUntilLemma(xs, suf)) { - // property - (incLazy(xs) match { - case Spine(Zero(), _, rear) => - concreteUntil(pushUntilCarry(rear), suf) - }) - } else false) - } holds - - def incNum[T](w: Number) = { - require(w.valid && - // instantiate the lemma that implies zeroPreceedsLazy - (w.schedule match { - case Cons(h, _) => - zeroPredSufConcreteUntilLemma(w.digs, h) - case _ => - concreteZeroPredLemma(w.digs) - })) - val nq = inc(w.digs) - val nsched = nq match { - case Spine(Zero(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons(rear, w.schedule) // this is the only case where we create a new lazy closure - else - w.schedule - case _ => - w.schedule - } - val lq: $[NumStream] = nq - (lq, nsched) - } ensuring { res => - // lemma instantiations - (w.schedule match { - case Cons(head, tail) => - w.digs* match { - case Spine(h, _, _) => - if (h != Zero()) - incLazyLemma(w.digs, head) - else true - case _ => true - } - case _ => true - }) && - schedulesProperty(res._1, res._2) && - time <= 80 - } - - def Pay[T](q: $[NumStream], scheds: Scheds): Scheds = { - require(schedulesProperty(q, scheds) && q.isEvaluated) - scheds match { - case c @ Cons(head, rest) => - head.value match { - case Spine(Zero(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons(rear, rest) - else - rest - } - case Nil() => scheds - } - } ensuring { res => - { - val in = inState[NumStream] - val out = outState[NumStream] - // instantiations for proving the scheds property - (scheds match { - case Cons(head, rest) => - concUntilExtenLemma(q, head, in, out) && - (head* match { - case Spine(Zero(), _, rear) => - res match { - case Cons(rhead, rtail) => - schedMonotone(in, out, rtail, pushUntilCarry(rhead)) && - concUntilMonotone(rear, rhead, in, out) && - concUntilCompose(q, rear, rhead) - case _ => - concreteMonotone(in, out, rear) && - concUntilConcreteExten(q, rear) - } - }) - case _ => true - }) && - // instantiations for zeroPreceedsSuf property - (scheds match { - case Cons(head, rest) => - concreteUntilIsSuffix(q, head) && - (res match { - case Cons(rhead, rtail) => - concreteUntilIsSuffix(pushUntilCarry(head), rhead) && - suffixZeroLemma(q, head, rhead) && - zeroPreceedsSuf(q, rhead) - case _ => - true - }) - case _ => - true - }) - } && // properties - schedulesProperty(q, res) && - time <= 70 - } - - // monotonicity lemmas - def schedMonotone[T](st1: Set[$[NumStream]], st2: Set[$[NumStream]], scheds: Scheds, l: $[NumStream]): Boolean = { - require(st1.subsetOf(st2) && - (schedulesProperty(l, scheds) withState st1)) // here the input state is fixed as 'st1' - //induction scheme - (scheds match { - case Cons(head, tail) => - head* match { - case Spine(_, _, rear) => - concUntilMonotone(l, head, st1, st2) && - schedMonotone(st1, st2, tail, pushUntilCarry(head)) - case _ => true - } - case Nil() => - concreteMonotone(st1, st2, l) - }) && (schedulesProperty(l, scheds) withState st2) //property - } holds - - def concreteMonotone[T](st1: Set[$[NumStream]], st2: Set[$[NumStream]], l: $[NumStream]): Boolean = { - require((isConcrete(l) withState st1) && st1.subsetOf(st2)) - // induction scheme - (l* match { - case Spine(_, _, tail) => - concreteMonotone[T](st1, st2, tail) - case _ => - true - }) && (isConcrete(l) withState st2) - } holds - - def concUntilMonotone[T](q: $[NumStream], suf: $[NumStream], st1: Set[$[NumStream]], st2: Set[$[NumStream]]): Boolean = { - require((concreteUntil(q, suf) withState st1) && st1.subsetOf(st2)) - (if (q != suf) { - q* match { - case Spine(_, _, tail) => - concUntilMonotone(tail, suf, st1, st2) - case _ => - true - } - } else true) && - (concreteUntil(q, suf) withState st2) - } holds - - // suffix predicates and their properties (this should be generalizable) - - def suffix[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - if (q == suf) true - else { - q* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case Tip() => false - } - } - } - - def properSuffix[T](l: $[NumStream], suf: $[NumStream]): Boolean = { - l* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case _ => false - } - } ensuring (res => !res || (suffixDisequality(l, suf) && suf != l)) - - /** - * suf(q, suf) ==> suf(q.rear, suf.rear) - */ - def suffixTrans[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - require(suffix(q, suf)) - // induction scheme - (if (q == suf) true - else { - q* match { - case Spine(_, _, rear) => - suffixTrans(rear, suf) - case Tip() => true - } - }) && // property - ((q*, suf*) match { - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffix(rear, sufRear) - case _ => true - }) - }.holds - - /** - * properSuf(l, suf) ==> l != suf - */ - def suffixDisequality[T](l: $[NumStream], suf: $[NumStream]): Boolean = { - require(properSuffix(l, suf)) - suffixTrans(l, suf) && // lemma instantiation - ((l*, suf*) match { // induction scheme - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffixDisequality(rear, sufRear) - case _ => true - }) && l != suf // property - }.holds - - def suffixCompose[T](q: $[NumStream], suf1: $[NumStream], suf2: $[NumStream]): Boolean = { - require(suffix(q, suf1) && properSuffix(suf1, suf2)) - // induction over suffix(q, suf1) - (if (q == suf1) true - else { - q* match { - case Spine(_, _, rear) => - suffixCompose(rear, suf1, suf2) - case Tip() => false - } - }) && properSuffix(q, suf2) - } holds - - // properties of 'concUntil' - - def concreteUntilIsSuffix[T](l: $[NumStream], suf: $[NumStream]): Boolean = { - require(concreteUntil(l, suf)) - // induction scheme - (if (l != suf) { - (l* match { - case Spine(_, cws, tail) => - concreteUntilIsSuffix(tail, suf) - case _ => - true - }) - } else true) && suffix(l, suf) - }.holds - - // properties that extend `concUntil` to larger portions of the queue - - def concUntilExtenLemma[T](q: $[NumStream], suf: $[NumStream], st1: Set[$[NumStream]], st2: Set[$[NumStream]]): Boolean = { - require((concreteUntil(q, suf) withState st1) && st2 == st1 ++ Set(suf)) - // induction scheme - (if (q != suf) { - q* match { - case Spine(_, _, tail) => - concUntilExtenLemma(tail, suf, st1, st2) - case _ => - true - } - } else true) && - (suf* match { - case Spine(_, _, rear) => - concreteUntil(q, rear) withState st2 - case _ => true - }) - } holds - - def concUntilConcreteExten[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - require(concreteUntil(q, suf) && isConcrete(suf)) - (if (q != suf) { - q* match { - case Spine(_, _, tail) => - concUntilConcreteExten(tail, suf) - case _ => - true - } - } else true) && isConcrete(q) - } holds - - def concUntilCompose[T](q: $[NumStream], suf1: $[NumStream], suf2: $[NumStream]): Boolean = { - require(concreteUntil(q, suf1) && concreteUntil(suf1, suf2)) - (if (q != suf1) { - q* match { - case Spine(_, _, tail) => - concUntilCompose(tail, suf1, suf2) - case _ => - true - } - } else true) && - concreteUntil(q, suf2) - } holds - - // properties that relate `concUntil`, `concrete`, `zeroPreceedsSuf` with `zeroPreceedsLazy` - // - these are used in preconditions to derive the `zeroPreceedsLazy` property - - def zeroPredSufConcreteUntilLemma[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - require(concreteUntil(q, suf) && zeroPreceedsSuf(q, suf)) - // induction scheme - (if (q != suf) { - q* match { - case Spine(Zero(), _, _) => true - case Spine(_, _, tail) => - zeroPredSufConcreteUntilLemma(tail, suf) - case _ => - true - } - } else true) && - zeroPreceedsLazy(q) - } holds - - def concreteZeroPredLemma[T](q: $[NumStream]): Boolean = { - require(isConcrete(q)) - // induction scheme - (q* match { - case Spine(_, _, tail) => - concreteZeroPredLemma(tail) - case _ => - true - }) && - zeroPreceedsLazy(q) - } holds - - // properties relating `suffix` an `zeroPreceedsSuf` - - def suffixZeroLemma[T](q: $[NumStream], suf: $[NumStream], suf2: $[NumStream]): Boolean = { - require(suf* match { - case Spine(Zero(), _, _) => - suffix(q, suf) && properSuffix(suf, suf2) - case _ => false - }) - suffixCompose(q, suf, suf2) && ( - // induction scheme - if (q != suf) { - q* match { - case Spine(_, _, tail) => - suffixZeroLemma(tail, suf, suf2) - case _ => - true - } - } else true) && - zeroPreceedsSuf(q, suf2) // property - }.holds - - /** - * Pushing an element to the left of the queue preserves the data-structure invariants - */ - def incAndPay[T](w: Number) = { - require(w.valid) - - val (q, scheds) = incNum(w) - val nscheds = Pay(q, scheds) - Number(q, nscheds) - - } ensuring { res => - res.valid && - time <= 200 - } -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/RealTimeDeque.scala b/testcases/lazy-datastructures/ManualnOutdated/RealTimeDeque.scala deleted file mode 100644 index ff06c754a3f8fe99ec8ec115d36d270261610765..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/RealTimeDeque.scala +++ /dev/null @@ -1,363 +0,0 @@ -package outdated -import leon.lazyeval._ -import leon.lazyeval.$._ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.instrumentation._ -import leon.math._ - -//TODO: need to automatically check monotonicity of isConcrete -// requires `unfoldFactor=2` -/** - * Here, both front and rear streams are scheduled. - * We require both the front and the rear streams to be of almost equal - * size. If not, we lazily rotate the streams. - * The invariants are a lot more complex than in `RealTimeQueue`. - */ -object RealTimeDeque { - - /** - * A stream of values of type T - */ - sealed abstract class Stream[T] { - @inline - def isEmpty: Boolean = { - this match { - case SNil() => true - case _ => false - } - } - - @inline - def isCons: Boolean = { - this match { - case SCons(_, _) => true - case _ => false - } - } - - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + (t*).size - } - } ensuring (_ >= 0) - } - case class SCons[T](x: T, tail: $[Stream[T]]) extends Stream[T] - case class SNil[T]() extends Stream[T] - - @inline - def ssize[T](l: $[Stream[T]]): BigInt = (l*).size - - //@monotonic - def isConcrete[T](l: $[Stream[T]]): Boolean = { - l.isEvaluated && (l* match { - case SCons(_, tail) => - isConcrete(tail) - case _ => true - }) - } - - @invstate - def revAppend[T](l1: $[Stream[T]], l2: $[Stream[T]]): $[Stream[T]] = { - require(isConcrete(l1) && isConcrete(l2)) - l1.value match { - case SNil() => l2 - case SCons(x, tail) => - val nt: $[Stream[T]] = SCons[T](x, l2) - revAppend(tail, nt) - } - } ensuring(res => ssize(res) == ssize(l1) + ssize(l2) && - isConcrete(res) && - (ssize(l1) >= 1 ==> (res*).isCons) && - time <= 20*ssize(l1) + 20) - - @invstate - def drop[T](n: BigInt, l: $[Stream[T]]): $[Stream[T]] = { - require(n >= 0 && isConcrete(l) && ssize(l) >= n) - if (n == 0) { - l - } else { - l.value match { - case SNil() => l - case SCons(x, tail) => drop(n - 1, tail) - } - } - } ensuring(res => isConcrete(res) && - ssize(res) == ssize(l) - n && - time <= 20*n + 20) - - @invstate - def take[T](n: BigInt, l: $[Stream[T]]): $[Stream[T]] = { - require(n >= 0 && isConcrete(l) && ssize(l) >= n) - val r: $[Stream[T]] = - if (n == 0) { - SNil[T]() - } else { - l.value match { - case SNil() => l - case SCons(x, tail) => - SCons[T](x, take(n - 1, tail)) - } - } - r - } ensuring(res => isConcrete(res) && - ssize(res) == n && - time <= 30*n + 30) - - @invstate - def takeLazy[T](n: BigInt, l: $[Stream[T]]): Stream[T] = { - require(isConcrete(l) && n >= 1 && ssize(l) >= n) - l.value match { - case SCons(x, tail) => - if (n == 1) - SCons[T](x, SNil[T]()) - else - SCons[T](x, $(takeLazy(n - 1, tail))) - } - } ensuring(res => res.size == n && res.isCons && - time <= 20) - - // requires unfoldFactor=2 why ? - @invstate - def rotateRev[T](r: $[Stream[T]], f: $[Stream[T]], a: $[Stream[T]]): Stream[T] = { // doesn't change state - require(isConcrete(r) && isConcrete(f) && isConcrete(a) && - { - val lenf = ssize(f) - val lenr = ssize(r) - (lenf <= 2 * lenr + 3 && lenf >= 2 * lenr + 1) // size invariant betwen 'f' and 'r' - }) - r.value match { - case SNil() => revAppend(f, a).value // |f| <= 3 - case SCons(x, rt) => - SCons(x, $(rotateRev(rt, drop(2, f), revAppend(take(2, f), a)))) - } // here, it doesn't matter whether 'f' has i elements or not, what we want is |drop(2,f)| + |take(2,f)| == |f| - } ensuring (res => res.size == (r*).size + (f*).size + (a*).size && - res.isCons && - time <= 250) - - @invstate - def rotateDrop[T](r: $[Stream[T]], i: BigInt, f: $[Stream[T]]): Stream[T] = { - require(isConcrete(r) && isConcrete(f) && i >= 0 && { - val lenf = ssize(f) - val lenr = ssize(r) - (lenf >= 2 * lenr + 2 && lenf <= 2 * lenr + 3) && // size invariant between 'f' and 'r' - lenf > i - }) - - val rval = r.value - if(i < 2){ // || rval == SNil[T]()) { - val a: $[Stream[T]] = SNil[T]() - rotateRev(r, drop(i, f), a) - } else { - rval match { - case SCons(x, rt) => - SCons(x, $(rotateDrop(rt, i - 2, drop(2, f)))) - } - } - } ensuring(res => res.size == (r*).size + (f*).size - i && - res.isCons && - time <= 300) - - /** - * Returns the first element of the stream that is not evaluated. - */ - def firstUneval[T](l: $[Stream[T]]): $[Stream[T]] = { - if (l.isEvaluated) { - l* match { - case SCons(_, tail) => - firstUneval(tail) - case _ => l - } - } else - l - } ensuring (res => (!(res*).isEmpty || isConcrete(l)) && - ((res*).isEmpty || !res.isEvaluated) && // if the return value is not a Nil closure then it would not have been evaluated - (res.value match { - case SCons(_, tail) => - firstUneval(l) == firstUneval(tail) // after evaluating the firstUneval closure in 'l' we can access the next unevaluated closure - case _ => true - })) - - case class Queue[T](f: $[Stream[T]], lenf: BigInt, sf: $[Stream[T]], - r: $[Stream[T]], lenr: BigInt, sr: $[Stream[T]]) { - def isEmpty = lenf + lenr == 0 - def valid = { - (firstUneval(f) == firstUneval(sf)) && - (firstUneval(r) == firstUneval(sr)) && - (lenf == ssize(f) && lenr == ssize(r)) && - (lenf <= 2*lenr + 1 && lenr <= 2*lenf + 1) && - { - val mind = min(2*lenr-lenf+2, 2*lenf-lenr+2) - ssize(sf) <= mind && ssize(sr) <= mind - } - } - } - - /** - * A function that takes streams where the size of front and rear streams violate - * the balance invariant, and restores the balance. - */ - def createQueue[T](f: $[Stream[T]], lenf: BigInt, sf: $[Stream[T]], - r: $[Stream[T]], lenr: BigInt, sr: $[Stream[T]]): Queue[T] = { - require(firstUneval(f) == firstUneval(sf) && - firstUneval(r) == firstUneval(sr) && - (lenf == ssize(f) && lenr == ssize(r)) && - ((lenf - 1 <= 2*lenr + 1 && lenr <= 2*lenf + 1) || - (lenf <= 2*lenr + 1 && lenr - 2 <= 2*lenf + 1)) && - { - val mind = max(min(2*lenr-lenf+2, 2*lenf-lenr+2), 0) - ssize(sf) <= mind && ssize(sr) <= mind - }) - if(lenf > 2*lenr + 1) { - val i = (lenf + lenr) / 2 - val j = lenf + lenr - i - val nr = rotateDrop(r, i, f) - val nf = takeLazy(i, f) - Queue(nf, i, nf, nr, j, nr) - } else if(lenr > 2*lenf + 1) { - val i = (lenf + lenr) / 2 - val j = lenf + lenr - i - val nf = rotateDrop(f, j, r) // here, both 'r' and 'f' are concretized - val nr = takeLazy(j, r) - Queue(nf, i, nf, nr, j, nr) - } else - Queue(f, lenf, sf, r, lenr, sr) - } ensuring(res => res.valid && - time <= 400) - - /** - * Forces the schedules, and ensures that `firstUneval` equality is preserved - */ - def force[T](tar: $[Stream[T]], htar: $[Stream[T]], other: $[Stream[T]], hother: $[Stream[T]]): $[Stream[T]] = { - require(firstUneval(tar) == firstUneval(htar) && - firstUneval(other) == firstUneval(hother)) - tar.value match { - case SCons(_, tail) => tail - case _ => tar - } - } ensuring (res => { - //lemma instantiations - val in = $.inState[Stream[T]] - val out = $.outState[Stream[T]] - funeMonotone(tar, htar, in, out) && - funeMonotone(other, hother, in, out) && { - //properties - val rsize = ssize(res) - firstUneval(htar) == firstUneval(res) && // follows from post of fune - firstUneval(other) == firstUneval(hother) && - (rsize == 0 || rsize == ssize(tar) - 1) - } && time <= 350 - }) - - /** - * Forces the schedules in the queue twice and ensures the `firstUneval` property. - */ - def forceTwice[T](q: Queue[T]): ($[Stream[T]], $[Stream[T]]) = { - require(q.valid) - val nsf = force(force(q.sf, q.f, q.r, q.sr), q.f, q.r, q.sr) // forces q.sf twice - val nsr = force(force(q.sr, q.r, q.f, nsf), q.r, q.f, nsf) // forces q.sr twice - (nsf, nsr) - } - // the following properties are ensured, but need not be stated - /*ensuring (res => { - val nsf = res._1 - val nsr = res._2 - firstUneval(q.f) == firstUneval(nsf) && - firstUneval(q.r) == firstUneval(nsr) && - (ssize(nsf) == 0 || ssize(nsf) == ssize(q.sf) - 2) && - (ssize(nsr) == 0 || ssize(nsr) == ssize(q.sr) - 2) && - time <= 1500 - })*/ - - def empty[T] = { - val nil: $[Stream[T]] = SNil[T]() - Queue(nil, 0, nil, nil, 0, nil) - } - - /** - * Adding an element to the front of the list - */ - def cons[T](x: T, q: Queue[T]): Queue[T] = { - require(q.valid) - val nf: Stream[T] = SCons[T](x, q.f) - // force the front and rear scheds once - val nsf = force(q.sf, q.f, q.r, q.sr) - val nsr = force(q.sr, q.r, q.f, nsf) - createQueue(nf, q.lenf + 1, nsf, q.r, q.lenr, nsr) - } ensuring (res => res.valid && time <= 1200) - - /** - * Removing the element at the front, and returning the tail - */ - def tail[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.valid) - force(q.f, q.sf, q.r, q.sr) match { // force 'f' - case _ => - tailSub(q) - } - } ensuring(res => res.valid && time <= 3000) - - def tailSub[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.valid && q.f.isEvaluated) - q.f.value match { - case SCons(x, nf) => - val (nsf, nsr) = forceTwice(q) - // here, sf and sr got smaller by 2 holds, the schedule invariant still holds - createQueue(nf, q.lenf - 1, nsf, q.r, q.lenr, nsr) - case SNil() => - // in this case 'r' will have only one element by invariant - empty[T] - } - } ensuring(res => res.valid && time <= 2750) - - /** - * Reversing a list. Takes constant time. - * This implies that data structure is a `deque`. - */ - def reverse[T](q: Queue[T]): Queue[T] = { - require(q.valid) - Queue(q.r, q.lenr, q.sr, q.f, q.lenf, q.sf) - } ensuring(q.valid && time <= 10) - - // Properties of `firstUneval`. We use `fune` as a shorthand for `firstUneval` - /** - * st1.subsetOf(st2) ==> fune(l, st2) == fune(fune(l, st1), st2) - */ - def funeCompose[T](l1: $[Stream[T]], st1: Set[$[Stream[T]]], st2: Set[$[Stream[T]]]): Boolean = { - require(st1.subsetOf(st2)) - // induction scheme - (if (l1.isEvaluated withState st1) { - l1* match { - case SCons(_, tail) => - funeCompose(tail, st1, st2) - case _ => true - } - } else true) && - // property - (firstUneval(l1) withState st2) == (firstUneval(firstUneval(l1) withState st1) withState st2) - } holds - - /** - * st1.subsetOf(st2) && fune(la,st1) == fune(lb,st1) ==> fune(la,st2) == fune(lb,st2) - * The `fune` equality is preseved by evaluation of lazy closures. - * This is a kind of frame axiom for `fune` but is slightly different in that - * it doesn't require (st2 \ st1) to be disjoint from la and lb. - */ - def funeMonotone[T](l1: $[Stream[T]], l2: $[Stream[T]], st1: Set[$[Stream[T]]], st2: Set[$[Stream[T]]]): Boolean = { - require((firstUneval(l1) withState st1) == (firstUneval(l2) withState st1) && - st1.subsetOf(st2)) - funeCompose(l1, st1, st2) && // lemma instantiations - funeCompose(l2, st1, st2) && - // induction scheme - (if (l1.isEvaluated withState st1) { - l1* match { - case SCons(_, tail) => - funeMonotone(tail, l2, st1, st2) - case _ => true - } - } else true) && - (firstUneval(l1) withState st2) == (firstUneval(l2) withState st2) // property - } holds -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/RealTimeQueue-transformed.scala b/testcases/lazy-datastructures/ManualnOutdated/RealTimeQueue-transformed.scala deleted file mode 100644 index 7eb26b58071e2acdab089fe919ec3f5cfdf36a17..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/RealTimeQueue-transformed.scala +++ /dev/null @@ -1,282 +0,0 @@ -package leon -import lang._ -import annotation._ -import collection._ - -object RealTimeQueue { - abstract class LList[T] - - def LList$isEmpty[T]($this: LList[T]): Boolean = { - $this match { - case SNil() => - true - case _ => - false - } - } - - def LList$isCons[T]($this: LList[T]): Boolean = { - $this match { - case SCons(_, _) => - true - case _ => - false - } - } - - def LList$size[T]($this: LList[T]): BigInt = { - $this match { - case SNil() => - BigInt(0) - case SCons(x, t) => - BigInt(1) + ssize[T](t) - } - } ensuring { - (x$1: BigInt) => (x$1 >= BigInt(0)) - } - - case class SCons[T](x: T, tail: LazyLList[T]) extends LList[T] - - case class SNil[T]() extends LList[T] - - // TODO: closures are not ADTs since two closures with same arguments are not necessarily equal but - // ADTs are equal. This creates a bit of problem in checking if a closure belongs to a set or not. - // However, currently we are assuming that such problems do not happen. - // A solution is to pass around a dummy id that is unique for each closure. - abstract class LazyLList[T] - - case class Rotate[T](f: LazyLList[T], r: List[T], a: LazyLList[T], res: LList[T]) extends LazyLList[T] - - case class Lazyarg[T](newa: LList[T]) extends LazyLList[T] - - def ssize[T](l: LazyLList[T]): BigInt = { - val clist = evalLazyLList[T](l, Set[LazyLList[T]]())._1 - LList$size[T](clist) - - } ensuring (res => res >= 0) - - def isConcrete[T](l: LazyLList[T], st: Set[LazyLList[T]]): Boolean = { - Set[LazyLList[T]](l).subsetOf(st) && (evalLazyLList[T](l, st)._1 match { - case SCons(_, tail) => - isConcrete[T](tail, st) - case _ => - true - }) || LList$isEmpty[T](evalLazyLList[T](l, st)._1) - } - - // an assertion: closures created by evaluating a closure will result in unevaluated closure - @library - def lemmaLazy[T](l: LazyLList[T], st: Set[LazyLList[T]]): Boolean = { - Set[LazyLList[T]](l).subsetOf(st) || { - evalLazyLList[T](l, Set[LazyLList[T]]())._1 match { - case SCons(_, tail) => - l != tail && !Set[LazyLList[T]](tail).subsetOf(st) - case _ => true - } - } - } holds - - def firstUnevaluated[T](l: LazyLList[T], st: Set[LazyLList[T]]): LazyLList[T] = { - if (Set[LazyLList[T]](l).subsetOf(st)) { - evalLazyLList[T](l, st)._1 match { - case SCons(_, tail) => - firstUnevaluated[T](tail, st) - case _ => - l - } - } else { - l - } - } ensuring (res => (!LList$isEmpty[T](evalLazyLList[T](res, st)._1) || isConcrete[T](l, st)) && - (LList$isEmpty[T](evalLazyLList[T](res, st)._1) || !Set[LazyLList[T]](res).subsetOf(st)) && - { - val (nval, nst, _) = evalLazyLList[T](res, st) - nval match { - case SCons(_, tail) => - firstUnevaluated(l, nst) == tail - case _ => true - } - } && - lemmaLazy(res, st)) - - @library - def evalLazyLList[T](cl: LazyLList[T], st: Set[LazyLList[T]]): (LList[T], Set[LazyLList[T]], BigInt) = { - cl match { - case t: Rotate[T] => - val (rres, _, rtime) = rotate(t.f, t.r, t.a, st) - val tset = Set[LazyLList[T]](t) - val tme = - if (tset.subsetOf(st)) - BigInt(1) - else // time of rotate - rtime - (rotate(t.f, t.r, t.a, Set[LazyLList[T]]())._1, st ++ tset, tme) - - case t: Lazyarg[T] => - (lazyarg(t.newa), st ++ Set[LazyLList[T]](t), BigInt(1)) - } - } ensuring (res => (cl match { - case t: Rotate[T] => - LList$size(res._1) == ssize(t.f) + t.r.size + ssize(t.a) && - res._1 != SNil[T]() && - res._3 <= 4 - case _ => true - }) // && - // (res._1 match { - // case SCons(_, tail) => - // Set[LazyLList[T]](cl).subsetOf(st) || !Set[LazyLList[T]](tail).subsetOf(res._2) - // case _ => true - // }) - ) - - @extern - def rotate2[T](f: LazyLList[T], r: List[T], a: LazyLList[T], st: Set[LazyLList[T]]): (LList[T], Set[LazyLList[T]], BigInt) = ??? - - def lazyarg[T](newa: LList[T]): LList[T] = { - newa - } - - def streamScheduleProperty[T](s: LazyLList[T], sch: LazyLList[T], st: Set[LazyLList[T]]): Boolean = { - firstUnevaluated[T](s, st) == sch - } - - case class Queue[T](f: LazyLList[T], r: List[T], s: LazyLList[T]) - - def Queue$isEmpty[T]($this: Queue[T], st: Set[LazyLList[T]]): Boolean = { - LList$isEmpty[T](evalLazyLList[T]($this.f, st)._1) - } - - def Queue$valid[T]($this: Queue[T], st: Set[LazyLList[T]]): Boolean = { - streamScheduleProperty[T]($this.f, $this.s, st) && - ssize[T]($this.s) == ssize[T]($this.f) - $this.r.size - } - - // things to prove: - // (a0) prove that pre implies post for 'rotate' (this depends on the assumption on eval) - // (a) Rotate closure creations satisfy the preconditions of 'rotate' (or) - // for the preconditions involving state, the state at the Rotate invocation sites (through eval) - // satisfy the preconditions of 'rotate' - // (b) If we verify that preconditoins involving state hold at creation time, - // then we can assume them for calling time only if the preconditions are monotonic - // with respect to inclusion of relation of state (this also have to be shown) - // Note: using both captured and calling context is possible but is more involved - // (c) Assume that 'eval' ensures the postcondition of 'rotate' - // (d) Moreover we can also assume that the preconditons of rotate hold whenever we use a closure - - // proof of (a) - // (i) for stateless invariants this can be proven by treating lazy eager, - // so not doing this here - - // monotonicity of isConcrete - def lemmaConcreteMonotone[T](f: LazyLList[T], st1: Set[LazyLList[T]], st2: Set[LazyLList[T]]): Boolean = { - (evalLazyLList[T](f, st1)._1 match { - case SCons(_, tail) => - lemmaConcreteMonotone(tail, st1, st2) - case _ => - true - }) && - !(st1.subsetOf(st2) && isConcrete(f, st1)) || isConcrete(f, st2) - } holds - - // proof that the precondition isConcrete(f, st) holds for closure creation in 'rotate' function - def rotateClosureLemma1[T](f: LazyLList[T], st: Set[LazyLList[T]]): Boolean = { - require(isConcrete(f, st)) - val dres = evalLazyLList[T](f, st); - dres._1 match { - case SCons(x, tail) => - isConcrete(tail, st) - case _ => true - } - } holds - - // proof that the precondition isConcrete(f, st) holds for closure creation in 'createQueue' function - // @ important use and instantiate monotonicity of - def rotateClosureLemma2[T](f: LazyLList[T], sch: LazyLList[T], st: Set[LazyLList[T]]): Boolean = { - require(streamScheduleProperty[T](f, sch, st)) // && ssize[T](sch) == (ssize[T](f) - r.size) + BigInt(1)) - val dres4 = evalLazyLList[T](sch, st); - dres4._1 match { - case SNil() => - //isConcrete(f, dres4._2) - isConcrete(f, st) // the above is implied by the monotonicity of 'isConcrete' - case _ => true - } - } holds - - // proof that the precondition isConcrete(f, st) holds for closure creation in 'dequeue' function - def rotateClosureLemma3[T](q: Queue[T], st: Set[LazyLList[T]]): Boolean = { - require(!Queue$isEmpty[T](q, st) && Queue$valid[T](q, st)) - val dres7 = evalLazyLList[T](q.f, st); - val SCons(x, nf) = dres7._1 - val dres8 = evalLazyLList[T](q.s, dres7._2); - dres8._1 match { - case SNil() => - isConcrete(nf, st) - // the above would imply: isConcrete(nf, dres8._2) by monotonicity - case _ => true - } - } holds - - // part(c) assume postconditon of 'rotate' in closure invocation time and also - // the preconditions of 'rotate' if necesssary, and prove the properties of the - // methods that invoke closures - - // proving specifications of 'rotate' (only state specifications are interesting) - def rotate[T](f: LazyLList[T], r: List[T], a: LazyLList[T], st: Set[LazyLList[T]]): (LList[T], Set[LazyLList[T]], BigInt) = { - require(r.size == ssize[T](f) + BigInt(1) && isConcrete(f, st)) - val dres = evalLazyLList[T](f, st); - (dres._1, r) match { - case (SNil(), Cons(y, _)) => - (SCons[T](y, a), dres._2, dres._3 + 2) - case (SCons(x, tail), Cons(y, r1)) => - val na = Lazyarg[T](SCons[T](y, a)) - (SCons[T](x, Rotate[T](tail, r1, na, SNil[T]())), dres._2, dres._3 + 3) - } - } ensuring (res => LList$size(res._1) == ssize(f) + r.size + ssize(a) && - res._1 != SNil[T]() && - res._3 <= 4) - - // a stub for creating new closure (ensures that the new closures do not belong to the old state) - // Note: this could result in inconsistency since we are associating unique ids with closures - @library - def newclosure[T](rt: Rotate[T], st: Set[LazyLList[T]]) = { - (rt, st) - } ensuring (res => !Set[LazyLList[T]](res._1).subsetOf(st)) - - // proving specifications of 'createQueue' (only state specifications are interesting) - def createQueue[T](f: LazyLList[T], r: List[T], sch: LazyLList[T], st: Set[LazyLList[T]]): (Queue[T], Set[LazyLList[T]], BigInt) = { - require(streamScheduleProperty[T](f, sch, st) && - ssize[T](sch) == (ssize[T](f) - r.size) + BigInt(1)) - val dres4 = evalLazyLList[T](sch, st); - dres4._1 match { - case SCons(_, tail) => - (Queue[T](f, r, tail), dres4._2, dres4._3 + 2) - case SNil() => - val rotres1 = newclosure(Rotate[T](f, r, Lazyarg[T](SNil[T]()), SNil[T]()), dres4._2); // can also directly call rotate here - (Queue[T](rotres1._1, List[T](), rotres1._1), dres4._2, dres4._3 + 3) - } - } ensuring (res => Queue$valid[T](res._1, res._2) && - res._3 <= 7) - - // proving specifications of 'enqueue' - def enqueue[T](x: T, q: Queue[T], st: Set[LazyLList[T]]): (Queue[T], Set[LazyLList[T]], BigInt) = { - require(Queue$valid[T](q, st)) - createQueue[T](q.f, Cons[T](x, q.r), q.s, st) - } ensuring (res => Queue$valid[T](res._1, res._2) && - res._3 <= 7) - - // proving specifications of 'dequeue' - def dequeue[T](q: Queue[T], st: Set[LazyLList[T]]): (Queue[T], Set[LazyLList[T]], BigInt) = { - require(!Queue$isEmpty[T](q, st) && Queue$valid[T](q, st)) - val dres7 = evalLazyLList[T](q.f, st); - val SCons(x, nf) = dres7._1 - val dres8 = evalLazyLList[T](q.s, dres7._2); - dres8._1 match { - case SCons(_, nsch) => - (Queue[T](nf, q.r, nsch), dres8._2, dres7._3 + dres8._3 + 3) - case _ => - val rotres3 = newclosure(Rotate[T](nf, q.r, Lazyarg[T](SNil[T]()), SNil[T]()), dres8._2); - (Queue[T](rotres3._1, List[T](), rotres3._1), dres8._2, dres7._3 + dres8._3 + 4) - } - } ensuring (res => Queue$valid[T](res._1, res._2) && - res._3 <= 12) -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/Sorting.scala b/testcases/lazy-datastructures/ManualnOutdated/Sorting.scala deleted file mode 100644 index ad1712e2c72230b89176efb9e4d16533e7f08476..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/Sorting.scala +++ /dev/null @@ -1,82 +0,0 @@ -package lazybenchmarks -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -//import leon.invariant._ - -object Sorting { - - // TODO: making this parametric will break many things. Fix them (note: we need each instantiation to be a unique closure) - sealed abstract class LList { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + ssize(t) - } - } ensuring (_ >= 0) - } - case class SCons(x: BigInt, tail: $[LList]) extends LList - case class SNil() extends LList - def ssize(l: $[LList]): BigInt = (l*).size - - sealed abstract class List { - def size: BigInt = this match { - case Cons(_, xs) => 1 + xs.size - case _ => BigInt(0) - } - } - case class Cons(x: BigInt, tail: List) extends List - case class Nil() extends List - - def pullMin(l: List): List = { - l match { - case Nil() => l - case Cons(x, xs) => - pullMin(xs) match { - case Nil() => Cons(x, Nil()) - case nxs @ Cons(y, ys) => - if (x <= y) Cons(x, nxs) - else Cons(y, Cons(x, ys)) - } - } - } ensuring (res => res.size == l.size && time <= 15 * l.size + 2) - - def sort(l: List): LList = { - pullMin(l) match { - case Cons(x, xs) => - // here, x is the minimum - SCons(x, $(sort(xs))) // sorts lazily only if needed - case _ => - SNil() - } - } ensuring (res => res.size == l.size && time <= 15 * l.size + 10) - - /* This is also an interesting benchmark. - * as it uses laziness internally that is - * not visible outside - * - * def secondMin(l: List) : BigInt = { - sort(l) match { - case SCons(x, xs) => - xs.value match { - case SCons(y, ys) => y - case SNil() => x - } - case SNil() => BigInt(0) - } - } ensuring (_ => time <= 30 * l.size + 40)*/ - - // Can be proved usign orb - def kthMin(l: $[LList], k: BigInt): BigInt = { - require(k >= 1) - l.value match { - case SCons(x, xs) => - if (k == 1) x - else - kthMin(xs, k - 1) - case SNil() => BigInt(0) - } - } ensuring (_ => time <= 60 * (k * ssize(l)) + ssize(l) + k + 37) - -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/TestArray.scala b/testcases/lazy-datastructures/ManualnOutdated/TestArray.scala deleted file mode 100644 index 61d729a5e02e1455164ad127721a8646a80c5f69..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/TestArray.scala +++ /dev/null @@ -1,49 +0,0 @@ -package ManualnOutdated - -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import scala.math.BigInt.int2bigInt -//import leon.invariant._ - -object TestArray { - - sealed abstract class LList { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + ssize(t) - } - } ensuring (_ >= 0) - } - case class SCons(x: BigInt, tail: $[LList]) extends LList - case class SNil() extends LList - def ssize(l: $[LList]): BigInt = (l*).size - - sealed abstract class List { - def size: BigInt = this match { - case Cons(_, xs) => 1 + xs.size - case _ => BigInt(0) - } - } - case class Cons(x: BigInt, tail: List) extends List - case class Nil() extends List - - def concat(l1: List, l2: LList) : LList = { - l1 match { - case Cons(x, xs) => SCons(x, $(concat(xs, l2))) - case Nil() => SNil() - } - } ensuring(res => time <= 15) - - @ignore - var arr = Array[BigInt]() - - @extern - def arrayFun(l1: List, l2: LList, i: BigInt): BigInt = { - //require(i >= 0) - //Array(concat(l1, l2)) - arr(i.toInt) - } -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/TestGenerics.scala b/testcases/lazy-datastructures/ManualnOutdated/TestGenerics.scala deleted file mode 100644 index 4a5971e296dd72a7fda878b71ac84ff6597557bb..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/TestGenerics.scala +++ /dev/null @@ -1,29 +0,0 @@ -package ManualnOutdated - -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.invariant._ -//import leon.invariant._ - -object TestGenerics { - - sealed abstract class List[T] { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + t.size - } - } ensuring (_ >= 0) - } - case class SCons[T](x: T, tail: List[T]) extends List[T] - case class SNil[T]() extends List[T] - - def concat[T](l1: List[T], l2: List[T]) : List[T] = { - l1 match { - case SCons(x, xs) => SCons(x, concat(xs, l2)) - case SNil() => SNil[T]() - } - } ensuring(res => time <= ? * l1.size + ?) -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/TestSets.scala b/testcases/lazy-datastructures/ManualnOutdated/TestSets.scala deleted file mode 100644 index f4a34ee33f13da911b07534063236abbd84a9516..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/TestSets.scala +++ /dev/null @@ -1,29 +0,0 @@ -package ManualnOutdated - -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.invariant._ -//import leon.invariant._ - -object TestSets { - - sealed abstract class List[T] { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + t.size - } - } ensuring (_ >= 0) - } - case class SCons[T](x: T, tail: List[T]) extends List[T] - case class SNil[T]() extends List[T] - - def concat[T](l1: List[T], l2: List[T], st: Set[T]) : List[T] = { - l1 match { - case SCons(x, xs) => SCons(x, concat(xs, l2, st ++ Set[T](x))) - case SNil() => SNil[T]() - } - } ensuring(res => time <= ? * l1.size + ?) -} diff --git a/testcases/lazy-datastructures/ManualnOutdated/WeightedScheduling-strategy2.scala b/testcases/lazy-datastructures/ManualnOutdated/WeightedScheduling-strategy2.scala deleted file mode 100644 index 198c3988e1e023e3d95fe9bd98ab25bf5fb19e41..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/ManualnOutdated/WeightedScheduling-strategy2.scala +++ /dev/null @@ -1,135 +0,0 @@ -import leon.lazyeval._ -import leon.lazyeval.Mem._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -//import leon.invariant._ - -object WeightedSched { - sealed abstract class IList { - def size: BigInt = { - this match { - case Cons(_, tail) => 1 + tail.size - case Nil() => BigInt(0) - } - } ensuring(_ >= 0) - } - case class Cons(x: BigInt, tail: IList) extends IList // a list of pairs of start, finish and weights - case class Nil() extends IList - - /*sealed abstract class LList { - def size: BigInt = { - this match { - case LCons(_, _, tail) => 1 + tail.size - case LNil() => BigInt(0) - } - } ensuring(_ >= 0) - } - case class LCons(l: IList, pl: LList, tail: LList) extends LList // a list of pointers into IList, and LList - case class LNil() extends LList*/ - - /** - * array of jobs - * (a) each job has a start time, finish time, and weight - * (b) Jobs are sorted in ascending order of finish times - */ - @ignore - var jobs = Array[(BigInt, BigInt, BigInt)]() - - /** - * A precomputed mapping from each job i to the previous job j it is compatible with. - */ - @ignore - var p = Array[BigInt]() - - @extern - def jobInfo(i: BigInt) = { - jobs(i.toInt) - } ensuring(_ => time <= 1) - - @extern - def prevCompatibleJob(i: BigInt): BigInt = { - //require(i >= 1) - p(i.toInt) - } ensuring(res => res >=0 && res < i && time <= 1) - -// @library -// def prevCompatLem(i: BigInt) : Boolean ={ -// require(i >= 1) -// val r = prevCompatibleJob(i) -// r >= 0 && r < i -// } holds - - @inline - def max(x: BigInt, y: BigInt) = if (x >= y) x else y - - def depsEval(i: BigInt) = i == 0 || (i > 0 && allEval(i-1)) - - def allEval(i: BigInt): Boolean = { - require(i >= 0) - sched(i).isCached && - (if (i == 0) true - else allEval(i - 1)) - } - - @traceInduct - def evalMono(i: BigInt, st1: Set[Mem[BigInt]], st2: Set[Mem[BigInt]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (allEval(i) withState st1)) ==> (allEval(i) withState st2) - } holds - - @traceInduct - def evalLem(x: BigInt, y: BigInt) = { - require(x >= 0 && y >= 0) - (x <= y && allEval(y)) ==> allEval(x) - } holds - - /** - * (a) assuming that jobs are sorted in descending order of the finish times - * (b) 'prev' - - */ - @invstate - @memoize - def sched(jobIndex: BigInt): BigInt = { - require(depsEval(jobIndex) && - (jobIndex == 0 || evalLem(prevCompatibleJob(jobIndex), jobIndex-1))) - val (st, fn, w) = jobInfo(jobIndex) - if(jobIndex == 0) w - else { - // we may either include the head job or not: - // if we include the head job, we have to skip every job that overlaps with it - val tailValue = sched(jobIndex - 1) - val prevCompatVal = sched(prevCompatibleJob(jobIndex)) - max(w + prevCompatVal, tailValue) - } - } ensuring(_ => time <= 100) -// } ensuring(res => { -// val in = Mem.inState[BigInt] -// val out = Mem.outState[BigInt] -// (( withState in) ==> (in == out)) //&& -// (jobIndex == 0 || evalMono(jobIndex-1, out, out ++ Set(Mem(sched(jobIndex)))) && -//// allEval(jobIndex-1)) -// //evalMono(tail, out, out ++ Set(Mem(optValOfSched(jobs)))) // lemma instantiation -// }) - - def invoke(jobIndex: BigInt) = { - require(depsEval(jobIndex)) - sched(jobIndex) - } ensuring (res => { - val in = Mem.inState[BigInt] - val out = Mem.outState[BigInt] - (jobIndex == 0 || evalMono(jobIndex-1, in, out)) && - time <= 150 - }) - - def schedBU(jobi: BigInt): IList = { - require(jobi >= 0) - if(jobi == 0) { - Cons(invoke(jobi), Nil()) - } else { - val tailRes = schedBU(jobi-1) - Cons(invoke(jobi), tailRes) - } - } ensuring(_ => allEval(jobi) && - time <= 200 * (jobi + 1)) -} diff --git a/testcases/lazy-datastructures/Unproved/ImplicitQueue.scala b/testcases/lazy-datastructures/Unproved/ImplicitQueue.scala deleted file mode 100644 index 61f6302a14b970ba5a29de9786619528ebc33540..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/Unproved/ImplicitQueue.scala +++ /dev/null @@ -1,147 +0,0 @@ -import leon.lazyeval._ -import leon.lazyeval.$._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import scala.math.BigInt.int2bigInt - -/** - * This is an version of the implicit recursive slowdwon queues of - * Okasaki. Here, snoc (enqueue) and tail (dequeue) have constant - * amortized time. But, accessing the ith element has linear time. - * Achieving logarithmic time for ith element is independent of lazy - * evaluation. We only need to change `Data` to a list instead of a single element, - * and add invariants on exponential increase in the size of the Data relative to the - * depth. - */ -object ImplicitQueue { - - // here Data is bascially a tree with elements stored only at the leaves - sealed abstract class Data[T] { - def size: BigInt = { - this match { - case Leaf(_) => BigInt(1) - case Node(l, r) => l.size + r.size - } - } ensuring (_ >= 1) - } - case class Node[T](l: Data[T], r: Data[T]) extends Data[T] - case class Leaf[T](x: T) extends Data[T] - - sealed abstract class ZeroOne[T] { - def level: BigInt = { - this match { - case Zero() => BigInt(0) - case One(x) => x.size - } - } - } - case class Zero[T]() extends ZeroOne[T] - case class One[T](d: Data[T]) extends ZeroOne[T] - - sealed abstract class OneTwo[T] { - def level: BigInt = { - this match { - case OneF(x) => x.size - case Two(x, y) => x.size - } - } - - def correct: Boolean = { - this match { - case OneF(_) => true - case Two(x, y) => x.size == y.size - } - } - } - case class OneF[T](d: Data[T]) extends OneTwo[T] - case class Two[T](x: Data[T], y: Data[T]) extends OneTwo[T] - - sealed abstract class Queue[T] { - def isEmpty: Boolean = { - this match { - case Shallow(Zero()) => true - case _ => false - } - } - - def level: BigInt = { - this match { - case Shallow(d) => d.level - case Deep(f, _, _) => f.level - } - } - - // queue invariants - // level of mid is one greater than the level of this - def correct: Boolean = { // a property about the content - this match { - case Shallow(_) => true - case Deep(f, m, r) => - val mq = (m*) - f.correct && (mq.level > this.level) && mq.correct - } - } - - // a property about the state - @invstate - def valid: Boolean = { - this match { - case Shallow(_) => true - case Deep(f, m, r) => - m.isEvaluated && (m*).valid - } - } - - } - case class Shallow[T](e: ZeroOne[T]) extends Queue[T] - case class Deep[T](f: OneTwo[T], m: $[Queue[T]], r: ZeroOne[T]) extends Queue[T] - - def head[T](q: Queue[T]): Data[T] = { - require(q.correct && !q.isEmpty) - q match { -// /case Shallow(Zero()) => DNone() - case Shallow(One(x)) => x - case Deep(Two(x, _), _, _) => x - case Deep(OneF(x), _, _) => x - } - } - - def tail[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.correct) - val r: Queue[T] = (q match { - case Shallow(One(x)) => - Shallow(Zero()) - case Deep(Two(x, y), m, r) => - Deep(OneF(y), m, r) - case Deep(OneF(x), m, r) => - m.value match { - case Shallow(Zero()) => // m is empty - Shallow(r) - case mq => - head(mq) match { - case Node(x, y) => - Deep(Two(x, y), $(tail(mq)), r) - //every other case is not allowed by the data structure invariants - } - } - }) - r - } - - /** - * Properties of `valid` - */ - def validMonotone[T](q: Queue[T], st1: Set[$[Queue[T]]], st2: Set[$[Queue[T]]]): Boolean = { - require((q.valid withState st1) && st1.subsetOf(st2)) - // induction scheme - (q match { - case Shallow(_) => true - case Deep(f, m, r) => - validMonotone(m*, st1, st2) - }) && - //property - (q.valid withState st2) - } holds - -} diff --git a/testcases/lazy-datastructures/build.sbt b/testcases/lazy-datastructures/build.sbt deleted file mode 100644 index ff26464c904443455179389615dcd4d5963986fb..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/build.sbt +++ /dev/null @@ -1,15 +0,0 @@ -name := "LazyDataStructures" - -version := "1.0" - -organization := "ch.epfl.lara" - -scalaVersion := "2.11.7" - -fork in run := true - -javaOptions in run ++= Seq("-Xmx5G", "-Xms3G", "-Xss500M") - -scalacOptions ++= Seq("-optimise") - -unmanagedSourceDirectories in Compile ++= Seq("withOrb", "eager").map(dir => baseDirectory.value / dir) diff --git a/testcases/lazy-datastructures/conc/ConcTrees.scala b/testcases/lazy-datastructures/conc/ConcTrees.scala deleted file mode 100644 index c8b007f14b60787c5212728443a80627e932207b..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/conc/ConcTrees.scala +++ /dev/null @@ -1,345 +0,0 @@ -package conctrees - -import leon.instrumentation._ -import leon.collection._ -import leon.lang._ -import ListSpecs._ -import leon.annotation._ -import leon.invariant._ - -/** - * For better performance use --disableInfer on this benchmark - */ -object ConcTrees { - - @inline - def max(x: BigInt, y: BigInt): BigInt = if (x >= y) x else y - def abs(x: BigInt): BigInt = if (x < 0) -x else x - - sealed abstract class Conc[T] { - - def isEmpty: Boolean = { - this == Empty[T]() - } - - def isLeaf: Boolean = { - this match { - case Empty() => true - case Single(_) => true - case _ => false - } - } - - @inline - def valid: Boolean = { - concInv && balanced - } - - /** - * (a) left and right trees of conc node should be non-empty - * (b) they cannot be append nodes - */ - def concInv: Boolean = this match { - case CC(l, r) => - !l.isEmpty && !r.isEmpty && - l.concInv && r.concInv - case _ => true - } - - def balanced: Boolean = { - this match { - case CC(l, r) => - l.level - r.level >= -1 && l.level - r.level <= 1 && - l.balanced && r.balanced - case _ => true - } - } - - val level: BigInt = { - (this match { - case Empty() => 0 - case Single(x) => 0 - case CC(l, r) => - 1 + max(l.level, r.level) - }): BigInt - } ensuring (_ >= 0) - - val size: BigInt = { - (this match { - case Empty() => 0 - case Single(x) => 1 - case CC(l, r) => - l.size + r.size - }): BigInt - } ensuring (_ >= 0) - - @invisibleBody - def toList: List[T] = { - this match { - case Empty() => Nil[T]() - case Single(x) => Cons(x, Nil[T]()) - case CC(l, r) => - l.toList ++ r.toList // note: left elements precede the right elements in the list - } - } ensuring (res => res.size == this.size) - } - - case class Empty[T]() extends Conc[T] - case class Single[T](x: T) extends Conc[T] - case class CC[T](left: Conc[T], right: Conc[T]) extends Conc[T] - - /*class Chunk(val array: Array[T], val size: Int, val k: Int) extends Leaf[T] { - def level = 0 - override def toString = s"Chunk(${array.mkString("", ", ", "")}; $size; $k)" - }*/ - - @invisibleBody - def lookup[T](xs: Conc[T], i: BigInt): T = { - require(xs.valid && !xs.isEmpty && i >= 0 && i < xs.size) - xs match { - case Single(x) => x - case CC(l, r) => - if (i < l.size) lookup(l, i) - else lookup(r, i - l.size) - } - } ensuring (res => - // axiom instantiation - instAppendIndexAxiom(xs, i) && - res == xs.toList(i) && // correctness - time <= ? * xs.level + ?) // lookup time is linear in the height - - @invisibleBody - def instAppendIndexAxiom[T](xs: Conc[T], i: BigInt): Boolean = { - require(0 <= i && i < xs.size) - xs match { - case CC(l, r) => - appendIndex(l.toList, r.toList, i) - case _ => true - } - }.holds - - @invisibleBody - def update[T](xs: Conc[T], i: BigInt, y: T): Conc[T] = { - require(xs.valid && !xs.isEmpty && i >= 0 && i < xs.size) - xs match { - case Single(x) => Single(y) - case CC(l, r) => - if (i < l.size) CC(update(l, i, y), r) - else CC(l, update(r, i - l.size, y)) - } - } ensuring (res => instAppendUpdateAxiom(xs, i, y) && // an auxiliary axiom instantiation - res.level == xs.level && // heights of the input and output trees are equal - res.valid && // tree invariants are preserved - res.toList == xs.toList.updated(i, y) && // correctness - time <= ? * xs.level + ?) // update time is linear in the height of the tree - - @invisibleBody - def instAppendUpdateAxiom[T](xs: Conc[T], i: BigInt, y: T): Boolean = { - require(i >= 0 && i < xs.size) - xs match { - case CC(l, r) => - appendUpdate(l.toList, r.toList, i, y) - case _ => true - } - }.holds - - /** - * A generic concat that applies to general concTrees - */ - // @invisibleBody - // def concat[T](xs: Conc[T], ys: Conc[T]): Conc[T] = { - // require(xs.valid && ys.valid) - // concatNormalized(normalize(xs), normalize(ys)) - // } - - @invisibleBody - def concatNonEmpty[T](xs: Conc[T], ys: Conc[T]): Conc[T] = { - require(xs.valid && ys.valid && !xs.isEmpty && !ys.isEmpty) - val diff = ys.level - xs.level - if (diff >= -1 && diff <= 1) CC(xs, ys) - else if (diff < -1) { // ys is smaller than xs - xs match { - case CC(l, r) if (l.level >= r.level) => - CC(l, concatNonEmpty(r, ys)) - case CC(l, r) => - r match { - case CC(rl, rr) => - val nrr = concatNonEmpty(rr, ys) - if (nrr.level == xs.level - 3) - CC(l, CC(rl, nrr)) - else - CC(CC(l, rl), nrr) - } - } - } else ys match { - case CC(l, r) if (r.level >= l.level) => - CC(concatNonEmpty(xs, l), r) - case CC(l, r) => - l match { - case CC(ll, lr) => - val nll = concatNonEmpty(xs, ll) - if (nll.level == ys.level - 3) - CC(CC(nll, lr), r) - else - CC(nll, CC(lr, r)) - } - } - } ensuring (res => - res.level <= max(xs.level, ys.level) + 1 && // height invariants - res.level >= max(xs.level, ys.level) && - res.valid && - appendAssocInst(xs, ys) && // instantiation of an axiom - concatCorrectness(res, xs, ys) && // correctness - time <= ? * abs(xs.level - ys.level) + ?) // time bounds - - @invisibleBody - def appendAssocInst[T](xs: Conc[T], ys: Conc[T]): Boolean = { - (xs match { - case CC(l, r) => - appendAssoc(l.toList, r.toList, ys.toList) && //instantiation of associativity of concatenation - (r match { - case CC(rl, rr) => - appendAssoc(rl.toList, rr.toList, ys.toList) && - appendAssoc(l.toList, rl.toList, rr.toList ++ ys.toList) - case _ => true - }) - case _ => true - }) && - (ys match { - case CC(l, r) => - appendAssoc(xs.toList, l.toList, r.toList) && - (l match { - case CC(ll, lr) => - appendAssoc(xs.toList, ll.toList, lr.toList) && - appendAssoc(xs.toList ++ ll.toList, lr.toList, r.toList) - case _ => true - }) - case _ => true - }) - }.holds - - /** - * This concat applies only to normalized trees. - * This prevents concat from being recursive - */ - @invisibleBody - def concatNormalized[T](xs: Conc[T], ys: Conc[T]): Conc[T] = { - require(xs.valid && ys.valid) - (xs, ys) match { - case (xs, Empty()) => xs - case (Empty(), ys) => ys - case _ => concatNonEmpty(xs, ys) - } - } ensuring (res => res.valid && // tree invariants - res.level <= max(xs.level, ys.level) + 1 && // height invariants - res.level >= max(xs.level, ys.level) && - concatCorrectness(res, xs, ys) && // correctness - time <= ? * abs(xs.level - ys.level) + ?) - - @invisibleBody - def concatCorrectness[T](res: Conc[T], xs: Conc[T], ys: Conc[T]): Boolean = - (res.toList == xs.toList ++ ys.toList) - - @invisibleBody - def insert[T](xs: Conc[T], i: BigInt, y: T): Conc[T] = { - require(xs.valid && i >= 0 && i <= xs.size) //note the precondition - xs match { - case Empty() => Single(y) - case Single(x) => - if (i == 0) CC(Single(y), xs) - else CC(xs, Single(y)) - case CC(l, r) if i < l.size => - concatNonEmpty(insert(l, i, y), r) - case CC(l, r) => - concatNonEmpty(l, insert(r, i - l.size, y)) - } - } ensuring (res => - res.valid && // tree invariants - res.level - xs.level <= 1 && res.level >= xs.level && // height of the output tree is at most 1 greater than that of the input tree - !res.isEmpty && - insertAppendAxiomInst(xs, i, y) && // instantiation of an axiom - res.toList == insertAtIndex(xs.toList, i, y) && // correctness - time <= ? * xs.level + ? // time is linear in the height of the tree - ) - - /** - * Using a different version of insert than of the library - * because the library implementation in unnecessarily complicated. - * TODO: update the code to use the library instead ? - */ - @invisibleBody - def insertAtIndex[T](l: List[T], i: BigInt, y: T): List[T] = { - require(0 <= i && i <= l.size) - l match { - case Nil() => - Cons[T](y, Nil()) - case _ if i == 0 => - Cons[T](y, l) - case Cons(x, tail) => - Cons[T](x, insertAtIndex(tail, i - 1, y)) - } - } - - // A lemma about `append` and `insertAtIndex` - @invisibleBody - def appendInsertIndex[T](l1: List[T], l2: List[T], i: BigInt, y: T): Boolean = { - require(0 <= i && i <= l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x, xs) => if (i == 0) true else appendInsertIndex[T](xs, l2, i - 1, y) - }) && - // lemma - (insertAtIndex((l1 ++ l2), i, y) == ( - if (i < l1.size) insertAtIndex(l1, i, y) ++ l2 - else l1 ++ insertAtIndex(l2, (i - l1.size), y))) - }.holds - - @invisibleBody - def insertAppendAxiomInst[T](xs: Conc[T], i: BigInt, y: T): Boolean = { - require(i >= 0 && i <= xs.size) - xs match { - case CC(l, r) => appendInsertIndex(l.toList, r.toList, i, y) - case _ => true - } - }.holds - - @invisibleBody - def split[T](xs: Conc[T], n: BigInt): (Conc[T], Conc[T]) = { - require(xs.valid) - xs match { - case Empty() => (Empty[T](), Empty[T]()) - case s @ Single(x) => - if (n <= 0) (Empty[T](), s) //a minor fix - else (s, Empty[T]()) - case CC(l, r) => - if (n < l.size) { - val (ll, lr) = split(l, n) - (ll, concatNormalized(lr, r)) - } else if (n > l.size) { - val (rl, rr) = split(r, n - l.size) - (concatNormalized(l, rl), rr) - } else { - (l, r) - } - } - } ensuring (res => res._1.valid && res._2.valid && // tree invariants are preserved - xs.level >= res._1.level && xs.level >= res._2.level && // height bounds of the resulting tree - instSplitAxiom(xs, n) && // instantiation of an axiom - splitCorrectness(res, xs, n) && - time <= ? * xs.level + ? * res._1.level + ? * res._2.level + ? // time is linear in height - ) - - @invisibleBody - def splitCorrectness[T](r: (Conc[T], Conc[T]), xs: Conc[T], n: BigInt): Boolean = { - r._1.toList == xs.toList.take(n) && r._2.toList == xs.toList.drop(n) - } - - @invisibleBody - def instSplitAxiom[T](xs: Conc[T], n: BigInt): Boolean = { - xs match { - case CC(l, r) => - appendTakeDrop(l.toList, r.toList, n) - case _ => true - } - }.holds -} diff --git a/testcases/lazy-datastructures/conc/Conqueue.scala b/testcases/lazy-datastructures/conc/Conqueue.scala deleted file mode 100644 index 360aef160c64cdd60406066fd4fbafbc9d43a4fc..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/conc/Conqueue.scala +++ /dev/null @@ -1,498 +0,0 @@ -package conc - -import leon._ -import lazyeval._ -import lang._ -import math._ -import annotation._ -import instrumentation._ - -import ConcTrees._ - -object ConcTrees { - - sealed abstract class Conc[T] { - def isEmpty: Boolean = { - this == Empty[T]() - } - - val level: BigInt = { - this match { - case Empty() => BigInt(0) - case Single(x) => BigInt(0) - case CC(l, r) => - BigInt(1) + max(l.level, r.level) - } - } ensuring (_ >= 0) - } - - case class Empty[T]() extends Conc[T] - case class Single[T](x: T) extends Conc[T] - case class CC[T](left: Conc[T], right: Conc[T]) extends Conc[T] -} - -object Conqueue { - - sealed abstract class ConQ[T] { - val isSpine: Boolean = this match { - case Spine(_, _, _) => true - case _ => false - } - val isTip = !isSpine - } - - case class Tip[T](t: Conc[T]) extends ConQ[T] - case class Spine[T](head: Conc[T], createdWithSuspension: Bool, rear: Lazy[ConQ[T]]) extends ConQ[T] - - sealed abstract class Bool - case class True() extends Bool - case class False() extends Bool - - /** - * Checks whether there is a zero before an unevaluated closure - */ - def zeroPrecedesLazy[T](q: Lazy[ConQ[T]]): Boolean = { - if (q.isEvaluated) { - q* match { - case Spine(Empty(), _, rear) => - true // here we have seen a zero - case Spine(h, _, rear) => - zeroPrecedesLazy(rear) //here we have not seen a zero - case Tip(_) => true - } - } else false - } - - /** - * Checks whether there is a zero before a given suffix - */ - def zeroPrecedesSuf[T](q: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - if (q != suf) { - q* match { - case Spine(Empty(), _, rear) => true - case Spine(_, _, rear) => - zeroPrecedesSuf(rear, suf) - case Tip(_) => false - } - } else false - } - - /** - * Everything until suf is evaluated. This - * also asserts that suf should be a suffix of the list - */ - def concreteUntil[T](l: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - if (l != suf) { - l.isEvaluated && (l* match { - case Spine(_, cws, tail) => - concreteUntil(tail, suf) - case _ => - false - }) - } else true - } - - def isConcrete[T](l: Lazy[ConQ[T]]): Boolean = { - l.isEvaluated && (l* match { - case Spine(_, _, tail) => - isConcrete(tail) - case _ => true - }) - } - - sealed abstract class Scheds[T] - case class Cons[T](h: Lazy[ConQ[T]], tail: Scheds[T]) extends Scheds[T] - case class Nil[T]() extends Scheds[T] - - def schedulesProperty[T](q: Lazy[ConQ[T]], schs: Scheds[T]): Boolean = { - schs match { - case Cons(head, tail) => - head* match { - case Spine(Empty(), _, _) => - head.isSuspension(pushLeftLazy[T] _) && - concreteUntil(q, head) && - schedulesProperty(pushUntilCarry(head), tail) - case _ => - false - } - case Nil() => - isConcrete(q) - } - } - - def strongSchedsProp[T](q: Lazy[ConQ[T]], schs: Scheds[T]) = { - q.isEvaluated && { - schs match { - case Cons(head, tail) => - zeroPrecedesSuf(q, head) // zeroPrecedesSuf holds initially - case Nil() => true - } - } && - schedulesProperty(q, schs) - } - - /** - * Note: if 'q' has a suspension then it would have a carry. - */ - def pushUntilCarry[T](q: Lazy[ConQ[T]]): Lazy[ConQ[T]] = { - q* match { - case Spine(Empty(), _, rear) => // if we push a carry and get back 0 then there is a new carry - pushUntilCarry(rear) - case Spine(h, _, rear) => // if we push a carry and get back 1 then there the carry has been fully pushed - rear - case Tip(_) => - q - } - } - - case class Queue[T](queue: Lazy[ConQ[T]], schedule: Scheds[T]) { - val valid = strongSchedsProp(queue, schedule) - } - - def pushLeft[T](ys: Single[T], xs: Lazy[ConQ[T]]): ConQ[T] = { - require(zeroPrecedesLazy(xs)) - xs.value match { - case Tip(CC(_, _)) => - Spine(ys, False(), xs) - case Tip(Empty()) => - Tip(ys) - case Tip(t @ Single(_)) => - Tip(CC(ys, t)) - case s @ Spine(Empty(), _, rear) => - Spine[T](ys, False(), rear) - case s @ Spine(_, _, _) => - pushLeftLazy(ys, xs) - } - } ensuring (_ => time <= 70) - - // this procedure does not change state - @invstate - def pushLeftLazy[T](ys: Conc[T], xs: Lazy[ConQ[T]]): ConQ[T] = { - require(!ys.isEmpty && zeroPrecedesLazy(xs) && - (xs* match { - case Spine(h, _, _) => h != Empty[T]() - case _ => false - })) - xs.value match { - case Spine(head, _, rear) => // here, rear is guaranteed to be evaluated by 'zeroPrecedesLazy' invariant - val carry = CC(head, ys) //here, head and ys are of the same level - rear.value match { - case s @ Spine(Empty(), _, srear) => - val tail: ConQ[T] = Spine(carry, False(), srear) - Spine(Empty(), False(), tail) - - case s @ Spine(_, _, _) => - Spine(Empty(), True(), $(pushLeftLazy(carry, rear))) - - case t @ Tip(tree) => - if (tree.level > carry.level) { // can this happen ? this means tree is of level at least two greater than rear ? - val y: ConQ[T] = Spine(carry, False(), rear) - Spine(Empty(), False(), y) - } else { // here tree level and carry level are equal - val x: ConQ[T] = Tip(CC(tree, carry)) - val y: ConQ[T] = Spine(Empty(), False(), x) - Spine(Empty(), False(), y) - } - } - } - } ensuring { res => - (res match { - case Spine(Empty(), _, rear) => - (!isConcrete(xs) || isConcrete(pushUntilCarry(rear))) && - { - val _ = rear.value // this is necessary to assert properties on the state in the recursive invocation (and note this cannot go first) - rear.isEvaluated // this is a tautology - } - case _ => - false - }) && - time <= 40 - } - - /** - * Lemma: - * forall suf. suf*.head != Empty() ^ zeroPredsSuf(xs, suf) ^ concUntil(xs.tail.tail, suf) => concUntil(push(rear), suf) - */ - @invstate - def pushLeftLazyLemma[T](ys: Conc[T], xs: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - require(!ys.isEmpty && zeroPrecedesSuf(xs, suf) && - (xs* match { - case Spine(h, _, _) => h != Empty[T]() - case _ => false - }) && - (suf* match { - case Spine(Empty(), _, _) => - concreteUntil(xs, suf) - case _ => false - })) - // induction scheme - (xs* match { - case Spine(head, _, rear) => - val carry = CC[T](head, ys) - rear* match { - case s @ Spine(h, _, _) => - if (h != Empty[T]()) - pushLeftLazyLemma(carry, rear, suf) - else true - case _ => true - } - }) && - // instantiate the lemma that implies zeroPrecedesLazy - (if (zeroPredSufConcreteUntilLemma(xs, suf)) { - // property - (pushLeftLazy(ys, xs) match { - case Spine(Empty(), _, rear) => - concreteUntil(pushUntilCarry(rear), suf) - }) - } else false) - } holds - - def pushLeftWrapper[T](ys: Single[T], w: Queue[T]) = { - require(w.valid && - // instantiate the lemma that implies zeroPrecedesLazy - (w.schedule match { - case Cons(h, _) => - zeroPredSufConcreteUntilLemma(w.queue, h) - case _ => - concreteZeroPredLemma(w.queue) - })) - val nq = pushLeft(ys, w.queue) - val nsched = nq match { - case Spine(Empty(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons[T](rear, w.schedule) // this is the only case where we create a new lazy closure - else - w.schedule - case _ => - w.schedule - } - val lq: Lazy[ConQ[T]] = nq - (lq, nsched) - } ensuring { res => - // lemma instantiations - (w.schedule match { - case Cons(head, tail) => - w.queue* match { - case Spine(h, _, _) => - if (h != Empty[T]()) - pushLeftLazyLemma(ys, w.queue, head) - else true - case _ => true - } - case _ => true - }) && - schedulesProperty(res._1, res._2) && - time <= 80 - } - - def Pay[T](q: Lazy[ConQ[T]], scheds: Scheds[T]): Scheds[T] = { - require(schedulesProperty(q, scheds) && q.isEvaluated) - scheds match { - case c @ Cons(head, rest) => - head.value match { - case Spine(Empty(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons(rear, rest) - else - rest - } - case Nil() => scheds - } - } ensuring { res => - { - val in = inState[ConQ[T]] - val out = outState[ConQ[T]] - // instantiations for proving the scheds property - (scheds match { - case Cons(head, rest) => - concUntilExtenLemma(q, head, in, out) && - (head* match { - case Spine(Empty(), _, rear) => - res match { - case Cons(rhead, rtail) => - schedMonotone(in, out, rtail, pushUntilCarry(rhead)) && - concUntilMonotone(rear, rhead, in, out) && - concUntilCompose(q, rear, rhead) - case _ => - concreteMonotone(in, out, rear) && - concUntilConcreteExten(q, rear) - } - }) - case _ => true - }) && - // instantiations for zeroPrecedesSuf property - (scheds match { - case Cons(head, rest) => - (concreteUntilIsSuffix(q, head) withState in) && - (res match { - case Cons(rhead, rtail) => - concreteUntilIsSuffix(pushUntilCarry(head), rhead) && - suffixZeroLemma(q, head, rhead) && - zeroPrecedesSuf(q, rhead) - case _ => - true - }) - case _ => - true - }) - } && // properties - schedulesProperty(q, res) && - time <= 70 - } - - // monotonicity lemmas - def schedMonotone[T](st1: Set[Lazy[ConQ[T]]], st2: Set[Lazy[ConQ[T]]], scheds: Scheds[T], l: Lazy[ConQ[T]]): Boolean = { - require(st1.subsetOf(st2) && - (schedulesProperty(l, scheds) withState st1)) // here the input state is fixed as 'st1' - //induction scheme - (scheds match { - case Cons(head, tail) => - head* match { - case Spine(_, _, rear) => - concUntilMonotone(l, head, st1, st2) && - schedMonotone(st1, st2, tail, pushUntilCarry(head)) - case _ => true - } - case Nil() => - concreteMonotone(st1, st2, l) - }) && (schedulesProperty(l, scheds) withState st2) //property - } holds - - @traceInduct - def concreteMonotone[T](st1: Set[Lazy[ConQ[T]]], st2: Set[Lazy[ConQ[T]]], l: Lazy[ConQ[T]]): Boolean = { - ((isConcrete(l) withState st1) && st1.subsetOf(st2)) ==> (isConcrete(l) withState st2) - } holds - - @traceInduct - def concUntilMonotone[T](q: Lazy[ConQ[T]], suf: Lazy[ConQ[T]], st1: Set[Lazy[ConQ[T]]], st2: Set[Lazy[ConQ[T]]]): Boolean = { - ((concreteUntil(q, suf) withState st1) && st1.subsetOf(st2)) ==> (concreteUntil(q, suf) withState st2) - } holds - - // suffix predicates and their properties (this should be generalizable) - - def suffix[T](q: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - if (q == suf) true - else { - q* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case Tip(_) => false - } - } - } - - def properSuffix[T](l: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - l* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case _ => false - } - } ensuring (res => !res || (suffixDisequality(l, suf) && suf != l)) - - /** - * suf(q, suf) ==> suf(q.rear, suf.rear) - */ - @traceInduct - def suffixTrans[T](q: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - suffix(q, suf) ==> ((q*, suf*) match { - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffix(rear, sufRear) - case _ => true - }) - }.holds - - /** - * properSuf(l, suf) ==> l != suf - */ - def suffixDisequality[T](l: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - require(properSuffix(l, suf)) - suffixTrans(l, suf) && // lemma instantiation - ((l*, suf*) match { // induction scheme - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffixDisequality(rear, sufRear) - case _ => true - }) && l != suf // property - }.holds - - @traceInduct - def suffixCompose[T](q: Lazy[ConQ[T]], suf1: Lazy[ConQ[T]], suf2: Lazy[ConQ[T]]): Boolean = { - (suffix(q, suf1) && properSuffix(suf1, suf2)) ==> properSuffix(q, suf2) - } holds - - // properties of 'concUntil' - - @traceInduct - def concreteUntilIsSuffix[T](l: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - concreteUntil(l, suf) ==> suffix(l, suf) - }.holds - - // properties that extend `concUntil` to larger portions of the queue - - @traceInduct - def concUntilExtenLemma[T](q: Lazy[ConQ[T]], suf: Lazy[ConQ[T]], st1: Set[Lazy[ConQ[T]]], st2: Set[Lazy[ConQ[T]]]): Boolean = { - ((concreteUntil(q, suf) withState st1) && st2 == st1 ++ Set(suf)) ==> - (suf* match { - case Spine(_, _, rear) => - concreteUntil(q, rear) withState st2 - case _ => true - }) - } holds - - @traceInduct - def concUntilConcreteExten[T](q: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - (concreteUntil(q, suf) && isConcrete(suf)) ==> isConcrete(q) - } holds - - @traceInduct - def concUntilCompose[T](q: Lazy[ConQ[T]], suf1: Lazy[ConQ[T]], suf2: Lazy[ConQ[T]]): Boolean = { - (concreteUntil(q, suf1) && concreteUntil(suf1, suf2)) ==> concreteUntil(q, suf2) - } holds - - // properties that relate `concUntil`, `concrete`, `zeroPrecedesSuf` with `zeroPrecedesLazy` - // - these are used in preconditions to derive the `zeroPrecedesLazy` property - - @traceInduct - def zeroPredSufConcreteUntilLemma[T](q: Lazy[ConQ[T]], suf: Lazy[ConQ[T]]): Boolean = { - (zeroPrecedesSuf(q, suf) && concreteUntil(q, suf)) ==> zeroPrecedesLazy(q) - } holds - - @traceInduct - def concreteZeroPredLemma[T](q: Lazy[ConQ[T]]): Boolean = { - isConcrete(q) ==> zeroPrecedesLazy(q) - } holds - - // properties relating `suffix` an `zeroPrecedesSuf` - - def suffixZeroLemma[T](q: Lazy[ConQ[T]], suf: Lazy[ConQ[T]], suf2: Lazy[ConQ[T]]): Boolean = { - require(suf* match { - case Spine(Empty(), _, _) => - suffix(q, suf) && properSuffix(suf, suf2) - case _ => false - }) - suffixCompose(q, suf, suf2) && ( - // induction scheme - if (q != suf) { - q* match { - case Spine(_, _, tail) => - suffixZeroLemma(tail, suf, suf2) - case _ => - true - } - } else true) && - zeroPrecedesSuf(q, suf2) // property - }.holds - - /** - * Pushing an element to the left of the queue preserves the data-structure invariants - */ - def pushLeftAndPay[T](ys: Single[T], w: Queue[T]) = { - require(w.valid) - - val (q, scheds) = pushLeftWrapper(ys, w) - val nscheds = Pay(q, scheds) - Queue(q, nscheds) - - } ensuring { res => res.valid && time <= 200 } -} diff --git a/testcases/lazy-datastructures/eager/AmortizedQueue.scala b/testcases/lazy-datastructures/eager/AmortizedQueue.scala deleted file mode 100644 index cdbb65727a009a4aed77514b904254a692f925b6..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/eager/AmortizedQueue.scala +++ /dev/null @@ -1,83 +0,0 @@ -package eagerEval - -import leon._ -import invariant._ -import instrumentation._ - -object AmortizedQueue { - sealed abstract class List { - val size: BigInt = this match { - case Nil() => 0 - case Cons(_, xs) => 1 + xs.size - } - } - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def concat(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => Cons(x, concat(xs, l2)) - - }) ensuring (res => res.size == l1.size + l2.size && time <= ? * l1.size + ?) - - def reverseRec(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverseRec(xs, Cons(x, l2)) - }) ensuring (res => l1.size + l2.size == res.size && time <= ? * l1.size + ?) - - def listRev(l: List): List = { - reverseRec(l, Nil()) - } ensuring (res => l.size == res.size && time <= ? * l.size + ?) - - def removeLast(l: List): List = { - require(l != Nil()) - l match { - case Cons(x, Nil()) => Nil() - case Cons(x, xs) => Cons(x, removeLast(xs)) - case _ => Nil() - } - } ensuring (res => res.size <= l.size && tmpl((a, b) => time <= a * l.size + b)) - - case class Queue(front: List, rear: List) { - def qsize: BigInt = front.size + rear.size - - def asList: List = concat(front, listRev(rear)) - - def isAmortized: Boolean = front.size >= rear.size - - def isEmpty: Boolean = this match { - case Queue(Nil(), Nil()) => true - case _ => false - } - - def amortizedQueue(front: List, rear: List): Queue = { - if (rear.size <= front.size) - Queue(front, rear) - else - Queue(concat(front, listRev(rear)), Nil()) - } - - def enqueue(elem: BigInt): Queue = ({ - amortizedQueue(front, Cons(elem, rear)) - }) ensuring (_ => time <= ? * qsize + ?) - - def dequeue: Queue = { - require(isAmortized && !isEmpty) - front match { - case Cons(f, fs) => amortizedQueue(fs, rear) - case _ => Queue(Nil(), Nil()) - } - } ensuring (_ => time <= ? * qsize + ?) - - def head: BigInt = { - require(isAmortized && !isEmpty) - front match { - case Cons(f, _) => f - } - } - - def reverse: Queue = { // this lets the queue perform deque operation (but they no longer have efficient constant time amortized bounds) - amortizedQueue(rear, front) - } - } -} diff --git a/testcases/lazy-datastructures/eager/BasicMergeSort.scala b/testcases/lazy-datastructures/eager/BasicMergeSort.scala deleted file mode 100644 index 481bbbbf061b3ca6bda3a72aee3744bb40252208..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/eager/BasicMergeSort.scala +++ /dev/null @@ -1,41 +0,0 @@ -package eagerEval - -import leon._ -import lang._ -import collection._ - -object MergeSort { - - def merge[T](less: (T, T) => Boolean)(xs: List[T], ys: List[T]): List[T] = { - (xs, ys) match { - case (Nil(), _) => ys - case (_, Nil()) => xs - case (Cons(x, xtail), Cons(y, ytail)) => - if (less(x, y)) - x :: merge(less)(xtail, ys) - else - y :: merge(less)(xs, ytail) - } - } ensuring { res => res.content == xs.content ++ ys.content && - res.size == xs.size + ys.size } - - def split[T](list: List[T]): (List[T], List[T]) = { - list match { - case Nil() => (Nil(), Nil()) - case Cons(x, Nil()) => (Cons(x, Nil()), Nil()) - case Cons(x1, Cons(x2, xs)) => - val (s1, s2) = split(xs) - (Cons(x1, s1), Cons(x2, s2)) - } - } - - def msort[T](less: (T, T) => Boolean)(l: List[T]): List[T] = { - l match { - case Nil() => Nil[T]() - case Cons(x, Nil()) => Cons(x, Nil()) - case _ => - val (first, second) = split(l) - merge(less)(msort(less)(first), msort(less)(second)) - } - } ensuring { res => res.content == l.content && res.size == l.size } -} diff --git a/testcases/lazy-datastructures/eager/BigNums.scala b/testcases/lazy-datastructures/eager/BigNums.scala deleted file mode 100644 index 5d0271b0e354a578b4a43371e9b5dce087a4015a..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/eager/BigNums.scala +++ /dev/null @@ -1,79 +0,0 @@ -package eagerEval - -import leon._ -import annotation._ -import invariant._ -import instrumentation._ - -object BigNums { - sealed abstract class Digit - case class Zero() extends Digit { - @ignore - override def toString = "0" - } - case class One() extends Digit { - @ignore - override def toString = "1" - } - - sealed abstract class BigNum - case class Cons(head: Digit, tail: BigNum) extends BigNum - case class Nil() extends BigNum - - /** - * Time taken by the increment method - * The number of leading one's - */ - def leadingOnes(l: BigNum) : BigInt = { - l match { - case Nil() => 1 - case Cons(Zero(), tail) => 1 - case Cons(_, tail) => 1 + leadingOnes(tail) - } - } - - /** - * Total number of one's in the number - */ - def numOnes(l: BigNum) : BigInt = { - l match { - case Nil() => 0 - case Cons(Zero(), tail) => numOnes(tail) - case Cons(_, tail) => 1 + numOnes(tail) - } - } - - /** - * Increments a number - */ - def increment(l: BigNum) : BigNum = { - l match { - case Nil() => Cons(One(), l) - case Cons(Zero(), tail) => Cons(One(), tail) - case Cons(_, tail) => - Cons(Zero(), increment(tail)) - } - } ensuring (res => time <= ? * leadingOnes(l) + ? && leadingOnes(l) + numOnes(res) - numOnes(l) <= ?) - - def firstDigit(l: BigNum): Digit = { - require(l != Nil()) - l match { - case Cons(d, _) => d - } - } - - /** - * Nop is the number of operations - */ - def incrUntil(nop: BigInt, l: BigNum) : BigNum = { - if(nop == 0) l - else { - incrUntil(nop-1, increment(l)) - } - } ensuring (res => time <= ? * nop + ? * numOnes(l) + ?) - - def count(nop: BigInt) : BigNum = { - incrUntil(nop, Nil()) - } ensuring (res => time <= ? * nop + ?) - -} diff --git a/testcases/lazy-datastructures/lazy-memoized-datastructures.zip b/testcases/lazy-datastructures/lazy-memoized-datastructures.zip deleted file mode 100644 index a949483dae9396dc2726a156459feec621c9bdbe..0000000000000000000000000000000000000000 Binary files a/testcases/lazy-datastructures/lazy-memoized-datastructures.zip and /dev/null differ diff --git a/testcases/lazy-datastructures/lib/lazybenchmarkexecution_2.11-1.0.jar b/testcases/lazy-datastructures/lib/lazybenchmarkexecution_2.11-1.0.jar deleted file mode 100644 index 784f4db57ac44a6c8e78d491fe8280d5866b0663..0000000000000000000000000000000000000000 Binary files a/testcases/lazy-datastructures/lib/lazybenchmarkexecution_2.11-1.0.jar and /dev/null differ diff --git a/testcases/lazy-datastructures/lib/macmemo.jar b/testcases/lazy-datastructures/lib/macmemo.jar deleted file mode 100644 index eacd3c002133ad6486d2c89eb63722ab088d2a6c..0000000000000000000000000000000000000000 Binary files a/testcases/lazy-datastructures/lib/macmemo.jar and /dev/null differ diff --git a/testcases/lazy-datastructures/memoization/FibonacciMemoized.scala b/testcases/lazy-datastructures/memoization/FibonacciMemoized.scala deleted file mode 100644 index 2780315c17ae7844e34a6b8a1be827d371f99578..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/memoization/FibonacciMemoized.scala +++ /dev/null @@ -1,23 +0,0 @@ -import leon._ -import mem._ -import lang._ -import annotation._ -import instrumentation._ -//import leon.invariant._ - -object FibMem { - sealed abstract class IList - case class Cons(x: BigInt, tail: IList) extends IList - case class Nil() extends IList - - @memoize - def fibRec(n: BigInt): BigInt = { - require(n >= 0) - if(n <= 2) - BigInt(1) - else - fibRec(n-1) + fibRec(n-2) // postcondition implies that the second call would be cached - } ensuring(_ => - (n <= 2 || (fibRec(n-1).isCached && - fibRec(n-2).isCached)) && time <= 40*n + 10) -} diff --git a/testcases/lazy-datastructures/memoization/HammingMemoized.scala b/testcases/lazy-datastructures/memoization/HammingMemoized.scala deleted file mode 100644 index 36f606b93437055f7bae7c7908f30cba9cee88d7..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/memoization/HammingMemoized.scala +++ /dev/null @@ -1,87 +0,0 @@ -import leon._ - -import mem._ -import lang._ -import annotation._ -import instrumentation._ - -/** - * A memoized version of the implementation of Hamming problem shown in - * section 4.3 of Type-based allocation analysis for Co-recursion - */ -object Hamming { - sealed abstract class IList - case class Cons(x: BigInt, tail: IList) extends IList - case class Nil() extends IList - - case class Data(v: BigInt, i2: BigInt, i3: BigInt, i5: BigInt) - - @invstate - @memoize - def ham(n: BigInt): Data = { - require(n ==0 || (n > 0 && depsEval(n - 1))) - if(n == BigInt(0)) Data(1, 0, 0, 0) - else { - val Data(x, i2, i3, i5) = ham(n-1) - val a = ham(i2).i2 * 2 - val b = ham(i3).i3 * 3 - val c = ham(i5).i5 * 5 - val (v, ni, nj, nk) = threeWayMerge(a, b, c, i2, i3, i5) - Data(v, ni, nj, nk) - } - } ensuring(res => res.i2 <= n && res.i3 <= n && res.i5 <= n && - res.i3 >= 0 && res.i5 >= 0 && res.i2 >= 0 && - depsLem(res.i2, n) && depsLem(res.i3, n) && depsLem(res.i5, n) && // instantiations - time <= 140) - - def depsEval(i: BigInt): Boolean = { - require(i >= 0) - ham(i).isCached && (if (i <= 0) true else depsEval(i - 1)) - } - - @traceInduct - def depsEvalMono(i: BigInt, st1: Set[Mem[Data]], st2: Set[Mem[Data]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (depsEval(i) withState st1)) ==> (depsEval(i) withState st2) - } holds - - @traceInduct - def depsLem(x: BigInt, y: BigInt) = { - require(x >= 0 && y >= 0) - (x <= y && depsEval(y)) ==> depsEval(x) - } holds - - def invoke(n: BigInt) = { - require(n == 0 || n > 0 && depsEval(n - 1)) - ham(n).v - } ensuring (res => { - val in = inState[Data] - val out = outState[Data] - (n == 0 || depsEvalMono(n-1, in, out)) && // instantiation - time <= 170 - }) - - /** - * Returns a list of hamming numbers upto 'n' - */ - def hammingList(n: BigInt): IList = { - require(n >= 0) - if(n == 0) { - Cons(invoke(n), Nil()) - } else { - val tailRes = hammingList(n-1) - Cons(invoke(n), tailRes) - } - } ensuring(_ => depsEval(n) && time <= 240 * (n + 1)) - - @inline - def threeWayMerge(a: BigInt, b: BigInt, c: BigInt, i2: BigInt, i3: BigInt, i5: BigInt) = { - if(a == b && b == c) (a, i2 + 1, i3 + 1, i5 + 1) - else if(a == b && a < c) (a, i2 + 1, i3 + 1, i5 ) - else if(a == c && a < b) (a, i2 + 1, i3 , i5 + 1) - else if(b == c && b < a) (b, i2 , i3 + 1, i5 + 1) - else if(a < b && a < c) (a, i2 + 1, i3 , i5 ) - else if(b < c && b < a) (b, i2 , i3 + 1, i5 ) - else/*if(c < a && c < b)*/(c, i2 , i3 , i5 + 1) - } -} diff --git a/testcases/lazy-datastructures/memoization/Knapsack.scala b/testcases/lazy-datastructures/memoization/Knapsack.scala deleted file mode 100644 index 44eadad05a0de6edba94c8796d668748cc0aaf49..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/memoization/Knapsack.scala +++ /dev/null @@ -1,104 +0,0 @@ -import leon._ -import mem._ -import annotation._ -import instrumentation._ -//import leon.invariant._ - -object Knapscak { - sealed abstract class IList { - def size: BigInt = { - this match { - case Cons(_, tail) => 1 + tail.size - case Nil() => BigInt(0) - } - } ensuring(_ >= 0) - } - case class Cons(x: (BigInt, BigInt), tail: IList) extends IList // a list of pairs of weights and values - case class Nil() extends IList - - def deps(i: BigInt, items: IList): Boolean = { - require(i >= 0) - knapSack(i, items).isCached && // if we have the cached check only along the else branch, we would get a counter-example. - (if (i <= 0) true - else { - deps(i - 1, items) - }) - } - - @invstate - def maxValue(items: IList, w: BigInt, currList: IList): BigInt = { - require((w ==0 || (w > 0 && deps(w - 1, items))) && - // lemma inst - (currList match { - case Cons((wi, vi), _) => - if (wi <= w && wi > 0) depsLem(w - wi, w - 1, items) - else true - case Nil() => true - })) - currList match { - case Cons((wi, vi), tail) => - val oldMax = maxValue(items, w, tail) - if (wi <= w && wi > 0) { - val choiceVal = vi + knapSack(w - wi, items) - if (choiceVal >= oldMax) - choiceVal - else - oldMax - } else oldMax - case Nil() => BigInt(0) - } - } ensuring(_ => time <= 40*currList.size + 20) // interchanging currList and items in the bound will produce a counter-example - - @memoize - def knapSack(w: BigInt, items: IList): BigInt = { - require(w >= 0 && (w == 0 || deps(w - 1, items))) - if (w == 0) BigInt(0) - else { - maxValue(items, w, items) - } - } ensuring(_ => time <= 40*items.size + 25) - - def invoke(i: BigInt, items: IList) = { - require(i == 0 || (i > 0 && deps(i - 1, items))) - knapSack(i, items) - } ensuring (res => { - (i == 0 || depsMono(i - 1, items, inState[BigInt], outState[BigInt]) && // lemma inst - deps(i - 1, items)) && - time <= 40*items.size + 40 - }) - - def bottomup(i: BigInt, w: BigInt, items: IList): IList = { - require(w >= i && (i == 0 || i > 0 && deps(i - 1, items))) - val ri = invoke(i, items) - if (i == w) - Cons((i,ri), Nil()) - else { - Cons((i,ri), bottomup(i + 1, w, items)) - } - } ensuring(_ => items.size <= 10 ==> time <= 500 * (w - i + 1)) - - /** - * Computes the list of optimal solutions of all weights up to 'w' - */ - def knapSackSol(w: BigInt, items: IList) = { - require(w >= 0 && items.size <= 10) // the second requirement is only to keep the bounds linear for z3 to work - bottomup(0, w, items) - } ensuring(_ => time <= 500*w + 510) - - /** - * Lemmas of deps - */ - // deps is monotonic - @traceInduct - def depsMono(i: BigInt, items: IList, st1: Set[Mem[BigInt]], st2: Set[Mem[BigInt]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (deps(i, items) withState st1)) ==> (deps(i, items) withState st2) - } holds - - // forall. x, x <= y && deps(y) => deps(x) - @traceInduct - def depsLem(x: BigInt, y: BigInt, items: IList) = { - require(x >= 0 && y >= 0) - (x <= y && deps(y, items)) ==> deps(x, items) - } holds -} diff --git a/testcases/lazy-datastructures/memoization/PackratParsing.scala b/testcases/lazy-datastructures/memoization/PackratParsing.scala deleted file mode 100644 index b1b5f175b1162f80d05bb394cad39ce075feb4d7..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/memoization/PackratParsing.scala +++ /dev/null @@ -1,203 +0,0 @@ -import leon._ -import leon.mem._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -//import leon.invariant._ - -/** - * The packrat parser that uses the Expressions grammar presented in Bran Ford ICFP'02 paper. - * The implementation is almost exactly as it was presented in the paper, but - * here indices are passed around between parse functions, instead of strings. - */ -object PackratParsing { - - sealed abstract class Terminal - case class Open() extends Terminal - case class Close() extends Terminal - case class Plus() extends Terminal - case class Times() extends Terminal - case class Digit() extends Terminal - - /** - * A mutable array of tokens returned by the lexer - */ - @ignore - var string = Array[Terminal]() - - /** - * looking up the ith token - */ - @extern - def lookup(i: BigInt): Terminal = { - string(i.toInt) - } ensuring(_ => time <= 1) - - sealed abstract class Result { - /** - * Checks if the index in the result (if any) is - * smaller than `i` - */ - @inline - def smallerIndex(i: BigInt) = this match { - case Parsed(m) => m < i - case _ => true - } - } - case class Parsed(rest: BigInt) extends Result - case class NoParse() extends Result - - @memoize - @invstate - def pAdd(i: BigInt): Result = { - require { - if (depsEval(i) && pMul(i).isCached && pPrim(i).isCached) - resEval(i, pMul(i)) - else false - } // lemma inst - // Rule 1: Add <- Mul + Add - val v = pMul(i) - v match { - case Parsed(j) => - if (j > 0 && lookup(j) == Plus()) { - pAdd(j - 1) match { - case Parsed(rem) => - Parsed(rem) - case _ => - v // Rule2: Add <- Mul - } - } else v - case _ => - v - } - } ensuring (res => res.smallerIndex(i) && time <= 26) - - @memoize - @invstate - def pMul(i: BigInt): Result = { - require { - if (depsEval(i) && pPrim(i).isCached) - resEval(i, pPrim(i)) // lemma inst - else false - } - // Rule 1: Mul <- Prim * Mul - val v = pPrim(i) - v match { - case Parsed(j) => - if (j > 0 && lookup(j) == Plus()) { - pMul(j - 1) match { - case Parsed(rem) => - Parsed(rem) - case _ => - v // Rule2: Mul <- Prim - } - } else v - case _ => - v - } - } ensuring (res => res.smallerIndex(i) && time <= 26) - - @memoize - @invstate - def pPrim(i: BigInt): Result = { - require(depsEval(i)) - val char = lookup(i) - if (char == Digit()) { - if (i > 0) - Parsed(i - 1) // Rule1: Prim <- Digit - else - Parsed(-1) // here, we can use -1 to convery that the suffix is empty - } else if (char == Open() && i > 0) { - pAdd(i - 1) match { // Rule 2: pPrim <- ( Add ) - case Parsed(rem) => - if (rem >= 0 && lookup(rem) == Close()) Parsed(rem - 1) - else NoParse() - case _ => - NoParse() - } - } else NoParse() - } ensuring (res => res.smallerIndex(i) && time <= 28) - - //@inline - def depsEval(i: BigInt) = i == 0 || (i > 0 && allEval(i-1)) - - def allEval(i: BigInt): Boolean = { - require(i >= 0) - (pPrim(i).isCached && pMul(i).isCached && pAdd(i).isCached) &&( - if (i == 0) true - else allEval(i - 1)) - } - - @traceInduct - def evalMono(i: BigInt, st1: Set[Mem[Result]], st2: Set[Mem[Result]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (allEval(i) withState st1)) ==> (allEval(i) withState st2) - } holds - - @traceInduct - def depsLem(x: BigInt, y: BigInt) = { - require(x >= 0 && y >= 0) - (x <= y && allEval(y)) ==> allEval(x) - } holds - - /** - * Instantiates the lemma `depsLem` on the result index (if any) - */ - def resEval(i: BigInt, res: Result) = { - (res match { - case Parsed(j) => - if (j >= 0 && i > 1) depsLem(j, i - 1) - else true - case _ => true - }) - } - - def invokePrim(i: BigInt): Result = { - require(depsEval(i)) - pPrim(i) - } ensuring {res => - val in = inState[Result] - val out = outState[Result] - (if(i >0) evalMono(i-1, in, out) else true) - } - - def invokeMul(i: BigInt): Result = { - require(depsEval(i)) - invokePrim(i) match { - case _ => pMul(i) - } - } ensuring {res => - val in = inState[Result] - val out = outState[Result] - (if(i >0) evalMono(i-1, in, out) else true) - } - - def invoke(i: BigInt): Result = { - require(depsEval(i)) - invokeMul(i) match { - case _ => pAdd(i) - } - } ensuring{ res => - val in = inState[Result] - val out = outState[Result] - (if(i >0) evalMono(i-1, in, out) else true) && - allEval(i) && - time <= 189 - } - - /** - * Parsing a string of length 'n+1'. - * Word is represented as an array indexed by 'n'. We only pass around the index. - * The 'lookup' function will return a character of the array. - */ - def parse(n: BigInt): Result = { - require(n >= 0) - if(n == 0) invoke(n) - else { - parse(n-1) match { // we parse the prefixes ending at 0, 1, 2, 3, ..., n - case _ => invoke(n) - } - } - } ensuring(_ => allEval(n) && - time <= 198*n + 192) -} diff --git a/testcases/lazy-datastructures/memoization/WeightedScheduling.scala b/testcases/lazy-datastructures/memoization/WeightedScheduling.scala deleted file mode 100644 index e640bd79e7fa7950e5b3dd01389c4bd84f734045..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/memoization/WeightedScheduling.scala +++ /dev/null @@ -1,104 +0,0 @@ -import leon._ -import leon.mem._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -//import leon.invariant._ - -object WeightedSched { - sealed abstract class IList { - def size: BigInt = { - this match { - case Cons(_, tail) => 1 + tail.size - case Nil() => BigInt(0) - } - } ensuring(_ >= 0) - } - case class Cons(x: BigInt, tail: IList) extends IList - case class Nil() extends IList - - /** - * array of jobs - * (a) each job has a start time, finish time, and weight - * (b) Jobs are sorted in ascending order of finish times - */ - @ignore - var jobs = Array[(BigInt, BigInt, BigInt)]() - - /** - * A precomputed mapping from each job i to the previous job j it is compatible with. - */ - @ignore - var p = Array[Int]() - - @extern - def jobInfo(i: BigInt) = { - jobs(i.toInt) - } ensuring(_ => time <= 1) - - @extern - def prevCompatibleJob(i: BigInt) = { - BigInt(p(i.toInt)) - } ensuring(res => res >=0 && res < i && time <= 1) - - @inline - def max(x: BigInt, y: BigInt) = if (x >= y) x else y - - def depsEval(i: BigInt) = i == 0 || (i > 0 && allEval(i-1)) - - def allEval(i: BigInt): Boolean = { - require(i >= 0) - sched(i).isCached && - (if (i == 0) true - else allEval(i - 1)) - } - - @traceInduct - def evalMono(i: BigInt, st1: Set[Mem[BigInt]], st2: Set[Mem[BigInt]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (allEval(i) withState st1)) ==> (allEval(i) withState st2) - } holds - - @traceInduct - def evalLem(x: BigInt, y: BigInt) = { - require(x >= 0 && y >= 0) - (x <= y && allEval(y)) ==> allEval(x) - } holds - - @invstate - @memoize - def sched(jobIndex: BigInt): BigInt = { - require(depsEval(jobIndex) && - (jobIndex == 0 || evalLem(prevCompatibleJob(jobIndex), jobIndex-1))) - val (st, fn, w) = jobInfo(jobIndex) - if(jobIndex == 0) w - else { - // we may either include the head job or not: - // if we include the head job, we have to skip every job that overlaps with it - val tailValue = sched(jobIndex - 1) - val prevCompatVal = sched(prevCompatibleJob(jobIndex)) - max(w + prevCompatVal, tailValue) - } - } ensuring(_ => time <= 100) - - def invoke(jobIndex: BigInt) = { - require(depsEval(jobIndex)) - sched(jobIndex) - } ensuring (res => { - val in = inState[BigInt] - val out = outState[BigInt] - (jobIndex == 0 || evalMono(jobIndex-1, in, out)) && - time <= 150 - }) - - def schedBU(jobi: BigInt): IList = { - require(jobi >= 0) - if(jobi == 0) { - Cons(invoke(jobi), Nil()) - } else { - val tailRes = schedBU(jobi-1) - Cons(invoke(jobi), tailRes) - } - } ensuring(_ => allEval(jobi) && - time <= 200 * (jobi + 1)) -} diff --git a/testcases/lazy-datastructures/project/Build.scala b/testcases/lazy-datastructures/project/Build.scala deleted file mode 100644 index 4d96b683b440afe56a993d3790105a0092410165..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/project/Build.scala +++ /dev/null @@ -1,21 +0,0 @@ -import sbt._ -import Keys._ - -object BuildSettings { - val paradiseVersion = "2.1.0-M5" - val buildSettings = Defaults.defaultSettings ++ Seq( - resolvers += Resolver.sonatypeRepo("snapshots"), - resolvers += Resolver.sonatypeRepo("releases"), - addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full) - ) -} - -object MyBuild extends Build { - import BuildSettings._ - - lazy val root = Project( - "root", - file("."), - settings = buildSettings - ) -} diff --git a/testcases/lazy-datastructures/withOrb/BottomUpMegeSort.scala b/testcases/lazy-datastructures/withOrb/BottomUpMegeSort.scala deleted file mode 100644 index 71179a087cffb9fe6c2a465d5884953a2432725e..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/BottomUpMegeSort.scala +++ /dev/null @@ -1,238 +0,0 @@ -package withOrb - -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import instrumentation._ -import invariant._ -import stats._ - -/** - * TODO Multiple instantiations of type parameters is not supported yet, - * since it require creation of multiple states one for each instantiation - */ - -/** - * A version of merge sort that operates bottom-up. That allows - * accessing the first element in the sorted list in constant time. - */ -object BottomUpMergeSort { - - /** - * A list of integers that have to be sorted - */ - sealed abstract class IList { - def size: BigInt = { - this match { - case ICons(_, xs) => 1 + xs.size - case _ => BigInt(0) - } - } ensuring (_ >= 0) - } - case class ICons(x: BigInt, tail: IList) extends IList - case class INil() extends IList - - /** - * A stream of integers (the tail is lazy) - */ - sealed abstract class IStream { - def size: BigInt = { - this match { - case SCons(_, xs) => 1 + ssize(xs) - case _ => BigInt(0) - } - } ensuring (_ >= 0) - } - case class SCons(x: BigInt, tail: Lazy[IStream]) extends IStream - case class SNil() extends IStream - @inline - def ssize(l: Lazy[IStream]): BigInt = (l*).size - - /** - * A list of suspensions - */ - sealed abstract class LList { - def size: BigInt = { - this match { - case LNil() => BigInt(0) - case LCons(_, t) => 1 + t.size - } - } ensuring (_ >= 0) - - def valid: Boolean = { - this match { - case LNil() => true - case LCons(l, t) => ssize(l) > 0 && t.valid - } - } - - def fullSize: BigInt = { - this match { - case LNil() => BigInt(0) - case LCons(l, t) => ssize(l) + t.fullSize - } - } ensuring (_ >= 0) - } - case class LCons(x: Lazy[IStream], tail: LList) extends LList - case class LNil() extends LList - - /** - * A function that given a list of (lazy) sorted lists, - * groups them into pairs and lazily invokes the 'merge' function - * on each pair. - * Takes time linear in the size of the input list - */ - @invisibleBody - def pairs(l: LList): LList = { - require(l.valid) - l match { - case LNil() => LNil() - case LCons(_, LNil()) => l - case LCons(l1, LCons(l2, rest)) => - LCons($(merge(l1, l2)), pairs(rest)) - } - } ensuring (res => res.size <= (l.size + 1) / 2 && - l.fullSize == res.fullSize && - res.valid && - time <= ? * l.size + ?) - - /** - * Create a linearized tree of merges e.g. merge(merge(2, 1), merge(17, 19)). - * Takes time linear in the size of the input list. - */ - @invisibleBody - def constructMergeTree(l: LList): LList = { - require(l.valid) - l match { - case LNil() => LNil() - case LCons(_, LNil()) => l - case _ => - constructMergeTree(pairs(l)) - } - } ensuring {res => - res.size <= 1 && res.fullSize == l.fullSize && - (res match { - case LCons(il, LNil()) => - res.fullSize == ssize(il) // this is implied by the previous conditions - case _ => true - }) && - res.valid && - time <= ? * l.size + ?} - - /** - * A function that merges two sorted streams of integers. - * Note: the sorted stream of integers may by recursively constructed using merge. - * Takes time linear in the size of the streams (non-trivial to prove due to cascading of lazy calls) - */ - @invisibleBody - @usePost - def merge(a: Lazy[IStream], b: Lazy[IStream]): IStream = { - require(((a*) != SNil() || b.isEvaluated) && // if one of the arguments is Nil then the other is evaluated - ((b*) != SNil() || a.isEvaluated) && - ((a*) != SNil() || (b*) != SNil())) // at least one of the arguments is not Nil - b.value match { - case SNil() => a.value - case bl @ SCons(x, xs) => - a.value match { - case SNil() => bl - case SCons(y, ys) => - if (y < x) - SCons(y, $(merge(ys, b))) - else - SCons(x, $(merge(a, xs))) - } - } - } ensuring (res => ssize(a) + ssize(b) == res.size && - //time <= ? * res.size + ?) // note: res.size >= 1 // here stack is max of a and b - time <= 67 * res.size - 47) // Orb cannot infer this due to issues with CVC4 set solving ! - - /** - * Converts a list of integers to a list of streams of integers - */ - val nilStream: IStream = SNil() - - @invisibleBody - def IListToLList(l: IList): LList = { - l match { - case INil() => LNil() - case ICons(x, xs) => - LCons(SCons(x, nilStream), IListToLList(xs)) - } - } ensuring { res => - res.fullSize == l.size && - res.size == l.size && - res.valid && - time <= ? * l.size + ? - } - - /** - * Takes list of integers and returns a sorted stream of integers. - * Takes time linear in the size of the input since it sorts lazily. - */ - def mergeSort(l: IList): IStream = { - l match { - case INil() => SNil() - case _ => - constructMergeTree(IListToLList(l)) match { - case LCons(r, LNil()) => r.value - } - } - } ensuring (res => time <= ? * l.size + ?) - - /** - * A function that accesses the first element of a list using lazy sorting. - */ - def firstMin(l: IList) : BigInt ={ - require(l != INil()) - mergeSort(l) match { - case SCons(x, rest) => x - } - } ensuring (res => time <= ? * l.size + ?) - - def kthMin(l: IStream, k: BigInt): BigInt = { - require(k >= 0) - l match { - case SCons(x, xs) => - if (k == 0) x - else - kthMin(xs.value, k - 1) - case SNil() => BigInt(0) - } - } //ensuring (_ => time <= ? * (k * ssize(l)) + ? * k + ?) - - @ignore - def main(args: Array[String]) { - //import eagerEval.MergeSort - import scala.util.Random - import scala.math.BigInt - import stats._ - import collection._ - - println("Running merge sort test...") - val length = 3000000 - val maxIndexValue = 100 - val randomList = Random.shuffle((0 until length).toList) - val l1 = randomList.foldRight(List[BigInt]()){ - case (i, acc) => BigInt(i) :: acc - } - val l2 = randomList.foldRight(INil(): IList){ - case (i, acc) => ICons(BigInt(i), acc) - } - println(s"Created inputs of size (${l1.size},${l2.size}), starting operations...") - val sort2 = timed{ mergeSort(l2) }{t => println(s"Lazy merge sort completed in ${t/1000.0} sec") } - //val sort1 = timed{ MergeSort.msort((x: BigInt, y: BigInt) => x <= y)(l1) } {t => println(s"Eager merge sort completed in ${t/1000.0} sec") } - // sample 10 elements from a space of [0-100] - val rand = Random - var totalTime1 = 0L - var totalTime2 = 0L - for(i <- 0 until 10) { - val idx = rand.nextInt(maxIndexValue) - //val e1 = timed { sort1(idx) } { totalTime1 +=_ } - val e2 = timed { kthMin(sort2, idx) }{ totalTime2 += _ } - //println(s"Element at index $idx - Eager: $e1 Lazy: $e2") - //assert(e1 == e2) - } - println(s"Time-taken to pick first 10 minimum elements - Eager: ${totalTime1/1000.0}s Lazy: ${totalTime2/1000.0}s") - } -} diff --git a/testcases/lazy-datastructures/withOrb/Concat.scala b/testcases/lazy-datastructures/withOrb/Concat.scala deleted file mode 100644 index b9653b5224a19298684e39bb6e3de401815cb40b..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/Concat.scala +++ /dev/null @@ -1,77 +0,0 @@ -package withOrb - -import leon._ -import lazyeval._ -import lazyeval.Lazy._ -import lang._ -import annotation._ -import instrumentation._ -import collection._ -import invariant._ - -object Concat { - sealed abstract class LList[T] { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + ssize(t) - } - } ensuring (_ >= 0) - } - case class SCons[T](x: T, tail: Lazy[LList[T]]) extends LList[T] - case class SNil[T]() extends LList[T] - def ssize[T](l: Lazy[LList[T]]): BigInt = (l*).size - - def concat[T](l1: List[T], l2: List[T]): LList[T] = { - l1 match { - case Cons(x, xs) => SCons(x, $(concat(xs, l2))) - case Nil() => SNil[T]() - } - } ensuring { _ => time <= ? } - - def kthElem[T](l: Lazy[LList[T]], k: BigInt): Option[T] = { - require(k >= 0) - l.value match { - case SCons(x, xs) => - if (k == 0) Some(x) - else - kthElem(xs, k - 1) - case SNil() => None[T] - } - } ensuring (_ => time <= ? * k + ?) - - def concatnSelect[T](l1: List[T], l2: List[T], k: BigInt): Option[T] = { - require(k >= 0) - kthElem($(concat(l1, l2)), k) - } ensuring (_ => time <= ? * k + ?) - - @ignore - def main(args: Array[String]) = { - import stats._ - println("Running concat test...") - val length = 1000000 - val k = 10 - val iterCount = 10 - val l1 = (0 until length).foldRight(List[BigInt]()) { - case (i, acc) => i :: acc - } - val l2 = (0 until length).foldRight(List[BigInt]()) { - case (i, acc) => 2 * i :: acc - } - println("Created inputs, starting operations...") - def iterate[T](op: => BigInt) = { - var res = BigInt(0) - var i = iterCount - while (i > 0) { - res = op - i -= 1 - } - res - } - val elem1 = timed { iterate((l1 ++ l2)(k)) } { t => println(s"Eager Concat completed in ${t / 1000.0} sec") } - println(s"$k th element of concatenated list: $elem1") - val elem2 = timed { iterate(concatnSelect(l1, l2, k).get) } { t => println(s"Lazy ConcatnSelect completed in ${t / 1000.0} sec") } - println(s"$k th element of concatenated list: $elem2") - assert(elem1 == elem2) - } -} diff --git a/testcases/lazy-datastructures/withOrb/Deque.scala b/testcases/lazy-datastructures/withOrb/Deque.scala deleted file mode 100644 index 38daf01442f4b12d9b7c39f4e6abf8f3e677186a..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/Deque.scala +++ /dev/null @@ -1,411 +0,0 @@ -package withOrb - -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import collection._ -import instrumentation._ -import math._ -import invariant._ - -/** - * A constant time deque based on Okasaki's implementation: Fig.8.4 Pg. 112. - * Here, both front and rear streams are scheduled. - * We require both the front and the rear streams to be of almost equal - * size. If not, we lazily rotate the streams. - * The invariants are a lot more complex than in `RealTimeQueue`. - * The program also fixes a bug in Okasaki's implementatin: see function `rotateDrop` - */ -object RealTimeDeque { - - sealed abstract class Stream[T] { - @inline - def isEmpty: Boolean = { - this match { - case SNil() => true - case _ => false - } - } - - @inline - def isCons: Boolean = { - this match { - case SCons(_, _) => true - case _ => false - } - } - - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + (t*).size - } - } ensuring (_ >= 0) - } - case class SCons[T](x: T, tail: Lazy[Stream[T]]) extends Stream[T] - case class SNil[T]() extends Stream[T] - - @inline - def ssize[T](l: Lazy[Stream[T]]): BigInt = (l*).size - - def isConcrete[T](l: Lazy[Stream[T]]): Boolean = { - l.isEvaluated && (l* match { - case SCons(_, tail) => - isConcrete(tail) - case _ => true - }) - } - - @invstate - def takeLazy[T](n: BigInt, l: Lazy[Stream[T]]): Stream[T] = { - require(isConcrete(l) && n >= 1 && ssize(l) >= n) - l.value match { - case SCons(x, tail) => - if (n == 1) - SCons[T](x, SNil[T]()) - else - SCons[T](x, $(takeLazy(n - 1, tail))) - } - } ensuring(res => res.size == n && res.isCons && - time <= ?) - - @invstate - def revAppend[T](l1: Lazy[Stream[T]], l2: Lazy[Stream[T]]): Lazy[Stream[T]] = { - require(isConcrete(l1) && isConcrete(l2)) - l1.value match { - case SNil() => l2 - case SCons(x, tail) => - val nt: Lazy[Stream[T]] = SCons[T](x, l2) - revAppend(tail, nt) - } - } ensuring(res => ssize(res) == ssize(l1) + ssize(l2) && - isConcrete(res) && - (ssize(l1) >= 1 ==> (res*).isCons) && - time <= ? * ssize(l1) + ?) - - @invstate - def drop[T](n: BigInt, l: Lazy[Stream[T]]): Lazy[Stream[T]] = { - require(n >= 0 && isConcrete(l) && ssize(l) >= n) - if (n == 0) { - l - } else { - l.value match { - case SNil() => l - case SCons(x, tail) => drop(n - 1, tail) - } - } - } ensuring(res => isConcrete(res) && - ssize(res) == ssize(l) - n && - time <= ? * n + ?) - - @invstate - def take[T](n: BigInt, l: Lazy[Stream[T]]): Lazy[Stream[T]] = { - require(n >= 0 && isConcrete(l) && ssize(l) >= n) - val r: Lazy[Stream[T]] = - if (n == 0) { - SNil[T]() - } else { - l.value match { - case SNil() => l - case SCons(x, tail) => - SCons[T](x, take(n - 1, tail)) - } - } - r - } ensuring(res => isConcrete(res) && - ssize(res) == n && - time <= ? * n + ?) - - @invstate - def rotateRev[T](r: Lazy[Stream[T]], f: Lazy[Stream[T]], a: Lazy[Stream[T]]): Stream[T] = { - require(isConcrete(r) && isConcrete(f) && isConcrete(a) && - { - val lenf = ssize(f) - val lenr = ssize(r) - (lenf <= 2 * lenr + 3 && lenf >= 2 * lenr + 1) - }) - r.value match { - case SNil() => revAppend(f, a).value // |f| <= 3 - case SCons(x, rt) => - SCons(x, $(rotateRev(rt, drop(2, f), revAppend(take(2, f), a)))) - } // here, it doesn't matter whether 'f' has i elements or not, what we want is |drop(2,f)| + |take(2,f)| == |f| - } ensuring (res => res.size == (r*).size + (f*).size + (a*).size && - res.isCons && - time <= ?) - - @invstate - def rotateDrop[T](r: Lazy[Stream[T]], i: BigInt, f: Lazy[Stream[T]]): Stream[T] = { - require(isConcrete(r) && isConcrete(f) && i >= 0 && { - val lenf = ssize(f) - val lenr = ssize(r) - (lenf >= 2 * lenr + 2 && lenf <= 2 * lenr + 3) && // size invariant between 'f' and 'r' - lenf > i - }) - val rval = r.value - if(i < 2 || rval == SNil[T]()) { // A bug in Okasaki implementation: we must check for: 'rval = SNil()' - val a: Lazy[Stream[T]] = SNil[T]() - rotateRev(r, drop(i, f), a) - } else { - rval match { - case SCons(x, rt) => - SCons(x, $(rotateDrop(rt, i - 2, drop(2, f)))) - } - } - } ensuring(res => res.size == (r*).size + (f*).size - i && - res.isCons && time <= ?) - - def firstUneval[T](l: Lazy[Stream[T]]): Lazy[Stream[T]] = { - if (l.isEvaluated) { - l* match { - case SCons(_, tail) => - firstUneval(tail) - case _ => l - } - } else - l - } ensuring (res => (!(res*).isEmpty || isConcrete(l)) && - ((res*).isEmpty || !res.isEvaluated) && // if the return value is not a Nil closure then it would not have been evaluated - (res.value match { - case SCons(_, tail) => - firstUneval(l) == firstUneval(tail) // after evaluating the firstUneval closure in 'l' we can access the next unevaluated closure - case _ => true - })) - - case class Queue[T](f: Lazy[Stream[T]], lenf: BigInt, sf: Lazy[Stream[T]], - r: Lazy[Stream[T]], lenr: BigInt, sr: Lazy[Stream[T]]) { - def isEmpty = lenf + lenr == 0 - def valid = { - (firstUneval(f) == firstUneval(sf)) && - (firstUneval(r) == firstUneval(sr)) && - (lenf == ssize(f) && lenr == ssize(r)) && - (lenf <= 2*lenr + 1 && lenr <= 2*lenf + 1) && - { - val mind = min(2*lenr-lenf+2, 2*lenf-lenr+2) - ssize(sf) <= mind && ssize(sr) <= mind - } - } - } - - /** - * A function that takes streams where the size of front and rear streams violate - * the balance invariant, and restores the balance. - */ - @invisibleBody - def createQueue[T](f: Lazy[Stream[T]], lenf: BigInt, sf: Lazy[Stream[T]], - r: Lazy[Stream[T]], lenr: BigInt, sr: Lazy[Stream[T]]): Queue[T] = { - require(firstUneval(f) == firstUneval(sf) && - firstUneval(r) == firstUneval(sr) && - (lenf == ssize(f) && lenr == ssize(r)) && - ((lenf - 1 <= 2*lenr + 1 && lenr <= 2*lenf + 1) || - (lenf <= 2*lenr + 1 && lenr - 2 <= 2*lenf + 1)) && - { - val mind = max(min(2*lenr-lenf+2, 2*lenf-lenr+2), 0) - ssize(sf) <= mind && ssize(sr) <= mind - }) - if(lenf > 2*lenr + 1) { - val i = (lenf + lenr) / 2 - val j = lenf + lenr - i - val nr = rotateDrop(r, i, f) - val nf = takeLazy(i, f) - Queue(nf, i, nf, nr, j, nr) - } else if(lenr > 2*lenf + 1) { - val i = (lenf + lenr) / 2 - val j = lenf + lenr - i - val nf = rotateDrop(f, j, r) // here, both 'r' and 'f' are concretized - val nr = takeLazy(j, r) - Queue(nf, i, nf, nr, j, nr) - } else - Queue(f, lenf, sf, r, lenr, sr) - } ensuring(res => res.valid && - time <= ?) - - @invisibleBody - def funeEqual[T](s1: Lazy[Stream[T]], s2: Lazy[Stream[T]]) = firstUneval(s1) == firstUneval(s2) - - /** - * Forces the schedules, and ensures that `firstUneval` equality is preserved - */ - @invisibleBody - def force[T](tar: Lazy[Stream[T]], htar: Lazy[Stream[T]], other: Lazy[Stream[T]], hother: Lazy[Stream[T]]): Lazy[Stream[T]] = { - require(funeEqual(tar, htar) && funeEqual(other, hother)) - tar.value match { - case SCons(_, tail) => tail - case _ => tar - } - } ensuring (res => { - //lemma instantiations - val in = inState[Stream[T]] - val out = outState[Stream[T]] - funeMonotone(tar, htar, in, out) && - funeMonotone(other, hother, in, out) && { - //properties - val rsize = ssize(res) - firstUneval(htar) == firstUneval(res) && // follows from post of fune - firstUneval(other) == firstUneval(hother) && - (rsize == 0 || rsize == ssize(tar) - 1) - } && time <= ? - }) - - /** - * Forces the schedules in the queue twice and ensures the `firstUneval` property. - */ - @invisibleBody - def forceTwice[T](q: Queue[T]): (Lazy[Stream[T]], Lazy[Stream[T]]) = { - require(q.valid) - val nsf = force(force(q.sf, q.f, q.r, q.sr), q.f, q.r, q.sr) // forces q.sf twice - val nsr = force(force(q.sr, q.r, q.f, nsf), q.r, q.f, nsf) // forces q.sr twice - (nsf, nsr) - } ensuring(_ => time <= ?) - // the following properties are ensured, but need not be stated - /*ensuring (res => { - val nsf = res._1 - val nsr = res._2 - firstUneval(q.f) == firstUneval(nsf) && - firstUneval(q.r) == firstUneval(nsr) && - (ssize(nsf) == 0 || ssize(nsf) == ssize(q.sf) - 2) && - (ssize(nsr) == 0 || ssize(nsr) == ssize(q.sr) - 2) && - time <= 1500 - })*/ - - def empty[T] = { - val nil: Lazy[Stream[T]] = SNil[T]() - Queue(nil, 0, nil, nil, 0, nil) - } - - def head[T](q: Queue[T]): T = { - require(!q.isEmpty && q.valid) - (q.f.value, q.r.value) match { - case (SCons(x, _), _) => x - case (_, SCons(x, _)) => x - } - } - - /** - * Adding an element to the front of the list - */ - def cons[T](x: T, q: Queue[T]): Queue[T] = { - require(q.valid) - val nf: Stream[T] = SCons[T](x, q.f) - // force the front and rear scheds once - val nsf = force(q.sf, q.f, q.r, q.sr) - val nsr = force(q.sr, q.r, q.f, nsf) - createQueue(nf, q.lenf + 1, nsf, q.r, q.lenr, nsr) - } ensuring (res => res.valid && time <= ?) - - /** - * Removing the element at the front, and returning the tail - */ - def tail[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.valid) - force(q.f, q.sf, q.r, q.sr) match { // force 'f' - case _ => - tailSub(q) - } - } ensuring(res => res.valid && time <= ?) - - def tailSub[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.valid && q.f.isEvaluated) - q.f.value match { - case SCons(x, nf) => - val (nsf, nsr) = forceTwice(q) - // here, sf and sr got smaller by 2 holds, the schedule invariant still holds - createQueue(nf, q.lenf - 1, nsf, q.r, q.lenr, nsr) - case SNil() => - // in this case 'r' will have only one element by invariant - empty[T] - } - } ensuring(res => res.valid && time <= ?) - - /** - * Reversing a list. Takes constant time. - * This implies that data structure is a `deque`. - */ - def reverse[T](q: Queue[T]): Queue[T] = { - require(q.valid) - Queue(q.r, q.lenr, q.sr, q.f, q.lenf, q.sf) - } ensuring(_ => q.valid && time <= ?) - - def snoc[T](x: T, q: Queue[T]): Queue[T] = { - require(q.valid) - reverse(cons(x, reverse(q))) - } - - // Properties of `firstUneval`. We use `fune` as a shorthand for `firstUneval` - /** - * st1.subsetOf(st2) ==> fune(l, st2) == fune(fune(l, st1), st2) - */ - @traceInduct - def funeCompose[T](l1: Lazy[Stream[T]], st1: Set[Lazy[Stream[T]]], st2: Set[Lazy[Stream[T]]]): Boolean = { - require(st1.subsetOf(st2)) - // property - (firstUneval(l1) withState st2) == (firstUneval(firstUneval(l1) withState st1) withState st2) - } holds - - /** - * st1.subsetOf(st2) && fune(la,st1) == fune(lb,st1) ==> fune(la,st2) == fune(lb,st2) - * The `fune` equality is preseved by evaluation of lazy closures. - * This is a kind of frame axiom for `fune` but is slightly different in that - * it doesn't require (st2 \ st1) to be disjoint from la and lb. - */ - def funeMonotone[T](l1: Lazy[Stream[T]], l2: Lazy[Stream[T]], st1: Set[Lazy[Stream[T]]], st2: Set[Lazy[Stream[T]]]): Boolean = { - require((firstUneval(l1) withState st1) == (firstUneval(l2) withState st1) && - st1.subsetOf(st2)) - funeCompose(l1, st1, st2) && // lemma instantiations - funeCompose(l2, st1, st2) && - // induction scheme - (if (l1.isEvaluated withState st1) { - l1* match { - case SCons(_, tail) => - funeMonotone(tail, l2, st1, st2) - case _ => true - } - } else true) && - (firstUneval(l1) withState st2) == (firstUneval(l2) withState st2) // property - } holds - - @ignore - def main(args: Array[String]) { - //import eagerEval.AmortizedQueue - import scala.util.Random - import scala.math.BigInt - import stats._ - import collection._ - - println("Running Deque test...") - val ops = 2000000 - val rand = Random - // initialize to a queue with one element (required to satisfy preconditions of dequeue and front) - var rtd = empty[BigInt] - //var amq = AmortizedQueue.Queue(AmortizedQueue.Nil(), AmortizedQueue.Nil()) - var totalTime1 = 0L - var totalTime2 = 0L - println(s"Testing amortized emphemeral behavior on $ops operations...") - for (i <- 0 until ops) { - if (!rtd.isEmpty) { - val h1 = head(rtd) - //val h2 = amq.head - //assert(h1 == h2, s"Eager head: $h2 Lazy head: $h1") - } - rand.nextInt(3) match { - case x if x == 0 => //add to rear - //println("Enqueue..") - rtd = timed { snoc(BigInt(i), rtd) } { totalTime1 += _ } - //amq = timed { amq.enqueue(BigInt(i)) } { totalTime2 += _ } - case x if x == 1 => // remove from front - if (!rtd.isEmpty) { - //if(i%100000 == 0) - //println("Dequeue..") - rtd = timed { tail(rtd) } { totalTime1 += _ } - //amq = timed { amq.dequeue } { totalTime2 += _ } - } - case x if x == 2 => // reverse - //if(i%100000 == 0) - //println("reverse..") - rtd = timed { reverse(rtd) } { totalTime1 += _ } - //amq = timed { amq.reverse } { totalTime2 += _ } - } - } - println(s"Ephemeral Amortized Time - Eager: ${totalTime2/1000.0}s Lazy: ${totalTime1/1000.0}s") - } -} diff --git a/testcases/lazy-datastructures/withOrb/Esop15Benchmarks.scala b/testcases/lazy-datastructures/withOrb/Esop15Benchmarks.scala deleted file mode 100644 index 45d520dcf67579ddccb94c3f2d95278a16896e93..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/Esop15Benchmarks.scala +++ /dev/null @@ -1,58 +0,0 @@ -package withorb - -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import instrumentation._ -import collection._ -import invariant._ - -/** - * This file is the collection of programs in the ESOP 2015 paper. - * Note this benchmark is very good for finding counter-examples.s - * Decreasing the time bounds slightly will display counter-examples. - */ -object Esop15Benchmarks { - sealed abstract class IStream - case class SCons(x: BigInt, tail: Lazy[IStream]) extends IStream - case class SNil() extends IStream - - sealed abstract class StreamPairs - case class PCons(pair: (BigInt, BigInt), tail: Lazy[StreamPairs]) extends StreamPairs - case class PNil() extends StreamPairs - - def zipWith(xs: Lazy[IStream], ys: Lazy[IStream]): StreamPairs = { - (xs.value, ys.value) match { - case (SCons(x, xtail), SCons(y, ytail)) => - PCons((x, y), $(zipWith(xtail, ytail))) - case _ => - PNil() - } - } ensuring(_ => time <= ?) - - def nextFib(x: BigInt, y: BigInt, n: BigInt): IStream = { - if (n <= 0) - SNil() - else { - val next = x + y - SCons(next, $(nextFib(y, next, n - 1))) - } - } ensuring(_ => time <= ?) - - def fibStream(n: BigInt) : IStream = { - SCons(0, SCons(1, $(nextFib(0, 1, n)))) - } - - def nthFib(n: BigInt, fs: Lazy[IStream]): BigInt = { - require(n >= 0) - fs.value match { - case SCons(x, tail) => - if (n == 0) - x - else - nthFib(n - 1, tail) - case SNil() => BigInt(-1) - } - } ensuring(_ => time <= ? * n + ?) // you get a counter-example for 20*n + 20 -} \ No newline at end of file diff --git a/testcases/lazy-datastructures/withOrb/FibonacciMemoized.scala b/testcases/lazy-datastructures/withOrb/FibonacciMemoized.scala deleted file mode 100644 index db9db04212e5ee2dcd98ac37fd11b95ba4d3c9b1..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/FibonacciMemoized.scala +++ /dev/null @@ -1,31 +0,0 @@ -package withOrb - -import leon._ -import mem._ -import lang._ -import annotation._ -import instrumentation._ -import invariant._ -import Mem._ - -object FibMem { - sealed abstract class IList - case class Cons(x: BigInt, tail: IList) extends IList - case class Nil() extends IList - - @memoize - def fibRec(n: BigInt): BigInt = { - require(n >= 0) - if (n <= 2) - BigInt(1) - else - fibRec(n - 1) + fibRec(n - 2) // postcondition implies that the second call would be cached - } ensuring (_ => - (n <= 2 || (fibRec(n - 1).isCached && - fibRec(n - 2).isCached)) && time <= ? * n + ?) - - @ignore - def main(args: Array[String]) { - println("32nd fibonnacci number: " + fibRec(50)) - } -} diff --git a/testcases/lazy-datastructures/withOrb/HammingMemoized.scala b/testcases/lazy-datastructures/withOrb/HammingMemoized.scala deleted file mode 100644 index 65192934bb0f87128e9e6a8c8e64d436cd9ecd62..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/HammingMemoized.scala +++ /dev/null @@ -1,105 +0,0 @@ -package withOrb - -import leon._ -import mem._ -import lang._ -import annotation._ -import instrumentation._ -import invariant._ - -/** - * A memoized version of the implementation of Hamming problem shown in - * section 4.3 of Type-based allocation analysis for Co-recursion - */ -object Hamming { - sealed abstract class IList - case class Cons(x: BigInt, tail: IList) extends IList { - @ignore - override def toString: String = { - if(tail == Nil()) x.toString - else x.toString + "," + tail.toString - } - } - case class Nil() extends IList { - @ignore - override def toString = "" - } - - case class Data(v: BigInt, i2: BigInt, i3: BigInt, i5: BigInt) - - @invstate - @memoize - def ham(n: BigInt): Data = { - require(n ==0 || (n > 0 && depsEval(n - 1))) - if(n == BigInt(0)) Data(1, 0, 0, 0) - else { - val Data(x, i2, i3, i5) = ham(n-1) - val a = ham(i2).v * 2 - val b = ham(i3).v * 3 - val c = ham(i5).v * 5 - val (v, ni, nj, nk) = threeWayMerge(a, b, c, i2, i3, i5) - Data(v, ni, nj, nk) - } - } ensuring(res => res.i2 <= n && res.i3 <= n && res.i5 <= n && - res.i3 >= 0 && res.i5 >= 0 && res.i2 >= 0 && - depsLem(res.i2, n) && depsLem(res.i3, n) && depsLem(res.i5, n) && // instantiations - time <= ?) - - def depsEval(i: BigInt): Boolean = { - require(i >= 0) - ham(i).isCached && (if (i <= 0) true else depsEval(i - 1)) - } - - @traceInduct - def depsEvalMono(i: BigInt, st1: Set[Mem[Data]], st2: Set[Mem[Data]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (depsEval(i) withState st1)) ==> (depsEval(i) withState st2) - } holds - - @traceInduct - def depsLem(x: BigInt, y: BigInt) = { - require(x >= 0 && y >= 0) - (x <= y && depsEval(y)) ==> depsEval(x) - } holds - - def invoke(n: BigInt) = { - require(n == 0 || n > 0 && depsEval(n - 1)) - ham(n).v - } ensuring (res => { - val in = inState[Data] - val out =outState[Data] - (n == 0 || depsEvalMono(n-1, in, out)) && // instantiation - time <= ? - }) - - /** - * Returns a list of hamming numbers upto 'n' - */ - def hammingList(n: BigInt): IList = { - require(n >= 0) - if(n == 0) { - Cons(invoke(n), Nil()) - } else { - val tailRes = hammingList(n-1) - Cons(invoke(n), tailRes) - } - } ensuring(_ => depsEval(n) && time <= ? * (n + 1)) - - @inline - def threeWayMerge(a: BigInt, b: BigInt, c: BigInt, i2: BigInt, i3: BigInt, i5: BigInt) = { - if(a == b && b == c) (a, i2 + 1, i3 + 1, i5 + 1) - else if(a == b && a < c) (a, i2 + 1, i3 + 1, i5 ) - else if(a == c && a < b) (a, i2 + 1, i3 , i5 + 1) - else if(b == c && b < a) (b, i2 , i3 + 1, i5 + 1) - else if(a < b && a < c) (a, i2 + 1, i3 , i5 ) - else if(b < c && b < a) (b, i2 , i3 + 1, i5 ) - else/*if(c < a && c < b)*/(c, i2 , i3 , i5 + 1) - } - - @ignore - def main(args: Array[String]) { - import collection._ - val hlist = hammingList(100) // without memoization this will take too long - println("Hamming numbers: "+hlist) - } -} diff --git a/testcases/lazy-datastructures/withOrb/Knapsack.scala b/testcases/lazy-datastructures/withOrb/Knapsack.scala deleted file mode 100644 index 8eb64d369dbe2ef198508103d4790ae51c37ef3a..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/Knapsack.scala +++ /dev/null @@ -1,132 +0,0 @@ -package wihtOrb - -import leon._ -import mem._ -import lang._ -import annotation._ -import instrumentation._ -import invariant._ - -object Knapscak { - sealed abstract class IList { - def size: BigInt = { - this match { - case Cons(_, tail) => 1 + tail.size - case Nil() => BigInt(0) - } - } ensuring(_ >= 0) - } - case class Cons(x: (BigInt, BigInt), tail: IList) extends IList { // a list of pairs of weights and values - @ignore - override def toString: String = { - if(tail == Nil()) x.toString - else x.toString + "," + tail.toString - } - } - case class Nil() extends IList { - @ignore - override def toString = "" - } - - def deps(i: BigInt, items: IList): Boolean = { - require(i >= 0) - knapSack(i, items).isCached && // if we have the cached check only along the else branch, we would get a counter-example. - (if (i <= 0) true - else { - deps(i - 1, items) - }) - } - - @invstate - def maxValue(items: IList, w: BigInt, currList: IList): BigInt = { - require((w ==0 || (w > 0 && deps(w - 1, items))) && - // lemma inst - (currList match { - case Cons((wi, vi), _) => - if (wi <= w && wi > 0) depsLem(w - wi, w - 1, items) - else true - case Nil() => true - })) - currList match { - case Cons((wi, vi), tail) => - val oldMax = maxValue(items, w, tail) - if (wi <= w && wi > 0) { - val choiceVal = vi + knapSack(w - wi, items) - if (choiceVal >= oldMax) - choiceVal - else - oldMax - } else oldMax - case Nil() => BigInt(0) - } - } ensuring(_ => time <= ? * currList.size + ?) // interchanging currList and items in the bound will produce a counter-example - - @memoize - def knapSack(w: BigInt, items: IList): BigInt = { - require(w >= 0 && (w == 0 || deps(w - 1, items))) - if (w == 0) BigInt(0) - else { - maxValue(items, w, items) - } - } ensuring(_ => time <= ? * items.size + ?) - - def invoke(i: BigInt, items: IList) = { - require(i == 0 || (i > 0 && deps(i - 1, items))) - knapSack(i, items) - } ensuring (res => { - (i == 0 || depsMono(i - 1, items, inState[BigInt], outState[BigInt]) && // lemma inst - deps(i - 1, items)) && - time <= ? * items.size + ? - }) - - def bottomup(i: BigInt, w: BigInt, items: IList): IList = { - require(w >= i && (i == 0 || i > 0 && deps(i - 1, items))) - val ri = invoke(i, items) - if (i == w) - Cons((i,ri), Nil()) - else { - Cons((i,ri), bottomup(i + 1, w, items)) - } - } ensuring(_ => items.size <= 10 ==> time <= ? * (w - i + 1)) - - /** - * Computes the list of optimal solutions of all weights up to 'w' - */ - def knapSackSol(w: BigInt, items: IList) = { - require(w >= 0 && items.size <= 10) // the second requirement is only to keep the bounds linear for z3 to work - bottomup(0, w, items) - } ensuring(_ => time <= ? * w + ?) - - /** - * Lemmas of deps - */ - // deps is monotonic - @traceInduct - def depsMono(i: BigInt, items: IList, st1: Set[Mem[BigInt]], st2: Set[Mem[BigInt]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (deps(i, items) withState st1)) ==> (deps(i, items) withState st2) - } holds - - // forall. x, x <= y && deps(y) => deps(x) - @traceInduct - def depsLem(x: BigInt, y: BigInt, items: IList) = { - require(x >= 0 && y >= 0) - (x <= y && deps(y, items)) ==> deps(x, items) - } holds - - @ignore - def main(args: Array[String]) { - import scala.util.Random - // pick some random weights and values - val weightsnValues1 = (1 to 10).foldRight(Nil(): IList){ - case (i, acc) => Cons((i, i), acc) - } - val reslist1 = knapSackSol(100, weightsnValues1) // without memoization this will take too long - println("Optimal solutions: "+reslist1.toString) - val weightsnValues2 = ((1 to 10) zip (10 to 1 by -1)).foldRight(Nil(): IList){ - case ((i, j), acc) => Cons((i, j), acc) - } - val reslist2 = knapSackSol(100, weightsnValues2) - println("Optimal solutions for set 2: "+reslist2.toString) - } -} diff --git a/testcases/lazy-datastructures/withOrb/LazyNumericalRep.scala b/testcases/lazy-datastructures/withOrb/LazyNumericalRep.scala deleted file mode 100644 index b3c5a205fd392de97bc653a5750698197b825239..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/LazyNumericalRep.scala +++ /dev/null @@ -1,535 +0,0 @@ -package withOrb - -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import instrumentation._ -import invariant._ - -object DigitObject { - sealed abstract class Digit - case class Zero() extends Digit { - @ignore - override def toString = "0" - } - case class One() extends Digit { - @ignore - override def toString = "1" - } -} - -import DigitObject._ -object LazyNumericalRep { - - sealed abstract class NumStream { - val isSpine: Boolean = this match { - case Spine(_, _, _) => true - case _ => false - } - val isTip = !isSpine - } - - case class Tip() extends NumStream - case class Spine(head: Digit, createdWithSuspension: Bool, rear: Lazy[NumStream]) extends NumStream - - sealed abstract class Bool - case class True() extends Bool - case class False() extends Bool - - /** - * Checks whether there is a zero before an unevaluated closure - */ - def zeroPrecedeLazy[T](q: Lazy[NumStream]): Boolean = { - if (q.isEvaluated) { - q* match { - case Spine(Zero(), _, rear) => - true // here we have seen a zero - case Spine(_, _, rear) => - zeroPrecedeLazy(rear) //here we have not seen a zero - case Tip() => true - } - } else false - } - - /** - * Checks whether there is a zero before a given suffix - */ - def zeroPrecedeSuf[T](q: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - if (q != suf) { - q* match { - case Spine(Zero(), _, rear) => true - case Spine(_, _, rear) => - zeroPrecedeSuf(rear, suf) - case Tip() => false - } - } else false - } - - /** - * Everything until suf is evaluated. This - * also asserts that suf should be a suffix of the list - */ - def concreteUntil[T](l: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - if (l != suf) { - l.isEvaluated && (l* match { - case Spine(_, cws, tail) => - concreteUntil(tail, suf) - case _ => - false - }) - } else true - } - - def isConcrete[T](l: Lazy[NumStream]): Boolean = { - l.isEvaluated && (l* match { - case Spine(_, _, tail) => - isConcrete(tail) - case _ => true - }) - } - - sealed abstract class Scheds - case class Cons(h: Lazy[NumStream], tail: Scheds) extends Scheds - case class Nil() extends Scheds - - def schedulesProperty[T](q: Lazy[NumStream], schs: Scheds): Boolean = { - schs match { - case Cons(head, tail) => - head* match { - case Spine(Zero(), _, _) => // head starts with zero - head.isSuspension(incLazy _) && - concreteUntil(q, head) && - schedulesProperty(pushUntilCarry(head), tail) - case _ => - false - } - case Nil() => - isConcrete(q) - } - } - - @invisibleBody - def strongSchedsProp[T](q: Lazy[NumStream], schs: Scheds) = { - q.isEvaluated && { - schs match { - case Cons(head, tail) => - zeroPrecedeSuf(q, head) // zeroPrecedeSuf holds initially - case Nil() => true - } - } && - schedulesProperty(q, schs) - } - - /** - * Note: if 'q' has a suspension then it would have a carry. - */ - @invisibleBody - def pushUntilCarry[T](q: Lazy[NumStream]): Lazy[NumStream] = { - q* match { - case Spine(Zero(), _, rear) => // if we push a carry and get back 0 then there is a new carry - pushUntilCarry(rear) - case Spine(_, _, rear) => // if we push a carry and get back 1 then there the carry has been fully pushed - rear - case Tip() => - q - } - } - - case class Number(digs: Lazy[NumStream], schedule: Scheds) { - def isEmpty = digs.value.isTip - - def valid = strongSchedsProp(digs, schedule) - } - - def emptyNum = Number(Tip(), Nil()) - - @invisibleBody - def inc(xs: Lazy[NumStream]): NumStream = { - require(zeroPrecedeLazy(xs)) - xs.value match { - case Tip() => - Spine(One(), False(), xs) - case s @ Spine(Zero(), _, rear) => - Spine(One(), False(), rear) - case s @ Spine(_, _, _) => - incLazy(xs) - } - } ensuring (_ => time <= ?) - - @invisibleBody - @invstate - def incLazy(xs: Lazy[NumStream]): NumStream = { - require(zeroPrecedeLazy(xs) && - (xs* match { - case Spine(h, _, _) => h != Zero() // xs doesn't start with a zero - case _ => false - })) - xs.value match { - case Spine(head, _, rear) => // here, rear is guaranteed to be evaluated by 'zeroPrecedeLazy' invariant - val carry = One() - rear.value match { - case s @ Spine(Zero(), _, srear) => - val tail: NumStream = Spine(carry, False(), srear) - Spine(Zero(), False(), tail) - - case s @ Spine(_, _, _) => - Spine(Zero(), True(), $(incLazy(rear))) - - case t @ Tip() => - val y: NumStream = Spine(carry, False(), rear) - Spine(Zero(), False(), y) - } - } - } ensuring { res => - (res match { - case Spine(Zero(), _, rear) => - (!isConcrete(xs) || isConcrete(pushUntilCarry(rear))) && - { - val _ = rear.value // this is necessary to assert properties on the state in the recursive invocation (and note this cannot go first) - rear.isEvaluated // this is a tautology - } - case _ => - false - }) && - time <= ? - } - - /** - * Lemma: - * forall suf. suf*.head != Zero() ^ zeroPredsSuf(xs, suf) ^ concUntil(xs.tail.tail, suf) => concUntil(push(rear), suf) - */ - @invisibleBody - @invstate - def incLazyLemma[T](xs: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - require(zeroPrecedeSuf(xs, suf) && - (xs* match { - case Spine(h, _, _) => h != Zero() - case _ => false - }) && - (suf* match { - case Spine(Zero(), _, _) => - concreteUntil(xs, suf) - case _ => false - })) - // induction scheme - (xs* match { - case Spine(head, _, rear) => - rear* match { - case s @ Spine(h, _, _) => - if (h != Zero()) - incLazyLemma(rear, suf) - else true - case _ => true - } - }) && - // instantiate the lemma that implies zeroPrecedeLazy - (if (zeroPredSufConcreteUntilLemma(xs, suf)) { - // property - (incLazy(xs) match { - case Spine(Zero(), _, rear) => - concreteUntil(pushUntilCarry(rear), suf) - }) - } else false) - } holds - - @invisibleBody - def incNum[T](w: Number) = { - require(w.valid && - // instantiate the lemma that implies zeroPrecedeLazy - (w.schedule match { - case Cons(h, _) => - zeroPredSufConcreteUntilLemma(w.digs, h) - case _ => - concreteZeroPredLemma(w.digs) - })) - val nq = inc(w.digs) - val nsched = nq match { - case Spine(Zero(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons(rear, w.schedule) // this is the only case where we create a new lazy closure - else - w.schedule - case _ => - w.schedule - } - val lq: Lazy[NumStream] = nq - (lq, nsched) - } ensuring { res => - // lemma instantiations - (w.schedule match { - case Cons(head, tail) => - w.digs* match { - case Spine(h, _, _) => - if (h != Zero()) - incLazyLemma(w.digs, head) - else true - case _ => true - } - case _ => true - }) && - schedulesProperty(res._1, res._2) && - time <= ? - } - - @invisibleBody - def Pay[T](q: Lazy[NumStream], scheds: Scheds): Scheds = { - require(schedulesProperty(q, scheds) && q.isEvaluated) - scheds match { - case c @ Cons(head, rest) => - head.value match { - case Spine(Zero(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons(rear, rest) - else - rest - } - case Nil() => scheds - } - } ensuring { res => - { - val in = inState[NumStream] - val out = outState[NumStream] - // instantiations for proving the scheds property - (scheds match { - case Cons(head, rest) => - concUntilExtenLemma(q, head, in, out) && - (head* match { - case Spine(Zero(), _, rear) => - res match { - case Cons(rhead, rtail) => - schedMonotone(in, out, rtail, pushUntilCarry(rhead)) && - concUntilMonotone(rear, rhead, in, out) && - concUntilCompose(q, rear, rhead) - case _ => - concreteMonotone(in, out, rear) && - concUntilConcreteExten(q, rear) - } - }) - case _ => true - }) && - // instantiations for zeroPrecedeSuf property - (scheds match { - case Cons(head, rest) => - (concreteUntilIsSuffix(q, head) withState in) && - (res match { - case Cons(rhead, rtail) => - concreteUntilIsSuffix(pushUntilCarry(head), rhead) && - suffixZeroLemma(q, head, rhead) && - zeroPrecedeSuf(q, rhead) - case _ => - true - }) - case _ => - true - }) - } && // properties - schedulesProperty(q, res) && - time <= ? - } - - /** - * Pushing an element to the left of the queue preserves the data-structure invariants - */ - @invisibleBody - def incAndPay[T](w: Number) = { - require(w.valid) - - val (q, scheds) = incNum(w) - val nscheds = Pay(q, scheds) - Number(q, nscheds) - - } ensuring { res => res.valid && time <= ? } - - def firstDigit(w: Number): Digit = { - require(!w.isEmpty) - w.digs.value match { - case Spine(d, _, _) => d - } - } - - // monotonicity lemmas - def schedMonotone[T](st1: Set[Lazy[NumStream]], st2: Set[Lazy[NumStream]], scheds: Scheds, l: Lazy[NumStream]): Boolean = { - require(st1.subsetOf(st2) && - (schedulesProperty(l, scheds) withState st1)) // here the input state is fixed as 'st1' - //induction scheme - (scheds match { - case Cons(head, tail) => - head* match { - case Spine(_, _, rear) => - concUntilMonotone(l, head, st1, st2) && - schedMonotone(st1, st2, tail, pushUntilCarry(head)) - case _ => true - } - case Nil() => - concreteMonotone(st1, st2, l) - }) && (schedulesProperty(l, scheds) withState st2) //property - } holds - - @traceInduct - def concreteMonotone[T](st1: Set[Lazy[NumStream]], st2: Set[Lazy[NumStream]], l: Lazy[NumStream]): Boolean = { - ((isConcrete(l) withState st1) && st1.subsetOf(st2)) ==> (isConcrete(l) withState st2) - } holds - - @traceInduct - def concUntilMonotone[T](q: Lazy[NumStream], suf: Lazy[NumStream], st1: Set[Lazy[NumStream]], st2: Set[Lazy[NumStream]]): Boolean = { - ((concreteUntil(q, suf) withState st1) && st1.subsetOf(st2)) ==> (concreteUntil(q, suf) withState st2) - } holds - - // suffix predicates and their properties (this should be generalizable) - - def suffix[T](q: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - if (q == suf) true - else { - q* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case Tip() => false - } - } - } - - def properSuffix[T](l: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - l* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case _ => false - } - } ensuring (res => !res || (suffixDisequality(l, suf) && suf != l)) - - /** - * suf(q, suf) ==> suf(q.rear, suf.rear) - */ - @traceInduct - def suffixTrans[T](q: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - suffix(q, suf) ==> ((q*, suf*) match { - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffix(rear, sufRear) - case _ => true - }) - }.holds - - /** - * properSuf(l, suf) ==> l != suf - */ - def suffixDisequality[T](l: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - require(properSuffix(l, suf)) - suffixTrans(l, suf) && // lemma instantiation - ((l*, suf*) match { // induction scheme - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffixDisequality(rear, sufRear) - case _ => true - }) && l != suf // property - }.holds - - @traceInduct - def suffixCompose[T](q: Lazy[NumStream], suf1: Lazy[NumStream], suf2: Lazy[NumStream]): Boolean = { - (suffix(q, suf1) && properSuffix(suf1, suf2)) ==> properSuffix(q, suf2) - } holds - - // properties of 'concUntil' - - @traceInduct - def concreteUntilIsSuffix[T](l: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - concreteUntil(l, suf) ==> suffix(l, suf) - }.holds - - // properties that extend `concUntil` to larger portions of the queue - - @traceInduct - def concUntilExtenLemma[T](q: Lazy[NumStream], suf: Lazy[NumStream], st1: Set[Lazy[NumStream]], st2: Set[Lazy[NumStream]]): Boolean = { - ((concreteUntil(q, suf) withState st1) && st2 == st1 ++ Set(suf)) ==> - (suf* match { - case Spine(_, _, rear) => - concreteUntil(q, rear) withState st2 - case _ => true - }) - } holds - - @traceInduct - def concUntilConcreteExten[T](q: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - (concreteUntil(q, suf) && isConcrete(suf)) ==> isConcrete(q) - } holds - - @traceInduct - def concUntilCompose[T](q: Lazy[NumStream], suf1: Lazy[NumStream], suf2: Lazy[NumStream]): Boolean = { - (concreteUntil(q, suf1) && concreteUntil(suf1, suf2)) ==> concreteUntil(q, suf2) - } holds - - // properties that relate `concUntil`, `concrete`, `zeroPrecedeSuf` with `zeroPrecedeLazy` - // - these are used in preconditions to derive the `zeroPrecedeLazy` property - - @invisibleBody - @traceInduct - def zeroPredSufConcreteUntilLemma[T](q: Lazy[NumStream], suf: Lazy[NumStream]): Boolean = { - (zeroPrecedeSuf(q, suf) && concreteUntil(q, suf)) ==> zeroPrecedeLazy(q) - } holds - - @invisibleBody - @traceInduct - def concreteZeroPredLemma[T](q: Lazy[NumStream]): Boolean = { - isConcrete(q) ==> zeroPrecedeLazy(q) - } holds - - // properties relating `suffix` an `zeroPrecedeSuf` - - def suffixZeroLemma[T](q: Lazy[NumStream], suf: Lazy[NumStream], suf2: Lazy[NumStream]): Boolean = { - require(suf* match { - case Spine(Zero(), _, _) => - suffix(q, suf) && properSuffix(suf, suf2) - case _ => false - }) - suffixCompose(q, suf, suf2) && ( - // induction scheme - if (q != suf) { - q* match { - case Spine(_, _, tail) => - suffixZeroLemma(tail, suf, suf2) - case _ => - true - } - } else true) && - zeroPrecedeSuf(q, suf2) // property - }.holds - - @ignore - def main(args: Array[String]) { - //import eagerEval.BigNums - import scala.util.Random - import scala.math.BigInt - import stats._ - import collection._ - - println("Running Numerical Representation test...") - val ops = 1000000 - // initialize to a queue with one element (required to satisfy preconditions of dequeue and front) - //var bignum: BigNums.BigNum = BigNums.Nil() - var lazynum = emptyNum - var totalTime1 = 0L - var totalTime2 = 0L - println(s"Testing amortized emphemeral behavior on $ops operations...") - for (i <- 0 until ops) { - //println("Inc..") - //bignum = timed { BigNums.increment(bignum) } { totalTime1 += _ } - lazynum = timed { incAndPay(lazynum) } { totalTime2 += _ } - //val d1 = BigNums.firstDigit(bignum) - val d2 = firstDigit(lazynum) - //assert(d1.toString == d2.toString, s"Eager head: $d1 Lazy head: $d2") - } - println(s"Ephemeral Amortized Time - Eager: ${totalTime1 / 1000.0}s Lazy: ${totalTime2 / 1000.0}s") // this should be linear in length for both cases - // now, test worst-case behavior (in persitent mode if necessary) - val length = (1 << 22) - 1 // a number of the form: 2^{n-1} - //bignum = BigNums.Nil() - lazynum = emptyNum - for (i <- 0 until length) { - //bignum = BigNums.increment(bignum) - lazynum = incAndPay(lazynum) - } - //println(s"Number of leading ones of bignum: ${BigNums.leadingOnes(bignum)}") - //dequeue 1 element from both queues - //timed { BigNums.increment(bignum) } { t => println(s"Time for one eager increment in the worst case: ${t / 1000.0}s") } - timed { incAndPay(lazynum) } { t => println(s"Time for one lazy increment in the worst case: ${t / 1000.0}s") } - } -} diff --git a/testcases/lazy-datastructures/withOrb/PackratParsing.scala b/testcases/lazy-datastructures/withOrb/PackratParsing.scala deleted file mode 100644 index 4cf2b81fea9a1a574acef30b0535a4596eceb46d..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/PackratParsing.scala +++ /dev/null @@ -1,247 +0,0 @@ -package orb - -import leon._ -import mem._ -import lang._ -import annotation._ -import instrumentation._ -import invariant._ - -/** - * The packrat parser that uses the Expressions grammar presented in Bran Ford ICFP'02 paper. - * The implementation is almost exactly as it was presented in the paper, but - * here indices are passed around between parse functions, instead of strings. - */ -object PackratParsing { - - sealed abstract class Terminal - case class Open() extends Terminal - case class Close() extends Terminal - case class Plus() extends Terminal - case class Times() extends Terminal - case class Digit() extends Terminal - - /** - * A mutable array of tokens returned by the lexer. - * The string of tokens is reversed i.e, - * string(legnth-1) represents the first char and string(0) represents the last char. - */ - @ignore - var string = Array[Terminal]() - - /** - * looking up the ith token - */ - @extern - def lookup(i: BigInt): Terminal = { - string(i.toInt) - } ensuring (_ => time <= 1) - - sealed abstract class Result { - /** - * Checks if the index in the result (if any) is - * smaller than `i` - */ - @inline - def smallerIndex(i: BigInt) = this match { - case Parsed(m) => m < i - case _ => true - } - } - case class Parsed(rest: BigInt) extends Result - case class NoParse() extends Result - - @invisibleBody - @memoize - @invstate - def pAdd(i: BigInt): Result = { - require { - if (depsEval(i) && pMul(i).isCached && pPrim(i).isCached) - resEval(i, pMul(i)) // lemma inst - else false - } - // Rule 1: Add <- Mul + Add - val mulRes = pMul(i) - mulRes match { - case Parsed(j) => - if (j > 0 && lookup(j) == Plus()) { - pAdd(j - 1) match { - case Parsed(rem) => - Parsed(rem) - case _ => - mulRes // Rule2: Add <- Mul - } - } else mulRes - case _ => - mulRes - } - } ensuring (res => res.smallerIndex(i) && time <= ?) // time <= 26 - - @invisibleBody - @memoize - @invstate - def pMul(i: BigInt): Result = { - require{ - if (depsEval(i) && pPrim(i).isCached) - resEval(i, pPrim(i)) // lemma inst - else false - } - // Rule 1: Mul <- Prim * Mul - val primRes = pPrim(i) - primRes match { - case Parsed(j) => - if (j > 0 && lookup(j) == Times()) { - pMul(j - 1) match { - case Parsed(rem) => - Parsed(rem) - case _ => - primRes // Rule2: Mul <- Prim - } - } else primRes - case _ => - primRes - } - } ensuring (res => res.smallerIndex(i) && time <= ?) // time <= 26 - - @invisibleBody - @memoize - @invstate - def pPrim(i: BigInt): Result = { - require(depsEval(i)) - val char = lookup(i) - if (char == Digit()) { - if (i > 0) - Parsed(i - 1) // Rule1: Prim <- Digit - else - Parsed(-1) // here, we can use -1 to convey that the suffix is empty - } else if (char == Open() && i > 0) { - pAdd(i - 1) match { // Rule 2: pPrim <- ( Add ) - case Parsed(rem) => - if (rem >= 0 && lookup(rem) == Close()) Parsed(rem - 1) - else NoParse() - case _ => - NoParse() - } - } else NoParse() - } ensuring (res => res.smallerIndex(i) && time <= ?) // time <= 28 - - //@inline - def depsEval(i: BigInt) = i == 0 || (i > 0 && allEval(i - 1)) - - def allEval(i: BigInt): Boolean = { - require(i >= 0) - (pPrim(i).isCached && pMul(i).isCached && pAdd(i).isCached) && ( - if (i == 0) true - else allEval(i - 1)) - } - - @traceInduct - def evalMono(i: BigInt, st1: Set[Mem[Result]], st2: Set[Mem[Result]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (allEval(i) withState st1)) ==> (allEval(i) withState st2) - } holds - - @traceInduct - def depsLem(x: BigInt, y: BigInt) = { - require(x >= 0 && y >= 0) - (x <= y && allEval(y)) ==> allEval(x) - } holds - - /** - * Instantiates the lemma `depsLem` on the result index (if any) - */ - //@inline - def resEval(i: BigInt, res: Result) = { - (res match { - case Parsed(j) => - if (j >= 0 && i > 1) depsLem(j, i - 1) - else true - case _ => true - }) - } - - /*@invisibleBody - def invoke(i: BigInt): (Result, Result, Result) = { - require(i == 0 || (i > 0 && allEval(i - 1))) - (pPrim(i), pMul(i), pAdd(i)) - } ensuring (res => { - val in = inState[Result] - val out = outState[Result] - (if (i > 0) evalMono(i - 1, in, out) else true) && - allEval(i) && - time <= ? - })*/ - - def invokePrim(i: BigInt): Result = { - require(depsEval(i)) - pPrim(i) - } ensuring { res => - val in = inState[Result] - val out = outState[Result] - (if (i > 0) evalMono(i - 1, in, out) else true) - } - - def invokeMul(i: BigInt): Result = { - require(depsEval(i)) - invokePrim(i) match { - case _ => pMul(i) - } - } ensuring { res => - val in = inState[Result] - val out = outState[Result] - (if (i > 0) evalMono(i - 1, in, out) else true) - } - - @invisibleBody - def invoke(i: BigInt): Result = { - require(depsEval(i)) - invokeMul(i) match { - case _ => pAdd(i) - } - } ensuring { res => - val in = inState[Result] - val out = outState[Result] - (if (i > 0) evalMono(i - 1, in, out) else true) && - allEval(i) && - time <= ? // 189 - } - - /** - * Parsing a string of length 'n+1'. - * Word is represented as an array indexed by 'n'. We only pass around the index. - * The 'lookup' function will return a character of the array. - */ - @invisibleBody - def parse(n: BigInt): Result = { - require(n >= 0) - if (n == 0) invoke(n) - else { - parse(n - 1) match { // we parse the prefixes ending at 0, 1, 2, 3, ..., n - case _ => - invoke(n) - } - } - } ensuring (_ => allEval(n) && - time <= ? * n + ?) // 198 * n + 192 - - @ignore - def main(args: Array[String]) { - // note: we can run only one test in each run as the cache needs to be cleared between the tests, - // which is not currently supported by the api's - test1() - //test2() - } - - @ignore - def test1() { - // list of tokens to parse. The list is reversed i.e, the first char is at the last index, the last char is at the first index. - string = Array(Plus(), Digit(), Times(), Close(), Digit(), Plus(), Digit(), Open()) // d * ( d + d ) + - println("Parsing Expression 1: " + parse(string.length - 1)) - } - - @ignore - def test2() { - string = Array(Times(), Digit(), Open()) // ( d * - println("Parsing Expression 2: " + parse(string.length - 1)) - } -} diff --git a/testcases/lazy-datastructures/withOrb/RealTimeQueue.scala b/testcases/lazy-datastructures/withOrb/RealTimeQueue.scala deleted file mode 100644 index 3eda466a8b6c3885d3c9ca34a3ebd15a58af3b83..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/RealTimeQueue.scala +++ /dev/null @@ -1,176 +0,0 @@ -package withOrb - -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import collection._ -import instrumentation._ -import invariant._ - -object RealTimeQueue { - - sealed abstract class Stream[T] { - def isEmpty: Boolean = { - this match { - case SNil() => true - case _ => false - } - } - - def isCons: Boolean = { - this match { - case SCons(_, _) => true - case _ => false - } - } - - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + (t*).size - } - } ensuring (_ >= 0) - } - case class SCons[T](x: T, tail: Lazy[Stream[T]]) extends Stream[T] - case class SNil[T]() extends Stream[T] - - def isConcrete[T](l: Lazy[Stream[T]]): Boolean = { - l.isEvaluated && (l* match { - case SCons(_, tail) => - isConcrete(tail) - case _ => true - }) - } - - @invisibleBody - @invstate - def rotate[T](f: Lazy[Stream[T]], r: List[T], a: Lazy[Stream[T]]): Stream[T] = { // doesn't change state - require(r.size == (f*).size + 1 && isConcrete(f)) - (f.value, r) match { - case (SNil(), Cons(y, _)) => //in this case 'y' is the only element in 'r' - SCons[T](y, a) - case (SCons(x, tail), Cons(y, r1)) => - val newa: Stream[T] = SCons[T](y, a) - val rot = $(rotate(tail, r1, newa)) //this creates a lazy rotate operation - SCons[T](x, rot) - } - } ensuring (res => res.size == (f*).size + r.size + (a*).size && res.isCons && - time <= ?) - - /** - * Returns the first element of the stream that is not evaluated. - */ - def firstUnevaluated[T](l: Lazy[Stream[T]]): Lazy[Stream[T]] = { - if (l.isEvaluated) { - l* match { - case SCons(_, tail) => - firstUnevaluated(tail) - case _ => l - } - } else - l - } ensuring (res => (!(res*).isEmpty || isConcrete(l)) && //if there are no lazy closures then the stream is concrete - (res.value match { - case SCons(_, tail) => - firstUnevaluated(l) == firstUnevaluated(tail) // after evaluating the firstUnevaluated closure in 'l' we can access the next unevaluated closure - case _ => true - })) - - case class Queue[T](f: Lazy[Stream[T]], r: List[T], s: Lazy[Stream[T]]) { - def isEmpty = (f*).isEmpty - def valid = { - (firstUnevaluated(f) == firstUnevaluated(s)) && - (s*).size == (f*).size - r.size //invariant: |s| = |f| - |r| - } - } - - @inline - def createQ[T](f: Lazy[Stream[T]], r: List[T], s: Lazy[Stream[T]]) = { - s.value match { - case SCons(_, tail) => Queue(f, r, tail) - case SNil() => - val newa: Stream[T] = SNil() - val rotres = $(rotate(f, r, newa)) - Queue(rotres, Nil(), rotres) - } - } - - def empty[T] = { - val a: Stream[T] = SNil() - Queue(a, Nil(), a) - } - - def head[T](q: Queue[T]): T = { - require(!q.isEmpty && q.valid) - q.f.value match { - case SCons(x, _) => x - } - } //ensuring (res => res.valid && time <= ?) - - def enqueue[T](x: T, q: Queue[T]): Queue[T] = { - require(q.valid) - createQ(q.f, Cons(x, q.r), q.s) - } ensuring (res => res.valid && time <= ?) - - def dequeue[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.valid) - q.f.value match { - case SCons(x, nf) => - createQ(nf, q.r, q.s) - } - } ensuring (res => res.valid && time <= ?) - - @ignore - def main(args: Array[String]) { - //import eagerEval.AmortizedQueue - import scala.util.Random - import scala.math.BigInt - import stats._ - import collection._ - - println("Running RTQ test...") - val ops = 10000000 - val rand = Random - // initialize to a queue with one element (required to satisfy preconditions of dequeue and front) - var rtq = empty[BigInt] - //var amq = AmortizedQueue.Queue(AmortizedQueue.Nil(), AmortizedQueue.Nil()) - var totalTime1 = 0L - var totalTime2 = 0L - println(s"Testing amortized emphemeral behavior on $ops operations...") - for (i <- 0 until ops) { - if (!rtq.isEmpty) { - val h1 = head(rtq) - //val h2 = amq.head - //assert(h1 == h2, s"Eager head: $h2 Lazy head: $h1") - } - rand.nextInt(2) match { - case x if x == 0 => //enqueue - // /if(i%100000 == 0) println("Enqueue..") - rtq = timed { enqueue(BigInt(i), rtq) } { totalTime1 += _ } - //amq = timed { amq.enqueue(BigInt(i)) } { totalTime2 += _ } - case x if x == 1 => //dequeue - if (!rtq.isEmpty) { - //if(i%100000 == 0) println("Dequeue..") - rtq = timed { dequeue(rtq) } { totalTime1 += _ } - //amq = timed { amq.dequeue } { totalTime2 += _ } - } - } - } - println(s"Ephemeral Amortized Time - Eager: ${totalTime2 / 1000.0}s Lazy: ${totalTime1 / 1000.0}s") // this should be linear in length for both cases - // now, test worst-case behavior (in persitent mode if necessary) - val length = (1 << 22) - 2 // a number of the form: 2^{n-2} - // reset the queues - rtq = empty[BigInt] - //amq = AmortizedQueue.Queue(AmortizedQueue.Nil(), AmortizedQueue.Nil()) - // enqueue length elements - for (i <- 0 until length) { - rtq = enqueue(BigInt(0), rtq) - //amq = amq.enqueue(BigInt(0)) - } - //println(s"Amortized queue size: ${amq.front.size}, ${amq.rear.size}") - //dequeue 1 element from both queues - //timed { amq.dequeue } { t => println(s"Time to dequeue one element from Amortized Queue in the worst case: ${t / 1000.0}s") } - timed { dequeue(rtq) } { t => println(s"Time to dequeue one element from RTQ in the worst case: ${t / 1000.0}s") } - } -} diff --git a/testcases/lazy-datastructures/withOrb/SortingnConcat.scala b/testcases/lazy-datastructures/withOrb/SortingnConcat.scala deleted file mode 100644 index 0f4c1151b72c4559be6a11c29aa7d854d881a28c..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/SortingnConcat.scala +++ /dev/null @@ -1,74 +0,0 @@ -package withOrb - -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import instrumentation._ -import invariant._ - -object SortingnConcat { - - // TODO: making this parametric will break many things. Fix them - sealed abstract class LList { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + ssize(t) - } - } ensuring (_ >= 0) - } - case class SCons(x: BigInt, tail: Lazy[LList]) extends LList - case class SNil() extends LList - def ssize(l: Lazy[LList]): BigInt = (l*).size - - sealed abstract class List { - def size: BigInt = this match { - case Cons(_, xs) => 1 + xs.size - case _ => BigInt(0) - } - } - case class Cons(x: BigInt, tail: List) extends List - case class Nil() extends List - - def pullMin(l: List): List = { - l match { - case Nil() => l - case Cons(x, xs) => - pullMin(xs) match { - case Nil() => Cons(x, Nil()) - case nxs @ Cons(y, ys) => - if (x <= y) Cons(x, nxs) - else Cons(y, Cons(x, ys)) - } - } - } ensuring (res => res.size == l.size && time <= ? * l.size + ?) - - def sort(l: List): LList = { - pullMin(l) match { - case Cons(x, xs) => - // here, x is the minimum - SCons(x, $(sort(xs))) // sorts lazily only if needed - case _ => - SNil() - } - } ensuring (res => res.size == l.size && time <= ? * l.size + ?) - - def concat(l1: List, l2: LList) : LList = { - l1 match { - case Cons(x, xs) => SCons(x, $(concat(xs, l2))) - case Nil() => SNil() - } - } ensuring(res => time <= ?) - - def kthMin(l: Lazy[LList], k: BigInt): BigInt = { - require(k >= 1) - l.value match { - case SCons(x, xs) => - if (k == 1) x - else - kthMin(xs, k - 1) - case SNil() => BigInt(0) - } - } ensuring (_ => time <= ? * (k * ssize(l)) + ? * k + ?) -} diff --git a/testcases/lazy-datastructures/withOrb/WeightedScheduling.scala b/testcases/lazy-datastructures/withOrb/WeightedScheduling.scala deleted file mode 100644 index fc254279b27b8e7c0596deb1a4a3c276341a9333..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withOrb/WeightedScheduling.scala +++ /dev/null @@ -1,133 +0,0 @@ -package orb - -import leon._ -import mem._ -import lang._ -import annotation._ -import instrumentation._ -import invariant._ - -object WeightedSched { - sealed abstract class IList { - def size: BigInt = { - this match { - case Cons(_, tail) => 1 + tail.size - case Nil() => BigInt(0) - } - } ensuring (_ >= 0) - } - case class Cons(x: BigInt, tail: IList) extends IList - case class Nil() extends IList - - /** - * array of jobs - * (a) each job has a start time, finish time, and weight - * (b) Jobs are sorted in ascending order of finish times - * The first job should be (0,0,0) so that it acts as sentinel of every other job - */ - @ignore - var jobs = Array[(BigInt, BigInt, BigInt)]() - - /** - * A precomputed mapping from each job i to the previous job j it is compatible with. - * The value of the first index could be anything. - */ - @ignore - var p = Array[Int]() - - @extern - def jobInfo(i: BigInt) = { - jobs(i.toInt) - } ensuring (_ => time <= 1) - - @extern - def prevCompatibleJob(i: BigInt) = { - BigInt(p(i.toInt)) - } ensuring (res => res >= 0 && res < i && time <= 1) - - @inline - def max(x: BigInt, y: BigInt) = if (x >= y) x else y - - def depsEval(i: BigInt) = i == 0 || (i > 0 && allEval(i - 1)) - - def allEval(i: BigInt): Boolean = { - require(i >= 0) - sched(i).isCached && - (if (i == 0) true - else allEval(i - 1)) - } - - @traceInduct - def evalMono(i: BigInt, st1: Set[Mem[BigInt]], st2: Set[Mem[BigInt]]) = { - require(i >= 0) - (st1.subsetOf(st2) && (allEval(i) withState st1)) ==> (allEval(i) withState st2) - } holds - - @traceInduct - def evalLem(x: BigInt, y: BigInt) = { - require(x >= 0 && y >= 0) - (x <= y && allEval(y)) ==> allEval(x) - } holds - - @invisibleBody - @invstate - @memoize - def sched(jobIndex: BigInt): BigInt = { - require(depsEval(jobIndex) && - (jobIndex == 0 || evalLem(prevCompatibleJob(jobIndex), jobIndex - 1))) - val (st, fn, w) = jobInfo(jobIndex) - if (jobIndex == 0) w - else { - // we may either include the head job or not: - // if we include the head job, we have to skip every job that overlaps with it - val tailValue = sched(jobIndex - 1) - val prevCompatVal = sched(prevCompatibleJob(jobIndex)) - max(w + prevCompatVal, tailValue) - } - } ensuring (_ => time <= ?) - - @invisibleBody - def invoke(jobIndex: BigInt) = { - require(depsEval(jobIndex)) - sched(jobIndex) - } ensuring (res => { - val in = inState[BigInt] - val out = outState[BigInt] - (jobIndex == 0 || evalMono(jobIndex - 1, in, out)) && - time <= ? - }) - - @invisibleBody - def schedBU(jobi: BigInt): IList = { - require(jobi >= 0) - if (jobi == 0) { - Cons(invoke(jobi), Nil()) - } else { - val tailRes = schedBU(jobi - 1) - Cons(invoke(jobi), tailRes) - } - } ensuring (_ => allEval(jobi) && - time <= ? * (jobi + 1)) - - @ignore - def main(args: Array[String]) { - // note: we can run only one test in each run as the cache needs to be cleared between the tests, - // which is not currently supported by the api's (note: the methods access a mutable field) - test1() - //test2() - } - - @ignore - def test1() { - jobs = Array((0, 0, 0), (1, 2, 5), (3, 4, 2), (3, 8, 5), (6, 7, 10), (8, 11, 11), (10, 13, 20)) - p = Array(0 /* anything */ , 0, 1, 1, 2, 4, 4) - println("Schedule for 5 jobs of set 1: " + schedBU(6)) - } - - @ignore - def test2() { - jobs = Array((0, 0, 0), (1, 3, 5), (3, 4, 2), (3, 8, 5), (6, 7, 10), (8, 11, 11), (10, 13, 20)) - p = Array(0 /* anything */ , 0, 0, 0, 2, 4, 4) - println("Schedule for 5 jobs of set 2: " + schedBU(6)) - } -} diff --git a/testcases/lazy-datastructures/withconst/BottomUpMegeSort.scala b/testcases/lazy-datastructures/withconst/BottomUpMegeSort.scala deleted file mode 100644 index 1f4672599a487d19f80b0ebae1f5382ebf53f30c..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withconst/BottomUpMegeSort.scala +++ /dev/null @@ -1,180 +0,0 @@ -package lazybenchmarks - -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import instrumentation._ -//import invariant._ - -/** - * TODO Multiple instantiations of type parameters is not supported yet, - * since it require creation of multiple states one for each instantiation - */ - -/** - * A version of merge sort that operates bottom-up. That allows - * accessing the first element in the sorted list in constant time. - */ -object BottomUpMergeSort { - - /** - * A list of integers that have to be sorted - */ - sealed abstract class IList { - def size: BigInt = { - this match { - case ICons(_, xs) => 1 + xs.size - case _ => BigInt(0) - } - } ensuring (_ >= 0) - } - case class ICons(x: BigInt, tail: IList) extends IList - case class INil() extends IList - - /** - * A stream of integers (the tail is lazy) - */ - sealed abstract class IStream { - def size: BigInt = { - this match { - case SCons(_, xs) => 1 + ssize(xs) - case _ => BigInt(0) - } - } ensuring (_ >= 0) - } - case class SCons(x: BigInt, tail: Lazy[IStream]) extends IStream - case class SNil() extends IStream - def ssize(l: Lazy[IStream]): BigInt = (l*).size - - /** - * A list of suspensions - */ - sealed abstract class LList { - def size: BigInt = { - this match { - case LNil() => BigInt(0) - case LCons(_, t) => 1 + t.size - } - } ensuring (_ >= 0) - - def valid: Boolean = { - this match { - case LNil() => true - case LCons(l, t) => ssize(l) > 0 && t.valid - } - } - - def fullSize: BigInt = { - this match { - case LNil() => BigInt(0) - case LCons(l, t) => ssize(l) + t.fullSize - } - } ensuring (_ >= 0) - } - case class LCons(x: Lazy[IStream], tail: LList) extends LList - case class LNil() extends LList - - /** - * A function that given a list of (lazy) sorted lists, - * groups them into pairs and lazily invokes the 'merge' function - * on each pair. - * Takes time linear in the size of the input list - */ - def pairs(l: LList): LList = { - require(l.valid) - l match { - case LNil() => LNil() - case LCons(_, LNil()) => l - case LCons(l1, LCons(l2, rest)) => - LCons($(merge(l1, l2)), pairs(rest)) - } - } ensuring (res => res.size <= (l.size + 1) / 2 && - l.fullSize == res.fullSize && - res.valid && - time <= 10 * l.size + 4) - - /** - * Create a linearized tree of merges e.g. merge(merge(2, 1), merge(17, 19)). - * Takes time linear in the size of the input list. - */ - def constructMergeTree(l: LList): LList = { - require(l.valid) - l match { - case LNil() => LNil() - case LCons(_, LNil()) => l - case _ => - constructMergeTree(pairs(l)) - } - } ensuring (res => res.size <= 1 && res.fullSize == l.fullSize && - (res match { - case LCons(il, LNil()) => - res.fullSize == ssize(il) // this is implied by the previous conditions - case _ => true - }) && - res.valid && - time <= 42 * l.size + 4) - - /** - * A function that merges two sorted streams of integers. - * Note: the sorted stream of integers may by recursively constructed using merge. - * Takes time linear in the size of the streams (non-trivial to prove due to cascading of lazy calls) - */ - @usePost - def merge(a: Lazy[IStream], b: Lazy[IStream]): IStream = { - require(((a*) != SNil() || b.isEvaluated) && // if one of the arguments is Nil then the other is evaluated - ((b*) != SNil() || a.isEvaluated) && - ((a*) != SNil() || (b*) != SNil())) // at least one of the arguments is not Nil - b.value match { - case SNil() => a.value - case bl @ SCons(x, xs) => - a.value match { - case SNil() => bl - case SCons(y, ys) => - if (y < x) - SCons(y, $(merge(ys, b))) - else - SCons(x, $(merge(a, xs))) - } - } - } ensuring (res => ssize(a) + ssize(b) == res.size && - time <= 300 * res.size - 100) // note: res.size >= 1 // here stack is max of a and b - - /** - * Converts a list of integers to a list of streams of integers - */ - def IListToLList(l: IList): LList = { - l match { - case INil() => LNil() - case ICons(x, xs) => - LCons(SCons(x, SNil()), IListToLList(xs)) - } - } ensuring (res => res.fullSize == l.size && - res.size == l.size && - res.valid && - time <= 11 * l.size + 3) - - /** - * Takes list of integers and returns a sorted stream of integers. - * Takes time linear in the size of the input since it sorts lazily. - */ - def mergeSort(l: IList): IStream = { - l match { - case INil() => SNil() - case _ => - constructMergeTree(IListToLList(l)) match { - case LCons(r, LNil()) => r.value - } - } - } ensuring (res => time <= 400 * l.size + 10) - - /** - * A function that accesses the first element of a list using lazy sorting. - */ - def firstMin(l: IList) : BigInt ={ - require(l != INil()) - mergeSort(l) match { - case SCons(x, rest) => x - } - } ensuring (res => time <= 400 * l.size + 20) -} diff --git a/testcases/lazy-datastructures/withconst/Deque.scala b/testcases/lazy-datastructures/withconst/Deque.scala deleted file mode 100644 index 931eb41b37b947c315cfe39d86e352a7a32ef790..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withconst/Deque.scala +++ /dev/null @@ -1,345 +0,0 @@ -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import collection._ -import instrumentation._ -import math._ - -/** - * A constant time deque based on Okasaki's implementation: Fig.8.4 Pg. 112. - * Here, both front and rear streams are scheduled. - * We require both the front and the rear streams to be of almost equal - * size. If not, we lazily rotate the streams. - * The invariants are a lot more complex than in `RealTimeQueue`. - * The program also fixes a bug in Okasaki's implementatin: see function `rotateDrop` - */ -object RealTimeDeque { - - sealed abstract class Stream[T] { - @inline - def isEmpty: Boolean = { - this match { - case SNil() => true - case _ => false - } - } - - @inline - def isCons: Boolean = { - this match { - case SCons(_, _) => true - case _ => false - } - } - - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + (t*).size - } - } ensuring (_ >= 0) - } - case class SCons[T](x: T, tail: Lazy[Stream[T]]) extends Stream[T] - case class SNil[T]() extends Stream[T] - - @inline - def ssize[T](l: Lazy[Stream[T]]): BigInt = (l*).size - - def isConcrete[T](l: Lazy[Stream[T]]): Boolean = { - l.isEvaluated && (l* match { - case SCons(_, tail) => - isConcrete(tail) - case _ => true - }) - } - - @invstate - def revAppend[T](l1: Lazy[Stream[T]], l2: Lazy[Stream[T]]): Lazy[Stream[T]] = { - require(isConcrete(l1) && isConcrete(l2)) - l1.value match { - case SNil() => l2 - case SCons(x, tail) => - val nt: Lazy[Stream[T]] = SCons[T](x, l2) - revAppend(tail, nt) - } - } ensuring(res => ssize(res) == ssize(l1) + ssize(l2) && - isConcrete(res) && - (ssize(l1) >= 1 ==> (res*).isCons) && - time <= 20*ssize(l1) + 20) - - @invstate - def drop[T](n: BigInt, l: Lazy[Stream[T]]): Lazy[Stream[T]] = { - require(n >= 0 && isConcrete(l) && ssize(l) >= n) - if (n == 0) { - l - } else { - l.value match { - case SNil() => l - case SCons(x, tail) => drop(n - 1, tail) - } - } - } ensuring(res => isConcrete(res) && - ssize(res) == ssize(l) - n && - time <= 20*n + 20) - - @invstate - def take[T](n: BigInt, l: Lazy[Stream[T]]): Lazy[Stream[T]] = { - require(n >= 0 && isConcrete(l) && ssize(l) >= n) - val r: Lazy[Stream[T]] = - if (n == 0) { - SNil[T]() - } else { - l.value match { - case SNil() => l - case SCons(x, tail) => - SCons[T](x, take(n - 1, tail)) - } - } - r - } ensuring(res => isConcrete(res) && - ssize(res) == n && - time <= 30*n + 30) - - @invstate - def takeLazy[T](n: BigInt, l: Lazy[Stream[T]]): Stream[T] = { - require(isConcrete(l) && n >= 1 && ssize(l) >= n) - l.value match { - case SCons(x, tail) => - if (n == 1) - SCons[T](x, SNil[T]()) - else - SCons[T](x, $(takeLazy(n - 1, tail))) - } - } ensuring(res => res.size == n && res.isCons && - time <= 20) - - @invstate - def rotateRev[T](r: Lazy[Stream[T]], f: Lazy[Stream[T]], a: Lazy[Stream[T]]): Stream[T] = { - require(isConcrete(r) && isConcrete(f) && isConcrete(a) && - { - val lenf = ssize(f) - val lenr = ssize(r) - (lenf <= 2 * lenr + 3 && lenf >= 2 * lenr + 1) - }) - r.value match { - case SNil() => revAppend(f, a).value // |f| <= 3 - case SCons(x, rt) => - SCons(x, $(rotateRev(rt, drop(2, f), revAppend(take(2, f), a)))) - } // here, it doesn't matter whether 'f' has i elements or not, what we want is |drop(2,f)| + |take(2,f)| == |f| - } ensuring (res => res.size == (r*).size + (f*).size + (a*).size && - res.isCons && - time <= 250) - - @invstate - def rotateDrop[T](r: Lazy[Stream[T]], i: BigInt, f: Lazy[Stream[T]]): Stream[T] = { - require(isConcrete(r) && isConcrete(f) && i >= 0 && { - val lenf = ssize(f) - val lenr = ssize(r) - (lenf >= 2 * lenr + 2 && lenf <= 2 * lenr + 3) && // size invariant between 'f' and 'r' - lenf > i - }) - val rval = r.value - if(i < 2 || rval == SNil[T]()) { // A bug in Okasaki implementation: we must check for: 'rval = SNil()' - val a: Lazy[Stream[T]] = SNil[T]() - rotateRev(r, drop(i, f), a) - } else { - rval match { - case SCons(x, rt) => - SCons(x, $(rotateDrop(rt, i - 2, drop(2, f)))) - } - } - } ensuring(res => res.size == (r*).size + (f*).size - i && - res.isCons && time <= 300) - - def firstUneval[T](l: Lazy[Stream[T]]): Lazy[Stream[T]] = { - if (l.isEvaluated) { - l* match { - case SCons(_, tail) => - firstUneval(tail) - case _ => l - } - } else - l - } ensuring (res => (!(res*).isEmpty || isConcrete(l)) && - ((res*).isEmpty || !res.isEvaluated) && // if the return value is not a Nil closure then it would not have been evaluated - (res.value match { - case SCons(_, tail) => - firstUneval(l) == firstUneval(tail) // after evaluating the firstUneval closure in 'l' we can access the next unevaluated closure - case _ => true - })) - - case class Queue[T](f: Lazy[Stream[T]], lenf: BigInt, sf: Lazy[Stream[T]], - r: Lazy[Stream[T]], lenr: BigInt, sr: Lazy[Stream[T]]) { - def isEmpty = lenf + lenr == 0 - def valid = { - (firstUneval(f) == firstUneval(sf)) && - (firstUneval(r) == firstUneval(sr)) && - (lenf == ssize(f) && lenr == ssize(r)) && - (lenf <= 2*lenr + 1 && lenr <= 2*lenf + 1) && - { - val mind = min(2*lenr-lenf+2, 2*lenf-lenr+2) - ssize(sf) <= mind && ssize(sr) <= mind - } - } - } - - /** - * A function that takes streams where the size of front and rear streams violate - * the balance invariant, and restores the balance. - */ - def createQueue[T](f: Lazy[Stream[T]], lenf: BigInt, sf: Lazy[Stream[T]], - r: Lazy[Stream[T]], lenr: BigInt, sr: Lazy[Stream[T]]): Queue[T] = { - require(firstUneval(f) == firstUneval(sf) && - firstUneval(r) == firstUneval(sr) && - (lenf == ssize(f) && lenr == ssize(r)) && - ((lenf - 1 <= 2*lenr + 1 && lenr <= 2*lenf + 1) || - (lenf <= 2*lenr + 1 && lenr - 2 <= 2*lenf + 1)) && - { - val mind = max(min(2*lenr-lenf+2, 2*lenf-lenr+2), 0) - ssize(sf) <= mind && ssize(sr) <= mind - }) - if(lenf > 2*lenr + 1) { - val i = (lenf + lenr) / 2 - val j = lenf + lenr - i - val nr = rotateDrop(r, i, f) - val nf = takeLazy(i, f) - Queue(nf, i, nf, nr, j, nr) - } else if(lenr > 2*lenf + 1) { - val i = (lenf + lenr) / 2 - val j = lenf + lenr - i - val nf = rotateDrop(f, j, r) // here, both 'r' and 'f' are concretized - val nr = takeLazy(j, r) - Queue(nf, i, nf, nr, j, nr) - } else - Queue(f, lenf, sf, r, lenr, sr) - } ensuring(res => res.valid && - time <= 400) - - /** - * Forces the schedules, and ensures that `firstUneval` equality is preserved - */ - def force[T](tar: Lazy[Stream[T]], htar: Lazy[Stream[T]], other: Lazy[Stream[T]], hother: Lazy[Stream[T]]): Lazy[Stream[T]] = { - require(firstUneval(tar) == firstUneval(htar) && - firstUneval(other) == firstUneval(hother)) - tar.value match { - case SCons(_, tail) => tail - case _ => tar - } - } ensuring (res => { - //lemma instantiations - val in = inState[Stream[T]] - val out = outState[Stream[T]] - funeMonotone(tar, htar, in, out) && - funeMonotone(other, hother, in, out) && { - //properties - val rsize = ssize(res) - firstUneval(htar) == firstUneval(res) && // follows from post of fune - firstUneval(other) == firstUneval(hother) && - (rsize == 0 || rsize == ssize(tar) - 1) - } && time <= 350 - }) - - /** - * Forces the schedules in the queue twice and ensures the `firstUneval` property. - */ - def forceTwice[T](q: Queue[T]): (Lazy[Stream[T]], Lazy[Stream[T]]) = { - require(q.valid) - val nsf = force(force(q.sf, q.f, q.r, q.sr), q.f, q.r, q.sr) // forces q.sf twice - val nsr = force(force(q.sr, q.r, q.f, nsf), q.r, q.f, nsf) // forces q.sr twice - (nsf, nsr) - } - // the following properties are ensured, but need not be stated - /*ensuring (res => { - val nsf = res._1 - val nsr = res._2 - firstUneval(q.f) == firstUneval(nsf) && - firstUneval(q.r) == firstUneval(nsr) && - (ssize(nsf) == 0 || ssize(nsf) == ssize(q.sf) - 2) && - (ssize(nsr) == 0 || ssize(nsr) == ssize(q.sr) - 2) && - time <= 1500 - })*/ - - def empty[T] = { - val nil: Lazy[Stream[T]] = SNil[T]() - Queue(nil, 0, nil, nil, 0, nil) - } - - /** - * Adding an element to the front of the list - */ - def cons[T](x: T, q: Queue[T]): Queue[T] = { - require(q.valid) - val nf: Stream[T] = SCons[T](x, q.f) - // force the front and rear scheds once - val nsf = force(q.sf, q.f, q.r, q.sr) - val nsr = force(q.sr, q.r, q.f, nsf) - createQueue(nf, q.lenf + 1, nsf, q.r, q.lenr, nsr) - } ensuring (res => res.valid && time <= 1200) - - /** - * Removing the element at the front, and returning the tail - */ - def tail[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.valid) - force(q.f, q.sf, q.r, q.sr) match { // force 'f' - case _ => - tailSub(q) - } - } ensuring(res => res.valid && time <= 3000) - - def tailSub[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.valid && q.f.isEvaluated) - q.f.value match { - case SCons(x, nf) => - val (nsf, nsr) = forceTwice(q) - // here, sf and sr got smaller by 2 holds, the schedule invariant still holds - createQueue(nf, q.lenf - 1, nsf, q.r, q.lenr, nsr) - case SNil() => - // in this case 'r' will have only one element by invariant - empty[T] - } - } ensuring(res => res.valid && time <= 2750) - - /** - * Reversing a list. Takes constant time. - * This implies that data structure is a `deque`. - */ - def reverse[T](q: Queue[T]): Queue[T] = { - require(q.valid) - Queue(q.r, q.lenr, q.sr, q.f, q.lenf, q.sf) - } ensuring(q.valid && time <= 10) - - // Properties of `firstUneval`. We use `fune` as a shorthand for `firstUneval` - /** - * st1.subsetOf(st2) ==> fune(l, st2) == fune(fune(l, st1), st2) - */ - @traceInduct - def funeCompose[T](l1: Lazy[Stream[T]], st1: Set[Lazy[Stream[T]]], st2: Set[Lazy[Stream[T]]]): Boolean = { - require(st1.subsetOf(st2)) - // property - (firstUneval(l1) withState st2) == (firstUneval(firstUneval(l1) withState st1) withState st2) - } holds - - /** - * st1.subsetOf(st2) && fune(la,st1) == fune(lb,st1) ==> fune(la,st2) == fune(lb,st2) - * The `fune` equality is preseved by evaluation of lazy closures. - * This is a kind of frame axiom for `fune` but is slightly different in that - * it doesn't require (st2 \ st1) to be disjoint from la and lb. - */ - def funeMonotone[T](l1: Lazy[Stream[T]], l2: Lazy[Stream[T]], st1: Set[Lazy[Stream[T]]], st2: Set[Lazy[Stream[T]]]): Boolean = { - require((firstUneval(l1) withState st1) == (firstUneval(l2) withState st1) && - st1.subsetOf(st2)) - funeCompose(l1, st1, st2) && // lemma instantiations - funeCompose(l2, st1, st2) && - // induction scheme - (if (l1.isEvaluated withState st1) { - l1* match { - case SCons(_, tail) => - funeMonotone(tail, l2, st1, st2) - case _ => true - } - } else true) && - (firstUneval(l1) withState st2) == (firstUneval(l2) withState st2) // property - } holds -} diff --git a/testcases/lazy-datastructures/withconst/Esop15Benchmarks.scala b/testcases/lazy-datastructures/withconst/Esop15Benchmarks.scala deleted file mode 100644 index 009ecef063fb02a4d2ccc9727a6fa4fd72605e87..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withconst/Esop15Benchmarks.scala +++ /dev/null @@ -1,57 +0,0 @@ -package lazybenchmarks - -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.lazyeval.$._ -import leon.collection._ - -/** - * This file is the collection of programs in the ESOP 2015 paper. - * Note this benchmark is very good for finding counter-examples.s - * Decreasing the time bounds slightly will display counter-examples. - */ -object Esop15Benchmarks { - sealed abstract class IStream - case class SCons(x: BigInt, tail: $[IStream]) extends IStream - case class SNil() extends IStream - - sealed abstract class StreamPairs - case class PCons(pair: (BigInt, BigInt), tail: $[StreamPairs]) extends StreamPairs - case class PNil() extends StreamPairs - - def zipWith(xs: $[IStream], ys: $[IStream]): StreamPairs = { - (xs.value, ys.value) match { - case (SCons(x, xtail), SCons(y, ytail)) => - PCons((x, y), $(zipWith(xtail, ytail))) - case _ => - PNil() - } - } ensuring(_ => time <= 65) - - def nextFib(x: BigInt, y: BigInt, n: BigInt): IStream = { - if (n <= 0) - SNil() - else { - val next = x + y - SCons(next, $(nextFib(y, next, n - 1))) - } - } ensuring(_ => time <= 20) - - def fibStream(n: BigInt) : IStream = { - SCons(0, SCons(1, $(nextFib(0, 1, n)))) - } - - def nthFib(n: BigInt, fs: $[IStream]): BigInt = { - require(n >= 0) - fs.value match { - case SCons(x, tail) => - if (n == 0) - x - else - nthFib(n - 1, tail) - case SNil() => BigInt(-1) - } - } ensuring(_ => time <= 40 * n + 40) // you get a counter-example for 20*n + 20 -} \ No newline at end of file diff --git a/testcases/lazy-datastructures/withconst/LazyMegeSort.scala b/testcases/lazy-datastructures/withconst/LazyMegeSort.scala deleted file mode 100644 index 9ddca941efad67fe2434879fd11c2be0a97ff525..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withconst/LazyMegeSort.scala +++ /dev/null @@ -1,84 +0,0 @@ -package lazybenchmarks - -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -//import leon.invariant._ - -object MergeSort { - - // TODO: making this parametric will break many things. Fix them - sealed abstract class LList { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + ssize(t) - } - } ensuring (_ >= 0) - } - case class SCons(x: BigInt, tail: $[LList]) extends LList - case class SNil() extends LList - def ssize(l: $[LList]): BigInt = (l*).size - - sealed abstract class List { - def size: BigInt = { - this match { - case Cons(_, xs) => 1 + xs.size - case _ => BigInt(0) - } - } ensuring (_ >= 0) - } - case class Cons(x: BigInt, tail: List) extends List - case class Nil() extends List - - def length(l: List): BigInt = { - l match { - case Nil() => BigInt(0) - case Cons(x, xs) => 1 + length(xs) - } - } ensuring (res => res >= 0 && res == l.size && stack <= 14 * l.size + 15) - - def split(l: List, n: BigInt): (List, List) = { - require(n > 0 && n < l.size) - l match { - case Nil() => (Nil(), l) - case Cons(x, xs) => - if (n == 1) { - (Cons(x, Nil()), xs) - } else { - val (fst, snd) = split(xs, n - 1) - (Cons(x, fst), snd) - } - } - } ensuring (res => res._2.size == l.size - n && res._1.size == n && stack <= 25 * l.size - 1) - - /* - * Proving standalone bound for merge requires preconditions. - */ - def merge(a: $[LList], b: $[LList]): LList = (b.value match { - case SNil() => a.value - case bl @ SCons(x, xs) => - a.value match { - case SNil() => bl - case SCons(y, ys) => - if (y < x) - SCons(y, $(merge(ys, b))) - else - SCons(x, $(merge(a, xs))) - } - }) //ensuring (res => ssize(a) + ssize(b) == res.size) - - /** - * Note the time is not O(n) but only O(n log n) since - * we have time recurrence T(n) = 2T(n/2) + O(n) - */ - def mergeSort(l: List): LList = (l match { - case Nil() => SNil() - case Cons(x, Nil()) => SCons(x, $(SNil())) - case _ => - val (fst, snd) = split(l, length(l) / 2) - merge($(mergeSort(fst)), $(mergeSort(snd))) - - }) ensuring (res => stack <= 81 * l.size + 35) // res.size == l.size -} diff --git a/testcases/lazy-datastructures/withconst/LazyNumericalRep.scala b/testcases/lazy-datastructures/withconst/LazyNumericalRep.scala deleted file mode 100644 index fa1561035cd5ec7075d0b70676396b105ca67672..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withconst/LazyNumericalRep.scala +++ /dev/null @@ -1,468 +0,0 @@ -package lazybenchmarks - -import leon.lazyeval._ -import leon.lang._ -import leon.annotation._ -import leon.instrumentation._ -import leon.lazyeval.$._ - -object DigitObject { - sealed abstract class Digit - case class Zero() extends Digit - case class One() extends Digit -} - -import DigitObject._ -object LazyNumericalRep { - - sealed abstract class NumStream { - val isSpine: Boolean = this match { - case Spine(_, _, _) => true - case _ => false - } - val isTip = !isSpine - } - - case class Tip() extends NumStream - case class Spine(head: Digit, createdWithSuspension: Bool, rear: $[NumStream]) extends NumStream - - sealed abstract class Bool - case class True() extends Bool - case class False() extends Bool - - /** - * Checks whether there is a zero before an unevaluated closure - */ - def zeroPreceedsLazy[T](q: $[NumStream]): Boolean = { - if (q.isEvaluated) { - q* match { - case Spine(Zero(), _, rear) => - true // here we have seen a zero - case Spine(_, _, rear) => - zeroPreceedsLazy(rear) //here we have not seen a zero - case Tip() => true - } - } else false - } - - /** - * Checks whether there is a zero before a given suffix - */ - def zeroPreceedsSuf[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - if (q != suf) { - q* match { - case Spine(Zero(), _, rear) => true - case Spine(_, _, rear) => - zeroPreceedsSuf(rear, suf) - case Tip() => false - } - } else false - } - - /** - * Everything until suf is evaluated. This - * also asserts that suf should be a suffix of the list - */ - def concreteUntil[T](l: $[NumStream], suf: $[NumStream]): Boolean = { - if (l != suf) { - l.isEvaluated && (l* match { - case Spine(_, cws, tail) => - concreteUntil(tail, suf) - case _ => - false - }) - } else true - } - - def isConcrete[T](l: $[NumStream]): Boolean = { - l.isEvaluated && (l* match { - case Spine(_, _, tail) => - isConcrete(tail) - case _ => true - }) - } - - sealed abstract class Scheds - case class Cons(h: $[NumStream], tail: Scheds) extends Scheds - case class Nil() extends Scheds - - def schedulesProperty[T](q: $[NumStream], schs: Scheds): Boolean = { - schs match { - case Cons(head, tail) => - head* match { - case Spine(Zero(), _, _) => // head starts with zero - head.isSuspension(incLazy _) && - concreteUntil(q, head) && - schedulesProperty(pushUntilCarry(head), tail) - case _ => - false - } - case Nil() => - isConcrete(q) - } - } - - def strongSchedsProp[T](q: $[NumStream], schs: Scheds) = { - q.isEvaluated && { - schs match { - case Cons(head, tail) => - zeroPreceedsSuf(q, head) // zeroPreceedsSuf holds initially - case Nil() => true - } - } && - schedulesProperty(q, schs) - } - - /** - * Note: if 'q' has a suspension then it would have a carry. - */ - def pushUntilCarry[T](q: $[NumStream]): $[NumStream] = { - q* match { - case Spine(Zero(), _, rear) => // if we push a carry and get back 0 then there is a new carry - pushUntilCarry(rear) - case Spine(_, _, rear) => // if we push a carry and get back 1 then there the carry has been fully pushed - rear - case Tip() => - q - } - } - - case class Number(digs: $[NumStream], schedule: Scheds) { - val valid = strongSchedsProp(digs, schedule) - } - - def inc(xs: $[NumStream]): NumStream = { - require(zeroPreceedsLazy(xs)) - xs.value match { - case Tip() => - Spine(One(), False(), xs) - case s @ Spine(Zero(), _, rear) => - Spine(One(), False(), rear) - case s @ Spine(_, _, _) => - incLazy(xs) - } - } ensuring (_ => time <= 70) - - @invstate - def incLazy(xs: $[NumStream]): NumStream = { - require(zeroPreceedsLazy(xs) && - (xs* match { - case Spine(h, _, _) => h != Zero() // xs doesn't start with a zero - case _ => false - })) - xs.value match { - case Spine(head, _, rear) => // here, rear is guaranteed to be evaluated by 'zeroPreceedsLazy' invariant - val carry = One() - rear.value match { - case s @ Spine(Zero(), _, srear) => - val tail: NumStream = Spine(carry, False(), srear) - Spine(Zero(), False(), tail) - - case s @ Spine(_, _, _) => - Spine(Zero(), True(), $(incLazy(rear))) - - case t @ Tip() => - val y: NumStream = Spine(carry, False(), rear) - Spine(Zero(), False(), y) - } - } - } ensuring { res => - (res match { - case Spine(Zero(), _, rear) => - (!isConcrete(xs) || isConcrete(pushUntilCarry(rear))) && - { - val _ = rear.value // this is necessary to assert properties on the state in the recursive invocation (and note this cannot go first) - rear.isEvaluated // this is a tautology - } - case _ => - false - }) && - time <= 40 - } - - /** - * Lemma: - * forall suf. suf*.head != Zero() ^ zeroPredsSuf(xs, suf) ^ concUntil(xs.tail.tail, suf) => concUntil(push(rear), suf) - */ - @invstate - def incLazyLemma[T](xs: $[NumStream], suf: $[NumStream]): Boolean = { - require(zeroPreceedsSuf(xs, suf) && - (xs* match { - case Spine(h, _, _) => h != Zero() - case _ => false - }) && - (suf* match { - case Spine(Zero(), _, _) => - concreteUntil(xs, suf) - case _ => false - })) - // induction scheme - (xs* match { - case Spine(head, _, rear) => - rear* match { - case s @ Spine(h, _, _) => - if (h != Zero()) - incLazyLemma(rear, suf) - else true - case _ => true - } - }) && - // instantiate the lemma that implies zeroPreceedsLazy - (if (zeroPredSufConcreteUntilLemma(xs, suf)) { - // property - (incLazy(xs) match { - case Spine(Zero(), _, rear) => - concreteUntil(pushUntilCarry(rear), suf) - }) - } else false) - } holds - - def incNum[T](w: Number) = { - require(w.valid && - // instantiate the lemma that implies zeroPreceedsLazy - (w.schedule match { - case Cons(h, _) => - zeroPredSufConcreteUntilLemma(w.digs, h) - case _ => - concreteZeroPredLemma(w.digs) - })) - val nq = inc(w.digs) - val nsched = nq match { - case Spine(Zero(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons(rear, w.schedule) // this is the only case where we create a new lazy closure - else - w.schedule - case _ => - w.schedule - } - val lq: $[NumStream] = nq - (lq, nsched) - } ensuring { res => - // lemma instantiations - (w.schedule match { - case Cons(head, tail) => - w.digs* match { - case Spine(h, _, _) => - if (h != Zero()) - incLazyLemma(w.digs, head) - else true - case _ => true - } - case _ => true - }) && - schedulesProperty(res._1, res._2) && - time <= 80 - } - - def Pay[T](q: $[NumStream], scheds: Scheds): Scheds = { - require(schedulesProperty(q, scheds) && q.isEvaluated) - scheds match { - case c @ Cons(head, rest) => - head.value match { - case Spine(Zero(), createdWithSusp, rear) => - if (createdWithSusp == True()) - Cons(rear, rest) - else - rest - } - case Nil() => scheds - } - } ensuring { res => - { - val in = inState[NumStream] - val out = outState[NumStream] - // instantiations for proving the scheds property - (scheds match { - case Cons(head, rest) => - concUntilExtenLemma(q, head, in, out) && - (head* match { - case Spine(Zero(), _, rear) => - res match { - case Cons(rhead, rtail) => - schedMonotone(in, out, rtail, pushUntilCarry(rhead)) && - concUntilMonotone(rear, rhead, in, out) && - concUntilCompose(q, rear, rhead) - case _ => - concreteMonotone(in, out, rear) && - concUntilConcreteExten(q, rear) - } - }) - case _ => true - }) && - // instantiations for zeroPreceedsSuf property - (scheds match { - case Cons(head, rest) => - (concreteUntilIsSuffix(q, head) withState in) && - (res match { - case Cons(rhead, rtail) => - concreteUntilIsSuffix(pushUntilCarry(head), rhead) && - suffixZeroLemma(q, head, rhead) && - zeroPreceedsSuf(q, rhead) - case _ => - true - }) - case _ => - true - }) - } && // properties - schedulesProperty(q, res) && - time <= 70 - } - - // monotonicity lemmas - def schedMonotone[T](st1: Set[$[NumStream]], st2: Set[$[NumStream]], scheds: Scheds, l: $[NumStream]): Boolean = { - require(st1.subsetOf(st2) && - (schedulesProperty(l, scheds) withState st1)) // here the input state is fixed as 'st1' - //induction scheme - (scheds match { - case Cons(head, tail) => - head* match { - case Spine(_, _, rear) => - concUntilMonotone(l, head, st1, st2) && - schedMonotone(st1, st2, tail, pushUntilCarry(head)) - case _ => true - } - case Nil() => - concreteMonotone(st1, st2, l) - }) && (schedulesProperty(l, scheds) withState st2) //property - } holds - - @traceInduct - def concreteMonotone[T](st1: Set[$[NumStream]], st2: Set[$[NumStream]], l: $[NumStream]): Boolean = { - ((isConcrete(l) withState st1) && st1.subsetOf(st2)) ==> (isConcrete(l) withState st2) - } holds - - @traceInduct - def concUntilMonotone[T](q: $[NumStream], suf: $[NumStream], st1: Set[$[NumStream]], st2: Set[$[NumStream]]): Boolean = { - ((concreteUntil(q, suf) withState st1) && st1.subsetOf(st2)) ==> (concreteUntil(q, suf) withState st2) - } holds - - // suffix predicates and their properties (this should be generalizable) - - def suffix[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - if (q == suf) true - else { - q* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case Tip() => false - } - } - } - - def properSuffix[T](l: $[NumStream], suf: $[NumStream]): Boolean = { - l* match { - case Spine(_, _, rear) => - suffix(rear, suf) - case _ => false - } - } ensuring (res => !res || (suffixDisequality(l, suf) && suf != l)) - - /** - * suf(q, suf) ==> suf(q.rear, suf.rear) - */ - @traceInduct - def suffixTrans[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - suffix(q, suf) ==> ((q*, suf*) match { - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffix(rear, sufRear) - case _ => true - }) - }.holds - - /** - * properSuf(l, suf) ==> l != suf - */ - def suffixDisequality[T](l: $[NumStream], suf: $[NumStream]): Boolean = { - require(properSuffix(l, suf)) - suffixTrans(l, suf) && // lemma instantiation - ((l*, suf*) match { // induction scheme - case (Spine(_, _, rear), Spine(_, _, sufRear)) => - // 'sufRear' should be a suffix of 'rear1' - suffixDisequality(rear, sufRear) - case _ => true - }) && l != suf // property - }.holds - - @traceInduct - def suffixCompose[T](q: $[NumStream], suf1: $[NumStream], suf2: $[NumStream]): Boolean = { - (suffix(q, suf1) && properSuffix(suf1, suf2)) ==> properSuffix(q, suf2) - } holds - - // properties of 'concUntil' - - @traceInduct - def concreteUntilIsSuffix[T](l: $[NumStream], suf: $[NumStream]): Boolean = { - concreteUntil(l, suf) ==> suffix(l, suf) - }.holds - - // properties that extend `concUntil` to larger portions of the queue - - @traceInduct - def concUntilExtenLemma[T](q: $[NumStream], suf: $[NumStream], st1: Set[$[NumStream]], st2: Set[$[NumStream]]): Boolean = { - ((concreteUntil(q, suf) withState st1) && st2 == st1 ++ Set(suf)) ==> - (suf* match { - case Spine(_, _, rear) => - concreteUntil(q, rear) withState st2 - case _ => true - }) - } holds - - @traceInduct - def concUntilConcreteExten[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - (concreteUntil(q, suf) && isConcrete(suf)) ==> isConcrete(q) - } holds - - @traceInduct - def concUntilCompose[T](q: $[NumStream], suf1: $[NumStream], suf2: $[NumStream]): Boolean = { - (concreteUntil(q, suf1) && concreteUntil(suf1, suf2)) ==> concreteUntil(q, suf2) - } holds - - // properties that relate `concUntil`, `concrete`, `zeroPreceedsSuf` with `zeroPreceedsLazy` - // - these are used in preconditions to derive the `zeroPreceedsLazy` property - - @traceInduct - def zeroPredSufConcreteUntilLemma[T](q: $[NumStream], suf: $[NumStream]): Boolean = { - (zeroPreceedsSuf(q, suf) && concreteUntil(q, suf)) ==> zeroPreceedsLazy(q) - } holds - - @traceInduct - def concreteZeroPredLemma[T](q: $[NumStream]): Boolean = { - isConcrete(q) ==> zeroPreceedsLazy(q) - } holds - - // properties relating `suffix` an `zeroPreceedsSuf` - - def suffixZeroLemma[T](q: $[NumStream], suf: $[NumStream], suf2: $[NumStream]): Boolean = { - require(suf* match { - case Spine(Zero(), _, _) => - suffix(q, suf) && properSuffix(suf, suf2) - case _ => false - }) - suffixCompose(q, suf, suf2) && ( - // induction scheme - if (q != suf) { - q* match { - case Spine(_, _, tail) => - suffixZeroLemma(tail, suf, suf2) - case _ => - true - } - } else true) && - zeroPreceedsSuf(q, suf2) // property - }.holds - - /** - * Pushing an element to the left of the queue preserves the data-structure invariants - */ - def incAndPay[T](w: Number) = { - require(w.valid) - - val (q, scheds) = incNum(w) - val nscheds = Pay(q, scheds) - Number(q, nscheds) - - } ensuring { res => res.valid && time <= 200 } -} diff --git a/testcases/lazy-datastructures/withconst/RealTimeQueue.scala b/testcases/lazy-datastructures/withconst/RealTimeQueue.scala deleted file mode 100644 index 0c4c3a6db5a361212d15ab8a6fdbc80f59de4932..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withconst/RealTimeQueue.scala +++ /dev/null @@ -1,109 +0,0 @@ -import leon.lazyeval._ -import leon.lazyeval.$._ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.instrumentation._ - -object RealTimeQueue { - - sealed abstract class Stream[T] { - def isEmpty: Boolean = { - this match { - case SNil() => true - case _ => false - } - } - - def isCons: Boolean = { - this match { - case SCons(_, _) => true - case _ => false - } - } - - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + ssize(t) - } - } ensuring (_ >= 0) - } - case class SCons[T](x: T, tail: $[Stream[T]]) extends Stream[T] - case class SNil[T]() extends Stream[T] - - def ssize[T](l: $[Stream[T]]): BigInt = (l*).size - - def isConcrete[T](l: $[Stream[T]]): Boolean = { - l.isEvaluated && (l* match { - case SCons(_, tail) => - isConcrete(tail) - case _ => true - }) - } - - @invstate - def rotate[T](f: $[Stream[T]], r: List[T], a: $[Stream[T]]): Stream[T] = { // doesn't change state - require(r.size == ssize(f) + 1 && isConcrete(f)) - (f.value, r) match { - case (SNil(), Cons(y, _)) => //in this case 'y' is the only element in 'r' - SCons[T](y, a) - case (SCons(x, tail), Cons(y, r1)) => - val newa: Stream[T] = SCons[T](y, a) - val rot = $(rotate(tail, r1, newa)) //this creates a lazy rotate operation - SCons[T](x, rot) - } - } ensuring (res => res.size == (f*).size + r.size + (a*).size && res.isCons && - time <= 30) - - /** - * Returns the first element of the stream that is not evaluated. - */ - def firstUnevaluated[T](l: $[Stream[T]]): $[Stream[T]] = { - if (l.isEvaluated) { - l* match { - case SCons(_, tail) => - firstUnevaluated(tail) - case _ => l - } - } else - l - } ensuring (res => (!(res*).isEmpty || isConcrete(l)) && //if there are no lazy closures then the stream is concrete - (res.value match { - case SCons(_, tail) => - firstUnevaluated(l) == firstUnevaluated(tail) // after evaluating the firstUnevaluated closure in 'l' we can access the next unevaluated closure - case _ => true - })) - - case class Queue[T](f: $[Stream[T]], r: List[T], s: $[Stream[T]]) { - def isEmpty = (f*).isEmpty - def valid = { - (firstUnevaluated(f) == firstUnevaluated(s)) && - ssize(s) == ssize(f) - r.size //invariant: |s| = |f| - |r| - } - } - - @inline - def createQ[T](f: $[Stream[T]], r: List[T], s: $[Stream[T]]) = { - s.value match { - case SCons(_, tail) => Queue(f, r, tail) - case SNil() => - val newa: Stream[T] = SNil() - val rotres = $(rotate(f, r, newa)) - Queue(rotres, Nil(), rotres) - } - } - - def enqueue[T](x: T, q: Queue[T]): Queue[T] = { - require(q.valid) - createQ(q.f, Cons(x, q.r), q.s) - } ensuring (res => res.valid && time <= 60) - - def dequeue[T](q: Queue[T]): Queue[T] = { - require(!q.isEmpty && q.valid) - q.f.value match { - case SCons(x, nf) => - createQ(nf, q.r, q.s) - } - } ensuring (res => res.valid && time <= 120) -} diff --git a/testcases/lazy-datastructures/withconst/SortingnConcat.scala b/testcases/lazy-datastructures/withconst/SortingnConcat.scala deleted file mode 100644 index 1899c30b673fa05b6529f141f5bad58d81e2613c..0000000000000000000000000000000000000000 --- a/testcases/lazy-datastructures/withconst/SortingnConcat.scala +++ /dev/null @@ -1,82 +0,0 @@ -import leon._ -import lazyeval._ -import lang._ -import annotation._ -import instrumentation._ - -object SortingnConcat { - - sealed abstract class LList { - def size: BigInt = { - this match { - case SNil() => BigInt(0) - case SCons(x, t) => 1 + ssize(t) - } - } ensuring (_ >= 0) - } - case class SCons(x: BigInt, tail: Lazy[LList]) extends LList - case class SNil() extends LList - def ssize(l: Lazy[LList]): BigInt = (l*).size - - sealed abstract class List { - def size: BigInt = this match { - case Cons(_, xs) => 1 + xs.size - case _ => BigInt(0) - } - } - case class Cons(x: BigInt, tail: List) extends List - case class Nil() extends List - - def pullMin(l: List): List = { - l match { - case Nil() => l - case Cons(x, xs) => - pullMin(xs) match { - case Nil() => Cons(x, Nil()) - case nxs @ Cons(y, ys) => - if (x <= y) Cons(x, nxs) - else Cons(y, Cons(x, ys)) - } - } - } ensuring (res => res.size == l.size && time <= 15 * l.size + 2) - - def sort(l: List): LList = { - pullMin(l) match { - case Cons(x, xs) => - // here, x is the minimum - SCons(x, $(sort(xs))) // sorts lazily only if needed - case _ => - SNil() - } - } ensuring (res => res.size == l.size && time <= 15 * l.size + 20) - - def concat(l1: List, l2: LList) : LList = { - l1 match { - case Cons(x, xs) => SCons(x, $(concat(xs, l2))) - case Nil() => SNil() - } - } ensuring(res => time <= 15) - - def secondMin(l: Lazy[LList]) : BigInt = { - l.value match { - case SCons(x, xs) => - xs.value match { - case SCons(y, ys) => y - case SNil() => x - } - case SNil() => BigInt(0) - } - } ensuring (_ => time <= 30 * ssize(l) + 40) - - /* Orb can prove this - * def kthMin(l: Lazy[LList], k: BigInt): BigInt = { - require(k >= 1) - l.value match { - case SCons(x, xs) => - if (k == 1) x - else - kthMin(xs, k - 1) - case SNil() => BigInt(0) // None[BigInt] - } - } ensuring (_ => time <= 15 * k * ssize(l) + 20 * k + 20)*/ -} diff --git a/testcases/orb-testcases/amortized/BigNums.scala b/testcases/orb-testcases/amortized/BigNums.scala deleted file mode 100644 index e4860ff5af743e01eb6530018bf93bde5ca53932..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/amortized/BigNums.scala +++ /dev/null @@ -1,79 +0,0 @@ -package orb - -import leon._ -import annotation._ -import invariant._ -import instrumentation._ - -object BigNums { - sealed abstract class Digit - case class Zero() extends Digit { - @ignore - override def toString = "0" - } - case class One() extends Digit { - @ignore - override def toString = "1" - } - - sealed abstract class BigNum - case class Cons(head: Digit, tail: BigNum) extends BigNum - case class Nil() extends BigNum - - /** - * Time taken by the increment method - * The number of leading one's - */ - def leadingOnes(l: BigNum) : BigInt = { - l match { - case Nil() => 1 - case Cons(Zero(), tail) => 1 - case Cons(_, tail) => 1 + leadingOnes(tail) - } - } - - /** - * Total number of one's in the number - */ - def numOnes(l: BigNum) : BigInt = { - l match { - case Nil() => 0 - case Cons(Zero(), tail) => numOnes(tail) - case Cons(_, tail) => 1 + numOnes(tail) - } - } - - /** - * Increments a number - */ - def increment(l: BigNum) : BigNum = { - l match { - case Nil() => Cons(One(), l) - case Cons(Zero(), tail) => Cons(One(), tail) - case Cons(_, tail) => - Cons(Zero(), increment(tail)) - } - } ensuring (res => time <= ? * leadingOnes(l) + ? && leadingOnes(l) + numOnes(res) - numOnes(l) <= ?) - - def firstDigit(l: BigNum): Digit = { - require(l != Nil()) - l match { - case Cons(d, _) => d - } - } - - /** - * Nop is the number of operations - */ - def incrUntil(nop: BigInt, l: BigNum) : BigNum = { - if(nop == 0) l - else { - incrUntil(nop-1, increment(l)) - } - } ensuring (res => time <= ? * nop + ? * numOnes(l) + ?) - - def count(nop: BigInt) : BigNum = { - incrUntil(nop, Nil()) - } ensuring (res => time <= ? * nop + ?) - -} diff --git a/testcases/orb-testcases/depth/AVLTree.scala b/testcases/orb-testcases/depth/AVLTree.scala deleted file mode 100644 index b9a7cf520f71ec94cbbc682bfc2635fae25a15c9..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/AVLTree.scala +++ /dev/null @@ -1,193 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - - -/** - * created by manos and modified by ravi. - * BST property cannot be verified - */ -object AVLTree { - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(left : Tree, value : BigInt, right: Tree, rank : BigInt) extends Tree - - sealed abstract class OptionBigInt - case class None() extends OptionBigInt - case class Some(i: BigInt) extends OptionBigInt - - def min(i1:BigInt, i2:BigInt) : BigInt = if (i1<=i2) i1 else i2 - def max(i1:BigInt, i2:BigInt) : BigInt = if (i1>=i2) i1 else i2 - - /*def twopower(x: BigInt) : BigInt = { - //require(x >= 0) - if(x < 1) 1 - else - 3/2 * twopower(x - 1) - } ensuring(res => res >= 1 && tmpl((a) => a <= 0))*/ - - def rank(t: Tree) : BigInt = { - t match { - case Leaf() => 0 - case Node(_,_,_,rk) => rk - } - } - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r, _) => { - val hl = height(l) - val hr = height(r) - max(hl,hr) + 1 - } - } - } - - def size(t: Tree): BigInt = { - //require(isAVL(t)) - (t match { - case Leaf() => 0 - case Node(l, _, r,_) => size(l) + 1 + size(r) - }) - - } ensuring (res => true && tmpl((a,b) => height(t) <= a*res + b)) - - def rankHeight(t: Tree) : Boolean = t match { - case Leaf() => true - case Node(l,_,r,rk) => rankHeight(l) && rankHeight(r) && rk == height(t) - } - - def balanceFactor(t : Tree) : BigInt = { - t match{ - case Leaf() => 0 - case Node(l, _, r, _) => rank(l) - rank(r) - } - } - - /*def isAVL(t:Tree) : Boolean = { - t match { - case Leaf() => true - case Node(l,_,r,rk) => isAVL(l) && isAVL(r) && balanceFactor(t) >= -1 && balanceFactor(t) <= 1 && rankHeight(t) //isBST(t) && - } - }*/ - - def unbalancedInsert(t: Tree, e : BigInt) : Tree = { - t match { - case Leaf() => Node(Leaf(), e, Leaf(), 1) - case Node(l,v,r,h) => - if (e == v) t - else if (e < v){ - val newl = avlInsert(l,e) - Node(newl, v, r, max(rank(newl), rank(r)) + 1) - } - else { - val newr = avlInsert(r,e) - Node(l, v, newr, max(rank(l), rank(newr)) + 1) - } - } - } - - def avlInsert(t: Tree, e : BigInt) : Tree = { - - balance(unbalancedInsert(t,e)) - - } ensuring(res => true && tmpl((a,b) => depth <= a*height(t) + b)) - //minbound: ensuring(res => time <= 138*height(t) + 19) - - def deleteMax(t: Tree): (Tree, OptionBigInt) = { - - t match { - case Node(Leaf(), v, Leaf(), _) => (Leaf(), Some(v)) - case Node(l, v, Leaf(), _) => { - val (newl, opt) = deleteMax(l) - opt match { - case None() => (t, None()) - case Some(lmax) => { - val newt = balance(Node(newl, lmax, Leaf(), rank(newl) + 1)) - (newt, Some(v)) - } - } - } - case Node(_, _, r, _) => deleteMax(r) - case _ => (t, None()) - } - } ensuring(res => true && tmpl((a,b) => depth <= a*height(t) + b)) - - def unbalancedDelete(t: Tree, e: BigInt): Tree = { - t match { - case Leaf() => Leaf() //not found case - case Node(l, v, r, h) => - if (e == v) { - if (l == Leaf()) r - else if(r == Leaf()) l - else { - val (newl, opt) = deleteMax(l) - opt match { - case None() => t - case Some(newe) => { - Node(newl, newe, r, max(rank(newl), rank(r)) + 1) - } - } - } - } else if (e < v) { - val newl = avlDelete(l, e) - Node(newl, v, r, max(rank(newl), rank(r)) + 1) - } else { - val newr = avlDelete(r, e) - Node(l, v, newr, max(rank(l), rank(newr)) + 1) - } - } - } - - def avlDelete(t: Tree, e: BigInt): Tree = { - - balance(unbalancedDelete(t, e)) - - } ensuring(res => true && tmpl((a,b) => depth <= a*height(t) + b)) - - def balance(t:Tree) : Tree = { - t match { - case Leaf() => Leaf() // impossible... - case Node(l, v, r, h) => - val bfactor = balanceFactor(t) - // at this poBigInt, the tree is unbalanced - if(bfactor > 1 ) { // left-heavy - val newL = - if (balanceFactor(l) < 0) { // l is right heavy - rotateLeft(l) - } - else l - rotateRight(Node(newL,v,r, max(rank(newL), rank(r)) + 1)) - } - else if(bfactor < -1) { - val newR = - if (balanceFactor(r) > 0) { // r is left heavy - rotateRight(r) - } - else r - rotateLeft(Node(l,v,newR, max(rank(newR), rank(l)) + 1)) - } else t - } - } - - def rotateRight(t:Tree) = { - t match { - case Node(Node(ll, vl, rl, _),v,r, _) => - - val hr = max(rank(rl),rank(r)) + 1 - Node(ll, vl, Node(rl,v,r,hr), max(rank(ll),hr) + 1) - - case _ => t // this should not happen - } } - - - def rotateLeft(t:Tree) = { - t match { - case Node(l, v, Node(lr,vr,rr,_), _) => - - val hl = max(rank(l),rank(lr)) + 1 - Node(Node(l,v,lr,hl), vr, rr, max(hl, rank(rr)) + 1) - case _ => t // this should not happen - } } -} - diff --git a/testcases/orb-testcases/depth/AmortizedQueue.scala b/testcases/orb-testcases/depth/AmortizedQueue.scala deleted file mode 100644 index 1678d8980ba741be46f464b321bc2c05c6575c80..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/AmortizedQueue.scala +++ /dev/null @@ -1,86 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - -object AmortizedQueue { - sealed abstract class List - case class Cons(head : BigInt, tail : List) extends List - case class Nil() extends List - - case class Queue(front : List, rear : List) - - def size(list : List) : BigInt = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) - - def sizeList(list : List) : BigInt = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + sizeList(xs) - }) ensuring(res => res >= 0 && tmpl((a,b) => depth <= a*size(list) + b)) - - def qsize(q : Queue) : BigInt = size(q.front) + size(q.rear) - - def asList(q : Queue) : List = concat(q.front, reverse(q.rear)) - - def concat(l1 : List, l2 : List) : List = (l1 match { - case Nil() => l2 - case Cons(x,xs) => Cons(x, concat(xs, l2)) - - }) ensuring (res => size(res) == size(l1) + size(l2) && tmpl((a,b,c) => depth <= a*size(l1) + b)) - - def isAmortized(q : Queue) : Boolean = sizeList(q.front) >= sizeList(q.rear) - - def isEmpty(queue : Queue) : Boolean = queue match { - case Queue(Nil(), Nil()) => true - case _ => false - } - - def reverseRec(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverseRec(xs, Cons(x, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && tmpl((a,b) => depth <= a*size(l1) + b)) - - def reverse(l: List): List = { - reverseRec(l, Nil()) - } ensuring (res => size(l) == size(res) && tmpl((a,b) => depth <= a*size(l) + b)) - - def amortizedQueue(front : List, rear : List) : Queue = { - if (sizeList(rear) <= sizeList(front)) - Queue(front, rear) - else - Queue(concat(front, reverse(rear)), Nil()) - } - - def enqueue(q : Queue, elem : BigInt) : Queue = ({ - - amortizedQueue(q.front, Cons(elem, q.rear)) - - }) ensuring(res => true && tmpl((a,b) => depth <= a*qsize(q) + b)) - - def dequeue(q : Queue) : Queue = { - require(isAmortized(q) && !isEmpty(q)) - q match { - case Queue(Cons(f, fs), rear) => amortizedQueue(fs, rear) - case _ => Queue(Nil(),Nil()) - } - } ensuring(res => true && tmpl((a,b) => depth <= a*qsize(q) + b)) - - def removeLast(l : List) : List = { - require(l != Nil()) - l match { - case Cons(x,Nil()) => Nil() - case Cons(x,xs) => Cons(x, removeLast(xs)) - case _ => Nil() - } - } ensuring(res => size(res) <= size(l) && tmpl((a,b) => depth <= a*size(l) + b)) - - def pop(q : Queue) : Queue = { - require(isAmortized(q) && !isEmpty(q)) - q match { - case Queue(front, Cons(r,rs)) => Queue(front, rs) - case Queue(front, rear) => Queue(removeLast(front), rear) - case _ => Queue(Nil(),Nil()) - } - } ensuring(res => true && tmpl((a,b) => depth <= a*size(q.front) + b)) -} diff --git a/testcases/orb-testcases/depth/BinaryTrie.scala b/testcases/orb-testcases/depth/BinaryTrie.scala deleted file mode 100755 index 562ab19ea8913551bafd45e429ec28c98cbee064..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/BinaryTrie.scala +++ /dev/null @@ -1,121 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - -import scala.collection.immutable.Set - -object ParallelBinaryTrie { - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(nvalue: BigInt, left: Tree, right: Tree) extends Tree - - sealed abstract class IList - case class Cons(head: BigInt, tail: IList) extends IList - case class Nil() extends IList - - def listSize(l: IList): BigInt = (l match { - case Nil() => 0 - case Cons(x, xs) => 1 + listSize(xs) - }) - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(x, l, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def find(inp: IList, t: Tree): Tree = { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x, xs @ Cons(y, _)) => { - t match { - case Leaf() => t - case Node(v, l, r) => { - if (y > 0) find(xs, l) else find(xs, r) - } - } - } - case _ => t - } - } ensuring (res => true && tmpl ((a, c) => depth <= a * listSize(inp) + c)) - - def insert(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => t - case Cons(x, xs) => { - val newch = insert(xs, Leaf()) - newch match { - case Leaf() => Node(x, Leaf(), Leaf()) - case Node(y, _, _) => if (y > 0) Node(x, newch, Leaf()) else Node(y, Leaf(), newch) - } - } - } - - } - case Node(v, l, r) => { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x, xs @ Cons(y, _)) => { - val ch = if (y > 0) l else r - if (y > 0) - Node(v, insert(xs, ch), r) - else - Node(v, l, insert(xs, ch)) - } - case _ => t - } - } - } - } ensuring (res => true && tmpl ((a, c) => depth <= a * listSize(inp) + c)) - - def create(inp: IList): Tree = { - insert(inp, Leaf()) - } ensuring (res => true && tmpl ((a, c) => depth <= a * listSize(inp) + c)) - - def delete(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => Leaf() - case Cons(x ,xs) => { - //the input is not in the tree, so do nothing - Leaf() - } - } - } - case Node(v, l, r) => { - inp match { - case Nil() => { - //the tree has extensions of the input list so do nothing - t - } - case Cons(x, Nil()) => { - //if "l" and "r" are nil, remove the node - if(l == Leaf() && r == Leaf()) Leaf() - else t - } - case Cons(x ,xs@Cons(y, _)) => { - val ch = if(y > 0) l else r - val newch = delete(xs, ch) - if(newch == Leaf() && ((y > 0 && r == Leaf()) || (y <= 0 && l == Leaf()))) Leaf() - else { - if(y > 0) - Node(v, newch, r) - else - Node(v, l, newch) - } - } - case _ => t - } - } - } - } ensuring (res => true && tmpl ((a, c) => depth <= a * listSize(inp) + c)) -} diff --git a/testcases/orb-testcases/depth/BinomialHeap.scala b/testcases/orb-testcases/depth/BinomialHeap.scala deleted file mode 100644 index 7dd9e613cd8964348fd63f1df22d22bab6d6c7f3..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/BinomialHeap.scala +++ /dev/null @@ -1,199 +0,0 @@ -/** - * @author Ravi - **/ -import leon.instrumentation._ -import leon.invariant._ - - -object BinomialHeap { - sealed abstract class BinomialTree - case class Node(rank: BigInt, elem: Element, children: BinomialHeap) extends BinomialTree - - sealed abstract class ElementAbs - case class Element(n: BigInt) extends ElementAbs - - sealed abstract class BinomialHeap - case class ConsHeap(head: BinomialTree, tail: BinomialHeap) extends BinomialHeap - case class NilHeap() extends BinomialHeap - - sealed abstract class List - case class NodeL(head: BinomialHeap, tail: List) extends List - case class NilL() extends List - - sealed abstract class OptionalTree - case class Some(t : BinomialTree) extends OptionalTree - case class None() extends OptionalTree - - /* Lower or Equal than for Element structure */ - private def leq(a: Element, b: Element) : Boolean = { - a match { - case Element(a1) => { - b match { - case Element(a2) => { - if(a1 <= a2) true - else false - } - } - } - } - } - - /* isEmpty function of the Binomial Heap */ - def isEmpty(t: BinomialHeap) = t match { - case ConsHeap(_,_) => false - case NilHeap() => true - } - - /* Helper function to determine rank of a BinomialTree */ - def rank(t: BinomialTree) : BigInt = t match { - case Node(r, _, _) => r - } - - /* Helper function to get the root element of a BinomialTree */ - def root(t: BinomialTree) : Element = t match { - case Node(_, e, _) => e - } - - /* Linking trees of equal ranks depending on the root element */ - def link(t1: BinomialTree, t2: BinomialTree) : BinomialTree = { - t1 match { - case Node(r, x1, c1) => { - t2 match { - case Node(_, x2, c2) => { - if (leq(x1,x2)) { - Node(r+1, x1, ConsHeap(t2, c1)) - } else { - Node(r+1, x2, ConsHeap(t1, c2)) - } - } - } - } - } - } - - def treeNum(h: BinomialHeap) : BigInt = { - h match { - case ConsHeap(head, tail) => 1 + treeNum(tail) - case NilHeap() => 0 - } - } - - /* Insert a tree into a binomial heap. The tree should be correct in relation to the heap */ - def insTree(t: BinomialTree, h: BinomialHeap) : BinomialHeap = { - h match { - case ConsHeap(head, tail) => { - if (rank(t) < rank(head)) { - ConsHeap(t, h) - } else if (rank(t) > rank(head)) { - ConsHeap(head, insTree(t,tail)) - } else { - insTree(link(t,head), tail) - } - } - case NilHeap() => ConsHeap(t, NilHeap()) - } - } ensuring(res => true && tmpl((a,b) => depth <= a*treeNum(h) + b)) - - /* Merge two heaps together */ - def merge(h1: BinomialHeap, h2: BinomialHeap): BinomialHeap = { - h1 match { - case ConsHeap(head1, tail1) => { - h2 match { - case ConsHeap(head2, tail2) => { - if (rank(head1) < rank(head2)) { - ConsHeap(head1, merge(tail1, h2)) - } else if (rank(head2) < rank(head1)) { - ConsHeap(head2, merge(h1, tail2)) - } else { - mergeWithCarry(link(head1, head2), tail1, tail2) - } - } - case NilHeap() => h1 - } - } - case NilHeap() => h2 - } - } ensuring(res => true && tmpl((a,b,c) => depth <= a*treeNum(h1) + b*treeNum(h2) + c)) - - def mergeWithCarry(t: BinomialTree, h1: BinomialHeap, h2: BinomialHeap): BinomialHeap = { - t match { - case Node(r, _, _) => { - h1 match { - case ConsHeap(head1, tail1) => { - h2 match { - case ConsHeap(head2, tail2) => { - if (rank(head1) < rank(head2)) { - - if (rank(t) < rank(head1)) - ConsHeap(t, ConsHeap(head1, merge(tail1, h2))) - else - mergeWithCarry(link(t, head1), tail1, h2) - - } else if (rank(head2) < rank(head1)) { - - if (rank(t) < rank(head2)) - ConsHeap(t, ConsHeap(head2, merge(h1, tail2))) - else - mergeWithCarry(link(t, head2), h1, tail2) - - } else { - ConsHeap(t, mergeWithCarry(link(head1, head2), tail1, tail2)) - } - } - case NilHeap() => { - insTree(t, h1) - } - } - } - case NilHeap() => insTree(t, h2) - } - } - } - } ensuring (res => true && tmpl ((d, e, f) => depth <= d * treeNum(h1) + e * treeNum(h2) + f)) - - //Auxiliary helper function to simplify findMin and deleteMin - def removeMinTree(h: BinomialHeap): (OptionalTree, BinomialHeap) = { - h match { - case ConsHeap(head, NilHeap()) => (Some(head), NilHeap()) - case ConsHeap(head1, tail1) => { - val (opthead2, tail2) = removeMinTree(tail1) - opthead2 match { - case None() => (Some(head1), tail1) - case Some(head2) => - if (leq(root(head1), root(head2))) { - (Some(head1), tail1) - } else { - (Some(head2), ConsHeap(head1, tail2)) - } - } - } - case _ => (None(), NilHeap()) - } - } ensuring (res => treeNum(res._2) <= treeNum(h) && tmpl ((a, b) => depth <= a*treeNum(h) + b)) - - /*def findMin(h: BinomialHeap) : Element = { - val (opt, _) = removeMinTree(h) - opt match { - case Some(Node(_,e,ts1)) => e - case _ => Element(-1) - } - } ensuring(res => true && tmpl((a,b) => time <= a*treeNum(h) + b))*/ - - def minTreeChildren(h: BinomialHeap) : BigInt = { - val (min, _) = removeMinTree(h) - min match { - case None() => 0 - case Some(Node(_,_,ch)) => treeNum(ch) - } - } - - // Discard the minimum element of the extracted min tree and put its children back into the heap - def deleteMin(h: BinomialHeap) : BinomialHeap = { - val (min, ts2) = removeMinTree(h) - min match { - case Some(Node(_,_,ts1)) => merge(ts1, ts2) - case _ => h - } - } ensuring(res => true && tmpl((a,b,c) => depth <= a*minTreeChildren(h) + b*treeNum(h) + c)) - -} diff --git a/testcases/orb-testcases/depth/ConcatVariations.scala b/testcases/orb-testcases/depth/ConcatVariations.scala deleted file mode 100644 index aea7080d6421e03901f6e1c58db1c5e0c6ed80d9..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/ConcatVariations.scala +++ /dev/null @@ -1,42 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - - -object ConcatVariations { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def genL(n: BigInt): List = { - require(n >= 0) - if (n == 0) Nil() - else - Cons(n, genL(n - 1)) - } ensuring (res => size(res) == n && tmpl((a,b) => depth <= a*n + b)) - - def append(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => Cons(x, append(xs, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && tmpl((a,b) => depth <= a*size(l1) + b)) - - def f_good(m: BigInt, n: BigInt): List = { - require(0 <= m && 0 <= n) - if (m == 0) Nil() - else append(genL(n), f_good(m - 1, n)) - - } ensuring(res => size(res) == n*m && tmpl((a,b,c,d) => depth <= a*(n*m) + b*n + c*m +d)) - - def f_worst(m: BigInt, n: BigInt): List = { - require(0 <= m && 0 <= n) - - if (m == 0) Nil() - else append(f_worst(m - 1, n), genL(n)) - - } ensuring(res => size(res) == n*m && tmpl((a,c,d,e,f) => depth <= a*((n*m)*m)+c*(n*m)+d*n+e*m+f)) -} diff --git a/testcases/orb-testcases/depth/Folds.scala b/testcases/orb-testcases/depth/Folds.scala deleted file mode 100755 index 305446be53b27c976080968b881119ce06de11e6..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/Folds.scala +++ /dev/null @@ -1,82 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - - -object TreeMaps { - - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def parallelSearch(elem : BigInt, t : Tree) : Boolean = { - t match { - case Leaf() => false - case Node(l, x, r) => - if(x == elem) true - else { - val r1 = parallelSearch(elem, r) - val r2 = parallelSearch(elem, l) - if(r1 || r2) true - else false - } - } - } ensuring(res => true && tmpl((a,b) => depth <= a*height(t) + b)) - - - def squareMap(t : Tree) : Tree = { - t match { - case Leaf() => t - case Node(l, x, r) => - val nl = squareMap(l) - val nr = squareMap(r) - Node(nl, x*x, nr) - } - } ensuring (res => true && tmpl((a,b) => depth <= a*height(t) + b)) - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def fact(n : BigInt) : BigInt = { - require(n >= 0) - - if(n == 1 || n == 0) BigInt(1) - else n * fact(n-1) - - } ensuring(res => tmpl((a,b) => depth <= a*n + b)) - - def descending(l: List, k: BigInt) : Boolean = { - l match { - case Nil() => true - case Cons(x, t) => x > 0 && x <= k && descending(t, x-1) - } - } - - def factMap(l: List, k: BigInt): List = { - require(descending(l, k) && k >= 0) - - l match { - case Nil() => Nil() - case Cons(x, t) => { - val f = fact(x) - Cons(f, factMap(t, x-1)) - } - - }} ensuring(res => true && tmpl((a,b) => depth <= a*k + b)) -} \ No newline at end of file diff --git a/testcases/orb-testcases/depth/ForElimParallel.scala b/testcases/orb-testcases/depth/ForElimParallel.scala deleted file mode 100644 index a065af8f3383e2c283241758111bca380dbe41fe..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/ForElimParallel.scala +++ /dev/null @@ -1,119 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - - -object ForElimination { - - sealed abstract class Tree - case class Node(left: Tree, value: Statement, right: Tree) extends Tree - case class Leaf() extends Tree - - sealed abstract class Statement - case class Print(msg: BigInt, varID: BigInt) extends Statement - case class Assign(varID: BigInt, expr: Expression) extends Statement - case class Skip() extends Statement - case class Block(body: Tree) extends Statement - case class IfThenElse(expr: Expression, then: Statement, elze: Statement) extends Statement - case class While(expr: Expression, body: Statement) extends Statement - case class For(init: Statement, expr: Expression, step: Statement, body: Statement) extends Statement - - sealed abstract class Expression - case class Var(varID: BigInt) extends Expression - case class BigIntLiteral(value: BigInt) extends Expression - case class Plus(lhs: Expression, rhs: Expression) extends Expression - case class Minus(lhs: Expression, rhs: Expression) extends Expression - case class Times(lhs: Expression, rhs: Expression) extends Expression - case class Division(lhs: Expression, rhs: Expression) extends Expression - case class Equals(lhs: Expression, rhs: Expression) extends Expression - case class LessThan(lhs: Expression, rhs: Expression) extends Expression - case class And(lhs: Expression, rhs: Expression) extends Expression - case class Or(lhs: Expression, rhs: Expression) extends Expression - case class Not(expr: Expression) extends Expression - - /*def sizeStat(st: Statement) : BigInt = st match { - case Block(l) => sizeList(l) + 1 - case IfThenElse(c,th,el) => sizeStat(th) + sizeStat(el) + 1 - case While(c,b) => sizeStat(b) + 1 - case For(init,cond,step,body) => sizeStat(init) + sizeStat(step) + sizeStat(body) - case other => 1 - } - - def sizeTree(l: List) : BigInt = l match { - case Node(l,x,r) => sizeTree(l) + sizeTree(r) + sizeStat(x) - case Nil() => 0 - }*/ - - def max(x: BigInt, y: BigInt) = if(x >= y) x else y - - def depthStat(st: Statement) : BigInt = st match { - case Block(t) => depthTree(t) + 1 - case IfThenElse(c,th,el) => max(depthStat(th),depthStat(el)) + 1 - case While(c,b) => depthStat(b) + 1 - case For(init,cond,step,body) => max(max(depthStat(init),depthStat(step)),depthStat(body)) - case other => 1 - } - - def depthTree(t: Tree) : BigInt = t match { - case Node(l,x,r) => max(max(depthTree(l),depthTree(r)),depthStat(x)) + 1 - case Leaf() => 0 - } - - /*def isForFree(stat: Statement): Boolean = (stat match { - case Block(body) => isForFreeTree(body) - case IfThenElse(_, then, elze) => isForFree(then) && isForFree(elze) - case While(_, body) => isForFree(body) - case For(_,_,_,_) => false - case _ => true - }) ensuring(res => true && tmpl((a,b) => depth <= a*depthStat(stat) + b)) - - def isForFreeTree(t: Tree): Boolean = (t match { - case Leaf() => true - case Node(l, x, r) => isForFree(x) && isForFreeTree(l) && isForFreeTree(r) - }) ensuring(res => true && tmpl((a,b) => depth <= a*depthTree(t) + b))*/ - - /*def forLoopsWellFormedTree(t: Tree): Boolean = (t match { - case Leaf() => true - case Node(l, x, r) => forLoopsWellFormed(x) && forLoopsWellFormedTree(l) && forLoopsWellFormedTree(r) - }) ensuring(res => true && tmpl((a,b) => depth <= a*depthTree(t) + b)) - - def forLoopsWellFormed(stat: Statement): Boolean = (stat match { - case Block(body) => forLoopsWellFormedTree(body) - case IfThenElse(_, then, elze) => forLoopsWellFormed(then) && forLoopsWellFormed(elze) - case While(_, body) => forLoopsWellFormed(body) - case For(init, _, step, body) => isForFree(init) && isForFree(step) && forLoopsWellFormed(body) - case _ => true - }) ensuring(res => true && tmpl((a,b) => depth <= a*depthStat(stat) + b))*/ - - def eliminateWhileLoopsTree(t: Tree): Tree = { - t match { - case Leaf() => Leaf() - case Node(l,x,r) => Node(eliminateWhileLoopsTree(l), eliminateWhileLoops(x), eliminateWhileLoopsTree(r)) - } - } ensuring(res => true && tmpl((a,b) => depth <= a*depthTree(t) + b)) - - def eliminateWhileLoops(stat: Statement): Statement = (stat match { - case Block(body) => Block(eliminateWhileLoopsTree(body)) - case IfThenElse(expr, then, elze) => IfThenElse(expr, eliminateWhileLoops(then), eliminateWhileLoops(elze)) - case While(expr, body) => For(Skip(), expr, Skip(), eliminateWhileLoops(body)) - case For(init, expr, step, body) => For(eliminateWhileLoops(init), expr, eliminateWhileLoops(step), eliminateWhileLoops(body)) - case other => other - }) ensuring(res => true && tmpl((a,b) => depth <= a*depthStat(stat) + b)) - - /*def eliminateForLoopsTree(t: Tree): Tree = { - t match { - case Leaf() => Leaf() - case Node(l,x,r) => Node(eliminateForLoopsTree(l), eliminateForLoops(x), eliminateForLoopsTree(r)) - } - } ensuring(res => true && tmpl((a,b) => depth <= a*depthTree(t) + b)) - - def eliminateForLoops(stat: Statement): Statement = { - stat match { - case Block(body) => Block(eliminateForLoopsTree(body)) - case IfThenElse(expr, then, elze) => IfThenElse(expr, eliminateForLoops(then), eliminateForLoops(elze)) - case While(expr, body) => While(expr, eliminateForLoops(body)) - case For(init, expr, step, body) => Block(Node(Leaf(),eliminateForLoops(init),Node(Leaf(), - While(expr, Block(Node(Leaf(),eliminateForLoops(body), Node(Leaf(),eliminateForLoops(step), Leaf())))),Leaf()))) - case other => other - } - } ensuring(res => true && tmpl((a,b) => depth <= a*depthStat(stat) + b))*/ -} diff --git a/testcases/orb-testcases/depth/ForElimination.scala b/testcases/orb-testcases/depth/ForElimination.scala deleted file mode 100644 index b1c5ba98f1a7da5c626dd61e55a34b0ed97515c7..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/ForElimination.scala +++ /dev/null @@ -1,103 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - - -object ForElimination { - - sealed abstract class List - case class Nil() extends List - case class Cons(head: Statement, tail: List) extends List - - sealed abstract class Statement - case class Print(msg: BigInt, varID: BigInt) extends Statement - case class Assign(varID: BigInt, expr: Expression) extends Statement - case class Skip() extends Statement - case class Block(body: List) extends Statement - case class IfThenElse(expr: Expression, thenExpr: Statement, elseExpr: Statement) extends Statement - case class While(expr: Expression, body: Statement) extends Statement - case class For(init: Statement, expr: Expression, step: Statement, body: Statement) extends Statement - - sealed abstract class Expression - case class Var(varID: BigInt) extends Expression - case class BigIntLiteral(value: BigInt) extends Expression - case class Plus(lhs: Expression, rhs: Expression) extends Expression - case class Minus(lhs: Expression, rhs: Expression) extends Expression - case class Times(lhs: Expression, rhs: Expression) extends Expression - case class Division(lhs: Expression, rhs: Expression) extends Expression - case class Equals(lhs: Expression, rhs: Expression) extends Expression - case class LessThan(lhs: Expression, rhs: Expression) extends Expression - case class And(lhs: Expression, rhs: Expression) extends Expression - case class Or(lhs: Expression, rhs: Expression) extends Expression - case class Not(expr: Expression) extends Expression - - def sizeStat(st: Statement) : BigInt = st match { - case Block(l) => sizeList(l) + 1 - case IfThenElse(c,th,el) => sizeStat(th) + sizeStat(el) + 1 - case While(c,b) => sizeStat(b) + 1 - case For(init,cond,step,body) => sizeStat(init) + sizeStat(step) + sizeStat(body) - case other => 1 - } - - def sizeList(l: List) : BigInt = l match { - case Cons(h,t) => sizeStat(h) + sizeList(t) - case Nil() => 0 - } - - def isForFree(stat: Statement): Boolean = (stat match { - case Block(body) => isForFreeList(body) - case IfThenElse(_, thenExpr, elseExpr) => isForFree(thenExpr) && isForFree(elseExpr) - case While(_, body) => isForFree(body) - case For(_,_,_,_) => false - case _ => true - }) ensuring(res => true && tmpl((a,b) => depth <= a*sizeStat(stat) + b)) - - def isForFreeList(l: List): Boolean = (l match { - case Nil() => true - case Cons(x, xs) => isForFree(x) && isForFreeList(xs) - }) ensuring(res => true && tmpl((a,b) => depth <= a*sizeList(l) + b)) - - def forLoopsWellFormedList(l: List): Boolean = (l match { - case Nil() => true - case Cons(x, xs) => forLoopsWellFormed(x) && forLoopsWellFormedList(xs) - }) ensuring(res => true && tmpl((a,b) => depth <= a*sizeList(l) + b)) - - def forLoopsWellFormed(stat: Statement): Boolean = (stat match { - case Block(body) => forLoopsWellFormedList(body) - case IfThenElse(_, thenExpr, elseExpr) => forLoopsWellFormed(thenExpr) && forLoopsWellFormed(elseExpr) - case While(_, body) => forLoopsWellFormed(body) - case For(init, _, step, body) => isForFree(init) && isForFree(step) && forLoopsWellFormed(body) - case _ => true - }) ensuring(res => true && tmpl((a,b) => depth <= a*sizeStat(stat) + b)) - - def eliminateWhileLoopsList(l: List): List = { - l match { - case Nil() => Nil() - case Cons(x, xs) => Cons(eliminateWhileLoops(x), eliminateWhileLoopsList(xs)) - } - } ensuring(res => true && tmpl((a,b) => depth <= a*sizeList(l) + b)) - - def eliminateWhileLoops(stat: Statement): Statement = (stat match { - case Block(body) => Block(eliminateWhileLoopsList(body)) - case IfThenElse(expr, thenExpr, elseExpr) => IfThenElse(expr, eliminateWhileLoops(thenExpr), eliminateWhileLoops(elseExpr)) - case While(expr, body) => For(Skip(), expr, Skip(), eliminateWhileLoops(body)) - case For(init, expr, step, body) => For(eliminateWhileLoops(init), expr, eliminateWhileLoops(step), eliminateWhileLoops(body)) - case other => other - }) ensuring(res => true && tmpl((a,b) => depth <= a*sizeStat(stat) + b)) - - def eliminateForLoopsList(l: List): List = { - l match { - case Nil() => Nil() - case Cons(x, xs) => Cons(eliminateForLoops(x), eliminateForLoopsList(xs)) - } - } ensuring(res => true && tmpl((a,b) => depth <= a*sizeList(l) + b)) - - def eliminateForLoops(stat: Statement): Statement = { - stat match { - case Block(body) => Block(eliminateForLoopsList(body)) - case IfThenElse(expr, thenExpr, elseExpr) => IfThenElse(expr, eliminateForLoops(thenExpr), eliminateForLoops(elseExpr)) - case While(expr, body) => While(expr, eliminateForLoops(body)) - case For(init, expr, step, body) => Block(Cons(eliminateForLoops(init), Cons(While(expr, Block(Cons(eliminateForLoops(body), Cons(eliminateForLoops(step), Nil())))), Nil()))) - case other => other - } - } ensuring(res => true && tmpl((a,b) => depth <= a*sizeStat(stat) + b)) -} diff --git a/testcases/orb-testcases/depth/InsertionSort.scala b/testcases/orb-testcases/depth/InsertionSort.scala deleted file mode 100644 index e52adc62f4a119393e4a3560af1d20aae7b9c34c..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/InsertionSort.scala +++ /dev/null @@ -1,28 +0,0 @@ -import scala.collection.immutable.Set -import leon.instrumentation._ -import leon.invariant._ - - -object InsertionSort { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case class Nil() extends List - - def size(l : List) : BigInt = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) - - def sortedIns(e: BigInt, l: List): List = { - l match { - case Nil() => Cons(e,Nil()) - case Cons(x,xs) => if (x <= e) Cons(x,sortedIns(e, xs)) else Cons(e, l) - } - } ensuring(res => size(res) == size(l) + 1 && tmpl((a,b) => depth <= a*size(l) +b)) - - def sort(l: List): List = (l match { - case Nil() => Nil() - case Cons(x,xs) => sortedIns(x, sort(xs)) - - }) ensuring(res => size(res) == size(l) && tmpl((a,b) => depth <= a*(size(l)*size(l)) +b)) -} diff --git a/testcases/orb-testcases/depth/LeftistHeap.scala b/testcases/orb-testcases/depth/LeftistHeap.scala deleted file mode 100644 index 06a59d2d6745821130d2da5a7e6453425c573b81..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/LeftistHeap.scala +++ /dev/null @@ -1,66 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object LeftistHeap { - sealed abstract class Heap - case class Leaf() extends Heap - case class Node(rk : BigInt, value: BigInt, left: Heap, right: Heap) extends Heap - - private def rightHeight(h: Heap) : BigInt = h match { - case Leaf() => 0 - case Node(_,_,_,r) => rightHeight(r) + 1 - } - - private def rank(h: Heap) : BigInt = h match { - case Leaf() => 0 - case Node(rk,_,_,_) => rk - } - - private def hasLeftistProperty(h: Heap) : Boolean = (h match { - case Leaf() => true - case Node(_,_,l,r) => hasLeftistProperty(l) && hasLeftistProperty(r) && rightHeight(l) >= rightHeight(r) && (rank(h) == rightHeight(h)) - }) - - def leftRightHeight(h: Heap) : BigInt = {h match { - case Leaf() => 0 - case Node(_,_,l,r) => rightHeight(l) - }} - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h)) - h match { - case Node(_,_,l,r) => merge(l, r) - case l @ Leaf() => l - } - } ensuring(res => true && tmpl((a,b) => depth <= a*leftRightHeight(h) + b)) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2)) - h1 match { - case Leaf() => h2 - case Node(_, v1, l1, r1) => h2 match { - case Leaf() => h1 - case Node(_, v2, l2, r2) => - if(v1 > v2) - makeT(v1, l1, merge(r1, h2)) - else - makeT(v2, l2, merge(h1, r2)) - } - } - } ensuring(res => true && tmpl((a,b,c) => depth <= a*rightHeight(h1) + b*rightHeight(h2) + c)) - - private def makeT(value: BigInt, left: Heap, right: Heap) : Heap = { - if(rank(left) >= rank(right)) - Node(rank(right) + 1, value, left, right) - else - Node(rank(left) + 1, value, right, left) - } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap)) - - merge(Node(1, element, Leaf(), Leaf()), heap) - - } ensuring(res => true && tmpl((a,b,c) => depth <= a*rightHeight(heap) + c)) -} diff --git a/testcases/orb-testcases/depth/ListOperations.scala b/testcases/orb-testcases/depth/ListOperations.scala deleted file mode 100644 index 9eb3c790707d630b32f42b8d707b367c8622a1be..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/ListOperations.scala +++ /dev/null @@ -1,61 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object ListOperations { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def append(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => Cons(x, append(xs, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && tmpl((a,b) => depth <= a*size(l1) + b)) - - def reverseRec(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverseRec(xs, Cons(x, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && tmpl((a,b) => depth <= a*size(l1) + b)) - - def reverse(l: List): List = { - reverseRec(l, Nil()) - - } ensuring (res => size(l) == size(res) && tmpl((a,b) => depth <= a*size(l) + b)) - - def reverse2(l: List): List = { - l match { - case Nil() => l - case Cons(hd, tl) => append(reverse2(tl), Cons(hd, Nil())) - } - } ensuring (res => size(res) == size(l) && tmpl((a,b) => depth <= a*(size(l)*size(l)) + b)) - - def remove(elem: BigInt, l: List): List = { - l match { - case Nil() => Nil() - case Cons(hd, tl) => if (hd == elem) remove(elem, tl) else Cons(hd, remove(elem, tl)) - } - } ensuring (res => size(l) >= size(res) && tmpl((a,b) => depth <= a*size(l) + b)) - - def contains(list: List, elem: BigInt): Boolean = (list match { - case Nil() => false - case Cons(x, xs) => x == elem || contains(xs, elem) - - }) ensuring (res => true && tmpl((a,b) => depth <= a*size(list) + b)) - - def distinct(l: List): List = ( - l match { - case Nil() => Nil() - case Cons(x, xs) => { - val newl = distinct(xs) - if (contains(newl, x)) newl - else Cons(x, newl) - } - }) ensuring (res => size(l) >= size(res) && tmpl((a,b) => depth <= a*(size(l)*size(l)) + b)) -} diff --git a/testcases/orb-testcases/depth/MergeSort.scala b/testcases/orb-testcases/depth/MergeSort.scala deleted file mode 100644 index de9fea5347a6ddf27679ae69b7b559a4ca981aa2..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/MergeSort.scala +++ /dev/null @@ -1,56 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object MergeSort { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case class Nil() extends List - - def size(list:List): BigInt = {list match { - case Nil() => BigInt(0) - case Cons(x,xs) => 1 + size(xs) - }} ensuring(res => res >= 0) - - def length(l:List): BigInt = { - l match { - case Nil() => BigInt(0) - case Cons(x,xs) => 1 + length(xs) - } - } ensuring(res => res >= 0 && res == size(l) && tmpl((a,b) => depth <= a*size(l) + b)) - - def split(l:List,n:BigInt): (List,List) = { - require(n >= 0 && n <= size(l)) - if (n <= 0) (Nil(),l) - else - l match { - case Nil() => (Nil(),l) - case Cons(x,xs) => { - val (fst,snd) = split(xs, n-1) - (Cons(x,fst), snd) - } - } - } ensuring(res => size(res._2) == size(l) - n && size(res._1) == n && tmpl((a,b) => depth <= a*n +b)) - - def merge(aList:List, bList:List):List = (bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - }) ensuring(res => size(aList)+size(bList) == size(res) && tmpl((a,b,c) => depth <= a*size(aList) + b*size(bList) + c)) - - def mergeSort(list:List):List = (list match { - case Nil() => list - case Cons(x,Nil()) => list - case _ => - val (fst,snd) = split(list,length(list)/2) - merge(mergeSort(fst), mergeSort(snd)) - - }) ensuring(res => size(res) == size(list) && tmpl((a,b) => depth <= a*size(list) + b)) -} diff --git a/testcases/orb-testcases/depth/PrimesParallel.scala b/testcases/orb-testcases/depth/PrimesParallel.scala deleted file mode 100644 index 98724e97289a565d00f2f96b18754849dcc448e0..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/PrimesParallel.scala +++ /dev/null @@ -1,78 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object PrimesParallel { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - //a program that removes from a list, all multiples of a number 'i' upto 'n' - //the depth of this program is again 1 -// def removeMultiples(l: List, i: BigInt, n: BigInt, incr: BigInt): (List, BigInt) = { -// require(i >= 0 && incr >= 1 && i <= n) -// l match { -// case Nil() => (Nil(), 0) -// case Cons(x, t) => { -// if (x < i) { -// val (r,d) = removeMultiples(t, i, n, incr) -// (Cons(x, r), max(d, 2)) -// -// } else if (x > i) { -// val ni = i + incr -// if (ni > n) (l, 2) -// else { -// val (r,d) = removeMultiples(l, ni, n, incr) -// (r, max(d, 2)) -// } -// -// -// } else { -// val ni = i + incr -// if (ni > n) (t, 2) -// else{ -// val (r,d) = removeMultiples(l, ni, n, incr) -// (r, max(d, 2)) -// } -// } -// } -// } -// } //ensuring (res => true && tmpl ((a) => res._2 <= a)) - //ensuring (res => true && tmpl ((a,b) => time <= a*(size(l) + n - i) + b)) - - //another function with constant depth -// def createList(i: BigInt, n: BigInt) : (List, BigInt) = { -// require(i <= n) -// if(n == i) (Nil(), 0) -// else { -// val (r, d) = createList(i+1, n) -// (Cons(i, r), max(d, 2)) -// } -// } //ensuring(res => true && tmpl((a) => res._2 <= a)) - //ensuring(res => true && tmpl((a,b) => time <= a*(n-i) + b)) - -// def removeNonPrimes(currval: BigInt, l: List, n: BigInt, sqrtn: BigInt): (List, BigInt) = { -// require(currval <= sqrtn && sqrtn <= n && currval >= 1) -// -// val (r,d) = removeMultiples(l, currval, n, currval) -// if(currval == sqrtn) { -// (r, d + 2) -// } else { -// val (res, t) = removeNonPrimes(currval + 1, r, n, sqrtn) -// (res, t + 2) -// } -// } //ensuring(res => true && tmpl((a,b) => res._2 <= a*(sqrtn - currval) + b)) - -// def simplePrimes(n: BigInt, sqrtn : BigInt) : (List, BigInt) = { -// require(sqrtn >= 2 && sqrtn <= n) -// -// val (l, d1) = createList(2, n) -// val (resl, t2) = removeNonPrimes(2, l, n, sqrtn) -// (resl, d1 + t2 + 3) -// } //ensuring(res => true && tmpl((a,b) => res._2 <= a*sqrtn + b)) -} diff --git a/testcases/orb-testcases/depth/PropLogicDepth.scala b/testcases/orb-testcases/depth/PropLogicDepth.scala deleted file mode 100644 index 881cd61a4b31ad2b40ab22b84651f4362e00878c..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/PropLogicDepth.scala +++ /dev/null @@ -1,112 +0,0 @@ -import scala.collection.immutable.Set -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object PropLogicDepth { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Implies(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Literal(id: BigInt) extends Formula - case class True() extends Formula - case class False() extends Formula - - def max(x: BigInt,y: BigInt) = if (x >= y) x else y - - def nestingDepth(f: Formula) : BigInt = (f match { - case And(lhs, rhs) => max(nestingDepth(lhs),nestingDepth(rhs)) + 1 - case Or(lhs, rhs) => max(nestingDepth(lhs),nestingDepth(rhs)) + 1 - case Implies(lhs, rhs) => max(nestingDepth(lhs),nestingDepth(rhs)) + 1 - case Not(f) => nestingDepth(f) + 1 - case _ => 1 - }) - - def removeImplies(f: Formula): Formula = (f match { - case And(lhs, rhs) => And(removeImplies(lhs), removeImplies(rhs)) - case Or(lhs, rhs) => Or(removeImplies(lhs), removeImplies(rhs)) - case Implies(lhs, rhs) => Or(Not(removeImplies(lhs)),removeImplies(rhs)) - case Not(f) => Not(removeImplies(f)) - case _ => f - - }) ensuring((res) => true && tmpl((a,b) => depth <= a*nestingDepth(f) + b)) - - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Implies(lhs, rhs) => Implies(nnf(lhs), nnf(rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Implies(lhs, rhs)) => And(nnf(lhs), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case Not(Literal(_)) => formula - case Literal(_) => formula - case Not(True()) => False() - case Not(False()) => True() - case _ => formula - }) ensuring((res) => true && tmpl((a,b) => depth <= a*nestingDepth(formula) + b)) - - def isNNF(f: Formula): Boolean = { f match { - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Implies(lhs, rhs) => false - case Not(Literal(_)) => true - case Not(_) => false - case _ => true - }} ensuring((res) => true && tmpl((a,b) => depth <= a*nestingDepth(f) + b)) - - def simplify(f: Formula): Formula = (f match { - case And(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs or rhs is false, return false - //if lhs is true return rhs - //if rhs is true return lhs - (sl,sr) match { - case (False(), _) => False() - case (_, False()) => False() - case (True(), _) => sr - case (_, True()) => sl - case _ => And(sl, sr) - } - } - case Or(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs or rhs is true, return true - //if lhs is false return rhs - //if rhs is false return lhs - (sl,sr) match { - case (True(), _) => True() - case (_, True()) => True() - case (False(), _) => sr - case (_, False()) => sl - case _ => Or(sl, sr) - } - } - case Implies(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs is false return true - //if rhs is true return true - //if lhs is true return rhs - //if rhs is false return Not(rhs) - (sl,sr) match { - case (False(), _) => True() - case (_, True()) => True() - case (True(), _) => sr - case (_, False()) => Not(sl) - case _ => Implies(sl, sr) - } - } - case Not(True()) => False() - case Not(False()) => True() - case _ => f - - }) ensuring((res) => true && tmpl((a,b) => depth <= a*nestingDepth(f) + b)) -} \ No newline at end of file diff --git a/testcases/orb-testcases/depth/QSortDepth.scala b/testcases/orb-testcases/depth/QSortDepth.scala deleted file mode 100644 index cd8f16627836a3d23067dafaac9bcac627140d6b..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/QSortDepth.scala +++ /dev/null @@ -1,41 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object QSortDepth { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case class Nil() extends List - - def size(l:List): BigInt = {l match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - }} - - case class Triple(fst:List,snd:List, trd: List) - - def append(aList:List,bList:List): List = {aList match { - case Nil() => bList - case Cons(x, xs) => Cons(x,append(xs,bList)) - }} ensuring(res => size(res) == size(aList) + size(bList) && tmpl((a,b) => depth <= a*size(aList) +b)) - - def partition(n:BigInt,l:List) : Triple = (l match { - case Nil() => Triple(Nil(), Nil(), Nil()) - case Cons(x,xs) => { - val t = partition(n,xs) - if (n < x) Triple(t.fst, t.snd, Cons(x,t.trd)) - else if(n == x) Triple(t.fst, Cons(x,t.snd), t.trd) - else Triple(Cons(x,t.fst), t.snd, t.trd) - } - }) ensuring(res => (size(l) == size(res.fst) + size(res.snd) + size(res.trd)) && tmpl((a,b) => depth <= a*size(l) +b)) - - def quickSort(l:List): List = (l match { - case Nil() => Nil() - case Cons(x,Nil()) => l - case Cons(x,xs) => { - val t = partition(x, xs) - append(append(quickSort(t.fst), Cons(x, t.snd)), quickSort(t.trd)) - } - case _ => l - }) ensuring(res => size(res) == size(l) && tmpl((a,b,c) => depth <= a*(size(l)*size(l)) + b*size(l) + c)) -} diff --git a/testcases/orb-testcases/depth/RedBlackTree.scala b/testcases/orb-testcases/depth/RedBlackTree.scala deleted file mode 100755 index 9bde5ebdf9f5f59c133498602beb7ae2c5a9c0c4..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/RedBlackTree.scala +++ /dev/null @@ -1,113 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import scala.collection.immutable.Set -import leon.annotation._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: BigInt, right: Tree) extends Tree - - def twopower(x: BigInt) : BigInt = { - require(x >= 0) - if(x < 1) 1 - else - 2* twopower(x - 1) - } - - def size(t: Tree): BigInt = { - require(blackBalanced(t)) - (t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - }) - } //ensuring (res => true && tmpl((a,b) => twopower(blackHeight(t)) <= a*res + b)) - - def blackHeight(t : Tree) : BigInt = { - t match { - case Empty() => 0 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - } - - //We consider leaves to be black by definition - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case _ => false - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case _ => true - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case _ => true - } - - // <<insert element x into the tree t>> - def ins(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if(x < y) { - val t1 = ins(x, a) - balance(c, t1, y, b) - } - else if (x == y){ - Node(c,a,y,b) - } - else{ - val t1 = ins(x, b) - balance(c,a,y,t1) - } - } - } ensuring(res => true && tmpl((a,b) => depth <= a*blackHeight(t) + b)) - - def makeBlack(n: Tree): Tree = { - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } - - def add(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) ) - val t1 = ins(x, t) - makeBlack(t1) - - } ensuring(res => true && tmpl((a,b) => depth <= a*blackHeight(t) + b)) - - def balance(co: Color, l: Tree, x: BigInt, r: Tree): Tree = { - Node(co,l,x,r) - match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case _ => Node(co,l,x,r) - } - } - - -} diff --git a/testcases/orb-testcases/depth/SpeedBenchmarks.scala b/testcases/orb-testcases/depth/SpeedBenchmarks.scala deleted file mode 100644 index c8679d68de7065fd03de68f762233c998a6c5fdb..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/SpeedBenchmarks.scala +++ /dev/null @@ -1,109 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object SpeedBenchmarks { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - sealed abstract class StringBuffer - case class Chunk(str: List, next: StringBuffer) extends StringBuffer - case class Empty() extends StringBuffer - - def length(sb: StringBuffer) : BigInt = sb match { - case Chunk(_, next) => 1 + length(next) - case _ => 0 - } - - def sizeBound(sb: StringBuffer, k: BigInt) : Boolean ={ - sb match { - case Chunk(str, next) => size(str) <= k && sizeBound(next, k) - case _ => 0 <= k - } - } - - /** - * Fig. 1 of SPEED, POPL'09: The functional version of the implementation. - * Equality check of two string buffers - */ - def Equals(str1: List, str2: List, s1: StringBuffer, s2: StringBuffer, k: BigInt) : Boolean = { - require(sizeBound(s1, k) && sizeBound(s2, k) && size(str1) <= k && size(str2) <= k && k >= 0) - - (str1, str2) match { - case (Cons(h1,t1), Cons(h2,t2)) => { - - if(h1 != h2) false - else Equals(t1,t2, s1,s2, k) - } - case (Cons(_,_), Nil()) => { - //load from s2 - s2 match { - case Chunk(str, next) => Equals(str1, str, s1, next, k) - case Empty() => false - } - } - case (Nil(), Cons(_,_)) => { - //load from s1 - s1 match { - case Chunk(str, next) => Equals(str, str2, next, s2, k) - case Empty() => false - } - } - case _ =>{ - //load from both - (s1,s2) match { - case (Chunk(nstr1, next1),Chunk(nstr2, next2)) => Equals(nstr1, nstr2, next1, next2, k) - case (Empty(),Chunk(nstr2, next2)) => Equals(str1, nstr2, s1, next2, k) - case (Chunk(nstr1, next1), Empty()) => Equals(nstr1, str2, next1, s2, k) - case _ => true - } - } - } - } ensuring(res => true && tmpl((a,b,c,d,e) => depth <= a*((k+1)*(length(s1) + length(s2))) + b*size(str1) + e)) - - def max(x: BigInt, y: BigInt) : BigInt = if(x >= y) x else y - - //Fig. 2 of Speed POPL'09 - def Dis1(x : BigInt, y : BigInt, n: BigInt, m: BigInt) : BigInt = { - if(x >= n) 0 - else { - if(y < m) Dis1(x, y+1, n, m) - else Dis1(x+1, y, n, m) - } - } ensuring(res => true && tmpl((a,b,c) => depth <= a*max(0,n-x) + b*max(0,m-y) + c)) - - //Fig. 2 of Speed POPL'09 - def Dis2(x : BigInt, z : BigInt, n: BigInt) : BigInt = { - if(x >= n) 0 - else { - if(z > x) Dis2(x+1, z, n) - else Dis2(x, z+1, n) - } - } ensuring(res => true && tmpl((a,b,c) => depth <= a*max(0,n-x) + b*max(0,n-z) + c)) - - //Pg. 138, Speed POPL'09 - def Dis3(x : BigInt, b : Boolean, t: BigInt, n: BigInt) : BigInt = { - require((b && t == 1) || (!b && t == -1)) - if(x > n || x < 0) 0 - else { - if(b) Dis3(x+t, b, t, n) - else Dis3(x-t, b, t, n) - } - } ensuring(res => true && tmpl((a,c) => depth <= a*max(0,(n-x)) + c)) - - //Pg. 138, Speed POPL'09 - def Dis4(x : BigInt, b : Boolean, t: BigInt, n: BigInt) : BigInt = { - if(x > n || x < 0) 0 - else { - if(b) Dis4(x+t, b, t, n) - else Dis4(x-t, b, t, n) - } - } ensuring(res => true && tmpl((a,c,d,e) => (((b && t >= 0) || (!b && t < 0)) && depth <= a*max(0,(n-x)) + c) - || (((!b && t >= 0) || (b && t < 0)) && depth <= d*max(0,x) + e))) -} diff --git a/testcases/orb-testcases/depth/TreeOperations.scala b/testcases/orb-testcases/depth/TreeOperations.scala deleted file mode 100755 index d6199f16345d0e39ba3239949d8ac0486d3345e5..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/depth/TreeOperations.scala +++ /dev/null @@ -1,93 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object TreeOperations { - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def listSize(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + listSize(t) - }) - - def size(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - size(l) + size(r) + 1 - } - } - } - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def insert(elem: BigInt, t: Tree): Tree = { - t match { - case Leaf() => Node(Leaf(), elem, Leaf()) - case Node(l, x, r) => if (x <= elem) Node(l, x, insert(elem, r)) - else Node(insert(elem, l), x, r) - } - } ensuring (res => height(res) <= height(t) + 1 && tmpl((a,b) => depth <= a*height(t) + b)) - - def addAll(l: List, t: Tree): Tree = { - l match { - case Nil() => t - case Cons(x, xs) =>{ - val newt = insert(x, t) - addAll(xs, newt) - } - } - } ensuring(res => true && tmpl((a,b,c) => depth <= a*(listSize(l) * (height(t) + listSize(l))) + b*listSize(l) + c)) - - def remove(elem: BigInt, t: Tree): Tree = { - t match { - case Leaf() => Leaf() - case Node(l, x, r) => { - - if (x < elem) Node(l, x, remove(elem, r)) - else if (x > elem) Node(remove(elem, l), x, r) - else { - t match { - case Node(Leaf(), x, Leaf()) => Leaf() - case Node(Leaf(), x, Node(_, rx, _)) => Node(Leaf(), rx, remove(rx, r)) - case Node(Node(_, lx, _), x, r) => Node(remove(lx, l), lx, r) - case _ => Leaf() - } - } - } - } - } ensuring (res => height(res) <= height(t) && tmpl ((a, b, c) => depth <= a*height(t) + b)) - - def removeAll(l: List, t: Tree): Tree = { - l match { - case Nil() => t - case Cons(x, xs) => removeAll(xs, remove(x, t)) - } - } ensuring(res => true && tmpl((a,b,c) => depth <= a*(listSize(l) * height(t)) + b*listSize(l) + c)) - - def contains(elem : BigInt, t : Tree) : Boolean = { - t match { - case Leaf() => false - case Node(l, x, r) => - if(x == elem) true - else if (x < elem) contains(elem, r) - else contains(elem, l) - } - } ensuring (res => true && tmpl((a,b) => depth <= a*height(t) + b)) -} \ No newline at end of file diff --git a/testcases/orb-testcases/numerical/ConcatVariationsAbs.scala b/testcases/orb-testcases/numerical/ConcatVariationsAbs.scala deleted file mode 100644 index bff880ab30ac1495c7ab6c706265376f1fafe7ad..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/numerical/ConcatVariationsAbs.scala +++ /dev/null @@ -1,43 +0,0 @@ -import leon.invariant._ - -object ConcatVariationsAbs { - def genL(n: BigInt): BigInt = { - require(n >= 0) - if (n == 0) - BigInt(2) - else - 4 + genL(n - 1) - } ensuring (res => tmpl((a, b) => res <= a * n + b)) - - def append(l1: BigInt, l2: BigInt): BigInt = { - require(l1 >= 0 && l2 >= 0) - if (l1 == 0) - BigInt(3) - else - append(l1 - 1, l2 + 1) + 5 - } ensuring (res => tmpl((a, b) => res <= a * l1 + b)) - - def f_good(m: BigInt, n: BigInt): BigInt = { - require(0 <= m && 0 <= n) - if (m == 0) BigInt(2) - else { - val t1 = genL(n) - val t2 = f_good(m - 1, n) - val t3 = append(n, n * (m - 1)) - (t1 + t2 + t3 + 6) - } - - } ensuring (res => tmpl((a, b, c, d) => res <= a * (n * m) + b * n + c * m + d)) - - def f_worst(m: BigInt, n: BigInt): BigInt = { - require(0 <= m && 0 <= n) - if (m == 0) BigInt(2) - else { - val t1 = genL(n) - val t2 = f_worst(m - 1, n) - val t3 = append(n * (m - 1), n) - (t1 + t2 + t3 + 6) - } - - } ensuring (res => tmpl((a, c, d, e, f) => res <= a * ((n * m) * m) + c * (n * m) + d * n + e * m + f)) -} diff --git a/testcases/orb-testcases/numerical/ListAppendAbs.scala b/testcases/orb-testcases/numerical/ListAppendAbs.scala deleted file mode 100755 index 63038cc74064b928534a0e53ac0baf0184c09d78..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/numerical/ListAppendAbs.scala +++ /dev/null @@ -1,20 +0,0 @@ -import leon.invariant._ - -object ListAppendAbs -{ - def app(x: BigInt) : BigInt = { - require(x >=0) - - app0(x,1) - - } ensuring(res => res == x + 1) - - def app0(a: BigInt, b: BigInt) : BigInt = { - require(a >=0 && b >=0) - - if(a <= 0) - b - else - app0(a-1,b+1) - } ensuring(res => tmpl((p, q, r) => (p*res + q*a + r*b == 0 && q != 0))) -} diff --git a/testcases/orb-testcases/numerical/LogarithmTest.scala b/testcases/orb-testcases/numerical/LogarithmTest.scala deleted file mode 100755 index 00fdc552dcb7b0d691139f07578fed5d654d0272..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/numerical/LogarithmTest.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.invariant._ -import leon.annotation._ - -object LogarithmTest { - - @monotonic - def log(x: BigInt) : BigInt = { - require(x >= 0) - if(x <= 1) BigInt(0) - else { - 1 + log(x/2) - } - } ensuring(_ >= 0) - - def binarySearchAbs(x: BigInt, min: BigInt, max: BigInt): BigInt = { - require(max - min >= 0) - if (max - min <= 1) BigInt(2) - else { - val mid = (min + max) / 2 - if (x < mid) { - binarySearchAbs(x, min, mid) + 5 - } else if (x > mid) { - binarySearchAbs(x, mid + 1, max) + 7 - } else - BigInt(8) - } - } ensuring(res => tmpl((a,b) => res <= a*log(max - min) + b)) - //ensuring(res => tmpl((a,b) => res <= 7*log(max - min) + 2)) - // -} diff --git a/testcases/orb-testcases/numerical/QueueAbs.scala b/testcases/orb-testcases/numerical/QueueAbs.scala deleted file mode 100644 index a7aee3a93d4ca9ee058b2f0695f001d29fdf3acc..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/numerical/QueueAbs.scala +++ /dev/null @@ -1,70 +0,0 @@ -import leon.invariant._ - -object AmortizedQueue { - def concat(l1: BigInt, l2: BigInt): BigInt = { - require(l1 >= 0 && l2 >= 0) - if (l1 == 0) - BigInt(3) - else - concat(l1 - 1, l2 + 1) + 5 - } ensuring (res => tmpl((a, b) => res <= a * l1 + b)) - - def reverseRec(l1: BigInt, l2: BigInt): BigInt = { - require(l1 >= 0 && l2 >= 0) - if (l1 == 0) - BigInt(3) - else { - reverseRec(l1 - 1, l2 + 1) + 6 - } - } ensuring (res => tmpl((a, b) => res <= a * l1 + b)) - - def reverse(l: BigInt): BigInt = { - require(l >= 0) - reverseRec(l, 0) + 1 - } ensuring (res => tmpl((a, b) => res <= a * l + b)) - - def create(front: BigInt, rear: BigInt): BigInt = { - require(front >= 0 && rear >= 0) - if (rear <= front) - BigInt(4) - else { - val t1 = reverse(rear) - val t2 = concat(front, rear) - t1 + t2 + 7 - } - } - - def enqueue(q: BigInt, front: BigInt, rear: BigInt): BigInt = { - require(q == front + rear && q >= 0 && front >= 0 && rear >= 0) - create(front, rear) + 5 - } ensuring (res => tmpl((a, b) => res <= a * q + b)) - - def dequeue(q: BigInt, front: BigInt, rear: BigInt): BigInt = { - require(q == front + rear && q >= 1 && front >= rear && rear >= 0) - if (front >= 1) { - create(front - 1, rear) + 4 - } else { - //since front should be greater than rear, here rear should be 0 as well - BigInt(5) - } - } ensuring (res => tmpl((a, b) => res <= a * q + b)) - - def removeLast(l: BigInt): BigInt = { - require(l >= 1) - if (l == 1) { - BigInt(4) - } else { - removeLast(l - 1) + 6 - } - } ensuring (res => tmpl((a, b) => res <= a * l + b)) - - def pop(q: BigInt, front: BigInt, rear: BigInt): BigInt = { - require(q == front + rear && q >= 1 && front >= rear && rear >= 0) - if (rear >= 1) { - BigInt(3) - } else { - val t1 = removeLast(front) - t1 + 5 - } - } ensuring (res => tmpl((a, b) => res <= a * q + b)) -} diff --git a/testcases/orb-testcases/numerical/SimpleInterProc.scala b/testcases/orb-testcases/numerical/SimpleInterProc.scala deleted file mode 100755 index b2ac527b54cefa3d1dadb063ac58a770dcc76bf9..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/numerical/SimpleInterProc.scala +++ /dev/null @@ -1,16 +0,0 @@ -object SimpleInterProc -{ - def s(x: BigInt) : BigInt = { - if(x < 0) - makePositive(x) - else - s(x-1) + 1 - } ensuring(res => res != -1) - - def makePositive(y : BigInt) : BigInt = { - 2*negate(y) - } - def negate(c : BigInt) : BigInt={ - -c - } -} \ No newline at end of file diff --git a/testcases/orb-testcases/numerical/SimpleLoop.scala b/testcases/orb-testcases/numerical/SimpleLoop.scala deleted file mode 100755 index 6a2cdb3d9958f5ad41783d3723b1c08ef7c0ba16..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/numerical/SimpleLoop.scala +++ /dev/null @@ -1,9 +0,0 @@ -object SimpleLoop -{ - def s(x: BigInt) : BigInt = { - if(x < 0) - BigInt(0) - else - s(x-1) + 1 - } ensuring(res => res != -1) -} \ No newline at end of file diff --git a/testcases/orb-testcases/numerical/see-saw.scala b/testcases/orb-testcases/numerical/see-saw.scala deleted file mode 100644 index 894a8caed2a298a22a89d8bb6925cc03f022407c..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/numerical/see-saw.scala +++ /dev/null @@ -1,15 +0,0 @@ -object SeeSaw { - def s(x: BigInt, y: BigInt, z: BigInt): BigInt = { - require(y >= 0) - - if (x >= 100) { - y - } else if (x <= z) { //some condition - s(x + 1, y + 2, z) - } else if (x <= z + 9) { //some condition - s(x + 1, y + 3, z) - } else { - s(x + 2, y + 1, z) - } - } ensuring (res => (100 - x <= 2 * res)) -} \ No newline at end of file diff --git a/testcases/orb-testcases/stack/BinaryTrie.scala b/testcases/orb-testcases/stack/BinaryTrie.scala deleted file mode 100644 index f2dfd876cdbc51c969f4afc7d1548810be111c02..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/stack/BinaryTrie.scala +++ /dev/null @@ -1,120 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -//import scala.collection.immutable.Set - -object BinaryTrie { - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(nvalue: BigInt, left: Tree, right: Tree) extends Tree - - sealed abstract class IList - case class Cons(head: BigInt, tail: IList) extends IList - case class Nil() extends IList - - def listSize(l: IList): BigInt = (l match { - case Nil() => 0 - case Cons(x, xs) => 1 + listSize(xs) - }) - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(x, l, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def find(inp: IList, t: Tree): Tree = { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x, xs @ Cons(y, _)) => { - t match { - case Leaf() => t - case Node(v, l, r) => { - if (y > 0) find(xs, l) else find(xs, r) - } - } - } - case _ => t - } - } ensuring (_ => stack <= ? * listSize(inp) + ?) - - def insert(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => t - case Cons(x, xs) => { - val newch = insert(xs, Leaf()) - newch match { - case Leaf() => Node(x, Leaf(), Leaf()) - case Node(y, _, _) => if (y > 0) Node(x, newch, Leaf()) else Node(y, Leaf(), newch) - } - } - } - - } - case Node(v, l, r) => { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x, xs @ Cons(y, _)) => { - val ch = if (y > 0) l else r - if (y > 0) - Node(v, insert(xs, ch), r) - else - Node(v, l, insert(xs, ch)) - } - case _ => t - } - } - } - } ensuring (_ => stack <= ? * listSize(inp) + ?) - - def create(inp: IList): Tree = { - insert(inp, Leaf()) - } ensuring (_ => stack <= ? * listSize(inp) + ?) - - def delete(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => Leaf() - case Cons(x ,xs) => { - //the input is not in the tree, so do nothing - Leaf() - } - } - } - case Node(v, l, r) => { - inp match { - case Nil() => { - //the tree has extensions of the input list so do nothing - t - } - case Cons(x, Nil()) => { - //if "l" and "r" are nil, remove the node - if(l == Leaf() && r == Leaf()) Leaf() - else t - } - case Cons(x ,xs@Cons(y, _)) => { - val ch = if(y > 0) l else r - val newch = delete(xs, ch) - if(newch == Leaf() && ((y > 0 && r == Leaf()) || (y <= 0 && l == Leaf()))) Leaf() - else { - if(y > 0) - Node(v, newch, r) - else - Node(v, l, newch) - } - } - case _ => t - } - } - } - } ensuring (_ => stack <= ? * listSize(inp) + ?) -} diff --git a/testcases/orb-testcases/stack/BinomialHeap.scala b/testcases/orb-testcases/stack/BinomialHeap.scala deleted file mode 100644 index e18b9b1438b9c66925750dd86a2367f76f5866a0..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/stack/BinomialHeap.scala +++ /dev/null @@ -1,207 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object BinomialHeap { - //sealed abstract class TreeNode - case class TreeNode(rank: BigInt, elem: Element, children: BinomialHeap) - case class Element(n: BigInt) - - sealed abstract class BinomialHeap - case class ConsHeap(head: TreeNode, tail: BinomialHeap) extends BinomialHeap - case class NilHeap() extends BinomialHeap - - sealed abstract class List - case class NodeL(head: BinomialHeap, tail: List) extends List - case class NilL() extends List - - sealed abstract class OptionalTree - case class Some(t : TreeNode) extends OptionalTree - case class None() extends OptionalTree - - /* Lower or Equal than for Element structure */ - private def leq(a: Element, b: Element) : Boolean = { - a match { - case Element(a1) => { - b match { - case Element(a2) => { - if(a1 <= a2) true - else false - } - } - } - } - } - - /* isEmpty function of the Binomial Heap */ - def isEmpty(t: BinomialHeap) = t match { - case ConsHeap(_,_) => false - case _ => true - } - - /* Helper function to determine rank of a TreeNode */ - def rank(t: TreeNode) : BigInt = t.rank /*t match { - case TreeNode(r, _, _) => r - }*/ - - /* Helper function to get the root element of a TreeNode */ - def root(t: TreeNode) : Element = t.elem /*t match { - case TreeNode(_, e, _) => e - }*/ - - /* Linking trees of equal ranks depending on the root element */ - def link(t1: TreeNode, t2: TreeNode): TreeNode = { - if (leq(t1.elem, t2.elem)) { - TreeNode(t1.rank + 1, t1.elem, ConsHeap(t2, t1.children)) - } else { - TreeNode(t1.rank + 1, t2.elem, ConsHeap(t1, t2.children)) - } - } - - def treeNum(h: BinomialHeap) : BigInt = { - h match { - case ConsHeap(head, tail) => 1 + treeNum(tail) - case _ => 0 - } - } - - /* Insert a tree into a binomial heap. The tree should be correct in relation to the heap */ - def insTree(t: TreeNode, h: BinomialHeap) : BinomialHeap = { - h match { - case ConsHeap(head, tail) => { - if (rank(t) < rank(head)) { - ConsHeap(t, h) - } else if (rank(t) > rank(head)) { - ConsHeap(head, insTree(t,tail)) - } else { - insTree(link(t,head), tail) - } - } - case _ => ConsHeap(t, NilHeap()) - } - } ensuring(res => tmpl((a,b) => stack <= a*treeNum(h) + b)) - - /* Merge two heaps together */ - def merge(h1: BinomialHeap, h2: BinomialHeap): BinomialHeap = { - h1 match { - case ConsHeap(head1, tail1) => { - h2 match { - case ConsHeap(head2, tail2) => { - if (rank(head1) < rank(head2)) { - ConsHeap(head1, merge(tail1, h2)) - } else if (rank(head2) < rank(head1)) { - ConsHeap(head2, merge(h1, tail2)) - } else { - mergeWithCarry(link(head1, head2), tail1, tail2) - } - } - case _ => h1 - } - } - case _ => h2 - } - } ensuring(res => tmpl((a,b,c) => stack <= a*treeNum(h1) + b*treeNum(h2) + c)) - - def mergeWithCarry(t: TreeNode, h1: BinomialHeap, h2: BinomialHeap): BinomialHeap = { - h1 match { - case ConsHeap(head1, tail1) => { - h2 match { - case ConsHeap(head2, tail2) => { - if (rank(head1) < rank(head2)) { - - if (rank(t) < rank(head1)) - ConsHeap(t, ConsHeap(head1, merge(tail1, h2))) - else - mergeWithCarry(link(t, head1), tail1, h2) - - } else if (rank(head2) < rank(head1)) { - - if (rank(t) < rank(head2)) - ConsHeap(t, ConsHeap(head2, merge(h1, tail2))) - else - mergeWithCarry(link(t, head2), h1, tail2) - - } else { - ConsHeap(t, mergeWithCarry(link(head1, head2), tail1, tail2)) - } - } - case _ => { - insTree(t, h1) - } - } - } - case _ => insTree(t, h2) - } - } ensuring (res => tmpl((d, e, f) => stack <= d * treeNum(h1) + e * treeNum(h2) + f)) - - //Auxiliary helper function to simplefy findMin and deleteMin - def removeMinTree(h: BinomialHeap): (OptionalTree, BinomialHeap) = { - h match { - case ConsHeap(head, NilHeap()) => (Some(head), NilHeap()) - case ConsHeap(head1, tail1) => { - val (opthead2, tail2) = removeMinTree(tail1) - opthead2 match { - case Some(head2) => - if (leq(root(head1), root(head2))) { - (Some(head1), tail1) - } else { - (Some(head2), ConsHeap(head1, tail2)) - } - case _ => (Some(head1), tail1) - } - } - case _ => (None(), NilHeap()) - } - } ensuring (res => treeNum(res._2) <= treeNum(h) && tmpl((a, b) => stack <= a * treeNum(h) + b)) - - /*def findMin(h: BinomialHeap) : Element = { - val (opt, _) = removeMinTree(h) - opt match { - case Some(TreeNode(_,e,ts1)) => e - case _ => Element(-1) - } - } ensuring(res => true && tmpl((a,b) => time <= a*treeNum(h) + b))*/ - - def minTreeChildren(h: BinomialHeap) : BigInt = { - val (min, _) = removeMinTree(h) - min match { - case Some(TreeNode(_,_,ch)) => treeNum(ch) - case _ => 0 - } - } - - // Discard the minimum element of the extracted min tree and put its children back into the heap - def deleteMin(h: BinomialHeap) : BinomialHeap = { - val (min, ts2) = removeMinTree(h) - min match { - case Some(TreeNode(_,_,ts1)) => merge(ts1, ts2) - case _ => h - } - } ensuring(res => tmpl((a,b,c) => stack <= a*minTreeChildren(h) + b*treeNum(h) + c)) - - /*def heapSize(h: BinomialHeap) : BigInt = { - h match { - NilHeap() => 0 - ConsHeap(head, tail) => - treeSize(head) + heapSize(tail) - } - } - - def treeSize(tree: TreeNode) : BigInt = { - val (_, _, children) = tree - heapSize(children) + 1 - } - - @monotonic - def twopower(x: BigInt) : BigInt = { - require(x >= 0) - if(x < 1) 1 - else - 2* twopower(x - 1) - } - - def sizeProperty(tree: TreeNode) : BigInt = { - val (r, _, _) = tree - treeSize(tree) == twopower(r) - }*/ - -} diff --git a/testcases/orb-testcases/stack/ListOperations.scala b/testcases/orb-testcases/stack/ListOperations.scala deleted file mode 100644 index 3ae4a2d1705051b185c444c7342bf9b180fc4086..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/stack/ListOperations.scala +++ /dev/null @@ -1,35 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object ListOperations { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def reverseRec(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverseRec(xs, Cons(x, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && tmpl((a,b) => stack <= a*size(l1) + b)) - - def contains(list: List, elem: BigInt): Boolean = (list match { - case Nil() => false - case Cons(x, xs) => x == elem || contains(xs, elem) - - }) ensuring (res => tmpl((a,b) => stack <= a*size(list) + b)) - - def distinct(l: List): List = ( - l match { - case Nil() => Nil() - case Cons(x, xs) => { - val newl = distinct(xs) - if (contains(newl, x)) newl - else Cons(x, newl) - } - }) ensuring (res => size(l) >= size(res) && tmpl((a,b) => stack <= a*size(l) + b)) -} diff --git a/testcases/orb-testcases/stack/MergeSort.scala b/testcases/orb-testcases/stack/MergeSort.scala deleted file mode 100644 index 7a104689f06714c51e042291d7660d8b46c92541..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/stack/MergeSort.scala +++ /dev/null @@ -1,63 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -import leon.annotation._ - -object MergeSort { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(list: List): BigInt = (list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - }) //ensuring(res => true && tmpl((a) => res >= 0)) - - def length(l: List): BigInt = { - l match { - case Nil() => BigInt(0) - case Cons(x,xs) => 1 + length(xs) - } - } ensuring(res => res == size(l) && tmpl((a,b) => stack <= a*size(l) + b)) - - def split(l: List, n: BigInt): (List, List) = { - require(n >= 0 && n <= size(l)) - if (n <= 0) (Nil(),l) - else - l match { - case Nil() => (Nil(),l) - case Cons(x,xs) => { - if(n == 1) (Cons(x,Nil()), xs) - else { - val (fst,snd) = split(xs, n-1) - (Cons(x,fst), snd) - } - } - } - } ensuring(res => size(res._2) == size(l) - n && size(res._1) == n && size(res._2) + size(res._1) == size(l) && tmpl((a,b) => stack <= a*size(l) +b)) - - def merge(aList: List, bList: List): List = (bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - }) ensuring(res => size(aList) + size(bList) == size(res) && tmpl((a,b,c) => stack <= a*size(aList) + b*size(bList) + c)) - - def mergeSort(list: List): List = { - list match { - case Cons(x, Nil()) => list - case Cons(_, Cons(_, _)) => - val lby2 = length(list) / 2 - val (fst, snd) = split(list, lby2) - merge(mergeSort(fst), mergeSort(snd)) - - case _ => list - } - } ensuring(res => size(res) == size(list) && tmpl((a,b) => stack <= a*size(list) + b)) -} diff --git a/testcases/orb-testcases/stack/QuickSort.scala b/testcases/orb-testcases/stack/QuickSort.scala deleted file mode 100644 index 20150475348464c5d8c35caaa9a865be0049eace..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/stack/QuickSort.scala +++ /dev/null @@ -1,41 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object QuickSort { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case class Nil() extends List - - def size(l:List): BigInt = {l match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - }} - - case class Triple(fst:List,snd:List, trd: List) - - def append(aList:List,bList:List): List = {aList match { - case Nil() => bList - case Cons(x, xs) => Cons(x,append(xs,bList)) - }} ensuring(res => size(res) == size(aList) + size(bList) && tmpl((a,b) => stack <= a*size(aList) +b)) - - def partition(n:BigInt,l:List) : Triple = (l match { - case Nil() => Triple(Nil(), Nil(), Nil()) - case Cons(x,xs) => { - val t = partition(n,xs) - if (n < x) Triple(t.fst, t.snd, Cons(x,t.trd)) - else if(n == x) Triple(t.fst, Cons(x,t.snd), t.trd) - else Triple(Cons(x,t.fst), t.snd, t.trd) - } - }) ensuring(res => (size(l) == size(res.fst) + size(res.snd) + size(res.trd)) && tmpl((a,b) => stack <= a*size(l) +b)) - - def quickSort(l:List): List = (l match { - case Nil() => Nil() - case Cons(x,Nil()) => l - case Cons(x,xs) => { - val t = partition(x, xs) - append(append(quickSort(t.fst), Cons(x, t.snd)), quickSort(t.trd)) - } - case _ => l - }) ensuring(res => size(l) == size(res) && tmpl((a,b,c,d) => stack <= a*size(l) + d)) -} - diff --git a/testcases/orb-testcases/stack/RedBlackTree.scala b/testcases/orb-testcases/stack/RedBlackTree.scala deleted file mode 100644 index 44f84a9b3e90e98a362348c8862892e384851344..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/stack/RedBlackTree.scala +++ /dev/null @@ -1,110 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -import scala.collection.immutable.Set - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: BigInt, right: Tree) extends Tree - - def twopower(x: BigInt) : BigInt = { - require(x >= 0) - if(x < 1) 1 - else - 2* twopower(x - 1) - } - - def size(t: Tree): BigInt = { - require(blackBalanced(t)) - (t match { - case Empty() => BigInt(0) - case Node(_, l, v, r) => size(l) + 1 + size(r) - }) - } ensuring (res => tmpl((a,b) => twopower(blackHeight(t)) <= a*res + b)) - - def blackHeight(t : Tree) : BigInt = { - t match { - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - case _ => 0 - } - } - - //We consider leaves to be black by definition - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case _ => false - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case _ => true - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case _ => true - } - - // <<insert element x BigInto the tree t>> - def ins(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if(x < y) { - val t1 = ins(x, a) - balance(c, t1, y, b) - } - else if (x == y){ - Node(c,a,y,b) - } - else{ - val t1 = ins(x, b) - balance(c,a,y,t1) - } - } - } ensuring(res => tmpl((a,b) => stack <= a*blackHeight(t) + b)) - - def makeBlack(n: Tree): Tree = { - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } - - def add(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) ) - val t1 = ins(x, t) - makeBlack(t1) - - } ensuring(res => tmpl((a,b) => stack <= a*blackHeight(t) + b)) - - def balance(co: Color, l: Tree, x: BigInt, r: Tree): Tree = { - Node(co,l,x,r) - match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case _ => Node(co,l,x,r) - } - } -} diff --git a/testcases/orb-testcases/stack/SpeedBenchmarks.scala b/testcases/orb-testcases/stack/SpeedBenchmarks.scala deleted file mode 100644 index c1c59d592b2b0b59cfe79b780aaca479fcbb222d..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/stack/SpeedBenchmarks.scala +++ /dev/null @@ -1,75 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -import leon.math._ - -object SpeedBenchmarks { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - sealed abstract class StringBuffer - case class Chunk(str: List, next: StringBuffer) extends StringBuffer - case class Empty() extends StringBuffer - - def length(sb: StringBuffer) : BigInt = sb match { - case Chunk(_, next) => 1 + length(next) - case _ => 0 - } - - def sizeBound(sb: StringBuffer, k: BigInt) : Boolean ={ - sb match { - case Chunk(str, next) => size(str) <= k && sizeBound(next, k) - case _ => 0 <= k - } - } - - def sizeBuffer(sb: StringBuffer): BigInt = { - sb match { - case Chunk(str, next) => size(str) + sizeBuffer(sb) - case Empty() => 0 - } - } - - /** - * Fig. 1 of SPEED, POPL'09: The functional version of the implementation. - * Equality check of two string buffers - */ - def Equals(str1: List, str2: List, s1: StringBuffer, s2: StringBuffer, k: BigInt) : Boolean = { - require(sizeBound(s1, k) && sizeBound(s2, k) && size(str1) <= k && size(str2) <= k && k >= 0) - - (str1, str2) match { - case (Cons(h1,t1), Cons(h2,t2)) => { - if(h1 != h2) false - else Equals(t1,t2, s1,s2, k) - } - case (Cons(_,_), Nil()) => { - //load from s2 - s2 match { - case Chunk(str, next) => Equals(str1, str, s1, next, k) - case Empty() => false - } - } - case (Nil(), Cons(_,_)) => { - //load from s1 - s1 match { - case Chunk(str, next) => Equals(str, str2, next, s2, k) - case Empty() => false - } - } - case _ =>{ - //load from both - (s1,s2) match { - case (Chunk(nstr1, next1),Chunk(nstr2, next2)) => Equals(nstr1, nstr2, next1, next2, k) - case (Empty(),Chunk(nstr2, next2)) => Equals(str1, nstr2, s1, next2, k) - case (Chunk(nstr1, next1), Empty()) => Equals(nstr1, str2, next1, s2, k) - case _ => true - } - } - } - } ensuring(res => tmpl((a,b,c,d,e) => stack <= a*max(sizeBuffer(s1), sizeBuffer(s2)) + c*(k+1) + e)) -} diff --git a/testcases/orb-testcases/stack/TreeOperations.scala b/testcases/orb-testcases/stack/TreeOperations.scala deleted file mode 100644 index 123031d7d0cb523f164f69aabb5b8f0d4aef4ca9..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/stack/TreeOperations.scala +++ /dev/null @@ -1,93 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - - -object TreeOperations { - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def listSize(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + listSize(t) - }) - - def size(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - size(l) + size(r) + 1 - } - } - } - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def insert(elem: BigInt, t: Tree): Tree = { - t match { - case Leaf() => Node(Leaf(), elem, Leaf()) - case Node(l, x, r) => if (x <= elem) Node(l, x, insert(elem, r)) - else Node(insert(elem, l), x, r) - } - } ensuring (res => height(res) <= height(t) + 1 && tmpl((a,b) => stack <= a*height(t) + b)) - - def addAll(l: List, t: Tree): Tree = { - l match { - case Nil() => t - case Cons(x, xs) =>{ - val newt = insert(x, t) - addAll(xs, newt) - } - } - } ensuring(res => tmpl((a,b,c) => stack <= a*(listSize(l) * (height(t) + listSize(l))) + b*listSize(l) + c)) - - def remove(elem: BigInt, t: Tree): Tree = { - t match { - case Leaf() => Leaf() - case Node(l, x, r) => { - - if (x < elem) Node(l, x, remove(elem, r)) - else if (x > elem) Node(remove(elem, l), x, r) - else { - t match { - case Node(Leaf(), x, Leaf()) => Leaf() - case Node(Leaf(), x, Node(_, rx, _)) => Node(Leaf(), rx, remove(rx, r)) - case Node(Node(_, lx, _), x, r) => Node(remove(lx, l), lx, r) - case _ => Leaf() - } - } - } - } - } ensuring (res => height(res) <= height(t) && tmpl ((a, b, c) => stack <= a*height(t) + b)) - - def removeAll(l: List, t: Tree): Tree = { - l match { - case Nil() => t - case Cons(x, xs) => removeAll(xs, remove(x, t)) - } - } ensuring(res => tmpl((a,b,c) => stack <= a*(listSize(l) * height(t)) + b*listSize(l) + c)) - - def contains(elem : BigInt, t : Tree) : Boolean = { - t match { - case Leaf() => false - case Node(l, x, r) => - if(x == elem) true - else if (x < elem) contains(elem, r) - else contains(elem, l) - } - } ensuring (res => tmpl((a,b) => stack <= a*height(t) + b)) -} \ No newline at end of file diff --git a/testcases/orb-testcases/timing/AVLTree.scala b/testcases/orb-testcases/timing/AVLTree.scala deleted file mode 100644 index 2dad4712c0933969d49963ef9ecc94af093d632d..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/AVLTree.scala +++ /dev/null @@ -1,172 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -import leon.math._ -import leon.annotation._ - -object AVLTree { - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(left: Tree, value: BigInt, right: Tree, rank: BigInt) extends Tree - - sealed abstract class OptionInt - case class None() extends OptionInt - case class Some(i: BigInt) extends OptionInt - - /*def expGoldenRatio(x: BigInt) : BigInt = { - //require(x >= 0) - if(x < 1) 1 - else - 3/2 * twopower(x - 1) - } ensuring(res => res >= 1 template((a) => a <= 0))*/ - - def rank(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(_, _, _, rk) => rk - } - } - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r, _) => { - val hl = height(l) - val hr = height(r) - max(hl, hr) + 1 - } - } - } - - def size(t: Tree): BigInt = { - //require(isAVL(t)) - (t match { - case Leaf() => 0 - case Node(l, _, r, _) => size(l) + 1 + size(r) - }) - - } - //ensuring (_ => height(t) <= ? * res + ?) - - def rankHeight(t: Tree): Boolean = t match { - case Leaf() => true - case Node(l, _, r, rk) => rankHeight(l) && rankHeight(r) && rk == height(t) - } - - def balanceFactor(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, _, r, _) => rank(l) - rank(r) - } - } - - /*def isAVL(t:Tree) : Boolean = { - t match { - case Leaf() => true - case Node(l,_,r,rk) => isAVL(l) && isAVL(r) && balanceFactor(t) >= -1 && balanceFactor(t) <= 1 && rankHeight(t) //isBST(t) && - } - }*/ - - def unbalancedInsert(t: Tree, e: BigInt): Tree = { - t match { - case Leaf() => Node(Leaf(), e, Leaf(), 1) - case Node(l, v, r, h) => - if (e == v) t - else if (e < v) { - val newl = avlInsert(l, e) - Node(newl, v, r, max(rank(newl), rank(r)) + 1) - } else { - val newr = avlInsert(r, e) - Node(l, v, newr, max(rank(l), rank(newr)) + 1) - } - } - } - - def avlInsert(t: Tree, e: BigInt): Tree = { - balance(unbalancedInsert(t, e)) - } ensuring (_ => time <= ? * height(t) + ?) - - def deletemax(t: Tree): (Tree, OptionInt) = { - t match { - case Node(Leaf(), v, Leaf(), _) => (Leaf(), Some(v)) - case Node(l, v, Leaf(), _) => { - deletemax(l) match { - case (_, None()) => (t, None()) - case (newl, Some(lmax)) => - (balance(Node(newl, lmax, Leaf(), rank(newl) + 1)), Some(v)) - } - } - case Node(_, _, r, _) => deletemax(r) - case _ => (t, None()) - } - } ensuring (res => time <= ? * height(t) + ?) - - def unbalancedDelete(t: Tree, e: BigInt): Tree = { - t match { - case Leaf() => Leaf() //not found case - case Node(l, v, r, h) => - if (e == v) { - if (l == Leaf()) r - else if (r == Leaf()) l - else { - deletemax(l) match { - case (_, None()) => t - case (newl, Some(newe)) => - Node(newl, newe, r, max(rank(newl), rank(r)) + 1) - } - } - } else if (e < v) { - val newl = avlDelete(l, e) - Node(newl, v, r, max(rank(newl), rank(r)) + 1) - } else { - val newr = avlDelete(r, e) - Node(l, v, newr, max(rank(l), rank(newr)) + 1) - } - } - } - - def avlDelete(t: Tree, e: BigInt): Tree = { - balance(unbalancedDelete(t, e)) - } ensuring (res => tmpl((a, b) => time <= a * height(t) + b)) - - @invisibleBody - def balance(t: Tree): Tree = { - t match { - case Leaf() => Leaf() // impossible... - case Node(l, v, r, h) => - val bfactor = balanceFactor(t) - // at this point, the tree is unbalanced - if (bfactor > 1) { // left-heavy - val newL = - if (balanceFactor(l) < 0) { // l is right heavy - rotateLeft(l) - } else l - rotateRight(Node(newL, v, r, max(rank(newL), rank(r)) + 1)) - } else if (bfactor < -1) { - val newR = - if (balanceFactor(r) > 0) { // r is left heavy - rotateRight(r) - } else r - rotateLeft(Node(l, v, newR, max(rank(newR), rank(l)) + 1)) - } else t - } - } ensuring (_ => time <= ?) - - def rotateRight(t: Tree) = { - t match { - case Node(Node(ll, vl, rl, _), v, r, _) => - val hr = max(rank(rl), rank(r)) + 1 - Node(ll, vl, Node(rl, v, r, hr), max(rank(ll), hr) + 1) - case _ => t // this should not happen - } - } - - def rotateLeft(t: Tree) = { - t match { - case Node(l, v, Node(lr, vr, rr, _), _) => - val hl = max(rank(l), rank(lr)) + 1 - Node(Node(l, v, lr, hl), vr, rr, max(hl, rank(rr)) + 1) - case _ => t // this should not happen - } - } -} - diff --git a/testcases/orb-testcases/timing/AmortizedQueue.scala b/testcases/orb-testcases/timing/AmortizedQueue.scala deleted file mode 100644 index 8aece6a669c4fe6dd51d764efb40529731666a66..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/AmortizedQueue.scala +++ /dev/null @@ -1,83 +0,0 @@ -package orb - -import leon._ -import invariant._ -import instrumentation._ - -object AmortizedQueue { - sealed abstract class List { - val size: BigInt = this match { - case Nil() => 0 - case Cons(_, xs) => 1 + xs.size - } - } - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def concat(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => Cons(x, concat(xs, l2)) - - }) ensuring (res => res.size == l1.size + l2.size && time <= ? * l1.size + ?) - - def reverseRec(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverseRec(xs, Cons(x, l2)) - }) ensuring (res => l1.size + l2.size == res.size && time <= ? * l1.size + ?) - - def listRev(l: List): List = { - reverseRec(l, Nil()) - } ensuring (res => l.size == res.size && time <= ? * l.size + ?) - - def removeLast(l: List): List = { - require(l != Nil()) - l match { - case Cons(x, Nil()) => Nil() - case Cons(x, xs) => Cons(x, removeLast(xs)) - case _ => Nil() - } - } ensuring (res => res.size <= l.size && tmpl((a, b) => time <= a * l.size + b)) - - case class Queue(front: List, rear: List) { - def qsize: BigInt = front.size + rear.size - - def asList: List = concat(front, listRev(rear)) - - def isAmortized: Boolean = front.size >= rear.size - - def isEmpty: Boolean = this match { - case Queue(Nil(), Nil()) => true - case _ => false - } - - def amortizedQueue(front: List, rear: List): Queue = { - if (rear.size <= front.size) - Queue(front, rear) - else - Queue(concat(front, listRev(rear)), Nil()) - } - - def enqueue(elem: BigInt): Queue = ({ - amortizedQueue(front, Cons(elem, rear)) - }) ensuring (_ => time <= ? * qsize + ?) - - def dequeue: Queue = { - require(isAmortized && !isEmpty) - front match { - case Cons(f, fs) => amortizedQueue(fs, rear) - case _ => Queue(Nil(), Nil()) - } - } ensuring (_ => time <= ? * qsize + ?) - - def head: BigInt = { - require(isAmortized && !isEmpty) - front match { - case Cons(f, _) => f - } - } - - def reverse: Queue = { // this lets the queue perform deque operation (but they no longer have efficient constant time amortized bounds) - amortizedQueue(rear, front) - } - } -} diff --git a/testcases/orb-testcases/timing/BinaryTrie.scala b/testcases/orb-testcases/timing/BinaryTrie.scala deleted file mode 100644 index a1de6ee0e13bb53383b1bba6548e9e0fa449a166..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/BinaryTrie.scala +++ /dev/null @@ -1,119 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object BinaryTrie { - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(nvalue: BigInt, left: Tree, right: Tree) extends Tree - - sealed abstract class IList - case class Cons(head: BigInt, tail: IList) extends IList - case class Nil() extends IList - - def listSize(l: IList): BigInt = (l match { - case Nil() => 0 - case Cons(x, xs) => 1 + listSize(xs) - }) - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(x, l, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def find(inp: IList, t: Tree): Tree = { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x, xs @ Cons(y, _)) => { - t match { - case Leaf() => t - case Node(v, l, r) => { - if (y > 0) find(xs, l) else find(xs, r) - } - } - } - case _ => t - } - } ensuring (_ => time <= ? * listSize(inp) + ?) - - def insert(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => t - case Cons(x, xs) => { - val newch = insert(xs, Leaf()) - newch match { - case Leaf() => Node(x, Leaf(), Leaf()) - case Node(y, _, _) => if (y > 0) Node(x, newch, Leaf()) else Node(y, Leaf(), newch) - } - } - } - - } - case Node(v, l, r) => { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x, xs @ Cons(y, _)) => { - val ch = if (y > 0) l else r - if (y > 0) - Node(v, insert(xs, ch), r) - else - Node(v, l, insert(xs, ch)) - } - case _ => t - } - } - } - } ensuring (_ => time <= ? * listSize(inp) + ?) - - def create(inp: IList): Tree = { - insert(inp, Leaf()) - } ensuring (res => true && tmpl((a, c) => time <= a * listSize(inp) + c)) - - def delete(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => Leaf() - case Cons(x ,xs) => { - //the input is not in the tree, so do nothing - Leaf() - } - } - } - case Node(v, l, r) => { - inp match { - case Nil() => { - //the tree has extensions of the input list so do nothing - t - } - case Cons(x, Nil()) => { - //if "l" and "r" are nil, remove the node - if(l == Leaf() && r == Leaf()) Leaf() - else t - } - case Cons(x ,xs@Cons(y, _)) => { - val ch = if(y > 0) l else r - val newch = delete(xs, ch) - if(newch == Leaf() && ((y > 0 && r == Leaf()) || (y <= 0 && l == Leaf()))) Leaf() - else { - if(y > 0) - Node(v, newch, r) - else - Node(v, l, newch) - } - } - case _ => t - } - } - } - } ensuring (_ => time <= ? * listSize(inp) + ?) -} diff --git a/testcases/orb-testcases/timing/BinomialHeap.scala b/testcases/orb-testcases/timing/BinomialHeap.scala deleted file mode 100644 index 81b990d41323f353098f5cd02feddf3e25ec9264..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/BinomialHeap.scala +++ /dev/null @@ -1,181 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object BinomialHeap { - //sealed abstract class TreeNode - case class TreeNode(rank: BigInt, elem: Element, children: BinomialHeap) - case class Element(n: BigInt) - - sealed abstract class BinomialHeap - case class ConsHeap(head: TreeNode, tail: BinomialHeap) extends BinomialHeap - case class NilHeap() extends BinomialHeap - - sealed abstract class List - case class NodeL(head: BinomialHeap, tail: List) extends List - case class NilL() extends List - - sealed abstract class OptionalTree - case class Some(t : TreeNode) extends OptionalTree - case class None() extends OptionalTree - - /* Lower or Equal than for Element structure */ - private def leq(a: Element, b: Element) : Boolean = { - a match { - case Element(a1) => { - b match { - case Element(a2) => { - if(a1 <= a2) true - else false - } - } - } - } - } - - /* isEmpty function of the Binomial Heap */ - def isEmpty(t: BinomialHeap) = t match { - case ConsHeap(_,_) => false - case _ => true - } - - /* Helper function to determine rank of a TreeNode */ - def rank(t: TreeNode) : BigInt = t.rank /*t match { - case TreeNode(r, _, _) => r - }*/ - - /* Helper function to get the root element of a TreeNode */ - def root(t: TreeNode) : Element = t.elem /*t match { - case TreeNode(_, e, _) => e - }*/ - - /* Linking trees of equal ranks depending on the root element */ - def link(t1: TreeNode, t2: TreeNode): TreeNode = { - if (leq(t1.elem, t2.elem)) { - TreeNode(t1.rank + 1, t1.elem, ConsHeap(t2, t1.children)) - } else { - TreeNode(t1.rank + 1, t2.elem, ConsHeap(t1, t2.children)) - } - } - - def treeNum(h: BinomialHeap) : BigInt = { - h match { - case ConsHeap(head, tail) => 1 + treeNum(tail) - case _ => 0 - } - } - - /* Insert a tree into a binomial heap. The tree should be correct in relation to the heap */ - def insTree(t: TreeNode, h: BinomialHeap) : BinomialHeap = { - h match { - case ConsHeap(head, tail) => { - if (rank(t) < rank(head)) { - ConsHeap(t, h) - } else if (rank(t) > rank(head)) { - ConsHeap(head, insTree(t,tail)) - } else { - insTree(link(t,head), tail) - } - } - case _ => ConsHeap(t, NilHeap()) - } - } ensuring(_ => time <= ? * treeNum(h) + ?) - - /* Merge two heaps together */ - def merge(h1: BinomialHeap, h2: BinomialHeap): BinomialHeap = { - h1 match { - case ConsHeap(head1, tail1) => { - h2 match { - case ConsHeap(head2, tail2) => { - if (rank(head1) < rank(head2)) { - ConsHeap(head1, merge(tail1, h2)) - } else if (rank(head2) < rank(head1)) { - ConsHeap(head2, merge(h1, tail2)) - } else { - mergeWithCarry(link(head1, head2), tail1, tail2) - } - } - case _ => h1 - } - } - case _ => h2 - } - } ensuring(_ => time <= ? * treeNum(h1) + ? * treeNum(h2) + ?) - - def mergeWithCarry(t: TreeNode, h1: BinomialHeap, h2: BinomialHeap): BinomialHeap = { - h1 match { - case ConsHeap(head1, tail1) => { - h2 match { - case ConsHeap(head2, tail2) => { - if (rank(head1) < rank(head2)) { - - if (rank(t) < rank(head1)) - ConsHeap(t, ConsHeap(head1, merge(tail1, h2))) - else - mergeWithCarry(link(t, head1), tail1, h2) - - } else if (rank(head2) < rank(head1)) { - - if (rank(t) < rank(head2)) - ConsHeap(t, ConsHeap(head2, merge(h1, tail2))) - else - mergeWithCarry(link(t, head2), h1, tail2) - - } else { - ConsHeap(t, mergeWithCarry(link(head1, head2), tail1, tail2)) - } - } - case _ => { - insTree(t, h1) - } - } - } - case _ => insTree(t, h2) - } - } ensuring (_ => time <= ? * treeNum(h1) + ? * treeNum(h2) + ?) - - //Auxiliary helper function to simplefy findMin and deleteMin - def removeMinTree(h: BinomialHeap): (OptionalTree, BinomialHeap) = { - h match { - case ConsHeap(head, NilHeap()) => (Some(head), NilHeap()) - case ConsHeap(head1, tail1) => { - val (opthead2, tail2) = removeMinTree(tail1) - opthead2 match { - case Some(head2) => - if (leq(root(head1), root(head2))) { - (Some(head1), tail1) - } else { - (Some(head2), ConsHeap(head1, tail2)) - } - case _ => (Some(head1), tail1) - } - } - case _ => (None(), NilHeap()) - } - } ensuring (res => treeNum(res._2) <= treeNum(h) && time <= ? * treeNum(h) + ?) - - /*def findMin(h: BinomialHeap) : Element = { - val (opt, _) = removeMinTree(h) - opt match { - case Some(TreeNode(_,e,ts1)) => e - case _ => Element(-1) - } - } ensuring(res => true && tmpl((a,b) => time <= a*treeNum(h) + b))*/ - - def minTreeChildren(h: BinomialHeap) : BigInt = { - val (min, _) = removeMinTree(h) - min match { - case Some(TreeNode(_,_,ch)) => treeNum(ch) - case _ => 0 - } - } - - // Discard the minimum element of the extracted min tree and put its children back into the heap - def deleteMin(h: BinomialHeap) : BinomialHeap = { - val (min, ts2) = removeMinTree(h) - min match { - case Some(TreeNode(_,_,ts1)) => merge(ts1, ts2) - case _ => h - } - } ensuring(_ => time <= ? * minTreeChildren(h) + ? * treeNum(h) + ?) - -} diff --git a/testcases/orb-testcases/timing/ConcTrees.scala b/testcases/orb-testcases/timing/ConcTrees.scala deleted file mode 100644 index 9145789294ea99cce0323261b6505d67e7492648..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/ConcTrees.scala +++ /dev/null @@ -1,536 +0,0 @@ -package conctrees - -import leon.instrumentation._ -import leon.collection._ -import leon.lang._ -import ListSpecs._ -import leon.annotation._ -import leon.invariant._ - -object ConcTrees { - - def max(x: BigInt, y: BigInt): BigInt = if (x >= y) x else y - def abs(x: BigInt): BigInt = if (x < 0) -x else x - - sealed abstract class Conc[T] { - - def isEmpty: Boolean = { - this == Empty[T]() - } - - def isLeaf: Boolean = { - this match { - case Empty() => true - case Single(_) => true - case _ => false - } - } - - def isNormalized: Boolean = this match { - case Append(_, _) => false - case _ => true - } - - def valid: Boolean = { - concInv && balanced && appendInv - } - - /** - * (a) left and right trees of conc node should be non-empty - * (b) they cannot be append nodes - */ - def concInv: Boolean = this match { - case CC(l, r) => - !l.isEmpty && !r.isEmpty && - l.isNormalized && r.isNormalized && - l.concInv && r.concInv - case _ => true - } - - def balanced: Boolean = { - this match { - case CC(l, r) => - l.level - r.level >= -1 && l.level - r.level <= 1 && - l.balanced && r.balanced - case _ => true - } - } - - /** - * (a) Right subtree of an append node is not an append node - * (b) If the tree is of the form a@Append(b@Append(_,_),_) then - * a.right.level < b.right.level - * (c) left and right are not empty - */ - def appendInv: Boolean = this match { - case Append(l, r) => - !l.isEmpty && !r.isEmpty && - l.valid && r.valid && - r.isNormalized && - (l match { - case Append(_, lr) => - lr.level > r.level - case _ => - l.level > r.level - }) - case _ => true - } - - val level: BigInt = { - (this match { - case Empty() => 0 - case Single(x) => 0 - case CC(l, r) => - 1 + max(l.level, r.level) - case Append(l, r) => - 1 + max(l.level, r.level) - }): BigInt - } ensuring (_ >= 0) - - val size: BigInt = { - (this match { - case Empty() => 0 - case Single(x) => 1 - case CC(l, r) => - l.size + r.size - case Append(l, r) => - l.size + r.size - }): BigInt - } ensuring (_ >= 0) - - def toList: List[T] = { - this match { - case Empty() => Nil[T]() - case Single(x) => Cons(x, Nil[T]()) - case CC(l, r) => - l.toList ++ r.toList // note: left elements precede the right elements in the list - case Append(l, r) => - l.toList ++ r.toList - } - } ensuring (res => res.size == this.size) - } - - case class Empty[T]() extends Conc[T] - case class Single[T](x: T) extends Conc[T] - case class CC[T](left: Conc[T], right: Conc[T]) extends Conc[T] - case class Append[T](left: Conc[T], right: Conc[T]) extends Conc[T] - - /*class Chunk(val array: Array[T], val size: Int, val k: Int) extends Leaf[T] { - def level = 0 - override def toString = s"Chunk(${array.mkString("", ", ", "")}; $size; $k)" - }*/ - - def lookup[T](xs: Conc[T], i: BigInt): T = { - require(xs.valid && !xs.isEmpty && i >= 0 && i < xs.size) - xs match { - case Single(x) => x - case CC(l, r) => - if (i < l.size) { - lookup(l, i) - } else { - lookup(r, i - l.size) - } - case Append(l, r) => - if (i < l.size) { - lookup(l, i) - } else { - lookup(r, i - l.size) - } - } - } ensuring (res => tmpl((a,b) => time <= a*xs.level + b) && // lookup time is linear in the height - res == xs.toList(i) && // correctness - instAppendIndexAxiom(xs, i)) // an auxiliary axiom instantiation that is required for the proof - - // @library - def instAppendIndexAxiom[T](xs: Conc[T], i: BigInt): Boolean = { - require(0 <= i && i < xs.size) - xs match { - case CC(l, r) => - appendIndex(l.toList, r.toList, i) - case Append(l, r) => - appendIndex(l.toList, r.toList, i) - case _ => true - } - }.holds - - @library - def update[T](xs: Conc[T], i: BigInt, y: T): Conc[T] = { - require(xs.valid && !xs.isEmpty && i >= 0 && i < xs.size) - xs match { - case Single(x) => Single(y) - case CC(l, r) => - if (i < l.size) - CC(update(l, i, y), r) - else - CC(l, update(r, i - l.size, y)) - case Append(l, r) => - if (i < l.size) - Append(update(l, i, y), r) - else - Append(l, update(r, i - l.size, y)) - } - } ensuring (res => res.level == xs.level && // heights of the input and output trees are equal - res.valid && // tree invariants are preserved - tmpl((a,b) => time <= a*xs.level + b) && // update time is linear in the height of the tree - res.toList == xs.toList.updated(i, y) && // correctness - numTrees(res) == numTrees(xs) && //auxiliary property that preserves the potential function - instAppendUpdateAxiom(xs, i, y)) // an auxiliary axiom instantiation - - @library - def instAppendUpdateAxiom[T](xs: Conc[T], i: BigInt, y: T): Boolean = { - require(i >= 0 && i < xs.size) - xs match { - case CC(l, r) => - appendUpdate(l.toList, r.toList, i, y) - case Append(l, r) => - appendUpdate(l.toList, r.toList, i, y) - case _ => true - } - }.holds - - /** - * A generic concat that applies to general concTrees - */ - @library - def concat[T](xs: Conc[T], ys: Conc[T]): Conc[T] = { - require(xs.valid && ys.valid) - concatNormalized(normalize(xs), normalize(ys)) - } - - /** - * This concat applies only to normalized trees. - * This prevents concat from being recursive - */ - @library - def concatNormalized[T](xs: Conc[T], ys: Conc[T]): Conc[T] = { - require(xs.valid && ys.valid && - xs.isNormalized && ys.isNormalized) - (xs, ys) match { - case (xs, Empty()) => xs - case (Empty(), ys) => ys - case _ => - concatNonEmpty(xs, ys) - } - } ensuring (res => res.valid && // tree invariants - res.level <= max(xs.level, ys.level) + 1 && // height invariants - res.level >= max(xs.level, ys.level) && - (res.toList == xs.toList ++ ys.toList) && // correctness - res.isNormalized //auxiliary properties - ) - - //@library - def concatNonEmpty[T](xs: Conc[T], ys: Conc[T]): Conc[T] = { - require(xs.valid && ys.valid && - xs.isNormalized && ys.isNormalized && - !xs.isEmpty && !ys.isEmpty) - - val diff = ys.level - xs.level - if (diff >= -1 && diff <= 1) - CC(xs, ys) - else if (diff < -1) { - // ys is smaller than xs - xs match { - case CC(l, r) => - if (l.level >= r.level) - CC(l, concatNonEmpty(r, ys)) - else { - r match { - case CC(rl, rr) => - val nrr = concatNonEmpty(rr, ys) - if (nrr.level == xs.level - 3) - CC(l, CC(rl, nrr)) - else - CC(CC(l, rl), nrr) - } - } - } - } else { - ys match { - case CC(l, r) => - if (r.level >= l.level) - CC(concatNonEmpty(xs, l), r) - else { - l match { - case CC(ll, lr) => - val nll = concatNonEmpty(xs, ll) - if (nll.level == ys.level - 3) - CC(CC(nll, lr), r) - else - CC(nll, CC(lr, r)) - } - } - } - } - } ensuring (res => tmpl((a,b) => time <= a*abs(xs.level - ys.level) + b) && // time bound - res.level <= max(xs.level, ys.level) + 1 && // height invariants - res.level >= max(xs.level, ys.level) && - res.balanced && res.appendInv && res.concInv && //this is should not be needed. But, seems necessary for leon - res.valid && // tree invariant is preserved - res.toList == xs.toList ++ ys.toList && // correctness - res.isNormalized && // auxiliary properties - appendAssocInst(xs, ys) // instantiation of an axiom - ) - - @library - def appendAssocInst[T](xs: Conc[T], ys: Conc[T]): Boolean = { - (xs match { - case CC(l, r) => - appendAssoc(l.toList, r.toList, ys.toList) && //instantiation of associativity of concatenation - (r match { - case CC(rl, rr) => - appendAssoc(rl.toList, rr.toList, ys.toList) && - appendAssoc(l.toList, rl.toList, rr.toList ++ ys.toList) - case _ => true - }) - case _ => true - }) && - (ys match { - case CC(l, r) => - appendAssoc(xs.toList, l.toList, r.toList) && - (l match { - case CC(ll, lr) => - appendAssoc(xs.toList, ll.toList, lr.toList) && - appendAssoc(xs.toList ++ ll.toList, lr.toList, r.toList) - case _ => true - }) - case _ => true - }) - }.holds - - @library - def insert[T](xs: Conc[T], i: BigInt, y: T): Conc[T] = { - require(xs.valid && i >= 0 && i <= xs.size && - xs.isNormalized) //note the precondition - xs match { - case Empty() => Single(y) - case Single(x) => - if (i == 0) - CC(Single(y), xs) - else - CC(xs, Single(y)) - case CC(l, r) if i < l.size => - concatNonEmpty(insert(l, i, y), r) - case CC(l, r) => - concatNonEmpty(l, insert(r, i - l.size, y)) - } - } ensuring (res => res.valid && res.isNormalized && // tree invariants - res.level - xs.level <= 1 && res.level >= xs.level && // height of the output tree is at most 1 greater than that of the input tree - tmpl((a,b) => time <= a*xs.level + b) && // time is linear in the height of the tree - res.toList == xs.toList.insertAt(i, y) && // correctness - insertAppendAxiomInst(xs, i, y) // instantiation of an axiom - ) - - @library - def insertAppendAxiomInst[T](xs: Conc[T], i: BigInt, y: T): Boolean = { - require(i >= 0 && i <= xs.size) - xs match { - case CC(l, r) => appendInsert(l.toList, r.toList, i, y) - case _ => true - } - }.holds - - //TODO: why with instrumentation we are not able prove the running time here ? (performance bug ?) - @library - def split[T](xs: Conc[T], n: BigInt): (Conc[T], Conc[T]) = { - require(xs.valid && xs.isNormalized) - xs match { - case Empty() => - (Empty(), Empty()) - case s @ Single(x) => - if (n <= 0) { //a minor fix - (Empty(), s) - } else { - (s, Empty()) - } - case CC(l, r) => - if (n < l.size) { - val (ll, lr) = split(l, n) - (ll, concatNormalized(lr, r)) - } else if (n > l.size) { - val (rl, rr) = split(r, n - l.size) - (concatNormalized(l, rl), rr) - } else { - (l, r) - } - } - } ensuring (res => res._1.valid && res._2.valid && // tree invariants are preserved - res._1.isNormalized && res._2.isNormalized && - xs.level >= res._1.level && xs.level >= res._2.level && // height bounds of the resulting tree - tmpl((a,b,c,d) => time <= a*xs.level + b*res._1.level + c*res._2.level + d) && // time is linear in height - res._1.toList == xs.toList.take(n) && res._2.toList == xs.toList.drop(n) && // correctness - instSplitAxiom(xs, n) // instantiation of an axiom - ) - - @library - def instSplitAxiom[T](xs: Conc[T], n: BigInt): Boolean = { - xs match { - case CC(l, r) => - appendTakeDrop(l.toList, r.toList, n) - case _ => true - } - }.holds - - @library - def append[T](xs: Conc[T], x: T): Conc[T] = { - require(xs.valid) - val ys = Single[T](x) - xs match { - case xs @ Append(_, _) => - appendPriv(xs, ys) - case CC(_, _) => - Append(xs, ys) //creating an append node - case Empty() => - ys - case Single(_) => - CC(xs, ys) - } - } ensuring (res => res.valid && //conctree invariants - res.toList == xs.toList ++ Cons(x, Nil[T]()) && //correctness - res.level <= xs.level + 1 && - tmpl((a,b,c) => time <= a*numTrees(xs) - b*numTrees(res) + c) //time bound (worst case) - ) - - /** - * This is a private method and is not exposed to the - * clients of conc trees - */ - @library - def appendPriv[T](xs: Append[T], ys: Conc[T]): Conc[T] = { - require(xs.valid && ys.valid && - !ys.isEmpty && ys.isNormalized && - xs.right.level >= ys.level) - - if (xs.right.level > ys.level) - Append(xs, ys) - else { - val zs = CC(xs.right, ys) - xs.left match { - case l @ Append(_, _) => - appendPriv(l, zs) - case l if l.level <= zs.level => //note: here < is not possible - CC(l, zs) - case l => - Append(l, zs) - } - } - } ensuring (res => res.valid && //conc tree invariants - res.toList == xs.toList ++ ys.toList && //correctness invariants - res.level <= xs.level + 1 && - tmpl((a,b,c) => time <= a*numTrees(xs) - b*numTrees(res) + c) && //time bound (worst case) - appendAssocInst2(xs, ys)) - - @library - def appendAssocInst2[T](xs: Conc[T], ys: Conc[T]): Boolean = { - xs match { - case CC(l, r) => - appendAssoc(l.toList, r.toList, ys.toList) - case Append(l, r) => - appendAssoc(l.toList, r.toList, ys.toList) - case _ => true - } - }.holds - - @library - def numTrees[T](t: Conc[T]): BigInt = { - t match { - case Append(l, r) => numTrees(l) + 1 - case _ => BigInt(1) - } - } ensuring (res => res >= 0) - - @library - def normalize[T](t: Conc[T]): Conc[T] = { - require(t.valid) - t match { - case Append(l @ Append(_, _), r) => - wrap(l, r) - case Append(l, r) => - concatNormalized(l, r) - case _ => t - } - } ensuring (res => res.valid && - res.isNormalized && - res.toList == t.toList && //correctness - res.size == t.size && res.level <= t.level && //normalize preserves level and size - tmpl((a,b) => time <= a*t.level + b) //time bound (a little over approximate) - ) - - @library - def wrap[T](xs: Append[T], ys: Conc[T]): Conc[T] = { - require(xs.valid && ys.valid && ys.isNormalized && - xs.right.level >= ys.level) - val nr = concatNormalized(xs.right, ys) - xs.left match { - case l @ Append(_, _) => - wrap(l, nr) - case l => - concatNormalized(l, nr) - } - } ensuring (res => res.valid && - res.isNormalized && - res.toList == xs.toList ++ ys.toList && //correctness - res.size == xs.size + ys.size && //other auxiliary properties - res.level <= xs.level && - tmpl((a,b,c) => time <= a*xs.level - b*ys.level + c) && //time bound - appendAssocInst2(xs, ys)) //some lemma instantiations - - /** - * A class that represents an operation on a concTree. - * opid - an integer that denotes the function that has to be performed e.g. append, insert, update ... - * opid <= 0 => the operation is lookup - * opid == 1 => the operation is update - * opid == 2 => the operation is insert - * opid == 3 => the operation is split - * opid >= 4 => the operation is append - * index, x - denote the arguments the function given by opid - */ - case class Operation[T](opid: BigInt, /*argument to the operations*/ index: BigInt /*for lookup, update, insert, split*/ , - x: T /*for update, insert, append*/ ) - - /** - * Proving amortized running time of 'Append' when used ephimerally. - * ops- a arbitrary sequence of operations, - * noaps - number of append operations in the list - */ - def performOperations[T](xs: Conc[T], ops: List[Operation[T]], noaps: BigInt): Conc[T] = { - require(xs.valid && noaps >= 0) - ops match { - case Cons(Operation(id, i, _), tail) if id <= 0 => - //we need to perform a lookup operation, but do the operation only if - //preconditions hold - // val _ = if (0 <= i && i < xs.size) - // lookup(xs, i) - // else BigInt(0) - performOperations(xs, tail, noaps) //returns the time taken by appends in the remaining operations - - case Cons(Operation(id, i, x), tail) if id == 1 => - val newt = if (0 <= i && i < xs.size) - update(xs, i, x) - else xs - //note that only the return value is used by the subsequent operations (emphimeral use) - performOperations(newt, tail, noaps) - - case Cons(Operation(id, i, x), tail) if id == 2 => - val newt = if (0 <= i && i <= xs.size) - insert(normalize(xs), i, x) - else xs - performOperations(newt, tail, noaps) - - case Cons(Operation(id, n, _), tail) if id == 3 => - //use the larger tree to perform the remaining operations - val (newl, newr) = split(normalize(xs), n) - val newt = if (newl.size >= newr.size) newl else newr - performOperations(newt, tail, noaps) - - case Cons(Operation(id, _, x), tail) if noaps > 0 => - //here, we need to perform append operation - val newt = append(xs, x) - val r = performOperations(newt, tail, noaps - 1) - r //time taken by this append and those that follow it - - case _ => - xs - } - } ensuring (res => tmpl((a, b) => time <= a*noaps + b*numTrees(xs))) -//res._2 <= noaps + 2*nops*(xs.level + res._1.level)+ numTrees(xs) -} diff --git a/testcases/orb-testcases/timing/ConcatVariations.scala b/testcases/orb-testcases/timing/ConcatVariations.scala deleted file mode 100644 index a94fb418a48db5b27ab88cfbbe84a59233f394b0..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/ConcatVariations.scala +++ /dev/null @@ -1,42 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - - -object ConcatVariations { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def genL(n: BigInt): List = { - require(n >= 0) - if (n == 0) Nil() - else - Cons(n, genL(n - 1)) - } ensuring (res => size(res) == n && tmpl((a,b) => time <= a*n + b)) - - def append(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => Cons(x, append(xs, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && tmpl((a,b) => time <= a*size(l1) + b)) - - def f_good(m: BigInt, n: BigInt): List = { - require(0 <= m && 0 <= n) - if (m == 0) Nil() - else append(genL(n), f_good(m - 1, n)) - - } ensuring(res => size(res) == n*m && tmpl((a,b,c,d) => time <= a*(n*m) + b*n + c*m +d)) - - def f_worst(m: BigInt, n: BigInt): List = { - require(0 <= m && 0 <= n) - - if (m == 0) Nil() - else append(f_worst(m - 1, n), genL(n)) - - } ensuring(res => size(res) == n*m && tmpl((a,c,d,e,f) => time <= a*((n*m)*m)+c*(n*m)+d*n+e*m+f)) -} diff --git a/testcases/orb-testcases/timing/ConstantPropagation.scala b/testcases/orb-testcases/timing/ConstantPropagation.scala deleted file mode 100644 index f344b4d84c745be978aadf6ca4f00fa06a4955dc..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/ConstantPropagation.scala +++ /dev/null @@ -1,294 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ -import leon.invariant._ -import leon.instrumentation._ - -object IntLattice { - abstract class Element - case class Bot() extends Element - case class Top() extends Element - case class BigIntVal(x: BigInt) extends Element - - def height: BigInt = { - /** - * A number that depends on the lattice definition. - * In simplest case it has height 3 (_|_ (bot) <= BigInts <= T (top)) - */ - 3 - } - - def join(oldVal: Element, newVal: Element) = (oldVal, newVal) match { - case (Bot(), any) => any // bot is the identity for join - case (any, Bot()) => any - case (Top(), _) => Top() // top joined with anything is top - case (_, Top()) => Top() - case (BigIntVal(x), BigIntVal(y)) if (x == y) => BigIntVal(y) - case _ => - //here old and new vals are different BigIntegers - Top() - } -} - -object LatticeOps { - import IntLattice._ - - def add(a: Element, b: Element): Element = { - (a, b) match { - case (Bot(), _) => Bot() - case (_, Bot()) => Bot() - case (Top(), _) => Top() - case (_, Top()) => Top() - case (BigIntVal(x), BigIntVal(y)) => BigIntVal(x + y) - } - } - - def multiply(a: Element, b: Element): Element = { - (a, b) match { - case (_, BigIntVal(x)) if x == 0 => BigIntVal(0) - case (BigIntVal(x), _) if x == 0 => BigIntVal(0) - case (Bot(), _) => Bot() - case (_, Bot()) => Bot() - case (Top(), _) => Top() - case (_, Top()) => Top() - case (BigIntVal(x), BigIntVal(y)) => BigIntVal(x * y) - } - } -} - -object ConstantPropagation { - import IntLattice._ - import LatticeOps._ - - abstract class Expr - case class Times(lhs: Expr, rhs: Expr) extends Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class BigIntLiteral(v: BigInt) extends Expr - case class FunctionCall(calleeId: BigInt, args: List[Expr]) extends Expr - case class IfThenElse(cond: Expr, thenExpr: Expr, elseExpr: Expr) extends Expr - case class Identifier(id: BigInt) extends Expr - - /** - * Definition of a function AST - */ - case class Function(id: BigInt, params: List[Expr], body: Expr) - - /** - * Assuming that the functions are ordered from callee to - * caller and there is no mutual recursion, only self recursion - */ - case class Program(funcs: List[Function]) - - def size(l: List[Function]): BigInt = { - l match { - case Cons(_, t) => 1 + size(t) - case Nil() => 0 - } - } - - def sizeExprList(exprs: List[Expr]): BigInt = { - exprs match { - case Nil() => 0 - case Cons(currExpr, otherExprs) => sizeExpr(currExpr) + sizeExprList(otherExprs) - } - } - - def sizeExpr(e: Expr): BigInt = { - e match { - case Plus(l, r) => 1 + sizeExpr(l) + sizeExpr(r) - case Times(l, r) => 1 + sizeExpr(l) + sizeExpr(r) - case FunctionCall(c, args) => { - 1 + sizeExprList(args) - } - case IfThenElse(c, th, el) => - 1 + sizeExpr(c) + sizeExpr(th) + sizeExpr(el) - case _ => 1 - } - } - - def sizeFuncList(funcs: List[Function]): BigInt = { - funcs match { - case Nil() => 0 - case Cons(currFunc, otherFuncs) => - 1 + sizeExpr(currFunc.body) + sizeFuncList(otherFuncs) - } - } - - def progSize(p: Program) = { - sizeFuncList(p.funcs) - } - - def initToBot(l: List[Function]): List[(BigInt /*function id*/ , Element)] = { - l match { - case Nil() => Nil[(BigInt /*function id*/ , Element)]() - case Cons(fun, tail) => Cons((fun.id, Bot()), initToBot(tail)) - } - } ensuring (_ => time <= ? * size(l) + ?) - - def foldConstants(p: Program): Program = { - val initVals = initToBot(p.funcs) - val fvals = computeSummaries(p, initToBot(p.funcs), height) - val newfuns = transformFuns(p.funcs, fvals) - Program(newfuns) - } ensuring(_ => time <= ? * (progSize(p)*height) + ? * height + ? * size(p.funcs) + ?) - - /** - * The initVals is the initial values for the - * values of the functions - */ - def computeSummaries(p: Program, initVals: List[(BigInt /*function id*/ , Element)], noIters: BigInt): List[(BigInt /*function id*/ , Element)] = { - require(noIters >= 0) - if (noIters <= 0) { - initVals - } else - computeSummaries(p, analyzeFuns(p.funcs, initVals, initVals), noIters - 1) - } ensuring(_ => time <= ? * (progSize(p)*noIters) + ? * noIters + ?) - - /** - * Initial fvals and oldVals are the same - * but as the function progresses, fvals will only have the olds values - * of the functions that are yet to be processed, whereas oldVals will remain the same. - */ - def analyzeFuns(funcs: List[Function], fvals: List[(BigInt, Element)], oldVals: List[(BigInt, Element)]): List[(BigInt, Element)] = { - (funcs, fvals) match { - case (Cons(f, otherFuns), Cons((fid, fval), otherVals)) => - val newval = analyzeFunction(f, oldVals) - val approxVal = join(fval, newval) //creates an approximation of newVal to ensure convergence - Cons((fid, approxVal), analyzeFuns (otherFuns, otherVals, oldVals)) - case _ => - Nil[(BigInt, Element)]() //this also handles precondition violations e.g. lists aren't of same size etc. - } - } ensuring (_ => time <= ? * sizeFuncList(funcs) + ?) - - @library - def getFunctionVal(funcId: BigInt, funcVals: List[(BigInt, Element)]): Element = { - funcVals match { - case Nil() => Bot() - case Cons((currFuncId, currFuncVal), otherFuncVals) if (currFuncId == funcId) => currFuncVal - case Cons(_, otherFuncVals) => - getFunctionVal(funcId, otherFuncVals) - } - } ensuring (_ => time <= 1) - - - def analyzeExprList(l: List[Expr], funcVals: List[(BigInt, Element)]): List[Element] = { - l match { - case Nil() => Nil[Element]() - case Cons(expr, otherExprs) => Cons(analyzeExpr(expr, funcVals), analyzeExprList(otherExprs, funcVals)) - } - } ensuring (_ => time <= ? * sizeExprList(l) + ?) - - /** - * Returns the value of the expression when "Abstractly Interpreted" - * using the lattice. - */ - def analyzeExpr(e: Expr, funcVals: List[(BigInt, Element)]): Element = { - e match { - case Times(lhs: Expr, rhs: Expr) => { - val lval = analyzeExpr(lhs, funcVals) - val rval = analyzeExpr(rhs, funcVals) - multiply(lval, rval) - } - case Plus(lhs: Expr, rhs: Expr) => { - val lval = analyzeExpr(lhs, funcVals) - val rval = analyzeExpr(rhs, funcVals) - add(lval, rval) - } - case FunctionCall(id, args: List[Expr]) => { - getFunctionVal(id, funcVals) - } - case IfThenElse(c, th, el) => { - //analyze then and else branches and join their values - //TODO: this can be made more precise e.g. if 'c' is - //a non-zero value it can only execute the then branch. - val v1 = analyzeExpr(th, funcVals) - val v2 = analyzeExpr(el, funcVals) - join(v1, v2) - } - case lit @ BigIntLiteral(v) => - BigIntVal(v) - - case Identifier(_) => Bot() - } - } ensuring (_ => time <= ? * sizeExpr(e) + ?) - - - def analyzeFunction(f: Function, oldVals: List[(BigInt, Element)]): Element = { - // traverse the body of the function and simplify constants - // for function calls assume the value given by oldVals - // also for if-then-else statments, take a join of the values along if and else branches - // assume that bot op any = bot and top op any = top (but this can be made more precise). - analyzeExpr(f.body, oldVals) - } ensuring (_ => time <= ? * sizeExpr(f.body) + ?) - - - def transformExprList(l: List[Expr], funcVals: List[(BigInt, Element)]): List[Expr] = { - l match { - case Nil() => Nil[Expr]() - case Cons(expr, otherExprs) => Cons(transformExpr(expr, funcVals), - transformExprList(otherExprs, funcVals)) - } - } ensuring (_ => time <= ? * sizeExprList(l) + ?) - - /** - * Returns the folded expression - */ - def transformExpr(e: Expr, funcVals: List[(BigInt, Element)]): Expr = { - e match { - case Times(lhs: Expr, rhs: Expr) => { - val foldedLHS = transformExpr(lhs, funcVals) - val foldedRHS = transformExpr(rhs, funcVals) - (foldedLHS, foldedRHS) match { - case (BigIntLiteral(x), BigIntLiteral(y)) => - BigIntLiteral(x * y) - case _ => - Times(foldedLHS, foldedRHS) - } - } - case Plus(lhs: Expr, rhs: Expr) => { - val foldedLHS = transformExpr(lhs, funcVals) - val foldedRHS = transformExpr(rhs, funcVals) - (foldedLHS, foldedRHS) match { - case (BigIntLiteral(x), BigIntLiteral(y)) => - BigIntLiteral(x + y) - case _ => - Plus(foldedLHS, foldedRHS) - } - } - case FunctionCall(calleeid, args: List[Expr]) => { - getFunctionVal(calleeid, funcVals) match { - case BigIntVal(x) => - BigIntLiteral(x) - case _ => - val foldedArgs = transformExprList(args, funcVals) - FunctionCall(calleeid, foldedArgs) - } - } - case IfThenElse(c, th, el) => { - val foldedCond = transformExpr(c, funcVals) - val foldedTh = transformExpr(th, funcVals) - val foldedEl = transformExpr(el, funcVals) - foldedCond match { - case BigIntLiteral(x) => { - if (x != 0) foldedTh - else foldedEl - } - case _ => IfThenElse(foldedCond, foldedTh, foldedEl) - } - } - case _ => e - } - } ensuring (_ => time <= ? * sizeExpr(e) + ?) - - - def transformFuns(funcs: List[Function], fvals: List[(BigInt, Element)]): List[Function] = { - funcs match { - case Cons(f, otherFuns) => - val newfun = Function(f.id, f.params, transformExpr(f.body, fvals)) - Cons(newfun, transformFuns(otherFuns, fvals)) - case _ => - Nil[Function]() - } - } ensuring (_ => time <= ? * sizeFuncList(funcs) + ?) -} \ No newline at end of file diff --git a/testcases/orb-testcases/timing/Folds.scala b/testcases/orb-testcases/timing/Folds.scala deleted file mode 100644 index 2dac7e26684a0764429f0a14b8098160bcd0a0e4..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/Folds.scala +++ /dev/null @@ -1,77 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object TreeMaps { - - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def size(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => size(l) + size(r) + 1 - } - } - - def parallelSearch(elem : BigInt, t : Tree) : Boolean = { - t match { - case Node(l, x, r) => - if(x == elem) true - else { - val r1 = parallelSearch(elem, r) - val r2 = parallelSearch(elem, l) - if(r1 || r2) true - else false - } - case Leaf() => false - } - } ensuring(res => true && tmpl((a,b) => time <= a*size(t) + b)) - - - def squareMap(t : Tree) : Tree = { - t match { - case Node(l, x, r) => - val nl = squareMap(l) - val nr = squareMap(r) - Node(nl, x*x, nr) - case _ => t - } - } ensuring (res => true && tmpl((a,b) => time <= a*size(t) + b)) - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def fact(n : BigInt) : BigInt = { - require(n >= 0) - - if(n == 1 || n == 0) BigInt(1) - else n * fact(n-1) - - } ensuring(res => true && tmpl((a,b) => time <= a*n + b)) - - def descending(l: List, k: BigInt) : Boolean = { - l match { - case Nil() => true - case Cons(x, t) => x > 0 && x <= k && descending(t, x-1) - } - } - - def factMap(l: List, k: BigInt): List = { - require(descending(l, k) && k >= 0) - - l match { - case Nil() => Nil() - case Cons(x, t) => { - val f = fact(x) - Cons(f, factMap(t, x-1)) - } - - }} ensuring(res => true && tmpl((a,b) => time <= a*(k*k) + b)) -} \ No newline at end of file diff --git a/testcases/orb-testcases/timing/ForElimination.scala b/testcases/orb-testcases/timing/ForElimination.scala deleted file mode 100644 index c76da1507651ca301816ef6fa26c6e468cf6df3d..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/ForElimination.scala +++ /dev/null @@ -1,102 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object ForElimination { - - sealed abstract class List - case class Nil() extends List - case class Cons(head: Statement, tail: List) extends List - - sealed abstract class Statement - case class Print(msg: BigInt, varID: BigInt) extends Statement - case class Assign(varID: BigInt, expr: Expression) extends Statement - case class Skip() extends Statement - case class Block(body: List) extends Statement - case class IfThenElse(expr: Expression, thenExpr: Statement, elseExpr: Statement) extends Statement - case class While(expr: Expression, body: Statement) extends Statement - case class For(init: Statement, expr: Expression, step: Statement, body: Statement) extends Statement - - sealed abstract class Expression - case class Var(varID: BigInt) extends Expression - case class IntLiteral(value: BigInt) extends Expression - case class Plus(lhs: Expression, rhs: Expression) extends Expression - case class Minus(lhs: Expression, rhs: Expression) extends Expression - case class Times(lhs: Expression, rhs: Expression) extends Expression - case class Division(lhs: Expression, rhs: Expression) extends Expression - case class Equals(lhs: Expression, rhs: Expression) extends Expression - case class LessThan(lhs: Expression, rhs: Expression) extends Expression - case class And(lhs: Expression, rhs: Expression) extends Expression - case class Or(lhs: Expression, rhs: Expression) extends Expression - case class Not(expr: Expression) extends Expression - - def sizeStat(st: Statement) : BigInt = st match { - case Block(l) => sizeList(l) + 1 - case IfThenElse(c,th,el) => sizeStat(th) + sizeStat(el) + 1 - case While(c,b) => sizeStat(b) + 1 - case For(init,cond,step,body) => sizeStat(init) + sizeStat(step) + sizeStat(body) - case other => 1 - } - - def sizeList(l: List) : BigInt = l match { - case Cons(h,t) => sizeStat(h) + sizeList(t) - case Nil() => 0 - } - - def isForFree(stat: Statement): Boolean = (stat match { - case Block(body) => isForFreeList(body) - case IfThenElse(_, thenExpr, elseExpr) => isForFree(thenExpr) && isForFree(elseExpr) - case While(_, body) => isForFree(body) - case For(_,_,_,_) => false - case _ => true - }) ensuring(res => true && tmpl((a,b) => time <= a*sizeStat(stat) + b)) - - def isForFreeList(l: List): Boolean = (l match { - case Nil() => true - case Cons(x, xs) => isForFree(x) && isForFreeList(xs) - }) ensuring(res => true && tmpl((a,b) => time <= a*sizeList(l) + b)) - - def forLoopsWellFormedList(l: List): Boolean = (l match { - case Nil() => true - case Cons(x, xs) => forLoopsWellFormed(x) && forLoopsWellFormedList(xs) - }) ensuring(res => true && tmpl((a,b) => time <= a*sizeList(l) + b)) - - def forLoopsWellFormed(stat: Statement): Boolean = (stat match { - case Block(body) => forLoopsWellFormedList(body) - case IfThenElse(_, thenExpr, elseExpr) => forLoopsWellFormed(thenExpr) && forLoopsWellFormed(elseExpr) - case While(_, body) => forLoopsWellFormed(body) - case For(init, _, step, body) => isForFree(init) && isForFree(step) && forLoopsWellFormed(body) - case _ => true - }) ensuring(res => true && tmpl((a,b) => time <= a*sizeStat(stat) + b)) - - def eliminateWhileLoopsList(l: List): List = { - l match { - case Nil() => Nil() - case Cons(x, xs) => Cons(eliminateWhileLoops(x), eliminateWhileLoopsList(xs)) - } - } ensuring(res => true && tmpl((a,b) => time <= a*sizeList(l) + b)) - - def eliminateWhileLoops(stat: Statement): Statement = (stat match { - case Block(body) => Block(eliminateWhileLoopsList(body)) - case IfThenElse(expr, thenExpr, elseExpr) => IfThenElse(expr, eliminateWhileLoops(thenExpr), eliminateWhileLoops(elseExpr)) - case While(expr, body) => For(Skip(), expr, Skip(), eliminateWhileLoops(body)) - case For(init, expr, step, body) => For(eliminateWhileLoops(init), expr, eliminateWhileLoops(step), eliminateWhileLoops(body)) - case other => other - }) ensuring(res => true && tmpl((a,b) => time <= a*sizeStat(stat) + b)) - - def eliminateForLoopsList(l: List): List = { - l match { - case Nil() => Nil() - case Cons(x, xs) => Cons(eliminateForLoops(x), eliminateForLoopsList(xs)) - } - } ensuring(res => true && tmpl((a,b) => time <= a*sizeList(l) + b)) - - def eliminateForLoops(stat: Statement): Statement = { - stat match { - case Block(body) => Block(eliminateForLoopsList(body)) - case IfThenElse(expr, thenExpr, elseExpr) => IfThenElse(expr, eliminateForLoops(thenExpr), eliminateForLoops(elseExpr)) - case While(expr, body) => While(expr, eliminateForLoops(body)) - case For(init, expr, step, body) => Block(Cons(eliminateForLoops(init), Cons(While(expr, Block(Cons(eliminateForLoops(body), Cons(eliminateForLoops(step), Nil())))), Nil()))) - case other => other - } - } ensuring(res => true && tmpl((a,b) => time <= a*sizeStat(stat) + b)) -} diff --git a/testcases/orb-testcases/timing/InsertionSort.scala b/testcases/orb-testcases/timing/InsertionSort.scala deleted file mode 100644 index 8c0f029798e29fc8834c0dd598f61e323f307f67..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/InsertionSort.scala +++ /dev/null @@ -1,25 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object InsertionSort { - sealed abstract class List - case class Cons(head: BigInt, tail:List) extends List - case class Nil() extends List - - def size(l : List) : BigInt = (l match { - case Cons(_, xs) => 1 + size(xs) - case _ => 0 - }) - - def sortedIns(e: BigInt, l: List): List = { - l match { - case Cons(x,xs) => if (x <= e) Cons(x,sortedIns(e, xs)) else Cons(e, l) - case _ => Cons(e,Nil()) - } - } ensuring(res => size(res) == size(l) + 1 && time <= ? * size(l) + ? && depth <= ? * size(l) + ?) - - def sort(l: List): List = (l match { - case Cons(x,xs) => sortedIns(x, sort(xs)) - case _ => Nil() - }) ensuring(res => size(res) == size(l) && time <= ? * (size(l)*size(l)) + ? && rec <= ? * size(l) + ?) -} diff --git a/testcases/orb-testcases/timing/LeftistHeap.scala b/testcases/orb-testcases/timing/LeftistHeap.scala deleted file mode 100644 index 2d3cd389ab13e437b6f2458eafc7b841bc005f4f..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/LeftistHeap.scala +++ /dev/null @@ -1,82 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -import leon.annotation._ - -object LeftistHeap { - sealed abstract class Heap - case class Leaf() extends Heap - case class Node(rk : BigInt, value: BigInt, left: Heap, right: Heap) extends Heap - - private def rightHeight(h: Heap) : BigInt = h match { - case Leaf() => 0 - case Node(_,_,_,r) => rightHeight(r) + 1 - } - - private def rank(h: Heap) : BigInt = h match { - case Leaf() => 0 - case Node(rk,_,_,_) => rk - } - - private def hasLeftistProperty(h: Heap) : Boolean = (h match { - case Leaf() => true - case Node(_,_,l,r) => hasLeftistProperty(l) && hasLeftistProperty(r) && rightHeight(l) >= rightHeight(r) && (rank(h) == rightHeight(h)) - }) - - @monotonic - def twopower(x: BigInt) : BigInt = { - require(x >= 0) - if(x < 1) 1 - else - 2* twopower(x - 1) - } - - def size(t: Heap): BigInt = { - require(hasLeftistProperty(t)) - (t match { - case Leaf() => BigInt(0) - case Node(_,v, l, r) => size(l) + 1 + size(r) - }) - } ensuring (res => true && tmpl((a,b) => twopower(rightHeight(t)) <= a*res + b)) - - def leftRightHeight(h: Heap) : BigInt = {h match { - case Leaf() => 0 - case Node(_,_,l,r) => rightHeight(l) - }} - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h)) - h match { - case Node(_,_,l,r) => merge(l, r) - case l @ Leaf() => l - } - } ensuring(res => true && tmpl((a,b) => time <= a*leftRightHeight(h) + b)) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2)) - h1 match { - case Leaf() => h2 - case Node(_, v1, l1, r1) => h2 match { - case Leaf() => h1 - case Node(_, v2, l2, r2) => - if(v1 > v2) - makeT(v1, l1, merge(r1, h2)) - else - makeT(v2, l2, merge(h1, r2)) - } - } - } ensuring(res => true && tmpl((a,b,c) => time <= a*rightHeight(h1) + b*rightHeight(h2) + c)) - - private def makeT(value: BigInt, left: Heap, right: Heap) : Heap = { - if(rank(left) >= rank(right)) - Node(rank(right) + 1, value, left, right) - else - Node(rank(left) + 1, value, right, left) - } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap)) - - merge(Node(1, element, Leaf(), Leaf()), heap) - - } ensuring(res => true && tmpl((a,b,c) => time <= a*rightHeight(heap) + c)) -} diff --git a/testcases/orb-testcases/timing/ListOperations.scala b/testcases/orb-testcases/timing/ListOperations.scala deleted file mode 100644 index 444029464261b21ec3a4dc434c31bed4904101b8..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/ListOperations.scala +++ /dev/null @@ -1,61 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object ListOperations { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def append(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => Cons(x, append(xs, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && tmpl((a,b) => time <= a*size(l1) + b)) - - def reverseRec(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverseRec(xs, Cons(x, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && tmpl((a,b) => time <= a*size(l1) + b)) - //ensuring (res => size(l1) + size(l2) == size(res) && time <= 4*size(l1) + 1) - - def reverse(l: List): List = { - reverseRec(l, Nil()) - - } ensuring (res => size(l) == size(res) && tmpl((a,b) => time <= a*size(l) + b)) - - def reverse2(l: List): List = { - l match { - case Nil() => l - case Cons(hd, tl) => append(reverse2(tl), Cons(hd, Nil())) - } - } ensuring (res => size(res) == size(l) && tmpl((a,b) => time <= a*(size(l)*size(l)) + b)) - - def remove(elem: BigInt, l: List): List = { - l match { - case Nil() => Nil() - case Cons(hd, tl) => if (hd == elem) remove(elem, tl) else Cons(hd, remove(elem, tl)) - } - } ensuring (res => size(l) >= size(res) && tmpl((a,b) => time <= a*size(l) + b)) - - def contains(list: List, elem: BigInt): Boolean = (list match { - case Nil() => false - case Cons(x, xs) => x == elem || contains(xs, elem) - - }) ensuring (res => true && tmpl((a,b) => time <= a*size(list) + b)) - - def distinct(l: List): List = ( - l match { - case Nil() => Nil() - case Cons(x, xs) => { - val newl = distinct(xs) - if (contains(newl, x)) newl - else Cons(x, newl) - } - }) ensuring (res => size(l) >= size(res) && tmpl((a,b) => time <= a*(size(l)*size(l)) + b)) -} diff --git a/testcases/orb-testcases/timing/MergeSort.scala b/testcases/orb-testcases/timing/MergeSort.scala deleted file mode 100644 index aa900aada57f70fb4ef7e63b8cbeefd82abe9457..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/MergeSort.scala +++ /dev/null @@ -1,76 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -import leon.annotation._ - -object MergeSort { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case class Nil() extends List - - //case class Pair(fst:List,snd:List) - - @monotonic - def log(x: BigInt) : BigInt = { - require(x >= 0) - if(x <= 1) 0 - else { - val k = x/2 - 1 + log(x - k) - } - } ensuring(res => true && tmpl((a) => res >= 0)) - - def size(list:List): BigInt = {list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - }} ensuring(res => true && tmpl((a) => res >= 0)) - - def length(l:List): BigInt = { - l match { - case Nil() => 0 - case Cons(x,xs) => 1 + length(xs) - } - } ensuring(res => res == size(l) && tmpl((a,b) => time <= a*size(l) + b)) - - def split(l:List,n:BigInt): (List,List) = { - require(n >= 0 && n <= size(l)) - if (n <= 0) (Nil(),l) - else - l match { - case Nil() => (Nil(),l) - case Cons(x,xs) => { - if(n == 1) (Cons(x,Nil()), xs) - else { - val (fst,snd) = split(xs, n-1) - (Cons(x,fst), snd) - } - } - } - } ensuring(res => size(res._2) == size(l) - n && size(res._1) == n && tmpl((a,b) => time <= a*n +b)) - - def merge(aList:List, bList:List):List = (bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - }) ensuring(res => size(aList)+size(bList) == size(res) && tmpl((a,b,c) => time <= a*size(aList) + b*size(bList) + c)) - - def mergeSort(list:List):List = { - list match { - case Cons(x,Nil()) => list - case Cons(_,Cons(_,_)) => - val lby2 = length(list)/2 - val (fst,snd) = split(list,lby2) - //merge(mergeSort(fst,l), mergeSort(snd,len - l)) - merge(mergeSort(fst),mergeSort(snd)) - - case _ => list - - }} ensuring(res => true && tmpl((a,b) => time <= a*(size(list)*log(size(list))) + b)) -} diff --git a/testcases/orb-testcases/timing/PropositionalLogic.scala b/testcases/orb-testcases/timing/PropositionalLogic.scala deleted file mode 100644 index 22dfdcdec06cef0760222140d669d11ae134a658..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/PropositionalLogic.scala +++ /dev/null @@ -1,115 +0,0 @@ -import scala.collection.immutable.Set -import leon.invariant._ -import leon.instrumentation._ - -object PropositionalLogic { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Implies(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Literal(id: BigInt) extends Formula - case class True() extends Formula - case class False() extends Formula - - case class Pair(f: Formula, b: Boolean) - - sealed abstract class List - case class Cons(x: Pair, xs: List) extends List - case class Nil() extends List - - def size(f : Formula) : BigInt = (f match { - case And(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Or(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Implies(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Not(f) => size(f) + 1 - case _ => 1 - }) - - def removeImplies(f: Formula): Formula = (f match { - case And(lhs, rhs) => And(removeImplies(lhs), removeImplies(rhs)) - case Or(lhs, rhs) => Or(removeImplies(lhs), removeImplies(rhs)) - case Implies(lhs, rhs) => Or(Not(removeImplies(lhs)),removeImplies(rhs)) - case Not(f) => Not(removeImplies(f)) - case _ => f - - }) ensuring(_ => time <= ? * size(f) + ?) - - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Implies(lhs, rhs) => Implies(nnf(lhs), nnf(rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Implies(lhs, rhs)) => And(nnf(lhs), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case Not(Literal(_)) => formula - case Literal(_) => formula - case Not(True()) => False() - case Not(False()) => True() - case _ => formula - }) ensuring(_ => time <= ? * size(formula) + ?) - - def isNNF(f: Formula): Boolean = { f match { - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Implies(lhs, rhs) => false - case Not(Literal(_)) => true - case Not(_) => false - case _ => true - }} ensuring(_ => time <= ? * size(f) + ?) - - def simplify(f: Formula): Formula = (f match { - case And(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs or rhs is false, return false - //if lhs is true return rhs - //if rhs is true return lhs - (sl,sr) match { - case (False(), _) => False() - case (_, False()) => False() - case (True(), _) => sr - case (_, True()) => sl - case _ => And(sl, sr) - } - } - case Or(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs or rhs is true, return true - //if lhs is false return rhs - //if rhs is false return lhs - (sl,sr) match { - case (True(), _) => True() - case (_, True()) => True() - case (False(), _) => sr - case (_, False()) => sl - case _ => Or(sl, sr) - } - } - case Implies(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs is false return true - //if rhs is true return true - //if lhs is true return rhs - //if rhs is false return Not(rhs) - (sl,sr) match { - case (False(), _) => True() - case (_, True()) => True() - case (True(), _) => sr - case (_, False()) => Not(sl) - case _ => Implies(sl, sr) - } - } - case Not(True()) => False() - case Not(False()) => True() - case _ => f - - }) ensuring(_ => time <= ? *size(f) + ?) -} diff --git a/testcases/orb-testcases/timing/QuickSort.scala b/testcases/orb-testcases/timing/QuickSort.scala deleted file mode 100644 index 2f4101dc8636ff9a3dada89e73a4f11c1e908a90..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/QuickSort.scala +++ /dev/null @@ -1,43 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object QuickSort { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case class Nil() extends List - - def size(l:List): BigInt = {l match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - }} - - case class Triple(fst:List,snd:List, trd: List) - - def append(aList:List,bList:List): List = {aList match { - case Nil() => bList - case Cons(x, xs) => Cons(x,append(xs,bList)) - }} ensuring(res => size(res) == size(aList) + size(bList) && tmpl((a,b) => time <= a*size(aList) +b)) - - def partition(n:BigInt,l:List) : Triple = (l match { - case Nil() => Triple(Nil(), Nil(), Nil()) - case Cons(x,xs) => { - val t = partition(n,xs) - if (n < x) Triple(t.fst, t.snd, Cons(x,t.trd)) - else if(n == x) Triple(t.fst, Cons(x,t.snd), t.trd) - else Triple(Cons(x,t.fst), t.snd, t.trd) - } - }) ensuring(res => (size(l) == size(res.fst) + size(res.snd) + size(res.trd)) && tmpl((a,b) => time <= a*size(l) +b)) - - //Unable to prove n^2 upper bound :-( - def quickSort(l:List): List = (l match { - case Nil() => Nil() - case Cons(x,Nil()) => l - case Cons(x,xs) => { - val t = partition(x, xs) - append(append(quickSort(t.fst), Cons(x, t.snd)), quickSort(t.trd)) - } - case _ => l - }) - //ensuring(res => size(l) == size(res) && tmpl((a,b,c,d) => time <= a*(size(l)*size(l)) + c*size(l) + d)) -} - diff --git a/testcases/orb-testcases/timing/RedBlackTree.scala b/testcases/orb-testcases/timing/RedBlackTree.scala deleted file mode 100644 index 7ad0a1088ba09eac9195d9808d8ef6d647b84130..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/RedBlackTree.scala +++ /dev/null @@ -1,112 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -import scala.collection.immutable.Set - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: BigInt, right: Tree) extends Tree - - def twopower(x: BigInt) : BigInt = { - require(x >= 0) - if(x < 1) 1 - else - 2* twopower(x - 1) - } - - def size(t: Tree): BigInt = { - require(blackBalanced(t)) - (t match { - case Empty() => BigInt(0) - case Node(_, l, v, r) => size(l) + 1 + size(r) - }) - } ensuring (res => tmpl((a,b) => twopower(blackHeight(t)) <= a*res + b)) - - def blackHeight(t : Tree) : BigInt = { - t match { - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - case _ => 0 - } - } - - //We consider leaves to be black by definition - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case _ => false - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case _ => true - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case _ => true - } - - // <<insert element x BigInto the tree t>> - def ins(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if(x < y) { - val t1 = ins(x, a) - balance(c, t1, y, b) - } - else if (x == y){ - Node(c,a,y,b) - } - else{ - val t1 = ins(x, b) - balance(c,a,y,t1) - } - } - } ensuring(res => tmpl((a,b) => time <= a*blackHeight(t) + b)) - - def makeBlack(n: Tree): Tree = { - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } - - def add(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) ) - val t1 = ins(x, t) - makeBlack(t1) - - } ensuring(res => tmpl((a,b) => time <= a*blackHeight(t) + b)) - - def balance(co: Color, l: Tree, x: BigInt, r: Tree): Tree = { - Node(co,l,x,r) - match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case _ => Node(co,l,x,r) - } - } - - -} diff --git a/testcases/orb-testcases/timing/SortingCombined.scala b/testcases/orb-testcases/timing/SortingCombined.scala deleted file mode 100644 index 914d997aff4768b4ca5d5eb33cc46d2007477ee7..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/SortingCombined.scala +++ /dev/null @@ -1,116 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -import leon.annotation._ - -object Sort { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case class Nil() extends List - - //case class Pair(fst:List,snd:List) - - // @monotonic - def log(x: BigInt) : BigInt = { - //require(x >= 0) - if(x <= 1) 0 - else 1 + log(x/2) - } //ensuring(res=> true && tmpl((b) => res >= b)) - - def size(list:List): BigInt = {list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - }} - - def length(l:List): BigInt = { - l match { - case Nil() => 0 - case Cons(x,xs) => 1 + length(xs) - } - } ensuring(res => res == size(l) && tmpl((a,b) => time <= a*size(l) + b)) - - def split(l:List,n:BigInt): (List,List) = { - require(n >= 0 && n <= size(l)) - if (n <= 0) (Nil(),l) - else - l match { - case Nil() => (Nil(),l) - case Cons(x,xs) => { - if(n == 1) (Cons(x,Nil()), xs) - else { - val (fst,snd) = split(xs, n-1) - (Cons(x,fst), snd) - } - } - } - } ensuring(res => size(res._2) == size(l) - n && size(res._1) == n && tmpl((a,b) => time <= a*n +b)) - - def merge(aList:List, bList:List):List = (bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - }) ensuring(res => size(aList)+size(bList) == size(res) && tmpl((a,b,c) => time <= a*size(aList) + b*size(bList) + c)) - - def mergeSort(list:List, len: BigInt):List = { - require(len == size(list)) - - list match { - case Cons(x,Nil()) => list - case Cons(_,Cons(_,_)) => - val l = len/2 - val (fst,snd) = split(list,l) - merge(mergeSort(fst,l), mergeSort(snd,len - l)) - - case _ => list - - }} //ensuring(res => size(res) == size(list) && tmpl((a,b,c) => time <= a*(size(list)*size(list)) + c)) - //&& tmpl((a,b) => time <= a*size(list) + b)) - //ensuring(res => true && tmpl((a,b) => time <= a*(size(list)*log(size(list))) + b)) - case class Triple(fst:List,snd:List, trd: List) - - def append(aList:List,bList:List): List = {aList match { - case Nil() => bList - case Cons(x, xs) => Cons(x,append(xs,bList)) - }} ensuring(res => size(res) == size(aList) + size(bList) && tmpl((a,b) => time <= a*size(aList) +b)) - - def partition(n:BigInt,l:List) : Triple = (l match { - case Nil() => Triple(Nil(), Nil(), Nil()) - case Cons(x,xs) => { - val t = partition(n,xs) - if (n < x) Triple(t.fst, t.snd, Cons(x,t.trd)) - else if(n == x) Triple(t.fst, Cons(x,t.snd), t.trd) - else Triple(Cons(x,t.fst), t.snd, t.trd) - } - }) ensuring(res => (size(l) == size(res.fst) + size(res.snd) + size(res.trd)) && tmpl((a,b) => time <= a*size(l) +b)) - - //Unable to prove n^2 upper bound :-( - def quickSort(l:List): List = (l match { - case Nil() => Nil() - case Cons(x,Nil()) => l - case Cons(x,xs) => { - val t = partition(x, xs) - append(append(quickSort(t.fst), Cons(x, t.snd)), quickSort(t.trd)) - } - case _ => l - }) - - def sortedIns(e: BigInt, l: List): List = { - l match { - case Nil() => Cons(e,Nil()) - case Cons(x,xs) => if (x <= e) Cons(x,sortedIns(e, xs)) else Cons(e, l) - } - } ensuring(res => size(res) == size(l) + 1 && tmpl((a,b) => time <= a*size(l) +b)) - - def sort(l: List): List = (l match { - case Nil() => Nil() - case Cons(x,xs) => sortedIns(x, sort(xs)) - - }) ensuring(res => size(res) == size(l) && tmpl((a,b) => time <= a*(size(l)*size(l)) +b)) - -} diff --git a/testcases/orb-testcases/timing/SpeedBenchmarks.scala b/testcases/orb-testcases/timing/SpeedBenchmarks.scala deleted file mode 100644 index 4728ae6bc6f5a5089d0ee046887e7f85ed495686..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/SpeedBenchmarks.scala +++ /dev/null @@ -1,110 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - - -object SpeedBenchmarks { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - sealed abstract class StringBuffer - case class Chunk(str: List, next: StringBuffer) extends StringBuffer - case class Empty() extends StringBuffer - - def length(sb: StringBuffer) : BigInt = sb match { - case Chunk(_, next) => 1 + length(next) - case _ => 0 - } - - def sizeBound(sb: StringBuffer, k: BigInt) : Boolean ={ - sb match { - case Chunk(str, next) => size(str) <= k && sizeBound(next, k) - case _ => 0 <= k - } - } - - /** - * Fig. 1 of SPEED, POPL'09: The functional version of the implementation. - * Equality check of two string buffers - */ - def Equals(str1: List, str2: List, s1: StringBuffer, s2: StringBuffer, k: BigInt) : Boolean = { - require(sizeBound(s1, k) && sizeBound(s2, k) && size(str1) <= k && size(str2) <= k && k >= 0) - - (str1, str2) match { - case (Cons(h1,t1), Cons(h2,t2)) => { - - if(h1 != h2) false - else Equals(t1,t2, s1,s2, k) - } - case (Cons(_,_), Nil()) => { - //load from s2 - s2 match { - case Chunk(str, next) => Equals(str1, str, s1, next, k) - case Empty() => false - } - } - case (Nil(), Cons(_,_)) => { - //load from s1 - s1 match { - case Chunk(str, next) => Equals(str, str2, next, s2, k) - case Empty() => false - } - } - case _ =>{ - //load from both - (s1,s2) match { - case (Chunk(nstr1, next1),Chunk(nstr2, next2)) => Equals(nstr1, nstr2, next1, next2, k) - case (Empty(),Chunk(nstr2, next2)) => Equals(str1, nstr2, s1, next2, k) - case (Chunk(nstr1, next1), Empty()) => Equals(nstr1, str2, next1, s2, k) - case _ => true - } - } - } - } ensuring(res => true && tmpl((a,b,c,d,e) => time <= a*((k+1)*(length(s1) + length(s2))) + b*size(str1) + e)) - //ensuring(res => true && tmpl((a,b,c,d,e) => time <= a*(k*(length(s1) + length(s2))) + b*size(str1) + c*length(s1) + d*length(s2) + e)) - - def max(x: BigInt, y: BigInt) : BigInt = if(x >= y) x else y - - //Fig. 2 of Speed POPL'09 - def Dis1(x : BigInt, y : BigInt, n: BigInt, m: BigInt) : BigInt = { - if(x >= n) BigInt(0) - else { - if(y < m) Dis1(x, y+1, n, m) - else Dis1(x+1, y, n, m) - } - } ensuring(res => true && tmpl((a,b,c) => time <= a*max(0,n-x) + b*max(0,m-y) + c)) - - //Fig. 2 of Speed POPL'09 - def Dis2(x : BigInt, z : BigInt, n: BigInt) : BigInt = { - if(x >= n) BigInt(0) - else { - if(z > x) Dis2(x+1, z, n) - else Dis2(x, z+1, n) - } - } ensuring(res => true && tmpl((a,b,c) => time <= a*max(0,n-x) + b*max(0,n-z) + c)) - - //Pg. 138, Speed POPL'09 - def Dis3(x : BigInt, b : Boolean, t: BigInt, n: BigInt) : BigInt = { - require((b && t == 1) || (!b && t == -1)) - if(x > n || x < 0) BigInt(0) - else { - if(b) Dis3(x+t, b, t, n) - else Dis3(x-t, b, t, n) - } - } ensuring(res => true && tmpl((a,c) => time <= a*max(0,(n-x)) + c)) - - //Pg. 138, Speed POPL'09 - def Dis4(x : BigInt, b : Boolean, t: BigInt, n: BigInt) : BigInt = { - if(x > n || x < 0) BigInt(0) - else { - if(b) Dis4(x+t, b, t, n) - else Dis4(x-t, b, t, n) - } - } ensuring(res => true && tmpl((a,c,d,e) => (((b && t >= 0) || (!b && t < 0)) && time <= a*max(0,(n-x)) + c) - || (((!b && t >= 0) || (b && t < 0)) && time <= d*max(0,x) + e))) -} diff --git a/testcases/orb-testcases/timing/TreeOperations.scala b/testcases/orb-testcases/timing/TreeOperations.scala deleted file mode 100644 index 2e73dcd77ddfa630ba3801514ec96482fabfdb1d..0000000000000000000000000000000000000000 --- a/testcases/orb-testcases/timing/TreeOperations.scala +++ /dev/null @@ -1,93 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - - -object TreeOperations { - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def listSize(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + listSize(t) - }) - - def size(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - size(l) + size(r) + 1 - } - } - } - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def insert(elem: BigInt, t: Tree): Tree = { - t match { - case Leaf() => Node(Leaf(), elem, Leaf()) - case Node(l, x, r) => if (x <= elem) Node(l, x, insert(elem, r)) - else Node(insert(elem, l), x, r) - } - } ensuring (res => height(res) <= height(t) + 1 && tmpl((a,b) => time <= a*height(t) + b)) - - def addAll(l: List, t: Tree): Tree = { - l match { - case Nil() => t - case Cons(x, xs) =>{ - val newt = insert(x, t) - addAll(xs, newt) - } - } - } ensuring(res => tmpl((a,b,c) => time <= a*(listSize(l) * (height(t) + listSize(l))) + b*listSize(l) + c)) - - def remove(elem: BigInt, t: Tree): Tree = { - t match { - case Leaf() => Leaf() - case Node(l, x, r) => { - - if (x < elem) Node(l, x, remove(elem, r)) - else if (x > elem) Node(remove(elem, l), x, r) - else { - t match { - case Node(Leaf(), x, Leaf()) => Leaf() - case Node(Leaf(), x, Node(_, rx, _)) => Node(Leaf(), rx, remove(rx, r)) - case Node(Node(_, lx, _), x, r) => Node(remove(lx, l), lx, r) - case _ => Leaf() - } - } - } - } - } ensuring (res => height(res) <= height(t) && tmpl ((a, b, c) => time <= a*height(t) + b)) - - def removeAll(l: List, t: Tree): Tree = { - l match { - case Nil() => t - case Cons(x, xs) => removeAll(xs, remove(x, t)) - } - } ensuring(res => tmpl((a,b,c) => time <= a*(listSize(l) * height(t)) + b*listSize(l) + c)) - - def contains(elem : BigInt, t : Tree) : Boolean = { - t match { - case Leaf() => false - case Node(l, x, r) => - if(x == elem) true - else if (x < elem) contains(elem, r) - else contains(elem, l) - } - } ensuring (res => tmpl((a,b) => time <= a*height(t) + b)) -} \ No newline at end of file diff --git a/testcases/proof/proba/Coins.scala b/testcases/proof/proba/Coins.scala deleted file mode 100644 index 1d2687a4a0f14bee09c048403dd3c45d090a9e5e..0000000000000000000000000000000000000000 --- a/testcases/proof/proba/Coins.scala +++ /dev/null @@ -1,205 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Coins { - - case class CoinDist(pHead: Real) { - def pTail: Real = { - require(pHead >= Real(0) && pHead <= Real(1)) - Real(1) - pHead - } ensuring(res => res >= Real(0) && res <= Real(1)) - } - - def isDist(dist: CoinDist): Boolean = - dist.pHead >= Real(0) && dist.pHead <= Real(1) - - - case class CoinsJoinDist(hh: Real, ht: Real, th: Real, tt: Real) - - def isDist(dist: CoinsJoinDist): Boolean = - dist.hh >= Real(0) && dist.hh <= Real(1) && - dist.ht >= Real(0) && dist.ht <= Real(1) && - dist.th >= Real(0) && dist.th <= Real(1) && - dist.tt >= Real(0) && dist.tt <= Real(1) && - (dist.hh + dist.ht + dist.th + dist.tt) == Real(1) - - - def isUniform(dist: CoinDist): Boolean = { - require(isDist(dist)) - dist.pHead == Real(1, 2) - } - - - def join(c1: CoinDist, c2: CoinDist): CoinsJoinDist = { - //require(isDist(c1) && isDist(c2)) - require( - c1.pHead >= Real(0) && c1.pHead <= Real(1) && - c2.pHead >= Real(0) && c2.pHead <= Real(1) - ) - - CoinsJoinDist( - c1.pHead*c2.pHead, - c1.pHead*(Real(1)-c2.pHead), - (Real(1)-c1.pHead)*c2.pHead, - (Real(1)-c1.pHead)*(Real(1)-c2.pHead) - ) - } ensuring(res => - res.hh >= Real(0) && res.hh <= Real(1) && - res.ht >= Real(0) && res.ht <= Real(1) && - res.th >= Real(0) && res.th <= Real(1) && - res.tt >= Real(0) && res.tt <= Real(1) && - (res.hh + res.ht + res.th + res.tt) == Real(1) - ) - - def firstCoin(dist: CoinsJoinDist): CoinDist = { - require(isDist(dist)) - CoinDist(dist.hh + dist.ht) - } ensuring(res => isDist(res) && res.pTail == (dist.th + dist.tt)) - - def secondCoin(dist: CoinsJoinDist): CoinDist = { - require(isDist(dist)) - CoinDist(dist.hh + dist.th) - } ensuring(res => isDist(res) && res.pTail == (dist.ht + dist.tt)) - - def isIndependent(dist: CoinsJoinDist): Boolean = { - require(isDist(dist)) - join(firstCoin(dist), secondCoin(dist)) == dist - } - - def isEquivalent(dist1: CoinsJoinDist, dist2: CoinsJoinDist): Boolean = { - require(isDist(dist1) && isDist(dist2)) - - (dist1.hh == dist2.hh) && - (dist1.ht == dist2.ht) && - (dist1.th == dist2.th) && - (dist1.tt == dist2.tt) - } - - - //case class CoinCondDist(ifHead: CoinDist, ifTail: CoinDist) - - //def condByFirstCoin(dist: CoinsJoinDist): CoinCondDist = { - // CoinCondDist( - // CoinDist( - // dist.hh*(dist.th + dist.tt), //probability of head if head - // dist.ht*(dist.th + dist.tt) //probability of tail if head - // ), - // CoinDist( - // dist.th*(dist.hh + dist.ht), //probability of head if tail - // dist.tt*(dist.hh + dist.ht) //probability of tail if tail - // ) - // ) - //} - - //def combine(cond: CoinCondDist, dist: CoinDist): CoinsJoinDist = { - // require(isDist(dist) && dist.pHead > 0 && dist.pTail > 0) - - // val hh = cond.ifHead.pHead * dist.pHead - // val ht = cond.ifHead.pTail * dist.pHead - // val th = cond.ifTail.pHead * dist.pTail - // val tt = cond.ifTail.pTail * dist.pTail - // CoinsJoinDist(hh, ht, th, tt) - //} - // - //def condIsSound(dist: CoinsJoinDist): Boolean = { - // require(isDist(dist) && dist.hh > 0 && dist.ht > 0 && dist.th > 0 && dist.tt > 0) - - // val computedDist = combine(condByFirstCoin(dist), firstCoin(dist)) - // isEquivalent(dist, computedDist) - //} holds - - - //should be INVALID - def anyDistributionsNotEquivalent(dist1: CoinsJoinDist, dist2: CoinsJoinDist): Boolean = { - require(isDist(dist1) && isDist(dist2)) - isEquivalent(dist1, dist2) - } holds - - //sum modulo: face is 0, tail is 1 - def sum(coin1: CoinDist, coin2: CoinDist): CoinDist = { - require(isDist(coin1) && isDist(coin2)) - CoinDist(coin1.pHead*coin2.pHead + coin1.pTail*coin2.pTail) - } ensuring(res => isDist(res) && res.pTail == (coin1.pHead*coin2.pTail + coin1.pTail*coin2.pHead)) - - def sum(dist: CoinsJoinDist): CoinDist = { - require(isDist(dist)) - CoinDist(dist.hh + dist.tt) - } ensuring(res => isDist(res) && res.pTail == (dist.ht + dist.th)) - - - - - /*************************************************** - * properties of sum operation * - ***************************************************/ - - def sumIsUniform1(coin1: CoinDist, coin2: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isUniform(coin1) && isUniform(coin2)) - val dist = sum(coin1, coin2) - isUniform(dist) - } holds - - def sumIsUniform2(coin1: CoinDist, coin2: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isUniform(coin1)) - val dist = sum(coin1, coin2) - isUniform(dist) - } holds - - def sumUniform3(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isDist(coin3) && isUniform(coin1)) - val dist = sum(sum(coin1, coin2), coin3) - isUniform(dist) - } holds - - def sumUniformWithIndependence(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && isIndependent(dist) && (isUniform(firstCoin(dist)) || isUniform(secondCoin(dist)))) - val res = sum(dist) - isUniform(res) - } holds - - //should find counterexample, indepenence is required - def sumUniformWithoutIndependence(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && (isUniform(firstCoin(dist)) || isUniform(secondCoin(dist)))) - val res = sum(dist) - isUniform(res) - } holds - - - ////sum of two non-uniform dices is potentially uniform (no result) - def sumNonUniform1(coin1: CoinDist, coin2: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && !isUniform(coin1) && !isUniform(coin2)) - val dist = sum(coin1, coin2) - !isUniform(dist) - } holds - - def sumNonUniform2(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isDist(coin3) && !isUniform(coin1) && !isUniform(coin2) && !isUniform(coin3)) - val dist = sum(sum(coin1, coin2), coin3) - !isUniform(dist) - } holds - - def sumNonUniformWithIndependence(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && isIndependent(dist) && !isUniform(firstCoin(dist)) && !isUniform(secondCoin(dist))) - val res = sum(dist) - !isUniform(res) - } holds - - //independence is required - def sumNonUniformWithoutIndependence(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && !isUniform(firstCoin(dist)) && !isUniform(secondCoin(dist))) - val res = sum(dist) - !isUniform(res) - } holds - - - def sumIsCommutative(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2)) - sum(coin1, coin2) == sum(coin2, coin1) - } holds - - def sumIsAssociative(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isDist(coin3)) - sum(sum(coin1, coin2), coin3) == sum(coin1, sum(coin2, coin3)) - } holds - -} diff --git a/testcases/proof/proba/coins-simple.smt2 b/testcases/proof/proba/coins-simple.smt2 deleted file mode 100644 index 6d9fcddb3b5c45614357fe18cc6b947ad66c458a..0000000000000000000000000000000000000000 --- a/testcases/proof/proba/coins-simple.smt2 +++ /dev/null @@ -1,23 +0,0 @@ -(declare-fun c1 () Real) -(declare-fun c2 () Real) -(declare-fun hh () Real) -(declare-fun ht () Real) -(declare-fun th () Real) -(declare-fun tt () Real) - -(assert (and (>= c1 0) (<= c1 1) (>= c2 0) (<= c2 1))) - -(assert (= hh (* c1 c2))) -(assert (= ht (* c1 (- 1 c2)))) -(assert (= th (* (- 1 c1) c2))) -(assert (= tt (* (- 1 c1) (- 1 c2)))) - -(assert (not - (and (>= hh 0) (<= hh 1) - (>= ht 0) (<= ht 1) - (>= th 0) (<= th 1) - (>= tt 0) (<= tt 1) - (= (+ hh ht th tt) 1)))) - - -(check-sat) diff --git a/testcases/proof/proba/coins.smt2 b/testcases/proof/proba/coins.smt2 deleted file mode 100644 index d6a7aeb515ac6b0002a18116fc286e70b12dbccb..0000000000000000000000000000000000000000 --- a/testcases/proof/proba/coins.smt2 +++ /dev/null @@ -1,31 +0,0 @@ -(declare-fun start!1 () Bool) - -(assert start!1) - -(declare-datatypes () ( (CoinDist!2 (CoinDist!3 (pHead!1 Real))) )) - -(declare-fun c1!0 () CoinDist!2) - -(declare-fun c2!0 () CoinDist!2) - -(declare-datatypes () ( (CoinsJoinDist!1 (CoinsJoinDist!2 (hh!1 Real) (ht!1 Real) (th!1 Real) (tt!1 Real))) )) - -(declare-fun lt!2 () CoinsJoinDist!1) - -(declare-fun isDist!1 (CoinsJoinDist!1) Bool) - -(assert (and (>= (pHead!1 c1!0) 0) (<= (pHead!1 c1!0) 1) (>= (pHead!1 c2!0) 0) (<= (pHead!1 c2!0) 1))) - -(assert (= lt!2 (CoinsJoinDist!2 (* (pHead!1 c1!0) (pHead!1 c2!0)) (* (pHead!1 c1!0) (- 1 (pHead!1 c2!0))) (* (- 1 (pHead!1 c1!0)) (pHead!1 c2!0)) (* (- 1 (pHead!1 c1!0)) (- 1 (pHead!1 c2!0)))))) - - -(assert (not - (and (>= (hh!1 lt!2) 0) (<= (hh!1 lt!2) 1) - (>= (ht!1 lt!2) 0) (<= (ht!1 lt!2) 1) - (>= (th!1 lt!2) 0) (<= (th!1 lt!2) 1) - (>= (tt!1 lt!2) 0) (<= (tt!1 lt!2) 1) - (= (+ (hh!1 lt!2) (ht!1 lt!2) (th!1 lt!2) (tt!1 lt!2)) 1)))) - - -(check-sat) - diff --git a/testcases/proof/proba/ints/Coins.scala b/testcases/proof/proba/ints/Coins.scala deleted file mode 100644 index ff8bf91222b6493591be4e279a6069218c781d2f..0000000000000000000000000000000000000000 --- a/testcases/proof/proba/ints/Coins.scala +++ /dev/null @@ -1,185 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Coins { - - /* - * number of outcomes for each face - */ - case class CoinDist(pHead: BigInt, pTail: BigInt) - - case class CoinsJoinDist(hh: BigInt, ht: BigInt, th: BigInt, tt: BigInt) - - def isUniform(dist: CoinDist): Boolean = { - require(isDist(dist)) - dist.pHead == dist.pTail - } - - def isDist(dist: CoinDist): Boolean = - dist.pHead >= 0 && dist.pTail >= 0 && (dist.pHead > 0 || dist.pTail > 0) - - def isDist(dist: CoinsJoinDist): Boolean = - dist.hh >= 0 && dist.ht >= 0 && dist.th >= 0 && dist.tt >= 0 && - (dist.hh > 0 || dist.ht > 0 || dist.th > 0 || dist.tt > 0) - - def join(c1: CoinDist, c2: CoinDist): CoinsJoinDist = - CoinsJoinDist( - c1.pHead*c2.pHead, - c1.pHead*c2.pTail, - c1.pTail*c2.pHead, - c1.pTail*c2.pTail) - - def firstCoin(dist: CoinsJoinDist): CoinDist = - CoinDist(dist.hh + dist.ht, dist.th + dist.tt) - - def secondCoin(dist: CoinsJoinDist): CoinDist = - CoinDist(dist.hh + dist.th, dist.ht + dist.tt) - - def isIndependent(dist: CoinsJoinDist): Boolean = - join(firstCoin(dist), secondCoin(dist)) == dist - - def isEquivalent(dist1: CoinsJoinDist, dist2: CoinsJoinDist): Boolean = { - require(isDist(dist1) && dist1.hh > 0 && isDist(dist2) && dist2.hh > 0) - - dist1.hh*dist2.hh == dist2.hh*dist1.hh && - dist1.ht*dist2.hh == dist2.ht*dist1.hh && - dist1.th*dist2.hh == dist2.th*dist1.hh && - dist1.tt*dist2.hh == dist2.tt*dist1.hh - } - - - case class CoinCondDist(ifHead: CoinDist, ifTail: CoinDist) - - def condByFirstCoin(dist: CoinsJoinDist): CoinCondDist = { - CoinCondDist( - CoinDist( - dist.hh*(dist.th + dist.tt), //probability of head if head - dist.ht*(dist.th + dist.tt) //probability of tail if head - ), - CoinDist( - dist.th*(dist.hh + dist.ht), //probability of head if tail - dist.tt*(dist.hh + dist.ht) //probability of tail if tail - ) - ) - } - - def combine(cond: CoinCondDist, dist: CoinDist): CoinsJoinDist = { - require(isDist(dist) && dist.pHead > 0 && dist.pTail > 0) - - val hh = cond.ifHead.pHead * dist.pHead - val ht = cond.ifHead.pTail * dist.pHead - val th = cond.ifTail.pHead * dist.pTail - val tt = cond.ifTail.pTail * dist.pTail - CoinsJoinDist(hh, ht, th, tt) - } - - def condIsSound(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && dist.hh > 0 && dist.ht > 0 && dist.th > 0 && dist.tt > 0) - - val computedDist = combine(condByFirstCoin(dist), firstCoin(dist)) - isEquivalent(dist, computedDist) - } holds - - - //should be INVALID - def anyDistributionsNotEquivalent(dist1: CoinsJoinDist, dist2: CoinsJoinDist): Boolean = { - require(isDist(dist1) && isDist(dist2) && dist1.hh > 0 && dist2.hh > 0) - isEquivalent(dist1, dist2) - } holds - - //sum modulo: face is 0, tail is 1 - def sum(coin1: CoinDist, coin2: CoinDist): CoinDist = { - require(isDist(coin1) && isDist(coin2)) - CoinDist( - coin1.pHead*coin2.pHead + coin1.pTail*coin2.pTail, - coin1.pHead*coin2.pTail + coin1.pTail*coin2.pHead - ) - } - - def sum(dist: CoinsJoinDist): CoinDist = { - require(isDist(dist)) - CoinDist( - dist.hh + dist.tt, - dist.ht + dist.th - ) - } - - - - - - - /*************************************************** - * properties of sum operation * - ***************************************************/ - - def sumIsUniform1(coin1: CoinDist, coin2: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isUniform(coin1) && isUniform(coin2)) - val dist = sum(coin1, coin2) - isUniform(dist) - } holds - - def sumIsUniform2(coin1: CoinDist, coin2: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isUniform(coin1)) - val dist = sum(coin1, coin2) - isUniform(dist) - } holds - - def sumUniform3(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isDist(coin3) && isUniform(coin1)) - val dist = sum(sum(coin1, coin2), coin3) - isUniform(dist) - } holds - - def sumUniformWithIndependence(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && isIndependent(dist) && (isUniform(firstCoin(dist)) || isUniform(secondCoin(dist)))) - val res = sum(dist) - isUniform(res) - } holds - - //should find counterexample, indepenence is required - def sumUniformWithoutIndependence(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && (isUniform(firstCoin(dist)) || isUniform(secondCoin(dist)))) - val res = sum(dist) - isUniform(res) - } holds - - - //sum of two non-uniform dices is potentially uniform (no result) - def sumNonUniform1(coin1: CoinDist, coin2: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && !isUniform(coin1) && !isUniform(coin2)) - val dist = sum(coin1, coin2) - !isUniform(dist) - } holds - - def sumNonUniform2(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isDist(coin3) && !isUniform(coin1) && !isUniform(coin2) && !isUniform(coin3)) - val dist = sum(sum(coin1, coin2), coin3) - !isUniform(dist) - } //holds - - def sumNonUniformWithIndependence(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && isIndependent(dist) && !isUniform(firstCoin(dist)) && !isUniform(secondCoin(dist))) - val res = sum(dist) - !isUniform(res) - } holds - - //independence is required - def sumNonUniformWithoutIndependence(dist: CoinsJoinDist): Boolean = { - require(isDist(dist) && !isUniform(firstCoin(dist)) && !isUniform(secondCoin(dist))) - val res = sum(dist) - !isUniform(res) - } holds - - - def sumIsCommutative(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2)) - sum(coin1, coin2) == sum(coin2, coin1) - } holds - - def sumIsAssociative(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - require(isDist(coin1) && isDist(coin2) && isDist(coin3)) - sum(sum(coin1, coin2), coin3) == sum(coin1, sum(coin2, coin3)) - } //holds - -} diff --git a/testcases/proof/proba/ints/Dices.scala b/testcases/proof/proba/ints/Dices.scala deleted file mode 100644 index d7ac55f5645f0e6ad23343d1a0186679f349c515..0000000000000000000000000000000000000000 --- a/testcases/proof/proba/ints/Dices.scala +++ /dev/null @@ -1,94 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Dices { - - /* - * number of outcomes for each face of a dice - */ - case class DiceDist(p1: BigInt, p2: BigInt, p3: BigInt, p4: BigInt, p5: BigInt, p6: BigInt) - - case class SumDist(p1: BigInt, p2: BigInt, p3: BigInt, p4: BigInt, p5: BigInt, p6: BigInt, - p7: BigInt, p8: BigInt, p9: BigInt, p10: BigInt, p11: BigInt, p12: BigInt) - - def isUniform(dist: DiceDist): Boolean = dist.p1 == dist.p2 && dist.p2 == dist.p3 && dist.p3 == dist.p4 && - dist.p4 == dist.p5 && dist.p5 == dist.p6 - - def isDist(dice: DiceDist): Boolean = - dice.p1 >= 0 && dice.p2 >= 0 && dice.p3 >= 0 && dice.p4 >= 0 && dice.p5 >= 0 && dice.p6 >= 0 && - (dice.p1 > 0 || dice.p2 > 0 || dice.p3 > 0 || dice.p4 > 0 || dice.p5 > 0 || dice.p6 > 0) - - def sum(dice1: DiceDist, dice2: DiceDist): SumDist = { - require(isDist(dice1) && isDist(dice2)) - SumDist(0, //1 - dice1.p1*dice2.p1, //2 - dice1.p1*dice2.p2 + dice1.p2*dice2.p1, //3 - dice1.p1*dice2.p3 + dice1.p2*dice2.p2 + dice1.p3*dice2.p1, //4 - dice1.p1*dice2.p4 + dice1.p2*dice2.p3 + dice1.p3*dice2.p2 + dice1.p4*dice2.p1, //5 - dice1.p1*dice2.p5 + dice1.p2*dice2.p4 + dice1.p3*dice2.p3 + - dice1.p4*dice2.p2 + dice1.p5*dice2.p1, //6 - dice1.p1*dice2.p6 + dice1.p2*dice2.p5 + dice1.p3*dice2.p4 + - dice1.p4*dice2.p3 + dice1.p5*dice2.p2 + dice1.p6*dice2.p1, //7 - dice1.p2*dice2.p6 + dice1.p3*dice2.p5 + dice1.p4*dice2.p4 + - dice1.p5*dice2.p3 + dice1.p6*dice2.p2, //8 - dice1.p3*dice2.p6 + dice1.p4*dice2.p5 + dice1.p5*dice2.p4 + dice1.p6*dice2.p3, //9 - dice1.p4*dice2.p6 + dice1.p5*dice2.p5 + dice1.p6*dice2.p4, //10 - dice1.p5*dice2.p6 + dice1.p6*dice2.p5, //11 - dice1.p6*dice2.p6 //12 - ) - } - - //distribution of the addition modulo 6 of two dices - def sumMod(dice1: DiceDist, dice2: DiceDist): DiceDist = { - require(isDist(dice1) && isDist(dice2)) - DiceDist( - dice1.p1*dice2.p6 + dice1.p2*dice2.p5 + dice1.p3*dice2.p4 + dice1.p4*dice2.p3 + dice1.p5*dice2.p2 + dice1.p6*dice2.p1, //1 - dice1.p1*dice2.p1 + dice1.p2*dice2.p6 + dice1.p3*dice2.p5 + dice1.p4*dice2.p4 + dice1.p5*dice2.p3 + dice1.p6*dice2.p2, //2 - dice1.p1*dice2.p2 + dice1.p2*dice2.p1 + dice1.p3*dice2.p6 + dice1.p4*dice2.p5 + dice1.p5*dice2.p4 + dice1.p6*dice2.p3, //3 - dice1.p1*dice2.p3 + dice1.p2*dice2.p2 + dice1.p3*dice2.p1 + dice1.p4*dice2.p6 + dice1.p5*dice2.p5 + dice1.p6*dice2.p4, //4 - dice1.p1*dice2.p4 + dice1.p2*dice2.p3 + dice1.p3*dice2.p2 + dice1.p4*dice2.p1 + dice1.p5*dice2.p6 + dice1.p6*dice2.p5, //5 - dice1.p1*dice2.p5 + dice1.p2*dice2.p4 + dice1.p3*dice2.p3 + dice1.p4*dice2.p2 + dice1.p5*dice2.p1 + dice1.p6*dice2.p6 //6 - ) - } - - def uniformSumProperties1(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && isUniform(dice1) && isUniform(dice2)) - val dist = sum(dice1, dice2) - - dist.p2 == dist.p12 && - dist.p3 == dist.p11 && - dist.p4 == dist.p10 && - dist.p5 == dist.p9 && - dist.p6 == dist.p8 - } holds - - def uniformSumMostLikelyOutcome(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && isUniform(dice1) && isUniform(dice2)) - val dist = sum(dice1, dice2) - - dist.p7 > dist.p1 && dist.p7 > dist.p2 && dist.p7 > dist.p3 && - dist.p7 > dist.p4 && dist.p7 > dist.p5 && dist.p7 > dist.p6 && - dist.p7 >= dist.p7 && dist.p7 > dist.p8 && dist.p7 > dist.p9 && - dist.p7 > dist.p10 && dist.p7 > dist.p11 && dist.p7 > dist.p12 - } holds - - def sumModIsUniform1(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && isUniform(dice1) && isUniform(dice2)) - val dist = sumMod(dice1, dice2) - isUniform(dist) - } holds - - def sumModIsUniform2(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && isUniform(dice1)) - val dist = sumMod(dice1, dice2) - isUniform(dist) - } holds - - //sum of two non-uniform dices is potentially uniform (no result) - def sumModNonUniform(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && !isUniform(dice1) && !isUniform(dice2)) - val dist = sumMod(dice1, dice2) - !isUniform(dist) - } holds - -} diff --git a/testcases/proof/proba/ints/FiniteDistributions.scala b/testcases/proof/proba/ints/FiniteDistributions.scala deleted file mode 100644 index 81b4ea581135304708acfd4105e08dd431760be0..0000000000000000000000000000000000000000 --- a/testcases/proof/proba/ints/FiniteDistributions.scala +++ /dev/null @@ -1,79 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.collection._ - -object FiniteDistributions { - - /* - * number of outcomes for each index (ps(0) outcomes of value 0, ps(1) outcomes of value 1). - * Sort of generalization of a dice distribution - */ - //case class FiniteDist(ps: List[BigInt]) - - case class FiniteDist(domain: List[BigInt], outcomes: Map[BigInt, BigInt]) - - def isUniform(dist: FiniteDist): Boolean = dist.domain match { - case Nil() => true - case Cons(x, Nil()) => true - case Cons(x, rest@Cons(y, _)) => outcomes(x) == outcomes(y) && isUniform(FiniteDist(rest, dist.domain)) - } - - def isDist(dist: FiniteDist): Boolean = { - - def allPos(dist: FiniteDist): Boolean = dist.ps match { - case Cons(x, Nil()) => x >= 0 - case Cons(x, xs) => x >= 0 && isDist(xs) - } - def atLeastOne(dist: FiniteDist): Boolean = dist.ps match { - case Cons(x, xs) => x > 0 || atLeastOne(xs) - case Nil => false - } - - allPos(dist) && atLeastOne(dist) - } - - def probaHead(dist1: FiniteDist, dist2: FiniteDist): BigInt = { - require(isDist(dist1) && isDist(dist2) && dist1.size == dist2.size) - if(dist1.ps.isEmpty) 0 else dist1.head*dist2.last + probaHead(dist1.tail, dist2.init) - } - - def sumMod(dist1: FiniteDist, dist2: FiniteDist): FiniteDist = { - require(isDist(dist1) && isDist(dist2) && dist1.size == dist2.size) - - def - rotate(1) - } - - def uniformSumProperties1(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && isUniform(dice1) && isUniform(dice2)) - val dist = sum(dice1, dice2) - - dist.p2 == dist.p12 && - dist.p3 == dist.p11 && - dist.p4 == dist.p10 && - dist.p5 == dist.p9 && - dist.p6 == dist.p8 - } holds - - def uniformSumMostLikelyOutcome(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && isUniform(dice1) && isUniform(dice2)) - val dist = sum(dice1, dice2) - - dist.p7 > dist.p1 && dist.p7 > dist.p2 && dist.p7 > dist.p3 && - dist.p7 > dist.p4 && dist.p7 > dist.p5 && dist.p7 > dist.p6 && - dist.p7 >= dist.p7 && dist.p7 > dist.p8 && dist.p7 > dist.p9 && - dist.p7 > dist.p10 && dist.p7 > dist.p11 && dist.p7 > dist.p12 - } holds - - def sumModIsUniform1(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && isUniform(dice1) && isUniform(dice2)) - val dist = sumMod(dice1, dice2) - isUniform(dist) - } holds - - def sumModIsUniform2(dice1: DiceDist, dice2: DiceDist): Boolean = { - require(isDist(dice1) && isDist(dice2) && isUniform(dice1)) - val dist = sumMod(dice1, dice2) - isUniform(dist) - } holds -} diff --git a/testcases/proof/proba/ints/RandomVariables.scala b/testcases/proof/proba/ints/RandomVariables.scala deleted file mode 100644 index 74899bb46648bd3141ec2cd33c99edc19c389247..0000000000000000000000000000000000000000 --- a/testcases/proof/proba/ints/RandomVariables.scala +++ /dev/null @@ -1,8 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object RandomVariables { - - //case class RandomVariable(p: (BigInt) => Real, -} - diff --git a/testcases/proof/proba/rationals/Coins.scala b/testcases/proof/proba/rationals/Coins.scala deleted file mode 100644 index f7f5b6f9a73ec07dddfad378d70139bb7fdb4fe3..0000000000000000000000000000000000000000 --- a/testcases/proof/proba/rationals/Coins.scala +++ /dev/null @@ -1,188 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Coins { - - case class CoinDist(pHead: Rational) { - def pTail: Rational = Rational(1) - pHead - } - - def isDist(dist: CoinDist): Boolean = - dist.pHead.isRational && dist.pHead >= Rational(0) && dist.pHead <= Rational(1) - - - case class CoinsJoinDist(hh: Rational, ht: Rational, th: Rational, tt: Rational) - - def isDist(dist: CoinsJoinDist): Boolean = - dist.hh.isRational && dist.hh >= Rational(0) && dist.hh <= Rational(1) && - dist.ht.isRational && dist.ht >= Rational(0) && dist.ht <= Rational(1) && - dist.th.isRational && dist.th >= Rational(0) && dist.th <= Rational(1) && - dist.tt.isRational && dist.tt >= Rational(0) && dist.tt <= Rational(1) && - (dist.hh + dist.ht + dist.th + dist.tt) ~ Rational(1) - - - def isUniform(dist: CoinDist): Boolean = { - require(isDist(dist)) - dist.pHead ~ Rational(1, 2) - } - - - def join(c1: CoinDist, c2: CoinDist): CoinsJoinDist = - CoinsJoinDist( - c1.pHead*c2.pHead, - c1.pHead*c2.pTail, - c1.pTail*c2.pHead, - c1.pTail*c2.pTail) - - def firstCoin(dist: CoinsJoinDist): CoinDist = { - require(isDist(dist)) - CoinDist(dist.hh + dist.ht) - } ensuring(res => res.pTail ~ (dist.th + dist.tt)) - - def secondCoin(dist: CoinsJoinDist): CoinDist = { - require(isDist(dist)) - CoinDist(dist.hh + dist.th) - } ensuring(res => res.pTail ~ (dist.ht + dist.tt)) - - def isIndependent(dist: CoinsJoinDist): Boolean = { - require(isDist(dist)) - join(firstCoin(dist), secondCoin(dist)) == dist - } - - def isEquivalent(dist1: CoinsJoinDist, dist2: CoinsJoinDist): Boolean = { - require(isDist(dist1) && isDist(dist2)) - - (dist1.hh ~ dist2.hh) && - (dist1.ht ~ dist2.ht) && - (dist1.th ~ dist2.th) && - (dist1.tt ~ dist2.tt) - } - - - //case class CoinCondDist(ifHead: CoinDist, ifTail: CoinDist) - - //def condByFirstCoin(dist: CoinsJoinDist): CoinCondDist = { - // CoinCondDist( - // CoinDist( - // dist.hh*(dist.th + dist.tt), //probability of head if head - // dist.ht*(dist.th + dist.tt) //probability of tail if head - // ), - // CoinDist( - // dist.th*(dist.hh + dist.ht), //probability of head if tail - // dist.tt*(dist.hh + dist.ht) //probability of tail if tail - // ) - // ) - //} - - //def combine(cond: CoinCondDist, dist: CoinDist): CoinsJoinDist = { - // require(isDist(dist) && dist.pHead > 0 && dist.pTail > 0) - - // val hh = cond.ifHead.pHead * dist.pHead - // val ht = cond.ifHead.pTail * dist.pHead - // val th = cond.ifTail.pHead * dist.pTail - // val tt = cond.ifTail.pTail * dist.pTail - // CoinsJoinDist(hh, ht, th, tt) - //} - // - //def condIsSound(dist: CoinsJoinDist): Boolean = { - // require(isDist(dist) && dist.hh > 0 && dist.ht > 0 && dist.th > 0 && dist.tt > 0) - - // val computedDist = combine(condByFirstCoin(dist), firstCoin(dist)) - // isEquivalent(dist, computedDist) - //} holds - - - //should be INVALID - def anyDistributionsNotEquivalent(dist1: CoinsJoinDist, dist2: CoinsJoinDist): Boolean = { - require(isDist(dist1) && isDist(dist2)) - isEquivalent(dist1, dist2) - } holds - - //sum modulo: face is 0, tail is 1 - def sum(coin1: CoinDist, coin2: CoinDist): CoinDist = { - require(isDist(coin1) && isDist(coin2)) - CoinDist(coin1.pHead*coin2.pHead + coin1.pTail*coin2.pTail) - } ensuring(res => res.pTail ~ (coin1.pHead*coin2.pTail + coin1.pTail*coin2.pHead)) - - def sum(dist: CoinsJoinDist): CoinDist = { - require(isDist(dist)) - CoinDist(dist.hh + dist.tt) - } ensuring(res => res.pTail ~ (dist.ht + dist.th)) - - - - - /*************************************************** - * properties of sum operation * - ***************************************************/ - - //def sumIsUniform1(coin1: CoinDist, coin2: CoinDist): Boolean = { - // require(isDist(coin1) && isDist(coin2) && isUniform(coin1) && isUniform(coin2)) - // val dist = sum(coin1, coin2) - // isUniform(dist) - //} holds - - //def sumIsUniform2(coin1: CoinDist, coin2: CoinDist): Boolean = { - // require(isDist(coin1) && isDist(coin2) && isUniform(coin1)) - // val dist = sum(coin1, coin2) - // isUniform(dist) - //} holds - - //def sumUniform3(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - // require(isDist(coin1) && isDist(coin2) && isDist(coin3) && isUniform(coin1)) - // val dist = sum(sum(coin1, coin2), coin3) - // isUniform(dist) - //} holds - - //def sumUniformWithIndependence(dist: CoinsJoinDist): Boolean = { - // require(isDist(dist) && isIndependent(dist) && (isUniform(firstCoin(dist)) || isUniform(secondCoin(dist)))) - // val res = sum(dist) - // isUniform(res) - //} holds - - ////should find counterexample, indepenence is required - //def sumUniformWithoutIndependence(dist: CoinsJoinDist): Boolean = { - // require(isDist(dist) && (isUniform(firstCoin(dist)) || isUniform(secondCoin(dist)))) - // val res = sum(dist) - // isUniform(res) - //} holds - - - ////sum of two non-uniform dices is potentially uniform (no result) - //def sumNonUniform1(coin1: CoinDist, coin2: CoinDist): Boolean = { - // require(isDist(coin1) && isDist(coin2) && !isUniform(coin1) && !isUniform(coin2)) - // val dist = sum(coin1, coin2) - // !isUniform(dist) - //} holds - - //def sumNonUniform2(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - // require(isDist(coin1) && isDist(coin2) && isDist(coin3) && !isUniform(coin1) && !isUniform(coin2) && !isUniform(coin3)) - // val dist = sum(sum(coin1, coin2), coin3) - // !isUniform(dist) - //} //holds - - //def sumNonUniformWithIndependence(dist: CoinsJoinDist): Boolean = { - // require(isDist(dist) && isIndependent(dist) && !isUniform(firstCoin(dist)) && !isUniform(secondCoin(dist))) - // val res = sum(dist) - // !isUniform(res) - //} holds - - ////independence is required - //def sumNonUniformWithoutIndependence(dist: CoinsJoinDist): Boolean = { - // require(isDist(dist) && !isUniform(firstCoin(dist)) && !isUniform(secondCoin(dist))) - // val res = sum(dist) - // !isUniform(res) - //} holds - - - //def sumIsCommutative(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - // require(isDist(coin1) && isDist(coin2)) - // sum(coin1, coin2) == sum(coin2, coin1) - //} holds - - //def sumIsAssociative(coin1: CoinDist, coin2: CoinDist, coin3: CoinDist): Boolean = { - // require(isDist(coin1) && isDist(coin2) && isDist(coin3)) - // sum(sum(coin1, coin2), coin3) == sum(coin1, sum(coin2, coin3)) - //} //holds - -} diff --git a/testcases/repair/Compiler/Compiler.scala b/testcases/repair/Compiler/Compiler.scala deleted file mode 100644 index 4b77a547a378b84aab4378459a5fb5b91f83d8a3..0000000000000000000000000000000000000000 --- a/testcases/repair/Compiler/Compiler.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/repair/Compiler/Compiler1.scala b/testcases/repair/Compiler/Compiler1.scala deleted file mode 100644 index b1f9bc859cccdc53162b29d3480e5c4519e7cd96..0000000000000000000000000000000000000000 --- a/testcases/repair/Compiler/Compiler1.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Neg(desugar(lhs)) // FIXME - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/repair/Compiler/Compiler2.scala b/testcases/repair/Compiler/Compiler2.scala deleted file mode 100644 index 1950b679a6d5727bec02a6fe4bf457f1260bc1c7..0000000000000000000000000000000000000000 --- a/testcases/repair/Compiler/Compiler2.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Literal(0)// FIXME: Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/repair/Compiler/Compiler3.scala b/testcases/repair/Compiler/Compiler3.scala deleted file mode 100644 index 367e43b9fcf8e1579dd91ed08a13506184a05532..0000000000000000000000000000000000000000 --- a/testcases/repair/Compiler/Compiler3.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(els), desugar(thn)) // FIXME - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/repair/Compiler/Compiler4.scala b/testcases/repair/Compiler/Compiler4.scala deleted file mode 100644 index 6323496df930172e84b71bf5c55006eb33767c6a..0000000000000000000000000000000000000000 --- a/testcases/repair/Compiler/Compiler4.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(1), Literal(1)) // FIXME should be 0 - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/repair/Compiler/Compiler5.scala b/testcases/repair/Compiler/Compiler5.scala deleted file mode 100644 index fdefc6b31d8edabc379968c101b3db2d8513a007..0000000000000000000000000000000000000000 --- a/testcases/repair/Compiler/Compiler5.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(1), Literal(1)) // FIMXE - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(els), desugar(thn)) // FIXME - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/repair/Compiler/Compiler6.scala b/testcases/repair/Compiler/Compiler6.scala deleted file mode 100644 index dc633b1ae3d4d929e262ea44d6466a41ee4babf0..0000000000000000000000000000000000000000 --- a/testcases/repair/Compiler/Compiler6.scala +++ /dev/null @@ -1,214 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a-b) // FIXME - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) && ((e, res) passes { - case Plus(IntLiteral(BigInt(0)), IntLiteral(a)) => IntLiteral(a) - }) - } -} diff --git a/testcases/repair/DaysToYears/DaysToYears.scala b/testcases/repair/DaysToYears/DaysToYears.scala deleted file mode 100644 index 3a71a49602ff9d818df2cf2e1d2476a78f9e0b3a..0000000000000000000000000000000000000000 --- a/testcases/repair/DaysToYears/DaysToYears.scala +++ /dev/null @@ -1,38 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object DaysToYears { - val base : Int = 1980 - - def isLeapYear(y : Int): Boolean = y % 4 == 0 - - def daysToYears(days : Int): Int = { - require(days > 0) - daysToYears1(base, days)._1 - } - - def daysToYears1(year : Int, days : Int): (Int, Int) = { - require(year >= base && days > 0) - if (days > 366 && isLeapYear(year)) - daysToYears1(year + 1, days - 366) - else if (days > 365 && !isLeapYear(year)) - daysToYears1(year + 1, days - 365) - else (year, days) - } ensuring { res => - res._2 <= 366 && - res._2 > 0 && - res._1 >= base && - (((year,days), res) passes { - case (1980, 366 ) => (1980, 366) - case (1980, 1000) => (1982, 269) - }) - } - - @ignore - def main(args : Array[String]) = { - println(daysToYears1(base, 10593 )) - println(daysToYears1(base, 366 )) - println(daysToYears1(base, 1000 )) - } -} - diff --git a/testcases/repair/DaysToYears/DaysToYears1.scala b/testcases/repair/DaysToYears/DaysToYears1.scala deleted file mode 100644 index 1ef2d337989c7dc1a718637777d6e97726d7a276..0000000000000000000000000000000000000000 --- a/testcases/repair/DaysToYears/DaysToYears1.scala +++ /dev/null @@ -1,39 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object DaysToYears { - val base : Int = 1980 - - def isLeapYear(y : Int): Boolean = y % 4 == 0 - - def daysToYears(days : Int): Int = { - require(days > 0) - daysToYears1(base, days)._1 - } - - def daysToYears1(year : Int, days : Int): (Int, Int) = { - require(year >= base && days > 0) - if (days > 366 && isLeapYear(year)) - daysToYears1(year + 1, days - 366) - else if (days > 365 && !isLeapYear(year)) - daysToYears1(year, days - 365) // FIXME forgot +1 - else (year, days) - } ensuring { res => - res._2 <= 366 && - res._2 > 0 && - res._1 >= base && - (((year,days), res) passes { - case (1999, 14 ) => (1999, 14) - case (1980, 366) => (1980, 366) - case (1981, 366) => (1982, 1) - }) - } - - @ignore - def main(args : Array[String]) = { - println(daysToYears1(base, 10593 )) - println(daysToYears1(base, 366 )) - println(daysToYears1(base, 1000 )) - } -} - diff --git a/testcases/repair/DaysToYears/DaysToYears2.scala b/testcases/repair/DaysToYears/DaysToYears2.scala deleted file mode 100644 index 40396f05c6c3e40c4cfd0beccee02ed7d4c59553..0000000000000000000000000000000000000000 --- a/testcases/repair/DaysToYears/DaysToYears2.scala +++ /dev/null @@ -1,38 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object DaysToYears { - val base : Int = 1980 - - def isLeapYear(y : Int): Boolean = y % 4 == 0 - - def daysToYears(days : Int): Int = { - require(days > 0) - daysToYears1(base, days)._1 - } - - def daysToYears1(year : Int, days : Int): (Int, Int) = { - require(year >= base && days > 0) - if (days > 366 && isLeapYear(year)) - daysToYears1(year + 1, days - 366) // TODO this branch cannot be solved although it is correct because it depends on the erroneous branch - else if (days > 365 && !isLeapYear(year)) - daysToYears1(year + 1, days - 365) - else (year + 1, days) // FIXME +1 - } ensuring { res => - res._2 <= 366 && - res._2 > 0 && - res._1 >= base && - (((year,days), res) passes { - case (1980, 366 ) => (1980, 366) - case (1980, 1000) => (1982, 269) - }) - } - - @ignore - def main(args : Array[String]) = { - println(daysToYears1(base, 10593 )) - println(daysToYears1(base, 366 )) - println(daysToYears1(base, 1000 )) - } -} - diff --git a/testcases/repair/Desugar/Desugar.scala b/testcases/repair/Desugar/Desugar.scala deleted file mode 100644 index 19cd3305ab3e7a63fbb4f35c924819a143838aa3..0000000000000000000000000000000000000000 --- a/testcases/repair/Desugar/Desugar.scala +++ /dev/null @@ -1,172 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : Int = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean) = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : Int = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else 0 - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else 1 - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : Int) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : Int = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} diff --git a/testcases/repair/Desugar/Desugar1.scala b/testcases/repair/Desugar/Desugar1.scala deleted file mode 100644 index 18ba8dadf874375eb4615241cf2fe165558c66f9..0000000000000000000000000000000000000000 --- a/testcases/repair/Desugar/Desugar1.scala +++ /dev/null @@ -1,176 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : Int = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean) = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : Int = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else 0 - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else 1 - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : Int) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Neg(desugar(lhs)) // FIXME: Complete nonsense - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - ((e, res) passes { - case Trees.Plus(Trees.IntLiteral(i), Trees.Minus(Trees.IntLiteral(j), Trees.IntLiteral(42))) => - Plus(Literal(i), Plus(Literal(j), Neg(Literal(42)))) - }) && - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : Int = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} diff --git a/testcases/repair/Desugar/Desugar2.scala b/testcases/repair/Desugar/Desugar2.scala deleted file mode 100644 index a068dadcba0e35683147b8141bb53e38eb01f7a4..0000000000000000000000000000000000000000 --- a/testcases/repair/Desugar/Desugar2.scala +++ /dev/null @@ -1,175 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : Int = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean) = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : Int = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else 0 - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else 1 - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : Int) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Literal(0)//Plus(desugar(lhs), desugar(rhs)) // FIXME forgot Neg - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) && ((e,res) passes { - case Trees.Minus(Trees.IntLiteral(42), Trees.IntLiteral(i)) => - Plus(Literal(42), Neg(Literal(i))) - }) - } - - def sem(e : SimpleE) : Int = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} diff --git a/testcases/repair/Desugar/Desugar3.scala b/testcases/repair/Desugar/Desugar3.scala deleted file mode 100644 index f1f23df5dc5eae5248b14c468297363ee1b0fdb7..0000000000000000000000000000000000000000 --- a/testcases/repair/Desugar/Desugar3.scala +++ /dev/null @@ -1,174 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : Int = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean) = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : Int = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else 0 - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else 1 - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : Int) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => - // FIXME switched the branches - Ite(desugar(cond), desugar(els), desugar(thn)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : Int = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} diff --git a/testcases/repair/Desugar/Desugar4.scala b/testcases/repair/Desugar/Desugar4.scala deleted file mode 100644 index 9f6ac963a2d04e47b66e4eadb172dc19abb4094a..0000000000000000000000000000000000000000 --- a/testcases/repair/Desugar/Desugar4.scala +++ /dev/null @@ -1,172 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : Int = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean) = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : Int = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else 0 - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else 1 - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : Int) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(1), Literal(1)) // FIXME else should be 0 - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : Int = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} diff --git a/testcases/repair/Heap/Heap.scala b/testcases/repair/Heap/Heap.scala deleted file mode 100644 index 7b70693c77dcee60b8998b7b76ab9d3c3acddc26..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value: BigInt, left: Heap, right: Heap) extends Heap - - def max(i1: BigInt, i2: BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap1.scala b/testcases/repair/Heap/Heap1.scala deleted file mode 100644 index 9a4e074bb20f560c4dc6dc71750acccc545a942e..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap1.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - //if(v1 >= v2) // FIXME - makeN(v1, l1, merge(r1, h2)) - //else - // makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap10.scala b/testcases/repair/Heap/Heap10.scala deleted file mode 100644 index c27bc93507b847bb6af22200fc2b3cf3e13f0511..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap10.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h1 // FIXME: swapped these cases - case (_, Leaf()) => h2 // FIXME - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap2.scala b/testcases/repair/Heap/Heap2.scala deleted file mode 100644 index a975f5c65e73c44c69adfa00348ee6b5c775e30e..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap2.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - Node(v1, l1, merge(r1, h2)) // FIXME should use makeN - else - Node(v2, l2, merge(h1, r2)) // FIXME here also - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap3.scala b/testcases/repair/Heap/Heap3.scala deleted file mode 100644 index 8e3013399534679c58221bd4d5547a14a76d9b57..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap3.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) // FIXME swapped the branches - makeN(v2, l2, merge(h1, r2)) - else - makeN(v1, l1, merge(r1, h2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap4.scala b/testcases/repair/Heap/Heap4.scala deleted file mode 100644 index 46c78c8fd25dc5519aa6d8bddba257eb1e7c39e2..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap4.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h2 // FIXME should be h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap5.scala b/testcases/repair/Heap/Heap5.scala deleted file mode 100644 index 4e963e3bd63b913bb960dc0640f52aa2d9150723..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap5.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 <= v2) // FIXME should be >= - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap6.scala b/testcases/repair/Heap/Heap6.scala deleted file mode 100644 index d284bb3804496fddadd8edced8c8fd98ddf5217c..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap6.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l1, merge(h1, r2)) // FIXME: l1 instead of l2 - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap7.scala b/testcases/repair/Heap/Heap7.scala deleted file mode 100644 index ed4d189ce0f4c8dd78327f707627c1e9319b9187..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap7.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 + v2 > 0) // FIXME Totally wrong - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap8.scala b/testcases/repair/Heap/Heap8.scala deleted file mode 100644 index 2564dceb8678e25dafabdc81b2dee125f63928ea..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap8.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element + 1, Leaf(), Leaf()), heap) // FIXME: unneeded +1 - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/Heap/Heap9.scala b/testcases/repair/Heap/Heap9.scala deleted file mode 100644 index 4f5f4f3986d1daabb3ce3e9e94440ebe9235f7b8..0000000000000000000000000000000000000000 --- a/testcases/repair/Heap/Heap9.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank + 42) // FIXME unneeded constant - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/List/List.scala b/testcases/repair/List/List.scala deleted file mode 100644 index 043cd86ad8e600434adb9933d984d8e7a679fa43..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List.scala +++ /dev/null @@ -1,421 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List1.scala b/testcases/repair/List/List1.scala deleted file mode 100644 index b2802d5f5135b8aadecaad999b1d7e00b97ae2c4..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List1.scala +++ /dev/null @@ -1,419 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s-1, e)) // FIXME should be s - }} ensuring { res => - (s > 0) ==> (res.size == this.size + s && res.contains(e)) - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List10.scala b/testcases/repair/List/List10.scala deleted file mode 100644 index 81cf37c6b32b5b70c095c81efe6d94d14da7c8b4..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List10.scala +++ /dev/null @@ -1,424 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(3) + t.size //FIXME - }) ensuring { (this, _) passes { - case Cons(_, Nil()) => 1 - case Nil() => 0 - }} - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil[T]() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil[T]() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil[T]() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List11.scala b/testcases/repair/List/List11.scala deleted file mode 100644 index 73c76fecc8acfb2d0719e73e694474a8158f0b9c..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List11.scala +++ /dev/null @@ -1,430 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } - - def sum(l: List[BigInt]): BigInt = { l match { - case Nil() => BigInt(0) - case Cons(x, xs) => BigInt(1) + sum(xs) // FIXME - }} ensuring { (l, _) passes { - case Cons(a, Nil()) => a - case Cons(a, Cons(b, Nil())) => a + b - }} - -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List12.scala b/testcases/repair/List/List12.scala deleted file mode 100644 index 2f8afafd14d3665a51747ab5742c1821183c5823..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List12.scala +++ /dev/null @@ -1,422 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = { this match { - case Cons(h, t) => - if (e == h) { - t // FIXME missing rec. call - } else { - Cons(h, t - e) - } - case Nil() => - Nil[T]() - }} ensuring { _.content == this.content -- Set(e) } - - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil[T]() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil[T]() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List13.scala b/testcases/repair/List/List13.scala deleted file mode 100644 index 1093efc3dc951ee8307c2257d8dcec2d154c9ecd..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List13.scala +++ /dev/null @@ -1,429 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = { - require(i >= 0) - (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - if (i == 0) { - Cons[T](h, t) - } else { - t.drop(i) // FIXME Should be -1 - } - } - } ensuring { (res: List[T]) => - ((this, i), res) passes { - case (Cons(a, Cons(b, Nil())), BigInt(1)) => Cons(b, Nil()) - case (Cons(a, Cons(b, Nil())), BigInt(2)) => Nil() - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List2.scala b/testcases/repair/List/List2.scala deleted file mode 100644 index d035e3933b6d509cf6535e850997daa166260b60..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List2.scala +++ /dev/null @@ -1,424 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => xs ++ that // FIXME forgot x - }) ensuring { res => - (res.content == this.content ++ that.content) && - (res.size == this.size + that.size) - } - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List3.scala b/testcases/repair/List/List3.scala deleted file mode 100644 index 7ab14a218574d20a17379ac6cfb4aa60f48dbda3..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List3.scala +++ /dev/null @@ -1,421 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => this // FIXME forgot t - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List4.scala b/testcases/repair/List/List4.scala deleted file mode 100644 index 1ee180b3331e9cc51df34207b8ab5b6fec9b710b..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List4.scala +++ /dev/null @@ -1,428 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = { - (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - // FIXME - if (i != 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - } ensuring { ((this, i), _) passes { - case (Cons(_, Nil()), BigInt(42)) => Nil() - case (l@Cons(_, _), BigInt(0)) => l - case (Cons(a, Cons(b, Nil())), BigInt(1)) => Cons(b, Nil()) - }} - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List5.scala b/testcases/repair/List/List5.scala deleted file mode 100644 index f13f91da3d55d7cdcf0eb0d3ef41027e1a8e94d8..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List5.scala +++ /dev/null @@ -1,424 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = { this match { - case Nil() => Nil[T]() - case Cons(h, t) => - val r = t.replace(from, to) - if (h != from) { // FIXME - Cons(to, r) - } else { - Cons(h, r) - } - }} ensuring { res => - (((this.content -- Set(from)) ++ (if (this.content contains from) Set(to) else Set[T]())) == res.content) && - res.size == this.size - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List6.scala b/testcases/repair/List/List6.scala deleted file mode 100644 index 7ccf9ef721afe93f8276f9dc9cea65b1971d5a35..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List6.scala +++ /dev/null @@ -1,425 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = { this match { - case Cons(h, t) => - if (h == e) { - t.count(e) // FIXME missing +1 - } else { - t.count(e) - } - case Nil() => - BigInt(0) - }} ensuring {((this, e), _) passes { - case (Cons(a, Cons(b, Cons(a1, Cons(b2, Nil())))), a2) if a == a1 && a == a2 && b != a2 && b2 != a2 => 2 - case (Cons(a, Cons(b, Nil())), c) if a != c && b != c => 0 - }} - - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List7.scala b/testcases/repair/List/List7.scala deleted file mode 100644 index 41972f4cefffa0bd63245856b2d31b0cfe241c10..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List7.scala +++ /dev/null @@ -1,427 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = { this match { - case Nil() => None[BigInt]() - case Cons(h, t) => - if (h == e) { - Some(BigInt(0)) - } else { - t.find(e) match { - case None() => None[BigInt]() - case Some(i) => Some(i) // FIXME forgot +1 - } - } - }} ensuring { res => - if (this.content contains e) { - res.isDefined && this.size > res.get && this.apply(res.get) == e && res.get >= 0 - } else { - res.isEmpty - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List8.scala b/testcases/repair/List/List8.scala deleted file mode 100644 index 02f5294c26e7f3b4f29e307db07186927bfff82c..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List8.scala +++ /dev/null @@ -1,427 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = { this match { - case Nil() => None[BigInt]() - case Cons(h, t) => - if (h == e) { - Some(BigInt(0)) - } else { - t.find(e) match { - case None() => None[BigInt]() - case Some(i) => Some(i+2) // FIXME +1 - } - } - }} ensuring { res => - if (this.content contains e) { - res.isDefined && this.size > res.get && this.apply(res.get) == e && res.get >= 0 - } else { - res.isEmpty - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/List/List9.scala b/testcases/repair/List/List9.scala deleted file mode 100644 index 104e2ecabdfa0ac8bef8cc179ff68acc1a7c6ccc..0000000000000000000000000000000000000000 --- a/testcases/repair/List/List9.scala +++ /dev/null @@ -1,427 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = { this match { - case Nil() => None[BigInt]() - case Cons(h, t) => - if (h != e) { // FIXME - Some(BigInt(0)) - } else { - t.find(e) match { - case None() => None[BigInt]() - case Some(i) => Some(i + 1) - } - } - }} ensuring { res => - if (this.content contains e) { - res.isDefined && this.size > res.get && this.apply(res.get) == e && res.get >= 0 - } else { - res.isEmpty - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/repair/MergeSort/MergeSort.scala b/testcases/repair/MergeSort/MergeSort.scala deleted file mode 100644 index 1ce4210a52bbe53e911660e9c5cab4cb5dbbaf6c..0000000000000000000000000000000000000000 --- a/testcases/repair/MergeSort/MergeSort.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - Cons(h2, merge(l1, t2)) - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/repair/MergeSort/MergeSort1.scala b/testcases/repair/MergeSort/MergeSort1.scala deleted file mode 100644 index 340dfbc46077306b64752e73cebeb725ef40a781..0000000000000000000000000000000000000000 --- a/testcases/repair/MergeSort/MergeSort1.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (rec1, Cons(b, rec2)) // FIXME: Forgot a - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - Cons(h2, merge(l1, t2)) - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/repair/MergeSort/MergeSort2.scala b/testcases/repair/MergeSort/MergeSort2.scala deleted file mode 100644 index 5c186eca76861f679e67e046c987bebd2951ac97..0000000000000000000000000000000000000000 --- a/testcases/repair/MergeSort/MergeSort2.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - Cons(h1, merge(l1, t2)) // FIXME: h1 -> h2 - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/repair/MergeSort/MergeSort3.scala b/testcases/repair/MergeSort/MergeSort3.scala deleted file mode 100644 index ec37db65c053e3ae3db8871640f516747b7da08d..0000000000000000000000000000000000000000 --- a/testcases/repair/MergeSort/MergeSort3.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 >= h2) // FIXME Condition inverted - Cons(h1, merge(t1, l2)) - else - Cons(h2, merge(l1, t2)) - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/repair/MergeSort/MergeSort4.scala b/testcases/repair/MergeSort/MergeSort4.scala deleted file mode 100644 index 5c3479844d213bf8617f72f9e5dd6aec127f59b2..0000000000000000000000000000000000000000 --- a/testcases/repair/MergeSort/MergeSort4.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - merge(l1, t2) // FIXME: missing h2 - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/repair/MergeSort/MergeSort5.scala b/testcases/repair/MergeSort/MergeSort5.scala deleted file mode 100644 index 7746d23c7fa58e3e3c60c7ff4e9fe2c62fc8f3a9..0000000000000000000000000000000000000000 --- a/testcases/repair/MergeSort/MergeSort5.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - Cons(h2, merge(l1, t2)) - case (Nil(), _) => l1 // FIXME should be l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/repair/Naturals/Naturals.scala b/testcases/repair/Naturals/Naturals.scala deleted file mode 100644 index 963f487a8fb972ba24de84fbe1ee99177804b7a9..0000000000000000000000000000000000000000 --- a/testcases/repair/Naturals/Naturals.scala +++ /dev/null @@ -1,83 +0,0 @@ -import leon.lang.synthesis._ - -object Naturals { - - abstract class Nat { - def intValue : Int = { this match { - case Zero => 0 - case Succ(n) => n.intValue + 1 - }} ensuring { _ >= 0 } - - def +(that : Nat) : Nat = { this match { - case Zero => that - case Succ(n) => n + Succ(that) - }} ensuring { _.intValue == this.intValue + that.intValue } - - def <=(that : Nat) : Boolean = { (this, that) match { - case (Zero, _) => true - case (_, Zero) => false - case (Succ(n1), Succ(n2)) => n1 <= n2 - }} ensuring { _ == this.intValue <= that.intValue } - - def >(that : Nat) = !(this <= that) - - def -(that : Nat) : Nat = { - require(that <= this) - (this, that) match { - case (_, Zero) => this - case (Succ(n1), Succ(n2)) => n1 - n2 - } - } ensuring { _.intValue == this.intValue - that.intValue } - - def * (that: Nat) : Nat = { this match { - case Zero => Zero - case Succ(n) => that + n * that - }} ensuring { _.intValue == this.intValue * that.intValue } - - /* - def /(that : Nat) : Nat = { - require(that > Zero) - if (that <= this) (this - that)/ that + one - else Zero - } ensuring { _.intValue == this.intValue / that.intValue } - - def %(that : Nat) : Nat = { - require(that > Zero) - this - (this / that) * that - } ensuring { _.intValue == this.intValue % that.intValue } - - // Convension : least s. digit first - def isDecimalRepr(l : List[Nat]) : Boolean = l match { - case Nil() => false - case Cons(h, t) => h <= ten && isDecimalRepr(t) - } - - def decimalToNat(l : List[Nat]) : Nat = { - require(isDecimalRepr(l)) - l match { - case Cons(h, Nil()) => h - case Cons(h, t) => 10 * decimalToNat(t) + h - } - } - - */ - - } - case object Zero extends Nat - case class Succ(n : Nat) extends Nat - - def ten = { - val two = Succ(Succ(Zero)) - val five = Succ(two + two) - two * five - } - - def fortyTwo = { - val one = Succ(Zero) - val two = one + one - val three = two + one - val seven = (two * three) + one - two * three * seven - } ensuring { _.intValue == 42 } - -} diff --git a/testcases/repair/Numerical/Numerical.scala b/testcases/repair/Numerical/Numerical.scala deleted file mode 100644 index bad9160654675694afd68519089fcf1d0d5b35a3..0000000000000000000000000000000000000000 --- a/testcases/repair/Numerical/Numerical.scala +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ -import leon.annotation._ - -object Numerical { - def power(base: BigInt, p: BigInt): BigInt = { - require(p >= BigInt(0)) - if (p == BigInt(0)) { - BigInt(1) - } else if (p%BigInt(2) == BigInt(0)) { - power(base*base, p/BigInt(2)) - } else { - base*power(base, p-BigInt(1)) - } - } ensuring { - res => ((base, p), res) passes { - case (_, BigInt(0)) => BigInt(1) - case (b, BigInt(1)) => b - case (BigInt(2), BigInt(7)) => BigInt(128) - case (BigInt(2), BigInt(10)) => BigInt(1024) - } - } - - def gcd(a: BigInt, b: BigInt): BigInt = { - require(a > BigInt(0) && b > BigInt(0)); - - if (a == b) { - a - } else if (a > b) { - gcd(a-b, b) - } else { - gcd(a, b-a) - } - } ensuring { - res => (a%res == BigInt(0)) && (b%res == BigInt(0)) && (((a,b), res) passes { - case (BigInt(468), BigInt(24)) => BigInt(12) - }) - } - - def moddiv(a: BigInt, b: BigInt): (BigInt, BigInt) = { - require(a >= BigInt(0) && b > BigInt(0)); - if (b > a) { - (a, BigInt(0)) - } else { - val (r1, r2) = moddiv(a-b, b) - (r1, r2+1) - } - } ensuring { - res => b*res._2 + res._1 == a - } - -} diff --git a/testcases/repair/Numerical/Numerical1.scala b/testcases/repair/Numerical/Numerical1.scala deleted file mode 100644 index 6223cc54703f5377047695ea21420701098e5f8d..0000000000000000000000000000000000000000 --- a/testcases/repair/Numerical/Numerical1.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ -import leon.annotation._ - -object Numerical { - def power(base: BigInt, p: BigInt): BigInt = { - require(p >= BigInt(0)) - if (p == BigInt(0)) { - BigInt(1) - } else if (p%BigInt(2) == BigInt(0)) { - power(base*base, p/BigInt(2)) - } else { - power(base, p-BigInt(1)) // fixme: Missing base* - } - } ensuring { - res => ((base, p), res) passes { - case (_, BigInt(0)) => BigInt(1) - case (b, BigInt(1)) => b - case (BigInt(2), BigInt(7)) => BigInt(128) - case (BigInt(2), BigInt(10)) => BigInt(1024) - } - } - - def gcd(a: BigInt, b: BigInt): BigInt = { - require(a > BigInt(0) && b > BigInt(0)); - - if (a == b) { - a - } else if (a > b) { - gcd(a-b, b) - } else { - gcd(a, b-a) - } - } ensuring { - res => (a%res == BigInt(0)) && (b%res == BigInt(0)) && (((a,b), res) passes { - case (BigInt(468), BigInt(24)) => BigInt(12) - }) - } - - def moddiv(a: BigInt, b: BigInt): (BigInt, BigInt) = { - require(a >= BigInt(0) && b > BigInt(0)); - if (b > a) { - (a, BigInt(0)) - } else { - val (r1, r2) = moddiv(a-b, b) - (r1, r2+1) - } - } ensuring { - res => b*res._2 + res._1 == a - } -} diff --git a/testcases/repair/Numerical/Numerical2.scala b/testcases/repair/Numerical/Numerical2.scala deleted file mode 100644 index 4315c8a07f7f56a7598a9425c911e807825e428d..0000000000000000000000000000000000000000 --- a/testcases/repair/Numerical/Numerical2.scala +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ -import leon.annotation._ - -object Numerical { - def power(base: BigInt, p: BigInt): BigInt = { - require(p >= BigInt(0)) - if (p == BigInt(0)) { - BigInt(1) - } else if (p%BigInt(2) == BigInt(0)) { - power(base*base, p/BigInt(2)) - } else { - base*power(base, p-BigInt(1)) - } - } ensuring { - res => ((base, p), res) passes { - case (_, BigInt(0)) => BigInt(1) - case (b, BigInt(1)) => b - case (BigInt(2), BigInt(7)) => BigInt(128) - case (BigInt(2), BigInt(10)) => BigInt(1024) - } - } - - def gcd(a: BigInt, b: BigInt): BigInt = { - require(a > BigInt(0) && b > BigInt(0)); - - if (a == b) { - BigInt(1) // fixme: should be a - } else if (a > b) { - gcd(a-b, b) - } else { - gcd(a, b-a) - } - } ensuring { - res => (a%res == BigInt(0)) && (b%res == BigInt(0)) && (((a,b), res) passes { - case (BigInt(120), BigInt(24)) => BigInt(12) - case (BigInt(5), BigInt(7)) => BigInt(1) - case (BigInt(5), BigInt(5)) => BigInt(5) - }) - } -} diff --git a/testcases/repair/Numerical/Numerical3.scala b/testcases/repair/Numerical/Numerical3.scala deleted file mode 100644 index 593bbd604d0aa1d2c8080cba1c2cd4fafb28132a..0000000000000000000000000000000000000000 --- a/testcases/repair/Numerical/Numerical3.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ -import leon.annotation._ - -object Numerical { - def power(base: BigInt, p: BigInt): BigInt = { - require(p >= BigInt(0)) - if (p == BigInt(0)) { - BigInt(1) - } else if (p%BigInt(2) == BigInt(0)) { - power(base*base, p/BigInt(2)) - } else { - base*power(base, p-BigInt(1)) - } - } ensuring { - res => ((base, p), res) passes { - case (_, BigInt(0)) => BigInt(1) - case (b, BigInt(1)) => b - case (BigInt(2), BigInt(7)) => BigInt(128) - case (BigInt(2), BigInt(10)) => BigInt(1024) - } - } - - def gcd(a: BigInt, b: BigInt): BigInt = { - require(a > BigInt(0) && b > BigInt(0)); - - if (a == b) { - a - } else if (a > b) { - gcd(a-b, b) - } else { - gcd(a, b-a) - } - } ensuring { - res => (a%res == BigInt(0)) && (b%res == BigInt(0)) && (((a,b), res) passes { - case (BigInt(468), BigInt(24)) => BigInt(12) - }) - } - - def moddiv(a: BigInt, b: BigInt): (BigInt, BigInt) = { - require(a >= BigInt(0) && b > BigInt(0)); - if (b > a) { - (BigInt(1), BigInt(0)) // fixme: should be (a, BigInt(0)) - } else { - val (r1, r2) = moddiv(a-b, b) - (r1, r2+1) - } - } ensuring { - res => b*res._2 + res._1 == a - } -} diff --git a/testcases/repair/Parser/Parser.scala b/testcases/repair/Parser/Parser.scala deleted file mode 100644 index 8d838f470d63d8e8967f53cf88b2a6bcaf98061c..0000000000000000000000000000000000000000 --- a/testcases/repair/Parser/Parser.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon._ -import leon.lang._ -import leon.collection._ - -object Parser { - abstract class Token - case object LParen extends Token - case object RParen extends Token - case class Id(id : Int) extends Token - - abstract class Tree - case class App(args : List[Tree]) extends Tree - case class Leaf(id : Int) extends Tree - - def parse(in : List[Token]) : (Option[Tree], List[Token]) = { in match { - case Cons(Id(s), tl) => - (Some[Tree](Leaf(s)),tl) - case Cons(LParen, tl) => parseMany(tl) match { - case (Some(trees:Cons[Tree]), Cons(RParen,rest)) => - (Some[Tree](App(trees)), rest) - case (_, rest) => (None[Tree](), rest) - } - case _ => (None[Tree](), in) - }} ensuring { _ match { - case ( Some(tree), rest@Cons(h,_)) => - print(tree, rest) == in -// case ( None(), Cons(h,_)) => !h.isInstanceOf[Id] -// case ( None(), Nil) => - case _ => true - }} - - def parseMany(in : List[Token]) : (Option[List[Tree]], List[Token]) = { parse(in) match { - case (None(), rest) if rest == in => (Some[List[Tree]](Nil()), in) - case (None(), rest) => (None[List[Tree]](), rest) - case (Some(tree), rest) => parseMany(rest) match { - case ( None(), rest2) => (None[List[Tree]](), rest2) - case ( Some(trees), rest2) => - ( Some[List[Tree]](tree::trees), rest2 ) - } - }} ensuring { _ match { - case ( Some(t), rest@Cons(h, _) ) => - h == RParen && printL(t, rest) == in - case ( None(), Cons(h, _)) => - h == RParen - case _ => true - }} - - - def printL(args : List[Tree], rest : List[Token]) : List[Token] = args match { - case Nil() => rest - case Cons(h,t) => print(h, printL(t, rest)) - } - - def print(t : Tree, rest : List[Token]) : List[Token] = t match { - case Leaf(s) => Id(s) :: rest - case App(args) => LParen :: printL(args, RParen :: rest) - } - -} diff --git a/testcases/repair/Parser/Parser1.scala b/testcases/repair/Parser/Parser1.scala deleted file mode 100644 index 5fd18245f4cc6d62ecef9278ae29cfb9e8a16bd0..0000000000000000000000000000000000000000 --- a/testcases/repair/Parser/Parser1.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon._ -import leon.lang._ -import leon.collection._ - -object Parser { - abstract class Token - case object LParen extends Token - case object RParen extends Token - case class Id(id : Int) extends Token - - abstract class Tree - case class App(args : List[Tree]) extends Tree - case class Leaf(id : Int) extends Tree - - def parse(in : List[Token]) : (Option[Tree], List[Token]) = { in match { - case Cons(Id(s), tl) => - (Some[Tree](Leaf(s)),tl) - case Cons(LParen, tl) => parseMany(tl) match { - case (Some(trees:Cons[Tree]), Cons(RParen,rest)) => - (Some[Tree](App(trees)), rest) - case (_, rest) => (None[Tree](), rest) - } - case _ => (None[Tree](), in) - }} ensuring { _ match { - case ( Some(tree), rest@Cons(h,_)) => - print(tree, rest) == in - case ( None(), Cons(h,_) ) => - h == RParen - case _ => true - }} - - def parseMany(in : List[Token]) : (Option[List[Tree]], List[Token]) = { parse(in) match { - case (None(), rest) /*if rest == in*/ => (Some[List[Tree]](Nil()), in) // FIXME: forgot condition - //case (None(), rest) => (None[List[Tree]](), rest) - case (Some(tree), rest) => parseMany(rest) match { - case ( None(), rest2) => (None[List[Tree]](), rest2) - case ( Some(trees), rest2) => - ( Some[List[Tree]](tree::trees), rest2 ) - } - }} ensuring { _ match { - case ( Some(t), rest@Cons(h, _) ) => - h == RParen && printL(t, rest) == in - case ( None(), Cons(h, _)) => - h == RParen - case _ => true - }} - - - def printL(args : List[Tree], rest : List[Token]) : List[Token] = args match { - case Nil() => rest - case Cons(h,t) => print(h, printL(t, rest)) - } - - def print(t : Tree, rest : List[Token]) : List[Token] = t match { - case Leaf(s) => Id(s) :: rest - case App(args) => LParen :: printL(args, RParen :: rest) - } - -} diff --git a/testcases/repair/Parser/Parser2.scala b/testcases/repair/Parser/Parser2.scala deleted file mode 100644 index 919132e04b7fe97ac81b836b02140eb42fb57b77..0000000000000000000000000000000000000000 --- a/testcases/repair/Parser/Parser2.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon._ -import leon.lang._ -import leon.collection._ - -object Parser { - abstract class Token - case object LParen extends Token - case object RParen extends Token - case class Id(id : Int) extends Token - - abstract class Tree - case class App(args : List[Tree]) extends Tree - case class Leaf(id : Int) extends Tree - - def parse(in : List[Token]) : (Option[Tree], List[Token]) = { in match { - case Cons(Id(s), tl) => - (Some[Tree](Leaf(s)),tl) - case Cons(LParen, tl) => parseMany(tl) match { - case (Some(trees:Cons[Tree]), Cons(RParen,rest)) => - (Some[Tree](App(trees)), rest) - case (_, rest) => (None[Tree](), rest) - } - case _ => (None[Tree](), in) - }} ensuring { _ match { - case ( Some(tree), rest@Cons(h,_)) => - print(tree, rest) == in - case ( None(), Cons(h,_) ) => - h == RParen - case _ => true - }} - - def parseMany(in : List[Token]) : (Option[List[Tree]], List[Token]) = { parse(in) match { - case (None(), rest) if rest == in => (Some[List[Tree]](Nil()), in) - case (None(), rest) => (None[List[Tree]](), rest) - case (Some(tree), rest) => parseMany(rest) match { - case ( None(), rest2) => (None[List[Tree]](), rest2) - case ( Some(trees), rest2) => - ( Some[List[Tree]](trees), rest2 ) // FIXME: should be tree::trees - } - }} ensuring { _ match { - case ( Some(t), rest@Cons(h, _) ) => - h == RParen && printL(t, rest) == in - case ( None(), Cons(h, _)) => - h == RParen - case _ => true - }} - - - def printL(args : List[Tree], rest : List[Token]) : List[Token] = args match { - case Nil() => rest - case Cons(h,t) => print(h, printL(t, rest)) - } - - def print(t : Tree, rest : List[Token]) : List[Token] = t match { - case Leaf(s) => Id(s) :: rest - case App(args) => LParen :: printL(args, RParen :: rest) - } - -} diff --git a/testcases/repair/Parser/Parser3.scala b/testcases/repair/Parser/Parser3.scala deleted file mode 100644 index cf11c4d3ff54ce42b6858f532e56a3f03e487fa0..0000000000000000000000000000000000000000 --- a/testcases/repair/Parser/Parser3.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon._ -import leon.lang._ -import leon.collection._ - -object Parser { - abstract class Token - case object LParen extends Token - case object RParen extends Token - case class Id(id : Int) extends Token - - abstract class Tree - case class App(args : List[Tree]) extends Tree - case class Leaf(id : Int) extends Tree - - def parse(in : List[Token]) : (Option[Tree], List[Token]) = { in match { - case Cons(Id(s), tl) => - (Some[Tree](Leaf(s)),tl) - case Cons(LParen, tl) => parseMany(tl) match { - case (Some(trees:Cons[Tree]), Cons(RParen,rest)) => - (Some[Tree](App(trees)), rest) - case (_, rest) => (None[Tree](), rest) - } - case _ => (None[Tree](), in) - }} ensuring { _ match { - case ( Some(tree), rest@Cons(h,_)) => - print(tree, rest) == in - case ( None(), Cons(h,_) ) => - h == RParen - case _ => true - }} - - def parseMany(in : List[Token]) : (Option[List[Tree]], List[Token]) = { parse(in) match { - case (None(), rest) if rest == in => (Some[List[Tree]](Nil()), in) - case (None(), rest) => (None[List[Tree]](), rest) - case (Some(tree), rest) => parseMany(rest) match { - case ( None(), rest2) => (None[List[Tree]](), rest2) - case ( Some(trees), rest2) => - ( Some[List[Tree]](tree::trees), rest2 ) - } - }} ensuring { _ match { - case ( Some(t), rest@Cons(h, _) ) => - h == RParen && printL(t, rest) == in - case ( None(), Cons(h, _)) => - h == RParen - case _ => true - }} - - - def printL(args : List[Tree], rest : List[Token]) : List[Token] = args match { - case Nil() => rest - case Cons(h,t) => print(h, printL(t, rest)) - } - - def print(t : Tree, rest : List[Token]) : List[Token] = t match { - case Leaf(s) => Id(s) :: rest - case App(args) => LParen :: printL(args, RParen :: rest) - } - -} diff --git a/testcases/repair/Parser/Parser4.scala b/testcases/repair/Parser/Parser4.scala deleted file mode 100644 index cf11c4d3ff54ce42b6858f532e56a3f03e487fa0..0000000000000000000000000000000000000000 --- a/testcases/repair/Parser/Parser4.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon._ -import leon.lang._ -import leon.collection._ - -object Parser { - abstract class Token - case object LParen extends Token - case object RParen extends Token - case class Id(id : Int) extends Token - - abstract class Tree - case class App(args : List[Tree]) extends Tree - case class Leaf(id : Int) extends Tree - - def parse(in : List[Token]) : (Option[Tree], List[Token]) = { in match { - case Cons(Id(s), tl) => - (Some[Tree](Leaf(s)),tl) - case Cons(LParen, tl) => parseMany(tl) match { - case (Some(trees:Cons[Tree]), Cons(RParen,rest)) => - (Some[Tree](App(trees)), rest) - case (_, rest) => (None[Tree](), rest) - } - case _ => (None[Tree](), in) - }} ensuring { _ match { - case ( Some(tree), rest@Cons(h,_)) => - print(tree, rest) == in - case ( None(), Cons(h,_) ) => - h == RParen - case _ => true - }} - - def parseMany(in : List[Token]) : (Option[List[Tree]], List[Token]) = { parse(in) match { - case (None(), rest) if rest == in => (Some[List[Tree]](Nil()), in) - case (None(), rest) => (None[List[Tree]](), rest) - case (Some(tree), rest) => parseMany(rest) match { - case ( None(), rest2) => (None[List[Tree]](), rest2) - case ( Some(trees), rest2) => - ( Some[List[Tree]](tree::trees), rest2 ) - } - }} ensuring { _ match { - case ( Some(t), rest@Cons(h, _) ) => - h == RParen && printL(t, rest) == in - case ( None(), Cons(h, _)) => - h == RParen - case _ => true - }} - - - def printL(args : List[Tree], rest : List[Token]) : List[Token] = args match { - case Nil() => rest - case Cons(h,t) => print(h, printL(t, rest)) - } - - def print(t : Tree, rest : List[Token]) : List[Token] = t match { - case Leaf(s) => Id(s) :: rest - case App(args) => LParen :: printL(args, RParen :: rest) - } - -} diff --git a/testcases/repair/Parser/Parser5.scala b/testcases/repair/Parser/Parser5.scala deleted file mode 100644 index cf11c4d3ff54ce42b6858f532e56a3f03e487fa0..0000000000000000000000000000000000000000 --- a/testcases/repair/Parser/Parser5.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon._ -import leon.lang._ -import leon.collection._ - -object Parser { - abstract class Token - case object LParen extends Token - case object RParen extends Token - case class Id(id : Int) extends Token - - abstract class Tree - case class App(args : List[Tree]) extends Tree - case class Leaf(id : Int) extends Tree - - def parse(in : List[Token]) : (Option[Tree], List[Token]) = { in match { - case Cons(Id(s), tl) => - (Some[Tree](Leaf(s)),tl) - case Cons(LParen, tl) => parseMany(tl) match { - case (Some(trees:Cons[Tree]), Cons(RParen,rest)) => - (Some[Tree](App(trees)), rest) - case (_, rest) => (None[Tree](), rest) - } - case _ => (None[Tree](), in) - }} ensuring { _ match { - case ( Some(tree), rest@Cons(h,_)) => - print(tree, rest) == in - case ( None(), Cons(h,_) ) => - h == RParen - case _ => true - }} - - def parseMany(in : List[Token]) : (Option[List[Tree]], List[Token]) = { parse(in) match { - case (None(), rest) if rest == in => (Some[List[Tree]](Nil()), in) - case (None(), rest) => (None[List[Tree]](), rest) - case (Some(tree), rest) => parseMany(rest) match { - case ( None(), rest2) => (None[List[Tree]](), rest2) - case ( Some(trees), rest2) => - ( Some[List[Tree]](tree::trees), rest2 ) - } - }} ensuring { _ match { - case ( Some(t), rest@Cons(h, _) ) => - h == RParen && printL(t, rest) == in - case ( None(), Cons(h, _)) => - h == RParen - case _ => true - }} - - - def printL(args : List[Tree], rest : List[Token]) : List[Token] = args match { - case Nil() => rest - case Cons(h,t) => print(h, printL(t, rest)) - } - - def print(t : Tree, rest : List[Token]) : List[Token] = t match { - case Leaf(s) => Id(s) :: rest - case App(args) => LParen :: printL(args, RParen :: rest) - } - -} diff --git a/testcases/repair/PropLogic/PropLogic.scala b/testcases/repair/PropLogic/PropLogic.scala deleted file mode 100644 index a03dd35b47d7b9abed256a13f9168c8afe666ff0..0000000000000000000000000000000000000000 --- a/testcases/repair/PropLogic/PropLogic.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => nnf(e) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/repair/PropLogic/PropLogic1.scala b/testcases/repair/PropLogic/PropLogic1.scala deleted file mode 100644 index a27d3afe5d0e20668e72ec654c91714bc0aa88a1..0000000000000000000000000000000000000000 --- a/testcases/repair/PropLogic/PropLogic1.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => e // FIXME missing nnf - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/repair/PropLogic/PropLogic2.scala b/testcases/repair/PropLogic/PropLogic2.scala deleted file mode 100644 index a03dd35b47d7b9abed256a13f9168c8afe666ff0..0000000000000000000000000000000000000000 --- a/testcases/repair/PropLogic/PropLogic2.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => nnf(e) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/repair/PropLogic/PropLogic3.scala b/testcases/repair/PropLogic/PropLogic3.scala deleted file mode 100644 index 87d78dbc98ae5e4dbbd163f6336e3e8428adbdbc..0000000000000000000000000000000000000000 --- a/testcases/repair/PropLogic/PropLogic3.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(v) // FIXME - case Not(Not(e)) => nnf(e) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/repair/PropLogic/PropLogic4.scala b/testcases/repair/PropLogic/PropLogic4.scala deleted file mode 100644 index 29e1c5783d1c8c675c848b9b0101d59539bf71bb..0000000000000000000000000000000000000000 --- a/testcases/repair/PropLogic/PropLogic4.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => nnf(e) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/repair/PropLogic/PropLogic5.scala b/testcases/repair/PropLogic/PropLogic5.scala deleted file mode 100644 index e89e2c5ae2cfda30e73743aab932f980a95fa46f..0000000000000000000000000000000000000000 --- a/testcases/repair/PropLogic/PropLogic5.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => formula//FIXME And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => nnf(e) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/repair/RedBlackTree/RedBlackTree.scala b/testcases/repair/RedBlackTree/RedBlackTree.scala deleted file mode 100644 index 8bf916e87dbaff0754d90843b8ee12b01103fbcd..0000000000000000000000000000000000000000 --- a/testcases/repair/RedBlackTree/RedBlackTree.scala +++ /dev/null @@ -1,159 +0,0 @@ -import leon.lang._ -import leon.collection._ -import annotation._ - -object RedBlackTree { - sealed abstract class Color - case object Red extends Color - case object Black extends Color - - sealed abstract class Tree { - /* We consider leaves to be black by definition */ - def color = this match { - case Empty => Black - case Node(c,_,_,_) => c - } - - def content : Set[Int] = this match { - case Empty => Set.empty - case Node(_, l, v, r) => l.content ++ Set(v) ++ r.content - } - - def size : Int = this match { - case Empty => 0 - case Node(_, l, v, r) => l.size + 1 + r.size - } - - def isBlack = color == Black - - def blackHeight : Int = this match { - case Empty => 1 - case Node(Black, l, _, _) => l.blackHeight + 1 - case Node(Red, l, _, _) => l.blackHeight - } - - def max : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - maxOption(Some(v), maxOption(l.max, r.max)) - } - - def min : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - minOption(Some(v), minOption(l.max, r.max)) - } - - } - - def minOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 < i2) i1 else i2) - case _ => i1 orElse i2 - } - - def maxOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 > i2) i1 else i2) - case _ => i1 orElse i2 - } - - case object Empty extends Tree - case class Node(color_ : Color, left: Tree, value: Int, right: Tree) extends Tree - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(Black, l, _, r) => - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - case Node(Red, l, _, r) => - l.isBlack && r.isBlack && - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && l.blackHeight == r.blackHeight - case Empty => true - } - - def keysSorted(t : Tree) : Boolean = t match { - case Empty => true - case Node(_, l, v, r) => - keysSorted(l) && keysSorted(r) && - (l.max.getOrElse (v-1) < v) && - (r.min.getOrElse (v+1) > v) - } - - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - t match { - case Empty => Node(Red,Empty,x,Empty) - case n@Node(c,a,y,b) => - if (x < y) balance(Node(c, ins(x, a), y, b)) - else if (x == y) n - else balance(Node(c, a, y, ins(x, b))) - } - } ensuring (res => - res.content == t.content ++ Set(x) && - t.size <= res.size && - res.size <= t.size + 1 && - keysSorted(res) && - redDescHaveBlackChildren(res) && - blackBalanced(res) - ) - - def makeBlack(n: Tree): Tree = { - require( - redDescHaveBlackChildren(n) && - blackBalanced(n) && - keysSorted(n) - ) - n match { - case Node(Red,l,v,r) => Node(Black,l,v,r) - case _ => n - } - } ensuring { res => - res.isBlack && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - makeBlack(ins(x, t)) - } ensuring { res => - res.content == t.content ++ Set(x) && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - - - def balance(t : Tree) : Tree = { - require(keysSorted(t)) - t match { - case Empty => Empty - case Node(Black,Node(Red,Node(Red,a,xV,b),yV,c),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,Node(Red,a,xV,Node(Red,b,yV,c)),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,Node(Red,b,yV,c),zV,d)) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,b,yV,Node(Red,c,zV,d))) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case other => other - } - } ensuring { res => - res.content == t.content && - keysSorted(res) - } - - -} diff --git a/testcases/repair/RedBlackTree/RedBlackTree1.scala b/testcases/repair/RedBlackTree/RedBlackTree1.scala deleted file mode 100644 index c19819441f00de6ae86f666aac2c312c650da851..0000000000000000000000000000000000000000 --- a/testcases/repair/RedBlackTree/RedBlackTree1.scala +++ /dev/null @@ -1,149 +0,0 @@ -import leon.lang._ -import leon.collection._ -import annotation._ - -object RedBlackTree { - sealed abstract class Color - case object Red extends Color - case object Black extends Color - - sealed abstract class Tree { - /* We consider leaves to be black by definition */ - def color = this match { - case Empty => Black - case Node(c,_,_,_) => c - } - - def content : Set[Int] = this match { - case Empty => Set.empty - case Node(_, l, v, r) => l.content ++ Set(v) ++ r.content - } - - def size : Int = this match { - case Empty => 0 - case Node(_, l, v, r) => l.size + 1 + r.size - } - - def isBlack = color == Black - - def blackHeight : Int = this match { - case Empty => 1 - case Node(Black, l, _, _) => l.blackHeight + 1 - case Node(Red, l, _, _) => l.blackHeight - } - - def max : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - maxOption(Some(v), maxOption(l.max, r.max)) - } - - def min : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - minOption(Some(v), minOption(l.max, r.max)) - } - - } - - def minOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 < i2) i1 else i2) - case _ => i1 orElse i2 - } - - def maxOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 > i2) i1 else i2) - case _ => i1 orElse i2 - } - - case object Empty extends Tree - case class Node(color_ : Color, left: Tree, value: Int, right: Tree) extends Tree - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(Black, l, _, r) => - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - case Node(Red, l, _, r) => - l.isBlack && r.isBlack && - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && l.blackHeight == r.blackHeight - case Empty => true - } - - def keysSorted(t : Tree) : Boolean = t match { - case Empty => true - case Node(_, l, v, r) => - keysSorted(l) && keysSorted(r) && - (l.max.getOrElse (v-1) < v) && - (r.min.getOrElse (v+1) > v) - } - - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - val newT = t match { - case Empty => Node(Red,Empty,x,Empty) - case n@Node(c,a,y,b) => - if (x < y) Node(c, ins(x, a), y, b) - else if (x == y) n - else Node(c, a, y, ins(x, b)) - } - newT match { - case Node(Black,Node(Red,Node(Red,a,xV,b),yV,c),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,Node(Red,a,xV,Node(Red,b,yV,c)),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,xV,d)) // FIXME: second xV -> zV - case Node(Black,a,xV,Node(Red,Node(Red,b,yV,c),zV,d)) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,xV,d)) // FIXME: same - case Node(Black,a,xV,Node(Red,b,yV,Node(Red,c,zV,d))) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case other => other - } - } ensuring (res => - res.content == t.content ++ Set(x) && - t.size <= res.size && - res.size <= t.size + 1 && - keysSorted(res) && - redDescHaveBlackChildren(res) && - blackBalanced(res) - ) - - def makeBlack(n: Tree): Tree = { - require( - redDescHaveBlackChildren(n) && - blackBalanced(n) && - keysSorted(n) - ) - n match { - case Node(Red,l,v,r) => Node(Black,l,v,r) - case _ => n - } - } ensuring { res => - res.isBlack && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - makeBlack(ins(x, t)) - } ensuring { res => - res.content == t.content ++ Set(x) && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - -} diff --git a/testcases/repair/RedBlackTree/RedBlackTree2.scala b/testcases/repair/RedBlackTree/RedBlackTree2.scala deleted file mode 100644 index a02dcb6f4224c9d27c23f55b2f238671a8e7801a..0000000000000000000000000000000000000000 --- a/testcases/repair/RedBlackTree/RedBlackTree2.scala +++ /dev/null @@ -1,159 +0,0 @@ -import leon.lang._ -import leon.collection._ -import annotation._ - -object RedBlackTree { - sealed abstract class Color - case object Red extends Color - case object Black extends Color - - sealed abstract class Tree { - /* We consider leaves to be black by definition */ - def color = this match { - case Empty => Black - case Node(c,_,_,_) => c - } - - def content : Set[Int] = this match { - case Empty => Set.empty - case Node(_, l, v, r) => l.content ++ Set(v) ++ r.content - } - - def size : Int = this match { - case Empty => 0 - case Node(_, l, v, r) => l.size + 1 + r.size - } - - def isBlack = color == Black - - def blackHeight : Int = this match { - case Empty => 1 - case Node(Black, l, _, _) => l.blackHeight + 1 - case Node(Red, l, _, _) => l.blackHeight - } - - def max : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - maxOption(Some(v), maxOption(l.max, r.max)) - } - - def min : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - minOption(Some(v), minOption(l.max, r.max)) - } - - } - - def minOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 < i2) i1 else i2) - case _ => i1 orElse i2 - } - - def maxOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 > i2) i1 else i2) - case _ => i1 orElse i2 - } - - case object Empty extends Tree - case class Node(color_ : Color, left: Tree, value: Int, right: Tree) extends Tree - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(Black, l, _, r) => - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - case Node(Red, l, _, r) => - l.isBlack && r.isBlack && - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && l.blackHeight == r.blackHeight - case Empty => true - } - - def keysSorted(t : Tree) : Boolean = t match { - case Empty => true - case Node(_, l, v, r) => - keysSorted(l) && keysSorted(r) && - (l.max.getOrElse (v-1) < v) && - (r.min.getOrElse (v+1) > v) - } - - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - t match { - case Empty => Node(Red,Empty,x,Empty) - case n@Node(c,a,y,b) => - if (x < y) Node(c, ins(x, a), y, b) // FIXME forgot to balance - else if (x == y) n - else balance(Node(c, a, y, ins(x, b))) - } - } ensuring (res => - res.content == t.content ++ Set(x) && - t.size <= res.size && - res.size <= t.size + 1 && - keysSorted(res) && - redDescHaveBlackChildren(res) && - blackBalanced(res) - ) - - def makeBlack(n: Tree): Tree = { - require( - redDescHaveBlackChildren(n) && - blackBalanced(n) && - keysSorted(n) - ) - n match { - case Node(Red,l,v,r) => Node(Black,l,v,r) - case _ => n - } - } ensuring { res => - res.isBlack && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - makeBlack(ins(x, t)) - } ensuring { res => - res.content == t.content ++ Set(x) && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - - - def balance(t : Tree) : Tree = { - require(keysSorted(t)) - t match { - case Empty => Empty - case Node(Black,Node(Red,Node(Red,a,xV,b),yV,c),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,Node(Red,a,xV,Node(Red,b,yV,c)),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,Node(Red,b,yV,c),zV,d)) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,b,yV,Node(Red,c,zV,d))) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case other => other - } - } ensuring { res => - res.content == t.content && - keysSorted(res) - } - - -} diff --git a/testcases/repair/RedBlackTree/RedBlackTree3.scala b/testcases/repair/RedBlackTree/RedBlackTree3.scala deleted file mode 100644 index ffacf352ebfd2adf85e1aaebdbe8026600034dd6..0000000000000000000000000000000000000000 --- a/testcases/repair/RedBlackTree/RedBlackTree3.scala +++ /dev/null @@ -1,149 +0,0 @@ -import leon.lang._ -import leon.collection._ -import annotation._ - -object RedBlackTree { - sealed abstract class Color - case object Red extends Color - case object Black extends Color - - sealed abstract class Tree { - /* We consider leaves to be black by definition */ - def color = this match { - case Empty => Black - case Node(c,_,_,_) => c - } - - def content : Set[Int] = this match { - case Empty => Set.empty - case Node(_, l, v, r) => l.content ++ Set(v) ++ r.content - } - - def size : Int = this match { - case Empty => 0 - case Node(_, l, v, r) => l.size + 1 + r.size - } - - def isBlack = color == Black - - def blackHeight : Int = this match { - case Empty => 1 - case Node(Black, l, _, _) => l.blackHeight + 1 - case Node(Red, l, _, _) => l.blackHeight - } - - def max : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - maxOption(Some(v), maxOption(l.max, r.max)) - } - - def min : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - minOption(Some(v), minOption(l.max, r.max)) - } - - } - - def minOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 < i2) i1 else i2) - case _ => i1 orElse i2 - } - - def maxOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 > i2) i1 else i2) - case _ => i1 orElse i2 - } - - case object Empty extends Tree - case class Node(color_ : Color, left: Tree, value: Int, right: Tree) extends Tree - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(Black, l, _, r) => - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - case Node(Red, l, _, r) => - l.isBlack && r.isBlack && - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && l.blackHeight == r.blackHeight - case Empty => true - } - - def keysSorted(t : Tree) : Boolean = t match { - case Empty => true - case Node(_, l, v, r) => - keysSorted(l) && keysSorted(r) && - (l.max.getOrElse (v-1) < v) && - (r.min.getOrElse (v+1) > v) - } - - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - val newT = t match { - case Empty => Node(Red,Empty,x,Empty) - case n@Node(c,a,y,b) => - if (x < y) Node(c, ins(x, a), y, b) - else if (x == y) n - else Node(c, a, y, ins(x, b)) - } - newT match { - case Node(Black,Node(Red,Node(Red,a,xV,b),yV,c),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,Node(Red,a,xV,Node(Red,b,yV,c)),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,xV,d)) // FIXME: second xV -> zV - case Node(Black,a,xV,Node(Red,Node(Red,b,yV,c),zV,d)) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,b,yV,Node(Red,c,zV,d))) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case other => other - } - } ensuring (res => - res.content == t.content ++ Set(x) && - t.size <= res.size && - res.size <= t.size + 1 && - keysSorted(res) && - redDescHaveBlackChildren(res) && - blackBalanced(res) - ) - - def makeBlack(n: Tree): Tree = { - require( - redDescHaveBlackChildren(n) && - blackBalanced(n) && - keysSorted(n) - ) - n match { - case Node(Red,l,v,r) => Node(Black,l,v,r) - case _ => n - } - } ensuring { res => - res.isBlack && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - makeBlack(ins(x, t)) - } ensuring { res => - res.content == t.content ++ Set(x) && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - -} diff --git a/testcases/repair/RedBlackTree/RedBlackTree6.scala b/testcases/repair/RedBlackTree/RedBlackTree6.scala deleted file mode 100644 index 82e0372d5ef33a50adc7ac44652a9da1c37454f6..0000000000000000000000000000000000000000 --- a/testcases/repair/RedBlackTree/RedBlackTree6.scala +++ /dev/null @@ -1,159 +0,0 @@ -import leon.lang._ -import leon.collection._ -import annotation._ - -object RedBlackTree { - sealed abstract class Color - case object Red extends Color - case object Black extends Color - - sealed abstract class Tree { - /* We consider leaves to be black by definition */ - def color = this match { - case Empty => Black - case Node(c,_,_,_) => c - } - - def content : Set[Int] = this match { - case Empty => Set.empty - case Node(_, l, v, r) => l.content ++ Set(v) ++ r.content - } - - def size : Int = this match { - case Empty => 0 - case Node(_, l, v, r) => l.size + 1 + r.size - } - - def isBlack = color == Black - - def blackHeight : Int = this match { - case Empty => 1 - case Node(Black, l, _, _) => l.blackHeight + 1 - case Node(Red, l, _, _) => l.blackHeight - } - - def max : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - maxOption(Some(v), maxOption(l.max, r.max)) - } - - def min : Option[Int] = this match { - case Empty => None() - case Node(_, l, v, r) => - minOption(Some(v), minOption(l.max, r.max)) - } - - } - - def minOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 < i2) i1 else i2) - case _ => i1 orElse i2 - } - - def maxOption(i1 : Option[Int], i2 : Option[Int]) : Option[Int] = (i1, i2) match { - case (Some(i1), Some(i2)) => Some(if (i1 > i2) i1 else i2) - case _ => i1 orElse i2 - } - - case object Empty extends Tree - case class Node(color_ : Color, left: Tree, value: Int, right: Tree) extends Tree - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(Black, l, _, r) => - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - case Node(Red, l, _, r) => - l.isBlack && r.isBlack && - redNodesHaveBlackChildren(l) && - redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && l.blackHeight == r.blackHeight - case Empty => true - } - - def keysSorted(t : Tree) : Boolean = t match { - case Empty => true - case Node(_, l, v, r) => - keysSorted(l) && keysSorted(r) && - (l.max.getOrElse (v-1) < v) && - (r.min.getOrElse (v+1) > v) - } - - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - t match { - case Empty => Node(Red,Empty,x,Empty) - case n@Node(c,a,y,b) => - if (x < y) balance(Node(c, ins(x, a), y, b)) - else if (x == y) n - else balance(Node(c, a, y, ins(x, b))) - } - } ensuring (res => - res.content == t.content ++ Set(x) && - t.size <= res.size && - res.size <= t.size + 1 && - keysSorted(res) && - redDescHaveBlackChildren(res) && - blackBalanced(res) - ) - - def makeBlack(n: Tree): Tree = { - require( - redDescHaveBlackChildren(n) && - blackBalanced(n) && - keysSorted(n) - ) - n match { - case Node(Red,l,v,r) => Node(Black,l,v,r) - case _ => n - } - } ensuring { res => - res.isBlack && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && keysSorted(t)) - ins(x, t) // FIXME forgot makeBlack - } ensuring { res => - res.content == t.content ++ Set(x) && - redNodesHaveBlackChildren(res) && - blackBalanced(res) && - keysSorted(res) - } - - - def balance(t : Tree) : Tree = { - require(keysSorted(t)) - t match { - case Empty => Empty - case Node(Black,Node(Red,Node(Red,a,xV,b),yV,c),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,Node(Red,a,xV,Node(Red,b,yV,c)),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,Node(Red,b,yV,c),zV,d)) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,b,yV,Node(Red,c,zV,d))) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case other => other - } - } ensuring { res => - res.content == t.content && - keysSorted(res) - } - - -} diff --git a/testcases/repair/SecondsToTime/SecondsToTime.scala b/testcases/repair/SecondsToTime/SecondsToTime.scala deleted file mode 100644 index 151b6c51ae39c6c508d88d1921398b24b0b6873d..0000000000000000000000000000000000000000 --- a/testcases/repair/SecondsToTime/SecondsToTime.scala +++ /dev/null @@ -1,38 +0,0 @@ - -object SecondsToTime { - - def toSecs(h: Int, m: Int, s: Int) = h * 3600 + m * 60 + s - def prop(t: Int, h: Int, m: Int, s: Int) : Boolean = - toSecs(h, m, s) == t && - m >= 0 && m < 60 && - s >= 0 && s < 60 - - def secondsToTime(total : Int) = { - require(total >= 0) - rec(total, total, 0, 0) - } ensuring(_ match { case (h,m,s) => prop(total, h, m, s) }) - - def rec(total : Int, r : Int, h : Int, m : Int) : (Int, Int, Int) = { - require( - total == toSecs(h, m, r) && - m >= 0 && m < 60 && - h >= 0 && r >= 0 && - (m == 0 || r + m * 60 < 3600) - ) - - if(r >= 3600) { - rec(total, r - 3600, h + 1, m) - } else if(r >= 60) { - rec(total, r - 60, h, m + 1) - } else { - (h, m, r) - } - } ensuring { res => - val (h,m,s) = res - prop(total, h, m, s) - } - - - - -} diff --git a/testcases/repair/SecondsToTime/SecondsToTime1.scala b/testcases/repair/SecondsToTime/SecondsToTime1.scala deleted file mode 100644 index 8396cece587ff949e16bfae3fe517dc4f10d2857..0000000000000000000000000000000000000000 --- a/testcases/repair/SecondsToTime/SecondsToTime1.scala +++ /dev/null @@ -1,38 +0,0 @@ - -object SecondsToTime { - - def toSecs(h: Int, m: Int, s: Int) = h * 3600 + m * 60 + s - def prop(t: Int, h: Int, m: Int, s: Int) : Boolean = - toSecs(h, m, s) == t && - m >= 0 && m < 60 && - s >= 0 && s < 60 - - def secondsToTime(total : Int) = { - require(total >= 0) - rec(total, total, 0, 0) - } ensuring(_ match { case (h,m,s) => prop(total, h, m, s) }) - - def rec(total : Int, r : Int, h : Int, m : Int) : (Int, Int, Int) = { - require( - total == toSecs(h, m, r) && - m >= 0 && m < 60 && - h >= 0 && r >= 0 && - (m == 0 || r + m * 60 < 3600) - ) - - if(r >= 3600) { - rec(total, r - 3600, h , m) // FIXME: Should be h+1 - } else if(r >= 60) { - rec(total, r - 60, h, m + 1) - } else { - (h, m, r) - } - } ensuring { res => - val (h,m,s) = res - prop(total, h, m, s) - } - - - - -} diff --git a/testcases/repair/SecondsToTime/SecondsToTime2.scala b/testcases/repair/SecondsToTime/SecondsToTime2.scala deleted file mode 100644 index 9a9aa90fcf371e13f45f060b7b05aa98d1d2806d..0000000000000000000000000000000000000000 --- a/testcases/repair/SecondsToTime/SecondsToTime2.scala +++ /dev/null @@ -1,38 +0,0 @@ - -object SecondsToTime { - - def toSecs(h: Int, m: Int, s: Int) = h * 3600 + m * 60 + s - def prop(t: Int, h: Int, m: Int, s: Int) : Boolean = - toSecs(h, m, s) == t && - m >= 0 && m < 60 && - s >= 0 && s < 60 - - def secondsToTime(total : Int) = { - require(total >= 0) - rec(total, total, 0, 0) - } ensuring(_ match { case (h,m,s) => prop(total, h, m, s) }) - - def rec(total : Int, r : Int, h : Int, m : Int) : (Int, Int, Int) = { - require( - total == toSecs(h, m, r) && - m >= 0 && m < 60 && - h >= 0 && r >= 0 && - (m == 0 || r + m * 60 < 3600) - ) - - if(r >= 3600) { - rec(total, r - 3600, h + 1, m) - } else if(r >= 60) { - rec(total, r - 60, h, m )// FIXME : Should be m + 1 - } else { - (h, m, r) - } - } ensuring { res => - val (h,m,s) = res - prop(total, h, m, s) - } - - - - -} diff --git a/testcases/repair/SecondsToTime/SecondsToTime3.scala b/testcases/repair/SecondsToTime/SecondsToTime3.scala deleted file mode 100644 index 3b23952e8fe23f2ae83f58f0614d100c432e234c..0000000000000000000000000000000000000000 --- a/testcases/repair/SecondsToTime/SecondsToTime3.scala +++ /dev/null @@ -1,38 +0,0 @@ - -object SecondsToTime { - - def toSecs(h: Int, m: Int, s: Int) = h * 3600 + m * 60 + s - def prop(t: Int, h: Int, m: Int, s: Int) : Boolean = - toSecs(h, m, s) == t && - m >= 0 && m < 60 && - s >= 0 && s < 60 - - def secondsToTime(total : Int) = { - require(total >= 0) - rec(total, total, 0, 0) - } ensuring(_ match { case (h,m,s) => prop(total, h, m, s) }) - - def rec(total : Int, r : Int, h : Int, m : Int) : (Int, Int, Int) = { - require( - total == toSecs(h, m, r) && - m >= 0 && m < 60 && - h >= 0 && r >= 0 && - (m == 0 || r + m * 60 < 3600) - ) - - if(r >= 3600) { - rec(total, r - 3600, h + 1, m) - } else if(r > 60) { // FIXME (hard!) condition should be >= - rec(total, r - 60, h, m + 1) - } else { - (h, m, r) - } - } ensuring { res => - val (h,m,s) = res - prop(total, h, m, s) - } - - - - -} diff --git a/testcases/repair/SecondsToTime/SecondsToTime4.scala b/testcases/repair/SecondsToTime/SecondsToTime4.scala deleted file mode 100644 index 31843a58cfebe4e74d52f049e0da1432b4313c60..0000000000000000000000000000000000000000 --- a/testcases/repair/SecondsToTime/SecondsToTime4.scala +++ /dev/null @@ -1,38 +0,0 @@ - -object SecondsToTime { - - def toSecs(h: Int, m: Int, s: Int) = h * 3600 + m * 60 + s - def prop(t: Int, h: Int, m: Int, s: Int) : Boolean = - toSecs(h, m, s) == t && - m >= 0 && m < 60 && - s >= 0 && s < 60 - - def secondsToTime(total : Int) = { - require(total >= 0) - rec(total, total, 0, 0) - } ensuring(_ match { case (h,m,s) => prop(total, h, m, s) }) - - def rec(total : Int, r : Int, h : Int, m : Int) : (Int, Int, Int) = { - require( - total == toSecs(h, m, r) && - m >= 0 && m < 60 && - h >= 0 && r >= 0 && - (m == 0 || r + m * 60 < 3600) - ) - - if(r >= 3600) { - rec(total, r - 3600, h + 1, m) - } else if(r >= 60) { - rec(total, r - 60, h, m + 1) - } else { - (r, m, h) // FIXME: flipped the order in the tuple - } - } ensuring { res => - val (h,m,s) = res - prop(total, h, m, s) - } - - - - -} diff --git a/testcases/repair/SecondsToTime/SecondsToTimeMod.scala b/testcases/repair/SecondsToTime/SecondsToTimeMod.scala deleted file mode 100644 index 32e48611909238385185ad3c2b42d86e98b1ca26..0000000000000000000000000000000000000000 --- a/testcases/repair/SecondsToTime/SecondsToTimeMod.scala +++ /dev/null @@ -1,22 +0,0 @@ - -object SecondsToTime { - - def toSecs(h: Int, m: Int, s: Int) = h * 3600 + m * 60 + s - def prop(t: Int, h: Int, m: Int, s: Int) : Boolean = - toSecs(h, m, s) == t && - m >= 0 && m < 60 && - s >= 0 && s < 60 - - def secondsToTime(total : Int) = { - require(total >= 0) - val h = total / 3600 - val rest = total % 3600 - val m = rest / 60 - val s = rest % 60 - (h,m,s) - } ensuring { _ match { case (h,m,s) => - prop(total, h, m, s) - }} - - -} diff --git a/testcases/repair/SecondsToTime/SecondsToTimeMod1.scala b/testcases/repair/SecondsToTime/SecondsToTimeMod1.scala deleted file mode 100644 index 7df923d6bd23165088b68119a53c7866fd5b92b1..0000000000000000000000000000000000000000 --- a/testcases/repair/SecondsToTime/SecondsToTimeMod1.scala +++ /dev/null @@ -1,22 +0,0 @@ - -object SecondsToTime { - - def toSecs(h: Int, m: Int, s: Int) = h * 3600 + m * 60 + s - def prop(t: Int, h: Int, m: Int, s: Int) : Boolean = - toSecs(h, m, s) == t && - m >= 0 && m < 60 && - s >= 0 && s < 60 - - def secondsToTime(total : Int) = { - require(total >= 0) - val h = total / 3600 - val rest = total % 3600 - val m = rest / 60 - val s = rest / 60 // FIXME : / instead of % - (h,m,s) - } ensuring { _ match { case (h,m,s) => - prop(total, h, m, s) - }} - - -} diff --git a/testcases/repair/SecondsToTime/SecondsToTimeMod2.scala b/testcases/repair/SecondsToTime/SecondsToTimeMod2.scala deleted file mode 100644 index d54d58666087e0d6961632428d3e85b7303d3743..0000000000000000000000000000000000000000 --- a/testcases/repair/SecondsToTime/SecondsToTimeMod2.scala +++ /dev/null @@ -1,22 +0,0 @@ - -object SecondsToTime { - - def toSecs(h: Int, m: Int, s: Int) = h * 3600 + m * 60 + s - def prop(t: Int, h: Int, m: Int, s: Int) : Boolean = - toSecs(h, m, s) == t && - m >= 0 && m < 60 && - s >= 0 && s < 60 - - def secondsToTime(total : Int) = { - require(total >= 0) - val h = total / 3600 - val rest = total % 3600 - val m = rest / 60 - val s = total % 60 // FIXME: total instead of rest - (h,m,s) - } ensuring { _ match { case (h,m,s) => - prop(total, h, m, s) - }} - - -} diff --git a/testcases/repair/SortedList/SortedList.scala b/testcases/repair/SortedList/SortedList.scala deleted file mode 100644 index 1b79edd82c8bafe3c28a4ff1fb1b747dbe089299..0000000000000000000000000000000000000000 --- a/testcases/repair/SortedList/SortedList.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.collection._ -import leon.lang.synthesis._ - -object SortedList { - - def isSorted(l : List[Int]) : Boolean = l match { - case Cons(h1, tl@Cons(h2, _)) => h1 <= h2 && isSorted(tl) - case _ => true - } - - def merge(l1 : List[Int], l2 : List[Int]) : List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1,l2)) - else - Cons(h2, merge(l1,t2)) - } - } ensuring { res => - isSorted(res) && (res.content == l1.content ++ l2.content) - } - - - def split(l : List[Int]) : (List[Int], List[Int]) = { l match { - case Cons(h1, Cons(h2, tl)) => - val (t1,t2) = split(tl) - ( Cons(h1,t1), Cons(h2,t2) ) - case _ => (l, Nil[Int]()) - }} ensuring { res => - val (res1,res2) = res - res1.content ++ res2.content == l.content && - res1.size + res2.size == l.size && - res1.size <= res2.size + 1 && - res1.size >= res2.size - 1 - } - - def mergeSort(l : List[Int]) : List[Int] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case _ => - val (l1, l2) = split(l) - merge(mergeSort(l1),mergeSort(l2)) - }} ensuring { res => - res.content == l.content && - isSorted(res) - } - -} diff --git a/testcases/repair/SortedList/SortedList1.scala b/testcases/repair/SortedList/SortedList1.scala deleted file mode 100644 index 6d27fa8393d2df72cf645139f5d75df8b478a916..0000000000000000000000000000000000000000 --- a/testcases/repair/SortedList/SortedList1.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.collection._ -import leon.lang.synthesis._ - -object SortedList { - - def isSorted(l : List[Int]) : Boolean = l match { - case Cons(h1, tl@Cons(h2, _)) => h1 <= h2 && isSorted(tl) - case _ => true - } - - def merge(l1 : List[Int], l2 : List[Int]) : List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1,l2)) - else - Cons(h2, merge(l1,t2)) - } - } ensuring { res => - isSorted(res) && (res.content == l1.content ++ l2.content) - } - - - def split(l : List[Int]) : (List[Int], List[Int]) = { l match { - case Cons(h1, Cons(h2, tl)) => - val (t1,t2) = split(tl) - ( Cons(h1,t1), Cons(h2,t2) ) - case _ => (l, Nil[Int]()) - }} ensuring { res => - val (res1,res2) = res - res1.content ++ res2.content == l.content && - res1.size + res2.size == l.size && - res1.size <= res2.size + 1 && - res1.size >= res2.size - 1 - } - - def mergeSort(l : List[Int]) : List[Int] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case _ => - merge(mergeSort(split(l)._1), split(l)._2) // FIXME: Forgot to mergeSort l1 and l2 - }} ensuring { res => - res.content == l.content && - isSorted(res) - } - -} diff --git a/testcases/repair/SortedList/SortedList2.scala b/testcases/repair/SortedList/SortedList2.scala deleted file mode 100644 index 0219d16f3eda550b09867a8224319ca16f9cc3bc..0000000000000000000000000000000000000000 --- a/testcases/repair/SortedList/SortedList2.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.collection._ -import leon.lang.synthesis._ - -object SortedList { - - def isSorted(l : List[Int]) : Boolean = l match { - case Cons(h1, tl@Cons(h2, _)) => h1 <= h2 && isSorted(tl) - case _ => true - } - - def merge(l1 : List[Int], l2 : List[Int]) : List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1,l2)) - else - Cons(h1, merge(l1,t2)) // FIXME: h1 instead of h2 - } - } ensuring { res => - isSorted(res) && (res.content == l1.content ++ l2.content) - } - - - def split(l : List[Int]) : (List[Int], List[Int]) = { l match { - case Cons(h1, Cons(h2, tl)) => - val (t1,t2) = split(tl) - ( Cons(h1,t1), Cons(h2,t2) ) - case _ => (l, Nil[Int]()) - }} ensuring { res => - val (res1,res2) = res - res1.content ++ res2.content == l.content && - res1.size + res2.size == l.size && - res1.size <= res2.size + 1 && - res1.size >= res2.size - 1 - } - - def mergeSort(l : List[Int]) : List[Int] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case _ => - val (l1, l2) = split(l) - merge(mergeSort(l1),mergeSort(l2)) - }} ensuring { res => - res.content == l.content && - isSorted(res) - } - -} diff --git a/testcases/repair/SortedList/SortedList3.scala b/testcases/repair/SortedList/SortedList3.scala deleted file mode 100644 index 175683215f6bf03be6610fa1455967379f7b5dc9..0000000000000000000000000000000000000000 --- a/testcases/repair/SortedList/SortedList3.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.collection._ -import leon.lang.synthesis._ - -object SortedList { - - def isSorted(l : List[Int]) : Boolean = l match { - case Cons(h1, tl@Cons(h2, _)) => h1 <= h2 && isSorted(tl) - case _ => true - } - - def merge(l1 : List[Int], l2 : List[Int]) : List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1, t1), Cons(h2,t2)) => - //if (h1 <= h2) // FIXME : didn't EqSplit here - Cons(h1, merge(t1,l2)) - //else - //Cons(h2, merge(l1,t2)) - } - } ensuring { res => - isSorted(res) && (res.content == l1.content ++ l2.content) - } - - - def split(l : List[Int]) : (List[Int], List[Int]) = { l match { - case Cons(h1, Cons(h2, tl)) => - val (t1,t2) = split(tl) - ( Cons(h1,t1), Cons(h2,t2) ) - case _ => (l, Nil[Int]()) - }} ensuring { res => - val (res1,res2) = res - res1.content ++ res2.content == l.content && - res1.size + res2.size == l.size && - res1.size <= res2.size + 1 && - res1.size >= res2.size - 1 - } - - def mergeSort(l : List[Int]) : List[Int] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case _ => - val (l1, l2) = split(l) - merge(mergeSort(l1),mergeSort(l2)) - }} ensuring { res => - res.content == l.content && - isSorted(res) - } - -} diff --git a/testcases/repair/SortedList/SortedList4.scala b/testcases/repair/SortedList/SortedList4.scala deleted file mode 100644 index 4a2ba301c0a66aeaa94f55e60fabb5d92f9e78a3..0000000000000000000000000000000000000000 --- a/testcases/repair/SortedList/SortedList4.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.collection._ -import leon.lang.synthesis._ - -object SortedList { - - def isSorted(l : List[Int]) : Boolean = l match { - case Cons(h1, tl@Cons(h2, _)) => h1 <= h2 && isSorted(tl) - case _ => true - } - - def merge(l1 : List[Int], l2 : List[Int]) : List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1,l2)) - else - Cons(h2, merge(l1,t2)) - } - } ensuring { res => - isSorted(res) && (res.content == l1.content ++ l2.content) - } - - - def split(l : List[Int]) : (List[Int], List[Int]) = { l match { - case Cons(h1, tl) => - val (t1,t2) = split(tl) - ( Cons(h1,t1), t2 ) - // FIXME (hard) : this is nonsense, just places everything on the first list - case _ => (l, Nil[Int]()) - }} ensuring { res => - val (res1,res2) = res - res1.content ++ res2.content == l.content && - res1.size + res2.size == l.size && - res1.size <= res2.size + 1 && - res1.size >= res2.size - 1 - } - - def mergeSort(l : List[Int]) : List[Int] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case _ => - val (l1, l2) = split(l) - merge(mergeSort(l1),mergeSort(l2)) - }} ensuring { res => - res.content == l.content && - isSorted(res) - } - -} diff --git a/testcases/repair/SortedList/SortedList5.scala b/testcases/repair/SortedList/SortedList5.scala deleted file mode 100644 index b0310ae8c3ada40ad4ac6a547258289cfa8830dd..0000000000000000000000000000000000000000 --- a/testcases/repair/SortedList/SortedList5.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.collection._ -import leon.lang.synthesis._ - -object SortedList { - - def isSorted(l : List[Int]) : Boolean = l match { - case Cons(h1, tl@Cons(h2, _)) => h1 <= h2 && isSorted(tl) - case _ => true - } - - def merge(l1 : List[Int], l2 : List[Int]) : List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1,l2)) - else - Cons(h2, merge(l1,t2)) - } - } ensuring { res => - isSorted(res) && (res.content == l1.content ++ l2.content) - } - - - def split(l : List[Int]) : (List[Int], List[Int]) = { l match { - case Cons(h1, Cons(h2, tl)) => - val (t1,t2) = split(tl) - ( t1, Cons(h2,t2) ) // FIXME: t1 should be h1 :: t1 - case _ => (l, Nil[Int]()) - }} ensuring { res => - val (res1,res2) = res - res1.content ++ res2.content == l.content && - res1.size + res2.size == l.size && - res1.size <= res2.size + 1 && - res1.size >= res2.size - 1 - } - - def mergeSort(l : List[Int]) : List[Int] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case _ => - val (l1, l2) = split(l) - merge(mergeSort(l1),mergeSort(l2)) - }} ensuring { res => - res.content == l.content && - isSorted(res) - } - -} diff --git a/testcases/repair/SortedList/SortedList6.scala b/testcases/repair/SortedList/SortedList6.scala deleted file mode 100644 index 523cee08c5aeaff45746574af4ed6369e6f3e9ca..0000000000000000000000000000000000000000 --- a/testcases/repair/SortedList/SortedList6.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.collection._ -import leon.lang.synthesis._ - -object SortedList { - - def isSorted(l : List[Int]) : Boolean = l match { - case Cons(h1, tl@Cons(h2, _)) => h1 <= h2 && isSorted(tl) - case _ => true - } - - def merge(l1 : List[Int], l2 : List[Int]) : List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1,l2)) - else - Cons(h2, merge(t1,t2)) // FIXME : t1 instead l1 - } - } ensuring { res => - isSorted(res) && (res.content == l1.content ++ l2.content) - } - - - def split(l : List[Int]) : (List[Int], List[Int]) = { l match { - case Cons(h1, Cons(h2, tl)) => - val (t1,t2) = split(tl) - ( Cons(h1,t1), Cons(h2,t2) ) - case _ => (l, Nil[Int]()) - }} ensuring { res => - val (res1,res2) = res - res1.content ++ res2.content == l.content && - res1.size + res2.size == l.size && - res1.size <= res2.size + 1 && - res1.size >= res2.size - 1 - } - - def mergeSort(l : List[Int]) : List[Int] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case _ => - val (l1, l2) = split(l) - merge(mergeSort(l1),mergeSort(l2)) - }} ensuring { res => - res.content == l.content && - isSorted(res) - } - -} diff --git a/testcases/repair/SortedList/SortedList7.scala b/testcases/repair/SortedList/SortedList7.scala deleted file mode 100644 index fbd78cf8ed9eaa2ee11db3394e253b51775431dd..0000000000000000000000000000000000000000 --- a/testcases/repair/SortedList/SortedList7.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.collection._ -import leon.lang.synthesis._ - -object SortedList { - - def isSorted(l : List[Int]) : Boolean = l match { - case Cons(h1, tl@Cons(h2, _)) => h1 <= h2 && isSorted(tl) - case _ => true - } - - def merge(l1 : List[Int], l2 : List[Int]) : List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - // FIXME : swap the branches - Cons(h2, merge(l1,t2)) - else - Cons(h1, merge(t1,l2)) - } - } ensuring { res => - isSorted(res) && (res.content == l1.content ++ l2.content) - } - - - def split(l : List[Int]) : (List[Int], List[Int]) = { l match { - case Cons(h1, Cons(h2, tl)) => - val (t1,t2) = split(tl) - ( Cons(h1,t1), Cons(h2,t2) ) - case _ => (l, Nil[Int]()) - }} ensuring { res => - val (res1,res2) = res - res1.content ++ res2.content == l.content && - res1.size + res2.size == l.size && - res1.size <= res2.size + 1 && - res1.size >= res2.size - 1 - } - - def mergeSort(l : List[Int]) : List[Int] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case _ => - val (l1, l2) = split(l) - merge(mergeSort(l1),mergeSort(l2)) - }} ensuring { res => - res.content == l.content && - isSorted(res) - } - -} diff --git a/testcases/repair/bijections/FirstRepair.scala b/testcases/repair/bijections/FirstRepair.scala deleted file mode 100644 index ea66d458d4f1d1a8a24132c5a4d21df640f0fd1b..0000000000000000000000000000000000000000 --- a/testcases/repair/bijections/FirstRepair.scala +++ /dev/null @@ -1,44 +0,0 @@ -/* Viktor Kuncak, 2015-08-27 - I tried to formalize linear bijection function for nested lists, - based on the paper: - - Ivan Kuraj, Viktor Kuncak, and Daniel Jackson. - Programming with enumerable sets of structures. In OOPSLA, 2015. - - Leon found a counterexample (which I did not quite understand), but - then synthesized an untrusted solution that looked similar (a bit - more concise in a few places) and had the role of two elements of - the tuple reversed. This made me realize I confused the order of - elements in the tuple. - -*/ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object DisperseBijection { - def totalSize[A](l: List[List[A]]): BigInt = { - l.map(_.size).foldRight(BigInt(0))(_ + _) - } ensuring(res => res >= 0) - - def lin1[A](l: List[List[A]], i : BigInt): (BigInt, BigInt) = { - require (0 <= i && i < totalSize(l)) - l match { - case Cons(h, t) => { - val s = h.size - if (i < s) (i, BigInt(0)) - else { - val (x1,y1) = lin1[A](t, i-s) - (x1, y1+1) - } - } - } - }.ensuring((res:(BigInt,BigInt)) => { res match { - case (x,y) => { - BigInt(0) <= x && x < l.size && l(x)(y) == flatten(l)(i) - } - }}) - -} \ No newline at end of file diff --git a/testcases/repair/features/focusIfCondition.scala b/testcases/repair/features/focusIfCondition.scala deleted file mode 100644 index 6209b40362483b327fb9199e6430a8b23cf75fd8..0000000000000000000000000000000000000000 --- a/testcases/repair/features/focusIfCondition.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Test { - def focusCond(a: BigInt) = { - if (a < 0) { - -a + 1 - } else { - a - } - } ensuring { - _ > 0 - } -} diff --git a/testcases/repair/features/focusIfElse.scala b/testcases/repair/features/focusIfElse.scala deleted file mode 100644 index f45927f3db178fc72a00757e8034b18558daa546..0000000000000000000000000000000000000000 --- a/testcases/repair/features/focusIfElse.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Test { - def focusCond(a: BigInt) = { - if (a > 0) { - a - } else { - BigInt(-1) - } - } ensuring { - _ > 0 - } -} diff --git a/testcases/repair/features/focusIfThen.scala b/testcases/repair/features/focusIfThen.scala deleted file mode 100644 index 211c2b9004c47436140b4e41aaa18f8dfd609ea5..0000000000000000000000000000000000000000 --- a/testcases/repair/features/focusIfThen.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Test { - def focusCond(a: BigInt) = { - if (a <= 0) { - BigInt(-1) - } else { - a - } - } ensuring { - _ > 0 - } -} diff --git a/testcases/repair/features/focusLetBody.scala b/testcases/repair/features/focusLetBody.scala deleted file mode 100644 index 2a5ed017d5cd7abf53961135db0bad80a6ae0c1a..0000000000000000000000000000000000000000 --- a/testcases/repair/features/focusLetBody.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test { - def focusCond(a: BigInt) = { - val tmp = -a - tmp - } ensuring { - _ > 0 - } -} diff --git a/testcases/repair/features/focusMatch.scala b/testcases/repair/features/focusMatch.scala deleted file mode 100644 index 7795a975ec8ff53a7404f1f897a1e239865f0a99..0000000000000000000000000000000000000000 --- a/testcases/repair/features/focusMatch.scala +++ /dev/null @@ -1,16 +0,0 @@ -import leon.lang._ - -object Test { - def focusMatch(a: BigInt, b: BigInt) = { - (a, b) match { - case (otherA, BigInt(0)) => otherA - case _ => a+1 - } - } ensuring { - res => if (b == 0) { - res == 0 - } else { - res == a+1 - } - } -} diff --git a/testcases/repair/features/splitIf.scala b/testcases/repair/features/splitIf.scala deleted file mode 100644 index 18167f777117fb7686c834c324f21c5fe3e8a297..0000000000000000000000000000000000000000 --- a/testcases/repair/features/splitIf.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Test { - def focusCond(a: BigInt) = { - if (a <= 0) { - (a, BigInt(0)) - } else { - (a, BigInt(0)) - } - } ensuring { - res => res._1 == a && res._2 > 1 - } -} diff --git a/testcases/repair/features/splitMatch.scala b/testcases/repair/features/splitMatch.scala deleted file mode 100644 index 5a6a67758d9b35cceae17b172d35690b6d985e44..0000000000000000000000000000000000000000 --- a/testcases/repair/features/splitMatch.scala +++ /dev/null @@ -1,13 +0,0 @@ -import leon.lang._ - -object Test { - def focusCond(a: BigInt) = { - a match { - case BigInt(1) => (BigInt(2), BigInt(0)) - case BigInt(2) => (BigInt(2), BigInt(0)) - case _ => (BigInt(0), BigInt(0)) - } - } ensuring { - res => res._1 == a && res._2 > 1 - } -} diff --git a/testcases/repair/inria/Desugar-io b/testcases/repair/inria/Desugar-io deleted file mode 100644 index 21dd7bc39bcddca22dedf6ec1179dc6700fcbce7..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/Desugar-io +++ /dev/null @@ -1,69 +0,0 @@ -INPUT: -def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) // FIXME forgot Neg - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) -}} ensuring { res => - sem(res) == Semantics.semUntyped(e) && ((e,res) passes { - case Trees.Minus(Trees.IntLiteral(42), Trees.IntLiteral(i)) => - Plus(Literal(42), Neg(Literal(i))) - }) -} - - -COMMAND: -leon Desugar2.scala --repair --functions=desugar --solvers=fairz3:enum --timeout=5 - - -OUTPUT: -(Focused Problem:) -[ Info ] ⟦ e;lhs;rhs, ↓ desugar(e) && ⊙ {Plus(desugar(lhs), desugar(rhs))} && ¬e.isInstanceOf[Plus] && e.isInstanceOf[Minus] && lhs == e.lhs && rhs == e.rhs ≺ ⟨ sem(res) == semUntyped(e) && (e, res) passes { - case Minus(IntLiteral(42), IntLiteral(i)) => - Plus(Literal(42), Neg(Literal(i))) - } ⟩ res ⟧ -... -(Solution:) -[ Info ] Found trusted solution! -[ Info ] ============================== Repair successful: ============================== -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] Plus(desugar(lhs), Neg(desugar(rhs))) -[ Info ] ================================= In context: ================================= -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] @induct - def desugar(e : Trees.Expr): SimpleE = { - e match { - case Trees.Plus(lhs, rhs) => - Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => - Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => - LessThan(desugar(lhs), desugar(rhs)) - case Trees.And(lhs, rhs) => - Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or(lhs, rhs) => - Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => - Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => - Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => - Literal(v) - case Trees.BoolLiteral(b) => - Literal(b2i(b)) - } - } ensuring { - (res : SimpleE) => sem(res) == semUntyped(e) && (e, res) passes { - case Trees.Minus(Trees.IntLiteral(42), Trees.IntLiteral(i)) => - Plus(Literal(42), Neg(Literal(i))) - } - } diff --git a/testcases/repair/inria/Desugar.scala b/testcases/repair/inria/Desugar.scala deleted file mode 100644 index 19cd3305ab3e7a63fbb4f35c924819a143838aa3..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/Desugar.scala +++ /dev/null @@ -1,172 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : Int = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean) = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : Int = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else 0 - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else 1 - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : Int) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : Int = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} diff --git a/testcases/repair/inria/Desugar2-io b/testcases/repair/inria/Desugar2-io deleted file mode 100644 index 18580e316b68a67798d20da42d073c880709c53e..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/Desugar2-io +++ /dev/null @@ -1,62 +0,0 @@ -INPUT: -def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(1)) // FIXME 1 instead of 0 - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) -}} ensuring { res => - sem(res) == Semantics.semUntyped(e) && ((e,res) passes { - case Trees.Minus(Trees.IntLiteral(42), Trees.IntLiteral(i)) => - Plus(Literal(42), Neg(Literal(i))) - }) -} - - -COMMAND: -leon --repair --timeout=5 Desugar5.scala --functions=desugar - -OUTPUT: -(Focused Problem:) -[ Info ] ⟦ e;lhs;rhs, ↓ desugar(e) && ⊙ {Ite(desugar(lhs), desugar(rhs), Literal(1))} && ¬e.isInstanceOf[Plus] && ¬e.isInstanceOf[Minus] && ¬e.isInstanceOf[LessThan] && e.isInstanceOf[And] && lhs == e.lhs && rhs == e.rhs ≺ ⟨ sem(res) == semUntyped(e) ⟩ res ⟧ - -(Solution:) -[ Info ] Found trusted solution! -[ Info ] ============================== Repair successful: ============================== -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] Ite(desugar(lhs), desugar(rhs), Literal(0)) -[ Info ] ================================= In context: ================================= -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] @induct - def desugar(e : Trees.Expr): SimpleE = { - e match { - case Trees.Plus(lhs, rhs) => - Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => - Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => - LessThan(desugar(lhs), desugar(rhs)) - case Trees.And(lhs, rhs) => - Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or(lhs, rhs) => - Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => - Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => - Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => - Literal(v) - case Trees.BoolLiteral(b) => - Literal(b2i(b)) - } - } ensuring { - (res : SimpleE) => sem(res) == semUntyped(e) - } diff --git a/testcases/repair/inria/FirstIndexOf-io b/testcases/repair/inria/FirstIndexOf-io deleted file mode 100644 index 587199f2bd7457045b83e74931c949f8d5008628..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/FirstIndexOf-io +++ /dev/null @@ -1,87 +0,0 @@ -INPUT: - -def firstIndexOf(l: List[Int], v: Int): Int = { - l match { - case Cons(h, t) if v == h => 0 - case Cons(h, t) => - if (firstIndexOf(t, v) >= 0) { - firstIndexOf(t, v) // Should be +1 (Solves with CEGIS) - } else { - -1 - } - case Nil() => - -1 - } -} ensuring { - (res: Int) => (if (l.content contains v) { - l.size > res && l.apply(res) == v - } else { - res == -1 - }) && (((l,v), res) passes { - case (Cons(0, Cons(1, Cons(2, Cons(3, Nil())))), 3) => 3 - case (Cons(0, Cons(2, Cons(3, Cons(1, Nil())))), 1) => 3 - case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 1) => 1 - case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 2) => -1 - }) -} - - -COMMAND: -leon FirstIndexOf1.scala --repair --solvers=fairz3:enum --timeout=5 - -OUTPUT: -(Focused problem:) - -[ Info ] ⟦ v;l;t;h, ↓ firstIndexOf(l, v) && ⊙ {firstIndexOf(t, v)} && ¬(l.isInstanceOf[Cons[Int]] && v == l.h) && l.isInstanceOf[Cons[Int]] && h == l.h && t == l.t && firstIndexOf(t, v) >= 0 ≺ ⟨ (if (v ∈ l.content()) { - l.size() > res && l.apply(res) == v - } else { - res == -1 - }) && ((l, v), res) passes { - case (Cons(0, Cons(1, Cons(2, Cons(3, Nil())))), 3) => - 3 - case (Cons(0, Cons(2, Cons(3, Cons(1, Nil())))), 1) => - 3 - case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 1) => - 1 - case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 2) => - -1 - } ⟩ res ⟧ - - -(Solution) -[ Info ] Found trusted solution! -[ Info ] ============================== Repair successful: ============================== -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] firstIndexOf(t, v) + 1 -[ Info ] ================================= In context: ================================= -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] def firstIndexOf(l : List[Int], v : Int): Int = { - l match { - case Cons(h, t) if v == h => - 0 - case Cons(h, t) => - if (firstIndexOf(t, v) >= 0) { - firstIndexOf(t, v) + 1 - } else { - -1 - } - case Nil() => - -1 - } - } ensuring { - (res : Int) => (if (l.content().contains(e)) { - l.size() > res && l.apply(res) == v - } else { - res == -1 - }) && ((l, v), res) passes { - case (Cons(0, Cons(1, Cons(2, Cons(3, Nil())))), 3) => - 3 - case (Cons(0, Cons(2, Cons(3, Cons(1, Nil())))), 1) => - 3 - case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 1) => - 1 - case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 2) => - -1 - } - } - diff --git a/testcases/repair/inria/FirstIndexOf.scala b/testcases/repair/inria/FirstIndexOf.scala deleted file mode 100644 index 3239632e45a4d15c24f44dea3ee735077690e697..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/FirstIndexOf.scala +++ /dev/null @@ -1,31 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon.lang.synthesis._ - - -object FirstIndexOf { - def firstIndexOf(l: List[Int], v: Int): BigInt = { - l match { - case Cons(h, t) if v == h => BigInt(0) - case Cons(h, t) => - if (firstIndexOf(t, v) >= 0) { - firstIndexOf(t, v)+1 - } else { - BigInt(-1) - } - case Nil() => - BigInt(-1) - } - } ensuring { - (res: BigInt) => (if (l.content contains v) { - l.size > res && l.apply(res) == v - } else { - res == -1 - }) && (((l,v), res) passes { - case (Cons(0, Cons(1, Cons(2, Cons(3, Nil())))), 3) => 3 - case (Cons(0, Cons(2, Cons(3, Cons(1, Nil())))), 1) => 3 - case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 1) => 1 - case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 2) => -1 - }) - } -} diff --git a/testcases/repair/inria/HeapSort-io b/testcases/repair/inria/HeapSort-io deleted file mode 100644 index af9f8b12419c89b56d040f62a87e613dc8f735f1..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/HeapSort-io +++ /dev/null @@ -1,61 +0,0 @@ -INPUT: - -private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 + v2 > 0) // FIXME: Nonsense, should be v1 >= v2 - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } -} ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content -} - - -COMMAND: -leon HeapSort7.scala --repair --functions=merge - -OUTPUT: - -(focused problem/ condition fails) -[ Info ] ⟦ l1;r2;v1;l2;h1;v2;h2;r1, ↓ merge(h1, h2) && ⊙ {(v1 + v2 > 0)} && hasLeftistProperty(h1) && hasLeftistProperty(h2) && hasHeapProperty(h1) && hasHeapProperty(h2) && ¬h1.isInstanceOf[Leaf] && ¬h2.isInstanceOf[Leaf] && h1.isInstanceOf[Node] && v1 == h1.value && l1 == h1.left && r1 == h1.right && h2.isInstanceOf[Node] && v2 == h2.value && l2 == h2.left && r2 == h2.right ≺ ⟨ val res = if (cond) { - makeN(v1, l1, merge(r1, h2)) - } else { - makeN(v2, l2, merge(h1, r2)) - }; - hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res) && h1.content() ∪ h2.content() == res.content() ⟩ cond ⟧ - -(solution) -[ Info ] Found trusted solution! -[ Info ] ============================== Repair successful: ============================== -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] v2 <= v1 -[ Info ] ================================= In context: ================================= -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] def merge(h1 : Heap, h2 : Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2) && hasHeapProperty(h1) && hasHeapProperty(h2)) - (h1, h2) match { - case (Leaf(), _) => - h2 - case (_, Leaf()) => - h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if (v2 <= v1) { - makeN(v1, l1, merge(r1, h2)) - } else { - makeN(v2, l2, merge(h1, r2)) - } - } - } ensuring { - (res : Heap) => hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res) && h1.content() ++ h2.content() == res.content() - } - diff --git a/testcases/repair/inria/HeapSort.scala b/testcases/repair/inria/HeapSort.scala deleted file mode 100644 index 01d2616894cea1f97629afa2359c0a1e6ebe2f92..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/HeapSort.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object HeapSort { - - sealed abstract class Heap { - val rank : Int = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[Int] = this match { - case Leaf() => Set[Int]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:Int, left: Heap, right: Heap) extends Heap - - def max(i1 : Int, i2 : Int) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): Int = { t match { - case Leaf() => 0 - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: Int, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: Int, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[Int] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/repair/inria/PropLogic-io b/testcases/repair/inria/PropLogic-io deleted file mode 100644 index 517099269c80202dcc521cec11cc7d704a530bc3..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/PropLogic-io +++ /dev/null @@ -1,84 +0,0 @@ -INPUT: - -def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - // FIXME: forgot to handle the Not(Not(_)) case - case other => other -}} ensuring { res => - isNNF(res) && ((formula, res) passes { - case Not(Not(Not(Const(a)))) => Const(!a) - }) -} - -COMMAND: -leon PropLogic2.scala --repair --functions=nnf --solvers=fairz3:enum - - -OUTPUT: -(Focused Problem:) -(Comment: - There is something here that is not legal Scala, namely formula.f - The path condition makes sure formula is indeed a Not so it has the f field, but Scala would require a typecast here. -) -[ Info ] ⟦ formula;other, ↓ nnf(formula) && ⊙ {other} && ¬(formula.isInstanceOf[Not] && formula.f.isInstanceOf[And]) && ¬(formula.isInstanceOf[Not] && formula.f.isInstanceOf[Or]) && ¬(formula.isInstanceOf[Not] && formula.f.isInstanceOf[Const]) && ¬formula.isInstanceOf[And] && ¬formula.isInstanceOf[Or] && other == formula ≺ ⟨ isNNF(res) && (formula, res) passes { - case Not(Not(Not(Const(a)))) => - Const(¬a) - } ⟩ res ⟧ - -(Solution:) -[ Info ] Found trusted solution! -[ Info ] ============================== Repair successful: ============================== -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] formula match { - case Const(v) => - other - case Literal(id) => - other - case Not(f) => - f match { - case Literal(id) => - nnf(Literal(id)) - case Not(f1) => - nnf(f1) - } - } -[ Info ] ================================= In context: ================================= -[ Info ] --------------------------------- Solution 1: --------------------------------- -[ Info ] def nnf(formula : Formula): Formula = { - formula match { - case Not(And(lhs, rhs)) => - Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => - And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => - Const(!v) - case And(lhs, rhs) => - And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => - Or(nnf(lhs), nnf(rhs)) - case other => - formula match { - case Const(v) => - other - case Literal(id) => - other - case Not(f) => - f match { - case Literal(id) => - nnf(Literal(id)) - case Not(f1) => - nnf(f1) - } - } - } - } ensuring { - (res : Formula) => isNNF(res) && (formula, res) passes { - case Not(Not(Not(Const(a)))) => - Const(!a) - } - } - diff --git a/testcases/repair/inria/PropLogic.scala b/testcases/repair/inria/PropLogic.scala deleted file mode 100644 index 718a36e89b1fb70e7eb1c4cfc0a35520f7f953c4..0000000000000000000000000000000000000000 --- a/testcases/repair/inria/PropLogic.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: Int) extends Formula - - def size(f : Formula) : Int = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => 1 - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[Int]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => nnf(e) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/repair/outputSummary.txt b/testcases/repair/outputSummary.txt deleted file mode 100644 index 9cbab52d228169bfb7c16fdd32de318cdf4510aa..0000000000000000000000000000000000000000 --- a/testcases/repair/outputSummary.txt +++ /dev/null @@ -1,1149 +0,0 @@ -%%% Compiler1.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Plus(desugar(lhs), desugar(rhs)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -@induct -def desugar(e : Trees.Expr): SimpleE = { - e match { - case Trees.Plus(lhs, rhs) => - Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => - Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => - LessThan(desugar(lhs), desugar(rhs)) - case Trees.And(lhs, rhs) => - Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or(lhs, rhs) => - Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => - Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => - Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => - Literal(v) - case Trees.BoolLiteral(b) => - Literal(b2i(b)) - } -} ensuring { - (res : SimpleE) => (e, res) passes { - case Trees.Plus(Trees.IntLiteral(i), Trees.Minus(Trees.IntLiteral(j), Trees.IntLiteral(42))) => - Plus(Literal(i), Plus(Literal(j), Neg(Literal(42)))) - } && sem(res) == semUntyped(e) -} - -%%% Compiler2.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Plus(None[SimpleE]().getOrElse(desugar(lhs)), Neg(desugar(rhs))) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -@induct -def desugar(e : Trees.Expr): SimpleE = { - e match { - case Trees.Plus(lhs, rhs) => - Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => - Plus(None[SimpleE]().getOrElse(desugar(lhs)), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => - LessThan(desugar(lhs), desugar(rhs)) - case Trees.And(lhs, rhs) => - Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or(lhs, rhs) => - Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => - Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => - Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => - Literal(v) - case Trees.BoolLiteral(b) => - Literal(b2i(b)) - } -} ensuring { - (res : SimpleE) => sem(res) == semUntyped(e) && (e, res) passes { - case Trees.Minus(Trees.IntLiteral(42), Trees.IntLiteral(i)) => - Plus(Literal(42), Neg(Literal(i))) - } -} - -%%% Compiler3.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Ite(desugar(cond), desugar(thn), desugar(els)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -@induct -def desugar(e : Trees.Expr): SimpleE = { - e match { - case Trees.Plus(lhs, rhs) => - Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => - Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => - LessThan(desugar(lhs), desugar(rhs)) - case Trees.And(lhs, rhs) => - Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or(lhs, rhs) => - Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => - Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => - Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => - Literal(v) - case Trees.BoolLiteral(b) => - Literal(b2i(b)) - } -} ensuring { - (res : SimpleE) => sem(res) == semUntyped(e) -} - -%%% Compiler4.scala -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Ite(desugar(e), Literal(0), Literal(1)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -@induct -def desugar(e : Trees.Expr): SimpleE = { - e match { - case Trees.Plus(lhs, rhs) => - Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => - Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => - LessThan(desugar(lhs), desugar(rhs)) - case Trees.And(lhs, rhs) => - Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or(lhs, rhs) => - Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => - Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => - Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => - Literal(v) - case Trees.BoolLiteral(b) => - Literal(b2i(b)) - } -} ensuring { - (res : SimpleE) => sem(res) == semUntyped(e) -} - -%%% Compiler5.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -e match { - case Plus(lhs, rhs) => - Plus(desugar(lhs), desugar(rhs)) - case Minus(lhs, rhs) => - Plus(desugar(lhs), Neg(desugar(rhs))) - case LessThan(lhs, rhs) => - LessThan(desugar(lhs), desugar(rhs)) - case And(lhs, rhs) => - Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Or(lhs, rhs) => - Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Not(e) => - Ite(desugar(e), Literal(0), Literal(1)) - case Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Ite(cond, thn, els) => - Ite(desugar(cond), desugar(thn), desugar(els)) - case IntLiteral(v) => - Literal(v) - case BoolLiteral(b) => - Literal(b2i(b)) -} -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -@induct -def desugar(e : Trees.Expr): SimpleE = { - e match { - case Trees.Plus(lhs, rhs) => - Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => - Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => - LessThan(desugar(lhs), desugar(rhs)) - case Trees.And(lhs, rhs) => - Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or(lhs, rhs) => - Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => - Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => - Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => - Literal(v) - case Trees.BoolLiteral(b) => - Literal(b2i(b)) - } -} ensuring { - (res : SimpleE) => sem(res) == semUntyped(e) -} - -%%% Compiler6.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -IntLiteral(a + b) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -@induct -def simplify(e : Trees.Expr): Trees.Expr = { - e match { - case Trees.And(Trees.BoolLiteral(false), _) => - Trees.BoolLiteral(false) - case Trees.Or(Trees.BoolLiteral(true), _) => - Trees.BoolLiteral(true) - case Trees.Plus(Trees.IntLiteral(a), Trees.IntLiteral(b)) => - Trees.IntLiteral(a + b) - case Trees.Not(Trees.Not(Trees.Not(a))) => - Trees.Not(a) - case e => - e - } -} ensuring { - (res : Trees.Expr) => eval(res) == eval(e) -} - -%%% Compiler7.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -BoolLiteral(true) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -@induct -def simplify(e : Trees.Expr): Trees.Expr = { - e match { - case Trees.And(Trees.BoolLiteral(false), _) => - Trees.BoolLiteral(false) - case Trees.Or(Trees.BoolLiteral(true), _) => - Trees.BoolLiteral(true) - case Trees.Plus(Trees.IntLiteral(a), Trees.IntLiteral(b)) => - Trees.IntLiteral(a + b) - case Trees.Not(Trees.Not(Trees.Not(a))) => - Trees.Not(a) - case e => - e - } -} ensuring { - (res : Trees.Expr) => eval(res) == eval(e) && (e, res) passes { - case Trees.Or(Trees.BoolLiteral(true), e) => - Trees.BoolLiteral(true) - } -} - -%%% Heap3.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -v2 >= v1 -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(h1 : Heap, h2 : Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2) && hasHeapProperty(h1) && hasHeapProperty(h2)) - (h1, h2) match { - case (Leaf(), _) => - h2 - case (_, Leaf()) => - h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if (v2 >= v1) { - makeN(v2, l2, merge(h1, r2)) - } else { - makeN(v1, l1, merge(r1, h2)) - } - } -} ensuring { - (res : Heap) => hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res) && h1.content() ++ h2.content() == res.content() -} - -%%% Heap4.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -h1 -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(h1 : Heap, h2 : Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2) && hasHeapProperty(h1) && hasHeapProperty(h2)) - (h1, h2) match { - case (Leaf(), _) => - h2 - case (_, Leaf()) => - h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if (v1 >= v2) { - makeN(v1, l1, merge(r1, h2)) - } else { - makeN(v2, l2, merge(h1, r2)) - } - } -} ensuring { - (res : Heap) => hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res) && h1.content() ++ h2.content() == res.content() -} - -%%% Heap5.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -v2 <= v1 -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(h1 : Heap, h2 : Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2) && hasHeapProperty(h1) && hasHeapProperty(h2)) - (h1, h2) match { - case (Leaf(), _) => - h2 - case (_, Leaf()) => - h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if (v2 <= v1) { - makeN(v1, l1, merge(r1, h2)) - } else { - makeN(v2, l2, merge(h1, r2)) - } - } -} ensuring { - (res : Heap) => hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res) && h1.content() ++ h2.content() == res.content() -} - -%%% Heap6.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -makeN(v2, l2, merge(h1, r2)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(h1 : Heap, h2 : Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2) && hasHeapProperty(h1) && hasHeapProperty(h2)) - (h1, h2) match { - case (Leaf(), _) => - h2 - case (_, Leaf()) => - h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if (v1 >= v2) { - makeN(v1, l1, merge(r1, h2)) - } else { - makeN(v2, l2, merge(h1, r2)) - } - } -} ensuring { - (res : Heap) => hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res) && h1.content() ++ h2.content() == res.content() -} - -%%% Heap7.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -v1 + v2 > v2 + v2 -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(h1 : Heap, h2 : Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2) && hasHeapProperty(h1) && hasHeapProperty(h2)) - (h1, h2) match { - case (Leaf(), _) => - h2 - case (_, Leaf()) => - h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if (v1 + v2 > v2 + v2) { - makeN(v1, l1, merge(r1, h2)) - } else { - makeN(v2, l2, merge(h1, r2)) - } - } -} ensuring { - (res : Heap) => hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res) && h1.content() ++ h2.content() == res.content() -} - -%%% Heap8.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -merge(Node(element, Leaf(), Leaf()), heap) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def insert(element : Int, heap : Heap): Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - merge(Node(element, Leaf(), Leaf()), heap) -} ensuring { - (res : Heap) => hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(res) == heapSize(heap) + 1 && res.content() == heap.content() ++ Set[Int](element) -} - -%%% Heap9.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -left.rank() >= right.rank() -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def makeN(value : Int, left : Heap, right : Heap): Heap = { - require(hasLeftistProperty(left) && hasLeftistProperty(right)) - if (left.rank() >= right.rank()) { - Node(value, left, right) - } else { - Node(value, right, left) - } -} ensuring { - (res : Heap) => hasLeftistProperty(res) -} - -%%% Heap10.scala %%% -Solution is not trusted! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -(h1, h2) match { - case (Leaf(), _) => - h2 - case (_, Leaf()) => - h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if (v1 >= v2) { - makeN(v1, l1, merge(r1, h2)) - } else { - makeN(v2, merge(h1, r2), l2) - } -} -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(h1 : Heap, h2 : Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2) && hasHeapProperty(h1) && hasHeapProperty(h2)) - (h1, h2) match { - case (Leaf(), _) => - h2 - case (_, Leaf()) => - h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if (v1 >= v2) { - makeN(v1, l1, merge(r1, h2)) - } else { - makeN(v2, merge(h1, r2), l2) - } - } -} ensuring { - (res : Heap) => hasLeftistProperty(res) && hasHeapProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res) && h1.content() ++ h2.content() == res.content() -} - -%%% PropLogic1.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -nnf(Not(e)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def nnf(formula : Formula): Formula = { - formula match { - case Not(And(lhs, rhs)) => - Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => - And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => - Const(!v) - case Not(Not(e)) => - nnf(Not(e)) - case And(lhs, rhs) => - And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => - Or(nnf(lhs), nnf(rhs)) - case other => - other - } -} ensuring { - (res : Formula) => isNNF(res) && (formula, res) passes { - case Not(Not(Not(Const(a)))) => - Const(!a) - } -} - -%%% PropLogic2.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -other match { - case Const(v) => - Literal(1) - case Literal(id) => - Const(false) - case Not(f) => - nnf(f) -} -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def nnf(formula : Formula): Formula = { - formula match { - case Not(And(lhs, rhs)) => - Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => - And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => - Const(!v) - case And(lhs, rhs) => - And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => - Or(nnf(lhs), nnf(rhs)) - case other => - other match { - case Const(v) => - Literal(1) - case Literal(id) => - Const(false) - case Not(f) => - nnf(f) - } - } -} ensuring { - (res : Formula) => isNNF(res) && (formula, res) passes { - case Not(Not(Not(Const(a)))) => - Const(!a) - } -} - -%%% PropLogic3.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Const(false == v) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def nnf(formula : Formula): Formula = { - formula match { - case Not(And(lhs, rhs)) => - Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => - And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => - Const(false == v) - case Not(Not(e)) => - nnf(e) - case And(lhs, rhs) => - And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => - Or(nnf(lhs), nnf(rhs)) - case other => - other - } -} ensuring { - (res : Formula) => isNNF(res) && (formula, res) passes { - case Not(Const(true)) => - Const(false) - case Not(Const(false)) => - Const(true) - } -} - -%%% PropLogic4.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Or(nnf(lhs), nnf(rhs)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def nnf(formula : Formula): Formula = { - formula match { - case Not(And(lhs, rhs)) => - Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => - And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => - Const(!v) - case Not(Not(e)) => - nnf(e) - case And(lhs, rhs) => - And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => - Or(nnf(lhs), nnf(rhs)) - case other => - other - } -} ensuring { - (res : Formula) => isNNF(res) && (formula, res) passes { - case Or(Not(Const(c)), Not(Literal(l))) => - Or(Const(!c), Not(Literal(l))) - } -} - -%%% PropLogic5.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Or(nnf(lhs), nnf(rhs)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def nnf(formula : Formula): Formula = { - formula match { - case Not(And(lhs, rhs)) => - Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => - And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => - Const(!v) - case Not(Not(e)) => - nnf(e) - case And(lhs, rhs) => - And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => - Or(nnf(lhs), nnf(rhs)) - case other => - other - } -} ensuring { - (res : Formula) => isNNF(res) && (formula, res) passes { - case Or(Not(Const(c)), Not(Literal(l))) => - Or(Const(!c), Not(Literal(l))) - } -} - -%%% List1.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Cons0[T](h, t.pad(s, e)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$pad[T]($this : List0[T], s : Int, e : T): List0[T] = { - ($this, s) match { - case (_, s) if s <= 0 => - $this - case (Nil0(), s) => - Cons0[T](e, Nil0[T]().pad(s - 1, e)) - case (Cons0(h, t), s) => - Cons0[T](h, t.pad(s, e)) - } -} ensuring { - (res : List0[T]) => (($this, s, e), res) passes { - case (Cons0(a, Nil0()), 2, x) => - Cons0[T](a, Cons0[T](x, Cons0[T](x, Nil0[T]()))) - } -} - -%%% List2.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Cons0[T](x, xs ++ that) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$$plus$plus[T]($this : List0[T], that : List0[T]): List0[T] = { - $this match { - case Nil0() => - that - case Cons0(x, xs) => - Cons0[T](x, xs ++ that) - } -} ensuring { - (res : List0[T]) => res.content() == $this.content() ++ that.content() && res.size() == $this.size() + that.size() -} - -%%% List3.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Cons0[T](t, Nil0[T]()) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$ap[T]($this : List0[T], t : T): List0[T] = { - $this match { - case Nil0() => - Cons0[T](t, Nil0[T]()) - case Cons0(x, xs) => - Cons0[T](x, xs.ap(t)) - } -} ensuring { - (res : List0[T]) => res.size() == $this.size() + 1 && res.content() == $this.content() ++ Set[T](t) -} - -%%% List5.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -if (h == from) { - Cons0[T](to, t.replace(h, to)) -} else { - Cons0[T](h, r) -} -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$replace[T]($this : List0[T], from : T, to : T): List0[T] = { - $this match { - case Nil0() => - Nil0[T]() - case Cons0(h, t) => - val r = t.replace(from, to); - if (h == from) { - Cons0[T](to, t.replace(h, to)) - } else { - Cons0[T](h, r) - } - } -} ensuring { - (res : List0[T]) => $this.content() -- Set[T](from) ++ (if ($this.content().contains(e)) { - Set[T](to) - } else { - Set[T]() - }) == res.content() && res.size() == $this.size() -} - -%%% List6.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -t.count(h) + 1 -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$count[T]($this : List0[T], e : T): Int = { - $this match { - case Cons0(h, t) => - if (h == e) { - t.count(h) + 1 - } else { - t.count(e) - } - case Nil0() => - 0 - } -} ensuring { - (x$2 : Int) => (($this, e), x$2) passes { - case (Cons0(a, Cons0(b, Cons0(a1, Cons0(b2, Nil0())))), a2) if a == a1 && a == a2 && b != a2 && b2 != a2 => - 2 - case (Cons0(a, Cons0(b, Nil0())), c) if a != c && b != c => - 0 - } -} - -%%% List7.scala %%% -Solution is not trusted! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Some[Int](i + 1) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$find[T]($this : List0[T], e : T): Option[Int] = { - $this match { - case Nil0() => - None[Int]() - case Cons0(h, t) => - if (h == e) { - Some[Int](0) - } else { - t.find(e) match { - case None() => - None[Int]() - case Some(i) => - Some[Int](i + 1) - } - } - } -} ensuring { - (res : Option[Int]) => if ($this.content().contains(e)) { - res.isDefined() && $this.size() > res.get() && $this.apply(res.get()) == e - } else { - res.isEmpty() - } -} - -%%% List8.scala %%% -Solution is not trusted! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Some[Int]((i + 2) - 1) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$find[T]($this : List0[T], e : T): Option[Int] = { - $this match { - case Nil0() => - None[Int]() - case Cons0(h, t) => - if (h == e) { - Some[Int](0) - } else { - t.find(e) match { - case None() => - None[Int]() - case Some(i) => - Some[Int]((i + 2) - 1) - } - } - } -} ensuring { - (res : Option[Int]) => if ($this.content().contains(e)) { - res.isDefined() && $this.size() > res.get() && $this.apply(res.get()) == e - } else { - res.isEmpty() - } -} - -%%% List9.scala %%% -Solution is not trusted! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -if (e == h) { - Some[Int](0) -} else { - t.find(e) match { - case None() => - None[Int]() - case Some(i) => - Some[Int](i + 1) - } -} -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$find[T]($this : List0[T], e : T): Option[Int] = { - $this match { - case Nil0() => - None[Int]() - case Cons0(h, t) => - if (e == h) { - Some[Int](0) - } else { - t.find(e) match { - case None() => - None[Int]() - case Some(i) => - Some[Int](i + 1) - } - } - } -} ensuring { - (res : Option[Int]) => if ($this.content().contains(e)) { - res.isDefined() && $this.size() > res.get() && $this.apply(res.get()) == e - } else { - res.isEmpty() - } -} - -%%% List10.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -1 + t.size() -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$size[T]($this : List0[T]): Int = { - $this match { - case Nil0() => - 0 - case Cons0(h, t) => - 1 + t.size() - } -} ensuring { - (x$1 : Int) => ($this, x$1) passes { - case Cons0(_, Nil0()) => - 1 - case Nil0() => - 0 - } -} - -%%% List11.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -h + sum(t) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def sum(l : List0[Int]): Int = { - l match { - case Nil0() => - 0 - case Cons0(h, t) => - h + sum(t) - } -} ensuring { - (x$2 : Int) => (l, x$2) passes { - case Cons0(a, Nil0()) => - a - case Cons0(a, Cons0(b, Nil0())) => - a + b - } -} - -%%% List12.scala %% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -t - e -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$$minus[T]($this : List0[T], e : T): List0[T] = { - $this match { - case Cons0(h, t) => - if (e == h) { - t - e - } else { - Cons0[T](h, t - e) - } - case Nil0() => - Nil0[T]() - } -} ensuring { - (res : List0[T]) => res.content() == $this.content() -- Set[T](e) -} - -%%% List13.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -val scrut = ($this, i); - scrut match { - case (Nil0(), _) => - Nil0[T]() - case (Cons0(h, t), 0) => - scrut._1 - case (Cons0(_, t), i) => - t.drop(2) - } -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def List0$drop[T]($this : List0[T], i : Int): List0[T] = { - val scrut = ($this, i); - scrut match { - case (Nil0(), _) => - Nil0[T]() - case (Cons0(h, t), 0) => - scrut._1 - case (Cons0(_, t), i) => - t.drop(2) - } -} ensuring { - (res : List0[T]) => (($this, i), res) passes { - case (Cons0(_, Nil0()), 42) => - Nil0[T]() - case (l @ Cons0(_, _), 0) => - l - case (Cons0(a, Cons0(b, Nil0())), 1) => - Cons0[T](b, Nil0[T]()) - case (Cons0(a, Cons0(b, Cons0(c, Nil0()))), 2) => - Cons0[T](c, Nil0[T]()) - } -} - -%%% Numerical1.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -power(base, p - 1) * base -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def power(base : Int, p : Int): Int = { - require(p >= 0) - if (p == 0) { - 1 - } else { - if (p % 2 == 0) { - power(base * base, p / 2) - } else { - power(base, p - 1) * base - } - } -} ensuring { - (res : Int) => ((base, p), res) passes { - case (_, 0) => - 1 - case (b, 1) => - b - case (2, 7) => - 128 - case (2, 10) => - 1024 - } -} - -%%% Numerical3.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -(a, 0) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def moddiv(a : Int, b : Int): (Int, Int) = { - require(a >= 0 && b > 0) - if (b > a) { - (a, 0) - } else { - {val x$1 = { - moddiv(a - b, b) match { - case (r1, r2) => - (r1, r2) - } - } - val r1 = { - x$1._1 - } - val r2 = x$1._2; - (r1, (r2 + 1))} - } -} ensuring { - (res : (Int, Int)) => b * res._2 + res._1 == a -} - -%%% MergeSort1.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -(Cons(b, rec1), Cons(a, rec2)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def split(l : List): (List, List) = { - l match { - case Cons(a, Cons(b, t)) => - val x$1 = { - split(t) match { - case (rec1, rec2) => - (rec1, rec2) - } - } - val rec1 = { - x$1._1 - } - val rec2 = x$1._2; - (Cons(b, rec1), Cons(a, rec2)) - case other => - (other, Nil()) - } -} ensuring { - (res : (List, List)) => val x$2 = { - res match { - case (l1, l2) => - (l1, l2) - } - } - val l1 = { - x$2._1 - } - val l2 = x$2._2; - l1.size() >= l2.size() && l1.size() <= l2.size() + 1 && l1.size() + l2.size() == l.size() && l1.content() ++ l2.content() == l.content() -} - -%%% MergeSort2.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -Cons[Int](h2, merge(l1, t2)) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(l1 : List[Int], l2 : List[Int]): List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2, t2)) => - if (h1 <= h2) { - Cons[Int](h1, merge(t1, l2)) - } else { - Cons[Int](h2, merge(l1, t2)) - } - case (Nil(), _) => - l2 - case (_, Nil()) => - l1 - } -} ensuring { - (res : List[Int]) => isSorted(res) && res.size() == l1.size() + l2.size() && res.content() == l1.content() ++ l2.content() -} - -%%% MergeSort3.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -h2 >= h1 -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(l1 : List[Int], l2 : List[Int]): List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2, t2)) => - if (h2 >= h1) { - Cons[Int](h1, merge(t1, l2)) - } else { - Cons[Int](h2, merge(l1, t2)) - } - case (Nil(), _) => - l2 - case (_, Nil()) => - l1 - } -} ensuring { - (res : List[Int]) => isSorted(res) && res.size() == l1.size() + l2.size() && res.content() == l1.content() ++ l2.content() -} - -%%% MergeSort4.scala %%% -Found trusted solution! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -h2 :: merge(l1, t2) -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(l1 : List[Int], l2 : List[Int]): List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2, t2)) => - if (h1 <= h2) { - Cons[Int](h1, merge(t1, l2)) - } else { - h2 :: merge(l1, t2) - } - case (Nil(), _) => - l2 - case (_, Nil()) => - l1 - } -} ensuring { - (res : List[Int]) => isSorted(res) && res.size() == l1.size() + l2.size() && res.content() == l1.content() ++ l2.content() -} - -%%% MergeSort5.scala %%% -Solution is not trusted! -============================== Repair successful: ============================== ---------------------------------- Solution 1: --------------------------------- -(l1, l2) match { - case (Nil(), _) => - l2 - case (_, Nil()) => - l1 - case (Cons(h1, t1), Cons(h2, t2)) => - if (h1 <= h2) { - Cons[Int](h1, merge(t1, l2)) - } else { - Cons[Int](h2, merge(l1, t2)) - } -} -================================= In context: ================================= ---------------------------------- Solution 1: --------------------------------- -def merge(l1 : List[Int], l2 : List[Int]): List[Int] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => - l2 - case (_, Nil()) => - l1 - case (Cons(h1, t1), Cons(h2, t2)) => - if (h1 <= h2) { - Cons[Int](h1, merge(t1, l2)) - } else { - Cons[Int](h2, merge(l1, t2)) - } - } -} ensuring { - (res : List[Int]) => isSorted(res) && res.size() == l1.size() + l2.size() && res.content() == l1.content() ++ l2.content() -} diff --git a/testcases/repair/report.html b/testcases/repair/report.html deleted file mode 100644 index 91a45bc552688cadbe3f77c7a6c11d29c95eebb0..0000000000000000000000000000000000000000 --- a/testcases/repair/report.html +++ /dev/null @@ -1,227 +0,0 @@ -<html> - <head> - <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> - <script src="http://code.highcharts.com/highcharts.js"></script> -<script> - if (window.File && window.FileReader && window.FileList && window.Blob) { - // Great success! All the File APIs are supported. - } else { - alert('The File APIs are not fully supported in this browser.'); - } - - function initGraph(data) { - $('#overview').highcharts({ - title: { - text: 'Overview', - x: -20 //center - }, - - xAxis: { - type: 'datetime', - dateTimeLabelFormats: { // don't display the dummy year - month: '%e. %b', - year: '%b' - }, - title: { - text: 'Date' - } - }, - yAxis: { - title: { - text: 'Time (ms)' - }, - min: 0 - }, - tooltip: { - headerFormat: '<b>{series.name}</b><br>', - }, - - legend: { - layout: 'vertical', - align: 'right', - verticalAlign: 'middle', - borderWidth: 0 - }, - - plotOptions: { - spline: { - marker: { - enabled: true - } - } - }, - - series: data - }); - } - - function specificGraph(serie) { - var dataTests = []; - var dataRepair = []; - var dataVerification = []; - - for (var i = 0, r; r = serie.data[i]; i++) { - dataTests.push([1000*r.ts, r.time_tests]); - dataVerification.push([1000*r.ts, r.time_verification]); - dataRepair.push([1000*r.ts, r.time_synthesis]); - } - - $('#specific').highcharts({ - chart: { - type: 'area' - }, - title: { - text: serie.name - }, - xAxis: { - type: 'datetime', - dateTimeLabelFormats: { // don't display the dummy year - month: '%e. %b', - year: '%b' - }, - title: { - text: 'Date' - } - }, - yAxis: { - title: { - text: 'Time (ms)' - }, - min: 0 - }, - tooltip: { - pointFormat: '{point.y:,.0f} ms' - }, - plotOptions: { - area: { - stacking: 'normal', - lineColor: '#666666', - lineWidth: 1, - marker: { - lineWidth: 1, - lineColor: '#666666' - } - } - }, - series: [{ - name: 'Verification', - data: dataVerification - }, { - name: 'Repair', - data: dataRepair - }, { - name: 'Tests', - data: dataTests - }] - }); - } - - var data = []; - var dataMap = {} - - $(function () { - - function processData() { - dataMap = {}; - - for (var i = 0, r; r = data[i]; i++) { - var parts = r.files.split("/") - var name = parts[parts.length-1]+' '+r.function - - var serie = { - "name": name, - "data": [] - }; - - if (name in dataMap) { - serie = dataMap[name] - } - - serie.data.push(r) - -/*)*/ - - dataMap[name] = serie - } - - } - - function overviewGraph() { - var res = []; - - for (k in dataMap) { - var serie = dataMap[k]; - - res.push({ - "name": serie.name, - "data": serie.data.map(function(r) { - return { - x: 1000 * r.ts, - y: r.time_synthesis+r.time_tests, - t: r.time_tests, - r: r.time_synthesis - }; - }) - }) - } - - initGraph(res) - } - - function specificGraphs() { - var sel = ['<option value=""> -- Select one -- </option>'] - - for (s in dataMap) { - var r = dataMap[s] - sel.push('<option value="'+s+'">'+r.name+'</option>'); - } - - $("#graphSelect").html(sel.join("")); - - $("#graphSelect").unbind("change").change(function() { - var sel = $(this).find(":selected").val() - - specificGraph(dataMap[sel]); - }); - - } - - function handleFileSelect(evt) { - var files = evt.target.files; // FileList object - - graphData = []; - // files is a FileList of File objects. List some properties. - - for (var i = 0, f; f = files[i]; i++) { - var reader = new FileReader(); - - reader.onload = (function(theFile) { - return function(e) { - data = JSON.parse(e.target.result); - - processData() - - overviewGraph() - specificGraphs() - }; - })(f); - - reader.readAsText(f) - } - } - - document.getElementById('fileLoader').addEventListener('change', handleFileSelect, false); - }); -</script> - </head> - <body> - <h1>Leon Benchmarks</h1> - <h2>Load Data</h2> - <input type="file" id="fileLoader" name="data" /> - <h2>Overview</h2> - <div id="overview" style="min-width: 310px; height: 400px; margin: 0 auto"></div> - <h2>Details</h2> - <select id="graphSelect"></select> - <div id="specific" style="min-width: 310px; height: 400px; margin: 0 auto"></div> - </body> -</html> diff --git a/testcases/repair/runTests.sh b/testcases/repair/runTests.sh deleted file mode 100755 index e21e51af58ad0e2f464b080ef5b546770de8f86a..0000000000000000000000000000000000000000 --- a/testcases/repair/runTests.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -log=repairs.last -summaryLog=repairs.log -fullLog=fullLog.log - -echo -n "" > $log; -echo -n "" > "repairs.table"; - - -echo "################################" >> $summaryLog -echo "#" `hostname` >> $summaryLog -echo "#" `date +"%d.%m.%Y %T"` >> $summaryLog -echo "#" `git log -1 --pretty=format:"%h - %cd"` >> $summaryLog -echo "################################" >> $summaryLog -echo "# Category, File, function, p.S, fuS, foS, Tms, Fms, Rms, verif?" >> $summaryLog - -#All benchmarks: - -echo "=====================================================================" >> repair-report.txt - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/repair/Compiler/Compiler1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/repair/Compiler/Compiler2.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/repair/Compiler/Compiler3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/repair/Compiler/Compiler4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/repair/Compiler/Compiler5.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=simplify testcases/repair/Compiler/Compiler6.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/Heap/Heap3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/Heap/Heap4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/Heap/Heap5.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/Heap/Heap6.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/Heap/Heap7.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/Heap/Heap10.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=insert testcases/repair/Heap/Heap8.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=makeN testcases/repair/Heap/Heap9.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=nnf testcases/repair/PropLogic/PropLogic1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=nnf testcases/repair/PropLogic/PropLogic2.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=nnf testcases/repair/PropLogic/PropLogic3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=nnf testcases/repair/PropLogic/PropLogic4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=nnf testcases/repair/PropLogic/PropLogic5.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=pad testcases/repair/List/List1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=++ testcases/repair/List/List2.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=:+ testcases/repair/List/List3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --functions=replace testcases/repair/List/List5.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=count testcases/repair/List/List6.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=find testcases/repair/List/List7.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=find testcases/repair/List/List8.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=60 --functions=find testcases/repair/List/List9.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=size testcases/repair/List/List10.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=sum testcases/repair/List/List11.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=- testcases/repair/List/List12.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --functions=drop testcases/repair/List/List4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=drop testcases/repair/List/List13.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=power testcases/repair/Numerical/Numerical1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=moddiv testcases/repair/Numerical/Numerical3.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=split testcases/repair/MergeSort/MergeSort1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/MergeSort/MergeSort2.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/MergeSort/MergeSort3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/MergeSort/MergeSort4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/repair/MergeSort/MergeSort5.scala | tee -a $fullLog - -# Average results -#cat $log >> $summaryLog -#awk '{ total1 += $7; total2 += $8; total3 += $9; count++ } END { printf "#%74s Avg: %5d, %5d, %5d\n\n", "", total1/count, total2/count, total3/count }' $log >> $summaryLog - diff --git a/testcases/runtime/CachedList.scala b/testcases/runtime/CachedList.scala deleted file mode 100644 index 031503a9d8eb411d1c441caba98a8f0afbf441f3..0000000000000000000000000000000000000000 --- a/testcases/runtime/CachedList.scala +++ /dev/null @@ -1,43 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedList { - abstract class List - case class Cons(h: Int, t: List) extends List - case object Nil extends List - - def size(l: List): Int = l match { - case Cons(h, t) => 1 + size(t) - case Nil => 0 - } - - def content(l: List): Set[Int] = l match { - case Cons(h, t) => Set(h) ++ content(t) - case Nil => Set() - } - - case class CachedList(cache: Int, data: List) - - def inv(cl: CachedList) = { - (content(cl.data) contains cl.cache) || (cl.data == Nil) - } - - def withCache(l: List): CachedList = choose { - (x: CachedList) => inv(x) && content(x.data) == content(l) - } - - def insert(l: CachedList, i: Int): CachedList = { - require(inv(l)) - choose{ (x: CachedList) => content(x.data) == content(l.data) ++ Set(i) && inv(x) } - } - - def delete(l: CachedList, i: Int): CachedList = { - require(inv(l)) - choose{ (x: CachedList) => content(x.data) == content(l.data) -- Set(i) && inv(x) } - } - - def contains(l: CachedList, i: Int): Boolean = { - require(inv(l)) - choose{ (x: Boolean) => x == (content(l.data) contains i) } - } -} diff --git a/testcases/runtime/SquareRoot.scala b/testcases/runtime/SquareRoot.scala deleted file mode 100644 index 95bdf52f6c9e0967da3af474ba70cadc30e9cc45..0000000000000000000000000000000000000000 --- a/testcases/runtime/SquareRoot.scala +++ /dev/null @@ -1,31 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SquareRoot { - - def isqrt(x : Int) : Int = { - choose { (y : Int) => - y * y <= x && (y + 1) * (y + 1) >= x - } - } - - def isqrt2(x: Int): Int = { - if ((x == 0)) { - 0 - } else { - if ((x < 0)) { - leon.lang.error[(Int)]("(((y * y) ≤ x) ∧ (((y + 1) * (y + 1)) ≥ x)) is UNSAT!") - } else { - (choose { (y: Int) => - (((y * y) <= x) && (((y + 1) * (y + 1)) >= x)) - }) - } - } - } - - @ignore - def main(a: Array[String]) { - isqrt2(42) - } -} diff --git a/testcases/stringrender/BinaryTreeRender.scala b/testcases/stringrender/BinaryTreeRender.scala deleted file mode 100644 index 3e939217dee43b7963fc2d784a25b597e05bc3de..0000000000000000000000000000000000000000 --- a/testcases/stringrender/BinaryTreeRender.scala +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Name: BinaryTreeRender.scala - * Creation: 14.10.2015 - * Author: Mikael Mayer (mikael.mayer@epfl.ch) - * Comments: Binary tree rendering specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object TreeRender { - sealed abstract class Tree[T] - case class Node[T](left: Tree[T], i: T, right: Tree[T]) extends Tree[T] - case class Leaf[T]() extends Tree[T] - - /** Synthesis by example specs */ - @inline def psStandard(s: Tree[Int]) = (res: String) => (s, res) passes { - case Node(Node(Leaf[Int](), 2, Leaf[Int]()), 1, Node(Leaf[Int](), -3, Leaf[Int]())) => "Node(Node(Leaf(), 2, Leaf()), 1, Node(Leaf(), -3, Leaf()))" - case Node(Leaf[Int](), 1, Leaf[Int]()) => "Node(Leaf(), 1, Leaf())" - case Leaf[Int]() => "Leaf()" - } - - @inline def psRemoveNode(s: Tree[Int]) = (res: String) => (s, res) passes { - case Node(Node(Leaf(), 2, Leaf()), 1, Node(Leaf(), -3, Leaf())) => "((Leaf(), 2, Leaf()), 1, (Leaf(), -3, Leaf()))" - case Node(Leaf(), 1, Leaf()) => "(Leaf(), 1, Leaf())" - case Leaf() => "Leaf()" - } - - @inline def psRemoveLeaf(s: Tree[Int]) = (res: String) => (s, res) passes { - case Node(Node(Leaf(), 2, Leaf()), 1, Node(Leaf(), -3, Leaf())) => "((, 2, ), 1, (, -3, ))" - case Node(Leaf(), 1, Leaf()) => "(, 1, )" - case Leaf() => "" - } - - @inline def psRemoveComma(s: Tree[Int]) = (res: String) => (s, res) passes { - case Node(Node(Leaf(), 2, Leaf()), 1, Node(Leaf(), -3, Leaf())) => "((2), 1, (-3))" - case Node(Leaf(), 1, Node(Leaf(), 2, Leaf())) => "(1, (2))" - case Node(Node(Leaf(), 2, Leaf()), 1, Leaf()) => "((2), 1)" - case Leaf() => "" - } - - @inline def psRemoveParentheses(s: Tree[Int]) = (res: String) => (s, res) passes { - case Node(Node(Leaf(), 2, Leaf()), 1, Node(Leaf(), -3, Leaf())) => "(2), 1, (-3)" - case Node(Leaf(), 1, Node(Leaf(), 2, Leaf())) => "1, (2)" - case Node(Node(Leaf(), 2, Leaf()), 1, Leaf()) => "(2), 1" - case Leaf() => "" - } - - @inline def psPrefix(s: Tree[Int]) = (res: String) => (s, res) passes { - case Node(Node(Leaf(), 2, Leaf()), 1, Node(Leaf(), -3, Leaf())) => "1 (2) (-3)" - case Node(Leaf(), 1, Node(Leaf(), 2, Leaf())) => "1 () (2)" - case Node(Node(Leaf(), 2, Leaf()), 1, Leaf()) => "1 (2) ()" - case Leaf() => "()" - } - - @inline def psLispLike(s: Tree[Int]) = (res: String) => (s, res) passes { - case Node(Node(Leaf(), 2, Leaf()), 1, Node(Leaf(), -3, Leaf())) => "(1 (2) (-3))" - case Node(Leaf(), 1, Node(Leaf(), 2, Leaf())) => "(1 () (2))" - case Node(Node(Leaf(), 2, Leaf()), 1, Leaf()) => "(1 (2) ())" - case Leaf() => "()" - } - - @inline def psSuffix(s: Tree[Int]) = (res: String) => (s, res) passes { - case Node(Node(Leaf(), 2, Leaf()), 1, Node(Leaf(), -3, Leaf())) => "(2) (-3) 1" - case Node(Leaf(), 1, Node(Leaf(), 2, Leaf())) => "() (2) 1" - case Node(Node(Leaf(), 2, Leaf()), 1, Leaf()) => "(2) () 1" - case Leaf() => "()" - } - - ////////////////////////////////////////////// - // Non-incremental examples: pure synthesis // - ////////////////////////////////////////////// - def synthesizeStandard(s: Tree[Int]): String = { - ???[String] - } ensuring psStandard(s) - - def synthesizeRemoveNode(s: Tree[Int]): String = { - ???[String] - } ensuring psRemoveNode(s) - - def synthesizeRemoveLeaf(s: Tree[Int]): String = { - ???[String] - } ensuring psRemoveLeaf(s) - - def synthesizeRemoveComma(s: Tree[Int]): String = { - ???[String] - } ensuring psRemoveComma(s) - - def synthesizeRemoveParentheses(s: Tree[Int]): String = { - ???[String] - } ensuring psRemoveParentheses(s) - - def synthesizePrefix(s: Tree[Int]): String = { - ???[String] - } ensuring psPrefix(s) - - def synthesizeLispLike(s: Tree[Int]): String = { - ???[String] - } ensuring psLispLike(s) - - def synthesizeSuffix(s: Tree[Int]): String = { - ???[String] - } ensuring psSuffix(s) -} \ No newline at end of file diff --git a/testcases/stringrender/CalendarRender.scala b/testcases/stringrender/CalendarRender.scala deleted file mode 100644 index 062c908be0926f37871f4168330fd556b1d50a42..0000000000000000000000000000000000000000 --- a/testcases/stringrender/CalendarRender.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ -import leon.collection._ - -object CalendartoString { - val dayEventsSep = "\n" - val eventsSep = "\n" - val daysSep = "\n\n" - val hoursSep = "-" - val dayPlusPrefix = " (D+" - val dayPlusSuffix = ")" - val hoursDescriptionSep = " : " - val titleDescriptionSep = "\n" - - case class Week(days: List[Day]) - case class Day(name: String, events: List[Event]) - case class Event(startHour: Int, startMinute: Int, durationMinutes: Int, description: String) - - def renderHour(h: Int, m: Int) = { - //require(m >= 0 && m < 60 && h > 0) - val h_adjusted = h + m / 60 - val realh = h_adjusted % 24 - val realm = m % 60 - val days = h_adjusted / 24 - realh + "h" + (if(realm == 0) "" else (if(realm < 10) "0" + realm else realm.toString)) + (if(days > 0) dayPlusPrefix + days + dayPlusSuffix else "") - } - - def renderEvent(e: Event) = { - renderHour(e.startHour, e.startMinute) + hoursSep + renderHour(e.startHour, e.startMinute + e.durationMinutes) + hoursDescriptionSep + e.description - } - - def renderList[T](l: List[T], f: T => String, prefix: String, separator: String, suffix: String): String = l match { - case Nil() => prefix + suffix - case Cons(e, tail:Cons[T]) => prefix + f(e) + separator + renderList(tail, f, "", separator, suffix) - case Cons(e, Nil()) => prefix + f(e) + suffix - } - - def renderDay(d: Day): String = { - renderList(d.events, (e: Event) => renderEvent(e), d.name + dayEventsSep, eventsSep, "") - } - - def renderWeek(s: Week): String = { - renderList(s.days, (d: Day) => renderDay(d), """Dear manager, -Here is what happened last week: -""", daysSep, "") - } ensuring { (res: String) => - (s, res) passes { - case Week(Cons(Day("Wednesday", Cons(Event(8, 30, 60, "First meeting"), Cons(Event(23, 15, 420, "Bus journey"), Nil()))), Cons(Day("Thursday", Cons(Event(12, 0, 65, "Meal with client"), Nil())), Nil()))) => """Dear manager, -Here is what happened last week: -Wednesday -8h30-9h30 : First meeting -23h15-6h15 (D+1) : Bus journey - -Thursday -12h-13h05 : Meal with client""" - } - } -} \ No newline at end of file diff --git a/testcases/stringrender/ChoiceRender.scala b/testcases/stringrender/ChoiceRender.scala deleted file mode 100644 index 3547d6fdcdc45dc00539f28b8610d80de798af38..0000000000000000000000000000000000000000 --- a/testcases/stringrender/ChoiceRender.scala +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Name: TupleWrapperRender.scala - * Creation: 15.10.2015 - * Author: Mikaël Mayer (mikael.mayer@epfl.ch) - * Comments: Tuple rendering specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object ChoiceRender { - sealed abstract class Thread - case class T1() extends Thread - case class T2() extends Thread - case class T3() extends Thread - - sealed abstract class Action - case class Call(t: Thread, args: Option[Int]) extends Action - - @inline def psStandard(s: Action) = (res: String) => (s, res) passes { - case Call(T1(),None()) => "T1 call" - case Call(T1(),Some(2)) => "T1 -> 2" - } - - def synthesizeStandard(s: Action): String = { - ???[String] - } ensuring psStandard(s) -} \ No newline at end of file diff --git a/testcases/stringrender/ConstantRender.scala b/testcases/stringrender/ConstantRender.scala deleted file mode 100644 index f208fdb2b09a09846307340fc79c778f8fa8392b..0000000000000000000000000000000000000000 --- a/testcases/stringrender/ConstantRender.scala +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Name: TupleWrapperRender.scala - * Creation: 15.10.2015 - * Author: Mikaël Mayer (mikael.mayer@epfl.ch) - * Comments: Tuple rendering specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object ConstantRender { - sealed abstract class Thread - case class T1() extends Thread - case class T2() extends Thread - case class T3() extends Thread - - @inline def psStandard(s: Thread) = (res: String) => (s, res) passes { - case T1() => "T1" - } - - @inline def psSuffix(s: Thread) = (res: String) => (s, res) passes { - case T1() => "T1()" - } - - @inline def psPrefix(s: Thread) = (res: String) => (s, res) passes { - case T1() => "Call: T1()" - } - - def synthesizeStandard(s: Thread): String = { - ???[String] - } ensuring psStandard(s) - - def synthesizeSuffix(s: Thread): String = { - ???[String] - } ensuring psSuffix(s) - - def synthesizePrefix(s: Thread): String = { - ???[String] - } ensuring psPrefix(s) -} \ No newline at end of file diff --git a/testcases/stringrender/CustomRender.scala b/testcases/stringrender/CustomRender.scala deleted file mode 100644 index 7f81d50f0bf756096222944dbb14bf6a9b405720..0000000000000000000000000000000000000000 --- a/testcases/stringrender/CustomRender.scala +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Name: CustomRender.scala - * Creation: 15.1.2015 - * Author: Mikael Mayer (mikael.mayer@epfl.ch) - * Comments: Custom generic rendering - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object CustomRender { - def generic_list[T](l: List[T], f: T => String): String = { - ??? - } ensuring { - (res: String) => ((l, res) passes { - case Nil() => "[]" - case Cons(a, Cons(b, Nil())) => "[" + f(a) + ", " + f(b) + "]" - }) - } -} \ No newline at end of file diff --git a/testcases/stringrender/Default.scala b/testcases/stringrender/Default.scala deleted file mode 100644 index baab8ba1801da72afeca7ed6cb6cfc073f381454..0000000000000000000000000000000000000000 --- a/testcases/stringrender/Default.scala +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Name: Default.scala - * Creation: 15.10.2015 - * Author: Mikaël Mayer (mikael.mayer@epfl.ch) - * Comments: Benchmark for solving default string transformation problems. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -/** - * @author Mikael - */ -object Default { - @inline def psIntStandard(s: Int) = (res: String) => (s, res) passes { - case 1 => "1" - case 42 => "42" - case -3 => "-3" - } - - @inline def psBigIntStandard(s: BigInt) = (res: String) => (s, res) passes { - case BigInt(1) => "1" - case BigInt(42) => "42" - case BigInt(-3) => "-3" - } - - @inline def psBooleanStandard(s: Boolean) = (res: String) => (s, res) passes { - case true => "true" - case false => "false" - } - - @inline def psBoolean2(s: Boolean) = (res: String) => (s, res) passes { - case true => "yes" - case false => "no" - } - - def synthesizeIntStandard(s: Int): String = { - ???[String] - } ensuring psIntStandard(s) - - def synthesizeBigIntStandard(s: BigInt): String = { - ???[String] - } ensuring psBigIntStandard(s) - - def synthesizeBooleanStandard(s: Boolean): String = { - ???[String] - } ensuring psBooleanStandard(s) - - def synthesizeBoolean2(s: Boolean): String = { - ???[String] - } ensuring psBoolean2(s) -} \ No newline at end of file diff --git a/testcases/stringrender/DoubleListRender.scala b/testcases/stringrender/DoubleListRender.scala deleted file mode 100644 index bd0dba714601685ae9c3ed22d199ff8c6a825daf..0000000000000000000000000000000000000000 --- a/testcases/stringrender/DoubleListRender.scala +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Name: DoubleListRender.scala - * Creation: 09.12.2015 - * Author: Mikael Mayer (mikael.mayer@epfl.ch) - * Comments: Double lists rendering specification (requires many disambiguation rounds) - */ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object DoubleListRender { - abstract class A - case class B(i: AA, a: A) extends A - case class N() extends A - - abstract class AA - case class BB(i: A, a: AA) extends AA - case class NN() extends AA - - // Obviously wrong, but it is useful to use the display function. - def twoOutOfThreeAsAreTheSame(a: A, b: A, c: A): Boolean = { - a == b || a == c || b == c - } holds - - def mutual_lists(a : A): String = { - ??? - } ensuring { - (res : String) => (a, res) passes { - case N() => - "[]" - case B(NN(), N()) => - "[()]" - case B(NN(), B(NN(), N())) => - "[(), ()]" - case B(BB(N(), NN()), N()) => - "[([])]" - case B(NN(), B(NN(), B(NN(), N()))) => - "[(), (), ()]" - case B(BB(N(), BB(N(), NN())), N()) => - "[([], [])]" - case B(NN(), B(BB(N(), NN()), N())) => - "[(), ([])]" - case B(BB(N(), NN()), B(NN(), N())) => - "[([]), ()]" - case B(BB(B(NN(), N()), NN()), N()) => - "[([()])]" - case B(BB(N(), BB(N(), BB(N(), NN()))), N()) => - "[([], [], [])]" - case B(NN(), B(BB(N(), NN()), B(NN(), N()))) => - "[(), ([]), ()]" - case B(BB(B(NN(), N()), BB(N(), NN())), N()) => - "[([()], [])]" - case B(BB(B(BB(N(), NN()), N()), NN()), N()) => - "[([([])])]" - case B(BB(B(NN(), B(NN(), N())), NN()), N()) => - "[([(), ()])]" - case B(BB(N(), BB(B(NN(), N()), NN())), N()) => - "[([], [()])]" - } - } -} \ No newline at end of file diff --git a/testcases/stringrender/Example-Stack.scala b/testcases/stringrender/Example-Stack.scala deleted file mode 100644 index 05943c72e59fade4c78a3788c17ae031a286f92d..0000000000000000000000000000000000000000 --- a/testcases/stringrender/Example-Stack.scala +++ /dev/null @@ -1,359 +0,0 @@ -import leon.collection._ -import leon.collection.List -import leon.lang._ -import leon.proof.check -import leon.lang.synthesis._ -import scala.language.postfixOps - - -/** The Concurrency object defines the semantics of concurrent programs. - * - * It gives the definition of libraries, and gives a function - * isLibraryExecution which describes valid executions of the library. - * We show the files AtomicStack and TreiberStack how to instantiate it in - * order to describe specific implementations. - */ - - - -object Concurrency { - - /** The class Method gives a syntax to define a method of a library. - * - * A Method is a tuple (initials,transitions,finals) where: - * "initials" gives the initial state of the method depending on the argument - * "transitions" in transition relation, which specifies how local and global - * states are updated - * "finals" gives the final states, and the corresponding return value - * a state mapped to None means it's not final and the method cannot return here - * - * ArgData is the type of arguments values, given to the method - * RetData is the type of the values returned by the method - * LocalState is the type representing the local variables and control-flow positions - * of the method - */ - - case class Method[ArgData,RetData,LocalState,GlobalState]( - initials: ArgData => LocalState, - transitions: (LocalState,GlobalState) => (LocalState,GlobalState), - finals: LocalState => Option[RetData] - ) - - - /** A Library associates to each method name a Method instance */ - - case class Library[MethodName,ArgData,RetData,LocalState,GlobalState]( - methods: MethodName => Method[ArgData,RetData,LocalState,GlobalState] - ) - - - /** The Event class represents low-level events. - * - * Each event is executed by a particular thread (type Tid). - - * An event can be a call event. In which case, the event has information - * about the method `m' called, and the argument `arg' with which m was - * called. - * - * An event can be a return event. In which case, the event the same - * information than the corresponding call event, plus the return - * value `rv' (in RetData) which was returned. - * - * Otherwise, an event is an internal event (inside a method). - */ - - abstract class Event[Tid,MethodName,ArgData,RetData] - case class CallEvent[Tid,MethodName,ArgData,RetData] - (tid: Tid, m: MethodName, arg: ArgData) extends Event[Tid,MethodName,ArgData,RetData] - case class RetEvent[Tid,MethodName,ArgData,RetData] - (tid: Tid, m: MethodName, arg: ArgData, rv: RetData) extends Event[Tid,MethodName,ArgData,RetData] - case class InternalEvent[Tid,MethodName,ArgData,RetData] - (tid: Tid) extends Event[Tid,MethodName,ArgData,RetData] - - - - /** The Configuration class describes the whole state of a concurrent system. - * - * More precisely, it is a pair composed of a global state, and a map giving - * for each thread, the local state of the method in which the thread is. - * The map also stores information about the method name and the argument - * value with which the method was called. - * A thread mapped to None means that the thread is not currently calling - * any method. - * - * Intuitively, the global state represents the valuation of the global - * variables which are shared between the different methods. For programs - * which can use memory allocation, it should also represent the heap. - */ - - case class Configuration[Tid,MethodName,ArgData,LocalState,GlobalState]( - gs: GlobalState, - control: List[(Tid,Option[(MethodName,ArgData,LocalState)])] - ) - - - /** This class describes client's of a library. - * - * A client can be composed of multiple thread. It specifies for each - * thread, the sequence of calls made to the library, with the expected* - * return values. - */ - - case class Client[Tid,MethodName,ArgData,RetData](threads: Tid => List[Event[Tid,MethodName,ArgData,RetData]]) -} - -object AtomicStack { - - import Concurrency._ - - - - /** Represents the states of the control-flow graph of the push and pop - * methods. - */ - - abstract class StackState - case class ValueState(v: BigInt) extends StackState - case class EmptyState() extends StackState - case class InitState() extends StackState - case class FinalState() extends StackState - case class BlockState() extends StackState - - - abstract class StackTid - case class T1() extends StackTid - case class T2() extends StackTid - - - /** We now describe the Atomic Stack library. - * - * The arguments taken by push and pop are of type Option[BigInt]. - * Typically the pop method won't take an argument (None), while - * push will take a BigInt argument (Some[BigInt]). - * - * Similarly, the type of return values is also Option[BigInt]. - * - */ - - def initialsPush(arg: Option[BigInt]): StackState = arg match { - case None() => BlockState() - case Some(arg) => ValueState(arg) - } - - def transitionsPush(ls: StackState, gs: List[BigInt]): (StackState,List[BigInt]) = (ls,gs) match { - case (ValueState(arg),_) => (FinalState(), arg :: gs) - case _ => (BlockState(), gs) - } - - def finalsPush(ls: StackState): Option[Option[BigInt]] = ls match { - case FinalState() => Some(None()) - case _ => None() - } - - val PushMethod: Method[Option[BigInt],Option[BigInt],StackState,List[BigInt]] = { - Method(initialsPush,transitionsPush,finalsPush) - } - - - def initialsPop(arg: Option[BigInt]): StackState = InitState() - - def transitionsPop(ls: StackState, gs: List[BigInt]): (StackState,List[BigInt]) = (ls,gs) match { - case (InitState(),Nil()) => (EmptyState(), Nil()) - case (InitState(),Cons(rv,rvs)) => (ValueState(rv),rvs) - case _ => (BlockState(), gs) - } - - def finalsPop(ls: StackState): Option[Option[BigInt]] = ls match { - case EmptyState() => Some(None()) - case ValueState(arg) => Some(Some(arg)) - case _ => None() - } - - val PopMethod: Method[Option[BigInt],Option[BigInt],StackState,List[BigInt]] = { - Method(initialsPop,transitionsPop,finalsPop) - } - - abstract class StackMethodName - case class Push() extends StackMethodName - case class Pop() extends StackMethodName - - - def methods(name: StackMethodName): Method[Option[BigInt],Option[BigInt],StackState,List[BigInt]] = name match { - case Push() => PushMethod - case Pop() => PopMethod - } - - val libAtomicStack = Library[StackMethodName,Option[BigInt],Option[BigInt],StackState,List[BigInt]](methods) - - - def threads(tid: StackTid): List[Event[StackTid,StackMethodName,Option[BigInt],Option[BigInt]]] = tid match { - case T1() => - List( - CallEvent(T1(),Push(),Some(5)), - RetEvent(T1(),Push(),Some(5),None()) - ) - case T2() => - List( - CallEvent(T2(),Pop(),None()), - RetEvent(T2(),Pop(),None(),Some(5)) - ) - } - - val client: Client[StackTid,StackMethodName,Option[BigInt],Option[BigInt]] = Client(threads) - - def threadToStringSimplest(p: StackTid): String = { - ???[String] - } ensuring { - res => (p, res) passes { - case T1() - => - "T1: call Push(5)" - } - } - - def threadToStringSimple0(p: Event[StackTid,StackMethodName,Option[BigInt],Option[BigInt]]): String = { - ???[String] - } ensuring { - res => (p, res) passes { - case CallEvent(T1(), Push(), Some(BigInt(5))) - => - "T1: call Push(5)" - } - } - - def threadToStringSimple1(p: List[Event[StackTid,StackMethodName,Option[BigInt],Option[BigInt]]]): String = { - ???[String] - } ensuring { - res => (p, res) passes { - case Cons(CallEvent(T1(), Push(), Some(BigInt(5))), - Cons(InternalEvent(T1()), Nil())) - => - "T1: call Push(5)\nT1: internal" - } - } - - def threadToStringSimple2(p: List[Event[StackTid,StackMethodName,Option[BigInt],Option[BigInt]]]): String = { - ???[String] - } ensuring { - res => (p, res) passes { - case Cons(RetEvent(T1(), Push(), Some(BigInt(5)), None()), - Cons(InternalEvent(T2()), - Cons(RetEvent(T2(), Pop(), None(), Some(BigInt(5))), Nil()))) - => - "T1: ret Push(5)\nT2: internal\nT2: ret Pop() -> 5" - } - } - - - /** This is THE method we want to render */ - def threadToString(p: List[Event[StackTid,StackMethodName,Option[BigInt],Option[BigInt]]]): String = { - ???[String] - } ensuring { - res => (p, res) passes { - case Cons(CallEvent(T1(), Push(), Some(BigInt(5))), - Cons(InternalEvent(T1()), - Cons(CallEvent(T2(), Pop(), None()), - Cons(RetEvent(T1(), Push(), Some(BigInt(5)), None()), - Cons(InternalEvent(T2()), - Cons(RetEvent(T2(), Pop(), None(), Some(BigInt(5))), Nil())))))) - => - "T1: call Push(5)\nT1: internal\nT2: call Pop()\nT1: ret Push(5)\nT2: internal\nT2: ret Pop() -> 5" - } - } - - // Warning: Spacing differs from records to records. - // Warning: The displaying of a tuple might depend on its operands. - def configurationToString(p: List[Configuration[StackTid, StackMethodName, Option[BigInt], StackState, List[BigInt]]]): String = { - ???[String] - } ensuring { - res => (p, res) passes { - case Cons(Configuration(Nil(), Cons((T1(), Some((Push(), Some(BigInt(5)), ValueState(BigInt(5))))), Nil())), - Cons(Configuration(Cons(BigInt(5), Nil()), Cons((T1(), Some((Push(), Some(BigInt(5)), FinalState()))), Nil())), - Cons(Configuration(Cons(BigInt(5), Nil()), Cons((T2(), Some((Pop(), None(), InitState()))), Cons((T1(), Some((Push(), Some(BigInt(5)), FinalState()))), Nil()))), - Cons(Configuration(Cons(BigInt(5), Nil()), Cons((T2(), Some((Pop(), None(), InitState()))), Cons((T1(), None()), Nil()))), - Cons(Configuration(Nil(), Cons((T2(), Some((Pop(), None(), ValueState(BigInt(5))))), Cons((T1(), None()), Nil()))), - Cons(Configuration(Nil(), Cons((T2(), None()), Cons((T1(), None()), Nil()))), Nil())))))) => - """([], { - T1 -> Push(5): ValueState(5) -}) - - -([5], { - T1 -> Push(5): FinalState -}) - - -([5], { - T2 -> Pop(): InitState; - T1 -> Push(5): FinalState -}) - - -([5], { - T2 -> Pop(): InitState; - T1 -> idle -}) - - -([], { - T2 -> Pop(): ValueState(5); - T1 -> idle -}) - - -([], { - T2 -> idle; - T1 -> idle -})""" - - } - } - /* - /// Out of order configurationToString - def configurationToStringOOO(p: List[Configuration[StackTid, StackMethodName, Option[BigInt], StackState, List[BigInt]]]): String = { - ???[String] - } ensuring { - res => (p, res) passes { - case Cons(Configuration(Nil(), Map(T1() -> Some((Push(), Some(BigInt(5)), ValueState(BigInt(5)))))), - Cons(Configuration(Cons(BigInt(5), Nil()), Map(T1() -> Some((Push(), Some(BigInt(5)), FinalState())))), - Cons(Configuration(Cons(BigInt(5), Nil()), Map(T2() -> Some((Pop(), None(), InitState())), T1() -> Some((Push(), Some(BigInt(5)), FinalState())))), - Cons(Configuration(Cons(BigInt(5), Nil()), Map(T2() -> Some((Pop(), None(), InitState())), T1() -> None())), - Cons(Configuration(Nil(), Map(T2() -> Some((Pop(), None(), ValueState(BigInt(5)))), T1() -> None())), - Cons(Configuration(Nil(), Map(T2() -> None(), T1() -> None())), Nil())))))) => - """([], { - T1 -> ValueState(5) in Push(5) -}) - - -([5], { - T1 -> FinalState in Push(5) -}) - - -([5], { - T2 -> InitState in Pop(); - T1 -> FinalState in Push(5) -}) - - -([5], { - T2 -> InitState in Pop(); - T1 -> idle -}) - - -([], { - T2 -> ValueState(5) in Pop(); - T1 -> idle -}) - - -([], { - T2 -> idle; - T1 -> idle -})""" - - } - }*/ -} - diff --git a/testcases/stringrender/GrammarRender.scala b/testcases/stringrender/GrammarRender.scala deleted file mode 100644 index a2de93e9b41bc552db923b9eec2cce3fdf89d41b..0000000000000000000000000000000000000000 --- a/testcases/stringrender/GrammarRender.scala +++ /dev/null @@ -1,241 +0,0 @@ -/** - * Name: GrammarRender.scala - * Creation: 15.10.2015 - * Author: Mika�l Mayer (mikael.mayer@epfl.ch) - * Comments: Grammar rendering specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object GrammarRender { - abstract class Symbol - case class Terminal(i: Int) extends Symbol - case class NonTerminal(i: Int) extends Symbol - - case class Rule(left: Symbol, right: List[Symbol]) - case class Grammar(start: Symbol, rules: List[Rule]) - - /** Synthesis by example specs */ - @inline def psStandard(s: Grammar) = (res: String) => (s, res) passes { - case Grammar(NonTerminal(0), Nil()) => "Grammar(NonTerminal(0), Nil())" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Nil())) => - "Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Nil()))" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Cons(Rule(NonTerminal(0), Cons(NonTerminal(0), Cons(Terminal(1), Nil()))), Nil()))) => - "Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Cons(Rule(NonTerminal(0), Cons(NonTerminal(0), Cons(Terminal(1), Nil()))), Nil())))" - } - - @inline def psRemoveNames(s: Grammar) = (res: String) => (s, res) passes { - case Grammar(NonTerminal(0), Nil()) => "(S0, ())" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Nil())) => - "(S0, ((S0, (t1, ())), ()))" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Cons(Rule(NonTerminal(0), Cons(NonTerminal(0), Cons(Terminal(1), Nil()))), Nil()))) => - "(S0, ((S0, (t1, ())), ((S0, (S0, (t1, ()))), ())))" - } - - @inline def psArrowRules(s: Grammar) = (res: String) => (s, res) passes { - case Grammar(NonTerminal(0), Nil()) => "(S0, ())" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Nil())) => - "(S0, ((S0 -> (t1, ())), ()))" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Cons(Rule(NonTerminal(0), Cons(NonTerminal(0), Cons(Terminal(1), Nil()))), Nil()))) => - "(S0, ((S0 -> (t1, ())), ((S0 -> (S0, (t1, ()))), ())))" - } - - @inline def psListRules(s: Grammar) = (res: String) => (s, res) passes { - case Grammar(NonTerminal(0), Nil()) => "(S0, [])" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Nil())) => - "(S0, [S0 -> [t1]])" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Cons(Rule(NonTerminal(0), Cons(NonTerminal(0), Cons(Terminal(1), Nil()))), Nil()))) => - "(S0, [S0 -> [t1], S0 -> [S0, t1])" - } - - // The difficulty here is that two lists have to be rendered differently. - @inline def psSpaceRules(s: Grammar) = (res: String) => (s, res) passes { - case Grammar(NonTerminal(0), Nil()) => "(S0, [])" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Nil())) => - "(S0, [S0 -> t1])" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Cons(Rule(NonTerminal(0), Cons(NonTerminal(0), Cons(Terminal(1), Nil()))), Nil()))) => - "(S0, [S0 -> t1, S0 -> S0 t1)" - } - - // Full HTML generation - @inline def psHTMLRules(s: Grammar) = (res: String) => (s, res) passes { - case Grammar(NonTerminal(0), Nil()) => "<b>Start:</b> S0<br><pre></pre>" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Nil())) => - "<b>Start:</b> S0<br><pre>S0 -> t1</pte>" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Cons(Rule(NonTerminal(0), Cons(NonTerminal(0), Cons(Terminal(1), Nil()))), Nil()))) => - "<b>Start:</b> S0<br><pre>S0 -> t1<br>S0 -> S0 t1</pte>" - } - //Render in plain text. - @inline def psPlainTextRules(s: Grammar) = (res: String) => (s, res) passes { - case Grammar(NonTerminal(0), Nil()) => - """Start:S0""" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Nil())) => - """Start:S0 -S0 -> t1""" - case Grammar(NonTerminal(0), Cons(Rule(NonTerminal(0), Cons(Terminal(1), Nil())), Cons(Rule(NonTerminal(0), Cons(NonTerminal(0), Cons(Terminal(1), Nil()))), Nil()))) => - """Start:S0 -S0 -> t1 -S0 -> S0 t1""" - } - - /** Each function's body is the solution of the previous problem. - * We want to check that the Leon can repair the programs and also find some ambiguities.*/ - def render0RemoveNames(s: Grammar): String = { - def renderSymbol(s: Symbol) = s match { - case NonTerminal(i) => "NonTerminal(" + i + ")" - case Terminal(i) => "Terminal(" + i + ")" - } - def renderRule(r: Rule): String = { - def renderListSymbol(s: List[Symbol]): String = s match { - case Nil() => "Nil()" - case Cons(a, q) => "Cons(" + rendersymbol(a) + ", " + renderListsymbol(q) + ")" - } - "Rule(" + renderSymbol(r.left) + ", " + renderListSymbol(r.right) + ")" - } - def renderListRules(s: List[Rules]): String = s match { - case Nil() => "Nil()" - case Cons(r, q) => "Cons(" + renderRule(r) + ", " + renderListRules(q) + ")" - } - "Grammar(" + renderSymbol(s.start) + ", " + renderListRules(s.rules) + ")" - } ensuring psRemoveNames(s) - - def render1ArrowRules(s: Grammar): String = { - def renderSymbol(s: Symbol) = s match { - case NonTerminal(i) => "S" + i - case Terminal(i) => "t" + i - } - def renderRule(r: Rule): String = { - def renderListSymbol(s: List[Symbol]): String = s match { - case Nil() => "()" - case Cons(a, q) => "(" + rendersymbol(a) + ", " + renderListsymbol(q) + ")" - } - "(" + renderSymbol(r.left) + ", " + renderListSymbol(r.right) + ")" - } - def renderListRules(s: List[Rules]): String = s match { - case Nil() => "()" - case Cons(r, q) => "(" + renderRule(r) + ", " + renderListRules(q) + ")" - } - "(" + renderSymbol(s.start) + ", " + renderListRules(s.rules) + ")" - } ensuring psArrowRules(s) - - def render2ListRules(s: Grammar): String = { - def renderSymbol(s: Symbol) = s match { - case NonTerminal(i) => "S" + i - case Terminal(i) => "t" + i - } - def renderRule(r: Rule): String = { - def renderListSymbol(s: List[Symbol]): String = s match { - case Nil() => "()" - case Cons(a, q) => "(" + rendersymbol(a) + ", " + renderListsymbol(q) + ")" - } - "(" + renderSymbol(r.left) + " -> " + renderListSymbol(r.right) + ")" - } - def renderListRules(s: List[Rules]): String = s match { - case Nil() => "()" - case Cons(r, q) => "(" + renderRule(r) + ", " + renderListRules(q) + ")" - } - "(" + renderSymbol(s.start) + ", " + renderListRules(s.rules) + ")" - } ensuring psListRules(s) - - def render3SpaceRules(s: Grammar): String = { - def renderSymbol(s: Symbol) = s match { - case NonTerminal(i) => "S" + i - case Terminal(i) => "t" + i - } - def renderRule(r: Rule): String = { - def renderListSymbol(s: List[Symbol]): String = s match { - case Nil() => "" - case Cons(a, Nil()) => rendersymbol(a) - case Cons(a, q) => rendersymbol(a) + ", " + renderListsymbol(q) - } - renderSymbol(r.left) + " -> [" + renderListSymbol(r.right) + "]" - } - def renderListRules(s: List[Rules]): String = s match { - case Nil() => "" - case Cons(r, Nil()) => renderRule(r) - case Cons(r, q) => renderRule(r) + ", " + renderListRules(q) - } - "(" + renderSymbol(s.start) + ", [" + renderListRules(s.rules) + "])" - } ensuring psSpaceRules(s) - - def render4HTMLRules(s: Grammar): String = { - def renderSymbol(s: Symbol) = s match { - case NonTerminal(i) => "S" + i - case Terminal(i) => "t" + i - } - def renderRule(r: Rule): String = { - def renderListSymbol(s: List[Symbol]): String = s match { - case Nil() => "" - case Cons(a, Nil()) => rendersymbol(a) - case Cons(a, q) => rendersymbol(a) + " " + renderListsymbol(q) - } - renderSymbol(r.left) + " -> " + renderListSymbol(r.right) + "" - } - def renderListRules(s: List[Rules]): String = s match { - case Nil() => "" - case Cons(r, Nil()) => renderRule(r) - case Cons(r, q) => renderRule(r) + ", " + renderListRules(q) - } - "(" + renderSymbol(s.start) + ", [" + renderListRules(s.rules) + "])" - } ensuring psHTMLRules(s) - - /* The initial body of this function is the solution of render3 */ - def render5PlainTextRules(s: Grammar): String = { - def renderSymbol(s: Symbol) = s match { - case NonTerminal(i) => "S" + i - case Terminal(i) => "t" + i - } - def renderRule(r: Rule): String = { - def renderListSymbol(s: List[Symbol]): String = s match { - case Nil() => "" - case Cons(a, Nil()) => rendersymbol(a) - case Cons(a, q) => rendersymbol(a) + " " + renderListsymbol(q) - } - renderSymbol(r.left) + " -> " + renderListSymbol(r.right) + "" - } - def renderListRules(s: List[Rules]): String = s match { - case Nil() => "" - case Cons(r, Nil()) => renderRule(r) - case Cons(r, q) => renderRule(r) + ", " + renderListRules(q) - } - "(" + renderSymbol(s.start) + ", [" + renderListRules(s.rules) + "])" - } ensuring psPlainTextRules(s) - - ////////////////////////////////////////////// - // Non-incremental examples: pure synthesis // - ////////////////////////////////////////////// - def synthesizeStandard(s: Grammar): String = { - ???[String] - } ensuring psStandard(s) - - def synthesizeRemoveNames(s: Grammar): String = { - ???[String] - } ensuring psRemoveNames(s) - - def synthesizeArrowRules(s: Grammar): String = { - ???[String] - } ensuring psArrowRules(s) - - def synthesizeListRules(s: Grammar): String = { - ???[String] - } ensuring psListRules(s) - - def synthesizeSpaceRules(s: Grammar): String = { - ???[String] - } ensuring psSpaceRules(s) - - def synthesizeHTMLRules(s: Grammar): String = { - ???[String] - } ensuring psHTMLRules(s) - - def synthesizePlainTextRules(s: Grammar): String = { - ???[String] - } ensuring psPlainTextRules(s) - - def allGrammarsAreIdentical(g: Grammar, g2: Grammar) = (g == g2 || g.rules == g2.rules) holds - -} \ No newline at end of file diff --git a/testcases/stringrender/IntWrapperRender.scala b/testcases/stringrender/IntWrapperRender.scala deleted file mode 100644 index fda0004afa3f52454d62d544e272c5d40be229a6..0000000000000000000000000000000000000000 --- a/testcases/stringrender/IntWrapperRender.scala +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Name: IntWrapperRender.scala - * Creation: 15.10.2015 - * Author: Mikaël Mayer (mikael.mayer@epfl.ch) - * Comments: Wrapped integer specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object IntWrapperRender { - case class IntWrapper(i: Int) - - @inline def psStandard(s: IntWrapper) = (res: String) => (s, res) passes { - case IntWrapper(0) => "IntWrapper(0)" - case IntWrapper(-1) => "IntWrapper(-1)" - case IntWrapper(12) => "IntWrapper(12)" - } - - @inline def psUnwrapped(s: IntWrapper) = (res: String) => (s, res) passes { - case IntWrapper(0) => "0" - case IntWrapper(-1) => "-1" - case IntWrapper(12) => "12" - } - - @inline def psNameChangedPrefix(s: IntWrapper) = (res: String) => (s, res) passes { - case IntWrapper(0) => "number: 0" - case IntWrapper(-1) => "number: -1" - case IntWrapper(12) => "number: 12" - } - - @inline def psNameChangedSuffix(s: IntWrapper) = (res: String) => (s, res) passes { - case IntWrapper(0) => "0.0" - case IntWrapper(-1) => "-1.0" // Here there should be an ambiguity before this line. - case IntWrapper(12) => "12.0" - } - - /*@inline def psDuplicate(s: IntWrapper) = (res: String) => (s, res) passes { - case IntWrapper(0) => "0 0" - case IntWrapper(-1) => "-1 -1" - case IntWrapper(12) => "12 12" - }*/ - - def repairUnwrapped(s: IntWrapper): String = { - "IntWrapper(" + s.i + ")" - } ensuring psUnwrapped(s) - - def repairNameChangedPrefix(s: IntWrapper): String = { - "IntWrapper(" + s.i + ")" - } ensuring psNameChangedPrefix(s) - - def repairNameChangedSuffix(s: IntWrapper): String = { - "IntWrapper(" + s.i + ")" - } ensuring psNameChangedSuffix(s) - - /*def repairDuplicate(s: IntWrapper): String = { - "IntWrapper(" + s.i + ")" - } ensuring psDuplicate(s)*/ - - def synthesizeStandard(s: IntWrapper): String = { - ???[String] - } ensuring psStandard(s) - - def synthesizeUnwrapped(s: IntWrapper): String = { - ???[String] - } ensuring psUnwrapped(s) - - def synthesizeNameChangedPrefix(s: IntWrapper): String = { - ???[String] - } ensuring psNameChangedPrefix(s) - - def synthesizeNameChangedSuffix(s: IntWrapper): String = { - ???[String] - } ensuring psNameChangedSuffix(s) - - /*def synthesizeDuplicate(s: IntWrapper): String = { - ???[String] - } ensuring psDuplicate(s)*/ -} \ No newline at end of file diff --git a/testcases/stringrender/JsonRender.scala b/testcases/stringrender/JsonRender.scala deleted file mode 100644 index 73acdce11f7ea620ed42ef7e00d36bcdf50c5509..0000000000000000000000000000000000000000 --- a/testcases/stringrender/JsonRender.scala +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Name: JsonRender.scala - * Creation: 25.11.2015 - * Author: Mikael Mayer (mikael.mayer@epfl.ch) - * Comments: Json specifications - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object JsonRender { - abstract class JSON - abstract class JCompositeValue extends JSON - abstract class JFinalValue extends JSON - case class JDict(values: List[(String, JSON)]) extends JCompositeValue - case class JArray(values: List[JSON]) extends JCompositeValue - case class JString(value: String) extends JFinalValue - case class JBoolean(value: Boolean) extends JFinalValue - case class JInt(value: Int) extends JFinalValue - - def JStringToString(j: JString) = "\"" + StrOps.escape(j.value) + "\"" - - /** Synthesize this function by example to have a JSON serializer. */ - def json_render(j: JSON): String = { - ???[String] ask j - } -} \ No newline at end of file diff --git a/testcases/stringrender/ListBigIntRender.scala b/testcases/stringrender/ListBigIntRender.scala deleted file mode 100644 index 9dddd97df7f03b2fedf576da86eb606e8d9f79ce..0000000000000000000000000000000000000000 --- a/testcases/stringrender/ListBigIntRender.scala +++ /dev/null @@ -1,183 +0,0 @@ -/** - * Name: ListBigIntRender.scala - * Creation: 15.10.2015 - * Author: Mika�l Mayer (mikael.mayer@epfl.ch) - * Comments: List of BigInt specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object ListBigIntRender { - /** Synthesis by example specs */ - @inline def psWithBigInts(s: List[BigInt]) = (res: String) => (s, res) passes { - case Cons(BigInt(12), Cons(BigInt(-1), Nil())) => "Cons(BigInt(12), Cons(BigInt(-1), Nil()))" - case Cons(BigInt(1), Nil()) => "Cons(BigInt(1), Nil())" - case Nil() => "Nil()" - } - - @inline def psStandard(s: List[BigInt]) = (res: String) => (s, res) passes { - case Cons(BigInt(12), Cons(BigInt(-1), Nil())) => "Cons(12, Cons(-1, Nil()))" - case Cons(BigInt(1), Nil()) => "Cons(1, Nil())" - case Nil() => "Nil()" - } - - @inline def psRemoveCons(s: List[BigInt]) = (res: String) => (s, res) passes { - case Cons(BigInt(12), Cons(BigInt(-1), Nil())) => "(12, (-1, Nil()))" - case Cons(BigInt(1), Nil()) => "(1, Nil())" - case Nil() => "Nil()" - } - - @inline def psRemoveNil(s: List[BigInt]) = (res: String) => (s, res) passes { - case Cons(BigInt(12), Cons(BigInt(-1), Nil())) => "(12, (-1, ))" - case Cons(BigInt(1), Nil()) => "(1, )" - case Nil() => "" - } - - @inline def psRemoveLastComma(s: List[BigInt]) = (res: String) => (s, res) passes { - case Cons(BigInt(12), Cons(BigInt(-1), Nil())) => "(12, (-1))" - case Cons(BigInt(1), Nil()) => "(1)" - case Nil() => "()" - } - - @inline def psRemoveParentheses(s: List[BigInt]) = (res: String) => (s, res) passes { - case Cons(BigInt(12), Cons(BigInt(-1), Nil())) => "12, -1" - case Cons(BigInt(1), Nil()) => "1" - case Nil() => "" - } - - @inline def psWrapParentheses(s: List[BigInt]) = (res: String) => (s, res) passes { - case Cons(BigInt(12), Cons(BigInt(-1), Nil())) => "(12, -1)" - case Cons(BigInt(1), Nil()) => "(1)" - case Nil() => "()" - } - - @inline def psList(s: List[BigInt]) = (res: String) => (s, res) passes { - case Nil() => "List()" - case Cons(BigInt(1), Nil()) => "List(1)" - case Cons(BigInt(12), Cons(BigInt(-1), Nil())) => "List(12, -1)" - } - - /** Each function's body is the solution of the previous problem. - * We want to check that the Leon can repair the programs and also find some ambiguities.*/ - /*def render0RemoveBigInt(s: List[BigInt]): String = { - def renderBigInt(b: BigInt): String = { - b.toString() - } - s match { - case Nil() => "Nil()" - case Cons(a, b) => "Cons(" + renderBigInt(a) + ", " + render1RemoveCons(b) + ")" - } - } ensuring psRemoveCons(s) - - def render1RemoveCons(s: List[BigInt]): String = { - def renderBigInt(b: BigInt): String = { - val a = b.toString() - a.substring(6, a.length - 1) - } - s match { - case Nil() => "Nil()" - case Cons(a, b) => "Cons(" + renderBigInt(a) + ", " + render1RemoveCons(b) + ")" - } - } ensuring psRemoveCons(s) - - def render2RemoveNil(s: List[BigInt]): String = { - def renderBigInt(b: BigInt): String = { - val a = b.toString() - a.substring(6, a.length - 1) - } - s match { - case Nil() => "Nil()" - case Cons(a, b) => "(" + renderBigInt(a) + ", " + render2RemoveNil(b) + ")" - } - } ensuring psRemoveNil(s) - - def render3RemoveLastComma(s: List[BigInt]): String = { - def renderBigInt(b: BigInt): String = { - val a = b.toString() - a.substring(6, a.length - 1) - } - s match { - case Nil() => "" - case Cons(a, b) => "(" + renderBigInt(a) + ", " + render3RemoveLastComma(b) + ")" - } - } ensuring psRemoveLastComma(s) - - def render4RemoveParentheses(s: List[BigInt]): String = { - def renderBigInt(b: BigInt): String = { - val a = b.toString() - a.substring(6, a.length - 1) - } - s match { - case Nil() => "" - case Cons(a, Nil()) => "(" + renderBigInt(a) + ")" - case Cons(a, b) => "(" + renderBigInt(a) + ", " + render4RemoveParentheses(b) + ")" - } - } ensuring psRemoveParentheses(s)*/ - - /* harder example: It needs to repair by wrapping the recursive call in a sub-method - * in order to add strings to the left and to the right (see render6List) */ - /*def render5WrapParentheses(s: List[BigInt]): String = { - def renderBigInt(b: BigInt): String = { - val a = b.toString() - a.substring(6, a.length - 1) - } - s match { - case Nil() => "" - case Cons(a, Nil()) => renderBigInt(a) - case Cons(a, b) => renderBigInt(a) + ", " + render5WrapParentheses(b) - } - } ensuring psWrapParentheses(s) - - def render6List(s: List[BigInt]): String = { - def renderBigInt(b: BigInt): String = { - val a = b.toString() - a.substring(6, a.length - 1) - } - def rec(s: List[BigInt]): String = - s match { - case Nil() => "" - case Cons(a, Nil()) => renderBigInt(a) - case Cons(a, b) => renderBigInt(a) + ", " + render6List(b) - } - "(" + rec(s) + ")" - } ensuring psList(s)*/ - - ////////////////////////////////////////////// - // Non-incremental examples: pure synthesis // - ////////////////////////////////////////////// - def synthesizeStandard(s: List[BigInt]): String = { - ???[String] - } ensuring psStandard(s) - - def synthesizeWithBigInts(s: List[BigInt]): String = { - ???[String] - } ensuring psWithBigInts(s) - - def synthesizeRemoveCons(s: List[BigInt]): String = { - ???[String] - } ensuring psRemoveCons(s) - - def synthesizeRemoveNil(s: List[BigInt]): String = { - ???[String] - } ensuring psRemoveNil(s) - - def synthesizeRemoveLastComma(s: List[BigInt]): String = { - ???[String] - } ensuring psRemoveLastComma(s) - - def synthesizeRemoveParentheses(s: List[BigInt]): String = { - ???[String] - } ensuring psRemoveParentheses(s) - - def synthesizeWrapParentheses(s: List[BigInt]): String = { - ???[String] - } ensuring psWrapParentheses(s) - - def synthesizeList(s: List[BigInt]): String = { - ???[String] - } ensuring psList(s) -} \ No newline at end of file diff --git a/testcases/stringrender/ListRender.scala b/testcases/stringrender/ListRender.scala deleted file mode 100644 index fbf9b8d7093c7183370e03ba46067877d79e977e..0000000000000000000000000000000000000000 --- a/testcases/stringrender/ListRender.scala +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Name: ListRender.scala - * Creation: 14.10.2015 - * Author: Mika�l Mayer (mikael.mayer@epfl.ch) - * Comments: First benchmark ever for solving string transformation problems. List specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object ListRender { - /** Synthesis by example specs */ - @inline def psStandard(s: List[Int]) = (res: String) =>(s, res) passes { - case Cons(12, Cons(-1, Nil())) => "Cons(12, Cons(-1, Nil))" - case Cons(-1, Cons(12, Nil())) => "Cons(-1, Cons(12, Nil))" - case Cons(1, Nil()) => "Cons(1, Nil)" - case Nil() => "Nil" - } - - @inline def psRemoveCons(s: List[Int]) = (res: String) =>(s, res) passes { - case Cons(12, Cons(-1, Nil())) => "(12, (-1, Nil))" - case Cons(1, Nil()) => "(1, Nil)" - case Nil() => "Nil" - } - - @inline def psRemoveNil(s: List[Int]) = (res: String) =>(s, res) passes { - case Cons(12, Cons(-1, Nil())) => "(12, (-1, ))" - case Cons(1, Nil()) => "(1, )" - case Nil() => "" - } - - @inline def psRemoveLastComma(s: List[Int]) = (res: String) =>(s, res) passes { - case Cons(12, Cons(-1, Nil())) => "(12, (-1))" - case Cons(1, Nil()) => "(1)" - case Nil() => "()" - } - - @inline def psRemoveParentheses(s: List[Int]) = (res: String) =>(s, res) passes { - case Cons(12, Cons(-1, Nil())) => "12, -1" - case Cons(1, Nil()) => "1" - case Nil() => "" - } - - @inline def psWrapParentheses(s: List[Int]) = (res: String) =>(s, res) passes { - case Cons(12, Cons(-1, Nil())) => "(12, -1)" - } - - @inline def psList(s: List[Int]) = (res: String) =>(s, res) passes { - case Nil() => "List()" - case Cons(1, Nil()) => "List(1)" - case Cons(12, Cons(-1, Nil())) => "List(12, -1)" - } - - /** Each function's body is the solution of the previous problem. - * We want to check that the Leon can repair the programs and also find some ambiguities.*/ - def render1RemoveCons(s: List[Int]): String = { - s match { - case Nil() => "Nil" - case Cons(a, b) => "Cons(" + a.toString + ", " + render1RemoveCons(b) + ")" - } - } ensuring psRemoveCons(s) - - def render2RemoveNil(s: List[Int]): String = { - s match { - case Nil() => "Nil" - case Cons(a, b) => "(" + a.toString + ", " + render2RemoveNil(b) + ")" - } - } ensuring psRemoveNil(s) - - def render3RemoveLastComma(s: List[Int]): String = { - s match { - case Nil() => "" - case Cons(a, b) => "(" + a.toString + ", " + render3RemoveLastComma(b) + ")" - } - } ensuring psRemoveLastComma(s) - - def render4RemoveParentheses(s: List[Int]): String = { - s match { - case Nil() => "" - case Cons(a, Nil()) => "(" + a.toString + ")" - case Cons(a, b) => "(" + a.toString + ", " + render4RemoveParentheses(b) + ")" - } - } ensuring psRemoveParentheses(s) - - /* harder example: It needs to repair by wrapping the recursive call in a sub-method - * in order to add strings to the left and to the right (see render6List) */ - def render5WrapParentheses(s: List[Int]): String = { - s match { - case Nil() => "" - case Cons(a, Nil()) => a.toString - case Cons(a, b) => a.toString + ", " + render5WrapParentheses(b) - } - } ensuring psWrapParentheses(s) - - def render6List(s: List[Int]): String = { - def rec(s: List[Int]): String = - s match { - case Nil() => "" - case Cons(a, Nil()) => a.toString - case Cons(a, b) => a.toString + ", " + render6List(b) - } - "(" + rec(s) + ")" - } ensuring psList(s) - - ////////////////////////////////////////////// - // Non-incremental examples: pure synthesis // - ////////////////////////////////////////////// - def synthesizeStandard(s: List[Int]): String = { - ???[String] - } ensuring psStandard(s) - - def synthesizeRemoveCons(s: List[Int]): String = { - ???[String] - } ensuring psRemoveCons(s) - - def synthesizeRemoveNil(s: List[Int]): String = { - ???[String] - } ensuring psRemoveNil(s) - - def synthesizeRemoveLastComma(s: List[Int]): String = { - ???[String] - } ensuring psRemoveLastComma(s) - - def synthesizeRemoveParentheses(s: List[Int]): String = { - ???[String] - } ensuring psRemoveParentheses(s) - - def synthesizeWrapParentheses(s: List[Int]): String = { - ???[String] - } ensuring psWrapParentheses(s) - - def synthesizeList(s: List[Int]): String = { - ???[String] - } ensuring psList(s) -} \ No newline at end of file diff --git a/testcases/stringrender/MapRender.scala b/testcases/stringrender/MapRender.scala deleted file mode 100644 index a5b27ad09a03be750caf6eacd19719fe7f640261..0000000000000000000000000000000000000000 --- a/testcases/stringrender/MapRender.scala +++ /dev/null @@ -1,25 +0,0 @@ -import leon.collection._ -import leon.collection.List -import leon.lang._ -import leon.proof.check -import leon.lang.synthesis._ -import scala.language.postfixOps -import leon.annotation._ - -object MapRender { - - def f(i: Int): Map[Int, Int] = { - Map(1 -> i) - } ensuring { - (m: Map[Int, Int]) => m(1) == 2 - } - - def g(m: Map[Int, Int]): Boolean = { - !m.contains(0) || !m.contains(1) - } holds - - def mapIntIntToString(in : Map[Int, Int]): String = { - Map.mkString(in, "MyMap(\n "," -> ", ",\n ", ")", (i:Int) => i.toString, (i:Int) => i.toString) - } -} - diff --git a/testcases/stringrender/MapSetBagListMkString.scala b/testcases/stringrender/MapSetBagListMkString.scala deleted file mode 100644 index 3d79aad5962fc97e904944248d738550fd47ead6..0000000000000000000000000000000000000000 --- a/testcases/stringrender/MapSetBagListMkString.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon.annotation._ -import leon.lang.synthesis._ - -object StringTest { - - def listToString(in : List[String]): String = { - ???[String] - } ensuring { - (res : String) => (in, res) passes { - case s if s == List("1", "2", "0") => - "[1 ## 2 ## 0]" - case s if s == List[String]() => - "[]" - } - } - - def setToString(in : Set[String]): String = { - ???[String] - } ensuring { - (res : String) => (in, res) passes { - case s if s == Set[String]("1", "2", "0") => - "{0 | 1 | 2}" - case s if s == Set[String]() => - "{}" - } - } - - def mapToString(in : Map[String, String]): String = { - ???[String] - } ensuring { - (res : String) => (in, res) passes { - case s if s == Map[String,String]("Title" -> "Modular Printing", "Abstract" -> "We discuss...", "Year" -> "2016") => - "[Abstract --> We discuss..., Title --> Modular Printing, Year --> 2016]" - case s if s == Map[String,String]() => - "[]" - } - } - - def bagToString(in : Bag[String]): String = { - ???[String] - } ensuring { - (res : String) => (in, res) passes { - case s if s == Bag[String]("3" -> BigInt(2), "2" -> BigInt(1), "5" -> BigInt(3)) => - "2*3*3*5*5*5" - case s if s == Bag[String]() => - "" - } - } -} diff --git a/testcases/stringrender/Matrix.scala b/testcases/stringrender/Matrix.scala deleted file mode 100644 index 3dd47168940487b7e8be9212b7ba805e499603b6..0000000000000000000000000000000000000000 --- a/testcases/stringrender/Matrix.scala +++ /dev/null @@ -1,36 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import synthesis._ - -object Matrix { - case class CList[T](head: T, tail: Option[CList[T]]) { - def +:(el: T) = CList(el, Some(this)) - } - - def clistMkString[T](in: CList[T], infix: String, f: T => String): String = { - in match { - case CList(head, Some(tail)) => f(head) + infix + clistMkString(tail, infix, f) - case CList(head, None()) => f(head) - } - } - - def CListStringToString(in: CList[CList[String]]): String = { - ???[String] - } ensuring { - (res: String) => (in, res) passes { - case CList(CList(a, Some(CList(b, None()))), Some(CList(CList(c, Some(CList(d, None()))), None()))) => - a + "," + b + "\n" + c + "," + d - } - } - - import leon.collection._ - - def listStringToString(in : List[List[String]]): String = { - ???[String] - } ensuring { - (res : String) => (in, res) passes { - case Cons(Cons(a, Cons(b, Nil())), Cons(Cons(c, Cons(d, Nil())), Nil())) => - a + "," + b + "\n" + c + "," + d - } - } -} diff --git a/testcases/stringrender/ModularRender.scala b/testcases/stringrender/ModularRender.scala deleted file mode 100644 index cf46ab0ab81162d9bf13fd2cfd89c1ca842f262c..0000000000000000000000000000000000000000 --- a/testcases/stringrender/ModularRender.scala +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Name: ModularRender.scala - * Creation: 26.01.2015 - * Author: Mikael Mayer (mikael.mayer@epfl.ch) - * Comments: Modular rendering, in one order or the other. - */ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object ModularRender { - def customToString[T](l : List[T], f : (T) => String): String = { - ??? - } ensuring { - (res : String) => (l, res) passes { - case Nil() => - "[]" - case Cons(t, Nil()) => - "[" + f(t) + "]" - case Cons(ta, Cons(tb, Nil())) => - "[" + f(ta) + ", " + f(tb) + "]" - case Cons(ta, Cons(tb, Cons(tc, Nil()))) => - "[" + f(ta) + ", " + f(tb) + ", " + f(tc) + "]" - } - } - - def booleanToString(b: Boolean) = if(!b) "Up" else "Down" - - case class Configuration(flags: List[Boolean]) - - // We want to write Config:[Up,Down,Up....] - def ConfigToString(config : Configuration): String = - ???[String] ask config -} diff --git a/testcases/stringrender/OutOfOrder.scala b/testcases/stringrender/OutOfOrder.scala deleted file mode 100644 index 72785cf605cfbfe26bb70abd37651c32d5eddd42..0000000000000000000000000000000000000000 --- a/testcases/stringrender/OutOfOrder.scala +++ /dev/null @@ -1,57 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object OutOfOrderToString { - def argumentsToString(i: Int, j: Int): String = { - ??? - } ensuring { (res: String) => ((i, j), res) passes { - case (1, 2) => "2, 1" - } } - - def tupleToString(i: (Int, Int)): String = { - ??? - } ensuring { (res: String) => (i, res) passes { - case (1, 2) => "2, 1" - } } - - - def reverseList(l : List[Int]): String = { - ???[String] - } ensuring { - (res : String) => (l, res) passes { - case Cons(1, Cons(2, Nil())) => - "2, 1" - } - } - - def listPairToString(l : List[(Int, Int)]): String = { - ???[String] - } ensuring { - (res : String) => (l, res) passes { - case Cons((1, 2), Cons((3, 4), Nil())) => - "2 -> 1, 4 -> 3" - } - } - - def reverselistPairToString(l: List[(Int, Int)]): String = { - ??? - } ensuring { (res: String) => (l, res) passes { - case Cons((1, 2), Cons((3,4), Nil())) => "4 -> 3, 2 -> 1" - } } - - case class Rule(input: Int, applied: Option[Int]) - - def ruleToString(r : Rule): String = { - ??? - } ensuring { - (res : String) => (r, res) passes { - case Rule(1, None()) => - "res: 1" - case Rule(4, Some(2)) => - "Push(2): 4" - } - } -} \ No newline at end of file diff --git a/testcases/stringrender/ProblemRender.scala b/testcases/stringrender/ProblemRender.scala deleted file mode 100644 index d1d4e4bb5acbedc5ba38b03930a080c9f7aea77c..0000000000000000000000000000000000000000 --- a/testcases/stringrender/ProblemRender.scala +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Name: ListRender.scala - * Creation: 14.10.2015 - * Author: Mika�l Mayer (mikael.mayer@epfl.ch) - * Comments: First benchmark ever for solving string transformation problems. List specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object ProblemRender { - case class Identifier(name: String) - sealed abstract class StringFormToken - - case class Left(e: String) extends StringFormToken - case class Right(i: Identifier) extends StringFormToken - - type StringForm = List[StringFormToken] - - type Equation = (StringForm, String) - - /** Sequences of equalities such as xyz"1"uv"2" = "1, 2" */ - type Problem = List[Equation] - - /** Synthesis by example specs */ - @inline def psStandard(s: Problem) = (res: String) => (s, res) passes { - case Cons((Cons(Left("1"), Cons(Right(Identifier("x")), Cons(Left("2"), Nil()))), "1432"), - Cons((Cons(Right(Identifier("y")), Cons(Left("4"), Cons(Right(Identifier("y")), Nil()))), "141"), Nil())) => "\"1\"+x+\"2\"==1432, y+\"4\"+y==\"141\"" - } - ////////////////////////////////////////////// - // Non-incremental examples: pure synthesis // - ////////////////////////////////////////////// - def synthesizeStandard(s: List[Int]): String = { - ???[String] - } ensuring psStandard(s) - -} \ No newline at end of file diff --git a/testcases/stringrender/SymbolGrammarRender.scala b/testcases/stringrender/SymbolGrammarRender.scala deleted file mode 100644 index 45d2c6c43af9884d2f13771868b16508a9ee7ce0..0000000000000000000000000000000000000000 --- a/testcases/stringrender/SymbolGrammarRender.scala +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Name: SymbolGrammarRender.scala - * Creation: 14.01.2016 - * Author: Mika�l Mayer (mikael.mayer@epfl.ch) - * Comments: Grammar rendering specifications starting with symbols - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object SymbolGrammarRender { - /** A tagged symbol */ - abstract class Symbol - /** A tagged non-terminal, used for markovization */ - case class NonTerminal(tag: String, vcontext: List[Symbol], hcontext: List[Symbol]) extends Symbol - /** A tagged terminal */ - case class Terminal(tag: String) extends Symbol - - /** All possible right-hand-side of rules */ - case class Expansion(ls: List[List[Symbol]]) - /** A grammar here has a start sequence instead of a start symbol */ - case class Grammar(start: List[Symbol], rules: List[(Symbol, Expansion)]) - - def symbol_markov(s: Symbol): String = { - ???[String] - } ensuring { - (res : String) => (s, res) passes { - case Terminal("foo") => - "Tfoo" - case Terminal("\"'\n\t") => - "T\"'\n\t" - case NonTerminal("foo", Nil(), Nil()) => - "Nfoo" - case NonTerminal("\"'\n\t", Nil(), Nil()) => - "N\"'\n\t" - case NonTerminal("foo", Nil(), Cons(Terminal("foo"), Nil())) => - "Nfoo_hTfoo" - case NonTerminal("foo", Cons(Terminal("foo"), Nil()), Nil()) => - "Nfoo_vTfoo" - case NonTerminal("foo", Nil(), Cons(NonTerminal("foo", Nil(), Nil()), Cons(NonTerminal("foo", Nil(), Nil()), Nil()))) => - "Nfoo_hNfoo_Nfoo" - case NonTerminal("foo", Cons(Terminal("foo"), Nil()), Cons(NonTerminal("foo", Nil(), Nil()), Nil())) => - "Nfoo_vTfoo_hNfoo" - case NonTerminal("foo", Cons(NonTerminal("foo", Nil(), Nil()), Cons(NonTerminal("foo", Nil(), Nil()), Nil())), Nil()) => - "Nfoo_vNfoo_Nfoo" - } - } - - def grammarToString(p : Grammar): String = - ???[String] ask p -} \ No newline at end of file diff --git a/testcases/stringrender/TupleWrapperRender.scala b/testcases/stringrender/TupleWrapperRender.scala deleted file mode 100644 index 6df42174bc4f9e4a7cadec3067ce0df8ae028fd1..0000000000000000000000000000000000000000 --- a/testcases/stringrender/TupleWrapperRender.scala +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Name: TupleWrapperRender.scala - * Creation: 15.10.2015 - * Author: Mikaël Mayer (mikael.mayer@epfl.ch) - * Comments: Tuple rendering specifications. - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object TupleWrapperRender { - case class TupleWrapper(i: Int, j: Int) - - @inline def psStandard(s: TupleWrapper) = (res: String) => (s, res) passes { - case TupleWrapper(0, 0) => "TupleWrapper(0, 0)" - case TupleWrapper(-1, 2) => "TupleWrapper(-1, 2)" - case TupleWrapper(12, 5) => "TupleWrapper(12, 5)" - } - - @inline def psUnwrapped(s: TupleWrapper) = (res: String) => (s, res) passes { - case TupleWrapper(0, 0) => "0, 0" - case TupleWrapper(-1, 2) => "-1, 2" - case TupleWrapper(12, 5) => "12, 5" - } - - @inline def psNameChangedPrefix(s: TupleWrapper) = (res: String) => (s, res) passes { - case TupleWrapper(0, 0) => "x = 0, y = 0" - case TupleWrapper(-1, 2) => "x = -1, y = 2" - case TupleWrapper(12, 5) => "x = 12, y = 5" - } - - @inline def psNameChangedSuffix(s: TupleWrapper) = (res: String) => (s, res) passes { - case TupleWrapper(0, 0) => "0.0,0.0" - case TupleWrapper(-1, 2) => "-1.0,2.0" // Here there should be an ambiguity before this line. - case TupleWrapper(12, 5) => "12.0,5.0" - } - - /*@inline def psDuplicate(s: TupleWrapper) = (res: String) => (s, res) passes { - case TupleWrapper(0, 0) => "d 0,0 0,15 15,15 15,0" - case TupleWrapper(-1, 2) => "d -1,-2 -1,15 15,15 15,2" - case TupleWrapper(12, 5) => "d 12,5 12,15 15,15 15,5" - }*/ - - def repairUnWrapped(s: TupleWrapper): String = { - "TupleWrapper(" + s.i + ", " + s.j + ")" - } ensuring psUnwrapped(s) - - def repairNameChangedPrefix(s: TupleWrapper): String = { - "TupleWrapper(" + s.i + ", " + s.j + ")" - } ensuring psNameChangedPrefix(s) - - def repairNameChangedSuffix(s: TupleWrapper): String = { - "TupleWrapper(" + s.i + ", " + s.j + ")" - } ensuring psNameChangedSuffix(s) - - /*def repairDuplicate(s: TupleWrapper): String = { - "TupleWrapper(" + s.i + ", " + s.j + ")" - } ensuring psDuplicate(s)*/ - - - def synthesizeStandard(s: TupleWrapper): String = { - ???[String] - } ensuring psStandard(s) - - def synthesizeUnwrapped(s: TupleWrapper): String = { - ???[String] - } ensuring psUnwrapped(s) - - def synthesizeNameChangedPrefix(s: TupleWrapper): String = { - ???[String] - } ensuring psNameChangedPrefix(s) - - def synthesizeNameChangedSuffix(s: TupleWrapper): String = { - ???[String] - } ensuring psNameChangedSuffix(s) - - /*def synthesizeDuplicate(s: TupleWrapper): String = { - ???[String] - } ensuring psDuplicate(s)*/ -} \ No newline at end of file diff --git a/testcases/stringrender/TwoArgsWrapperRender.scala b/testcases/stringrender/TwoArgsWrapperRender.scala deleted file mode 100644 index e438affa73ea7af0352e7937cc5afb328f25b9cb..0000000000000000000000000000000000000000 --- a/testcases/stringrender/TwoArgsWrapperRender.scala +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Name: TupleWrapperRender.scala - * Creation: 15.10.2015 - * Author: Mikaël Mayer (mikael.mayer@epfl.ch) - * Comments: Tuple rendering specifications. - */ - -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ -import leon.lang._ - -object TwoArgsWrapperRender { - @inline def psStandard(s: Int, t: Int) = (res: String) => ((s, t), res) passes { - case (0, 0) => "TupleWrapper(0, 0)" - case (-1, 2) => "TupleWrapper(-1, 2)" - case (12, 5) => "TupleWrapper(12, 5)" - } - - @inline def psUnwrapped(s: Int, t: Int) = (res: String) => ((s, t), res) passes { - case (0, 0) => "0, 0" - case (-1, 2) => "-1, 2" - case (12, 5) => "12, 5" - } - - @inline def psNameChangedPrefix(s: Int, t: Int) = (res: String) => ((s, t), res) passes { - case (0, 0) => "x = 0, y = 0" - case (-1, 2) => "x = -1, y = 2" - case (12, 5) => "x = 12, y = 5" - } - - @inline def psNameChangedSuffix(s: Int, t: Int) = (res: String) => ((s, t), res) passes { - case (0, 0) => "0.0,0.0" - case (-1, 2) => "-1.0,2.0" // Here there should be an ambiguity before this line. - case (12, 5) => "12.0,5.0" - } - - /*def psDuplicate(s: Int, t: Int) = (res: String) => ((s, t), res) passes { - case (0, 0) => "d 0,0 0,15 15,15 15,0" - case (-1, 2) => "d -1,-2 -1,15 15,15 15,2" - case (12, 5) => "d 12,5 12,15 15,15 15,5" - }*/ - - def repairUnWrapped(s: Int, t: Int): String = { - "(" + s + ", " + t + ")" - } ensuring psUnwrapped(s, t) - - def repairNameChangedPrefix(s: Int, t: Int): String = { - "(" + s + ", " + t + ")" - } ensuring psNameChangedPrefix(s, t) - - def repairNameChangedSuffix(s: Int, t: Int): String = { - "(" + s + ", " + t + ")" - } ensuring psNameChangedSuffix(s, t) - - /*def repairDuplicate(s: Int, t: Int): String = { - "(" + s + ", " + t + ")" - } ensuring psDuplicate(s)*/ - - - def synthesizeStandard(s: Int, t: Int): String = { - ???[String] - } ensuring psStandard(s, t) - - def synthesizeUnwrapped(s: Int, t: Int): String = { - ???[String] - } ensuring psUnwrapped(s, t) - - def synthesizeNameChangedPrefix(s: Int, t: Int): String = { - ???[String] - } ensuring psNameChangedPrefix(s, t) - - def synthesizeNameChangedSuffix(s: Int, t: Int): String = { - ???[String] - } ensuring psNameChangedSuffix(s, t) - - /*def synthesizeDuplicate(s: Int, t: Int): String = { - ???[String] - } ensuring psDuplicate(s)*/ -} \ No newline at end of file diff --git a/testcases/stringrender/_ParseExperimental.scala b/testcases/stringrender/_ParseExperimental.scala deleted file mode 100644 index c0391c8e231daafc86a7e27c5e86edb09fa91206..0000000000000000000000000000000000000000 --- a/testcases/stringrender/_ParseExperimental.scala +++ /dev/null @@ -1,29 +0,0 @@ -import leon.collection._ -import leon.lang._ - -object Parser { - def parse[T](s: String, fs: List[String => List[T]]): List[T] = { - fs.flatMap(f => f(s)) - } - - def parseBefore(prefix: String, s: String): List[String] = { - if(StrOps.startsWith(s, prefix)) List(StrOps.substring(s, StrOps.length(prefix), StrOps.length(s))) else Nil - } - - def parseAfter(suffix: String, s: String): List[String] = { - if(StrOps.endsWith(s, suffix)) List(StrOps.substring(s, 0, StrOps.length(s) - StrOps.length(suffix))) elseNil - } - - def parseExact(res: String, s: String): Boolean = - - def splitting(s: String): List[(String, String)] = { - @tailrec def rec(i: Int, acc: List[(String, String)]): List[(String, String)] = { - if(i > StrOps.length(s)) { - acc - } else { - rec(i + 1, (StrOps.substring(s, 0, i), StrOps.substring(s, i, StrOps.length(s)))::acc) - } - } - rec(0, Nil) - } -} diff --git a/testcases/stringrender/runRepair.sh b/testcases/stringrender/runRepair.sh deleted file mode 100644 index c1b616351dc8cfd326b38358e80e722f3a31f4cf..0000000000000000000000000000000000000000 --- a/testcases/stringrender/runRepair.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -log=stringrender.last -summaryLog=stringrender.log -fullLog=fullLog.log - -echo -n "" > $log; -echo -n "" > "stringrender.table"; - - -echo "################################" >> $summaryLog -echo "#" `hostname` >> $summaryLog -echo "#" `date +"%d.%m.%Y %T"` >> $summaryLog -echo "#" `git log -1 --pretty=format:"%h - %cd"` >> $summaryLog -echo "################################" >> $summaryLog -echo "# Category, File, function, p.S, fuS, foS, Tms, Fms, Rms, verif?" >> $summaryLog - -#All benchmarks: - -#./leon --synthesis --timeout=30 --solvers=smt-cvc4 --functions=synthesizeIntStandard testcases/stringrender/Default.scala | tee -a $fullLog -#./leon --synthesis --timeout=30 --solvers=smt-cvc4 --functions=synthesizeBooleanStandard testcases/stringrender/Default.scala | tee -a $fullLog -#./leon --synthesis --timeout=30 --solvers=smt-cvc4 --functions=synthesizeBoolean2 testcases/stringrender/Default.scala | tee -a $fullLog - -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairUnwrapped testcases/stringrender/IntWrapperRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairNameChangedPrefix testcases/stringrender/IntWrapperRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairNameChangedSuffix testcases/stringrender/IntWrapperRender.scala | tee -a $fullLog -# ./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairDuplicate testcases/stringrender/IntWrapperRender.scala | tee -a $fullLog - -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairUnwrapped testcases/stringrender/TwoArgsWrapperRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairNameChangedPrefix testcases/stringrender/TwoArgsWrapperRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairNameChangedSuffix testcases/stringrender/TwoArgsWrapperRender.scala | tee -a $fullLog -# ./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairDuplicate testcases/stringrender/TwoArgsWrapperRender.scala | tee -a $fullLog - -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairUnwrapped testcases/stringrender/TupleWrapperRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairNameChangedPrefix testcases/stringrender/TupleWrapperRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairNameChangedSuffix testcases/stringrender/TupleWrapperRender.scala | tee -a $fullLog -# ./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=repairDuplicate testcases/stringrender/TupleWrapperRender.scala | tee -a $fullLog - -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render1RemoveCons testcases/stringrender/ListRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render2RemoveNil testcases/stringrender/ListRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render3RemoveLastComma testcases/stringrender/ListRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render4RemoveParentheses testcases/stringrender/ListRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render5WrapParentheses testcases/stringrender/ListRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render6List testcases/stringrender/ListRender.scala | tee -a $fullLog - -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render0RemoveBigInt testcases/stringrender/ListBigIntRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render1RemoveCons testcases/stringrender/ListBigIntRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render2RemoveNil testcases/stringrender/ListBigIntRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render3RemoveLastComma testcases/stringrender/ListBigIntRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render4RemoveParentheses testcases/stringrender/ListBigIntRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render5WrapParentheses testcases/stringrender/ListBigIntRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render6List testcases/stringrender/ListBigIntRender.scala | tee -a $fullLog - -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render0RemoveNames testcases/stringrender/GrammarRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render1ArrowRules testcases/stringrender/GrammarRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render2ListRules testcases/stringrender/GrammarRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render3SpaceRules testcases/stringrender/GrammarRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render4HTMLRules testcases/stringrender/GrammarRender.scala | tee -a $fullLog -./leon --repair --timeout=30 --solvers=smt-cvc4 --functions=render5PlainTextRules testcases/stringrender/GrammarRender.scala | tee -a $fullLog - - -# Average results -cat $log >> $summaryLog -awk '{ total1 += $7; total2 += $8; total3 += $9; count++ } END { printf "#%74s Avg: %5d, %5d, %5d\n\n", "", total1/count, total2/count, total3/count }' $log >> $summaryLog - diff --git a/testcases/synthesis/archives/ADTInduction.scala b/testcases/synthesis/archives/ADTInduction.scala deleted file mode 100644 index 5341f1cbab05f3f4e22ba398ca3e8736e03694de..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/ADTInduction.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.lang._ - -object SortedList { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - // proved with unrolling=0 - def size(l: List) : Int = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - //def sizeSynth(l: List): Int = choose{ (i: Int) => i >= 0 && sizeSynth(Cons(0, l)) == i + 1} - - def content(l: List): Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(i, t) => Set(i) ++ content(t) - } - - //def artifialSubcase(v : Int) = choose { - // (out : List) => - // content(out) == (content(Nil()) -- Set(v)) - //} - - def deleteSynth(in: List, v: Int) = (in match { - case Cons(head22, tail21) => - (tail21 match { - case Cons(head23, tail23) => - (choose { (out: List) => - (content(out) == (content(Cons(head22, Cons(head23, tail23))) -- Set(v))) - }) - case _ => - (choose { (out: List) => - (content(out) == (content(Cons(head22, Nil())) -- Set(v))) - }) - }) - case _ => - Nil() - }) - - def concatSynth(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) ++ content(in2) - } - - 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)) - } -} diff --git a/testcases/synthesis/archives/BinaryTree.scala b/testcases/synthesis/archives/BinaryTree.scala deleted file mode 100644 index b24a6ddbc07623dd877f3113e1965594cc867fab..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/BinaryTree.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case class Leaf() extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def delete(in : Tree, v : Int) = choose { (out : Tree) => - content(out) == (content(in) -- Set(v)) - } - - def deleteSubProblem(left : Tree, leftR: Tree, value: Int, rightRleft: Tree, rightRvalue: Int, rightRright: Tree, rightR: Tree, right: Tree, toRemove : Int) = choose { (out : Tree) => - content(out) == (content(Node(left, value, right)) -- Set(toRemove)) && content(leftR) == (content(left) -- Set(toRemove)) && rightR == Node(rightRleft, rightRvalue, rightRright) && content(Node(rightRleft, rightRvalue, rightRright)) == (content(right) -- Set(toRemove)) && value == toRemove - } - - def deleteSubProblem2(left : Tree, leftR: Tree, value: Int, rightRleft: Tree, rightRvalue: Int, rightRright: Tree, right: Tree, toRemove : Int) = choose { (out : Tree) => - content(out) == (content(Node(left, value, right)) -- Set(toRemove)) && content(leftR) == (content(left) -- Set(toRemove)) && content(Node(rightRleft, rightRvalue, rightRright)) == (content(right) -- Set(toRemove)) && value == toRemove - } -} diff --git a/testcases/synthesis/archives/CegisExamples.scala b/testcases/synthesis/archives/CegisExamples.scala deleted file mode 100644 index 431cfa8ca1dcd1ed9ed1c7af1bcb950e5000d05b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/CegisExamples.scala +++ /dev/null @@ -1,25 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object CegisTests { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - // proved with unrolling=0 - 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() - case Cons(i, t) => Set(i) ++ content(t) - } - - def cegis1(a: Int) = choose { x: List => size(x) == 1 && content(x) == Set(a) } - def cegis2(a: Int) = choose { x: List => size(x) == 2 && content(x) == Set(a) } - def cegis3(a: Int) = choose { x: List => size(x) == 3 && content(x) == Set(a) } - def cegis4(a: Int) = choose { x: List => size(x) == 4 && content(x) == Set(a) } - def cegis5(a: Int) = choose { x: List => size(x) == 5 && content(x) == Set(a) } -} diff --git a/testcases/synthesis/archives/CegisFunctions.scala b/testcases/synthesis/archives/CegisFunctions.scala deleted file mode 100644 index 92d79426ef3d3a5c47ce92c18e4295a3ea6ae060..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/CegisFunctions.scala +++ /dev/null @@ -1,31 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object CegisTests { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - // proved with unrolling=0 - 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() - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert(l: List, i: Int) = { - Cons(i, l) - }.ensuring(res => size(res) == size(l)+1 && content(res) == content(l) ++ Set(i)) - - def testInsert(l: List, i: Int) = { - choose { (o: List) => size(o) == size(l) + 1 } - } - - def testDelete(l: List, i: Int) = { - choose { (o: List) => size(o) == size(l) - 1 } - } -} diff --git a/testcases/synthesis/archives/ChooseArith.scala b/testcases/synthesis/archives/ChooseArith.scala deleted file mode 100644 index 572cf790d0f5a55d2dd5b8a18ed1f33f6f8448ef..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/ChooseArith.scala +++ /dev/null @@ -1,7 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChooseArith { - def c1(a : Int) : (Int, Int) = - choose((x:Int,y:Int) => 2*x + 4*a == -y) -} diff --git a/testcases/synthesis/archives/ChooseIneq.scala b/testcases/synthesis/archives/ChooseIneq.scala deleted file mode 100644 index 127b047d35d221daecd1346c14e08854641d3428..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/ChooseIneq.scala +++ /dev/null @@ -1,12 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChooseIneq { - def c1(a: Int, b: Int): (Int, Int) = { - choose ((x: Int, y: Int) => -3*x + 2*y -b <= a && 2*x - a <= 4*y + b) - } - - def c2(a : Int) : (Int, Int) = choose { - (x : Int, y : Int) => 5*x + 7*y == a && 0 <= x && x <= y - } -} diff --git a/testcases/synthesis/archives/ChoosePos.scala b/testcases/synthesis/archives/ChoosePos.scala deleted file mode 100644 index f0db1d91e6f0c826a3ab263d4134a0625692e056..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/ChoosePos.scala +++ /dev/null @@ -1,8 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChoosePos { - - def c1(x: BigInt): BigInt = choose { (y: BigInt) => y > x } - -} diff --git a/testcases/synthesis/archives/ChurchNumerals.scala b/testcases/synthesis/archives/ChurchNumerals.scala deleted file mode 100644 index 5f6f6c1cdc3b9a5e4adf2af4ec9c1e0fbff2ec95..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/ChurchNumerals.scala +++ /dev/null @@ -1,28 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChurchNumerals { - sealed abstract class Num - case class Zero() extends Num - case class Succ(pred:Num) extends Num - - def value(n:Num) : Int = { - n match { - case Zero() => 0 - case Succ(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def succ(n:Num) : Num = Succ(n) ensuring(value(_) == value(n) + 1) - - def add(x:Num, y:Num):Num = { - choose { (r : Num) => - value(r) == value(x) + value(y) - } - } - - def workingAdd(x : Num, y : Num) : Num = (x match { - case Zero() => y - case Succ(p) => workingAdd(p, Succ(y)) - }) ensuring (value(_) == value(x) + value(y)) -} diff --git a/testcases/synthesis/archives/DrSuter.scala b/testcases/synthesis/archives/DrSuter.scala deleted file mode 100644 index 42adaa55be57e2c70751a556ac730239d419e5ee..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/DrSuter.scala +++ /dev/null @@ -1,16 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object DrSuter { - - abstract class List - case class Nil() extends List - case class Cons(head : Int, tail : List) extends List - - def myChoose(a : List) : (Int,Int,List) = { - choose { (x: Int, y: Int, ys: List) => - Cons(x, Cons(y, ys)) == a && x == y || - Cons(x, ys) == a && x < 0 - } - } -} diff --git a/testcases/synthesis/archives/FastExp.scala b/testcases/synthesis/archives/FastExp.scala deleted file mode 100644 index ef288f3bb960b0c0a6b656550d67405ecaa6f9f6..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/FastExp.scala +++ /dev/null @@ -1,23 +0,0 @@ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.lang._ - -object FastExp { - - def test(a : Int) : Int = { - val j1 = choose((k: Int) => 2*k == a) - val j2 = choose((k: Int) => 2*k + 1 == a) - j1 + j2 - } - - //def fp(m : Int, b : Int, i : Int) : Int = i match { - // case 0 => m - // case 2 * j => fp(m, b*b, j) - // case 2 * j + 1 => fp(m*b, b*b, j) - //} - - //def pow(base: Int, p: Int) = { - // fp(1, base, p) - //} - -} diff --git a/testcases/synthesis/archives/FiniteSort.scala b/testcases/synthesis/archives/FiniteSort.scala deleted file mode 100644 index afe827bb76a857aea1e500aec7427585e11016d9..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/FiniteSort.scala +++ /dev/null @@ -1,19 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object FiniteSort { - - def sort3(x1: Int, x2: Int, x3: Int): (Int, Int, Int) = { - choose((z1: Int, z2: Int, z3: Int) => - z1 <= z2 && z2 <= z3 && ( - (z1 == x1 && z2 == x2 && z3 == x3) || - (z1 == x1 && z2 == x3 && z3 == x2) || - (z1 == x2 && z2 == x1 && z3 == x3) || - (z1 == x2 && z2 == x3 && z3 == x1) || - (z1 == x3 && z2 == x1 && z3 == x2) || - (z1 == x3 && z2 == x2 && z3 == x1) - ) - ) - } - -} diff --git a/testcases/synthesis/archives/Injection.scala b/testcases/synthesis/archives/Injection.scala deleted file mode 100644 index 5bc7a41b51624e2596e4fac22d1fac1f07f16f97..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/Injection.scala +++ /dev/null @@ -1,24 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Injection { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - // proved with unrolling=0 - def size(l: List) : Int = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - - def listOfSizeSynth(in: List, i: Int) = choose{out: List => (size(out) == i) && (size(in) == i) } - def listOfSizeSynth2(i: Int) = choose{out: List => size(out) == i } - - def subProblem(in: List, i: Int) = choose{out: List => (size(out) == i) && (size(in)+1 == i) } - def simple(in: List) = choose{out: List => size(out) == size(in) } - - def invalidInjection(in: List, i: Int) = choose{out: List => (size(out) == i) && (size(in) == i) && in != out } -} diff --git a/testcases/synthesis/archives/InnerSplit.scala b/testcases/synthesis/archives/InnerSplit.scala deleted file mode 100644 index 1db595ba9954f21f9aba9e14c77bc3e513d86fc7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/InnerSplit.scala +++ /dev/null @@ -1,6 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object Test { - def test(x: Int, y: Int) = choose((z: Int) => z >= x && z >= y && (z == x || z == y)) -} diff --git a/testcases/synthesis/archives/Justify.scala b/testcases/synthesis/archives/Justify.scala deleted file mode 100644 index c396d6a01ebbdb34ba398163bbf88a282712405f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/Justify.scala +++ /dev/null @@ -1,156 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object Justify { - - abstract class IntList - case class IntCons(head: Int, tail: IntList) extends IntList - case class IntNil() extends IntList - - /* - * The Science of Programming from David Gries Section 20.1 - - * The goal is to justify a text. We are given a list of indices corresponding - * to the columns of the starting point of each word. Each words are already - * separated by one space. The parameter s is the additional number of spaces - * at the end of the line that we will need to add between words. We - * want the number of space on the same line to differ by at most one. - * - * If we denote by p and q the two number of spaces between words (p and q differ - * only by 1), then we want to only switch once the number of space between words - * on the line. This means that we first separate words using p, then we do it using - * q until the end of the line. - * - * z is the line number, the rule is for odd line number to have more spaces on the right (q=p+1) - * and for even line number to have more spaces on the left (p=q+1). We do not want trailing - * spaces. - * - * n is the number of words on the line. - * - * If we apply this justify to each line of a text separately, this should lead to a good looking - * justified text. - - * Here is an example: - * - * justifying lines by - * inserting extra blanks is - * one task of a text editor. - * - * results in: - * - * justifying lines by - * inserting extra blanks is - * one task of a text editor. - */ - def justify(n: Int, z: Int, s: Int, words: IntList): IntList = { - require(n >= 0 && s >= 0 && z >= 1) - - //here p and q are as defined above. t is used to find the index of the word where - //we switch from p spaces to q spaces. - val (res, p, q, t) = choose((justifiedWords: IntList, p: Int, q: Int, t: Int) => - p >= 0 && q >= 0 && t >= 1 && t <= n && - p*(t-1) + q*(n-t) == s && //this constraint is probably going to be an issue since it is non linear - ((z % 2 == 1 && q == p + 1) || (z % 2 == 0 && p == q + 1)) && - justifiedWords == addSpaces(words, p, q, t, n, 0) //this is likely to be problematic as well - ) - - res - } - - def addSpaces(words: IntList, p: Int, q: Int, t: Int, n: Int, i: Int): IntList = words match { - case IntNil() => IntNil() - case IntCons(head, tail) => - if(i <= t) IntCons(head + p*(i-1), addSpaces(tail, p, q, t, n, i+1)) - else if(i > t && i <= n) IntCons(head + p*(t-1) + q*(i-t), addSpaces(tail, p, q, t, n, i+1)) - else IntNil() //this should never happen - } - - //this version implements the computation of parameters - def justifyParamsImpl(n: Int, z: Int, s: Int): (Int, Int, Int) = { - require(n >= 2 && s >= 0 && z >= 1) - val (q, t, p) = if(z % 2 == 0) { - val tmp = s / (n-1) - (tmp, 1 + (s % (n - 1)), tmp + 1) - } else { - val tmp = s / (n-1) - (tmp + 1, n - (s % (n - 1)), tmp) - } - (q, t, p) - } ensuring(res => { - val (q, t, p) = res - p >= 0 && q >= 0 && t >= 1 && t <= n && p*(t - 1) + q*(n-t) == s && - ((z % 2 == 1 && q == p + 1) || (z % 2 == 0 && p == q + 1)) - }) - - def justifyImpl(n: Int, z: Int, s: Int, words: IntList): (Int, Int, Int, IntList) = { - require(n >= 2 && s >= 0 && z >= 1) - val (q, t, p) = if(z % 2 == 0) { - val tmp = s / (n-1) - (tmp, 1 + (s % (n - 1)), tmp + 1) - } else { - val tmp = s / (n-1) - (tmp + 1, n - (s % (n - 1)), tmp) - } - (q, t, p, addSpaces(words, p, q, t, n, 0)) - } ensuring(res => { - val (q, t, p, justifiedWords) = res - p >= 0 && q >= 0 && t >= 1 && t <= n && - p*(t-1) + q*(n-t) == s && //this constraint is probably going to be an issue since it is non linear - ((z % 2 == 1 && q == p + 1) || (z % 2 == 0 && p == q + 1)) && - justifiedWords == addSpaces(words, p, q, t, n, 0) //this is likely to be problematic as well - }) - - /* - * This version is a simpler one, in which we are just trying to determine parameters that can then - * be mecanically used to build the justified text. Also we do not distinguish on even/odd line number. - */ - def simpleJustify(n: Int, z: Int, s: Int, words: IntList): (Int, Int, Int) = { - require(n >= 0 && s >= 0 && z >= 1) - - val (p, q, t) = choose((p: Int, q: Int, t: Int) => - p >= 0 && q >= 0 && p == q+1 && t >= 1 && t <= n && p*(t - 1) + q*(n-t) == s - ) - - //actually, we could simply use the parameter to program the ocnstruction of the List, rather than explicitly synthesizing it - (p, q, t) - } - - //we use ascii code to represent text, 32 is the space separator - case class Word(chars: IntList) - - abstract class WordList - case class WordCons(word: IntList, tail: WordList) extends WordList - case class WordNil() extends WordList - - def tokenize(ascii: IntList): WordList = tokenize0(ascii, IntNil()) - def tokenize0(ascii: IntList, wordAcc: IntList): WordList = ascii match { - case IntNil() => WordNil() - case IntCons(head, tail) => if(head == 32) (wordAcc match { - case IntNil() => tokenize0(tail, IntNil()) - case IntCons(l, ls) => WordCons(wordAcc, tokenize0(tail, IntNil())) - }) else tokenize0(tail, IntCons(head, wordAcc)) - } - - - //we assume only one space between each word. This is the assumption made - //in the representation used in the previous algorithm - - def asciiToPos(in: IntList, index: Int): IntList = in match { - case IntNil() => IntNil() - case IntCons(head, tail) => if(head == 32) IntCons(index, asciiToPos(tail, index+1)) else asciiToPos(tail, index+1) - } - - def posToAscii(positions: IntList, originalText: IntList, currentPos: Int): IntList = positions match { - case IntCons(start, rest) => if(start > currentPos) IntCons(32, posToAscii(rest, originalText, currentPos+1)) else - (originalText match { - case IntCons(l, ls) => if(l == 32) IntCons(32, posToAscii(rest, ls, currentPos+1)) else IntCons(l, posToAscii(positions, ls, currentPos+1)) - case IntNil() => IntNil() - }) - case IntNil() => IntNil() - } - - def posToAsciiKeepTokens(ascii: IntList) = { - posToAscii(asciiToPos(ascii, 0), ascii, 0) - } ensuring(res => tokenize(res) == tokenize(ascii)) - -} diff --git a/testcases/synthesis/archives/Matching.scala b/testcases/synthesis/archives/Matching.scala deleted file mode 100644 index 861798cf7465e2622f69fcc70d8c48a32d6f4cb8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/Matching.scala +++ /dev/null @@ -1,14 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object Matching { - def t1(a: NatList) = choose( (x: Nat) => Cons(x, Nil()) == a) - - abstract class Nat - case class Z() extends Nat - case class Succ(n: Nat) extends Nat - - abstract class NatList - case class Nil() extends NatList - case class Cons(head: Nat, tail: NatList) extends NatList -} diff --git a/testcases/synthesis/archives/ScaleWeight.scala b/testcases/synthesis/archives/ScaleWeight.scala deleted file mode 100644 index 52081df23c5dfc8d674548367ee9513077a11646..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/ScaleWeight.scala +++ /dev/null @@ -1,13 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ScaleWeight { - - def sw(weight: Int): (Int, Int, Int, Int) = choose((w4:Int,w3:Int,w2:Int,w1:Int) => ( - w1 + 3 * w2 + 9 * w3 + 27 * w4 == weight - && -1 <= w1 && w1 <= 1 - && -1 <= w2 && w2 <= 1 - && -1 <= w3 && w3 <= 1 - && -1 <= w4 && w4 <= 1 - )) -} diff --git a/testcases/synthesis/archives/Sec2Time.scala b/testcases/synthesis/archives/Sec2Time.scala deleted file mode 100644 index 893f7e67ef8c0d981e478acf0975ad23dc3fc940..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/Sec2Time.scala +++ /dev/null @@ -1,12 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object Sec2Time { - - def s2t(total: Int) : (Int, Int, Int) = - choose((h: Int, m: Int, s: Int) => - 3600*h + 60*m + s == total && - h >= 0 && m >= 0 && m < 60 && s >= 0 && s < 60 - ) - -} diff --git a/testcases/synthesis/archives/SimplestCegis.scala b/testcases/synthesis/archives/SimplestCegis.scala deleted file mode 100644 index 678e3f4f04afbf576db954a4f8fb2e77b44937c8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/SimplestCegis.scala +++ /dev/null @@ -1,17 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Injection { - sealed abstract class List - case class Cons(tail: List) extends List - case class Nil() extends List - - // proved with unrolling=0 - def size(l: List) : Int = (l match { - case Nil() => 0 - case Cons(t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def simple(in: List) = choose{out: List => size(out) == size(in) } -} diff --git a/testcases/synthesis/archives/Spt.scala b/testcases/synthesis/archives/Spt.scala deleted file mode 100644 index 82a286e81f864821bb6998ccff351813188c3196..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/Spt.scala +++ /dev/null @@ -1,62 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -// Examples taken from http://lara.epfl.ch/~psuter/spt/ -object SynthesisProceduresToolkit { - - def e1(a: Nat, b: Nat, c: Nat): Nat = { - if (b == c) { - if (a == c) { - choose { (x: Nat) => x != a } - } else { - choose { (x: Nat) => x != a && x != b } - } - } else { - if (a == b) { - choose { (x: Nat) => x != a && x != c } - } else { - choose { (x: Nat) => x != a && x != b && x != c } - } - } - } - - def e2(): (Nat, Nat, Nat) = (Z(), Succ(Z()), Succ(Succ(Succ(Z())))) - - def e3(a1 : Nat, a2 : Nat, a3 : Nat, a4 : Nat): (Nat, Nat) = (a3, a4) - - def e4(a1 : Nat, a2 : Nat, a3 : Nat, a4 : Nat): (Nat, Nat, NatList) = (Succ(a2), a1, Nil()) - - def e5(a1 : NatList, a2 : Nat, a3 : NatList): (Nat, NatList, Nat, NatList) = - choose { (x1: Nat, x2: NatList, x3: Nat, x4: NatList) => - Cons(Succ(x1), x2) == a1 && Succ(x1) != a2 && a3 == Cons(x3, Cons(x3, x4)) - } - - def e6(a: Nat, b: Nat): (Nat, NatList) = { - if (a == Succ(b)) { - (Z(), Nil()) - } else { - leon.lang.error[(Nat, NatList)]("Precondition failed") - } - } - - def e7(a1 : NatList, a2 : Nat, a3 : NatList): (Nat, NatList, Nat, NatList) = - choose { (x1: Nat, x2: NatList, x3: Nat, x4: NatList) => - Cons(Succ(x1), x2) == a1 && Succ(x1) != a2 && a3 == Cons(x3, Cons(x3, x4)) - } - - def e8(a : Nat) = a match { - case Succ(n150) => - n150 - case _ => - leon.lang.error[(Nat)]("Precondition failed") - } - - abstract class Nat - case class Z() extends Nat - case class Succ(n: Nat) extends Nat - - abstract class NatList - case class Nil() extends NatList - case class Cons(head: Nat, tail: NatList) extends NatList - -} diff --git a/testcases/synthesis/archives/Unification.scala b/testcases/synthesis/archives/Unification.scala deleted file mode 100644 index 121644deca6a35343c835e6aadc0f44457d284cc..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/Unification.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnificationSynthesis { - - def u1(a1: Int): Int = choose { (x1: Int) => Cons(x1, Nil()) == Cons(a1, Nil()) } - - def u2(a1: Int): Int = choose { (x1: Int) => Cons(x1, Nil()) == Cons(x1, Cons(2, Nil())) } - - def u3(a1: Int): (Int,Int) = choose { (x1: Int, x2: Int) => Cons(x1, Nil()) == Cons(x2, Cons(a1, Nil())) } - - def u4(a1: Int): List = choose { (xs: List) => Cons(a1, xs) == xs } - - def u5(a1: Int): List = choose { (xs: List) => Cons(a1, Nil()) == xs } - - def u6(a1: List): Int = choose { (xs: Int) => Cons(xs, Nil()) == a1 } - - sealed abstract class List - case class Nil() extends List - case class Cons(head : Int, tail : List) extends List - - def size(lst : List) : Int = (lst match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) -} diff --git a/testcases/synthesis/archives/ZuneBug.scala b/testcases/synthesis/archives/ZuneBug.scala deleted file mode 100644 index fd4da94410f93411e5b567a6d514d80508867990..0000000000000000000000000000000000000000 --- a/testcases/synthesis/archives/ZuneBug.scala +++ /dev/null @@ -1,58 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -/* Inspired by the Zune bug that caused looping. - This encodes the task of date conversion into - integer linear arithmetic and tries to synthesize it. -*/ - -object ZuneBug { - @inline - def leapsTill(year: BigInt): BigInt = { - require(year >= 0) - val y1 = year - 1 - y1/4 + y1/100 + y1/400 - } - - @inline - def isLeap(year: BigInt): Boolean = { - require(year >= 0) - leapsTill(year+1) > leapsTill(year) - } - - // wrong, accidentaly underspecified - def yearDayConfused(daysSince1980: BigInt): (BigInt, BigInt) = { - require(daysSince1980 >= 0) - ???[(BigInt,BigInt)] - } ensuring (res => { - val (year, day) = res - year >= 1980 && - 0 <= day && day <= 366 && - (day == 366 ==> isLeap(year)) && - daysSince1980 == (year - 1980)*365 + - leapsTill(year) - leapsTill(1980) + day - }) - - // should be correct - def yearDay(daysSince1980: BigInt): (BigInt, BigInt) = { - require(daysSince1980 >= 0) - ???[(BigInt,BigInt)] - } ensuring (res => { - val (year, day) = res - year >= 1980 && - 0 <= day && day <= 365 && - (day == 365 ==> isLeap(year)) && - daysSince1980 == (year - 1980)*365 + - leapsTill(year) - leapsTill(1980) + day - }) - - // test run-time constraint solving. smt-cvc4 seems fastest - def testYearDay = { - (yearDay(364), - yearDay(365), - yearDay(366), - yearDay(366+364), - yearDay(366+365)) - } - -} diff --git a/testcases/synthesis/cav2013/AVLTree.scala b/testcases/synthesis/cav2013/AVLTree.scala deleted file mode 100644 index c9b4b116e3a08b78e631e9d86cefc6e1ce229688..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/AVLTree.scala +++ /dev/null @@ -1,90 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object AVLTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case class Leaf() extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def height(t: Tree): Int = t match { - case Leaf() => 0 - case Node(l, _, r) => - val lh = height(l) - val rh = height(r) - if (rh > lh) { - rh+1 - } else { - lh+1 - } - } - - def isSortedMinMax(t: Tree, min: Int, max: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMinMax(l, min, v) && - isSortedMinMax(r, v, max) && - v < max && v > min - case _ => true - } - - def isSortedMin(t: Tree, min: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMinMax(l, min, v) && - isSortedMin(r, v) && - v > min - case _ => true - } - - def isSortedMax(t: Tree, max: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMax(l, v) && - isSortedMinMax(r, v, max) && - v < max - case _ => true - } - - def isBalanced(t: Tree): Boolean = t match { - case Node(l, v, r) => - val diff = height(l)-height(r) - - !(diff > 1 || diff < -1) && isBalanced(l) && isBalanced(r) - case Leaf() => - true - } - - def isSorted(t: Tree): Boolean = t match { - case Node(l, v, r) => - isSortedMin(r, v) && - isSortedMax(l, v) - case _ => true - } - - def deleteSynth(in : Tree, v : Int) = choose { - (out : Tree) => content(out) == (content(in) -- Set(v)) - } - - def insertSynth(in : Tree, v : Int) = choose { - (out : Tree) => content(out) == (content(in) ++ Set(v)) - } - - def insertBalancedSynth(in: Tree, v: Int) = choose { - (out : Tree) => isBalanced(in) && (content(out) == (content(in) ++ Set(v))) && isBalanced(out) - } - - def insertSortedSynth(in : Tree, v : Int) = choose { - (out : Tree) => isSorted(in) && (content(out) == (content(in) ++ Set(v))) && isSorted(out) - } - - def deleteSortedSynth(in : Tree, v : Int) = choose { - (out : Tree) => isSorted(in) && (content(out) == (content(in) -- Set(v))) && isSorted(out) - } - - def deleteBalancedSynth(in: Tree, v: Int) = choose { - (out : Tree) => isBalanced(in) && (content(out) == (content(in) -- Set(v))) && isBalanced(out) - } -} diff --git a/testcases/synthesis/cav2013/BinaryTree.scala b/testcases/synthesis/cav2013/BinaryTree.scala deleted file mode 100644 index 84894af10cf0f7f1653798d6ef0f22091616f707..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/BinaryTree.scala +++ /dev/null @@ -1,61 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case class Leaf() extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def isSortedMinMax(t: Tree, min: Int, max: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMinMax(l, min, v) && - isSortedMinMax(r, v, max) && - v < max && v > min - case _ => true - } - - def isSortedMin(t: Tree, min: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMinMax(l, min, v) && - isSortedMin(r, v) && - v > min - case _ => true - } - - def isSortedMax(t: Tree, max: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMax(l, v) && - isSortedMinMax(r, v, max) && - v < max - case _ => true - } - - def isSorted(t: Tree): Boolean = t match { - case Node(l, v, r) => - isSortedMin(r, v) && - isSortedMax(l, v) - case _ => true - } - - def deleteSynth(in : Tree, v : Int) = choose { - (out : Tree) => content(out) == (content(in) -- Set(v)) - } - - def insertSynth(in : Tree, v : Int) = choose { - (out : Tree) => content(out) == (content(in) ++ Set(v)) - } - - def insertSortedSynth(in : Tree, v : Int) = choose { - (out : Tree) => isSorted(in) && (content(out) == (content(in) ++ Set(v))) && isSorted(out) - } - - def deleteSortedSynth(in : Tree, v : Int) = choose { - (out : Tree) => isSorted(in) && (content(out) == (content(in) -- Set(v))) && isSorted(out) - } -} diff --git a/testcases/synthesis/cav2013/List.scala b/testcases/synthesis/cav2013/List.scala deleted file mode 100644 index 08fcfc4c175dcbaad1985e8e0562a968fba4dc55..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/List.scala +++ /dev/null @@ -1,41 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object List { - sealed abstract class 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) - }) 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/ListByExample.scala b/testcases/synthesis/cav2013/ListByExample.scala deleted file mode 100644 index 9b450f4ab7e570ab6cb256438983773ea330b03b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/ListByExample.scala +++ /dev/null @@ -1,61 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Lists { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def size(l:List): Int = (l match { - case Nil() => 0 - case Cons(h,t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def listUp(a:Int,b:Int) : List = { - require(a <= b) - if (a == b) Cons(a,Nil()) - else Cons(a, listUp(a+1,b)) - } ensuring (res => size(res)==1+b-a) - - def listUp_syn(a:Int,b:Int) : List = { - require(a <= b) - choose((res:List) => - size(res)==1+b-a && - (!(a==5 && b==9) || res==Cons(5,Cons(6,Cons(7,Cons(8,Cons(9,Nil())))))) && - (!(a==100 && b==105) || - res==Cons(100,Cons(101,Cons(102,Cons(103,Cons(104,Cons(105,Nil()))))))) - ) - } - - def listDown(a:Int,b:Int) : List = { - require(a >= b) - if (a == b) Cons(a,Nil()) - else Cons(a, listUp(a-1,b)) - } ensuring (res => size(res)==1+b-a) - - def listDown_syn(a:Int,b:Int) : List = { - require(a >= b) - choose((res:List) => - size(res)==1+b-a && - (!(a==9 && b==5) || res==Cons(9,Cons(8,Cons(7,Cons(6,Cons(5,Nil())))))) && - (!(a==105 && b==100) || - res==Cons(105,Cons(104,Cons(103,Cons(102,Cons(101,Cons(100,Nil()))))))) - ) - } - - def concat_syn(a:List, b:List) : List = { - choose((res:List) => - size(res) == size(a) + size(b) && - (!(a==listUp(1,5) && b==listUp(6,9)) || - res==listUp(1,9)) && - (!(a==listUp(101,105) && b==listUp(106,109)) || - res==listUp(101,109)) && - (!(a==listUp(201,205) && b==listUp(206,209)) || - res==listUp(201,209)) && - (!(a==listUp(301,304) && b==listUp(304,310)) || - res==listUp(301,310)) - ) - } - -} diff --git a/testcases/synthesis/cav2013/ManyTimeSec.scala b/testcases/synthesis/cav2013/ManyTimeSec.scala deleted file mode 100644 index 3aba9ecac24ba6ae6c63e537bf47e18f1fed7e35..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/ManyTimeSec.scala +++ /dev/null @@ -1,109 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object ManyTimeSec { - case class Time(h:Int,m:Int,s:Int) - case class Seconds(total:Int) - - def timeAndSec(t:Time,seconds:Seconds) : Boolean = { - 3600*t.h + 60*t.m + t.s == seconds.total && - t.h >= 0 && t.m >= 0 && t.m < 60 && t.s >= 0 && t.s < 60 - } - def time2sec(t:Time) : Seconds = - choose((seconds:Seconds) => timeAndSec(t,seconds)) - def sec2time(seconds:Seconds):Time = - choose((t:Time) => timeAndSec(t,seconds)) - - def incTime(t0:Time,k:Int) : Time = - choose((t1:Time) => time2sec(t1).total == time2sec(t0).total + k) - - def testDetuple1(k:Int) : Seconds = { - choose((seconds0:Seconds) => - k == 2*seconds0.total - ) - } - def testDetuple2(total:Int) : Time = { - require(0 <= total) - choose((t:Time) => - 3600*t.h + 60*t.m + t.s == total && - t.h >= 0 && t.m >= 0 && t.m < 60 && t.s >= 0 && t.s < 60 - ) - } - - def incTimeUnfolded(t0:Time,k:Int) : Time = { - require(0 <= t0.h && 0 <= t0.m && t0.m < 60 && 0 <= t0.s && t0.s < 60) - choose((t1:Time,seconds0:Seconds) => - 3600*t0.h + 60*t0.m + t0.s == seconds0.total && - 3600*t1.h + 60*t1.m + t1.s == seconds0.total + k && - t1.h >= 0 && t1.m >= 0 && t1.m < 60 && t1.s >= 0 && t1.s < 60 - )._1 - } - - def incTimeUnfoldedOutOnly(t0:Time,k:Int) : Time = { - require(0 <= t0.h && 0 <= t0.m && t0.m < 60 && 0 <= t0.s && t0.s < 60) - val total = k + 3600*t0.h + 60*t0.m + t0.s - choose((t1:Time) => - 3600*t1.h + 60*t1.m + t1.s == total + k && - t1.h >= 0 && t1.m >= 0 && t1.m < 60 && t1.s >= 0 && t1.s < 60 - ) - } - - def incTime2(h1:Int,m1:Int,s1:Int,k:Int) : (Int,Int,Int) = { - require(0 <= k && 0 <= h1 && 0 <= m1 && m1 < 60 && 0 <= s1 && s1 < 60) - choose((h2:Int,m2:Int,s2:Int) => - 0 <= m2 && m2 < 60 && 0 <= s2 && s2 < 60 && - 3600*h2+60*m2+s2 == 3600*h1+60*m1+s1 + k) - } - - def incTime2one(h1:Int,m1:Int,s1:Int) : (Int,Int,Int) = { - require(0 <= h1 && 0 <= m1 && m1 < 60 && 0 <= s1 && s1 < 60) - choose((h2:Int,m2:Int,s2:Int) => - 0 <= m2 && m2 < 60 && 0 <= s2 && s2 < 60 && - 3600*h2+60*m2+s2 == 3600*h1+60*m1+s1 + 1) - } - - // Yes, we can, do it without multiply and divide - def incTime3one(h1:Int,m1:Int,s1:Int) : (Int,Int,Int) = { - require(0 <= h1 && 0 <= m1 && m1 < 60 && 0 <= s1 && s1 < 60) - if (s1 + 1 < 60) - (h1,m1,s1+1) - else - if (m1 + 1 < 60) - (h1,m1+1,0) - else - (h1+1,0,0) - } ensuring(res => { - val (h2,m2,s2) = res - 0 <= m2 && m2 < 60 && 0 <= s2 && s2 < 60 && - 3600*h2+60*m2+s2 == 3600*h1+60*m1+s1 + 1 - }) - - case class RedundantTime(t:Time, s:Seconds) - def isOkRT(rt:RedundantTime) : Boolean = timeAndSec(rt.t, rt.s) - - def incRT(rt0:RedundantTime, k:Int) : RedundantTime = { - require(isOkRT(rt0)) - choose((rt1:RedundantTime) => isOkRT(rt1) && rt1.s.total == rt0.s.total + k) - } - - abstract class RedundantTimeList - case class Nil() extends RedundantTimeList - case class Cons(head:RedundantTime,tail:RedundantTimeList) extends RedundantTimeList - - def isInced(l1:RedundantTimeList, k:Int, l2:RedundantTimeList) : Boolean = { - (l1,l2) match { - case (Nil(),Nil()) => true - case (Cons(rt1,rest1),Cons(rt2,rest2)) => { - isOkRT(rt1) && isOkRT(rt2) && - (rt2.s.total == rt2.s.total + k) && - isInced(rest1,k,rest2) - } - case _ => false - } - } - - def incAll(l:RedundantTimeList, k:Int) : RedundantTimeList = - choose((res:RedundantTimeList) => isInced(l,k,res)) - -} diff --git a/testcases/synthesis/cav2013/SortedList.scala b/testcases/synthesis/cav2013/SortedList.scala deleted file mode 100644 index 32b59d6011e3ca29ac0d3bff96c735ee29e56669..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/SortedList.scala +++ /dev/null @@ -1,45 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -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/Sorting.scala b/testcases/synthesis/cav2013/Sorting.scala deleted file mode 100644 index bdbd870c92cac14fb743251624f44536a39eab59..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/Sorting.scala +++ /dev/null @@ -1,282 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -// Sorting lists is a fundamental problem in CS. -object Sorting { - // Data types - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class LList - case class LCons(head : List, tail : LList) extends LList - case class LNil() extends LList - - // Abstraction functions - def content(list : List) : Set[Int] = list match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def lContent(llist : LList) : Set[Int] = llist match { - case LNil() => Set.empty[Int] - case LCons(x, xs) => content(x) ++ lContent(xs) - } - - def size(list : List) : Int = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def isSorted(list : List) : Boolean = list match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def lIsSorted(llist : LList) : Boolean = llist match { - case LNil() => true - case LCons(x, xs) => isSorted(x) && lIsSorted(xs) - } - - @induct - def sortedLemma(a: Int, x: Int, b: List) = { - !(isSorted(Cons(a,b)) && (content(b) contains x)) || (x >= a) - } holds - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - /*************************** - * * - * I N S E R T I O N * - * * - ***************************/ - - def insertSpec(elem : Int, list : List, res : List) : Boolean = { -// isSorted(list) && // Part of precondition, really. - isSorted(res) && content(res) == content(list) ++ Set(elem) - } - - def insert(elem : Int, list : List) : List = { - require(isSorted(list)) - choose { (res : List) => insertSpec(elem, list, res) } - } - - //require(head < elem && isSorted(Cons(head, tail)) && r == insertImpl(elem, tail)) - //require(head < elem && isSorted(Cons(head, tail)) && isSorted(r) && content(r) == content(tail) ++ Set(elem)) - // head3;tail3;r4;elem4, ((head3 < elem4) ∧ isSorted(Cons(head3, tail3)) ∧ insertSpec(elem4, tail3, r4)) ≺ ⟨ insertSpec(elem4, Cons(head3, tail3), res) ⟩ res - def insertV(head: Int, tail: List, r: List, rh: Int, rt: List, elem: Int) = { - require(head < elem && isSorted(Cons(head, tail)) && content(tail) == content(r) && isSorted(r) && r == Cons(rh, rt) && sortedLemma(head, rh, r)) - - //insertSpec(elem, Cons(head, tail), Cons(head, r)) - //rh >= head - isSorted(Cons(head, r)) - - } holds - - //require(head < elem && isSorted(Cons(head, tail)) && isSorted(r) && content(r) == content(tail) ++ Set(elem)) - // head3;tail3;r4;elem4, ((head3 < elem4) ∧ isSorted(Cons(head3, tail3)) ∧ insertSpec(elem4, tail3, r4)) ≺ ⟨ insertSpec(elem4, Cons(head3, tail3), res) ⟩ res - def insertV2(head: Int, tail: List, r: List, rh: Int, rt: List, elem: Int) = { - require(head < elem && isSorted(Cons(head, tail)) && r == insertImpl(elem, tail) && r == Cons(rh, rt)) - - //insertSpec(elem, Cons(head, tail), Cons(head, r)) - rh >= head - - } holds - - def insert2(elem : Int, list : List) : List = { - require(isSorted(list)) - list match { - case Cons(h, t) => - val r = insert2(elem, t) - if (elem > h) { - choose { (res : List) => insertSpec(elem, Cons(h,t), res) } - } else if (elem < h) { - Cons(elem, Cons(h, t)) - } else { - Cons(h, t) - } - case Nil() => - Cons(elem, Nil()) - } - } ensuring { res => insertSpec(elem, list, res) } - - def insertImpl(elem : Int, list : List) : List = { - require(isSorted(list)) - list match { - case Nil() => Cons(elem, Nil()) - case c @ Cons(x, _) if(elem <= x) => Cons(elem, c) - case Cons(x, xs) => Cons(x, insertImpl(elem, xs)) - } - } ensuring(insertSpec(elem, list, _)) - - /********************************** - * * - * M E R G I N G (slow+fast) * - * * - **********************************/ - - def mergeSpec(list1 : List, list2 : List, res : List) : Boolean = { - // isSorted(list1) && isSorted(list2) && // Part of precondition, really. - isSorted(res) && content(res) == content(list1) ++ content(list2) - } - - // The goal is that the synthesizer figures out that it should use insert. - // Currently, CEGIS with functions is too slow to handle that benchmark, - // even when insertImpl is the only function in the scope. - // (Note that I already propagated the path condition.) - // If you put mergeImpl in the scope, it solves it (how surprising). - def merge(list1 : List, list2 : List) : List = { - require(isSorted(list1) && isSorted(list2)) - choose { (res : List) => mergeSpec(list1, list2, res) } - } - - def mergeImpl(list1 : List, list2 : List) : List = { - require(isSorted(list1) && isSorted(list2)) - - list1 match { - case Nil() => list2 - case Cons(x, xs) => insertImpl(x, mergeImpl(xs, list2)) - } - } ensuring(res => mergeSpec(list1, list2, res)) - - def mergeFastImpl(list1 : List, list2 : List) : List = { - require(isSorted(list1) && isSorted(list2)) - - (list1, list2) match { - case (_, Nil()) => list1 - case (Nil(), _) => list2 - case (Cons(x, xs), Cons(y, ys)) => - if(x <= y) { - Cons(x, mergeFastImpl(xs, list2)) - } else { - Cons(y, mergeFastImpl(list1, ys)) - } - } - } ensuring(res => mergeSpec(list1, list2, res)) - - /*************************** - * * - * S P L I T T I N G * - * * - ***************************/ - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - // I think this one is really close to working. I suspect it would work - // if the generators in CEGIS had a way to read from tuples. E.g. if - // t of type (Int,Int) is in context, t._1 and t._2 should be candidates - // for integers. - // - // (Note that if you weaken splitSpec in any way, you get valid and - // useless answers). - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => splitSpec(list, res) } - } - - def splitImpl(list : List) : (List,List) = (list match { - case Nil() => (Nil(), Nil()) - case Cons(x, Nil()) => (Cons(x, Nil()), Nil()) - case Cons(x1, Cons(x2, xs)) => - val (s1,s2) = splitImpl(xs) - (Cons(x1, s1), Cons(x2, s2)) - }) ensuring(res => splitSpec(list, res)) - - /*********************** - * * - * S O R T I N G * - * * - ***********************/ - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - def insertSorted(in: List, v: Int): List = { - require(isSorted(in)); - - in match { - case Cons(h, t) => - val r = insertSorted(t, v) - if (h < v) { - Cons(h, r) - } else if (h > v) { - Cons(v, Cons(h, t)) - } else { - Cons(h, t) - } - case _ => - Cons(v, Nil()) - } - } ensuring { res => isSorted(res) && content(res) == content(in) ++ Set(v) } - - def insertSorted1(in: List, v: Int): List = { - require(isSorted(in)); - - in match { - case Cons(h, t) => - val r = insertSorted(t, v) - if (h < v) { - choose { (res: List) => isSorted(res) && content(res) == content(in) ++ Set(v) } - } else if (h > v) { - Cons(v, Cons(h, t)) - } else { - Cons(h, t) - } - case _ => - Cons(v, Nil()) - } - } ensuring { res => isSorted(res) && content(res) == content(in) ++ Set(v) } - - def insertionSortImpl(in : List) : List = (in match { - case Nil() => Nil() - case Cons(x, xs) => insertImpl(x, insertionSortImpl(xs)) - }) ensuring(res => sortSpec(in, res)) - - // Not really quicksort, neither mergesort. - def weirdSortImpl(in : List) : List = (in match { - case Nil() => Nil() - case Cons(x, Nil()) => Cons(x, Nil()) - case _ => - val (s1,s2) = splitImpl(in) - mergeFastImpl(weirdSortImpl(s1), weirdSortImpl(s2)) - }) ensuring(res => sortSpec(in, res)) - - def toLList(list : List) : LList = (list match { - case Nil() => LNil() - case Cons(x, xs) => LCons(Cons(x, Nil()), toLList(xs)) - }) ensuring(res => lContent(res) == content(list) && lIsSorted(res)) - - def mergeMap(llist : LList) : LList = { - require(lIsSorted(llist)) - - llist match { - case LNil() => LNil() - case o @ LCons(x, LNil()) => o - case LCons(x, LCons(y, ys)) => LCons(mergeFastImpl(x, y), mergeMap(ys)) - } - } ensuring(res => lContent(res) == lContent(llist) && lIsSorted(res)) - - def mergeReduce(llist : LList) : List = { - require(lIsSorted(llist)) - - llist match { - case LNil() => Nil() - case LCons(x, LNil()) => x - case _ => mergeReduce(mergeMap(llist)) - } - } ensuring(res => content(res) == lContent(llist) && isSorted(res)) - - def mergeSortImpl(in : List) : List = { - mergeReduce(toLList(in)) - } ensuring(res => sortSpec(in, res)) -} diff --git a/testcases/synthesis/cav2013/StrictlySortedList.scala b/testcases/synthesis/cav2013/StrictlySortedList.scala deleted file mode 100644 index dd6beeb36909d323d3625b9ff5867c182f735296..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/StrictlySortedList.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -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) - } -} diff --git a/testcases/synthesis/cav2013/SynAddresses.scala b/testcases/synthesis/cav2013/SynAddresses.scala deleted file mode 100644 index efb9a76a1d8ad49b11825666269b34fdf09dc7b2..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/SynAddresses.scala +++ /dev/null @@ -1,86 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - // list of integers - sealed abstract class List - case class Cons(a:Int,b:Int,c:Int, tail:List) extends List - case class Nil() extends List - - def setA(l:List) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(a,b,c,l1) => Set(a) ++ setA(l1) - } - - def allEq(l:List,k:Int) : Boolean = l match { - case Nil() => true - case Cons(a,b,c,l1) => c==k && allEq(l1,k) - } - - def containsA(x:Int,l:List) : Boolean = (l match { - case Nil() => false - case Cons(a,b,c,t) => a==x || containsA(x,t) - }) ensuring (res => res == (setA(l) contains x)) - - def containsA_syn(x:Int,l:List) : Boolean = choose((res:Boolean) => - res == (setA(l) contains x) - ) - - case class AddressBook(business : List, pers : List) - def isValidAB(ab:AddressBook) : Boolean = { - allEq(ab.business,0) && allEq(ab.pers,1) - } - def setAB(l:List) : Set[(Int,Int)] = l match { - case Nil() => Set.empty[(Int,Int)] - case Cons(a,b,c,l1) => Set((a,b)) ++ setAB(l1) - } - - def removeA(x:Int,l:List) : List = (l match { - case Nil() => Nil() - case Cons(a,b,c,l1) => - if (a==x) removeA(x,l1) - else Cons(a,b,c,removeA(x,l1)) - }) ensuring(res => !(setA(res) contains x)) - - def lookupA(x:Int,l:List) : (Int,Int,Int) = { - require(setA(l) contains x) - l match { - case Cons(a,b,c,l1) => { - if (a==x) (a,b,c) - else lookupA(x,l1) - } - } - } ensuring((res:(Int,Int,Int)) => { - val (a,b,c) = res - (a==x) && (setAB(l) contains (a,b)) - }) - - def lookupA_syn(x:Int,l:List) : (Int,Int,Int) = { - require(setA(l) contains x) - choose((res:(Int,Int,Int)) => { - val (a,b,c) = res - (x == a) && (setAB(l) contains (a,b)) - }) - } - - def makePers(ab:AddressBook, x:Int) : AddressBook = { - require(isValidAB(ab) && (setA(ab.business) contains x)) - val (a,b,c) = lookupA(x,ab.business) - val business1 = removeA(x, ab.business) - // assert(allEq(business1,0)) - val pers1 = Cons(a,b,1,ab.pers) - // assert(allEq(pers1,1)) - AddressBook(business1,pers1) - } ensuring (res => isValidAB(res) && - (setA(res.pers) contains x) && - !(setA(res.business) contains x)) - - def makePers_syn(ab:AddressBook, x:Int) : AddressBook = { - require(isValidAB(ab) && (setA(ab.business) contains x)) - choose((res:AddressBook) => isValidAB(res) && - (setA(res.pers) contains x) && - !(setA(res.business) contains x)) - } - -} diff --git a/testcases/synthesis/cav2013/SynTreeListSet.scala b/testcases/synthesis/cav2013/SynTreeListSet.scala deleted file mode 100644 index 23be38f875c4047aba8c2e4d3301706ef1c65f6d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/cav2013/SynTreeListSet.scala +++ /dev/null @@ -1,116 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - // list of integers - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def size(l:List): Int = (l match { - case Nil() => 0 - case Cons(h,t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def size_syn(l:List):Int = choose((k:Int) => - k >= 0 && - (l match { - case Nil() => k==0 - case Cons(_,Nil()) => k==1 - case Cons(_,Cons(_,Nil())) => k==2 - case Cons(_,Cons(_,Cons(_,Nil()))) => k > 2 - case _ => true - }) - ) - - // set of elements from l - def l2s(l: List): Set[Int] = l match { - case Nil() => Set() - case Cons(i, t) => Set(i) ++ l2s(t) - } - - def listFrom(k:Int) : List = { - require(0 <= k) - if (k==0) Nil() - else Cons(k, listFrom(k-1)) - } - def setFrom(k:Int) : Set[Int] = { - require(0 <= k) - if (k==0) Set.empty[Int] - else Set(k) ++ setFrom(k-1) - } - - def l2s_syn(l:List,k:Int):Set[Int] = { - require(0 <= k) - choose((res:Set[Int]) => - (l!=listFrom(k) || res==setFrom(k)) && - (l match { - case Nil() => (res==Set.empty[Int]) - case Cons(x,Nil()) => res==Set(x) - case Cons(x,Cons(y,Nil())) => res==Set(x,y) - case Cons(x1,Cons(x2,Cons(x3,Cons(x4,Nil())))) => res==Set(x1,x2,x3,x4) - case _ => true - }) - ) - } - -/* // For this, use the passes branch. - def l2s_syn(l:List):Set[Int] = { - choose((res:Set[Int]) => - passes(Map[List,Set[Int]]( - Nil() -> Set.empty[Int], - Cons(100,Nil()) -> Set(100), - Cons(200,Nil()) -> Set(200), - Cons(300,Nil()) -> Set(300), - Cons(1,Cons(2,Nil())) -> Set(1,2), - Cons(100,Cons(200,Nil())) -> Set(100,200), - Cons(1,Cons(2,Cons(3,Cons(4,Nil())))) -> Set(1,2,3,4)), - l, res)) - } -*/ - - def l2s_syn2(l:List):Set[Int] = { - choose((res:Set[Int]) => l2s(l)==res) - } - - // tree of integers - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case class Leaf() extends Tree - - // set of elements from t - def t2s(t : Tree): Set[Int] = t match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => t2s(l) ++ Set(v) ++ t2s(r) - } - - def t2s_syn(t:Tree) : Set[Int] = choose((res:Set[Int]) => - t match { - case Leaf() => res==Set.empty[Int] - case Node(Leaf(),v,Leaf()) => res==Set(v) - case Node(Node(Leaf(),v1,Leaf()),v2,Leaf()) => res==Set(v1,v2) - case Node(Leaf(),v1,Node(Leaf(),v2,Leaf())) => res==Set(v1,v2) - case _ => true - } - ) - - // list of t, in order, in from of l0 - // list of t, in order, in from of l0 - def seqWith(t:Tree,l0:List) : List = (t match { - case Leaf() => l0 - case Node(l, v, r) => seqWith(l,Cons(v,seqWith(r,l0))) - }) ensuring (res => l2s(res) == t2s(t) ++ l2s(l0)) - - def seqWith_syn(t:Tree,l0:List) : List = - choose((res:List) => - l2s(res) == t2s(t) ++ l2s(l0)) - - // list of tree t - def t2l(t:Tree) : List = ({ - seqWith(t,Nil()) - }) ensuring (res => l2s(res)==t2s(t)) - - def t2l_syn(t:Tree) : List = - choose((res:List) => l2s(res)==t2s(t)) -} diff --git a/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMakeAddressBook.scala b/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMakeAddressBook.scala deleted file mode 100644 index ec721a71fae93a50f863f0760e330453f0af7ecb..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMakeAddressBook.scala +++ /dev/null @@ -1,102 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - local: Boolean - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def isEmpty(ab: AddressBook) = size(ab) == 0 - - def content(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// !hasPrivate(res.business) && -// hasPrivate(res.pers) -// } - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } -// -// def makeAddressBook(l: List): AddressBook = -// choose { -// (res: AddressBook) => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } - - def makeAddressBook(l: List): AddressBook = choose { - (res: AddressBook) => - size(res) == size(l) && addressBookInvariant(res) - } - -} diff --git a/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMakeAddressBookWithHelpers.scala b/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMakeAddressBookWithHelpers.scala deleted file mode 100644 index 107f460cb5690181c2cd5de7a6b73c5772549346..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMakeAddressBookWithHelpers.scala +++ /dev/null @@ -1,105 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - - case class Address(a: Int, b: Int, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def content(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - def merge(l1: List, l2: List): List = l1 match { - case Nil => l2 - case Cons(a, tail) => Cons(a, merge(tail, l2)) - } - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// !hasPrivate(res.business) && -// hasPrivate(res.pers) -// } - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } -// -// def makeAddressBook(l: List): AddressBook = -// choose { -// (res: AddressBook) => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } - - def makeAddressBook(l: List): AddressBook = choose { - (res: AddressBook) => - size(res) == size(l) && - allPrivate(res.pers) && allBusiness(res.business) && - content(res) == content(l) - } - -} diff --git a/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMergeAddressBooks.scala b/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMergeAddressBooks.scala deleted file mode 100644 index 6d1a226ab66f480deb50b424305c6cdfec1ac35b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/AddressBook/AddressesMergeAddressBooks.scala +++ /dev/null @@ -1,80 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - phoneNumber: Int - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def isEmpty(ab: AddressBook) = size(ab) == 0 - - def content(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - def makeAddressBook(l: List): AddressBook = (l match { - case Nil => AddressBook(Nil, Nil) - case Cons(a, l1) => { - val res = makeAddressBook(l1) - if (a.priv) AddressBook(res.business, Cons(a, res.pers)) - else AddressBook(Cons(a, res.business), res.pers) - } - }) ensuring { - (res: AddressBook) => - size(res) == size(l) && addressBookInvariant(res) - } - - def merge(l1: List, l2: List): List = l1 match { - case Nil => l2 - case Cons(a, tail) => Cons(a, merge(tail, l2)) - } - - def mergeAddressBooks(ab1: AddressBook, ab2: AddressBook) = { - require(addressBookInvariant(ab1) && addressBookInvariant(ab2)) - choose { (res: AddressBook) => - (size(res) == size(ab1) + size(ab2)) && addressBookInvariant(res) - } - } - -} diff --git a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueue.scala b/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueue.scala deleted file mode 100644 index 3cf66229cb37d2c00e41ab63d0fbe4fb28aa4945..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueue.scala +++ /dev/null @@ -1,79 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.collection._ - -import leon.lang._ - -object BatchedQueue { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def content(p: Queue): Set[Int] = - content(p.f) ++ content(p.r) - - def isEmpty(p: Queue): Boolean = p.f == Nil - - case class Queue(f: List, r: List) - - def rev_append(aList: List, bList: List): List = (aList match { - case Nil => bList - case Cons(x, xs) => rev_append(xs, Cons(x, bList)) - }) ensuring (content(_) == content(aList) ++ content(bList)) - - def reverse(list: List) = rev_append(list, Nil) ensuring (content(_) == content(list)) - - def checkf(f: List, r: List): Queue = (f match { - case Nil => Queue(reverse(r), Nil) - case _ => Queue(f, r) - }) ensuring { - res => content(res) == content(f) ++ content(r) - } - - def head(p: Queue): Set[Int] = ( - p.f match { - case Nil => Set[Int]() - case Cons(x, xs) => Set(x) - }) ensuring ( - res => - if (isEmpty(p)) true - else content(p) == res ++ content(tail(p))) - - def tail(p: Queue): Queue = { - require(!isEmpty(p)) - p.f match { - case Nil => p - case Cons(_, xs) => checkf(xs, p.r) - } - } - // - // def last(p: Queue): Int = { - // require(!isEmpty(p)) - // p.r match { - // case Nil => reverse(p.f).asInstanceOf[Cons].head - // case Cons(x, _) => x - // } - // } - - def snoc(p: Queue, x: Int): Queue = - checkf(p.f, Cons(x, p.r)) ensuring ( - res => - content(res) == content(p) ++ Set(x) && - (if (isEmpty(p)) true - else content(tail(res)) ++ Set(x) == content(tail(res)))) - - @ignore - def main(args: Array[String]): Unit = { - val pair = Queue(Cons(4, Nil), Cons(3, Nil)) - - println(head(pair)) - println(content(pair) == head(pair) ++ content(tail(pair))) - - println(head(Queue(Nil, Nil))) - } -} diff --git a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueCheckf.scala b/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueCheckf.scala deleted file mode 100644 index 7d85a2c9bb96d5eae615f33b3557ecbb4a709e8e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueCheckf.scala +++ /dev/null @@ -1,48 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def content(p: Queue): Set[Int] = - content(p.f) ++ content(p.r) - - case class Queue(f: List, r: List) - - def rev_append(aList: List, bList: List): List = (aList match { - case Nil => bList - case Cons(x, xs) => rev_append(xs, Cons(x, bList)) - }) ensuring (content(_) == content(aList) ++ content(bList)) - - def reverse(list: List) = rev_append(list, Nil) ensuring (content(_) == content(list)) - - def invariantList(q:Queue, f: List, r: List): Boolean = { - rev_append(q.f, q.r) == rev_append(f, r) && - { if (q.f == Nil) q.r == Nil else true } - } - - def tail(p: Queue): Queue = { - p.f match { - case Nil => p - case Cons(_, xs) => checkf(xs, p.r) - } - } - -//(f match { -// case Nil => Queue(reverse(r), Nil) -// case _ => Queue(f, r) - def checkf(f: List, r: List): Queue = { - choose { - (res: Queue) => - invariantList(res, f, r) - } - } - -} diff --git a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueFull.scala b/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueFull.scala deleted file mode 100644 index c0697de3f62793ef7da4dfbe72ccaa8ad10d6bc4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueFull.scala +++ /dev/null @@ -1,100 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object BatchedQueue { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def content(p: Queue): Set[Int] = - content(p.f) ++ content(p.r) - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def size(q: Queue) : Int = - size(q.f) + size(q.r) - - def isEmpty(p: Queue): Boolean = p.f == Nil - - case class Queue(f: List, r: List) - - def rev_append(aList: List, bList: List): List = (aList match { - case Nil => bList - case Cons(x, xs) => rev_append(xs, Cons(x, bList)) - }) ensuring ( - res => - content(res) == content(aList) ++ content(bList) && - size(res) == size(aList) + size(bList) - ) - - def invariantList(q:Queue, f: List, r: List): Boolean = ({ - rev_append(q.f, q.r) == rev_append(f, r) - }) ensuring ( - res => - true - ) - - def reverse(list: List) = rev_append(list, Nil) ensuring ( - res => - content(res) == content(list) && size(res) == size(list) - ) - - def checkf(f: List, r: List): Queue = (f match { - case Nil => Queue(reverse(r), Nil) - case _ => Queue(f, r) - }) ensuring { - res => content(res) == content(f) ++ content(r) && - size(res) == size(f) + size(r) && - invariantList(res, f, r) - } - - def head(p: Queue): Set[Int] = ( - p.f match { - case Nil => Set[Int]() - case Cons(x, xs) => Set(x) - }) ensuring ( - res => - if (isEmpty(p)) true - else content(p) == res ++ content(tail(p))) - - def tail(p: Queue): Queue = { - require(!isEmpty(p)) - p.f match { - case Nil => p - case Cons(_, xs) => checkf(xs, p.r) - } - } ensuring { - (res: Queue) => content(res) ++ head(p) == content(p) && - (if (isEmpty(p)) true - else size(res) + 1 == size(p)) - } - // - // def last(p: Queue): Int = { - // require(!isEmpty(p)) - // p.r match { - // case Nil => reverse(p.f).asInstanceOf[Cons].head - // case Cons(x, _) => x - // } - // } - - def snoc(p: Queue, x: Int): Queue = - checkf(p.f, Cons(x, p.r)) ensuring ( - res => - content(res) == content(p) ++ Set(x) && - size(res) == size(p) + 1 && - ( - if (isEmpty(p)) true - else (content(tail(res)) ++ Set(x) == content(tail(res)) && - size(res.f) == size(p.f)) - ) - ) - -} diff --git a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueSnoc.scala b/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueSnoc.scala deleted file mode 100644 index c595f8253a4501bd56d7ada06a96091587003595..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueSnoc.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def content(p: Queue): Set[Int] = - content(p.f) ++ content(p.r) - - case class Queue(f: List, r: List) - - def rev_append(aList: List, bList: List): List = (aList match { - case Nil => bList - case Cons(x, xs) => rev_append(xs, Cons(x, bList)) - }) ensuring (content(_) == content(aList) ++ content(bList)) - - def reverse(list: List) = rev_append(list, Nil) ensuring (content(_) == content(list)) - - def invariantList(q:Queue, f: List, r: List): Boolean = { - rev_append(q.f, q.r) == rev_append(f, r) && - { if (q.f == Nil) q.r == Nil else true } - } - - def tail(p: Queue): Queue = { - p.f match { - case Nil => p - case Cons(_, xs) => checkf(xs, p.r) - } - } - - def checkf(f: List, r: List): Queue = (f match { - case Nil => Queue(reverse(r), Nil) - case _ => Queue(f, r) - }) ensuring { - res => content(res) == content(f) ++ content(r) - } - // - // def last(p: Queue): Int = { - // require(!isEmpty(p)) - // p.r match { - // case Nil => reverse(p.f).asInstanceOf[Cons].head - // case Cons(x, _) => x - // } - // } - - def snoc(p: Queue, x: Int): Queue = - choose { (res: Queue) => - content(res) == content(p) ++ Set(x) && - (p.f == Nil || content(tail(res)) ++ - Set(x) == content(tail(res))) - } -} diff --git a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueSnocWeird.scala b/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueSnocWeird.scala deleted file mode 100644 index 2a82511d59eec356413da146f144d8cdf8935eb2..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueSnocWeird.scala +++ /dev/null @@ -1,62 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def content(p: Queue): Set[Int] = - content(p.f) ++ content(p.r) - - def isEmpty(p: Queue): Boolean = p.f == Nil - - case class Queue(f: List, r: List) - - def rev_append(aList: List, bList: List): List = (aList match { - case Nil => bList - case Cons(x, xs) => rev_append(xs, Cons(x, bList)) - }) ensuring (content(_) == content(aList) ++ content(bList)) - - def reverse(list: List) = rev_append(list, Nil) ensuring (content(_) == content(list)) - - def queueInvariant(q:Queue) = if (q.f == Nil) q.r == Nil else true - - def invariantList(q:Queue, f: List, r: List): Boolean = { - rev_append(q.f, q.r) == rev_append(f, r) && - { if (q.f == Nil) q.r == Nil else true } - } - - def checkf(f: List, r: List): Queue = (f match { - case Nil => Queue(reverse(r), Nil) - case _ => Queue(f, r) - }) ensuring { - res => content(res) == content(f) ++ content(r) - } - // - // def last(p: Queue): Int = { - // require(!isEmpty(p)) - // p.r match { - // case Nil => reverse(p.f).asInstanceOf[Cons].head - // case Cons(x, _) => x - // } - // } - - def snoc(p: Queue, x: Int): Queue = { - require(queueInvariant(p)) - choose { (res: Queue) => - content(res) == content(p) ++ Set(x) && - {res.f match { - case Nil => content(res) ++ Set(x) == content(res) - case Cons(_, xs) => - content(checkf(xs, p.r)) ++ Set(x) == content(checkf(xs, p.r)) - }} - - } - } -} diff --git a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueTail.scala b/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueTail.scala deleted file mode 100644 index 4c7d22df90293201fde63efe09b693314805ba8c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BatchedQueue/BatchedQueueTail.scala +++ /dev/null @@ -1,55 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def content(p: Queue): Set[Int] = - content(p.f) ++ content(p.r) - - def isEmpty(p: Queue): Boolean = p.f == Nil - - case class Queue(f: List, r: List) - - def rev_append(aList: List, bList: List): List = (aList match { - case Nil => bList - case Cons(x, xs) => rev_append(xs, Cons(x, bList)) - }) ensuring (content(_) == content(aList) ++ content(bList)) - - def reverse(list: List) = rev_append(list, Nil) ensuring (content(_) == content(list)) - - def invariantList(q:Queue, f: List, r: List): Boolean = { - rev_append(q.f, q.r) == rev_append(f, r) && - { if (q.f == Nil) q.r == Nil else true } - } - - def checkf(f: List, r: List): Queue = (f match { - case Nil => Queue(reverse(r), Nil) - case _ => Queue(f, r) - }) ensuring { - res => content(res) == content(f) ++ content(r) - } - - def tail(p: Queue): Queue = { - require( if (p.f == Nil) p.r == Nil else true ) -// p.f match { -// case Nil => p -// case Cons(_, xs) => checkf(xs, p.r) -// } - choose { - (res: Queue) => - p.f match { - case Nil => isEmpty(res) - case Cons(x, xs) => content(res) ++ Set(x) == content(p) && content(res) != content(p) - } - } - } - -} diff --git a/testcases/synthesis/condabd/benchmarks/BinarySearch.scala b/testcases/synthesis/condabd/benchmarks/BinarySearch.scala deleted file mode 100644 index 40f91c988fb2771364b98ae93b795f9386d9c9b4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BinarySearch.scala +++ /dev/null @@ -1,43 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BinarySearch { - - def binarySearch(a: Array[Int], key: Int): Int = - choose{ (res: Int) => - res >= -1 && - res < a.length && - (if(res >= 0) a(res) == key else !occurs(a, 0, a.length, key)) - } - - - def occurs(a: Array[Int], from: Int, to: Int, key: Int): Boolean = { - require(a.length >= 0 && to <= a.length && from >= 0) - def rec(i: Int): Boolean = { - require(i >= 0) - if(i >= to) - false - else { - if(a(i) == key) true else rec(i+1) - } - } - if(from >= to) - false - else - rec(from) - } - - - def sorted(a: Array[Int], l: Int, u: Int) : Boolean = { - require(a.length >= 0 && l >= 0 && l <= u && u < a.length) - val t = sortedWhile(true, l, l, u, a) - t._1 - } - - def sortedWhile(isSorted: Boolean, k: Int, l: Int, u: Int, a: Array[Int]): (Boolean, Int) = { - require(a.length >= 0 && l >= 0 && l <= u && u < a.length && k >= l && k <= u) - if(k < u) { - sortedWhile(if(a(k) > a(k + 1)) false else isSorted, k + 1, l, u, a) - } else (isSorted, k) - } -} diff --git a/testcases/synthesis/condabd/benchmarks/BinarySearchTree/BinarySearchTreeFull.scala b/testcases/synthesis/condabd/benchmarks/BinarySearchTree/BinarySearchTreeFull.scala deleted file mode 100644 index bcc6d17ab28c023a63e1ea508d34bdd8ee2e2975..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BinarySearchTree/BinarySearchTreeFull.scala +++ /dev/null @@ -1,142 +0,0 @@ - -import leon.annotation._ -import leon.lang._ - -object BinarySearchTree { - sealed abstract class Tree - case class Node(left: Tree, value: Int, right: Tree) extends Tree - case class Leaf() extends Tree - - def contents(tree: Tree): Set[Int] = tree match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => contents(l) ++ Set(v) ++ contents(r) - } - - def isSortedMinMax(t: Tree, min: Int, max: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMinMax(l, min, v) && - isSortedMinMax(r, v, max) && - v < max && v > min - case _ => true - } - - def isSortedMin(t: Tree, min: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMinMax(l, min, v) && - isSortedMin(r, v) && - v > min - case _ => true - } - - def isSortedMax(t: Tree, max: Int): Boolean = t match { - case Node(l, v, r) => - isSortedMax(l, v) && - isSortedMinMax(r, v, max) && - v < max - case _ => true - } - - def isSorted(t: Tree): Boolean = t match { - case Node(l, v, r) => - isSortedMin(r, v) && - isSortedMax(l, v) - case _ => true - } - -// def isSorted(tree: Tree): Boolean = tree match { -// case Leaf() => true -// case Node(Leaf(), v, Leaf()) => true -// case Node(l @ Node(_, vIn, _), v, Leaf()) => v > vIn && isSorted(l) -// case Node(Leaf(), v, r @ Node(_, vIn, _)) => v < vIn && isSorted(r) -// case Node(l @ Node(_, vInLeft, _), v, r @ Node(_, vInRight, _)) => -// v > vInLeft && v < vInRight && isSorted(l) && isSorted(r) -// } -// -// def isSorted(tree: Tree): Boolean = tree match { -// case Leaf() => true -// case Node(l, v, r) => isLowerThan(l, v) && isGreaterThan(r, v) && isSorted(l) && isSorted(r) -// } -// -// def isLowerThan(tree: Tree, max: Int): Boolean = tree match { -// case Leaf() => true -// case Node(l, v, r) => v < max && isLowerThan(l, max) && isLowerThan(r, max) -// } -// -// def isGreaterThan(tree: Tree, min: Int): Boolean = tree match { -// case Leaf() => true -// case Node(l, v, r) => v > min && isGreaterThan(r, min) && isGreaterThan(l, min) -// } -// -// def isSorted(tree: Tree): Boolean = tree match { -// case Leaf() => true -// case Node(l, v, r) => isSorted(l) && isSorted(r) && -// contents(l).forall( v > _ ) && contents(r).forall( v < _ ) -// } - - def member(tree: Tree, value: Int): Boolean = { - require(isSorted(tree)) - tree match { - case Leaf() => false - case n @ Node(l, v, r) => if (v < value) { - member(r, value) - } else if (v > value) { - member(l, value) - } else { - true - } - } - } ensuring (res => - (res && contents(tree).contains(value)) || - (!res && !contents(tree).contains(value)) - ) - -// def insert(tree: Tree, value: Int): Node = { -// require(isSorted(tree)) -// tree match { -// case Leaf() => Node(Leaf(), value, Leaf()) -// case n @ Node(l, v, r) => if (v < value) { -// Node(l, v, insert(r, value)) -// } else if (v > value) { -// Node(insert(l, value), v, r) -// } else { -// n -// } -// } -// } ensuring (res => contents(res) == contents(tree) ++ Set(value) && isSorted(res)) - -// def treeMin(tree: Node): Int = { -// require(isSorted(tree)) -// tree match { -// case Node(left, v, _) => left match { -// case Leaf() => v -// case n @ Node(_, _, _) => treeMin(n) -// } -// } -// } -// -// def treeMax(tree: Node): Int = { -// require(isSorted(tree)) -// tree match { -// case Node(_, v, right) => right match { -// case Leaf() => v -// case n @ Node(_, _, _) => treeMax(n) -// } -// } -// } - -// def remove(tree: Tree, value: Int): Node = { -// require(isSorted(tree)) -// tree match { -// case l @ Leaf() => l -// case n @ Node(l, v, r) => if (v < value) { -// Node(l, v, insert(r, value)) -// } else if (v > value) { -// Node(insert(l, value), v, r) -// } else { -// n -// } -// } -// } ensuring (res => contents(res) == contents(tree) -- Set(value)) - -} - diff --git a/testcases/synthesis/condabd/benchmarks/BinarySearchTree/BinarySearchTreeMember.scala b/testcases/synthesis/condabd/benchmarks/BinarySearchTree/BinarySearchTreeMember.scala deleted file mode 100644 index 661e02e5c37823039bbdccc59a0379b8f477a3c1..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/BinarySearchTree/BinarySearchTreeMember.scala +++ /dev/null @@ -1,114 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinarySearchTree { - sealed abstract class Tree - case class Node(left: Tree, value: Int, right: Tree) extends Tree - case class Leaf() extends Tree - - def contents(tree: Tree): Set[Int] = tree match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => contents(l) ++ Set(v) ++ contents(r) - } -// def isSorted(tree: Tree): Boolean = tree match { -// case Leaf() => true -// case Node(Leaf(), v, Leaf()) => true -// case Node(l@Node(_, vIn, _), v, Leaf()) => v > vIn && isSorted(l) -// case Node(Leaf(), v, r@Node(_, vIn, _)) => v < vIn && isSorted(r) -// case Node(l@Node(_, vInLeft, _), v, r@Node(_, vInRight, _)) => -// v > vInLeft && v < vInRight && isSorted(l) && isSorted(r) -// } -// - - def isSorted(tree: Tree): Boolean = - isSortedMaxMin(tree, Int.MinValue, Int.MaxValue) - - def max(a: Int, b: Int) = if (a < b) b else a - - def min(a: Int, b: Int) = if (a > b) b else a - - def isSortedMaxMin(tree: Tree, minVal: Int, maxVal: Int): Boolean = tree match { - case Leaf() => true - case Node(left, v, right) => - minVal < v && v < maxVal && - // go left, update upper bound - isSortedMaxMin(left, minVal, min(maxVal, v)) && - isSortedMaxMin(right, max(minVal, v), maxVal) - } - - def member(tree: Tree, value: Int): Boolean = { - require(isSorted(tree)) - choose { - (res: Boolean) => - ( - if (res) (contents(tree) == contents(tree) ++ Set(value)) - else !(contents(tree) == contents(tree) ++ Set(value)) - ) - } - } - -// def member(tree: Tree, value: Int): Boolean = { -// require(isSorted(tree)) -// tree match { -// case Leaf() => false -// case n @ Node(l, v, r) => if (v < value) { -// member(r, value) -// } else if (v > value) { -// member(l, value) -// } else { -// true -// } -// } -// } ensuring (_ || !(contents(tree) == contents(tree) ++ Set(value))) -// -// def insert(tree: Tree, value: Int): Node = { -// require(isSorted(tree)) -// tree match { -// case Leaf() => Node(Leaf(), value, Leaf()) -// case n @ Node(l, v, r) => if (v < value) { -// Node(l, v, insert(r, value)) -// } else if (v > value) { -// Node(insert(l, value), v, r) -// } else { -// n -// } -// } -// } ensuring (res => contents(res) == contents(tree) ++ Set(value) && isSorted(res)) - - // def treeMin(tree: Node): Int = { - // require(isSorted(tree).sorted) - // tree match { - // case Node(left, v, _) => left match { - // case Leaf() => v - // case n@Node(_, _, _) => treeMin(n) - // } - // } - // } - // - // def treeMax(tree: Node): Int = { - // require(isSorted(tree).sorted) - // tree match { - // case Node(_, v, right) => right match { - // case Leaf() => v - // case n@Node(_, _, _) => treeMax(n) - // } - // } - // } - -// def remove(tree: Tree, value: Int): Node = { -// require(isSorted(tree)) -// tree match { -// case l @ Leaf() => l -// case n @ Node(l, v, r) => if (v < value) { -// Node(l, v, insert(r, value)) -// } else if (v > value) { -// Node(insert(l, value), v, r) -// } else { -// n -// } -// } -// } ensuring (contents(_) == contents(tree) -- Set(value)) - -} - diff --git a/testcases/synthesis/condabd/benchmarks/InsertionSort/InsertionSortInsert.scala b/testcases/synthesis/condabd/benchmarks/InsertionSort/InsertionSortInsert.scala deleted file mode 100644 index 7aa7fdd52f9869b9e387b9623c7bb68ba93d14c5..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/InsertionSort/InsertionSortInsert.scala +++ /dev/null @@ -1,61 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object InsertionSort { - sealed abstract class List - case class Cons(head:Int,tail:List) extends List - case class Nil() extends List - - def size(l : List) : Int = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contents(l: List): Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - 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)) - } - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def sortedIns(e: Int, l: List): List = { - require(isSorted(l)) - choose { (res : List) => - ( - contents(res) == contents(l) ++ Set(e) && - isSorted(res) && - size(res) == size(l) + 1 - ) - } -// val cond1: Boolean = /*!*/ -// l match { -// case Nil() => /*!*/ // Cons(e,Nil()) -// case Cons(x,xs) => -// val cond2: Boolean = /*!*/ -// if (x <= e) /*!*/ // Cons(x,sortedIns(e, xs)) -// else /*!*/ // Cons(e, l) -// } - } -// ensuring(res => contents(res) == contents(l) ++ Set(e) -// && isSorted(res) -// && size(res) == size(l) + 1 -// ) - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort(l: List): List = (l match { - case Nil() => Nil() - case Cons(x,xs) => sortedIns(x, sort(xs)) - }) ensuring(res => contents(res) == contents(l) - && isSorted(res) - && size(res) == size(l) - ) - -} diff --git a/testcases/synthesis/condabd/benchmarks/InsertionSort/InsertionSortSort.scala b/testcases/synthesis/condabd/benchmarks/InsertionSort/InsertionSortSort.scala deleted file mode 100644 index 21fc426cab62022b5bdc457f8765ec853d1fa5e8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/InsertionSort/InsertionSortSort.scala +++ /dev/null @@ -1,57 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object InsertionSort { - sealed abstract class List - case class Cons(head:Int,tail:List) extends List - case class Nil() extends List - - def size(l : List) : Int = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contents(l: List): Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - 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)) - } - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def sortedIns(e: Int, l: List): List = { - require(isSorted(l)) - l match { - case Nil() => Cons(e,Nil()) - case Cons(x,xs) => - if (x <= e) Cons(x,sortedIns(e, xs)) - else Cons(e, l) - } - } ensuring(res => contents(res) == contents(l) ++ Set(e) - && isSorted(res) - && size(res) == size(l) + 1 -) - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def xxsort(l: List): List = choose { - (res : List) => - contents(res) == contents(l) && - isSorted(res) && - size(res) == size(l) -// val cond: Boolean = /*!*/ -// case Nil() => /*!*/ // Nil() -// case Cons(x,xs) => /*!*/ // sortedIns(x, sort(xs)) - } -// ensuring(res => contents(res) == contents(l) -// && isSorted(res) -// && size(res) == size(l) -// ) - -} diff --git a/testcases/synthesis/condabd/benchmarks/List/ListConcat.scala b/testcases/synthesis/condabd/benchmarks/List/ListConcat.scala deleted file mode 100644 index a4c4523454ad7e7d8df85cd165de2b1b8241fc0a..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/List/ListConcat.scala +++ /dev/null @@ -1,19 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ListOperations { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def concat(l1: List, l2: List) : List = choose { - (out : List) => - content(out) == content(l1) ++ content(l2) - } - -} diff --git a/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortMerge.scala b/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortMerge.scala deleted file mode 100644 index ad20d41b24816b2237e87f35961c833ca492926f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortMerge.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object MergeSort { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class PairAbs - case class Pair(fst : List, snd : List) extends PairAbs - - def contents(l : List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def isSorted(l : List) : Boolean = l match { - case Nil() => true - case Cons(x,xs) => xs match { - case Nil() => true - case Cons(y, ys) => x <= y && isSorted(Cons(y, ys)) - } - } - - def size(list : List) : Int = list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - } - - def merge(aList : List, bList : List) : List = { - require(isSorted(aList) && isSorted(bList)) - choose( (res: List) => - contents(res) == contents(aList) ++ contents(bList) && isSorted(res) - ) - } - -// def merge(aList : List, bList : List) : List = { -// require(isSorted(aList) && isSorted(bList)) -// -// bList match { -// case Nil() => aList -// case Cons(x,xs) => -// aList match { -// case Nil() => bList -// case Cons(y,ys) => -// if (y < x) -// Cons(y,merge(ys, bList)) -// else -// Cons(x,merge(aList, xs)) -// } -// } -// } ensuring(res => contents(res) == contents(aList) ++ contents(bList) && isSorted(res)) - -} diff --git a/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortSort.scala b/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortSort.scala deleted file mode 100644 index feff019ed6b44024e001f7624a9c3c8db9791aad..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortSort.scala +++ /dev/null @@ -1,85 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object MergeSort { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class PairAbs - case class Pair(fst : List, snd : List) extends PairAbs - - def contents(l : List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def isSorted(l : List) : Boolean = l match { - case Nil() => true - case Cons(x,xs) => xs match { - case Nil() => true - case Cons(y, ys) => x <= y && isSorted(Cons(y, ys)) - } - } - - def size(list : List) : Int = list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - } - - def splithelper(aList : List, bList : List, n : Int) : Pair = { - if (n <= 0) Pair(aList,bList) - else - bList match { - case Nil() => Pair(aList,bList) - case Cons(x,xs) => splithelper(Cons(x,aList),xs,n-1) - } - } ensuring(res => contents(aList) ++ contents(bList) == contents(res.fst) ++ contents(res.snd)) - -// def split(list : List, n : Int): Pair = { -// splithelper(Nil(),list,n) -// } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def split(list: List): Pair = { - splithelper(Nil(),list,size(list)/2) - } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def merge(aList : List, bList : List) : List = { - require(isSorted(aList) && isSorted(bList)) - bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - } - } ensuring(res => contents(res) == contents(aList) ++ contents(bList) && isSorted(res)) - - def isEmpty(list: List) : Boolean = list match { - case Nil() => true - case Cons(x,xs) => false - } - - def sort(list : List) : List = choose { - - (res : List) => - contents(res) == contents(list) && isSorted(res) - -// list match { -// case Nil() => list -// case Cons(x,Nil()) => list -// case _ => -// val p = split(list,size(list)/2) -// merge(mergeSort(p.fst), mergeSort(p.snd)) - -// merge(mergeSort(split(list).fst), mergeSort(split(list).snd)) - } - - //ensuring(res => contents(res) == contents(list) && isSorted(res)) - -} diff --git a/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortSortWithVal.scala b/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortSortWithVal.scala deleted file mode 100644 index 2f59d1ca59aad23cafd1f94437dc4e18188f3597..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/MergeSort/MergeSortSortWithVal.scala +++ /dev/null @@ -1,84 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object MergeSort { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class PairAbs - case class Pair(fst : List, snd : List) extends PairAbs - - def contents(l : List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def isSorted(l : List) : Boolean = l match { - case Nil() => true - case Cons(x,xs) => xs match { - case Nil() => true - case Cons(y, ys) => x <= y && isSorted(Cons(y, ys)) - } - } - - def size(list : List) : Int = list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - } - - def splithelper(aList : List, bList : List, n : Int) : Pair = { - if (n <= 0) Pair(aList,bList) - else - bList match { - case Nil() => Pair(aList,bList) - case Cons(x,xs) => splithelper(Cons(x,aList),xs,n-1) - } - } ensuring(res => contents(aList) ++ contents(bList) == contents(res.fst) ++ contents(res.snd)) - -// def split(list : List, n : Int): Pair = { -// splithelper(Nil(),list,n) -// } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def split(list: List): Pair = { - splithelper(Nil(),list,size(list)/2) - } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def merge(aList : List, bList : List) : List = { - require(isSorted(aList) && isSorted(bList)) - bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - } - } ensuring(res => contents(res) == contents(aList) ++ contents(bList) && isSorted(res)) - - def isEmpty(list: List) : Boolean = list match { - case Nil() => true - case Cons(x,xs) => false - } - - def sort(list : List) : List = - list match { - case Nil() => list - case Cons(_,Nil()) => list - case _ => { - val p = split(list) - choose {(res : List) => - contents(res) == contents(list) && isSorted(res) - } - } - } - -// merge(mergeSort(split(list).fst), mergeSort(split(list).snd)) - - //ensuring(res => contents(res) == contents(list) && isSorted(res)) - -} diff --git a/testcases/synthesis/condabd/benchmarks/RedBlackTree/RedBlackTree.scala b/testcases/synthesis/condabd/benchmarks/RedBlackTree/RedBlackTree.scala deleted file mode 100644 index e9eb12df8170fd6173c752806f1ecb096de6fe29..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/RedBlackTree/RedBlackTree.scala +++ /dev/null @@ -1,81 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - def content(t: Tree) : Set[Int] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : Int = t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t : Tree) : Int = t match { - case Empty() => 1 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b))) - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if (x < y) balance(c, ins(x, a), y, b) - else if (x == y) Node(c,a,y,b) - else balance(c,a,y,ins(x, b)) - } - } ensuring (res => content(res) == content(t) ++ Set(x) - && size(t) <= size(res) && size(res) <= size(t) + 1 - && redDescHaveBlackChildren(res) - && blackBalanced(res)) - -} diff --git a/testcases/synthesis/condabd/benchmarks/RedBlackTree/RedBlackTreeInsert.scala b/testcases/synthesis/condabd/benchmarks/RedBlackTree/RedBlackTreeInsert.scala deleted file mode 100644 index b6336fab5794ca295c6ec4a72f4d1d0eabd3c11b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/benchmarks/RedBlackTree/RedBlackTreeInsert.scala +++ /dev/null @@ -1,78 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - def content(t: Tree): Set[Int] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree): Int = t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree): Boolean = t match { - case Empty() => true - case Node(Black(), _, _, _) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree): Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree): Boolean = t match { - case Empty() => true - case Node(_, l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t: Tree): Boolean = t match { - case Node(_, l, _, r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t: Tree): Int = t match { - case Empty() => 1 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c, a, x, b) match { - case Node(Black(), Node(Red(), Node(Red(), a, xV, b), yV, c), zV, d) => - Node(Red(), Node(Black(), a, xV, b), yV, Node(Black(), c, zV, d)) - case Node(Black(), Node(Red(), a, xV, Node(Red(), b, yV, c)), zV, d) => - Node(Red(), Node(Black(), a, xV, b), yV, Node(Black(), c, zV, d)) - case Node(Black(), a, xV, Node(Red(), Node(Red(), b, yV, c), zV, d)) => - Node(Red(), Node(Black(), a, xV, b), yV, Node(Black(), c, zV, d)) - case Node(Black(), a, xV, Node(Red(), b, yV, Node(Red(), c, zV, d))) => - Node(Red(), Node(Black(), a, xV, b), yV, Node(Black(), c, zV, d)) - case Node(c, a, xV, b) => Node(c, a, xV, b) - } - } ensuring (res => content(res) == content(Node(c, a, x, b))) - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - choose { (res: Tree) => - content(res) == content(t) ++ Set(x) && - size (t) <= size(res) && size(res) <= size(t) + 1 && - redDescHaveBlackChildren (res) && - blackBalanced (res) - } - } - -} diff --git a/testcases/synthesis/condabd/test/insynth/Addresses.scala b/testcases/synthesis/condabd/test/insynth/Addresses.scala deleted file mode 100644 index 48fa32d739b7eef780ac970068f7214c4084f425..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/insynth/Addresses.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - - case class Address(aComp: Int, bComp: Int, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def setA(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(a, l1) => Set(a) ++ setA(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def makeAddressBook(l: List): AddressBook = - choose { - (res: AddressBook) => - size(res) == size(l) && - allPrivate(res.pers) && allBusiness(res.business) - } - -} diff --git a/testcases/synthesis/condabd/test/insynth/AddressesWithAddition.scala b/testcases/synthesis/condabd/test/insynth/AddressesWithAddition.scala deleted file mode 100644 index b9371603ad362f681bd3c14f37c51d009cbe9b35..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/insynth/AddressesWithAddition.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object AddressesWithAddition { - - case class Address(aComp: Int, bComp: Int, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def setA(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(a, l1) => Set(a) ++ setA(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def makeAddressBook(l: List, x: Int, y: Boolean): AddressBook = - choose { - (res: AddressBook) => - size(res) == size(l) && - allPrivate(res.pers) && allBusiness(res.business) - } - -} diff --git a/testcases/synthesis/condabd/test/insynth/ListConcat.scala b/testcases/synthesis/condabd/test/insynth/ListConcat.scala deleted file mode 100644 index bce1c20ea7bee5ed87fec0056e86fe99c1b0acd8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/insynth/ListConcat.scala +++ /dev/null @@ -1,20 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ListOperations { - - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def concat(l1: List, l2: List) : List = choose { - (out : List) => - content(out) == content(l1) ++ content(l2) - } - -} diff --git a/testcases/synthesis/condabd/test/lesynth/Addresses.scala b/testcases/synthesis/condabd/test/lesynth/Addresses.scala deleted file mode 100644 index 84870731196e01c342a6a0e4e3c189d19ac1e788..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/Addresses.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.annotation._ -import leon.lang.synthesis._ -import leon.lang._ - -object Addresses { - - case class Address(aComp: Int, bComp: Int, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def setA(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(a, l1) => Set(a) ++ setA(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def makeAddressBook(l: List): AddressBook = - choose { - (res: AddressBook) => - size(res) == size(l) && - allPrivate(res.pers) && allBusiness(res.business) - } - -} diff --git a/testcases/synthesis/condabd/test/lesynth/AddressesMergeAddressBooks.scala b/testcases/synthesis/condabd/test/lesynth/AddressesMergeAddressBooks.scala deleted file mode 100644 index 8436ef25f5ba3569b6b181847ed142f818dd63c8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/AddressesMergeAddressBooks.scala +++ /dev/null @@ -1,81 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - phoneNumber: Int - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def isEmpty(ab: AddressBook) = size(ab) == 0 - - def content(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - def makeAddressBook(l: List): AddressBook = (l match { - case Nil => AddressBook(Nil, Nil) - case Cons(a, l1) => { - val res = makeAddressBook(l1) - if (a.priv) AddressBook(res.business, Cons(a, res.pers)) - else AddressBook(Cons(a, res.business), res.pers) - } - }) ensuring { - (res: AddressBook) => - size(res) == size(l) && addressBookInvariant(res) - } - - def merge(l1: List, l2: List): List = l1 match { - case Nil => l2 - case Cons(a, tail) => Cons(a, merge(tail, l2)) - } - - def mergeAddressBooks(ab1: AddressBook, ab2: AddressBook) = { - require(addressBookInvariant(ab1) && addressBookInvariant(ab2)) - choose { - (res: AddressBook) => - (size(res) == size(ab1) + size(ab2)) && addressBookInvariant(res) - } - } - -} diff --git a/testcases/synthesis/condabd/test/lesynth/BinarySearchTree.scala b/testcases/synthesis/condabd/test/lesynth/BinarySearchTree.scala deleted file mode 100644 index aee07c36702ae3122cd917812bdbd1359b3ea5a8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/BinarySearchTree.scala +++ /dev/null @@ -1,64 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinarySearchTree { - sealed abstract class Tree - case class Node(left: Tree, value: Int, right: Tree) extends Tree - case class Leaf() extends Tree - - def contents(tree: Tree): Set[Int] = tree match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => contents(l) ++ Set(v) ++ contents(r) - } - - def isSorted(tree: Tree): Boolean = tree match { - case Leaf() => true - case Node(Leaf(), v, Leaf()) => true - case Node(l@Node(_, vIn, _), v, Leaf()) => v > vIn && isSorted(l) - case Node(Leaf(), v, r@Node(_, vIn, _)) => v < vIn && isSorted(r) - case Node(l@Node(_, vInLeft, _), v, r@Node(_, vInRight, _)) => - v > vInLeft && v < vInRight && isSorted(l) && isSorted(r) - } - - def member(tree: Tree, value: Int): Boolean = { - require(isSorted(tree)) - choose { - (res: Boolean) => - ( - if (res) (contents(tree) == contents(tree) ++ Set(value)) - else !(contents(tree) == contents(tree) ++ Set(value)) - ) - } - } - - def goodMember(tree: Tree, value: Int): Boolean = { - require(isSorted(tree)) - tree match { - case Leaf() => false - case n @ Node(l, v, r) => if (v < value) { - member(r, value) - } else if (v > value) { - member(l, value) - } else { - true - } - } - } ensuring (_ || !(contents(tree) == contents(tree) ++ Set(value))) - - def badMember(tree: Tree, value: Int): Boolean = { - require(isSorted(tree)) - tree match { - case Leaf() => false - case n @ Node(l, v, r) => if (v <= value) { - member(r, value) - } else if (v > value) { - member(l, value) - } else { - true - } - } - } ensuring (_ || !(contents(tree) == contents(tree) ++ Set(value))) - -} - diff --git a/testcases/synthesis/condabd/test/lesynth/InsertionSortInsert.scala b/testcases/synthesis/condabd/test/lesynth/InsertionSortInsert.scala deleted file mode 100644 index 7aa7fdd52f9869b9e387b9623c7bb68ba93d14c5..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/InsertionSortInsert.scala +++ /dev/null @@ -1,61 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object InsertionSort { - sealed abstract class List - case class Cons(head:Int,tail:List) extends List - case class Nil() extends List - - def size(l : List) : Int = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contents(l: List): Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - 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)) - } - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def sortedIns(e: Int, l: List): List = { - require(isSorted(l)) - choose { (res : List) => - ( - contents(res) == contents(l) ++ Set(e) && - isSorted(res) && - size(res) == size(l) + 1 - ) - } -// val cond1: Boolean = /*!*/ -// l match { -// case Nil() => /*!*/ // Cons(e,Nil()) -// case Cons(x,xs) => -// val cond2: Boolean = /*!*/ -// if (x <= e) /*!*/ // Cons(x,sortedIns(e, xs)) -// else /*!*/ // Cons(e, l) -// } - } -// ensuring(res => contents(res) == contents(l) ++ Set(e) -// && isSorted(res) -// && size(res) == size(l) + 1 -// ) - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort(l: List): List = (l match { - case Nil() => Nil() - case Cons(x,xs) => sortedIns(x, sort(xs)) - }) ensuring(res => contents(res) == contents(l) - && isSorted(res) - && size(res) == size(l) - ) - -} diff --git a/testcases/synthesis/condabd/test/lesynth/ListConcat.scala b/testcases/synthesis/condabd/test/lesynth/ListConcat.scala deleted file mode 100644 index bce1c20ea7bee5ed87fec0056e86fe99c1b0acd8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/ListConcat.scala +++ /dev/null @@ -1,20 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ListOperations { - - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def concat(l1: List, l2: List) : List = choose { - (out : List) => - content(out) == content(l1) ++ content(l2) - } - -} diff --git a/testcases/synthesis/condabd/test/lesynth/ListConcatVerifierTest.scala b/testcases/synthesis/condabd/test/lesynth/ListConcatVerifierTest.scala deleted file mode 100644 index 51876f0d998fec48a7c1e1dca38c2a4e71c3b178..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/ListConcatVerifierTest.scala +++ /dev/null @@ -1,43 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ListOperations { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def concat(l1: List, l2: List) : List = choose { - (out : List) => - content(out) == content(l1) ++ content(l2) - } - - def goodConcat1(l1: List, l2: List) : List = - l1 match { - case Nil() => l2 - case Cons(l1Head, l1Tail) => - l1 match { - case Nil() => l2 - case _ => Cons(l1Head, Cons(l1Head, concat(l1Tail, l2))) - } - } - - def goodConcat2(l1: List, l2: List) : List = - l1 match { - case Nil() => l2 - case Cons(l1Head, l1Tail) => - Cons(l1Head, Cons(l1Head, concat(l1Tail, l2))) - } - - def badConcat1(l1: List, l2: List) : List = - l1 match { - case Nil() => l1 - case Cons(l1Head, l1Tail) => - Cons(l1Head, Cons(l1Head, concat(l1Tail, l2))) - } - -} diff --git a/testcases/synthesis/condabd/test/lesynth/ListConcatWithEmpty.scala b/testcases/synthesis/condabd/test/lesynth/ListConcatWithEmpty.scala deleted file mode 100644 index 8c6f1662f51a0631da127cc9a546b49e9b601432..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/ListConcatWithEmpty.scala +++ /dev/null @@ -1,36 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ListOperations { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def isEmpty(l: List) = l match { - case Nil() => true - case Cons(head, tail) => false - } - - def isEmptyBad(l: List) = l match { - case Nil() => true - case Cons(head, tail) => true - } - - def hasContent(l: List) = l match { - case Nil() => false - case Cons(head, tail) => true - } - -// !content(l).isEmpty - - def concat(l1: List, l2: List) : List = choose { - (out : List) => - content(out) == content(l1) ++ content(l2) - } - -} diff --git a/testcases/synthesis/condabd/test/lesynth/MergeSortSort.scala b/testcases/synthesis/condabd/test/lesynth/MergeSortSort.scala deleted file mode 100644 index feff019ed6b44024e001f7624a9c3c8db9791aad..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/MergeSortSort.scala +++ /dev/null @@ -1,85 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object MergeSort { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class PairAbs - case class Pair(fst : List, snd : List) extends PairAbs - - def contents(l : List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def isSorted(l : List) : Boolean = l match { - case Nil() => true - case Cons(x,xs) => xs match { - case Nil() => true - case Cons(y, ys) => x <= y && isSorted(Cons(y, ys)) - } - } - - def size(list : List) : Int = list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - } - - def splithelper(aList : List, bList : List, n : Int) : Pair = { - if (n <= 0) Pair(aList,bList) - else - bList match { - case Nil() => Pair(aList,bList) - case Cons(x,xs) => splithelper(Cons(x,aList),xs,n-1) - } - } ensuring(res => contents(aList) ++ contents(bList) == contents(res.fst) ++ contents(res.snd)) - -// def split(list : List, n : Int): Pair = { -// splithelper(Nil(),list,n) -// } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def split(list: List): Pair = { - splithelper(Nil(),list,size(list)/2) - } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def merge(aList : List, bList : List) : List = { - require(isSorted(aList) && isSorted(bList)) - bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - } - } ensuring(res => contents(res) == contents(aList) ++ contents(bList) && isSorted(res)) - - def isEmpty(list: List) : Boolean = list match { - case Nil() => true - case Cons(x,xs) => false - } - - def sort(list : List) : List = choose { - - (res : List) => - contents(res) == contents(list) && isSorted(res) - -// list match { -// case Nil() => list -// case Cons(x,Nil()) => list -// case _ => -// val p = split(list,size(list)/2) -// merge(mergeSort(p.fst), mergeSort(p.snd)) - -// merge(mergeSort(split(list).fst), mergeSort(split(list).snd)) - } - - //ensuring(res => contents(res) == contents(list) && isSorted(res)) - -} diff --git a/testcases/synthesis/condabd/test/lesynth/RedBlackTreeInsert.scala b/testcases/synthesis/condabd/test/lesynth/RedBlackTreeInsert.scala deleted file mode 100644 index b6336fab5794ca295c6ec4a72f4d1d0eabd3c11b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/condabd/test/lesynth/RedBlackTreeInsert.scala +++ /dev/null @@ -1,78 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - def content(t: Tree): Set[Int] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree): Int = t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree): Boolean = t match { - case Empty() => true - case Node(Black(), _, _, _) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree): Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree): Boolean = t match { - case Empty() => true - case Node(_, l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t: Tree): Boolean = t match { - case Node(_, l, _, r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t: Tree): Int = t match { - case Empty() => 1 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c, a, x, b) match { - case Node(Black(), Node(Red(), Node(Red(), a, xV, b), yV, c), zV, d) => - Node(Red(), Node(Black(), a, xV, b), yV, Node(Black(), c, zV, d)) - case Node(Black(), Node(Red(), a, xV, Node(Red(), b, yV, c)), zV, d) => - Node(Red(), Node(Black(), a, xV, b), yV, Node(Black(), c, zV, d)) - case Node(Black(), a, xV, Node(Red(), Node(Red(), b, yV, c), zV, d)) => - Node(Red(), Node(Black(), a, xV, b), yV, Node(Black(), c, zV, d)) - case Node(Black(), a, xV, Node(Red(), b, yV, Node(Red(), c, zV, d))) => - Node(Red(), Node(Black(), a, xV, b), yV, Node(Black(), c, zV, d)) - case Node(c, a, xV, b) => Node(c, a, xV, b) - } - } ensuring (res => content(res) == content(Node(c, a, x, b))) - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - choose { (res: Tree) => - content(res) == content(t) ++ Set(x) && - size (t) <= size(res) && size(res) <= size(t) + 1 && - redDescHaveBlackChildren (res) && - blackBalanced (res) - } - } - -} diff --git a/testcases/synthesis/current/AddressBook/Make.scala b/testcases/synthesis/current/AddressBook/Make.scala deleted file mode 100644 index 612effe382140cfc87bd0c12d791c4de9ddfae8e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/AddressBook/Make.scala +++ /dev/null @@ -1,66 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object AddressBookMake { - - case class Address[A](info: A, priv: Boolean) - - sealed abstract class AddressList[A] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(head, tail) => BigInt(1) + tail.size - } - } ensuring { res => res >= 0 } - - def content: Set[Address[A]] = this match { - case Nil() => Set[Address[A]]() - case Cons(addr, l1) => Set(addr) ++ l1.content - } - } - - case class Cons[A](a: Address[A], tail: AddressList[A]) extends AddressList[A] - case class Nil[A]() extends AddressList[A] - - def allPersonal[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) allPersonal(l1) - else false - } - - def allBusiness[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook[A](business: AddressList[A], personal: AddressList[A]) { - def size: BigInt = business.size + personal.size - - def content: Set[Address[A]] = business.content ++ personal.content - - def invariant = { - allPersonal(personal) && allBusiness(business) - } - } - - def makeAddressBook[A](as: AddressList[A]): AddressBook[A] = { - choose( (res: AddressBook[A]) => res.content == as.content && res.invariant ) - - /* as match { - case Nil() => AddressBook[A](Nil[A](), Nil[A]()) - case Cons(x, xs) => - val AddressBook(b, p) = makeAddressBook(xs) - if(x.priv) AddressBook(b, Cons(x, p)) - else AddressBook(Cons(x, b), p) - } - - } ensuring { - res => res.content == as.content && res.invariant */ - } - - -} diff --git a/testcases/synthesis/current/AddressBook/Merge.scala b/testcases/synthesis/current/AddressBook/Merge.scala deleted file mode 100644 index 92a5b5bfef213e35c4f2a76bbbc9f295e406d1f4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/AddressBook/Merge.scala +++ /dev/null @@ -1,69 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object AddressBookMake { - - case class Address[A](info: A, priv: Boolean) - - sealed abstract class AddressList[A] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(head, tail) => BigInt(1) + tail.size - } - } ensuring { res => res >= 0 } - - def content: Set[Address[A]] = this match { - case Nil() => Set[Address[A]]() - case Cons(addr, l1) => Set(addr) ++ l1.content - } - - def ++(that: AddressList[A]): AddressList[A] = { - this match { - case Cons(h, t) => Cons(h, t ++ that) - case Nil() => that - } - } ensuring { - res => res.content == this.content ++ that.content - } - } - - case class Cons[A](a: Address[A], tail: AddressList[A]) extends AddressList[A] - case class Nil[A]() extends AddressList[A] - - def allPersonal[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) allPersonal(l1) - else false - } - - def allBusiness[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook[A](business: AddressList[A], personal: AddressList[A]) { - def size: BigInt = business.size + personal.size - - def content: Set[Address[A]] = business.content ++ personal.content - - @inline - def invariant = { - allPersonal(personal) && allBusiness(business) - } - } - - def merge[A](a1: AddressBook[A], a2: AddressBook[A]): AddressBook[A] = { - require(a1.invariant && a2.invariant) - - choose( (res: AddressBook[A]) => - res.personal.content == (a1.personal.content ++ a2.personal.content) && - res.business.content == (a1.business.content ++ a2.business.content) && - res.invariant - ) - } -} diff --git a/testcases/synthesis/current/BatchedQueue/Dequeue.scala b/testcases/synthesis/current/BatchedQueue/Dequeue.scala deleted file mode 100644 index c44fc062847b9af2264a9b3bba05186a313ab36b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/BatchedQueue/Dequeue.scala +++ /dev/null @@ -1,80 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List[T] { - def content: Set[T] = { - this match { - case Cons(h, t) => Set(h) ++ t.content - case Nil() => Set() - } - } - - def size: BigInt = { - this match { - case Cons(h, t) => BigInt(1) + t.size - case Nil() => BigInt(0) - } - } ensuring { _ >= 0 } - - def reverse: List[T] = { - this match { - case Cons(h, t) => t.reverse.append(Cons(h, Nil[T]())) - case Nil() => Nil[T]() - } - } ensuring { res => - this.content == res.content - } - - def append(r: List[T]): List[T] = { - this match { - case Cons(h, t) => Cons(h, t.append(r)) - case Nil() => r - } - } - - def isEmpty: Boolean = { - this == Nil[T]() - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - } - - case class Cons[T](h: T, t: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - case class Queue[T](f: List[T], r: List[T]) { - def content: Set[T] = f.content ++ r.content - def size: BigInt = f.size + r.size - - def isEmpty: Boolean = f.isEmpty && r.isEmpty - - def invariant: Boolean = { - (f.isEmpty) ==> (r.isEmpty) - } - - def toList: List[T] = f.append(r.reverse) - - def dequeue: Queue[T] = { - require(invariant && !isEmpty) - - choose { (res: Queue[T]) => - res.size == size-1 && res.toList == this.toList.tail && res.invariant - } - } - } - - val test = Queue[BigInt](Cons(42, Nil()), Nil()).dequeue -} diff --git a/testcases/synthesis/current/BatchedQueue/Enqueue.scala b/testcases/synthesis/current/BatchedQueue/Enqueue.scala deleted file mode 100644 index 0f30a5ba1a95d39e78a1594f39804c8161e919a6..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/BatchedQueue/Enqueue.scala +++ /dev/null @@ -1,83 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List[T] { - def content: Set[T] = { - this match { - case Cons(h, t) => Set(h) ++ t.content - case Nil() => Set() - } - } - - def size: BigInt = { - this match { - case Cons(h, t) => BigInt(1) + t.size - case Nil() => BigInt(0) - } - } ensuring { _ >= 0 } - - def reverse: List[T] = { - this match { - case Cons(h, t) => t.reverse.append(Cons(h, Nil[T]())) - case Nil() => Nil[T]() - } - } ensuring { res => - this.content == res.content - } - - def append(r: List[T]): List[T] = { - this match { - case Cons(h, t) => Cons(h, t.append(r)) - case Nil() => r - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def last: T = { - require(this != Nil[T]()) - this match { - case Cons(h, Nil()) => h - case Cons(h, t) => t.last - } - } - } - - case class Cons[T](h: T, t: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - case class Queue[T](f: List[T], r: List[T]) { - def content: Set[T] = f.content ++ r.content - def size: BigInt = f.size + r.size - - def invariant: Boolean = { - (f == Nil[T]()) ==> (r == Nil[T]()) - } - - def toList: List[T] = f.append(r.reverse) - - def enqueue(v: T): Queue[T] = { - require(invariant) - - ???[Queue[T]] - } ensuring { (res: Queue[T]) => - res.invariant && - res.toList.last == v && - res.size == size + 1 && - res.content == this.content ++ Set(v) - } - } -} diff --git a/testcases/synthesis/current/Compiler/Desugar.scala b/testcases/synthesis/current/Compiler/Desugar.scala deleted file mode 100644 index 2684c71b2b8bbc9e5fe6cc307899ca7b92d366b4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/Compiler/Desugar.scala +++ /dev/null @@ -1,118 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon._ - -object Compiler { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Implies(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntLiteral(i: BigInt) extends Expr - - abstract class Value - case class BoolValue(b: Boolean) extends Value - case class IntValue(i: BigInt) extends Value - case object Error extends Value - - def eval(e: Expr): Value = e match { - case Plus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il+ir) - case _ => Error - } - - case Minus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il-ir) - case _ => Error - } - - case UMinus(l) => - eval(l) match { - case IntValue(b) => IntValue(-b) - case _ => Error - } - - case LessThan(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il < ir) - case _ => Error - } - - case And(l, r) => - eval(l) match { - case b @ BoolValue(false) => b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Or(l, r) => - eval(l) match { - case b @ BoolValue(true) => - b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Implies(l, r) => - eval(l) match { - case b @ BoolValue(true) => - eval(r) - case b @ BoolValue(false) => - BoolValue(true) - case _ => Error - } - - case Not(l) => - eval(l) match { - case BoolValue(b) => BoolValue(!b) - case _ => Error - } - - case Eq(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il == ir) - case (BoolValue(il), BoolValue(ir)) => BoolValue(il == ir) - case _ => Error - } - - case Ite(c, t, e) => - eval(c) match { - case BoolValue(true) => eval(t) - case BoolValue(false) => eval(t) - case _ => Error - } - - case IntLiteral(l) => IntValue(l) - case BoolLiteral(b) => BoolValue(b) - } - - def rewriteMinus(in: Minus): Expr = { - choose{ (out: Expr) => - eval(in) == eval(out) && !(out.isInstanceOf[Minus]) - } - } - - def rewriteImplies(in: Implies): Expr = { - choose{ (out: Expr) => - eval(in) == eval(out) && !(out.isInstanceOf[Implies]) - } - } - - - def plop(x: Expr) = { - eval(x) == Error//eval(Not(IntLiteral(BigInt(2)))) - }.holds -} diff --git a/testcases/synthesis/current/Compiler/DesugarImplies.scala b/testcases/synthesis/current/Compiler/DesugarImplies.scala deleted file mode 100644 index de5c544ff368043ca7847376af8cd9ae6b513f4d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/Compiler/DesugarImplies.scala +++ /dev/null @@ -1,144 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon._ - -object Compiler { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Implies(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntLiteral(i: BigInt) extends Expr - - def exists(e: Expr, f: Expr => Boolean): Boolean = { - f(e) || (e match { - case Plus(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Minus(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case LessThan(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case And(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Or(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Implies(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Eq(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Ite(c, t, e) => exists(c, f) || exists(t, f) || exists(e, f) - case Not(e) => exists(e, f) - case UMinus(e) => exists(e, f) - case _ => false - }) - } - - abstract class Value - case class BoolValue(b: Boolean) extends Value - case class IntValue(i: BigInt) extends Value - case object Error extends Value - - def eval(e: Expr): Value = e match { - case Plus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il+ir) - case _ => Error - } - - case Minus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il-ir) - case _ => Error - } - - case UMinus(l) => - eval(l) match { - case IntValue(b) => IntValue(-b) - case _ => Error - } - - case LessThan(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il < ir) - case _ => Error - } - - case And(l, r) => - eval(l) match { - case b @ BoolValue(false) => b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Or(l, r) => - eval(l) match { - case b @ BoolValue(true) => - b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Implies(l, r) => - eval(l) match { - case b @ BoolValue(true) => - eval(r) - case b @ BoolValue(false) => - BoolValue(true) - case _ => Error - } - - case Not(l) => - eval(l) match { - case BoolValue(b) => BoolValue(!b) - case _ => Error - } - - case Eq(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il == ir) - case (BoolValue(il), BoolValue(ir)) => BoolValue(il == ir) - case _ => Error - } - - case Ite(c, t, e) => - eval(c) match { - case BoolValue(true) => eval(t) - case BoolValue(false) => eval(t) - case _ => Error - } - - case IntLiteral(l) => IntValue(l) - case BoolLiteral(b) => BoolValue(b) - } - - - //def desugar(e: Expr): Expr = { - // choose{ (out: Expr) => - // eval(e) == eval(out) && !exists(out, f => f.isInstanceOf[Implies]) - // } - //} - - def desugar(e: Expr): Expr = { - e match { - case Plus(lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Minus(lhs, rhs) => Minus(desugar(lhs), desugar(rhs)) - case LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case And(lhs, rhs) => And(desugar(lhs), desugar(rhs)) - case Or(lhs, rhs) => Or(desugar(lhs), desugar(rhs)) - case Implies(lhs, rhs) => //Implies(desugar(lhs), desugar(rhs)) - Or(Not(desugar(lhs)), desugar(rhs)) - case Eq(lhs, rhs) => Eq(desugar(lhs), desugar(rhs)) - case Ite(c, t, e) => Ite(desugar(c), desugar(t), desugar(e)) - case Not(e) => Not(desugar(e)) - case UMinus(e) => UMinus(desugar(e)) - case e => e - } - } ensuring { out => - //eval(e) == eval(out) && - !exists(out, f => f.isInstanceOf[Implies]) - } -} diff --git a/testcases/synthesis/current/Compiler/RewriteImplies.scala b/testcases/synthesis/current/Compiler/RewriteImplies.scala deleted file mode 100644 index 4b50b9cbe34043f65d1a8feeaadac929822e6c70..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/Compiler/RewriteImplies.scala +++ /dev/null @@ -1,124 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon._ - -object Compiler { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Implies(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntLiteral(i: BigInt) extends Expr - - def exists(e: Expr, f: Expr => Boolean): Boolean = { - f(e) || (e match { - case Plus(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Minus(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case LessThan(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case And(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Or(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Implies(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Eq(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Ite(c, t, e) => exists(c, f) || exists(t, f) || exists(e, f) - case Not(e) => exists(e, f) - case UMinus(e) => exists(e, f) - case _ => false - }) - } - - abstract class Value - case class BoolValue(b: Boolean) extends Value - case class IntValue(i: BigInt) extends Value - case object Error extends Value - - def eval(e: Expr): Value = e match { - case Plus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il+ir) - case _ => Error - } - - case Minus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il-ir) - case _ => Error - } - - case UMinus(l) => - eval(l) match { - case IntValue(b) => IntValue(-b) - case _ => Error - } - - case LessThan(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il < ir) - case _ => Error - } - - case And(l, r) => - eval(l) match { - case b @ BoolValue(false) => b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Or(l, r) => - eval(l) match { - case b @ BoolValue(true) => - b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Implies(l, r) => - eval(l) match { - case b @ BoolValue(true) => - eval(r) - case b @ BoolValue(false) => - BoolValue(true) - case _ => Error - } - - case Not(l) => - eval(l) match { - case BoolValue(b) => BoolValue(!b) - case _ => Error - } - - case Eq(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il == ir) - case (BoolValue(il), BoolValue(ir)) => BoolValue(il == ir) - case _ => Error - } - - case Ite(c, t, e) => - eval(c) match { - case BoolValue(true) => eval(t) - case BoolValue(false) => eval(t) - case _ => Error - } - - case IntLiteral(l) => IntValue(l) - case BoolLiteral(b) => BoolValue(b) - } - - - def desugar(in: Expr): Expr = { - choose{ (out: Expr) => - eval(in) == eval(out) && !(out.isInstanceOf[Implies]) - } - } -} diff --git a/testcases/synthesis/current/Compiler/RewriteMinus.scala b/testcases/synthesis/current/Compiler/RewriteMinus.scala deleted file mode 100644 index de2fa4360de5fa899110b43c171e592be5282803..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/Compiler/RewriteMinus.scala +++ /dev/null @@ -1,107 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon._ - -object Compiler { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Implies(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntLiteral(i: BigInt) extends Expr - - abstract class Value - case class BoolValue(b: Boolean) extends Value - case class IntValue(i: BigInt) extends Value - case object Error extends Value - - def eval(e: Expr): Value = e match { - case Plus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il+ir) - case _ => Error - } - - case Minus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il-ir) - case _ => Error - } - - case UMinus(l) => - eval(l) match { - case IntValue(b) => IntValue(-b) - case _ => Error - } - - case LessThan(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il < ir) - case _ => Error - } - - case And(l, r) => - eval(l) match { - case b @ BoolValue(false) => b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Or(l, r) => - eval(l) match { - case b @ BoolValue(true) => - b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Implies(l, r) => - eval(l) match { - case b @ BoolValue(true) => - eval(r) - case b @ BoolValue(false) => - BoolValue(true) - case _ => Error - } - - case Not(l) => - eval(l) match { - case BoolValue(b) => BoolValue(!b) - case _ => Error - } - - case Eq(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il == ir) - case (BoolValue(il), BoolValue(ir)) => BoolValue(il == ir) - case _ => Error - } - - case Ite(c, t, e) => - eval(c) match { - case BoolValue(true) => eval(t) - case BoolValue(false) => eval(t) - case _ => Error - } - - case IntLiteral(l) => IntValue(l) - case BoolLiteral(b) => BoolValue(b) - } - - def rewriteMinus(in: Minus): Expr = { - choose{ (out: Expr) => - eval(in) == eval(out) && !(out.isInstanceOf[Minus]) - } - } -} diff --git a/testcases/synthesis/current/Diffs/Diffs.scala b/testcases/synthesis/current/Diffs/Diffs.scala deleted file mode 100644 index fb0e01afb2a761260be85f6e020de73d7e32172e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/Diffs/Diffs.scala +++ /dev/null @@ -1,16 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon.lang.synthesis._ - -object Diffs { - - def diffs(l: List[BigInt]): List[BigInt] = - choose((res: List[BigInt]) => - res.size == l.size && undiff(res) == l - ) - - def undiff(l: List[BigInt]) = { - l.scanLeft(BigInt(0))(_ + _).tail - } -} - diff --git a/testcases/synthesis/current/HOFs/FilterNonNeg.scala b/testcases/synthesis/current/HOFs/FilterNonNeg.scala deleted file mode 100644 index 3d17b5d1447b4678baf9b64f15cb154ef4a887a5..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/HOFs/FilterNonNeg.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object FilterNonNeg { - - abstract class List - case object Nil extends List - case class Cons(h: Int, t: List) extends List - - def filter(l: List, f: Int => Boolean): List = { - l match { - case Cons(h, t) => if (f(h)) Cons(h, filter(t, f)) else filter(t, f) - case Nil => Nil - } - } - - def test(in: List): List = { - ???[List] - } ensuring { - out => (in, out) passes { - case Cons(1, Cons(2, Cons(3, Cons(4, Nil)))) => Cons(1, Cons(2, Cons(3, Cons(4, Nil)))) - case Cons(-1, Cons(-2, Cons(3, Cons(-4, Nil)))) => Cons(3, Nil) - case Cons(1, Cons(-2, Cons(3, Cons(-4, Nil)))) => Cons(1, Cons(3, Nil)) - } - } -} diff --git a/testcases/synthesis/current/HOFs/MapPlus1.scala b/testcases/synthesis/current/HOFs/MapPlus1.scala deleted file mode 100644 index e14451893054dcc3f3a3ff0a29fa0828fe5da9bc..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/HOFs/MapPlus1.scala +++ /dev/null @@ -1,42 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - - -object MapPlus1 { - abstract class List - case object Nil extends List - case class Cons(h: BigInt, t: List) extends List - - def size(l: List): BigInt = { - l match { - case Cons(h, t) => size(t) + 1 - case Nil => BigInt(0) - } - } ensuring { res => res >= 0 } - - def sum(l: List): BigInt = { - l match { - case Cons(h, t) => h + sum(t) - case Nil => BigInt(0) - } - } - - - def map(l: List, f: BigInt => BigInt): List = { - l match { - case Nil => Nil - case Cons(h, t) => Cons(f(h), map(t, f)) - } - } ensuring { res => - size(res) == size(l) - } - - - def test(l: List): List = { - ???[List] - } ensuring { res => - (sum(res) == sum(l) + size(l)) && - (size(res) == size(l)) - } - -} diff --git a/testcases/synthesis/current/List/Delete.scala b/testcases/synthesis/current/List/Delete.scala deleted file mode 100644 index 30716c5919256f052d0a0e741a147d30c5bc82fa..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/Delete.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Delete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def delete(in: List, v: BigInt) = { - ???[List] - } ensuring { - (out : List) => - content(out) == content(in) -- Set(v) - } -} diff --git a/testcases/synthesis/current/List/Diff.scala b/testcases/synthesis/current/List/Diff.scala deleted file mode 100644 index 9fb3ade9558a7db175c6056efb9bf724f487d7ca..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/Diff.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Diff { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert(in1: List, v: BigInt): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - def delete(in1: List, v: BigInt): List = { - in1 match { - case Cons(h,t) => - if (h == v) { - delete(t, v) - } else { - Cons(h, delete(t, v)) - } - case Nil => - Nil - } - } ensuring { content(_) == content(in1) -- Set(v) } - - // def diff(in1: List, in2: List): List = { - // in2 match { - // case Nil => - // in1 - // case Cons(h, t) => - // diff(delete(in1, h), t) - // } - // } ensuring { content(_) == content(in1) -- content(in2) } - - def diff(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) -- content(in2) - } -} diff --git a/testcases/synthesis/current/List/IndexOfInt.scala b/testcases/synthesis/current/List/IndexOfInt.scala deleted file mode 100644 index 595d40cf3ca361506ab2efccc19a0fa1140d9429..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/IndexOfInt.scala +++ /dev/null @@ -1,67 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object IndexOf { - sealed abstract class List[T] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(_, t) => BigInt(1) + t.size - } - } ensuring { - res => res >= 0 - } - - def content: Set[T] = this match { - case Nil() => Set.empty[T] - case Cons(i, t) => Set(i) ++ t.content - } - - def apply(i: BigInt): T = { - require(i >= 0 && i < size) - this match { - case Cons(h, t) => - if (i == 0) { - h - } else { - t.apply(i-1) - } - } - } ensuring { e => - content contains e - } - - def indexOfInt(e: T): BigInt = { - ???[BigInt] - - //this match { - // case Cons(h, t) => - // val r = t.indexOfInt(e) - - // if (e == h) { - // BigInt(0) - // } else { - // if (r < 0) { - // r - // } else { - // r + 1 - // } - // } - // case Nil() => - // BigInt(-1) - //} - - } ensuring { res => - if (res < 0) { - !(content contains e) - } else { - res < size && apply(res) == e - } - } - } - - case class Cons[T](head: T, tail: List[T]) extends List[T] - case class Nil[T]() extends List[T] - -} diff --git a/testcases/synthesis/current/List/IndexOfOpt.scala b/testcases/synthesis/current/List/IndexOfOpt.scala deleted file mode 100644 index 6738e5c23ff8764209bd43538c1e841fd894756e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/IndexOfOpt.scala +++ /dev/null @@ -1,65 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object IndexOf { - sealed abstract class List[T] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(_, t) => BigInt(1) + t.size - } - } ensuring { - res => res >= 0 - } - - def content: Set[T] = this match { - case Nil() => Set.empty[T] - case Cons(i, t) => Set(i) ++ t.content - } - - def apply(i: BigInt): T = { - require(i >= 0 && i < size) - this match { - case Cons(h, t) => - if (i == 0) { - h - } else { - t.apply(i-1) - } - } - } ensuring { e => - content contains e - } - - def indexOfOpt(e: T): Option[BigInt] = { - ???[Option[BigInt]] - /* - this match { - case Cons(h, t) => - val r = t.indexOfOpt(e) - - if (e == h) { - Some(BigInt(0)) - } else { - r match { - case Some(i) => Some(i+1) - case None() => None[BigInt]() - } - } - case Nil() => - None[BigInt]() - } - */ - } ensuring { res => - res match { - case None() => !(content contains e) - case Some(i) => i >= 0 && i < size && apply(i) == e - } - } - } - - case class Cons[T](head: T, tail: List[T]) extends List[T] - case class Nil[T]() extends List[T] - -} diff --git a/testcases/synthesis/current/List/IndexOfOpt2.scala b/testcases/synthesis/current/List/IndexOfOpt2.scala deleted file mode 100644 index ff85f7a1c42e067b2266a948027dd22445bedca5..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/IndexOfOpt2.scala +++ /dev/null @@ -1,67 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object IndexOf { - sealed abstract class List[T] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(_, t) => BigInt(1) + t.size - } - } ensuring { - res => res >= 0 - } - - def content: Set[T] = this match { - case Nil() => Set.empty[T] - case Cons(i, t) => Set(i) ++ t.content - } - - def apply(i: BigInt): T = { - require(i >= 0 && i < size) - this match { - case Cons(h, t) => - if (i == 0) { - h - } else { - t.apply(i-1) - } - } - } ensuring { e => - content contains e - } - - def indexOfOpt(e: T, offset: BigInt): Option[BigInt] = { - ???[Option[BigInt]] - /* - this match { - case Cons(h, t) => - val r = t.indexOfOpt(e) - - if (e == h) { - Some(BigInt(0)) - } else { - r match { - case Some(i) => Some(i+1) - case None() => None[BigInt]() - } - } - case Nil() => - None[BigInt]() - } - */ - } ensuring { res => - res match { - case None() => !(content contains e) - case Some(r) => - val i = r - offset; - i >= 0 && i < size && apply(i) == e - } - } - } - - case class Cons[T](head: T, tail: List[T]) extends List[T] - case class Nil[T]() extends List[T] - -} diff --git a/testcases/synthesis/current/List/Insert.scala b/testcases/synthesis/current/List/Insert.scala deleted file mode 100644 index 48c38f4df0098410814f3ed27038c9c36c0d6532..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/Insert.scala +++ /dev/null @@ -1,28 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Insert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - //def insert(in1: List, v: BigInt): List = { - // Cons(v, in1) - //} ensuring { content(_) == content(in1) ++ Set(v) } - - def insert(in1: List, v: BigInt) = choose { - (out : List) => - content(out) == content(in1) ++ Set(v) - } -} diff --git a/testcases/synthesis/current/List/ListOfSize.scala b/testcases/synthesis/current/List/ListOfSize.scala deleted file mode 100644 index 12a95b590ee97e1153f2b7610d81ff9195109236..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/ListOfSize.scala +++ /dev/null @@ -1,24 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object ListOfSize { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def listOfSize(s: BigInt) = { - require(s >= 0) - choose((l: List) => size(l) == s) - } -} diff --git a/testcases/synthesis/current/List/Split.scala b/testcases/synthesis/current/List/Split.scala deleted file mode 100644 index f37e68264a8b5c4030fa283abc630f22ef98cd6e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/Split.scala +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : BigInt) : BigInt = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => splitSpec(list, res) } - } - -} diff --git a/testcases/synthesis/current/List/Union.scala b/testcases/synthesis/current/List/Union.scala deleted file mode 100644 index d6a5fa579f5745f00e469f19ee853da15d4fece7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/List/Union.scala +++ /dev/null @@ -1,37 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Union { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1)+ size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert(in1: List, v: BigInt): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - // def union(in1: List, in2: List): List = { - // in1 match { - // case Cons(h, t) => - // Cons(h, union(t, in2)) - // case Nil => - // in2 - // } - // } ensuring { content(_) == content(in1) ++ content(in2) } - - def union(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) ++ content(in2) - } -} diff --git a/testcases/synthesis/current/Parentheses/Par.scala b/testcases/synthesis/current/Parentheses/Par.scala deleted file mode 100644 index b91213086be4792e9535efb450bca636ca907485..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/Parentheses/Par.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.collection._ - - -object MatchPar { - abstract class AbsChar - case object OP extends AbsChar - case object CP extends AbsChar - case object NA extends AbsChar - - def matchPar(l: List[AbsChar]): BigInt = { - - ???[BigInt] - /* - l match { - case Nil() => 0 - case Cons(h, t) => - val rec = matchPar(t) - h match { - case OP => 1 + rec - case CP => if (rec <= 0) { - -1 - } else { - rec - 1 - } - case NA => rec - } - }*/ - } ensuring { res => - ((count(OP, l) != count(CP, l)) ==> (res != 0)) && - ((l, res) passes { - case Nil() => 0 - case Cons(OP, Cons(CP, Nil())) => 0 - case Cons(CP, Cons(OP, _)) => -1 - case Cons(OP, Cons(OP, Nil())) => 2 - case Cons(OP, Cons(OP, Cons(CP, Cons(CP, Cons(OP, Cons(CP, Nil())))))) => 0 - }) - } - - def count[T](a: T, l: List[T]): BigInt = { - l match { - case Cons(h, t) => - if (h == a) { - 1 + count(a, t) - } else { - count(a, t) - } - case Nil() => BigInt(0) - } - } ensuring { (res: BigInt) => - res >= 0 - } -} diff --git a/testcases/synthesis/current/RunLength/RunLength.scala b/testcases/synthesis/current/RunLength/RunLength.scala deleted file mode 100644 index 1969220be8bee9ad7fed57ff7070b1560d32ebe9..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/RunLength/RunLength.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ -import leon.collection._ - -object RunLength { - - def decode[A](l: List[(BigInt, A)]): List[A] = { - def fill[A](i: BigInt, a: A): List[A] = { - if (i > 0) a :: fill(i - 1, a) - else Nil[A]() - } - l match { - case Nil() => Nil[A]() - case Cons((i, x), xs) => - fill(i, x) ++ decode(xs) - } - } - - def legal[A](l: List[(BigInt, A)]): Boolean = l match { - case Nil() => true - case Cons((i, _), Nil()) => i > 0 - case Cons((i, x), tl@Cons((_, y), _)) => - i > 0 && x != y && legal(tl) - } - - def encode[A](l: List[A]): List[(BigInt, A)] = { - // Solution - /*l match { - case Nil() => Nil[(BigInt, A)]() - case Cons(x, xs) => - val rec = encode(xs) - rec match { - case Nil() => - Cons( (BigInt(1), x), Nil[(BigInt,A)]()) - case Cons( (recC, recEl), recTl) => - if (x == recEl) { - Cons( (1+recC, x), recTl) - } else { - Cons( (BigInt(1), x), rec ) - } - } - }*/ - ???[List[(BigInt, A)]] - } ensuring { - (res: List[(BigInt, A)]) => - legal(res) && decode(res) == l - } - -} diff --git a/testcases/synthesis/current/SortedList/Delete.scala b/testcases/synthesis/current/SortedList/Delete.scala deleted file mode 100644 index 788f232d35449cff75ac27442ce7e9cb50f42391..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/SortedList/Delete.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListDelete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in: List, v: BigInt) = { - require(isSorted(in)) - - choose( (res : List) => - (content(res) == content(in) -- Set(v)) && isSorted(res) - ) - } -} diff --git a/testcases/synthesis/current/SortedList/Diff.scala b/testcases/synthesis/current/SortedList/Diff.scala deleted file mode 100644 index d391b85ba60e2b405530ddb45b40d94071263725..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/SortedList/Diff.scala +++ /dev/null @@ -1,53 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListDiff { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - - def diff(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - - choose { - (out : List) => - (content(out) == content(in1) -- content(in2)) && isSorted(out) - } - } - -} diff --git a/testcases/synthesis/current/SortedList/Insert.scala b/testcases/synthesis/current/SortedList/Insert.scala deleted file mode 100644 index 0bf80d1e99cef290e602b0da905d6966713c77b7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/SortedList/Insert.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - - choose { (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/current/SortedList/InsertAlways.scala b/testcases/synthesis/current/SortedList/InsertAlways.scala deleted file mode 100644 index 73e0b240d776780fab6ac8091a8f0c925c56e695..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/SortedList/InsertAlways.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsertAlways { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insertAlways(in1: List, v: BigInt) = { - require(isSorted(in1)) - - choose{ (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) && size(out) == size(in1) + 1 - } - } -} diff --git a/testcases/synthesis/current/SortedList/InsertionSort.scala b/testcases/synthesis/current/SortedList/InsertionSort.scala deleted file mode 100644 index 0752ad33fe2249de829d7180e6facaab8fb6e160..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/SortedList/InsertionSort.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsertionSort { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def insertionSort(in1: List): List = { - choose { (out: List) => - content(out) == content(in1) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/current/SortedList/MergeSort.scala b/testcases/synthesis/current/SortedList/MergeSort.scala deleted file mode 100644 index 7a285c146ff249a020b6c6611fe55bf3625ecf80..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/SortedList/MergeSort.scala +++ /dev/null @@ -1,62 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListUnion { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def split(in: List): (List, List) = { - in match { - case Cons(h1, Cons(h2, t)) => - val r = split(t) - (Cons(h1, r._1), Cons(h2, r._2)) - case Cons(h1, Nil) => - (in, Nil) - case Nil => - (Nil, Nil) - } - } - - def merge(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - (in1, in2) match { - case (Cons(h1, t1), Cons(h2, t2)) => - if (h1 < h2) { - Cons(h1, merge(t1, in2)) - } else { - Cons(h2, merge(in1, t2)) - } - case (l, Nil) => l - case (Nil, l) => l - } - } ensuring { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - - def sort(in: List): List = { - ???[List] - } ensuring { - (out : List) => - content(out) == content(in) && isSorted(out) - } -} diff --git a/testcases/synthesis/current/SortedList/MergeSortGuided.scala b/testcases/synthesis/current/SortedList/MergeSortGuided.scala deleted file mode 100644 index 0035eceeadbeea82295a56d06b7ff092e7df3f35..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/SortedList/MergeSortGuided.scala +++ /dev/null @@ -1,68 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListUnion { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def split(in: List): (List, List) = { - in match { - case Cons(h1, Cons(h2, t)) => - val r = split(t) - (Cons(h1, r._1), Cons(h2, r._2)) - case Cons(h1, Nil) => - (in, Nil) - case Nil => - (Nil, Nil) - } - } - - def merge(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - (in1, in2) match { - case (Cons(h1, t1), Cons(h2, t2)) => - if (h1 < h2) { - Cons(h1, merge(t1, in2)) - } else { - Cons(h2, merge(in1, t2)) - } - case (l, Nil) => l - case (Nil, l) => l - } - } ensuring { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - - def sort(in: List): List = { - in match { - case Cons(h1, Cons(h2, t)) => - val s = split(in) - merge(sort(s._1), sort(s._2)) - case _ => - ???[List] - } - } ensuring { - (out : List) => - content(out) == content(in) && isSorted(out) - } -} diff --git a/testcases/synthesis/current/SortedList/Union.scala b/testcases/synthesis/current/SortedList/Union.scala deleted file mode 100644 index d3f11adcccc07e44d1b82c1c6aed7144cb30523c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/SortedList/Union.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListUnion { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/current/StrictSortedList/Delete.scala b/testcases/synthesis/current/StrictSortedList/Delete.scala deleted file mode 100644 index 23999d96c3577b80b00b252e0c07509f4b4b2176..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/StrictSortedList/Delete.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListDelete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in: List, v: BigInt) = { - require(isSorted(in)) - - choose( (res : List) => - (content(res) == content(in) -- Set(v)) && isSorted(res) - ) - } -} diff --git a/testcases/synthesis/current/StrictSortedList/Insert.scala b/testcases/synthesis/current/StrictSortedList/Insert.scala deleted file mode 100644 index 65f3c01f9d7b7d8d45136196a6289088df46fa22..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/StrictSortedList/Insert.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListInsert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - - choose { (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/current/StrictSortedList/Union.scala b/testcases/synthesis/current/StrictSortedList/Union.scala deleted file mode 100644 index c10ed419d3c2cc4fefc9690efb37bc723799ef1c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/StrictSortedList/Union.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListUnion { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/current/UnaryNumerals/Add.scala b/testcases/synthesis/current/UnaryNumerals/Add.scala deleted file mode 100644 index a34d1834fbb5cc2418ca830c5576e64d74169b4f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/UnaryNumerals/Add.scala +++ /dev/null @@ -1,21 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsAdd { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) + value(y) - } - } -} diff --git a/testcases/synthesis/current/UnaryNumerals/Distinct.scala b/testcases/synthesis/current/UnaryNumerals/Distinct.scala deleted file mode 100644 index 4287378d1f95225e4ff1ffae57b2d0579d72c3a5..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/UnaryNumerals/Distinct.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsDistinct { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - x match { - case S(p) => S(add(p, y)) - case Z => y - } - } ensuring { (r : Num) => - value(r) == value(x) + value(y) - } - - def distinct(x: Num, y: Num): Num = { - choose { (r : Num) => - r != x && r != y - } - } -} diff --git a/testcases/synthesis/current/UnaryNumerals/Mult.scala b/testcases/synthesis/current/UnaryNumerals/Mult.scala deleted file mode 100644 index bfa39365e8a8b35555ddc2265f40c775251b8d17..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/UnaryNumerals/Mult.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsMult { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - x match { - case S(p) => S(add(p, y)) - case Z => y - } - } ensuring { (r : Num) => - value(r) == value(x) + value(y) - } - - def mult(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) * value(y) - } - } -} diff --git a/testcases/synthesis/current/run.sh b/testcases/synthesis/current/run.sh deleted file mode 100755 index 712f903582e49fe0a5c23601be546aee30ff59ec..0000000000000000000000000000000000000000 --- a/testcases/synthesis/current/run.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -function run { - cmd="./leon --debug=report --timeout=60 --synthesis --partial=off --solvers=smt-z3 $1" - echo "Running " $cmd - echo "------------------------------------------------------------------------------------------------------------------" - $cmd; -} - -echo "==================================================================================================================" >> synthesis-report.txt -# These are all the benchmarks included in my thesis -# List -run testcases/synthesis/current/List/Insert.scala -run testcases/synthesis/current/List/Delete.scala -run testcases/synthesis/current/List/Union.scala -run testcases/synthesis/current/List/Diff.scala -run testcases/synthesis/current/List/Split.scala -run testcases/synthesis/current/List/ListOfSize.scala - -# SortedList -run testcases/synthesis/current/SortedList/Insert.scala -run testcases/synthesis/current/SortedList/InsertAlways.scala -run testcases/synthesis/current/SortedList/Delete.scala -run testcases/synthesis/current/SortedList/Union.scala -run testcases/synthesis/current/SortedList/Diff.scala -run testcases/synthesis/current/SortedList/InsertionSort.scala - -# StrictSortedList -run testcases/synthesis/current/StrictSortedList/Insert.scala -run testcases/synthesis/current/StrictSortedList/Delete.scala -run testcases/synthesis/current/StrictSortedList/Union.scala - -# UnaryNumerals -run testcases/synthesis/current/UnaryNumerals/Add.scala -run testcases/synthesis/current/UnaryNumerals/Distinct.scala -run testcases/synthesis/current/UnaryNumerals/Mult.scala - -# BatchedQueue -run testcases/synthesis/current/BatchedQueue/Enqueue.scala -run testcases/synthesis/current/BatchedQueue/Dequeue.scala - -# AddressBook -run testcases/synthesis/current/AddressBook/Make.scala -run testcases/synthesis/current/AddressBook/Merge.scala - -# RunLength -run testcases/synthesis/current/RunLength/RunLength.scala - -# Diffs -run testcases/synthesis/current/Diffs/Diffs.scala - diff --git a/testcases/synthesis/etienne-thesis/AddressBook/Make.scala b/testcases/synthesis/etienne-thesis/AddressBook/Make.scala deleted file mode 100644 index 612effe382140cfc87bd0c12d791c4de9ddfae8e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/AddressBook/Make.scala +++ /dev/null @@ -1,66 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object AddressBookMake { - - case class Address[A](info: A, priv: Boolean) - - sealed abstract class AddressList[A] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(head, tail) => BigInt(1) + tail.size - } - } ensuring { res => res >= 0 } - - def content: Set[Address[A]] = this match { - case Nil() => Set[Address[A]]() - case Cons(addr, l1) => Set(addr) ++ l1.content - } - } - - case class Cons[A](a: Address[A], tail: AddressList[A]) extends AddressList[A] - case class Nil[A]() extends AddressList[A] - - def allPersonal[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) allPersonal(l1) - else false - } - - def allBusiness[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook[A](business: AddressList[A], personal: AddressList[A]) { - def size: BigInt = business.size + personal.size - - def content: Set[Address[A]] = business.content ++ personal.content - - def invariant = { - allPersonal(personal) && allBusiness(business) - } - } - - def makeAddressBook[A](as: AddressList[A]): AddressBook[A] = { - choose( (res: AddressBook[A]) => res.content == as.content && res.invariant ) - - /* as match { - case Nil() => AddressBook[A](Nil[A](), Nil[A]()) - case Cons(x, xs) => - val AddressBook(b, p) = makeAddressBook(xs) - if(x.priv) AddressBook(b, Cons(x, p)) - else AddressBook(Cons(x, b), p) - } - - } ensuring { - res => res.content == as.content && res.invariant */ - } - - -} diff --git a/testcases/synthesis/etienne-thesis/AddressBook/Merge.scala b/testcases/synthesis/etienne-thesis/AddressBook/Merge.scala deleted file mode 100644 index 92a5b5bfef213e35c4f2a76bbbc9f295e406d1f4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/AddressBook/Merge.scala +++ /dev/null @@ -1,69 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object AddressBookMake { - - case class Address[A](info: A, priv: Boolean) - - sealed abstract class AddressList[A] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(head, tail) => BigInt(1) + tail.size - } - } ensuring { res => res >= 0 } - - def content: Set[Address[A]] = this match { - case Nil() => Set[Address[A]]() - case Cons(addr, l1) => Set(addr) ++ l1.content - } - - def ++(that: AddressList[A]): AddressList[A] = { - this match { - case Cons(h, t) => Cons(h, t ++ that) - case Nil() => that - } - } ensuring { - res => res.content == this.content ++ that.content - } - } - - case class Cons[A](a: Address[A], tail: AddressList[A]) extends AddressList[A] - case class Nil[A]() extends AddressList[A] - - def allPersonal[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) allPersonal(l1) - else false - } - - def allBusiness[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook[A](business: AddressList[A], personal: AddressList[A]) { - def size: BigInt = business.size + personal.size - - def content: Set[Address[A]] = business.content ++ personal.content - - @inline - def invariant = { - allPersonal(personal) && allBusiness(business) - } - } - - def merge[A](a1: AddressBook[A], a2: AddressBook[A]): AddressBook[A] = { - require(a1.invariant && a2.invariant) - - choose( (res: AddressBook[A]) => - res.personal.content == (a1.personal.content ++ a2.personal.content) && - res.business.content == (a1.business.content ++ a2.business.content) && - res.invariant - ) - } -} diff --git a/testcases/synthesis/etienne-thesis/BatchedQueue/Dequeue.scala b/testcases/synthesis/etienne-thesis/BatchedQueue/Dequeue.scala deleted file mode 100644 index c44fc062847b9af2264a9b3bba05186a313ab36b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/BatchedQueue/Dequeue.scala +++ /dev/null @@ -1,80 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List[T] { - def content: Set[T] = { - this match { - case Cons(h, t) => Set(h) ++ t.content - case Nil() => Set() - } - } - - def size: BigInt = { - this match { - case Cons(h, t) => BigInt(1) + t.size - case Nil() => BigInt(0) - } - } ensuring { _ >= 0 } - - def reverse: List[T] = { - this match { - case Cons(h, t) => t.reverse.append(Cons(h, Nil[T]())) - case Nil() => Nil[T]() - } - } ensuring { res => - this.content == res.content - } - - def append(r: List[T]): List[T] = { - this match { - case Cons(h, t) => Cons(h, t.append(r)) - case Nil() => r - } - } - - def isEmpty: Boolean = { - this == Nil[T]() - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - } - - case class Cons[T](h: T, t: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - case class Queue[T](f: List[T], r: List[T]) { - def content: Set[T] = f.content ++ r.content - def size: BigInt = f.size + r.size - - def isEmpty: Boolean = f.isEmpty && r.isEmpty - - def invariant: Boolean = { - (f.isEmpty) ==> (r.isEmpty) - } - - def toList: List[T] = f.append(r.reverse) - - def dequeue: Queue[T] = { - require(invariant && !isEmpty) - - choose { (res: Queue[T]) => - res.size == size-1 && res.toList == this.toList.tail && res.invariant - } - } - } - - val test = Queue[BigInt](Cons(42, Nil()), Nil()).dequeue -} diff --git a/testcases/synthesis/etienne-thesis/BatchedQueue/Enqueue.scala b/testcases/synthesis/etienne-thesis/BatchedQueue/Enqueue.scala deleted file mode 100644 index 0f30a5ba1a95d39e78a1594f39804c8161e919a6..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/BatchedQueue/Enqueue.scala +++ /dev/null @@ -1,83 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List[T] { - def content: Set[T] = { - this match { - case Cons(h, t) => Set(h) ++ t.content - case Nil() => Set() - } - } - - def size: BigInt = { - this match { - case Cons(h, t) => BigInt(1) + t.size - case Nil() => BigInt(0) - } - } ensuring { _ >= 0 } - - def reverse: List[T] = { - this match { - case Cons(h, t) => t.reverse.append(Cons(h, Nil[T]())) - case Nil() => Nil[T]() - } - } ensuring { res => - this.content == res.content - } - - def append(r: List[T]): List[T] = { - this match { - case Cons(h, t) => Cons(h, t.append(r)) - case Nil() => r - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def last: T = { - require(this != Nil[T]()) - this match { - case Cons(h, Nil()) => h - case Cons(h, t) => t.last - } - } - } - - case class Cons[T](h: T, t: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - case class Queue[T](f: List[T], r: List[T]) { - def content: Set[T] = f.content ++ r.content - def size: BigInt = f.size + r.size - - def invariant: Boolean = { - (f == Nil[T]()) ==> (r == Nil[T]()) - } - - def toList: List[T] = f.append(r.reverse) - - def enqueue(v: T): Queue[T] = { - require(invariant) - - ???[Queue[T]] - } ensuring { (res: Queue[T]) => - res.invariant && - res.toList.last == v && - res.size == size + 1 && - res.content == this.content ++ Set(v) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/Compiler/Desugar.scala b/testcases/synthesis/etienne-thesis/Compiler/Desugar.scala deleted file mode 100644 index 2684c71b2b8bbc9e5fe6cc307899ca7b92d366b4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/Compiler/Desugar.scala +++ /dev/null @@ -1,118 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon._ - -object Compiler { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Implies(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntLiteral(i: BigInt) extends Expr - - abstract class Value - case class BoolValue(b: Boolean) extends Value - case class IntValue(i: BigInt) extends Value - case object Error extends Value - - def eval(e: Expr): Value = e match { - case Plus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il+ir) - case _ => Error - } - - case Minus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il-ir) - case _ => Error - } - - case UMinus(l) => - eval(l) match { - case IntValue(b) => IntValue(-b) - case _ => Error - } - - case LessThan(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il < ir) - case _ => Error - } - - case And(l, r) => - eval(l) match { - case b @ BoolValue(false) => b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Or(l, r) => - eval(l) match { - case b @ BoolValue(true) => - b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Implies(l, r) => - eval(l) match { - case b @ BoolValue(true) => - eval(r) - case b @ BoolValue(false) => - BoolValue(true) - case _ => Error - } - - case Not(l) => - eval(l) match { - case BoolValue(b) => BoolValue(!b) - case _ => Error - } - - case Eq(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il == ir) - case (BoolValue(il), BoolValue(ir)) => BoolValue(il == ir) - case _ => Error - } - - case Ite(c, t, e) => - eval(c) match { - case BoolValue(true) => eval(t) - case BoolValue(false) => eval(t) - case _ => Error - } - - case IntLiteral(l) => IntValue(l) - case BoolLiteral(b) => BoolValue(b) - } - - def rewriteMinus(in: Minus): Expr = { - choose{ (out: Expr) => - eval(in) == eval(out) && !(out.isInstanceOf[Minus]) - } - } - - def rewriteImplies(in: Implies): Expr = { - choose{ (out: Expr) => - eval(in) == eval(out) && !(out.isInstanceOf[Implies]) - } - } - - - def plop(x: Expr) = { - eval(x) == Error//eval(Not(IntLiteral(BigInt(2)))) - }.holds -} diff --git a/testcases/synthesis/etienne-thesis/Compiler/DesugarImplies.scala b/testcases/synthesis/etienne-thesis/Compiler/DesugarImplies.scala deleted file mode 100644 index de5c544ff368043ca7847376af8cd9ae6b513f4d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/Compiler/DesugarImplies.scala +++ /dev/null @@ -1,144 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon._ - -object Compiler { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Implies(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntLiteral(i: BigInt) extends Expr - - def exists(e: Expr, f: Expr => Boolean): Boolean = { - f(e) || (e match { - case Plus(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Minus(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case LessThan(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case And(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Or(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Implies(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Eq(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Ite(c, t, e) => exists(c, f) || exists(t, f) || exists(e, f) - case Not(e) => exists(e, f) - case UMinus(e) => exists(e, f) - case _ => false - }) - } - - abstract class Value - case class BoolValue(b: Boolean) extends Value - case class IntValue(i: BigInt) extends Value - case object Error extends Value - - def eval(e: Expr): Value = e match { - case Plus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il+ir) - case _ => Error - } - - case Minus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il-ir) - case _ => Error - } - - case UMinus(l) => - eval(l) match { - case IntValue(b) => IntValue(-b) - case _ => Error - } - - case LessThan(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il < ir) - case _ => Error - } - - case And(l, r) => - eval(l) match { - case b @ BoolValue(false) => b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Or(l, r) => - eval(l) match { - case b @ BoolValue(true) => - b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Implies(l, r) => - eval(l) match { - case b @ BoolValue(true) => - eval(r) - case b @ BoolValue(false) => - BoolValue(true) - case _ => Error - } - - case Not(l) => - eval(l) match { - case BoolValue(b) => BoolValue(!b) - case _ => Error - } - - case Eq(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il == ir) - case (BoolValue(il), BoolValue(ir)) => BoolValue(il == ir) - case _ => Error - } - - case Ite(c, t, e) => - eval(c) match { - case BoolValue(true) => eval(t) - case BoolValue(false) => eval(t) - case _ => Error - } - - case IntLiteral(l) => IntValue(l) - case BoolLiteral(b) => BoolValue(b) - } - - - //def desugar(e: Expr): Expr = { - // choose{ (out: Expr) => - // eval(e) == eval(out) && !exists(out, f => f.isInstanceOf[Implies]) - // } - //} - - def desugar(e: Expr): Expr = { - e match { - case Plus(lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Minus(lhs, rhs) => Minus(desugar(lhs), desugar(rhs)) - case LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case And(lhs, rhs) => And(desugar(lhs), desugar(rhs)) - case Or(lhs, rhs) => Or(desugar(lhs), desugar(rhs)) - case Implies(lhs, rhs) => //Implies(desugar(lhs), desugar(rhs)) - Or(Not(desugar(lhs)), desugar(rhs)) - case Eq(lhs, rhs) => Eq(desugar(lhs), desugar(rhs)) - case Ite(c, t, e) => Ite(desugar(c), desugar(t), desugar(e)) - case Not(e) => Not(desugar(e)) - case UMinus(e) => UMinus(desugar(e)) - case e => e - } - } ensuring { out => - //eval(e) == eval(out) && - !exists(out, f => f.isInstanceOf[Implies]) - } -} diff --git a/testcases/synthesis/etienne-thesis/Compiler/RewriteImplies.scala b/testcases/synthesis/etienne-thesis/Compiler/RewriteImplies.scala deleted file mode 100644 index 4b50b9cbe34043f65d1a8feeaadac929822e6c70..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/Compiler/RewriteImplies.scala +++ /dev/null @@ -1,124 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon._ - -object Compiler { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Implies(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntLiteral(i: BigInt) extends Expr - - def exists(e: Expr, f: Expr => Boolean): Boolean = { - f(e) || (e match { - case Plus(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Minus(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case LessThan(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case And(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Or(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Implies(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Eq(lhs, rhs) => exists(lhs, f) || exists(rhs, f) - case Ite(c, t, e) => exists(c, f) || exists(t, f) || exists(e, f) - case Not(e) => exists(e, f) - case UMinus(e) => exists(e, f) - case _ => false - }) - } - - abstract class Value - case class BoolValue(b: Boolean) extends Value - case class IntValue(i: BigInt) extends Value - case object Error extends Value - - def eval(e: Expr): Value = e match { - case Plus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il+ir) - case _ => Error - } - - case Minus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il-ir) - case _ => Error - } - - case UMinus(l) => - eval(l) match { - case IntValue(b) => IntValue(-b) - case _ => Error - } - - case LessThan(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il < ir) - case _ => Error - } - - case And(l, r) => - eval(l) match { - case b @ BoolValue(false) => b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Or(l, r) => - eval(l) match { - case b @ BoolValue(true) => - b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Implies(l, r) => - eval(l) match { - case b @ BoolValue(true) => - eval(r) - case b @ BoolValue(false) => - BoolValue(true) - case _ => Error - } - - case Not(l) => - eval(l) match { - case BoolValue(b) => BoolValue(!b) - case _ => Error - } - - case Eq(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il == ir) - case (BoolValue(il), BoolValue(ir)) => BoolValue(il == ir) - case _ => Error - } - - case Ite(c, t, e) => - eval(c) match { - case BoolValue(true) => eval(t) - case BoolValue(false) => eval(t) - case _ => Error - } - - case IntLiteral(l) => IntValue(l) - case BoolLiteral(b) => BoolValue(b) - } - - - def desugar(in: Expr): Expr = { - choose{ (out: Expr) => - eval(in) == eval(out) && !(out.isInstanceOf[Implies]) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/Compiler/RewriteMinus.scala b/testcases/synthesis/etienne-thesis/Compiler/RewriteMinus.scala deleted file mode 100644 index de2fa4360de5fa899110b43c171e592be5282803..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/Compiler/RewriteMinus.scala +++ /dev/null @@ -1,107 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon._ - -object Compiler { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Implies(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntLiteral(i: BigInt) extends Expr - - abstract class Value - case class BoolValue(b: Boolean) extends Value - case class IntValue(i: BigInt) extends Value - case object Error extends Value - - def eval(e: Expr): Value = e match { - case Plus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il+ir) - case _ => Error - } - - case Minus(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => IntValue(il-ir) - case _ => Error - } - - case UMinus(l) => - eval(l) match { - case IntValue(b) => IntValue(-b) - case _ => Error - } - - case LessThan(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il < ir) - case _ => Error - } - - case And(l, r) => - eval(l) match { - case b @ BoolValue(false) => b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Or(l, r) => - eval(l) match { - case b @ BoolValue(true) => - b - case b: BoolValue => - eval(r) - case _ => - Error - } - - case Implies(l, r) => - eval(l) match { - case b @ BoolValue(true) => - eval(r) - case b @ BoolValue(false) => - BoolValue(true) - case _ => Error - } - - case Not(l) => - eval(l) match { - case BoolValue(b) => BoolValue(!b) - case _ => Error - } - - case Eq(l, r) => - (eval(l), eval(r)) match { - case (IntValue(il), IntValue(ir)) => BoolValue(il == ir) - case (BoolValue(il), BoolValue(ir)) => BoolValue(il == ir) - case _ => Error - } - - case Ite(c, t, e) => - eval(c) match { - case BoolValue(true) => eval(t) - case BoolValue(false) => eval(t) - case _ => Error - } - - case IntLiteral(l) => IntValue(l) - case BoolLiteral(b) => BoolValue(b) - } - - def rewriteMinus(in: Minus): Expr = { - choose{ (out: Expr) => - eval(in) == eval(out) && !(out.isInstanceOf[Minus]) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/List/Delete.scala b/testcases/synthesis/etienne-thesis/List/Delete.scala deleted file mode 100644 index 30716c5919256f052d0a0e741a147d30c5bc82fa..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/List/Delete.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Delete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def delete(in: List, v: BigInt) = { - ???[List] - } ensuring { - (out : List) => - content(out) == content(in) -- Set(v) - } -} diff --git a/testcases/synthesis/etienne-thesis/List/Diff.scala b/testcases/synthesis/etienne-thesis/List/Diff.scala deleted file mode 100644 index 9fb3ade9558a7db175c6056efb9bf724f487d7ca..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/List/Diff.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Diff { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert(in1: List, v: BigInt): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - def delete(in1: List, v: BigInt): List = { - in1 match { - case Cons(h,t) => - if (h == v) { - delete(t, v) - } else { - Cons(h, delete(t, v)) - } - case Nil => - Nil - } - } ensuring { content(_) == content(in1) -- Set(v) } - - // def diff(in1: List, in2: List): List = { - // in2 match { - // case Nil => - // in1 - // case Cons(h, t) => - // diff(delete(in1, h), t) - // } - // } ensuring { content(_) == content(in1) -- content(in2) } - - def diff(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) -- content(in2) - } -} diff --git a/testcases/synthesis/etienne-thesis/List/Insert.scala b/testcases/synthesis/etienne-thesis/List/Insert.scala deleted file mode 100644 index 48c38f4df0098410814f3ed27038c9c36c0d6532..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/List/Insert.scala +++ /dev/null @@ -1,28 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Insert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - //def insert(in1: List, v: BigInt): List = { - // Cons(v, in1) - //} ensuring { content(_) == content(in1) ++ Set(v) } - - def insert(in1: List, v: BigInt) = choose { - (out : List) => - content(out) == content(in1) ++ Set(v) - } -} diff --git a/testcases/synthesis/etienne-thesis/List/Split.scala b/testcases/synthesis/etienne-thesis/List/Split.scala deleted file mode 100644 index f37e68264a8b5c4030fa283abc630f22ef98cd6e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/List/Split.scala +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : BigInt) : BigInt = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => splitSpec(list, res) } - } - -} diff --git a/testcases/synthesis/etienne-thesis/List/Union.scala b/testcases/synthesis/etienne-thesis/List/Union.scala deleted file mode 100644 index d6a5fa579f5745f00e469f19ee853da15d4fece7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/List/Union.scala +++ /dev/null @@ -1,37 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Union { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1)+ size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert(in1: List, v: BigInt): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - // def union(in1: List, in2: List): List = { - // in1 match { - // case Cons(h, t) => - // Cons(h, union(t, in2)) - // case Nil => - // in2 - // } - // } ensuring { content(_) == content(in1) ++ content(in2) } - - def union(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) ++ content(in2) - } -} diff --git a/testcases/synthesis/etienne-thesis/SortedList/Delete.scala b/testcases/synthesis/etienne-thesis/SortedList/Delete.scala deleted file mode 100644 index 788f232d35449cff75ac27442ce7e9cb50f42391..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/SortedList/Delete.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListDelete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in: List, v: BigInt) = { - require(isSorted(in)) - - choose( (res : List) => - (content(res) == content(in) -- Set(v)) && isSorted(res) - ) - } -} diff --git a/testcases/synthesis/etienne-thesis/SortedList/Diff.scala b/testcases/synthesis/etienne-thesis/SortedList/Diff.scala deleted file mode 100644 index d391b85ba60e2b405530ddb45b40d94071263725..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/SortedList/Diff.scala +++ /dev/null @@ -1,53 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListDiff { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - - def diff(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - - choose { - (out : List) => - (content(out) == content(in1) -- content(in2)) && isSorted(out) - } - } - -} diff --git a/testcases/synthesis/etienne-thesis/SortedList/Insert.scala b/testcases/synthesis/etienne-thesis/SortedList/Insert.scala deleted file mode 100644 index 0bf80d1e99cef290e602b0da905d6966713c77b7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/SortedList/Insert.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - - choose { (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/SortedList/InsertAlways.scala b/testcases/synthesis/etienne-thesis/SortedList/InsertAlways.scala deleted file mode 100644 index 73e0b240d776780fab6ac8091a8f0c925c56e695..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/SortedList/InsertAlways.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsertAlways { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insertAlways(in1: List, v: BigInt) = { - require(isSorted(in1)) - - choose{ (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) && size(out) == size(in1) + 1 - } - } -} diff --git a/testcases/synthesis/etienne-thesis/SortedList/InsertionSort.scala b/testcases/synthesis/etienne-thesis/SortedList/InsertionSort.scala deleted file mode 100644 index 0752ad33fe2249de829d7180e6facaab8fb6e160..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/SortedList/InsertionSort.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsertionSort { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def insertionSort(in1: List): List = { - choose { (out: List) => - content(out) == content(in1) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/SortedList/Union.scala b/testcases/synthesis/etienne-thesis/SortedList/Union.scala deleted file mode 100644 index d3f11adcccc07e44d1b82c1c6aed7144cb30523c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/SortedList/Union.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListUnion { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/StrictSortedList/Delete.scala b/testcases/synthesis/etienne-thesis/StrictSortedList/Delete.scala deleted file mode 100644 index 23999d96c3577b80b00b252e0c07509f4b4b2176..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/StrictSortedList/Delete.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListDelete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in: List, v: BigInt) = { - require(isSorted(in)) - - choose( (res : List) => - (content(res) == content(in) -- Set(v)) && isSorted(res) - ) - } -} diff --git a/testcases/synthesis/etienne-thesis/StrictSortedList/Insert.scala b/testcases/synthesis/etienne-thesis/StrictSortedList/Insert.scala deleted file mode 100644 index 65f3c01f9d7b7d8d45136196a6289088df46fa22..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/StrictSortedList/Insert.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListInsert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - - choose { (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/StrictSortedList/Union.scala b/testcases/synthesis/etienne-thesis/StrictSortedList/Union.scala deleted file mode 100644 index c10ed419d3c2cc4fefc9690efb37bc723799ef1c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/StrictSortedList/Union.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListUnion { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/UnaryNumerals/Add.scala b/testcases/synthesis/etienne-thesis/UnaryNumerals/Add.scala deleted file mode 100644 index a34d1834fbb5cc2418ca830c5576e64d74169b4f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/UnaryNumerals/Add.scala +++ /dev/null @@ -1,21 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsAdd { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) + value(y) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/UnaryNumerals/Distinct.scala b/testcases/synthesis/etienne-thesis/UnaryNumerals/Distinct.scala deleted file mode 100644 index 4287378d1f95225e4ff1ffae57b2d0579d72c3a5..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/UnaryNumerals/Distinct.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsDistinct { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - x match { - case S(p) => S(add(p, y)) - case Z => y - } - } ensuring { (r : Num) => - value(r) == value(x) + value(y) - } - - def distinct(x: Num, y: Num): Num = { - choose { (r : Num) => - r != x && r != y - } - } -} diff --git a/testcases/synthesis/etienne-thesis/UnaryNumerals/Mult.scala b/testcases/synthesis/etienne-thesis/UnaryNumerals/Mult.scala deleted file mode 100644 index bfa39365e8a8b35555ddc2265f40c775251b8d17..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/UnaryNumerals/Mult.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsMult { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - x match { - case S(p) => S(add(p, y)) - case Z => y - } - } ensuring { (r : Num) => - value(r) == value(x) + value(y) - } - - def mult(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) * value(y) - } - } -} diff --git a/testcases/synthesis/etienne-thesis/run.sh b/testcases/synthesis/etienne-thesis/run.sh deleted file mode 100755 index 3ab2ba70e48a305bc4a2ab84b644be69ff474b3d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/etienne-thesis/run.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -function run { - cmd="./leon --debug=report --timeout=30 --synthesis --cegis:maxsize=7 $1" - echo "Running " $cmd - echo "------------------------------------------------------------------------------------------------------------------" - $cmd; -} - -echo "==================================================================================================================" >> synthesis-report.txt -# These are all the benchmarks included in my thesis -# List -run testcases/synthesis/etienne-thesis/List/Insert.scala -run testcases/synthesis/etienne-thesis/List/Delete.scala -run testcases/synthesis/etienne-thesis/List/Union.scala -run testcases/synthesis/etienne-thesis/List/Diff.scala -run testcases/synthesis/etienne-thesis/List/Split.scala - -# SortedList -run testcases/synthesis/etienne-thesis/SortedList/Insert.scala -run testcases/synthesis/etienne-thesis/SortedList/InsertAlways.scala -run testcases/synthesis/etienne-thesis/SortedList/Delete.scala -run testcases/synthesis/etienne-thesis/SortedList/Union.scala -run testcases/synthesis/etienne-thesis/SortedList/Diff.scala -run testcases/synthesis/etienne-thesis/SortedList/InsertionSort.scala - -# StrictSortedList -run testcases/synthesis/etienne-thesis/StrictSortedList/Insert.scala -run testcases/synthesis/etienne-thesis/StrictSortedList/Delete.scala -run testcases/synthesis/etienne-thesis/StrictSortedList/Union.scala - -# UnaryNumerals -run testcases/synthesis/etienne-thesis/UnaryNumerals/Add.scala -run testcases/synthesis/etienne-thesis/UnaryNumerals/Distinct.scala -run testcases/synthesis/etienne-thesis/UnaryNumerals/Mult.scala - -# BatchedQueue -run testcases/synthesis/etienne-thesis/BatchedQueue/Enqueue.scala -run testcases/synthesis/etienne-thesis/BatchedQueue/Dequeue.scala - -# AddressBook -run testcases/synthesis/etienne-thesis/AddressBook/Make.scala -run testcases/synthesis/etienne-thesis/AddressBook/Merge.scala diff --git a/testcases/synthesis/future/Simplifier.scala b/testcases/synthesis/future/Simplifier.scala deleted file mode 100644 index 669c91c3b1b7069de3594710f32244ea23526d42..0000000000000000000000000000000000000000 --- a/testcases/synthesis/future/Simplifier.scala +++ /dev/null @@ -1,301 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - //case class Times(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Neg(ex : Expr) extends Expr - //case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class Let(id : Int, e : Expr, body : Expr) extends Expr - case class Var(id : Int) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - -object Environments { - val empty = Map.empty[Int,(Trees.Expr,Types.Type)] -} - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr)(implicit env : Map[Int, (Expr,Type)]) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - /*case Times(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - }*/ - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Neg(ex) => typeOf(ex) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - //case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - // case (Some(t1), Some(t2)) if t1 == t2 => Some(t1) - // case _ => None() - //} - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - case Let(i,e,body) => typeOf(e) match { - case None() => None() - case Some(tp) => typeOf(body)(env updated (i, (e,tp))) - } - case Var(id) => if (env contains id) Some(env(id)._2) else None() - } - - def typeChecks(e : Expr)= typeOf(e)(Environments.empty).isDefined -/* - def closed(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Boolean = { - require(typeChecks(t)) - t match { - case Var(id) => env contains id - case Let(id, e, body) => closed(e) && closed(body)(env updated (id, (e,typeOf(e).get))) - case Plus(l,r) => closed(l) && closed(r) - case Minus(l,r) => closed(l) && closed(r) - case LessThan(l,r) => closed(l) && closed(r) - case And(l,r) => closed(l) && closed(r) - case Or(l,r) => closed(l) && closed(r) - case Neg(ex) => closed(ex) - case Ite(c, th, el) => closed(c) && closed(th) && closed(el) - case IntLiteral(_) => true - case BoolLiteral(_) => true - } - }*/ - -// def closed(t : Expr) : Boolean = closed(t)(Map[Int,Expr]()) -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Int = { - require( typeOf(t).isDefined && typeOf(t).get == IntType ) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - //case Times(lhs, rhs) => semI(lhs) * semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - case Let(id, e, bd) => - typeOf(e) match { - case Some(IntType) => semI(bd)(env updated (id, (IntLiteral(semI(e)), IntType))) - case Some(BoolType) => semI(bd)(env updated (id, (BoolLiteral(semB(e)), BoolType))) - } - case Var(id) => semI(env(id)._1) - } - } - - def semB(t : Expr)(implicit env :Map[Int,(Expr,Type)]) : Boolean = { - require( typeOf(t).isDefined && typeOf(t).get == BoolType ) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Neg(ex) => !semB(ex) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Let(id, e, bd) => - typeOf(e) match { - case Some(IntType) => semB(bd)(env updated (id, (IntLiteral(semI(e)), IntType))) - case Some(BoolType) => semB(bd)(env updated (id, (BoolLiteral(semB(e)), BoolType))) - } - case Var(id) => semB(env(id)._1) - //case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - // case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - // case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - // } - case BoolLiteral(b) => b - } - } -} - -object Simplifier { - import Types._ - import Trees._ - import TypeChecker._ - import Semantics._ - - def simplify(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - - case Var(id) => env(id)._1 // Think about this - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t) == semB(res) - case Some(IntType) => semI(t) == semI(res) - }) - } - - /* - def simplify(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - - case Var(id) => env(id)._1 // Think about this - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t) == semB(res) - case Some(IntType) => semI(t) == semI(res) - }) - }*/ - - - def simplify2(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - case Plus(lhs, Minus(r1, r2)) if lhs == r2 => r1 - case Plus(Minus(l1, l2), rhs) if rhs == l2 => l1 - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - case Minus(Plus(l1,l2), r) if l1 == r => l2 - case Minus(Plus(l1,l2), r) if l2 == r => l1 - case Minus(lhs, rhs) if lhs == rhs => IntLiteral(0) - - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - case LessThan(lhs, rhs) if lhs == rhs => BoolLiteral(false) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - case And(Neg(rhs), Neg(lhs)) => Neg(Or(lhs,rhs)) - case And(lhs, rhs) if lhs == rhs => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - case Or(Neg(rhs), Neg(lhs)) => Neg(And(lhs,rhs)) - case Or(lhs, rhs) if lhs == rhs => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - case Neg(Neg(ex)) => ex - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - case Ite(_, thenn, elze) if thenn == elze => thenn - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t) == semB(res) - case Some(IntType) => semI(t) == semI(res) - }) - } - -} diff --git a/testcases/synthesis/future/Simplifier1.scala b/testcases/synthesis/future/Simplifier1.scala deleted file mode 100644 index b40745c6c867a115cf6389ce8ba5bc65895387da..0000000000000000000000000000000000000000 --- a/testcases/synthesis/future/Simplifier1.scala +++ /dev/null @@ -1,211 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - //case class Times(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Neg(ex : Expr) extends Expr - //case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class IntVar(i : Int) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - /*case Times(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - }*/ - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Neg(ex) => typeOf(ex) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - //case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - // case (Some(t1), Some(t2)) if t1 == t2 => Some(t1) - // case _ => None() - //} - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - case IntVar(_) => Some(IntType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr, env : Map[Int,Int]) : Int = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs, env) + semI(rhs, env) - case Minus(lhs , rhs) => semI(lhs, env) - semI(rhs, env) - //case Times(lhs, rhs) => semI(lhs) * semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond, env)) semI(thn, env) else semI(els, env) - case IntLiteral(v) => v - case IntVar(id) => env(id) - } - } - - def semB(t : Expr, env : Map[Int,Int]) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs, env) && semB(rhs, env) - case Or(lhs , rhs ) => semB(lhs, env) || semB(rhs, env) - case Neg(ex) => !semB(ex, env) - case LessThan(lhs, rhs) => semI(lhs, env) < semI(rhs, env) - case Ite(cond, thn, els) => - if (semB(cond, env)) semB(thn, env) else semB(els, env) - //case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - // case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - // case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - // } - case BoolLiteral(b) => b - } - } - - def simplify(t : Expr, env : Map[Int,Int]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - - case IntVar(id) if env contains id => IntLiteral(env(id)) - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t, env) == semB(res, env) - case Some(IntType) => semI(t, env) == semI(res, env) - }) - } - - def simplify2(t : Expr, env : Map[Int,Int]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - case Plus(lhs, Minus(r1, r2)) if lhs == r2 => r1 - case Plus(Minus(l1, l2), rhs) if rhs == l2 => l1 - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - case Minus(Plus(l1,l2), r) if l1 == r => l2 - case Minus(Plus(l1,l2), r) if l2 == r => l1 - case Minus(lhs, rhs) if lhs == rhs => IntLiteral(0) - - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - case LessThan(lhs, rhs) if lhs == rhs => BoolLiteral(false) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - case And(Neg(rhs), Neg(lhs)) => Neg(Or(lhs,rhs)) - case And(lhs, rhs) if lhs == rhs => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - case Or(Neg(rhs), Neg(lhs)) => Neg(And(lhs,rhs)) - case Or(lhs, rhs) if lhs == rhs => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - case Neg(Neg(ex)) => ex - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - case Ite(_, thenn, elze) if thenn == elze => thenn - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t, env) == semB(res, env) - case Some(IntType) => semI(t, env) == semI(res, env) - }) - } - -} diff --git a/testcases/synthesis/future/Simplifier2.scala b/testcases/synthesis/future/Simplifier2.scala deleted file mode 100644 index 86d66c9d952d34666a80767fbae8b578b71f424a..0000000000000000000000000000000000000000 --- a/testcases/synthesis/future/Simplifier2.scala +++ /dev/null @@ -1,297 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - //case class Times(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Neg(ex : Expr) extends Expr - //case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class Let(id : Int, e : Expr, body : Expr) extends Expr - case class Var(id : Int) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - -object Environments { - val empty = Map.empty[Int,Trees.Expr] -} - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr)(implicit env : Map[Int,Expr]) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - /*case Times(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - }*/ - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Neg(ex) => typeOf(ex) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - //case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - // case (Some(t1), Some(t2)) if t1 == t2 => Some(t1) - // case _ => None() - //} - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - case Let(i,e,body) => typeOf(e) match { - case None() => None() - case Some(tp) => typeOf(body)(env updated (i, e)) - } - case Var(id) => if (env contains id) typeOf(env(id)) else None() - } - - def typeChecks(e : Expr)= typeOf(e)(Environments.empty).isDefined -/* - def closed(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Boolean = { - require(typeChecks(t)) - t match { - case Var(id) => env contains id - case Let(id, e, body) => closed(e) && closed(body)(env updated (id, (e,typeOf(e).get))) - case Plus(l,r) => closed(l) && closed(r) - case Minus(l,r) => closed(l) && closed(r) - case LessThan(l,r) => closed(l) && closed(r) - case And(l,r) => closed(l) && closed(r) - case Or(l,r) => closed(l) && closed(r) - case Neg(ex) => closed(ex) - case Ite(c, th, el) => closed(c) && closed(th) && closed(el) - case IntLiteral(_) => true - case BoolLiteral(_) => true - } - }*/ - -// def closed(t : Expr) : Boolean = closed(t)(Map[Int,Expr]()) -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - - def semI(t : Expr)(implicit env : Map[Int,Expr]) : Int = { - require( typeOf(t).isDefined && typeOf(t).get == IntType ) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - //case Times(lhs, rhs) => semI(lhs) * semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - case Let(id, e, bd) => semI(bd)( env updated (id, e)) - case Var(id) => semI(env(id)) - } - } - - def semB(t : Expr)(implicit env :Map[Int,Expr]) : Boolean = { - require( typeOf(t).isDefined && typeOf(t).get == BoolType ) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Neg(ex) => !semB(ex) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Let(id, e, bd) => semB(bd)( env updated (id, e)) - case Var(id) => semB(env(id)) - //case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - // case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - // case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - // } - case BoolLiteral(b) => b - } - } -} - -object Simplifier { - import Types._ - import Trees._ - import TypeChecker._ - import Semantics._ - - implicit val env = Environments.empty - - @induct - def simplify(t : Expr) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - - //case Var(id) => env(id) // Think about this - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res).get match { - case BoolType => semB(t) == semB(res) - case IntType => semI(t) == semI(res) - }) - } - - /* - def simplify(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - - case Var(id) => env(id)._1 // Think about this - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t) == semB(res) - case Some(IntType) => semI(t) == semI(res) - }) - }*/ - - @induct - def simplify2(t : Expr)(implicit env : Map[Int,Expr]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - case Plus(lhs, Minus(r1, r2)) if lhs == r2 => r1 - case Plus(Minus(l1, l2), rhs) if rhs == l2 => l1 - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - case Minus(Plus(l1,l2), r) if l1 == r => l2 - case Minus(Plus(l1,l2), r) if l2 == r => l1 - case Minus(lhs, rhs) if lhs == rhs => IntLiteral(0) - - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - case LessThan(lhs, rhs) if lhs == rhs => BoolLiteral(false) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - case And(Neg(rhs), Neg(lhs)) => Neg(Or(lhs,rhs)) - case And(lhs, rhs) if lhs == rhs => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - case Or(Neg(rhs), Neg(lhs)) => Neg(And(lhs,rhs)) - case Or(lhs, rhs) if lhs == rhs => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - case Neg(Neg(ex)) => ex - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - case Ite(_, thenn, elze) if thenn == elze => thenn - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res).get match { - case BoolType => semB(t) == semB(res) - case IntType => semI(t) == semI(res) - }) - } - -} diff --git a/testcases/synthesis/future/Simplifier3.scala b/testcases/synthesis/future/Simplifier3.scala deleted file mode 100644 index 01662622bd059cc5d3359cb136d26c708118f7e7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/future/Simplifier3.scala +++ /dev/null @@ -1,322 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - //case class Times(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Neg(ex : Expr) extends Expr - //case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: Int) extends Expr - case class BoolLiteral(b : Boolean) extends Expr - case class Let(id : Int, e : Expr, body : Expr) extends Expr - case class Var(id : Int) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - -object Environments { - val empty = Map.empty[Int,Trees.Expr] -} - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr)(implicit env : Map[Int,Expr]) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - /*case Times(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - }*/ - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Neg(ex) => typeOf(ex) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - //case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - // case (Some(t1), Some(t2)) if t1 == t2 => Some(t1) - // case _ => None() - //} - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - case Let(i,e,body) => typeOf(e) match { - case None() => None() - case Some(tp) => typeOf(body)(env updated (i, e)) - } - case Var(id) => if (env contains id) typeOf(env(id)) else None() - } - - def typeChecks(e : Expr)= typeOf(e)(Environments.empty).isDefined -/* - def closed(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Boolean = { - require(typeChecks(t)) - t match { - case Var(id) => env contains id - case Let(id, e, body) => closed(e) && closed(body)(env updated (id, (e,typeOf(e).get))) - case Plus(l,r) => closed(l) && closed(r) - case Minus(l,r) => closed(l) && closed(r) - case LessThan(l,r) => closed(l) && closed(r) - case And(l,r) => closed(l) && closed(r) - case Or(l,r) => closed(l) && closed(r) - case Neg(ex) => closed(ex) - case Ite(c, th, el) => closed(c) && closed(th) && closed(el) - case IntLiteral(_) => true - case BoolLiteral(_) => true - } - }*/ - -// def closed(t : Expr) : Boolean = closed(t)(Map[Int,Expr]()) -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def isGround(t : Expr): Boolean = t match { - case Plus(l,r) => isGround(l) && isGround(r) - case Minus(l,r) => isGround(l) && isGround(r) - case LessThan(l,r)=> isGround(l) && isGround(r) - case And(l,r) => isGround(l) && isGround(r) - case Or(l,r) => isGround(l) && isGround(r) - case Neg(ex) => isGround(ex) - case Ite(c, th, el) => isGround(c) && isGround(th) && isGround(el) - case IntLiteral(_) => true - case BoolLiteral(_) => true - case _ => false - } - - - - def subst(t : Expr)(implicit env : Map[Int, Expr]) : Expr = { - require(typeOf(t).isDefined) - t match { - case Plus(l,r) => Plus(subst(l), subst(r)) - case Minus(l,r) => Minus(subst(l), subst(r)) - case LessThan(l,r) => LessThan( subst(l), subst(r)) - case And(l,r) => And(subst(l), subst(r)) - case Or(l,r) => Or( subst(l), subst(r)) - case Neg(ex) => Neg(subst(ex)) - case Ite(c, th, el) => Ite(subst(c), subst(th), subst(el)) - case Let(i,e,body) => subst(body)(env updated (i,subst(e))) - case Var(id_) => env(id_) - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && isGround(res) - } - - def semI(t : Expr) : Int = { - require( typeChecks(t) && typeOf(t)(Environments.empty).get == IntType && isGround(t)) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - //case Times(lhs, rhs) => semI(lhs) * semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( typeChecks(t) && typeOf(t)(Environments.empty).get == BoolType && isGround(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Neg(ex) => !semB(ex) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - //case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - // case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - // case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - // } - case BoolLiteral(b) => b - } - } -} -/* -object Simplifier { - import Types._ - import Trees._ - import TypeChecker._ - import Semantics._ - - def simplify(t : Expr)(implicit env : Map[Int,Expr]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - - //case Var(id) => env(id) // Think about this - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t) == semB(res) - case Some(IntType) => semI(t) == semI(res) - }) - } - - /* - def simplify(t : Expr)(implicit env : Map[Int,(Expr,Type)]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - - case Var(id) => env(id)._1 // Think about this - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t) == semB(res) - case Some(IntType) => semI(t) == semI(res) - }) - }*/ - - - def simplify2(t : Expr)(implicit env : Map[Int,Expr]) : Expr = { - require(typeChecks(t)) - t match { - case Plus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1+i2) - case Plus(IntLiteral(0), rhs) => rhs - case Plus(lhs, IntLiteral(0)) => lhs - case Plus(lhs, Minus(r1, r2)) if lhs == r2 => r1 - case Plus(Minus(l1, l2), rhs) if rhs == l2 => l1 - - case Minus(IntLiteral(i1), IntLiteral(i2)) => IntLiteral(i1-i2) - case Minus(lhs, IntLiteral(0)) => lhs - case Minus(Plus(l1,l2), r) if l1 == r => l2 - case Minus(Plus(l1,l2), r) if l2 == r => l1 - case Minus(lhs, rhs) if lhs == rhs => IntLiteral(0) - - - case LessThan(IntLiteral(i1), IntLiteral(i2)) => BoolLiteral(i1 < i2) - case LessThan(lhs, rhs) if lhs == rhs => BoolLiteral(false) - - case And(BoolLiteral(false), _ ) => BoolLiteral(false) - case And(_, BoolLiteral(false)) => BoolLiteral(false) - case And(BoolLiteral(true), rhs) => rhs - case And(lhs, BoolLiteral(true)) => lhs - case And(Neg(rhs), Neg(lhs)) => Neg(Or(lhs,rhs)) - case And(lhs, rhs) if lhs == rhs => lhs - - case Or(BoolLiteral(true), _ ) => BoolLiteral(true) - case Or(_, BoolLiteral(true)) => BoolLiteral(true) - case Or(BoolLiteral(false), rhs) => rhs - case Or(lhs, BoolLiteral(false)) => lhs - case Or(Neg(rhs), Neg(lhs)) => Neg(And(lhs,rhs)) - case Or(lhs, rhs) if lhs == rhs => lhs - - case Neg(BoolLiteral(b)) => BoolLiteral(!b) - case Neg(Neg(ex)) => ex - - //case Eq(i1, i2) if i1 == i2 => BoolLiteral(true) - //case Eq(BoolLiteral(true), BoolLiteral(false)) => BoolLiteral(false) - //case Eq(BoolLiteral(false), BoolLiteral(true)) => BoolLiteral(false) - //case Eq(IntLiteral(i1), IntLiteral(i2)) if i1 != i2 => BoolLiteral(false) - - case Ite(BoolLiteral(true), thenn, _ ) => thenn - case Ite(BoolLiteral(false), _, elze ) => elze - case Ite(_, thenn, elze) if thenn == elze => thenn - - case other => other - } - } ensuring { res => - typeOf(res) == typeOf(t) && (typeOf(res) match { - case Some(BoolType) => semB(t) == semB(res) - case Some(IntType) => semI(t) == semI(res) - }) - } -} -*/ diff --git a/testcases/synthesis/future/SortedList.scala b/testcases/synthesis/future/SortedList.scala deleted file mode 100644 index f02adaba2a97895a4f514ebdcbaf70e4b4db9580..0000000000000000000000000000000000000000 --- a/testcases/synthesis/future/SortedList.scala +++ /dev/null @@ -1,46 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedList { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - // proved with unrolling=0 - def size(l: List) : BigInt = (l match { - case Nil() => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= BigInt(0)) - - //def sizeSynth(l: List): BigInt = choose{ (i: BigInt) => i >= 0 && sizeSynth(Cons(0, l)) == i + 1} -/* - def content(l: List): Set[BigInt] = l match { - case Nil() => Set() - case Cons(i, t) => Set(i) ++ content(t) - } - - def groundSynth() = Cons(0, Cons(1, Cons(2, Cons(3, Cons(4, Nil()))))) ensuring { - (out: List) => size(out) == 5 - } - - def insertSynth(in: List, v: BigInt) = Cons(v, in) ensuring { - (out: List) => content(out) == content(in) ++ Set(v) - } - - def tailSynth(in: List) = { - require(in != Nil()) - in match { - case Cons(_, tl) => tl - } - } ensuring { - out: List => size(out)+1 == size(in) - } -*/ - def listOfSizeSynth(i: BigInt) = { - require(i >= 0) - choose { out: List => size(out) == i } - } - - -} diff --git a/testcases/synthesis/io-examples/List.scala b/testcases/synthesis/io-examples/List.scala deleted file mode 100644 index 0e2d2b0fddb909e6a06ac666b6371d7e518991d9..0000000000000000000000000000000000000000 --- a/testcases/synthesis/io-examples/List.scala +++ /dev/null @@ -1,19 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.collection._ - -object Foo { - - def listOp1(l: List[Int], i: Int) = { - //Cons(i, (l-i)) - //Cons[Int](i, l).slice(0, i) - ???[List[Int]] - } ensuring { (res: List[Int]) => - ((l, i), res) passes { - case (Nil(), 2) => Cons(2, Nil[Int]()) - case (Cons(1, Nil()), 2) => Cons(2, Cons(1, Nil())) - case (Cons(1, Cons(2, Cons(3, Nil()))), 3) => Cons(3, Cons(1, Cons(2, Nil()))) - } - } - -} diff --git a/testcases/synthesis/io-examples/Lists.scala b/testcases/synthesis/io-examples/Lists.scala deleted file mode 100644 index 7d3d068e0bfb279feee9fdfcbc0674eba84bd5a4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/io-examples/Lists.scala +++ /dev/null @@ -1,22 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon.lang.synthesis._ - -object Lists { - - def safetail(l: List[Int]): List[Int] = choose { (res : List[Int]) => - (l, res) passes { - case Cons(1, Cons(2, Cons(3, Cons(4, Nil())))) => Cons(2, Cons(3, Cons(4, Nil()))) - case Cons(2, Cons(3, Cons(4, Nil()))) => Cons(3, Cons(4, Nil())) - case Nil() => Nil() - } - } - - def uniq(l: List[Int]): List[Int] = choose { (res : List[Int]) => - (l, res) passes { - case Cons(1, Cons(1, Cons(1, Cons(2, Nil())))) => Cons(1, Cons(2, Nil())) - case Cons(3, Cons(3, Cons(4, Nil()))) => Cons(3, Cons(4, Nil())) - case Nil() => Nil() - } - } -} diff --git a/testcases/synthesis/io-examples/Math.scala b/testcases/synthesis/io-examples/Math.scala deleted file mode 100644 index 2e50289d6ba4cc31c695eaac16ad1863410e3dcf..0000000000000000000000000000000000000000 --- a/testcases/synthesis/io-examples/Math.scala +++ /dev/null @@ -1,27 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object Math { - - def fib(a: Int): Int = { - require(a >= 0) - if (a > 1) { - fib(a-1) + fib(a-2) - } else { - ???[Int] - } - } ensuring { res => - (a, res) passes { - case 0 => 0 - case 1 => 1 - case 2 => 1 - case 3 => 2 - case 4 => 3 - case 5 => 5 - case 18 => 2584 - } - } - - - -} diff --git a/testcases/synthesis/lesynth-results/RedBlackTreeSynthResult.scala b/testcases/synthesis/lesynth-results/RedBlackTreeSynthResult.scala deleted file mode 100644 index 511eb602e5987d2282cbcd3e754050dd71dfbef7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/lesynth-results/RedBlackTreeSynthResult.scala +++ /dev/null @@ -1,95 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - def content(t: Tree) : Set[Int] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : Int = t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t : Tree) : Int = t match { - case Empty() => 1 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b))) - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) -// t match { -// case Empty() => Node(Red(),Empty(),x,Empty()) -// case Node(c,a,y,b) => -// if (x < y) balance(c, ins(x, a), y, b) -// else if (x == y) Node(c,a,y,b) -// else balance(c,a,y,ins(x, b)) -// } - if ((redNodesHaveBlackChildren(t) && blackBalanced(t))) { - (t match { - case Empty() => - Node(Red(), Empty(), x, Empty()) - case n: Node => - if ((n.value == x)) { - balance(Black(), n.right, x, n.left) - } else { - balance(n.color, n.left, x, ins(n.value, n.right)) - } - }) - } else { - leon.lang.error[Tree]("Precondition failed") - } - } ensuring (res => content(res) == content(t) ++ Set(x) - && size(t) <= size(res) && size(res) <= size(t) + 1 - && redDescHaveBlackChildren(res) - && blackBalanced(res)) - -} diff --git a/testcases/synthesis/lesynth-results/RedBlackTreeSynthResultBad.scala b/testcases/synthesis/lesynth-results/RedBlackTreeSynthResultBad.scala deleted file mode 100644 index 5bee9ba90a119c6778067dff279c45022f5797e1..0000000000000000000000000000000000000000 --- a/testcases/synthesis/lesynth-results/RedBlackTreeSynthResultBad.scala +++ /dev/null @@ -1,95 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - def content(t: Tree) : Set[Int] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : Int = t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t : Tree) : Int = t match { - case Empty() => 1 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b))) - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) -// t match { -// case Empty() => Node(Red(),Empty(),x,Empty()) -// case Node(c,a,y,b) => -// if (x < y) balance(c, ins(x, a), y, b) -// else if (x == y) Node(c,a,y,b) -// else balance(c,a,y,ins(x, b)) -// } - if ((redNodesHaveBlackChildren(t) && blackBalanced(t))) { - (t match { - case Empty() => - Node(Red(), Empty(), x, Empty()) - case n: Node => - if ((n.value == x)) { - Node(n.color, n.left, x, n.right) - } else { - balance(n.color, n.right, n.value, ins(x, n.left)) - } - }) - } else { - leon.lang.error[Tree]("Precondition failed") - } - } ensuring (res => content(res) == content(t) ++ Set(x) - && size(t) <= size(res) && size(res) <= size(t) + 1 - && redDescHaveBlackChildren(res) - && blackBalanced(res)) - -} diff --git a/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBook.scala b/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBook.scala deleted file mode 100644 index 3d97a6e04f1b71dd075ac63be64f9284e2b2069c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBook.scala +++ /dev/null @@ -1,102 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - local: Boolean - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def sizeA(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def isEmpty(ab: AddressBook) = sizeA(ab) == 0 - - def content(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// !hasPrivate(res.business) && -// hasPrivate(res.pers) -// } - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } -// -// def makeAddressBook(l: List): AddressBook = -// choose { -// (res: AddressBook) => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } - - def makeAddressBook(l: List): AddressBook = choose { - (res: AddressBook) => - sizeA(res) == size(l) && addressBookInvariant(res) - } - -} diff --git a/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookStrong.scala b/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookStrong.scala deleted file mode 100644 index 9167ab27829b721c7788c3173b8aef5d115a4bf2..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookStrong.scala +++ /dev/null @@ -1,128 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - local: Boolean - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def sizeA(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - -// def isEmpty(ab: AddressBook) = sizeA(ab) == 0 - - def contentA(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// !hasPrivate(res.business) && -// hasPrivate(res.pers) -// } - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } -// -// def makeAddressBook(l: List): AddressBook = -// choose { -// (res: AddressBook) => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } - -/* - // MANUAL SOLUTION: - def makeAB(l:List) : AddressBook = { - l match { - case Nil => AddressBook(Nil,Nil) - case Cons(a,t) => { - val ab1 = makeAB(t) - if (a.priv) AddressBook(ab1.business, Cons(a,ab1.pers)) - else AddressBook(Cons(a,ab1.business), ab1.pers) - } - } - } ensuring((res: AddressBook) => - sizeA(res) == size(l) && - addressBookInvariant(res) && - contentA(res) == content(l)) - -*/ - -/* // Perhaps this can be useful? - def cond(b:Boolean, ab1: AddressBook, ab2: AddressBook) : AddressBook = { - if (b) ab1 else ab2 - } -*/ - - def makeAddressBook(l: List): AddressBook = choose { - (res: AddressBook) => - sizeA(res) == size(l) && - addressBookInvariant(res) && - contentA(res) == content(l) - } - -} diff --git a/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookSynthWrong.scala b/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookSynthWrong.scala deleted file mode 100644 index 8b2d19384b523c460b74866e5bc93bfdc9c91de3..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookSynthWrong.scala +++ /dev/null @@ -1,114 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - local: Boolean - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def sizeA(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def isEmpty(ab: AddressBook) = sizeA(ab) == 0 - - def content(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// !hasPrivate(res.business) && -// hasPrivate(res.pers) -// } - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } -// -// def makeAddressBook(l: List): AddressBook = -// choose { -// (res: AddressBook) => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } - - def makeAddressBook(l: List): AddressBook = { - l match { - case Nil => AddressBook(Nil,l) - case Cons(h,t) => - if (allPrivate(t)) - AddressBook(Nil, Cons(Address(h.info, allPrivate(t)), t)) - else - AddressBook( - Cons( Address(h.info, isEmpty(makeAddressBook(t))), makeAddressBook(t).business), - makeAddressBook(t).pers - ) - } - } ensuring ((res: AddressBook) => - sizeA(res) == size(l) && addressBookInvariant(res) - ) - -} - diff --git a/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookWithHelpers.scala b/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookWithHelpers.scala deleted file mode 100644 index 88798b9869dbbc01075816fbaf0469d1cd96f9d7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/AddressBook/AddressesMakeAddressBookWithHelpers.scala +++ /dev/null @@ -1,106 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - - case class Address(a: Int, b: Int, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def contentA(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - def merge(l1: List, l2: List): List = l1 match { - case Nil => l2 - case Cons(a, tail) => Cons(a, merge(tail, l2)) - } - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// !hasPrivate(res.business) && -// hasPrivate(res.pers) -// } - -// def makeAddressBook(l: List): AddressBook = (l match { -// case Nil => AddressBook(Nil, Nil) -// case Cons(a, l1) => { -// val res = makeAddressBook(l1) -// if (a.priv) AddressBook(res.business, Cons(a, res.pers)) -// else AddressBook(Cons(a, res.business), res.pers) -// } -// }) ensuring { -// res => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } -// -// def makeAddressBook(l: List): AddressBook = -// choose { -// (res: AddressBook) => -// size(res) == size(l) && -// (if (size(res.business) > 0) { -// !hasPrivate(res.business) -// } else true ) && -// (if (size(res.pers) > 0) { -// hasPrivate(res.pers) -// } else true ) -// } - - def makeAddressBook(l: List): AddressBook = choose { - (res: AddressBook) => - size(res) == size(l) && - allPrivate(res.pers) && - allBusiness(res.business) && - contentA(res) == content(l) - } - -} diff --git a/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooks.scala b/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooks.scala deleted file mode 100644 index 51836accdf8634c32cf11756d179a76a03a108da..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooks.scala +++ /dev/null @@ -1,77 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - phoneNumber: Int - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def sizeA(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def addToPers(ab: AddressBook, adr: Address) = ({ - require(addressBookInvariant(ab)) - AddressBook(ab.business, Cons(adr, ab.pers)) - }) ensuring(res => addressBookInvariant(res)) - - def addToBusiness(ab: AddressBook, adr: Address) = ({ - require(addressBookInvariant(ab)) - AddressBook(Cons(adr, ab.business), ab.pers) - }) ensuring(res => addressBookInvariant(res)) - - def isEmpty(ab: AddressBook) = sizeA(ab) == 0 - - def contentA(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - def merge(l1: List, l2: List): List = (l1 match { - case Nil => l2 - case Cons(a, tail) => Cons(a, merge(tail, l2)) - }) ensuring(res => size(res)==size(l1) + size(l2) && - (!allPrivate(l1) || !allPrivate(l2) || allPrivate(res)) && - (!allBusiness(l1) || !allBusiness(l2) || !allBusiness(res)) - ) - - def mergeAddressBooks(ab1: AddressBook, ab2: AddressBook) = { - require(addressBookInvariant(ab1) && addressBookInvariant(ab2)) - choose { (res: AddressBook) => - (sizeA(res) == sizeA(ab1) + sizeA(ab2)) && addressBookInvariant(res) - } - } - -} diff --git a/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooksStep1.scala b/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooksStep1.scala deleted file mode 100644 index de80592e981023621e65bfd3e56c279ec28b9cf8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooksStep1.scala +++ /dev/null @@ -1,73 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - phoneNumber: Int - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def isEmpty(ab: AddressBook) = size(ab) == 0 - - def content(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - def makeAddressBook(l: List): AddressBook = (l match { - case Nil => AddressBook(Nil, Nil) - case Cons(a, l1) => { - val res = makeAddressBook(l1) - if (a.priv) AddressBook(res.business, Cons(a, res.pers)) - else AddressBook(Cons(a, res.business), res.pers) - } - }) ensuring { - (res: AddressBook) => - size(res) == size(l) && addressBookInvariant(res) - } - - def merge(l1: List, l2: List): List = { - choose((res:List) => size(res) == size(l1) + size(l2) && - (!allBusiness(l1) || !allBusiness(l2) ||allBusiness(res)) && - (!allPrivate(l1) || !allPrivate(l2) ||allPrivate(res))) - } -} diff --git a/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooksStep2.scala b/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooksStep2.scala deleted file mode 100644 index 9398eb078c968a0a0c3fff26fe819551eb87890a..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/AddressBook/AddressesMergeAddressBooksStep2.scala +++ /dev/null @@ -1,81 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Addresses { - case class Info( - address: Int, - zipcode: Int, - phoneNumber: Int - ) - - case class Address(info: Info, priv: Boolean) - - sealed abstract class List - case class Cons(a: Address, tail:List) extends List - case object Nil extends List - - def content(l: List) : Set[Address] = l match { - case Nil => Set.empty[Address] - case Cons(addr, l1) => Set(addr) ++ content(l1) - } - - def size(l: List) : Int = l match { - case Nil => 0 - case Cons(head, tail) => 1 + size(tail) - } - - def allPrivate(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) allPrivate(l1) - else false - } - - def allBusiness(l: List): Boolean = l match { - case Nil => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook(business : List, pers : List) - - def size(ab: AddressBook): Int = size(ab.business) + size(ab.pers) - - def addToPers(ab: AddressBook, adr: Address) = AddressBook(ab.business, Cons(adr, ab.pers)) - - def addToBusiness(ab: AddressBook, adr: Address) = AddressBook(Cons(adr, ab.business), ab.pers) - - def isEmpty(ab: AddressBook) = size(ab) == 0 - - def content(ab: AddressBook) : Set[Address] = content(ab.pers) ++ content(ab.business) - - def addressBookInvariant(ab: AddressBook) = allPrivate(ab.pers) && allBusiness(ab.business) - - def makeAddressBook(l: List): AddressBook = (l match { - case Nil => AddressBook(Nil, Nil) - case Cons(a, l1) => - val res = makeAddressBook(l1) - if (a.priv) AddressBook(res.business, Cons(a, res.pers)) - else AddressBook(Cons(a, res.business), res.pers) - }) ensuring { - (res: AddressBook) => - size(res) == size(l) && addressBookInvariant(res) - } - - def merge(l1: List, l2: List): List = (l1 match { - case Nil => l2 - case Cons(a, tail) => Cons(a, merge(tail, l2)) - }) ensuring(res => size(res) == size(l1) + size(l2) && - (!allBusiness(l1) || !allBusiness(l2) ||allBusiness(res)) && - (!allPrivate(l1) || !allPrivate(l2) ||allPrivate(res))) - - def mergeAddressBooks(ab1: AddressBook, ab2: AddressBook) = { - require(addressBookInvariant(ab1) && addressBookInvariant(ab2)) - choose { (res: AddressBook) => - (size(res) == size(ab1) + size(ab2)) && addressBookInvariant(res) - } - } - -} diff --git a/testcases/synthesis/oopsla2013/BatchedQueue/BatchedQueueCheckf.scala b/testcases/synthesis/oopsla2013/BatchedQueue/BatchedQueueCheckf.scala deleted file mode 100644 index 7d85a2c9bb96d5eae615f33b3557ecbb4a709e8e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/BatchedQueue/BatchedQueueCheckf.scala +++ /dev/null @@ -1,48 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def content(p: Queue): Set[Int] = - content(p.f) ++ content(p.r) - - case class Queue(f: List, r: List) - - def rev_append(aList: List, bList: List): List = (aList match { - case Nil => bList - case Cons(x, xs) => rev_append(xs, Cons(x, bList)) - }) ensuring (content(_) == content(aList) ++ content(bList)) - - def reverse(list: List) = rev_append(list, Nil) ensuring (content(_) == content(list)) - - def invariantList(q:Queue, f: List, r: List): Boolean = { - rev_append(q.f, q.r) == rev_append(f, r) && - { if (q.f == Nil) q.r == Nil else true } - } - - def tail(p: Queue): Queue = { - p.f match { - case Nil => p - case Cons(_, xs) => checkf(xs, p.r) - } - } - -//(f match { -// case Nil => Queue(reverse(r), Nil) -// case _ => Queue(f, r) - def checkf(f: List, r: List): Queue = { - choose { - (res: Queue) => - invariantList(res, f, r) - } - } - -} diff --git a/testcases/synthesis/oopsla2013/BatchedQueue/BatchedQueueSnoc.scala b/testcases/synthesis/oopsla2013/BatchedQueue/BatchedQueueSnoc.scala deleted file mode 100644 index c595f8253a4501bd56d7ada06a96091587003595..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/BatchedQueue/BatchedQueueSnoc.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty - case Cons(head, tail) => Set(head) ++ content(tail) - } - - def content(p: Queue): Set[Int] = - content(p.f) ++ content(p.r) - - case class Queue(f: List, r: List) - - def rev_append(aList: List, bList: List): List = (aList match { - case Nil => bList - case Cons(x, xs) => rev_append(xs, Cons(x, bList)) - }) ensuring (content(_) == content(aList) ++ content(bList)) - - def reverse(list: List) = rev_append(list, Nil) ensuring (content(_) == content(list)) - - def invariantList(q:Queue, f: List, r: List): Boolean = { - rev_append(q.f, q.r) == rev_append(f, r) && - { if (q.f == Nil) q.r == Nil else true } - } - - def tail(p: Queue): Queue = { - p.f match { - case Nil => p - case Cons(_, xs) => checkf(xs, p.r) - } - } - - def checkf(f: List, r: List): Queue = (f match { - case Nil => Queue(reverse(r), Nil) - case _ => Queue(f, r) - }) ensuring { - res => content(res) == content(f) ++ content(r) - } - // - // def last(p: Queue): Int = { - // require(!isEmpty(p)) - // p.r match { - // case Nil => reverse(p.f).asInstanceOf[Cons].head - // case Cons(x, _) => x - // } - // } - - def snoc(p: Queue, x: Int): Queue = - choose { (res: Queue) => - content(res) == content(p) ++ Set(x) && - (p.f == Nil || content(tail(res)) ++ - Set(x) == content(tail(res))) - } -} diff --git a/testcases/synthesis/oopsla2013/BinaryTree/Batch.scala b/testcases/synthesis/oopsla2013/BinaryTree/Batch.scala deleted file mode 100644 index 1329aa1fe0366a0fbb314b51fd34cf6a087d1a33..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/BinaryTree/Batch.scala +++ /dev/null @@ -1,37 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case object Leaf extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf => Set() - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree): Int = { - t match { - case Leaf => 0 - case Node(l, v, r) => size(l) + size(r) + 1 - } - } ensuring { _ >= 0 } - - def insert(in: Tree, v: Int): Tree = choose { - (res: Tree) => content(res) == content(in) ++ Set(v) - } - - def delete(in: Tree, v: Int): Tree = choose { - (res: Tree) => content(res) == content(in) -- Set(v) - } - - def union(in1: Tree, in2: Tree): Tree = choose { - (res: Tree) => content(res) == content(in1) ++ content(in2) - } - - def diff(in1: Tree, in2: Tree): Tree = choose { - (res: Tree) => content(res) == content(in1) -- content(in2) - } -} diff --git a/testcases/synthesis/oopsla2013/BinaryTree/Complete.scala b/testcases/synthesis/oopsla2013/BinaryTree/Complete.scala deleted file mode 100644 index c863167738c5f78808b38bea7013ef10e5ce4bb7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/BinaryTree/Complete.scala +++ /dev/null @@ -1,77 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case object Leaf extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf => Set() - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree): Int = { - t match { - case Leaf => 0 - case Node(l, v, r) => size(l) + size(r) + 1 - } - } ensuring { _ >= 0 } - - def insert(in: Tree, v: Int): Tree = { - Node(in, v, Leaf) - } ensuring { res => content(res) == content(in) ++ Set(v) } - - //def insert(in: Tree, v: Int): Tree = choose { - // (res: Tree) => content(res) == content(in) ++ Set(v) - //} - - def delete(in: Tree, v: Int): Tree = { - in match { - case Node(l, vv, r) => - if (vv == v) { - delete(l, v) match { - case Node(ll, lv, lr) => - Node(Node(ll, lv, lr), lv, delete(r, v)) - case Leaf => - delete(r, v) - } - } else { - Node(delete(l, v), vv, delete(r, v)) - } - case Leaf => - Leaf - } - } ensuring { res => content(res) == content(in) -- Set(v) } - - //def delete(in: Tree, v: Int): Tree = choose { - // (res: Tree) => content(res) == content(in) -- Set(v) - //} - - def union(in1: Tree, in2: Tree): Tree = { - in1 match { - case Node(l1, v1, r1) => - insert(union(r1, union(l1, in2)), v1) - case Leaf => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) } - - //def union(in1: Tree, in2: Tree): Tree = choose { - // (res: Tree) => content(res) == content(in1) ++ content(in2) - //} - - def diff(in1: Tree, in2: Tree): Tree = { - in2 match { - case Node(l2, v2, r2) => - delete(diff(diff(in1, l2), r2), v2) - case Leaf => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) } - - //def diff(in1: Tree, in2: Tree): Tree = choose { - // (res: Tree) => content(res) == content(in1) -- content(in2) - //} -} diff --git a/testcases/synthesis/oopsla2013/BinaryTree/Delete.scala b/testcases/synthesis/oopsla2013/BinaryTree/Delete.scala deleted file mode 100644 index 905c1aea49179ff05f64f4c5a20736db76e11ea2..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/BinaryTree/Delete.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case object Leaf extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf => Set() - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree): Int = { - t match { - case Leaf => 0 - case Node(l, v, r) => size(l) + size(r) + 1 - } - } ensuring { _ >= 0 } - - def insert(in: Tree, v: Int): Tree = { - Node(in, v, Leaf) - } ensuring { res => content(res) == content(in) ++ Set(v) } - - // def delete(in: Tree, v: Int): Tree = { - // in match { - // case Node(l, vv, r) => - // if (vv == v) { - // delete(l, v) match { - // case Node(ll, lv, lr) => - // Node(Node(ll, lv, lr), lv, delete(r, v)) - // case Leaf => - // delete(r, v) - // } - // } else { - // Node(delete(l, v), vv, delete(r, v)) - // } - // case Leaf => - // Leaf - // } - // } ensuring { res => content(res) == content(in) -- Set(v) } - - def delete(in: Tree, v: Int): Tree = choose { - (res: Tree) => content(res) == content(in) -- Set(v) - } -} diff --git a/testcases/synthesis/oopsla2013/BinaryTree/Diff.scala b/testcases/synthesis/oopsla2013/BinaryTree/Diff.scala deleted file mode 100644 index 1b95fabe552d9f9dc3a80733b81be7c3a10f290d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/BinaryTree/Diff.scala +++ /dev/null @@ -1,65 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case object Leaf extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf => Set() - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree): Int = { - t match { - case Leaf => 0 - case Node(l, v, r) => size(l) + size(r) + 1 - } - } ensuring { _ >= 0 } - - def insert(in: Tree, v: Int): Tree = { - Node(in, v, Leaf) - } ensuring { res => content(res) == content(in) ++ Set(v) } - - def delete(in: Tree, v: Int): Tree = { - in match { - case Node(l, vv, r) => - if (vv == v) { - delete(l, v) match { - case Node(ll, lv, lr) => - Node(Node(ll, lv, lr), lv, delete(r, v)) - case Leaf => - delete(r, v) - } - } else { - Node(delete(l, v), vv, delete(r, v)) - } - case Leaf => - Leaf - } - } ensuring { res => content(res) == content(in) -- Set(v) } - - def union(in1: Tree, in2: Tree): Tree = { - in1 match { - case Node(l1, v1, r1) => - insert(union(r1, union(l1, in2)), v1) - case Leaf => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) } - - // def diff(in1: Tree, in2: Tree): Tree = { - // in2 match { - // case Node(l2, v2, r2) => - // delete(diff(diff(in1, l2), r2), v2) - // case Leaf => - // in1 - // } - // } ensuring { res => content(res) == content(in1) -- content(in2) } - - def diff(in1: Tree, in2: Tree): Tree = choose { - (res: Tree) => content(res) == content(in1) -- content(in2) - } -} diff --git a/testcases/synthesis/oopsla2013/BinaryTree/Insert.scala b/testcases/synthesis/oopsla2013/BinaryTree/Insert.scala deleted file mode 100644 index 5a4ce2059868f91e2a0fce542f45530b84262f25..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/BinaryTree/Insert.scala +++ /dev/null @@ -1,29 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case object Leaf extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf => Set() - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree): Int = { - t match { - case Leaf => 0 - case Node(l, v, r) => size(l) + size(r) + 1 - } - } ensuring { _ >= 0 } - - //def insert(in: Tree, v: Int): Tree = { - // Node(in, v, Leaf) - //} ensuring { res => content(res) == content(in) ++ Set(v) } - - def insert(in: Tree, v: Int): Tree = choose { - (res: Tree) => content(res) == content(in) ++ Set(v) - } -} diff --git a/testcases/synthesis/oopsla2013/BinaryTree/Union.scala b/testcases/synthesis/oopsla2013/BinaryTree/Union.scala deleted file mode 100644 index 40d20ec46ceebebea9dc0be97007645b6ecd6c37..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/BinaryTree/Union.scala +++ /dev/null @@ -1,56 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case object Leaf extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf => Set() - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree): Int = { - t match { - case Leaf => 0 - case Node(l, v, r) => size(l) + size(r) + 1 - } - } ensuring { _ >= 0 } - - def insert(in: Tree, v: Int): Tree = { - Node(in, v, Leaf) - } ensuring { res => content(res) == content(in) ++ Set(v) } - - def delete(in: Tree, v: Int): Tree = { - in match { - case Node(l, vv, r) => - if (vv == v) { - delete(l, v) match { - case Node(ll, lv, lr) => - Node(Node(ll, lv, lr), lv, delete(r, v)) - case Leaf => - delete(r, v) - } - } else { - Node(delete(l, v), vv, delete(r, v)) - } - case Leaf => - Leaf - } - } ensuring { res => content(res) == content(in) -- Set(v) } - - // def union(in1: Tree, in2: Tree): Tree = { - // in1 match { - // case Node(l1, v1, r1) => - // insert(union(r1, union(l1, in2)), v1) - // case Leaf => - // in2 - // } - // } ensuring { res => content(res) == content(in1) ++ content(in2) } - - def union(in1: Tree, in2: Tree): Tree = choose { - (res: Tree) => content(res) == content(in1) ++ content(in2) - } -} diff --git a/testcases/synthesis/oopsla2013/Church/Add.scala b/testcases/synthesis/oopsla2013/Church/Add.scala deleted file mode 100644 index 937a13e38d79484bb1c888f4ebe34f7e473e9eef..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/Church/Add.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChurchNumerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n:Num) : Int = { - n match { - case Z => 0 - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - // def add(x : Num, y : Num) : Num = (x match { - // case Z => y - // case S(p) => add(p, S(y)) - // }) ensuring (value(_) == value(x) + value(y)) - - def add(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) + value(y) - } - } -} diff --git a/testcases/synthesis/oopsla2013/Church/Batch.scala b/testcases/synthesis/oopsla2013/Church/Batch.scala deleted file mode 100644 index b511b94e6f3bba219529519beef9907978c63f47..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/Church/Batch.scala +++ /dev/null @@ -1,27 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChurchNumerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n:Num) : Int = { - n match { - case Z => 0 - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) + value(y) - } - } - - def distinct(x: Num, y: Num): Num = { - choose { (r : Num) => - r != x && r != y - } - } -} diff --git a/testcases/synthesis/oopsla2013/Church/Complete.scala b/testcases/synthesis/oopsla2013/Church/Complete.scala deleted file mode 100644 index 94e94cc21ebe0ad49c8ff237954b1d07b708f476..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/Church/Complete.scala +++ /dev/null @@ -1,45 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChurchNumerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n:Num) : Int = { - n match { - case Z => 0 - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x : Num, y : Num) : Num = (x match { - case Z => y - case S(p) => add(p, S(y)) - }) ensuring (value(_) == value(x) + value(y)) - - //def add(x: Num, y: Num): Num = { - // choose { (r : Num) => - // value(r) == value(x) + value(y) - // } - //} - - def distinct(x : Num, y : Num) : Num = (x match { - case Z => - S(y) - - case S(p) => - y match { - case Z => - S(x) - case S(p) => - Z - } - }) ensuring (res => res != x && res != y) - - // def distinct(x: Num, y: Num): Num = { - // choose { (r : Num) => - // r != x && r != y - // } - // } -} diff --git a/testcases/synthesis/oopsla2013/Church/Distinct.scala b/testcases/synthesis/oopsla2013/Church/Distinct.scala deleted file mode 100644 index 5e718f3a0b1f200998afc9ede1b5a55ad1ac98ff..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/Church/Distinct.scala +++ /dev/null @@ -1,39 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChurchNumerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n:Num) : Int = { - n match { - case Z => 0 - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x : Num, y : Num) : Num = (x match { - case Z => y - case S(p) => add(p, S(y)) - }) ensuring (value(_) == value(x) + value(y)) - - //def distinct(x : Num, y : Num) : Num = (x match { - // case Z => - // S(y) - - // case S(p) => - // y match { - // case Z => - // S(x) - // case S(p) => - // Z - // } - //}) ensuring (res => res != x && res != y) - - def distinct(x: Num, y: Num): Num = { - choose { (r : Num) => - r != x && r != y - } - } -} diff --git a/testcases/synthesis/oopsla2013/Church/Mult.scala b/testcases/synthesis/oopsla2013/Church/Mult.scala deleted file mode 100644 index 70a6d68f4c3b30ee51063c16ef66a4a92eef4c97..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/Church/Mult.scala +++ /dev/null @@ -1,39 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChurchNumerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n:Num) : Int = { - n match { - case Z => 0 - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x : Num, y : Num) : Num = (x match { - case Z => y - case S(p) => add(p, S(y)) - }) ensuring (value(_) == value(x) + value(y)) - - //def distinct(x : Num, y : Num) : Num = (x match { - // case Z => - // S(y) - - // case S(p) => - // y match { - // case Z => - // S(x) - // case S(p) => - // Z - // } - //}) ensuring (res => res != x && res != y) - - def mult(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) * value(y) - } - } -} diff --git a/testcases/synthesis/oopsla2013/Church/Squared.scala b/testcases/synthesis/oopsla2013/Church/Squared.scala deleted file mode 100644 index b5b764d06ea5873b4fa8d9dad199ec7ca6e12c8d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/Church/Squared.scala +++ /dev/null @@ -1,46 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object ChurchNumerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n:Num) : Int = { - n match { - case Z => 0 - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x : Num, y : Num) : Num = (x match { - case Z => y - case S(p) => add(p, S(y)) - }) ensuring (value(_) == value(x) + value(y)) - - //def distinct(x : Num, y : Num) : Num = (x match { - // case Z => - // S(y) - - // case S(p) => - // y match { - // case Z => - // S(x) - // case S(p) => - // Z - // } - //}) ensuring (res => res != x && res != y) - - def mult(x: Num, y: Num): Num = (y match { - case S(p) => - add(mult(x, p), x) - case Z => - Z - }) ensuring { value(_) == value(x) * value(y) } - - def squared(x: Num): Num = { - choose { (r : Num) => - value(r) == value(x) * value(x) - } - } -} diff --git a/testcases/synthesis/oopsla2013/InsertionSort/Insert.scala b/testcases/synthesis/oopsla2013/InsertionSort/Insert.scala deleted file mode 100644 index cff8535f32b7f92262cfa7d35dd5409a0f760f51..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/InsertionSort/Insert.scala +++ /dev/null @@ -1,53 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object InsertionSort { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def size(l: List): Int = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring (_ >= 0) - - def contents(l: List): Set[Int] = l match { - case Nil() => Set.empty - case Cons(x, xs) => contents(xs) ++ Set(x) - } - - 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)) - } - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def insert(e: Int, l: List): List = { - require(isSorted(l)) - choose { (res: List) => - ( - contents(res) == contents(l) ++ Set(e) && - isSorted(res) && - size(res) == size(l) + 1) - } - // l match { - // case Nil() => Cons(e, Nil()) - // case Cons(x, xs) => - // if (x <= e) Cons(x, sortedIns(e, xs)) - // else Cons(e, l) - // } - } - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort(l: List): List = (l match { - case Nil() => Nil() - case Cons(x, xs) => insert(x, sort(xs)) - }) ensuring (res => contents(res) == contents(l) - && isSorted(res) - && size(res) == size(l)) - -} diff --git a/testcases/synthesis/oopsla2013/InsertionSort/Sort.scala b/testcases/synthesis/oopsla2013/InsertionSort/Sort.scala deleted file mode 100644 index 11f9302794570b210c2f81d5c8d687169fd7ae64..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/InsertionSort/Sort.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object InsertionSort { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def size(l: List): Int = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring (_ >= 0) - - def contents(l: List): Set[Int] = l match { - case Nil() => Set.empty - case Cons(x, xs) => contents(xs) ++ Set(x) - } - - 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)) - } - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def insert(e: Int, l: List): List = { - require(isSorted(l)) - l match { - case Nil() => Cons(e, Nil()) - case Cons(x, xs) => - if (x <= e) Cons(x, insert(e, xs)) - else Cons(e, l) - } - } ensuring (res => contents(res) == contents(l) ++ Set(e) - && isSorted(res) - && size(res) == size(l) + 1) - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort(l: List): List = { - choose { (res: List) => - ( contents(res) == contents(l) - && isSorted(res) - && size(res) == size(l)) - } - } - // case Nil() => Nil() - // case Cons(x, xs) => sortedIns(x, sort(xs)) - -} diff --git a/testcases/synthesis/oopsla2013/List/Batch.scala b/testcases/synthesis/oopsla2013/List/Batch.scala deleted file mode 100644 index a03ef20334ea840e8f454b22d9a9240d1b24bc36..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/List/Batch.scala +++ /dev/null @@ -1,39 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object List { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def insert(in1: List, v: Int) = choose { - (out : List) => - content(out) == content(in1) ++ Set(v) - } - - def delete(in1: List, v: Int) = choose { - (out : List) => - content(out) == content(in1) -- Set(v) - } - - def union(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) ++ content(in2) - } - - def diff(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) -- content(in2) - } -} diff --git a/testcases/synthesis/oopsla2013/List/Complete.scala b/testcases/synthesis/oopsla2013/List/Complete.scala deleted file mode 100644 index 9d52f3181641bbe7ba194c60b29b55a0b1a3e894..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/List/Complete.scala +++ /dev/null @@ -1,75 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def insert(in1: List, v: Int): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - //def insert(in1: List, v: Int) = choose { - // (out : List) => - // content(out) == content(in1) ++ Set(v) - //} - - def delete(in1: List, v: Int): List = { - in1 match { - case Cons(h,t) => - if (h == v) { - delete(t, v) - } else { - Cons(h, delete(t, v)) - } - case Nil => - Nil - } - } ensuring { content(_) == content(in1) -- Set(v) } - - //def delete(in1: List, v: Int) = choose { - // (out : List) => - // content(out) == content(in1) -- Set(v) - //} - - def union(in1: List, in2: List): List = { - in1 match { - case Cons(h, t) => - Cons(h, union(t, in2)) - case Nil => - in2 - } - } ensuring { content(_) == content(in1) ++ content(in2) } - - //def union(in1: List, in2: List) = choose { - // (out : List) => - // content(out) == content(in1) ++ content(in2) - //} - - def diff(in1: List, in2: List): List = { - in2 match { - case Nil => - in1 - case Cons(h, t) => - diff(delete(in1, h), t) - } - } ensuring { content(_) == content(in1) -- content(in2) } - - //def diff(in1: List, in2: List) = choose { - // (out : List) => - // content(out) == content(in1) -- content(in2) - //} - -} diff --git a/testcases/synthesis/oopsla2013/List/Delete.scala b/testcases/synthesis/oopsla2013/List/Delete.scala deleted file mode 100644 index d6c5072aa3280481f212e15cf29adbb199c23c4c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/List/Delete.scala +++ /dev/null @@ -1,41 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Delete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def insert(in1: List, v: Int): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - //def delete(in1: List, v: Int): List = { - // in1 match { - // case Cons(h,t) => - // if (h == v) { - // delete(t, v) - // } else { - // Cons(h, delete(t, v)) - // } - // case Nil => - // Nil - // } - //} ensuring { content(_) == content(in1) -- Set(v) } - - def delete(in1: List, v: Int) = choose { - (out : List) => - content(out) == content(in1) -- Set(v) - } -} diff --git a/testcases/synthesis/oopsla2013/List/Diff.scala b/testcases/synthesis/oopsla2013/List/Diff.scala deleted file mode 100644 index 45b67f35a8f80678de65f5e79c00afce15f5b230..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/List/Diff.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Diff { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def insert(in1: List, v: Int): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - def delete(in1: List, v: Int): List = { - in1 match { - case Cons(h,t) => - if (h == v) { - delete(t, v) - } else { - Cons(h, delete(t, v)) - } - case Nil => - Nil - } - } ensuring { content(_) == content(in1) -- Set(v) } - - def union(in1: List, in2: List): List = { - in1 match { - case Cons(h, t) => - Cons(h, union(t, in2)) - case Nil => - in2 - } - } ensuring { content(_) == content(in1) ++ content(in2) } - - // def diff(in1: List, in2: List): List = { - // in2 match { - // case Nil => - // in1 - // case Cons(h, t) => - // diff(delete(in1, h), t) - // } - // } ensuring { content(_) == content(in1) -- content(in2) } - - def diff(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) -- content(in2) - } -} diff --git a/testcases/synthesis/oopsla2013/List/Insert.scala b/testcases/synthesis/oopsla2013/List/Insert.scala deleted file mode 100644 index 652190117a85dbf63c02136b0191ba0de969c3c8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/List/Insert.scala +++ /dev/null @@ -1,28 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Insert { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - //def insert(in1: List, v: Int): List = { - // Cons(v, in1) - //} ensuring { content(_) == content(in1) ++ Set(v) } - - def insert(in1: List, v: Int) = choose { - (out : List) => - content(out) == content(in1) ++ Set(v) - } -} diff --git a/testcases/synthesis/oopsla2013/List/Split.scala b/testcases/synthesis/oopsla2013/List/Split.scala deleted file mode 100644 index aca7da75fddb48752ee89864aa918ed70bf444e3..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/List/Split.scala +++ /dev/null @@ -1,101 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def insert(in1: List, v: Int): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - //def insert(in1: List, v: Int) = choose { - // (out : List) => - // content(out) == content(in1) ++ Set(v) - //} - - def delete(in1: List, v: Int): List = { - in1 match { - case Cons(h,t) => - if (h == v) { - delete(t, v) - } else { - Cons(h, delete(t, v)) - } - case Nil => - Nil - } - } ensuring { content(_) == content(in1) -- Set(v) } - - //def delete(in1: List, v: Int) = choose { - // (out : List) => - // content(out) == content(in1) -- Set(v) - //} - - def union(in1: List, in2: List): List = { - in1 match { - case Cons(h, t) => - Cons(h, union(t, in2)) - case Nil => - in2 - } - } ensuring { content(_) == content(in1) ++ content(in2) } - - //def union(in1: List, in2: List) = choose { - // (out : List) => - // content(out) == content(in1) ++ content(in2) - //} - - def diff(in1: List, in2: List): List = { - in2 match { - case Nil => - in1 - case Cons(h, t) => - diff(delete(in1, h), t) - } - } ensuring { content(_) == content(in1) -- content(in2) } - - //def diff(in1: List, in2: List) = choose { - // (out : List) => - // content(out) == content(in1) -- content(in2) - //} - - def splitSpec(list : List, res : (List,List)) : Boolean = { - - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - // def split(list : List) : (List,List) = (list match { - // case Nil => (Nil, Nil) - // case Cons(x, Nil) => (Cons(x, Nil), Nil) - // case Cons(x1, Cons(x2, xs)) => - // val (s1,s2) = split(xs) - // (Cons(x1, s1), Cons(x2, s2)) - // }) ensuring(res => splitSpec(list, res)) - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => splitSpec(list, res) } - } - -} diff --git a/testcases/synthesis/oopsla2013/List/Union.scala b/testcases/synthesis/oopsla2013/List/Union.scala deleted file mode 100644 index f33990420bd38a6246d3cf772f09c9cfe72d936a..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/List/Union.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Union { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def insert(in1: List, v: Int): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - def delete(in1: List, v: Int): List = { - in1 match { - case Cons(h,t) => - if (h == v) { - delete(t, v) - } else { - Cons(h, delete(t, v)) - } - case Nil => - Nil - } - } ensuring { content(_) == content(in1) -- Set(v) } - - // def union(in1: List, in2: List): List = { - // in1 match { - // case Cons(h, t) => - // Cons(h, union(t, in2)) - // case Nil => - // in2 - // } - // } ensuring { content(_) == content(in1) ++ content(in2) } - - def union(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) ++ content(in2) - } -} diff --git a/testcases/synthesis/oopsla2013/MergeSort/Complete.scala b/testcases/synthesis/oopsla2013/MergeSort/Complete.scala deleted file mode 100644 index 326295aafafdb88a71d0cd2c25f740efe0438fc9..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/MergeSort/Complete.scala +++ /dev/null @@ -1,83 +0,0 @@ -import leon.lang._ - -object MergeSort { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - sealed abstract class PairAbs - case class Pair(fst: List, snd: List) extends PairAbs - - def contents(l: List): Set[Int] = l match { - case Nil() => Set.empty - case Cons(x, xs) => contents(xs) ++ Set(x) - } - - def isSorted(l: List): Boolean = l match { - case Nil() => true - case Cons(x, xs) => xs match { - case Nil() => true - case Cons(y, ys) => x <= y && isSorted(Cons(y, ys)) - } - } - - def size(list: List): Int = list match { - case Nil() => 0 - case Cons(x, xs) => 1 + size(xs) - } - - def splithelper(aList: List, bList: List, n: Int): Pair = { - if (n <= 0) Pair(aList, bList) - else - bList match { - case Nil() => Pair(aList, bList) - case Cons(x, xs) => splithelper(Cons(x, aList), xs, n - 1) - } - } ensuring (res => - contents(aList) ++ contents(bList) == contents(res.fst) ++ contents(res.snd) - && - size(aList) + size(bList) == size(res.fst) + size(res.snd) - ) - - def split(list: List): Pair = { - splithelper(Nil(), list, 2) - } ensuring (res => - contents(list) == contents(res.fst) ++ contents(res.snd) - && - size(list) == size(res.fst) + size(res.snd) - ) - - def merge(aList: List, bList: List): List = { - require(isSorted(aList) && isSorted(bList)) - bList match { - case Nil() => aList - case Cons(x, xs) => - aList match { - case Nil() => bList - case Cons(y, ys) => - if (y < x) - Cons(y, merge(ys, bList)) - else - Cons(x, merge(aList, xs)) - } - } - } ensuring (res => contents(res) == - contents(aList) ++ contents(bList) && isSorted(res) && - size(res) == size(aList) + size(bList) - ) - - def isEmpty(list: List): Boolean = list match { - case Nil() => true - case Cons(x, xs) => false - } - - def sort(list: List): List = { - list match { - case Nil() => list - case Cons(x, Nil()) => list - case _ => - merge(sort(split(list).fst), sort(split(list).snd)) - } - } ensuring (res => contents(res) == contents(list) && isSorted(res) && size(res) == size(list)) - -} diff --git a/testcases/synthesis/oopsla2013/MergeSort/MergeSortSort.scala b/testcases/synthesis/oopsla2013/MergeSort/MergeSortSort.scala deleted file mode 100644 index feff019ed6b44024e001f7624a9c3c8db9791aad..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/MergeSort/MergeSortSort.scala +++ /dev/null @@ -1,85 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object MergeSort { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class PairAbs - case class Pair(fst : List, snd : List) extends PairAbs - - def contents(l : List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def isSorted(l : List) : Boolean = l match { - case Nil() => true - case Cons(x,xs) => xs match { - case Nil() => true - case Cons(y, ys) => x <= y && isSorted(Cons(y, ys)) - } - } - - def size(list : List) : Int = list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - } - - def splithelper(aList : List, bList : List, n : Int) : Pair = { - if (n <= 0) Pair(aList,bList) - else - bList match { - case Nil() => Pair(aList,bList) - case Cons(x,xs) => splithelper(Cons(x,aList),xs,n-1) - } - } ensuring(res => contents(aList) ++ contents(bList) == contents(res.fst) ++ contents(res.snd)) - -// def split(list : List, n : Int): Pair = { -// splithelper(Nil(),list,n) -// } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def split(list: List): Pair = { - splithelper(Nil(),list,size(list)/2) - } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def merge(aList : List, bList : List) : List = { - require(isSorted(aList) && isSorted(bList)) - bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - } - } ensuring(res => contents(res) == contents(aList) ++ contents(bList) && isSorted(res)) - - def isEmpty(list: List) : Boolean = list match { - case Nil() => true - case Cons(x,xs) => false - } - - def sort(list : List) : List = choose { - - (res : List) => - contents(res) == contents(list) && isSorted(res) - -// list match { -// case Nil() => list -// case Cons(x,Nil()) => list -// case _ => -// val p = split(list,size(list)/2) -// merge(mergeSort(p.fst), mergeSort(p.snd)) - -// merge(mergeSort(split(list).fst), mergeSort(split(list).snd)) - } - - //ensuring(res => contents(res) == contents(list) && isSorted(res)) - -} diff --git a/testcases/synthesis/oopsla2013/MergeSort/MergeSortSortWithVal.scala b/testcases/synthesis/oopsla2013/MergeSort/MergeSortSortWithVal.scala deleted file mode 100644 index 2f59d1ca59aad23cafd1f94437dc4e18188f3597..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/MergeSort/MergeSortSortWithVal.scala +++ /dev/null @@ -1,84 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object MergeSort { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class PairAbs - case class Pair(fst : List, snd : List) extends PairAbs - - def contents(l : List) : Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def isSorted(l : List) : Boolean = l match { - case Nil() => true - case Cons(x,xs) => xs match { - case Nil() => true - case Cons(y, ys) => x <= y && isSorted(Cons(y, ys)) - } - } - - def size(list : List) : Int = list match { - case Nil() => 0 - case Cons(x,xs) => 1 + size(xs) - } - - def splithelper(aList : List, bList : List, n : Int) : Pair = { - if (n <= 0) Pair(aList,bList) - else - bList match { - case Nil() => Pair(aList,bList) - case Cons(x,xs) => splithelper(Cons(x,aList),xs,n-1) - } - } ensuring(res => contents(aList) ++ contents(bList) == contents(res.fst) ++ contents(res.snd)) - -// def split(list : List, n : Int): Pair = { -// splithelper(Nil(),list,n) -// } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def split(list: List): Pair = { - splithelper(Nil(),list,size(list)/2) - } ensuring(res => contents(list) == contents(res.fst) ++ contents(res.snd)) - - def merge(aList : List, bList : List) : List = { - require(isSorted(aList) && isSorted(bList)) - bList match { - case Nil() => aList - case Cons(x,xs) => - aList match { - case Nil() => bList - case Cons(y,ys) => - if (y < x) - Cons(y,merge(ys, bList)) - else - Cons(x,merge(aList, xs)) - } - } - } ensuring(res => contents(res) == contents(aList) ++ contents(bList) && isSorted(res)) - - def isEmpty(list: List) : Boolean = list match { - case Nil() => true - case Cons(x,xs) => false - } - - def sort(list : List) : List = - list match { - case Nil() => list - case Cons(_,Nil()) => list - case _ => { - val p = split(list) - choose {(res : List) => - contents(res) == contents(list) && isSorted(res) - } - } - } - -// merge(mergeSort(split(list).fst), mergeSort(split(list).snd)) - - //ensuring(res => contents(res) == contents(list) && isSorted(res)) - -} diff --git a/testcases/synthesis/oopsla2013/SortedBinaryTree/Batch.scala b/testcases/synthesis/oopsla2013/SortedBinaryTree/Batch.scala deleted file mode 100644 index a35eaca9f5a4d7fac794d52a737d7156d3219855..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedBinaryTree/Batch.scala +++ /dev/null @@ -1,80 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case object Leaf extends Tree - - def content(t : Tree): Set[Int] = t match { - case Leaf => Set.empty[Int] - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - sealed abstract class OptPair - case class Pair(v1 : Int, v2 : Int) extends OptPair - case object NoPair extends OptPair - - def isSortedX(t : Tree) : (Boolean, OptPair) = (t match { - case Leaf => (true, NoPair) - case Node(Leaf, v, Leaf) => (true, Pair(v, v)) - case Node(Node(_, lv, _), v, _) if lv >= v => (false, NoPair) - case Node(_, v, Node(_, rv, _)) if rv <= v => (false, NoPair) - - case Node(l, v, r) => - val (ls,lb) = isSortedX(l) - - val (lOK,newMin) = lb match { - case NoPair => (ls, v) - case Pair(ll, lh) => (ls && lh < v, ll) - } - - if(lOK) { - val (rs,rb) = isSortedX(r) - val (rOK,newMax) = rb match { - case NoPair => (rs, v) - case Pair(rl, rh) => (rs && v < rl, rh) - } - - if(rOK) { - (true, Pair(newMin, newMax)) - } else { - (false, NoPair) - } - } else { - (false, NoPair) - } - }) ensuring((res : (Boolean,OptPair)) => res match { - case (s, Pair(l,u)) => s && (l <= u) - case _ => true - }) - - def isSorted(t: Tree): Boolean = isSortedX(t)._1 - - def deleteSynth(in : Tree, v : Int) = choose { - (out : Tree) => content(out) == (content(in) -- Set(v)) - } - - // def insertImpl(t : Tree, x : Int) : Tree = { - // require(isSorted(t)) - // t match { - // case Leaf => Node(Leaf, x, Leaf) - // case Node(l, v, r) if v == x => Node(l, v, r) - // case Node(l, v, r) if x < v => Node(insertImpl(l, x), v, r) - // case Node(l, v, r) if v < x => Node(l, v, insertImpl(r, x)) - // } - // } ensuring(isSorted(_)) - - def insertSynth(in : Tree, v : Int) = choose { - (out : Tree) => content(out) == (content(in) ++ Set(v)) - } - - def insertSortedSynth(in : Tree, v : Int) = choose { - (out : Tree) => isSorted(in) && (content(out) == (content(in) ++ Set(v))) && isSorted(out) - } - - def deleteSortedSynth(in : Tree, v : Int) = choose { - (out : Tree) => isSorted(in) && (content(out) == (content(in) -- Set(v))) && isSorted(out) - } -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Batch.scala b/testcases/synthesis/oopsla2013/SortedList/Batch.scala deleted file mode 100644 index 8da614143ef31571bbe112a53af48fb2bd89bd12..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Batch.scala +++ /dev/null @@ -1,90 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedList { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int) = { - require(isSorted(in1)) - - choose { - (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } - - def delete(in1: List, v: Int) = { - require(isSorted(in1)) - - choose { - (out : List) => - isSorted(in1) && (content(out) == content(in1) -- Set(v)) && isSorted(out) - } - } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - - choose { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } - - def diff(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - - choose { - (out : List) => - (content(out) == content(in1) -- content(in2)) && isSorted(out) - } - } - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => splitSpec(list, res) } - } - - def sort(list: List): List = choose { - (res: List) => sortSpec(list, res) - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Complete.scala b/testcases/synthesis/oopsla2013/SortedList/Complete.scala deleted file mode 100644 index b2465c9705c9d4299feb83226fb2654ddc724976..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Complete.scala +++ /dev/null @@ -1,172 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - //def insert(in1: List, v: Int) = choose { - // (out : List) => - // isSorted(in1) && (content(out) == content(in1) ++ Set(v)) && isSorted(out) - //} - - def insert2(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - Cons(v, in1) - } else { - Cons(h, insert2(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) && size(res) == size(in1) + 1 } - - //def insert2(in1: List, v: Int) = choose { - // (out : List) => - // isSorted(in1) && (content(out) == content(in1) ++ Set(v)) && isSorted(out) && size(out) == size(in1) + 1 - //} - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - //def delete(in1: List, v: Int) = choose { - // (out : List) => - // isSorted(in1) && (content(out) == content(in1) -- Set(v)) && isSorted(out) - //} - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - union(t1, insert(in2, h1)) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - //def union(in1: List, in2: List) = choose { - // (out : List) => - // isSorted(in1) && isSorted(in2) && (content(out) == content(in1) ++ content(in2)) && isSorted(out) - //} - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - //def diff(in1: List, in2: List) = choose { - // (out : List) => - // isSorted(in1) && isSorted(in2) && (content(out) == content(in1) -- content(in2)) && isSorted(out) - //} - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - - def split(list : List) : (List,List) = (list match { - case Nil => (Nil, Nil) - case Cons(x, Nil) => (Cons(x, Nil), Nil) - case Cons(x1, Cons(x2, xs)) => - val (s1,s2) = split(xs) - (Cons(x1, s1), Cons(x2, s2)) - }) ensuring(res => splitSpec(list, res)) - - //def split(list : List) : (List,List) = { - // choose { (res : (List,List)) => splitSpec(list, res) } - //} - - def sort1(in : List) : List = (in match { - case Nil => Nil - case Cons(x, xs) => insert(sort1(xs), x) - }) ensuring(res => sortSpec(in, res)) - - // Not really quicksort, neither mergesort. - def sort2(in : List) : List = (in match { - case Nil => Nil - case Cons(x, Nil) => Cons(x, Nil) - case _ => - val (s1,s2) = split(in) - union(sort2(s1), sort2(s2)) - }) ensuring(res => sortSpec(in, res)) - - //def sort(list: List): List = choose { - // (res: List) => sortSpec(list, res) - //} - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Delete.scala b/testcases/synthesis/oopsla2013/SortedList/Delete.scala deleted file mode 100644 index b66aa8b3308a677d28634d18dc328b9fe2fd6e00..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Delete.scala +++ /dev/null @@ -1,68 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - // def delete(in1: List, v: Int): List = { - // require(isSorted(in1)) - // in1 match { - // case Cons(h,t) => - // if (h < v) { - // Cons(h, delete(t, v)) - // } else if (h == v) { - // delete(t, v) - // } else { - // in1 - // } - // case Nil => - // Nil - // } - // } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def delete(in1: List, v: Int) = { - require(isSorted(in1)) - - choose { - (out : List) => - (content(out) == content(in1) -- Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Diff.scala b/testcases/synthesis/oopsla2013/SortedList/Diff.scala deleted file mode 100644 index 45ff5133851208a5884408107a0f30885d9bbcff..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Diff.scala +++ /dev/null @@ -1,89 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - union(t1, insert(in2, h1)) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - // def diff(in1: List, in2: List): List = { - // require(isSorted(in1) && isSorted(in2)) - // in2 match { - // case Cons(h2, t2) => - // diff(delete(in1, h2), t2) - // case Nil => - // in1 - // } - // } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - def diff(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - - choose { - (out : List) => - (content(out) == content(in1) -- content(in2)) && isSorted(out) - } - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Insert1.scala b/testcases/synthesis/oopsla2013/SortedList/Insert1.scala deleted file mode 100644 index b785401c1d8e3919620b550fe78910f394d23849..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Insert1.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - // def insert(in1: List, v: Int): List = { - // require(isSorted(in1)) - // in1 match { - // case Cons(h, t) => - // if (v < h) { - // Cons(v, in1) - // } else if (v == h) { - // in1 - // } else { - // Cons(h, insert(t, v)) - // } - // case Nil => - // Cons(v, Nil) - // } - // } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def insert(in1: List, v: Int) = { - require(isSorted(in1)) - - choose { (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) } - } -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Insert2.scala b/testcases/synthesis/oopsla2013/SortedList/Insert2.scala deleted file mode 100644 index 9b86ba2a0c74743a11a2877ee6ea575b49130c2d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Insert2.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - // def insert2(in1: List, v: Int): List = { - // require(isSorted(in1)) - // in1 match { - // case Cons(h, t) => - // if (v < h) { - // Cons(v, in1) - // } else if (v == h) { - // Cons(v, in1) - // } else { - // Cons(h, insert2(t, v)) - // } - // case Nil => - // Cons(v, Nil) - // } - // } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) && size(res) == size(in1) + 1 } - - def insert2(in1: List, v: Int) = { - require(isSorted(in1)) - - choose { - (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) && size(out) == size(in1) + 1 - } - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Sort.scala b/testcases/synthesis/oopsla2013/SortedList/Sort.scala deleted file mode 100644 index 28e6de67b3ba357d13b8c7ad5461bba151848a1e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Sort.scala +++ /dev/null @@ -1,126 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - insert(union(t1, in2), h1) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - - def split(list : List) : (List,List) = (list match { - case Nil => (Nil, Nil) - case Cons(x, Nil) => (Cons(x, Nil), Nil) - case Cons(x1, Cons(x2, xs)) => - val (s1,s2) = split(xs) - (Cons(x1, s1), Cons(x2, s2)) - }) ensuring(res => splitSpec(list, res)) - - // def sort1(in : List) : List = (in match { - // case Nil => Nil - // case Cons(x, xs) => insert(sort1(xs), x) - // }) ensuring(res => sortSpec(in, res)) - - // // Not really quicksort, neither mergesort. - // def sort2(in : List) : List = (in match { - // case Nil => Nil - // case Cons(x, Nil) => Cons(x, Nil) - // case _ => - // val (s1,s2) = split(in) - // union(sort2(s1), sort2(s2)) - // }) ensuring(res => sortSpec(in, res)) - - def sort(list: List): List = choose { - (res: List) => sortSpec(list, res) - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/SortInsert.scala b/testcases/synthesis/oopsla2013/SortedList/SortInsert.scala deleted file mode 100644 index b53ca0d05d4c40c7c66c5250a2d5a3e1114177fa..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/SortInsert.scala +++ /dev/null @@ -1,106 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - insert(union(t1, in2), h1) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - // *********************** - // Sorting algorithms - // *********************** - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - // def sort1(in : List) : List = (in match { - // case Nil => Nil - // case Cons(x, xs) => insert(sort1(xs), x) - // }) ensuring(res => sortSpec(in, res)) - - // // Not really quicksort, neither mergesort. - // def sort2(in : List) : List = (in match { - // case Nil => Nil - // case Cons(x, Nil) => Cons(x, Nil) - // case _ => - // val (s1,s2) = split(in) - // union(sort2(s1), sort2(s2)) - // }) ensuring(res => sortSpec(in, res)) - - def sort(list: List): List = choose { - (res: List) => sortSpec(list, res) - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/SortMerge.scala b/testcases/synthesis/oopsla2013/SortedList/SortMerge.scala deleted file mode 100644 index fb216a4c4d4278bf6499553d8220313f3ee89cd5..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/SortMerge.scala +++ /dev/null @@ -1,115 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def size(l: List) : Int = (l match { - case Nil => 0 - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty[Int] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2) && abs(size(in1)-size(in2)) <= 1) - (in1, in2) match { - case (Cons(h1, t1), Cons(h2, t2)) => - if (h1 < h2) { - Cons(h1, union(t1, Cons(h2, t2))) - } else { - Cons(h2, union(Cons(h1, t1), t2)) - } - case (Nil, l2) => - l2 - case (l1, Nil) => - l1 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - - def split(list : List) : (List,List) = (list match { - case Nil => (Nil, Nil) - case Cons(x, Nil) => (Cons(x, Nil), Nil) - case Cons(x1, Cons(x2, xs)) => - val (s1,s2) = split(xs) - (Cons(x1, s1), Cons(x2, s2)) - }) ensuring(res => splitSpec(list, res)) - - // def sort1(in : List) : List = (in match { - // case Nil => Nil - // case Cons(x, xs) => insert(sort1(xs), x) - // }) ensuring(res => sortSpec(in, res)) - - // // Not really quicksort, neither mergesort. - // def sort2(in : List) : List = (in match { - // case Nil => Nil - // case Cons(x, Nil) => Cons(x, Nil) - // case _ => - // val (s1,s2) = split(in) - // union(sort2(s1), sort2(s2)) - // }) ensuring(res => sortSpec(in, res)) - - def sort(list: List): List = choose { - (res: List) => sortSpec(list, res) - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/SortMergeWithHint.scala b/testcases/synthesis/oopsla2013/SortedList/SortMergeWithHint.scala deleted file mode 100644 index 06ed93ba9e5f715505eb53029bcbbd16fccee778..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/SortMergeWithHint.scala +++ /dev/null @@ -1,125 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - def size(l: List) : Int = (l match { - case Nil => 0 - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def content(l: List): Set[Int] = l match { - case Nil => Set.empty[Int] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2) && abs(size(in1)-size(in2)) <= 1) - (in1, in2) match { - case (Cons(h1, t1), Cons(h2, t2)) => - if (h1 < h2) { - Cons(h1, union(t1, Cons(h2, t2))) - } else { - Cons(h2, union(Cons(h1, t1), t2)) - } - case (Nil, l2) => - l2 - case (l1, Nil) => - l1 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - - def split(list : List) : (List,List) = (list match { - case Nil => (Nil, Nil) - case Cons(x, Nil) => (Cons(x, Nil), Nil) - case Cons(x1, Cons(x2, xs)) => - val (s1,s2) = split(xs) - (Cons(x1, s1), Cons(x2, s2)) - }) ensuring(res => splitSpec(list, res)) - - // def sort1(in : List) : List = (in match { - // case Nil => Nil - // case Cons(x, xs) => insert(sort1(xs), x) - // }) ensuring(res => sortSpec(in, res)) - - // // Not really quicksort, neither mergesort. - // def sort2(in : List) : List = (in match { - // case Nil => Nil - // case Cons(x, Nil) => Cons(x, Nil) - // case _ => - // val (s1,s2) = split(in) - // union(sort2(s1), sort2(s2)) - // }) ensuring(res => sortSpec(in, res)) - - def sort(list: List): List = (list match { - case Nil => Nil - case Cons(_, Nil) => list - case _ => split(list) match { - case (l1, l2) => - val r1 = sort(l1) - val r2 = sort(l2) - - choose { - (res: List) => sortSpec(list, res) - } - } - }) ensuring { res => size(res) == size(list) && sortSpec(list, res) } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Split.scala b/testcases/synthesis/oopsla2013/SortedList/Split.scala deleted file mode 100644 index 77a883c6056befede247b84e6e1fc22860ed7a0f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Split.scala +++ /dev/null @@ -1,112 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - union(t1, insert(in2, h1)) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - - // def split(list : List) : (List,List) = (list match { - // case Nil => (Nil, Nil) - // case Cons(x, Nil) => (Cons(x, Nil), Nil) - // case Cons(x1, Cons(x2, xs)) => - // val (s1,s2) = split(xs) - // (Cons(x1, s1), Cons(x2, s2)) - // }) ensuring(res => splitSpec(list, res)) - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => splitSpec(list, res) } - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Split1.scala b/testcases/synthesis/oopsla2013/SortedList/Split1.scala deleted file mode 100644 index 69a604755468e0e2d5bc6b38685de5f87769043a..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Split1.scala +++ /dev/null @@ -1,112 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - union(t1, insert(in2, h1)) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - - // def split(list : List) : (List,List) = (list match { - // case Nil => (Nil, Nil) - // case Cons(x, Nil) => (Cons(x, Nil), Nil) - // case Cons(x1, Cons(x2, xs)) => - // val (s1,s2) = split(xs) - // (Cons(x1, s1), Cons(x2, s2)) - // }) ensuring(res => splitSpec(list, res)) - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => (content(res._1) ++ content(res._2) == content(list)) } - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Split2.scala b/testcases/synthesis/oopsla2013/SortedList/Split2.scala deleted file mode 100644 index c3f30be7f571060414cccc2b454787ce4ed1a001..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Split2.scala +++ /dev/null @@ -1,112 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - union(t1, insert(in2, h1)) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - - // def split(list : List) : (List,List) = (list match { - // case Nil => (Nil, Nil) - // case Cons(x, Nil) => (Cons(x, Nil), Nil) - // case Cons(x1, Cons(x2, xs)) => - // val (s1,s2) = split(xs) - // (Cons(x1, s1), Cons(x2, s2)) - // }) ensuring(res => splitSpec(list, res)) - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => (content(res._1) ++ content(res._2) == content(list)) && abs(size(res._1) - size(res._2)) <= 1 } - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Split3.scala b/testcases/synthesis/oopsla2013/SortedList/Split3.scala deleted file mode 100644 index eb27d44140f32c3ad3cfa974e36608d9d78d864a..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Split3.scala +++ /dev/null @@ -1,112 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - union(t1, insert(in2, h1)) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - // *********************** - // Sorting algorithms - // *********************** - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - - // def split(list : List) : (List,List) = (list match { - // case Nil => (Nil, Nil) - // case Cons(x, Nil) => (Cons(x, Nil), Nil) - // case Cons(x1, Cons(x2, xs)) => - // val (s1,s2) = split(xs) - // (Cons(x1, s1), Cons(x2, s2)) - // }) ensuring(res => splitSpec(list, res)) - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => (content(res._1) ++ content(res._2) == content(list)) && abs(size(res._1) - size(res._2)) <= 1 && (size(res._1) + size(res._2) == size(list)) } - } - -} diff --git a/testcases/synthesis/oopsla2013/SortedList/Union.scala b/testcases/synthesis/oopsla2013/SortedList/Union.scala deleted file mode 100644 index 7681b838fe89811328c0abdcddbc7d46795fdc6c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/Union.scala +++ /dev/null @@ -1,74 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - // def union(in1: List, in2: List): List = { - // require(isSorted(in1) && isSorted(in2)) - // in1 match { - // case Cons(h1, t1) => - // union(t1, insert(in2, h1)) - // case Nil => - // in2 - // } - // } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def union(in1: List, in2: List) = choose { - (out : List) => - isSorted(in1) && isSorted(in2) && (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } -} diff --git a/testcases/synthesis/oopsla2013/SortedList/UnionIO.scala b/testcases/synthesis/oopsla2013/SortedList/UnionIO.scala deleted file mode 100644 index 8e851fd9ba6d5969cd9ff3b8f92ef9552d309b75..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SortedList/UnionIO.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - // def union(in1: List, in2: List): List = { - // require(isSorted(in1) && isSorted(in2)) - // in1 match { - // case Cons(h1, t1) => - // union(t1, insert(in2, h1)) - // case Nil => - // in2 - // } - // } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - -/* - def union(in1: List, in2: List) = choose { - (out : List) => - isSorted(in1) && isSorted(in2) && (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } -*/ - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { (out : List) => - (in1!= Cons(10,Cons(20,Cons(30,Cons(40,Nil)))) || - in2!= Cons(11,Cons(13,Cons(25,Cons(45,Cons(48,Cons(60,Nil)))))) || - out == Cons(10,Cons(11,Cons(13,Cons(20,Cons(25,Cons(30,Cons(40,Cons(45,Cons(48,Cons(60,Nil))))))))))) && - (content(out) == content(in1) ++ content(in2)) && isSorted(out) } - } -} diff --git a/testcases/synthesis/oopsla2013/SparseVector/Batch.scala b/testcases/synthesis/oopsla2013/SparseVector/Batch.scala deleted file mode 100644 index f7b603cd1e271888f22fbc790bed359c114ffd05..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SparseVector/Batch.scala +++ /dev/null @@ -1,64 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SparseVector { - sealed abstract class SparseVector - case class Cons(index: Int, value : Int, tail: SparseVector) extends SparseVector - case object Nil extends SparseVector - - sealed abstract class Option - case class Some(v: Int) extends Option - case object None extends Option - - def size(sv: SparseVector): Int = { - sv match { - case Cons(i, v, t) => - 1 + size(t) - case Nil => - 0 - } - } ensuring { _ >= 0 } - - def isDefined(o: Option) = o match { - case Some(v) => true - case None => false - } - - def valueOf(o: Option) = o match { - case Some(v) => v - case None => -42 - } - - def values(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - values(t) ++ Set(v) - case Nil => - Set() - } - - def indices(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - indices(t) ++ Set(i) - case Nil => - Set() - } - - def invariant(sv: SparseVector): Boolean = sv match { - case Cons(i1, v1, t1 @ Cons(i2, v2, t2)) => - (i1 < i2) && invariant(t1) - case _ => true - } - - def set(sv: SparseVector, at: Int, newV: Int): SparseVector = choose { - (res: SparseVector) => invariant(sv) && (values(res) contains newV) && invariant(res) && (indices(res) == indices(sv) ++ Set(at)) - } - - def delete(sv: SparseVector, at: Int): SparseVector = choose { - (res: SparseVector) => invariant(sv) && (size(res) <= size(sv)) && invariant(res) && (indices(res) == indices(sv) -- Set(at)) - } - - def get(sv: SparseVector, at: Int): Option = choose { - (res: Option) => invariant(sv) && ((indices(sv) contains at) == isDefined(res)) && (!isDefined(res) || (values(sv) contains valueOf(res))) - } -} diff --git a/testcases/synthesis/oopsla2013/SparseVector/Complete.scala b/testcases/synthesis/oopsla2013/SparseVector/Complete.scala deleted file mode 100644 index 8683e0b5a291fde438d4da03f7f72c390ab8d753..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SparseVector/Complete.scala +++ /dev/null @@ -1,115 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SparseVector { - sealed abstract class SparseVector - case class Cons(index: Int, value : Int, tail: SparseVector) extends SparseVector - case object Nil extends SparseVector - - sealed abstract class Option - case class Some(v: Int) extends Option - case object None extends Option - - def size(sv: SparseVector): Int = { - sv match { - case Cons(i, v, t) => - 1 + size(t) - case Nil => - 0 - } - } ensuring { _ >= 0 } - - def isDefined(o: Option) = o match { - case Some(v) => true - case None => false - } - - def valueOf(o: Option) = o match { - case Some(v) => v - case None => -42 - } - - def values(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - values(t) ++ Set(v) - case Nil => - Set() - } - - def indices(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - indices(t) ++ Set(i) - case Nil => - Set() - } - - def invariant(sv: SparseVector): Boolean = sv match { - case Cons(i1, v1, t1 @ Cons(i2, v2, t2)) => - (i1 < i2) && invariant(t1) - case _ => true - } - - def set(sv: SparseVector, at: Int, newV: Int): SparseVector = { - require(invariant(sv)) - - sv match { - case Cons(i, v, t) => - if (i == at) { - Cons(i, newV, t) - } else if (i > at) { - Cons(at, newV, sv) - } else { - Cons(i, v, set(t, at, newV)) - } - case Nil => - Cons(at, newV, Nil) - } - } ensuring { res => (values(res) contains newV) && invariant(res) && (indices(res) == indices(sv) ++ Set(at)) } - - //def set(sv: SparseVector, at: Int, newV: Int): SparseVector = choose { - // (res: SparseVector) => invariant(sv) && (values(res) contains newV) && invariant(res) && (indices(res) == indices(sv) ++ Set(at)) - //} - - def delete(sv: SparseVector, at: Int): SparseVector = { - require(invariant(sv)) - - sv match { - case Cons(i, v, t) => - if (i == at) { - t - } else if (i > at) { - sv - } else { - Cons(i, v, delete(t, at)) - } - case Nil => - Nil - } - } ensuring { res => (size(res) <= size(sv)) && invariant(res) && (indices(res) == indices(sv) -- Set(at)) } - - //def delete(sv: SparseVector, at: Int): SparseVector = choose { - // (res: SparseVector) => invariant(sv) && (size(res) <= size(sv)) && invariant(res) && (indices(res) == indices(sv) -- Set(at)) - //} - - def get(sv: SparseVector, at: Int): Option = { - require(invariant(sv)) - - sv match { - case Cons(i, v, t) => - if (i == at) { - Some(v) - } else if (i > at) { - None - } else { - get(t, at) - } - case Nil => - None - } - } ensuring { res => ((indices(sv) contains at) == isDefined(res)) && (!isDefined(res) || (values(sv) contains valueOf(res))) } - - // def get(sv: SparseVector, at: Int): Option = choose { - // (res: Option) => invariant(sv) && ((indices(sv) contains at) == isDefined(res)) && (!isDefined(res) || (values(sv) contains valueOf(res))) - // } -} diff --git a/testcases/synthesis/oopsla2013/SparseVector/Delete.scala b/testcases/synthesis/oopsla2013/SparseVector/Delete.scala deleted file mode 100644 index 1f94b26352783c27862a8a713a0f2c42111aa98f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SparseVector/Delete.scala +++ /dev/null @@ -1,90 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SparseVector { - sealed abstract class SparseVector - case class Cons(index: Int, value : Int, tail: SparseVector) extends SparseVector - case object Nil extends SparseVector - - sealed abstract class Option - case class Some(v: Int) extends Option - case object None extends Option - - def size(sv: SparseVector): Int = { - sv match { - case Cons(i, v, t) => - 1 + size(t) - case Nil => - 0 - } - } ensuring { _ >= 0 } - - def isDefined(o: Option) = o match { - case Some(v) => true - case None => false - } - - def valueOf(o: Option) = o match { - case Some(v) => v - case None => -42 - } - - def values(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - values(t) ++ Set(v) - case Nil => - Set() - } - - def indices(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - indices(t) ++ Set(i) - case Nil => - Set() - } - - def invariant(sv: SparseVector): Boolean = sv match { - case Cons(i1, v1, t1 @ Cons(i2, v2, t2)) => - (i1 < i2) && invariant(t1) - case _ => true - } - - def set(sv: SparseVector, at: Int, newV: Int): SparseVector = { - require(invariant(sv)) - - sv match { - case Cons(i, v, t) => - if (i == at) { - Cons(i, newV, t) - } else if (i > at) { - Cons(at, newV, sv) - } else { - Cons(i, v, set(t, at, newV)) - } - case Nil => - Cons(at, newV, Nil) - } - } ensuring { res => (values(res) contains newV) && invariant(res) && (indices(res) == indices(sv) ++ Set(at)) } - - // def delete(sv: SparseVector, at: Int): SparseVector = { - // require(invariant(sv)) - - // sv match { - // case Cons(i, v, t) => - // if (i == at) { - // t - // } else if (i > at) { - // sv - // } else { - // Cons(i, v, delete(t, at)) - // } - // case Nil => - // Nil - // } - // } ensuring { res => (size(res) <= size(sv)) && invariant(res) && (indices(res) == indices(sv) -- Set(at)) } - - def delete(sv: SparseVector, at: Int): SparseVector = choose { - (res: SparseVector) => invariant(sv) && (size(res) <= size(sv)) && invariant(res) && (indices(res) == indices(sv) -- Set(at)) - } -} diff --git a/testcases/synthesis/oopsla2013/SparseVector/Get.scala b/testcases/synthesis/oopsla2013/SparseVector/Get.scala deleted file mode 100644 index 53e0c57527b63a7f46cd4121cb32a495050369af..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SparseVector/Get.scala +++ /dev/null @@ -1,107 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SparseVector { - sealed abstract class SparseVector - case class Cons(index: Int, value : Int, tail: SparseVector) extends SparseVector - case object Nil extends SparseVector - - sealed abstract class Option - case class Some(v: Int) extends Option - case object None extends Option - - def size(sv: SparseVector): Int = { - sv match { - case Cons(i, v, t) => - 1 + size(t) - case Nil => - 0 - } - } ensuring { _ >= 0 } - - def isDefined(o: Option) = o match { - case Some(v) => true - case None => false - } - - def valueOf(o: Option) = o match { - case Some(v) => v - case None => -42 - } - - def values(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - values(t) ++ Set(v) - case Nil => - Set() - } - - def indices(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - indices(t) ++ Set(i) - case Nil => - Set() - } - - def invariant(sv: SparseVector): Boolean = sv match { - case Cons(i1, v1, t1 @ Cons(i2, v2, t2)) => - (i1 < i2) && invariant(t1) - case _ => true - } - - def set(sv: SparseVector, at: Int, newV: Int): SparseVector = { - require(invariant(sv)) - - sv match { - case Cons(i, v, t) => - if (i == at) { - Cons(i, newV, t) - } else if (i > at) { - Cons(at, newV, sv) - } else { - Cons(i, v, set(t, at, newV)) - } - case Nil => - Cons(at, newV, Nil) - } - } ensuring { res => (values(res) contains newV) && invariant(res) && (indices(res) == indices(sv) ++ Set(at)) } - - def delete(sv: SparseVector, at: Int): SparseVector = { - require(invariant(sv)) - - sv match { - case Cons(i, v, t) => - if (i == at) { - t - } else if (i > at) { - sv - } else { - Cons(i, v, delete(t, at)) - } - case Nil => - Nil - } - } ensuring { res => (size(res) <= size(sv)) && invariant(res) && (indices(res) == indices(sv) -- Set(at)) } - - // def get(sv: SparseVector, at: Int): Option = { - // require(invariant(sv)) - - // sv match { - // case Cons(i, v, t) => - // if (i == at) { - // Some(v) - // } else if (i > at) { - // None - // } else { - // get(t, at) - // } - // case Nil => - // None - // } - // } ensuring { res => ((indices(sv) contains at) == isDefined(res)) && (!isDefined(res) || (values(sv) contains valueOf(res)) } - - def get(sv: SparseVector, at: Int): Option = choose { - (res: Option) => invariant(sv) && ((indices(sv) contains at) == isDefined(res)) && (!isDefined(res) || (values(sv) contains valueOf(res))) - } -} diff --git a/testcases/synthesis/oopsla2013/SparseVector/Set.scala b/testcases/synthesis/oopsla2013/SparseVector/Set.scala deleted file mode 100644 index 8a5f379ea7231b2fca2171cdc219f4c5b7c68c72..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/SparseVector/Set.scala +++ /dev/null @@ -1,73 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SparseVector { - sealed abstract class SparseVector - case class Cons(index: Int, value : Int, tail: SparseVector) extends SparseVector - case object Nil extends SparseVector - - sealed abstract class Option - case class Some(v: Int) extends Option - case object None extends Option - - def size(sv: SparseVector): Int = { - sv match { - case Cons(i, v, t) => - 1 + size(t) - case Nil => - 0 - } - } ensuring { _ >= 0 } - - def isDefined(o: Option) = o match { - case Some(v) => true - case None => false - } - - def valueOf(o: Option) = o match { - case Some(v) => v - case None => -42 - } - - def values(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - values(t) ++ Set(v) - case Nil => - Set() - } - - def indices(sv: SparseVector): Set[Int] = sv match { - case Cons(i, v, t) => - indices(t) ++ Set(i) - case Nil => - Set() - } - - def invariant(sv: SparseVector): Boolean = sv match { - case Cons(i1, v1, t1 @ Cons(i2, v2, t2)) => - (i1 < i2) && invariant(t1) - case _ => true - } - - // def set(sv: SparseVector, at: Int, newV: Int): SparseVector = { - // require(invariant(sv)) - - // sv match { - // case Cons(i, v, t) => - // if (i == at) { - // Cons(i, newV, t) - // } else if (i > at) { - // Cons(at, newV, sv) - // } else { - // Cons(i, v, set(t, at, newV)) - // } - // case Nil => - // Cons(at, newV, Nil) - // } - // } ensuring { res => (values(res) contains newV) && invariant(res) && (indices(res) == indices(sv) ++ Set(at)) } - - def set(sv: SparseVector, at: Int, newV: Int): SparseVector = choose { - (res: SparseVector) => invariant(sv) && (values(res) contains newV) && invariant(res) && (indices(res) == indices(sv) ++ Set(at)) - } -} diff --git a/testcases/synthesis/oopsla2013/StrictSortedList/Batch.scala b/testcases/synthesis/oopsla2013/StrictSortedList/Batch.scala deleted file mode 100644 index 58d0e8b420e330913701207aa3117ab3b5d754f6..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/StrictSortedList/Batch.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedList { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int) = choose { - (out : List) => - isSorted(in1) && (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - - def delete(in1: List, v: Int) = choose { - (out : List) => - isSorted(in1) && (content(out) == content(in1) -- Set(v)) && isSorted(out) - } - - def union(in1: List, in2: List) = choose { - (out : List) => - isSorted(in1) && isSorted(in2) && (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - - def diff(in1: List, in2: List) = choose { - (out : List) => - isSorted(in1) && isSorted(in2) && (content(out) == content(in1) -- content(in2)) && isSorted(out) - } - -} diff --git a/testcases/synthesis/oopsla2013/StrictSortedList/Complete.scala b/testcases/synthesis/oopsla2013/StrictSortedList/Complete.scala deleted file mode 100644 index fca32e4f17ab84ba708377873129534a00a86805..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/StrictSortedList/Complete.scala +++ /dev/null @@ -1,100 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - //def insert1(in1: List, v: Int) = choose { - // (out : List) => - // isSorted(in1) && (content(out) == content(in1) ++ Set(v)) && isSorted(out) - //} - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - t - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - //def delete(in1: List, v: Int) = choose { - // (out : List) => - // isSorted(in1) && (content(out) == content(in1) -- Set(v)) && isSorted(out) - //} - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - union(t1, insert(in2, h1)) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - //def union(in1: List, in2: List) = choose { - // (out : List) => - // isSorted(in1) && isSorted(in2) && (content(out) == content(in1) ++ content(in2)) && isSorted(out) - //} - - def diff(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in2 match { - case Cons(h2, t2) => - diff(delete(in1, h2), t2) - case Nil => - in1 - } - } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - //def diff(in1: List, in2: List) = choose { - // (out : List) => - // isSorted(in1) && isSorted(in2) && (content(out) == content(in1) -- content(in2)) && isSorted(out) - //} - -} diff --git a/testcases/synthesis/oopsla2013/StrictSortedList/Delete.scala b/testcases/synthesis/oopsla2013/StrictSortedList/Delete.scala deleted file mode 100644 index 3fa6e78c70cf4bb38463eb5b28ffbafec94c7814..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/StrictSortedList/Delete.scala +++ /dev/null @@ -1,65 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Delete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - // def delete(in1: List, v: Int): List = { - // require(isSorted(in1)) - // in1 match { - // case Cons(h,t) => - // if (h < v) { - // Cons(h, delete(t, v)) - // } else if (h == v) { - // t - // } else { - // in1 - // } - // case Nil => - // Nil - // } - // } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def delete(in1: List, v: Int) = { - require(isSorted(in1)) - choose {(out : List) => content(out) == content(in1) -- Set(v) && - isSorted(out) } - } -} diff --git a/testcases/synthesis/oopsla2013/StrictSortedList/Diff.scala b/testcases/synthesis/oopsla2013/StrictSortedList/Diff.scala deleted file mode 100644 index 31481b52eed0878f1ef3e212d46410a80a6bae9d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/StrictSortedList/Diff.scala +++ /dev/null @@ -1,85 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - t - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def union(in1: List, in2: List): List = { - require(isSorted(in1) && isSorted(in2)) - in1 match { - case Cons(h1, t1) => - union(t1, insert(in2, h1)) - case Nil => - in2 - } - } ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - // def diff(in1: List, in2: List): List = { - // require(isSorted(in1) && isSorted(in2)) - // in2 match { - // case Cons(h2, t2) => - // diff(delete(in1, h2), t2) - // case Nil => - // in1 - // } - // } ensuring { res => content(res) == content(in1) -- content(in2) && isSorted(res) } - - def diff(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose((out : List) => - content(out) == content(in1) -- content(in2) && isSorted(out)) - } -} diff --git a/testcases/synthesis/oopsla2013/StrictSortedList/Insert.scala b/testcases/synthesis/oopsla2013/StrictSortedList/Insert.scala deleted file mode 100644 index d21176df0564636de0c5834e52de19a4ee808e24..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/StrictSortedList/Insert.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - // def insert(in1: List, v: Int): List = { - // require(isSorted(in1)) - // in1 match { - // case Cons(h, t) => - // if (v < h) { - // Cons(v, in1) - // } else if (v == h) { - // in1 - // } else { - // Cons(h, insert(t, v)) - // } - // case Nil => - // Cons(v, Nil) - // } - // } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def insert(in1: List, v: Int) = { - require(isSorted(in1)) - choose((out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out)) - } - -} diff --git a/testcases/synthesis/oopsla2013/StrictSortedList/Union.scala b/testcases/synthesis/oopsla2013/StrictSortedList/Union.scala deleted file mode 100644 index 595b11257f1176f30c7a732e12dd059a8ee43adb..0000000000000000000000000000000000000000 --- a/testcases/synthesis/oopsla2013/StrictSortedList/Union.scala +++ /dev/null @@ -1,76 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case object Nil extends List - - 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) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def delete(in1: List, v: Int): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - t - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - //def union(in1: List, in2: List): List = { - // require(isSorted(in1) && isSorted(in2)) - // in1 match { - // case Cons(h1, t1) => - // union(t1, insert(in2, h1)) - // case Nil => - // in2 - // } - //} ensuring { res => content(res) == content(in1) ++ content(in2) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose( (out : List) => (content(out) == content(in1) ++ content(in2)) && - isSorted(out) - ) - } -} diff --git a/testcases/synthesis/sygus/duration.scala b/testcases/synthesis/sygus/duration.scala deleted file mode 100644 index 06a9b9cd52c0d6a3e1aa5a9280c74bf37791b707..0000000000000000000000000000000000000000 --- a/testcases/synthesis/sygus/duration.scala +++ /dev/null @@ -1,65 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Times { - case class Hour(v: BigInt) { - def isValid = v >= 0// && v < 24 - def toSeconds = v*3600 - } - - case class Minute(v: BigInt) { - def isValid = v >= 0 && v < 60 - def toSeconds = v*60 - } - - case class Second(v: BigInt) { - def isValid = v >= 0 && v < 60 - def toSeconds = v - } - - case class Time(h: Hour, m: Minute, s: Second) { - def isValid = { - h.isValid && m.isValid && s.isValid - } - - def toSeconds = h.toSeconds + m.toSeconds + s.toSeconds - } - - def incTime(t: Time, k: BigInt) = { - choose((tres: Time, seconds: BigInt) => seconds == t.toSeconds && seconds + k == tres.toSeconds && tres.isValid) - } - - def incTimeInlined(h: BigInt, m: BigInt, s: BigInt, inc: BigInt) = { - require( - h >= 0 && - m >= 0 && m < 60 && - s >= 0 && s < 60 && - inc > 0 - ) - - choose { (hres: BigInt, mres: BigInt, sres: BigInt) => - hres >= 0 && - mres >= 0 && mres < 60 && - sres >= 0 && sres < 60 && - ((hres*3600+mres*60+sres) == ((h*3600 + m*60 + s) + inc)) - } - } - - def incTime2(m: BigInt, s: BigInt, inc: BigInt) = { - require( - m >= 0 && - s >= 0 && s < 60 && - inc > 0 - ) - - ???[(BigInt, BigInt)] - - } ensuring { (res: (BigInt, BigInt)) => - val (mres, sres) = res - - mres >= 0 && - sres >= 0 && sres < 60 && - ((mres*60+sres) == ((m*60 + s) + inc)) - } -} diff --git a/testcases/synthesis/sygus/listqueue.scala b/testcases/synthesis/sygus/listqueue.scala deleted file mode 100644 index d3783aceb36127f40030e63af162e5a6053c034f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/sygus/listqueue.scala +++ /dev/null @@ -1,64 +0,0 @@ -import leon._ -import leon.lang._ -import leon.collection._ -import leon.lang.synthesis._ - -object ListQueue { - - case class Queue[T](in: List[T], out: List[T]) { - def toListOut: List[T] = { - out ++ in.reverse - } - - def toListIn: List[T] = { - in ++ out.reverse - } - - def size: BigInt = { - in.size + out.size - } ensuring { - _ >= 0 - } - - def content: Set[T] = { - in.content ++ out.content - } - - - def isEmpty: Boolean = { - - ???[Boolean] - - } ensuring { - res => res == (in == Nil[T]() && out == Nil[T]()) - } - - def enqueue(t: T): Queue[T] = { - - ???[Queue[T]] // Queue(Cons(t, in), out) - - } ensuring { res => - (res.size == size + 1) && - (res.content == content ++ Set(t)) && - (res.toListIn == Cons(t, toListIn)) - } - - def dequeue(): (Queue[T], T) = { - require(in.nonEmpty || out.nonEmpty) - - out match { - case Cons(h, t) => - (Queue(in, t), h) - case Nil() => - Queue(Nil(), in.reverse).dequeue() - } - } ensuring { resAndT => - val res = resAndT._1 - val t = resAndT._2 - - (res.size == size - 1) && - (content contains t) && - (Cons(t, res.toListOut) == toListOut) - } - } -} diff --git a/testcases/synthesis/sygus/max2.scala b/testcases/synthesis/sygus/max2.scala deleted file mode 100644 index aebef892a8f88fa4c24fab16efc65f49cba013a1..0000000000000000000000000000000000000000 --- a/testcases/synthesis/sygus/max2.scala +++ /dev/null @@ -1,9 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - - -object Sort { - def max2(a: BigInt, b: BigInt): BigInt = { - choose((x: BigInt) => x >= a && x >= b && (x == a || x == b)) - } -} diff --git a/testcases/synthesis/sygus/mirror.scala b/testcases/synthesis/sygus/mirror.scala deleted file mode 100644 index 79528809a40cd01ba64e4345f36d2ffecf6b3b1f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/sygus/mirror.scala +++ /dev/null @@ -1,42 +0,0 @@ -import leon._ -import leon.lang._ -import leon.collection._ -import leon.lang.synthesis._ - -object Mirror { - - def inttuple(a: BigInt, b: BigInt): (BigInt, BigInt) = { - ???[(BigInt, BigInt)] - } ensuring { - out => out._1+1 == a && out._2-1 == b - } - - def tuple(a: List[BigInt], b: List[BigInt]): (List[BigInt], List[BigInt]) = { - ???[(List[BigInt], List[BigInt])] - } ensuring { - out => out._1 == a && out._2 == b - } - - def mirror1(a: List[BigInt], b: List[BigInt]): (List[BigInt], List[BigInt]) = { - ???[(List[BigInt], List[BigInt])] - } ensuring { - out => out._1 == b && out._2 == a - } - - def mirror2[T](a: List[T], b: List[T]): (List[T], List[T]) = { - ???[(List[T], List[T])] - } ensuring { - out => out._1 == b && out._2 == a - } - - def transfer(a: List[BigInt], b: List[BigInt]): (List[BigInt], List[BigInt]) = { - ???[(List[BigInt], List[BigInt])] - } ensuring { - out => - (a, b) match { - case (Cons(ah, at), b) => (out._2.head == (ah + 1)) && (out._2.tail == b) - case _ => true - } - } - -} diff --git a/testcases/synthesis/sygus/numerals1.scala b/testcases/synthesis/sygus/numerals1.scala deleted file mode 100644 index a61c7166f5051c9b751d40b172e21d01e5fe989f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/sygus/numerals1.scala +++ /dev/null @@ -1,16 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object Numerals { - abstract class N - case class S(succ: N) extends N - case object Z extends N - - - def plusone(a: N): N = { - choose((x: N) => x match { - case S(succ) => succ == a - case Z => false - }) - } -} diff --git a/testcases/synthesis/sygus/plusone.scala b/testcases/synthesis/sygus/plusone.scala deleted file mode 100644 index 6da98137842ad834fb8f2de7b8a29e76aeb2dacf..0000000000000000000000000000000000000000 --- a/testcases/synthesis/sygus/plusone.scala +++ /dev/null @@ -1,9 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - - -object Sort { - def plusone(a: BigInt): BigInt = { - choose((x: BigInt) => x > a) - } -} diff --git a/testcases/synthesis/synt2016/repair/Compiler/Compiler.scala b/testcases/synthesis/synt2016/repair/Compiler/Compiler.scala deleted file mode 100644 index 4b77a547a378b84aab4378459a5fb5b91f83d8a3..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Compiler/Compiler.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/synthesis/synt2016/repair/Compiler/Compiler1.scala b/testcases/synthesis/synt2016/repair/Compiler/Compiler1.scala deleted file mode 100644 index b1f9bc859cccdc53162b29d3480e5c4519e7cd96..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Compiler/Compiler1.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Neg(desugar(lhs)) // FIXME - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/synthesis/synt2016/repair/Compiler/Compiler2.scala b/testcases/synthesis/synt2016/repair/Compiler/Compiler2.scala deleted file mode 100644 index 1950b679a6d5727bec02a6fe4bf457f1260bc1c7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Compiler/Compiler2.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Literal(0)// FIXME: Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/synthesis/synt2016/repair/Compiler/Compiler3.scala b/testcases/synthesis/synt2016/repair/Compiler/Compiler3.scala deleted file mode 100644 index 367e43b9fcf8e1579dd91ed08a13506184a05532..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Compiler/Compiler3.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(els), desugar(thn)) // FIXME - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/synthesis/synt2016/repair/Compiler/Compiler4.scala b/testcases/synthesis/synt2016/repair/Compiler/Compiler4.scala deleted file mode 100644 index 6323496df930172e84b71bf5c55006eb33767c6a..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Compiler/Compiler4.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(1), Literal(1)) // FIXME should be 0 - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/synthesis/synt2016/repair/Compiler/Compiler5.scala b/testcases/synthesis/synt2016/repair/Compiler/Compiler5.scala deleted file mode 100644 index fdefc6b31d8edabc379968c101b3db2d8513a007..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Compiler/Compiler5.scala +++ /dev/null @@ -1,212 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(1), Literal(1)) // FIMXE - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(els), desugar(thn)) // FIXME - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) - } -} diff --git a/testcases/synthesis/synt2016/repair/Compiler/Compiler6.scala b/testcases/synthesis/synt2016/repair/Compiler/Compiler6.scala deleted file mode 100644 index dc633b1ae3d4d929e262ea44d6466a41ee4babf0..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Compiler/Compiler6.scala +++ /dev/null @@ -1,214 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Trees { - abstract class Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Minus(lhs: Expr, rhs: Expr) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Not(e : Expr) extends Expr - case class Eq(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class BoolLiteral(b : Boolean) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - - -object TypeChecker { - import Trees._ - import Types._ - - def typeOf(e :Expr) : Option[Type] = e match { - case Plus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case Minus(l,r) => (typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(IntType) - case _ => None() - } - case LessThan(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(IntType), Some(IntType)) => Some(BoolType) - case _ => None() - } - case And(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Or(l,r) => ( typeOf(l), typeOf(r)) match { - case (Some(BoolType), Some(BoolType)) => Some(BoolType) - case _ => None() - } - case Not(e) => typeOf(e) match { - case Some(BoolType) => Some(BoolType) - case _ => None() - } - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case (Some(t1), Some(t2)) if t1 == t2 => Some(BoolType) - case _ => None() - } - case Ite(c, th, el) => (typeOf(c), typeOf(th), typeOf(el)) match { - case (Some(BoolType), Some(t1), Some(t2)) if t1 == t2 => Some(t1) - case _ => None() - } - case IntLiteral(_) => Some(IntType) - case BoolLiteral(_) => Some(BoolType) - } - - def typeChecks(e : Expr) = typeOf(e).isDefined -} - - -object Semantics { - import Trees._ - import Types._ - import TypeChecker._ - - def semI(t : Expr) : BigInt = { - require( typeOf(t) == ( Some(IntType) : Option[Type] )) - t match { - case Plus(lhs , rhs) => semI(lhs) + semI(rhs) - case Minus(lhs , rhs) => semI(lhs) - semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semI(thn) else semI(els) - case IntLiteral(v) => v - } - } - - def semB(t : Expr) : Boolean = { - require( (Some(BoolType): Option[Type]) == typeOf(t)) - t match { - case And(lhs, rhs ) => semB(lhs) && semB(rhs) - case Or(lhs , rhs ) => semB(lhs) || semB(rhs) - case Not(e) => !semB(e) - case LessThan(lhs, rhs) => semI(lhs) < semI(rhs) - case Ite(cond, thn, els) => - if (semB(cond)) semB(thn) else semB(els) - case Eq(lhs, rhs) => (typeOf(lhs), typeOf(rhs)) match { - case ( Some(IntType), Some(IntType) ) => semI(lhs) == semI(rhs) - case ( Some(BoolType), Some(BoolType) ) => semB(lhs) == semB(rhs) - } - case BoolLiteral(b) => b - } - } - - def b2i(b : Boolean): BigInt = if (b) 1 else 0 - - @induct - def semUntyped( t : Expr) : BigInt = { t match { - case Plus (lhs, rhs) => semUntyped(lhs) + semUntyped(rhs) - case Minus(lhs, rhs) => semUntyped(lhs) - semUntyped(rhs) - case And (lhs, rhs) => if (semUntyped(lhs)!=0) semUntyped(rhs) else BigInt(0) - case Or(lhs, rhs ) => - if (semUntyped(lhs) == 0) semUntyped(rhs) else BigInt(1) - case Not(e) => - b2i(semUntyped(e) == 0) - case LessThan(lhs, rhs) => - b2i(semUntyped(lhs) < semUntyped(rhs)) - case Eq(lhs, rhs) => - b2i(semUntyped(lhs) == semUntyped(rhs)) - case Ite(cond, thn, els) => - if (semUntyped(cond) == 0) semUntyped(els) else semUntyped(thn) - case IntLiteral(v) => v - case BoolLiteral(b) => b2i(b) - }} ensuring { res => typeOf(t) match { - case Some(IntType) => res == semI(t) - case Some(BoolType) => res == b2i(semB(t)) - case None() => true - }} - -} - - -object Desugar { - import Types._ - import TypeChecker._ - import Semantics.b2i - - abstract class SimpleE - case class Plus(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Neg(arg : SimpleE) extends SimpleE - case class Ite(cond : SimpleE, thn : SimpleE, els : SimpleE) extends SimpleE - case class Eq(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class LessThan(lhs : SimpleE, rhs : SimpleE) extends SimpleE - case class Literal(i : BigInt) extends SimpleE - - @induct - def desugar(e : Trees.Expr) : SimpleE = { e match { - case Trees.Plus (lhs, rhs) => Plus(desugar(lhs), desugar(rhs)) - case Trees.Minus(lhs, rhs) => Plus(desugar(lhs), Neg(desugar(rhs))) - case Trees.LessThan(lhs, rhs) => LessThan(desugar(lhs), desugar(rhs)) - case Trees.And (lhs, rhs) => Ite(desugar(lhs), desugar(rhs), Literal(0)) - case Trees.Or (lhs, rhs) => Ite(desugar(lhs), Literal(1), desugar(rhs)) - case Trees.Not(e) => Ite(desugar(e), Literal(0), Literal(1)) - case Trees.Eq(lhs, rhs) => - Eq(desugar(lhs), desugar(rhs)) - case Trees.Ite(cond, thn, els) => Ite(desugar(cond), desugar(thn), desugar(els)) - case Trees.IntLiteral(v) => Literal(v) - case Trees.BoolLiteral(b) => Literal(b2i(b)) - }} ensuring { res => - sem(res) == Semantics.semUntyped(e) - } - - def sem(e : SimpleE) : BigInt = e match { - case Plus (lhs, rhs) => sem(lhs) + sem(rhs) - case Ite(cond, thn, els) => if (sem(cond) != 0) sem(thn) else sem(els) - case Neg(arg) => -sem(arg) - case Eq(lhs,rhs) => b2i(sem(lhs) == sem(rhs)) - case LessThan(lhs, rhs) => b2i(sem(lhs) < sem(rhs)) - case Literal(i) => i - } - -} - -object Evaluator { - import Trees._ - - def bToi(b: Boolean): BigInt = if (b) 1 else 0 - def iTob(i: BigInt) = i == 1 - - def eval(e: Expr): BigInt = { - e match { - case Plus(lhs, rhs) => eval(lhs) + eval(rhs) - case Minus(lhs, rhs) => eval(lhs) + eval(rhs) - case LessThan(lhs, rhs) => bToi(eval(lhs) < eval(rhs)) - case And(lhs, rhs) => bToi(iTob(eval(lhs)) && iTob(eval(rhs))) - case Or(lhs, rhs) => bToi(iTob(eval(lhs)) || iTob(eval(rhs))) - case Not(e) => bToi(!iTob(eval(e))) - case Eq(lhs, rhs) => bToi(eval(lhs) == eval(rhs)) - case Ite(cond, thn, els) => if (iTob(eval(cond))) eval(thn) else eval(els) - case IntLiteral(v) => v - case BoolLiteral(b) => bToi(b) - } - } -} - -object Simplifier { - import Trees._ - import Evaluator._ - - @induct - def simplify(e: Expr): Expr = { - e match { - case And(BoolLiteral(false), _) => BoolLiteral(false) - case Or(BoolLiteral(true), _) => BoolLiteral(true) - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a-b) // FIXME - case Not(Not(Not(a))) => Not(a) - case e => e - } - } ensuring { - res => eval(res) == eval(e) && ((e, res) passes { - case Plus(IntLiteral(BigInt(0)), IntLiteral(a)) => IntLiteral(a) - }) - } -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap.scala b/testcases/synthesis/synt2016/repair/Heap/Heap.scala deleted file mode 100644 index 7b70693c77dcee60b8998b7b76ab9d3c3acddc26..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value: BigInt, left: Heap, right: Heap) extends Heap - - def max(i1: BigInt, i2: BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap10.scala b/testcases/synthesis/synt2016/repair/Heap/Heap10.scala deleted file mode 100644 index c27bc93507b847bb6af22200fc2b3cf3e13f0511..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap10.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h1 // FIXME: swapped these cases - case (_, Leaf()) => h2 // FIXME - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap3.scala b/testcases/synthesis/synt2016/repair/Heap/Heap3.scala deleted file mode 100644 index 8e3013399534679c58221bd4d5547a14a76d9b57..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap3.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) // FIXME swapped the branches - makeN(v2, l2, merge(h1, r2)) - else - makeN(v1, l1, merge(r1, h2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap4.scala b/testcases/synthesis/synt2016/repair/Heap/Heap4.scala deleted file mode 100644 index 46c78c8fd25dc5519aa6d8bddba257eb1e7c39e2..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap4.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h2 // FIXME should be h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap5.scala b/testcases/synthesis/synt2016/repair/Heap/Heap5.scala deleted file mode 100644 index 4e963e3bd63b913bb960dc0640f52aa2d9150723..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap5.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 <= v2) // FIXME should be >= - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap6.scala b/testcases/synthesis/synt2016/repair/Heap/Heap6.scala deleted file mode 100644 index d284bb3804496fddadd8edced8c8fd98ddf5217c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap6.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l1, merge(h1, r2)) // FIXME: l1 instead of l2 - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap7.scala b/testcases/synthesis/synt2016/repair/Heap/Heap7.scala deleted file mode 100644 index ed4d189ce0f4c8dd78327f707627c1e9319b9187..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap7.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 + v2 > 0) // FIXME Totally wrong - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap8.scala b/testcases/synthesis/synt2016/repair/Heap/Heap8.scala deleted file mode 100644 index 2564dceb8678e25dafabdc81b2dee125f63928ea..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap8.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank) - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element + 1, Leaf(), Leaf()), heap) // FIXME: unneeded +1 - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/Heap/Heap9.scala b/testcases/synthesis/synt2016/repair/Heap/Heap9.scala deleted file mode 100644 index 4f5f4f3986d1daabb3ce3e9e94440ebe9235f7b8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Heap/Heap9.scala +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ -import leon.collection._ - -object Heaps { - - sealed abstract class Heap { - val rank : BigInt = this match { - case Leaf() => 0 - case Node(_, l, r) => - 1 + max(l.rank, r.rank) - } - def content : Set[BigInt] = this match { - case Leaf() => Set[BigInt]() - case Node(v,l,r) => l.content ++ Set(v) ++ r.content - } - } - case class Leaf() extends Heap - case class Node(value:BigInt, left: Heap, right: Heap) extends Heap - - def max(i1 : BigInt, i2 : BigInt) = if (i1 >= i2) i1 else i2 - - def hasHeapProperty(h : Heap) : Boolean = h match { - case Leaf() => true - case Node(v, l, r) => - ( l match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) && - ( r match { - case Leaf() => true - case n@Node(v2,_,_) => v >= v2 && hasHeapProperty(n) - }) - } - - def hasLeftistProperty(h: Heap) : Boolean = h match { - case Leaf() => true - case Node(_,l,r) => - hasLeftistProperty(l) && - hasLeftistProperty(r) && - l.rank >= r.rank - } - - def heapSize(t: Heap): BigInt = { t match { - case Leaf() => BigInt(0) - case Node(v, l, r) => heapSize(l) + 1 + heapSize(r) - }} ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require( - hasLeftistProperty(h1) && hasLeftistProperty(h2) && - hasHeapProperty(h1) && hasHeapProperty(h2) - ) - (h1,h2) match { - case (Leaf(), _) => h2 - case (_, Leaf()) => h1 - case (Node(v1, l1, r1), Node(v2, l2, r2)) => - if(v1 >= v2) - makeN(v1, l1, merge(r1, h2)) - else - makeN(v2, l2, merge(h1, r2)) - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - h1.content ++ h2.content == res.content - } - - private def makeN(value: BigInt, left: Heap, right: Heap) : Heap = { - require( - hasLeftistProperty(left) && hasLeftistProperty(right) - ) - if(left.rank >= right.rank + 42) // FIXME unneeded constant - Node(value, left, right) - else - Node(value, right, left) - } ensuring { res => - hasLeftistProperty(res) } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap) && hasHeapProperty(heap)) - - merge(Node(element, Leaf(), Leaf()), heap) - - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) && - heapSize(res) == heapSize(heap) + 1 && - res.content == heap.content ++ Set(element) - } - - def findMax(h: Heap) : Option[BigInt] = { - h match { - case Node(m,_,_) => Some(m) - case Leaf() => None() - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h) && hasHeapProperty(h)) - h match { - case Node(_,l,r) => merge(l, r) - case l => l - } - } ensuring { res => - hasLeftistProperty(res) && hasHeapProperty(res) - } - -} diff --git a/testcases/synthesis/synt2016/repair/List/List.scala b/testcases/synthesis/synt2016/repair/List/List.scala deleted file mode 100644 index 043cd86ad8e600434adb9933d984d8e7a679fa43..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List.scala +++ /dev/null @@ -1,421 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List1.scala b/testcases/synthesis/synt2016/repair/List/List1.scala deleted file mode 100644 index b2802d5f5135b8aadecaad999b1d7e00b97ae2c4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List1.scala +++ /dev/null @@ -1,419 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s-1, e)) // FIXME should be s - }} ensuring { res => - (s > 0) ==> (res.size == this.size + s && res.contains(e)) - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List10.scala b/testcases/synthesis/synt2016/repair/List/List10.scala deleted file mode 100644 index 81cf37c6b32b5b70c095c81efe6d94d14da7c8b4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List10.scala +++ /dev/null @@ -1,424 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(3) + t.size //FIXME - }) ensuring { (this, _) passes { - case Cons(_, Nil()) => 1 - case Nil() => 0 - }} - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil[T]() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil[T]() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil[T]() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List11.scala b/testcases/synthesis/synt2016/repair/List/List11.scala deleted file mode 100644 index 73c76fecc8acfb2d0719e73e694474a8158f0b9c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List11.scala +++ /dev/null @@ -1,430 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } - - def sum(l: List[BigInt]): BigInt = { l match { - case Nil() => BigInt(0) - case Cons(x, xs) => BigInt(1) + sum(xs) // FIXME - }} ensuring { (l, _) passes { - case Cons(a, Nil()) => a - case Cons(a, Cons(b, Nil())) => a + b - }} - -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List12.scala b/testcases/synthesis/synt2016/repair/List/List12.scala deleted file mode 100644 index 2f8afafd14d3665a51747ab5742c1821183c5823..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List12.scala +++ /dev/null @@ -1,422 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = { this match { - case Cons(h, t) => - if (e == h) { - t // FIXME missing rec. call - } else { - Cons(h, t - e) - } - case Nil() => - Nil[T]() - }} ensuring { _.content == this.content -- Set(e) } - - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil[T]() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil[T]() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List13.scala b/testcases/synthesis/synt2016/repair/List/List13.scala deleted file mode 100644 index 1093efc3dc951ee8307c2257d8dcec2d154c9ecd..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List13.scala +++ /dev/null @@ -1,429 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = { - require(i >= 0) - (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - if (i == 0) { - Cons[T](h, t) - } else { - t.drop(i) // FIXME Should be -1 - } - } - } ensuring { (res: List[T]) => - ((this, i), res) passes { - case (Cons(a, Cons(b, Nil())), BigInt(1)) => Cons(b, Nil()) - case (Cons(a, Cons(b, Nil())), BigInt(2)) => Nil() - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List2.scala b/testcases/synthesis/synt2016/repair/List/List2.scala deleted file mode 100644 index d035e3933b6d509cf6535e850997daa166260b60..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List2.scala +++ /dev/null @@ -1,424 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => xs ++ that // FIXME forgot x - }) ensuring { res => - (res.content == this.content ++ that.content) && - (res.size == this.size + that.size) - } - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List3.scala b/testcases/synthesis/synt2016/repair/List/List3.scala deleted file mode 100644 index 7ab14a218574d20a17379ac6cfb4aa60f48dbda3..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List3.scala +++ /dev/null @@ -1,421 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => this // FIXME forgot t - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List4.scala b/testcases/synthesis/synt2016/repair/List/List4.scala deleted file mode 100644 index 1ee180b3331e9cc51df34207b8ab5b6fec9b710b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List4.scala +++ /dev/null @@ -1,428 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = { - (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - // FIXME - if (i != 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - } ensuring { ((this, i), _) passes { - case (Cons(_, Nil()), BigInt(42)) => Nil() - case (l@Cons(_, _), BigInt(0)) => l - case (Cons(a, Cons(b, Nil())), BigInt(1)) => Cons(b, Nil()) - }} - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List5.scala b/testcases/synthesis/synt2016/repair/List/List5.scala deleted file mode 100644 index f13f91da3d55d7cdcf0eb0d3ef41027e1a8e94d8..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List5.scala +++ /dev/null @@ -1,424 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = { this match { - case Nil() => Nil[T]() - case Cons(h, t) => - val r = t.replace(from, to) - if (h != from) { // FIXME - Cons(to, r) - } else { - Cons(h, r) - } - }} ensuring { res => - (((this.content -- Set(from)) ++ (if (this.content contains from) Set(to) else Set[T]())) == res.content) && - res.size == this.size - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List6.scala b/testcases/synthesis/synt2016/repair/List/List6.scala deleted file mode 100644 index 7ccf9ef721afe93f8276f9dc9cea65b1971d5a35..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List6.scala +++ /dev/null @@ -1,425 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => - if (h == e) { - Some(0) - } else { - t.find(e) match { - case None() => None() - case Some(i) => Some(i+1) - } - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = { this match { - case Cons(h, t) => - if (h == e) { - t.count(e) // FIXME missing +1 - } else { - t.count(e) - } - case Nil() => - BigInt(0) - }} ensuring {((this, e), _) passes { - case (Cons(a, Cons(b, Cons(a1, Cons(b2, Nil())))), a2) if a == a1 && a == a2 && b != a2 && b2 != a2 => 2 - case (Cons(a, Cons(b, Nil())), c) if a != c && b != c => 0 - }} - - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List7.scala b/testcases/synthesis/synt2016/repair/List/List7.scala deleted file mode 100644 index 41972f4cefffa0bd63245856b2d31b0cfe241c10..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List7.scala +++ /dev/null @@ -1,427 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = { this match { - case Nil() => None[BigInt]() - case Cons(h, t) => - if (h == e) { - Some(BigInt(0)) - } else { - t.find(e) match { - case None() => None[BigInt]() - case Some(i) => Some(i) // FIXME forgot +1 - } - } - }} ensuring { res => - if (this.content contains e) { - res.isDefined && this.size > res.get && this.apply(res.get) == e && res.get >= 0 - } else { - res.isEmpty - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List8.scala b/testcases/synthesis/synt2016/repair/List/List8.scala deleted file mode 100644 index 02f5294c26e7f3b4f29e307db07186927bfff82c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List8.scala +++ /dev/null @@ -1,427 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = { this match { - case Nil() => None[BigInt]() - case Cons(h, t) => - if (h == e) { - Some(BigInt(0)) - } else { - t.find(e) match { - case None() => None[BigInt]() - case Some(i) => Some(i+2) // FIXME +1 - } - } - }} ensuring { res => - if (this.content contains e) { - res.isDefined && this.size > res.get && this.apply(res.get) == e && res.get >= 0 - } else { - res.isEmpty - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/List/List9.scala b/testcases/synthesis/synt2016/repair/List/List9.scala deleted file mode 100644 index 104e2ecabdfa0ac8bef8cc179ff68acc1a7c6ccc..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/List/List9.scala +++ /dev/null @@ -1,427 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.custom - -import leon._ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -sealed abstract class List[T] { - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => BigInt(1) + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { res => res == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => (res.content == this.content ++ that.content) && (res.size == this.size + that.size)} - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == 0) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Nil() - } else { - Cons(h, t.take(i-1)) - } - } - - def drop(i: BigInt): List[T] = (this, i) match { - case (Nil(), _) => Nil() - case (Cons(h, t), i) => - if (i == 0) { - Cons(h, t) - } else { - t.drop(i-1) - } - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(from < to && to < size && from >= 0) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == 0) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case (_) => - Nil() - } - - def -(e: T): List[T] = this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil() - } - - def --(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil() - } - - def &(that: List[T]): List[T] = this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil() - } - - def pad(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().pad(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.pad(s, e)) - }} ensuring { res => - ((this,s,e), res) passes { - case (Cons(a,Nil()), BigInt(2), x) => Cons(a, Cons(x, Cons(x, Nil()))) - } - } - - def find(e: T): Option[BigInt] = { this match { - case Nil() => None[BigInt]() - case Cons(h, t) => - if (h != e) { // FIXME - Some(BigInt(0)) - } else { - t.find(e) match { - case None() => None[BigInt]() - case Some(i) => Some(i + 1) - } - } - }} ensuring { res => - if (this.content contains e) { - res.isDefined && this.size > res.get && this.apply(res.get) == e && res.get >= 0 - } else { - res.isEmpty - } - } - - def init: List[T] = (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - case Nil() => - Nil[T]() - }) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) ) - - def lastOption: Option[T] = this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None() - } - - def firstOption: Option[T] = this match { - case Cons(h, t) => - Some(h) - case Nil() => - None() - } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def count(e: T): BigInt = this match { - case Cons(h, t) => - if (h == e) { - 1 + t.count(e) - } else { - t.count(e) - } - case Nil() => - 0 - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == 0) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == 0) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size+s) - } else { - val s2 = s % size - drop(s2) ++ take(s2) - } - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = ??? -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==0) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds -} diff --git a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort.scala b/testcases/synthesis/synt2016/repair/MergeSort/MergeSort.scala deleted file mode 100644 index 1ce4210a52bbe53e911660e9c5cab4cb5dbbaf6c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - Cons(h2, merge(l1, t2)) - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort1.scala b/testcases/synthesis/synt2016/repair/MergeSort/MergeSort1.scala deleted file mode 100644 index 340dfbc46077306b64752e73cebeb725ef40a781..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort1.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (rec1, Cons(b, rec2)) // FIXME: Forgot a - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - Cons(h2, merge(l1, t2)) - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort2.scala b/testcases/synthesis/synt2016/repair/MergeSort/MergeSort2.scala deleted file mode 100644 index 5c186eca76861f679e67e046c987bebd2951ac97..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort2.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - Cons(h1, merge(l1, t2)) // FIXME: h1 -> h2 - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort3.scala b/testcases/synthesis/synt2016/repair/MergeSort/MergeSort3.scala deleted file mode 100644 index ec37db65c053e3ae3db8871640f516747b7da08d..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort3.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 >= h2) // FIXME Condition inverted - Cons(h1, merge(t1, l2)) - else - Cons(h2, merge(l1, t2)) - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort4.scala b/testcases/synthesis/synt2016/repair/MergeSort/MergeSort4.scala deleted file mode 100644 index 5c3479844d213bf8617f72f9e5dd6aec127f59b2..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort4.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - merge(l1, t2) // FIXME: missing h2 - case (Nil(), _) => l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort5.scala b/testcases/synthesis/synt2016/repair/MergeSort/MergeSort5.scala deleted file mode 100644 index 7746d23c7fa58e3e3c60c7ff4e9fe2c62fc8f3a9..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/MergeSort/MergeSort5.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.collection._ - -object MergeSort { - - def split(l : List[BigInt]) : (List[BigInt],List[BigInt]) = { l match { - case Cons(a, Cons(b, t)) => - val (rec1, rec2) = split(t) - (Cons(a, rec1), Cons(b, rec2)) - case other => (other, Nil[BigInt]()) - }} ensuring { res => - val (l1, l2) = res - l1.size >= l2.size && - l1.size <= l2.size + 1 && - l1.size + l2.size == l.size && - l1.content ++ l2.content == l.content - } - - def isSorted(l : List[BigInt]) : Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1 : List[BigInt], l2 : List[BigInt]) : List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Cons(h1, t1), Cons(h2,t2)) => - if (h1 <= h2) - Cons(h1, merge(t1, l2)) - else - Cons(h2, merge(l1, t2)) - case (Nil(), _) => l1 // FIXME should be l2 - case (_, Nil()) => l1 - } - } ensuring { res => - isSorted(res) && - res.size == l1.size + l2.size && - res.content == l1.content ++ l2.content - } - - def mergeSort(l : List[BigInt]) : List[BigInt] = { l match { - case Nil() => l - case Cons(_, Nil()) => l - case other => - val (l1, l2) = split(other) - merge(mergeSort(l1), mergeSort(l2)) - }} ensuring { res => - isSorted(res) && - res.content == l.content && - res.size == l.size - } -} - - - diff --git a/testcases/synthesis/synt2016/repair/Numerical/Numerical.scala b/testcases/synthesis/synt2016/repair/Numerical/Numerical.scala deleted file mode 100644 index bad9160654675694afd68519089fcf1d0d5b35a3..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Numerical/Numerical.scala +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ -import leon.annotation._ - -object Numerical { - def power(base: BigInt, p: BigInt): BigInt = { - require(p >= BigInt(0)) - if (p == BigInt(0)) { - BigInt(1) - } else if (p%BigInt(2) == BigInt(0)) { - power(base*base, p/BigInt(2)) - } else { - base*power(base, p-BigInt(1)) - } - } ensuring { - res => ((base, p), res) passes { - case (_, BigInt(0)) => BigInt(1) - case (b, BigInt(1)) => b - case (BigInt(2), BigInt(7)) => BigInt(128) - case (BigInt(2), BigInt(10)) => BigInt(1024) - } - } - - def gcd(a: BigInt, b: BigInt): BigInt = { - require(a > BigInt(0) && b > BigInt(0)); - - if (a == b) { - a - } else if (a > b) { - gcd(a-b, b) - } else { - gcd(a, b-a) - } - } ensuring { - res => (a%res == BigInt(0)) && (b%res == BigInt(0)) && (((a,b), res) passes { - case (BigInt(468), BigInt(24)) => BigInt(12) - }) - } - - def moddiv(a: BigInt, b: BigInt): (BigInt, BigInt) = { - require(a >= BigInt(0) && b > BigInt(0)); - if (b > a) { - (a, BigInt(0)) - } else { - val (r1, r2) = moddiv(a-b, b) - (r1, r2+1) - } - } ensuring { - res => b*res._2 + res._1 == a - } - -} diff --git a/testcases/synthesis/synt2016/repair/Numerical/Numerical3.scala b/testcases/synthesis/synt2016/repair/Numerical/Numerical3.scala deleted file mode 100644 index 593bbd604d0aa1d2c8080cba1c2cd4fafb28132a..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/Numerical/Numerical3.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ -import leon.annotation._ - -object Numerical { - def power(base: BigInt, p: BigInt): BigInt = { - require(p >= BigInt(0)) - if (p == BigInt(0)) { - BigInt(1) - } else if (p%BigInt(2) == BigInt(0)) { - power(base*base, p/BigInt(2)) - } else { - base*power(base, p-BigInt(1)) - } - } ensuring { - res => ((base, p), res) passes { - case (_, BigInt(0)) => BigInt(1) - case (b, BigInt(1)) => b - case (BigInt(2), BigInt(7)) => BigInt(128) - case (BigInt(2), BigInt(10)) => BigInt(1024) - } - } - - def gcd(a: BigInt, b: BigInt): BigInt = { - require(a > BigInt(0) && b > BigInt(0)); - - if (a == b) { - a - } else if (a > b) { - gcd(a-b, b) - } else { - gcd(a, b-a) - } - } ensuring { - res => (a%res == BigInt(0)) && (b%res == BigInt(0)) && (((a,b), res) passes { - case (BigInt(468), BigInt(24)) => BigInt(12) - }) - } - - def moddiv(a: BigInt, b: BigInt): (BigInt, BigInt) = { - require(a >= BigInt(0) && b > BigInt(0)); - if (b > a) { - (BigInt(1), BigInt(0)) // fixme: should be (a, BigInt(0)) - } else { - val (r1, r2) = moddiv(a-b, b) - (r1, r2+1) - } - } ensuring { - res => b*res._2 + res._1 == a - } -} diff --git a/testcases/synthesis/synt2016/repair/PropLogic/PropLogic.scala b/testcases/synthesis/synt2016/repair/PropLogic/PropLogic.scala deleted file mode 100644 index a03dd35b47d7b9abed256a13f9168c8afe666ff0..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/PropLogic/PropLogic.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => nnf(e) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/synthesis/synt2016/repair/PropLogic/PropLogic1.scala b/testcases/synthesis/synt2016/repair/PropLogic/PropLogic1.scala deleted file mode 100644 index a27d3afe5d0e20668e72ec654c91714bc0aa88a1..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/PropLogic/PropLogic1.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => e // FIXME missing nnf - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/synthesis/synt2016/repair/PropLogic/PropLogic5.scala b/testcases/synthesis/synt2016/repair/PropLogic/PropLogic5.scala deleted file mode 100644 index e89e2c5ae2cfda30e73743aab932f980a95fa46f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/PropLogic/PropLogic5.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs : Formula, rhs : Formula) extends Formula - case class Or(lhs : Formula, rhs : Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Const(v: Boolean) extends Formula - case class Literal(id: BigInt) extends Formula - - def size(f : Formula) : BigInt = { f match { - case And(l,r) => 1 + size(l) + size(r) - case Or(l,r) => 1 + size(l) + size(r) - case Not(e) => 1 + size(e) - case _ => BigInt(1) - }} ensuring { _ >= 0 } - - def eval(formula: Formula)(implicit trueVars : Set[BigInt]): Boolean = formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Const(v) => v - case Literal(id) => trueVars contains id - } - - def nnf(formula : Formula) : Formula = { formula match { - case Not(And(lhs,rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs,rhs)) => formula//FIXME And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Const(v)) => Const(!v) - case Not(Not(e)) => nnf(e) - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case other => other - }} ensuring { res => - isNNF(res) - } - - def isNNF(f : Formula) : Boolean = f match { - case Not(Literal(_)) => true - case Not(_) => false - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case _ => true - } - - -} diff --git a/testcases/synthesis/synt2016/repair/runTests.sh b/testcases/synthesis/synt2016/repair/runTests.sh deleted file mode 100755 index 46bd02acc15726240e1afcbb7f75785cb5326b2b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/repair/runTests.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash -log=repairs.last -summaryLog=repairs.log -fullLog=fullLog.log - -echo -n "" > $log; -echo -n "" > "repairs.table"; - - -echo "################################" >> $summaryLog -echo "#" `hostname` >> $summaryLog -echo "#" `date +"%d.%m.%Y %T"` >> $summaryLog -echo "#" `git log -1 --pretty=format:"%h - %cd"` >> $summaryLog -echo "################################" >> $summaryLog -echo "# Category, File, function, p.S, fuS, foS, Tms, Fms, Rms, verif?" >> $summaryLog - -#All benchmarks: - -echo "=====================================================================" >> repair-report.txt - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/synthesis/synt2016/repair/Compiler/Compiler1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/synthesis/synt2016/repair/Compiler/Compiler2.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/synthesis/synt2016/repair/Compiler/Compiler3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/synthesis/synt2016/repair/Compiler/Compiler4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=desugar testcases/synthesis/synt2016/repair/Compiler/Compiler5.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=simplify testcases/synthesis/synt2016/repair/Compiler/Compiler6.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/Heap/Heap3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/Heap/Heap4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/Heap/Heap5.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/Heap/Heap6.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/Heap/Heap7.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/Heap/Heap10.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=insert testcases/synthesis/synt2016/repair/Heap/Heap8.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=makeN testcases/synthesis/synt2016/repair/Heap/Heap9.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=nnf testcases/synthesis/synt2016/repair/PropLogic/PropLogic1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=nnf testcases/synthesis/synt2016/repair/PropLogic/PropLogic5.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=pad testcases/synthesis/synt2016/repair/List/List1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=++ testcases/synthesis/synt2016/repair/List/List2.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=:+ testcases/synthesis/synt2016/repair/List/List3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --functions=replace testcases/synthesis/synt2016/repair/List/List5.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=count testcases/synthesis/synt2016/repair/List/List6.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=find testcases/synthesis/synt2016/repair/List/List7.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=find testcases/synthesis/synt2016/repair/List/List8.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=60 --functions=find testcases/synthesis/synt2016/repair/List/List9.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=size testcases/synthesis/synt2016/repair/List/List10.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=sum testcases/synthesis/synt2016/repair/List/List11.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=- testcases/synthesis/synt2016/repair/List/List12.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --functions=drop testcases/synthesis/synt2016/repair/List/List4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=drop testcases/synthesis/synt2016/repair/List/List13.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=moddiv testcases/synthesis/synt2016/repair/Numerical/Numerical3.scala | tee -a $fullLog - -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=split testcases/synthesis/synt2016/repair/MergeSort/MergeSort1.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/MergeSort/MergeSort2.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/MergeSort/MergeSort3.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/MergeSort/MergeSort4.scala | tee -a $fullLog -./leon --debug=report --repair --timeout=30 --solvers=fairz3,enum --functions=merge testcases/synthesis/synt2016/repair/MergeSort/MergeSort5.scala | tee -a $fullLog - -# Average results -#cat $log >> $summaryLog -#awk '{ total1 += $7; total2 += $8; total3 += $9; count++ } END { printf "#%74s Avg: %5d, %5d, %5d\n\n", "", total1/count, total2/count, total3/count }' $log >> $summaryLog - diff --git a/testcases/synthesis/synt2016/synthesis/AddressBook/Make.scala b/testcases/synthesis/synt2016/synthesis/AddressBook/Make.scala deleted file mode 100644 index 612effe382140cfc87bd0c12d791c4de9ddfae8e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/AddressBook/Make.scala +++ /dev/null @@ -1,66 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object AddressBookMake { - - case class Address[A](info: A, priv: Boolean) - - sealed abstract class AddressList[A] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(head, tail) => BigInt(1) + tail.size - } - } ensuring { res => res >= 0 } - - def content: Set[Address[A]] = this match { - case Nil() => Set[Address[A]]() - case Cons(addr, l1) => Set(addr) ++ l1.content - } - } - - case class Cons[A](a: Address[A], tail: AddressList[A]) extends AddressList[A] - case class Nil[A]() extends AddressList[A] - - def allPersonal[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) allPersonal(l1) - else false - } - - def allBusiness[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook[A](business: AddressList[A], personal: AddressList[A]) { - def size: BigInt = business.size + personal.size - - def content: Set[Address[A]] = business.content ++ personal.content - - def invariant = { - allPersonal(personal) && allBusiness(business) - } - } - - def makeAddressBook[A](as: AddressList[A]): AddressBook[A] = { - choose( (res: AddressBook[A]) => res.content == as.content && res.invariant ) - - /* as match { - case Nil() => AddressBook[A](Nil[A](), Nil[A]()) - case Cons(x, xs) => - val AddressBook(b, p) = makeAddressBook(xs) - if(x.priv) AddressBook(b, Cons(x, p)) - else AddressBook(Cons(x, b), p) - } - - } ensuring { - res => res.content == as.content && res.invariant */ - } - - -} diff --git a/testcases/synthesis/synt2016/synthesis/AddressBook/Merge.scala b/testcases/synthesis/synt2016/synthesis/AddressBook/Merge.scala deleted file mode 100644 index 92a5b5bfef213e35c4f2a76bbbc9f295e406d1f4..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/AddressBook/Merge.scala +++ /dev/null @@ -1,69 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object AddressBookMake { - - case class Address[A](info: A, priv: Boolean) - - sealed abstract class AddressList[A] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(head, tail) => BigInt(1) + tail.size - } - } ensuring { res => res >= 0 } - - def content: Set[Address[A]] = this match { - case Nil() => Set[Address[A]]() - case Cons(addr, l1) => Set(addr) ++ l1.content - } - - def ++(that: AddressList[A]): AddressList[A] = { - this match { - case Cons(h, t) => Cons(h, t ++ that) - case Nil() => that - } - } ensuring { - res => res.content == this.content ++ that.content - } - } - - case class Cons[A](a: Address[A], tail: AddressList[A]) extends AddressList[A] - case class Nil[A]() extends AddressList[A] - - def allPersonal[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) allPersonal(l1) - else false - } - - def allBusiness[A](l: AddressList[A]): Boolean = l match { - case Nil() => true - case Cons(a, l1) => - if (a.priv) false - else allBusiness(l1) - } - - case class AddressBook[A](business: AddressList[A], personal: AddressList[A]) { - def size: BigInt = business.size + personal.size - - def content: Set[Address[A]] = business.content ++ personal.content - - @inline - def invariant = { - allPersonal(personal) && allBusiness(business) - } - } - - def merge[A](a1: AddressBook[A], a2: AddressBook[A]): AddressBook[A] = { - require(a1.invariant && a2.invariant) - - choose( (res: AddressBook[A]) => - res.personal.content == (a1.personal.content ++ a2.personal.content) && - res.business.content == (a1.business.content ++ a2.business.content) && - res.invariant - ) - } -} diff --git a/testcases/synthesis/synt2016/synthesis/BatchedQueue/Dequeue.scala b/testcases/synthesis/synt2016/synthesis/BatchedQueue/Dequeue.scala deleted file mode 100644 index c44fc062847b9af2264a9b3bba05186a313ab36b..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/BatchedQueue/Dequeue.scala +++ /dev/null @@ -1,80 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List[T] { - def content: Set[T] = { - this match { - case Cons(h, t) => Set(h) ++ t.content - case Nil() => Set() - } - } - - def size: BigInt = { - this match { - case Cons(h, t) => BigInt(1) + t.size - case Nil() => BigInt(0) - } - } ensuring { _ >= 0 } - - def reverse: List[T] = { - this match { - case Cons(h, t) => t.reverse.append(Cons(h, Nil[T]())) - case Nil() => Nil[T]() - } - } ensuring { res => - this.content == res.content - } - - def append(r: List[T]): List[T] = { - this match { - case Cons(h, t) => Cons(h, t.append(r)) - case Nil() => r - } - } - - def isEmpty: Boolean = { - this == Nil[T]() - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - } - - case class Cons[T](h: T, t: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - case class Queue[T](f: List[T], r: List[T]) { - def content: Set[T] = f.content ++ r.content - def size: BigInt = f.size + r.size - - def isEmpty: Boolean = f.isEmpty && r.isEmpty - - def invariant: Boolean = { - (f.isEmpty) ==> (r.isEmpty) - } - - def toList: List[T] = f.append(r.reverse) - - def dequeue: Queue[T] = { - require(invariant && !isEmpty) - - choose { (res: Queue[T]) => - res.size == size-1 && res.toList == this.toList.tail && res.invariant - } - } - } - - val test = Queue[BigInt](Cons(42, Nil()), Nil()).dequeue -} diff --git a/testcases/synthesis/synt2016/synthesis/BatchedQueue/Enqueue.scala b/testcases/synthesis/synt2016/synthesis/BatchedQueue/Enqueue.scala deleted file mode 100644 index 0f30a5ba1a95d39e78a1594f39804c8161e919a6..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/BatchedQueue/Enqueue.scala +++ /dev/null @@ -1,83 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object BatchedQueue { - sealed abstract class List[T] { - def content: Set[T] = { - this match { - case Cons(h, t) => Set(h) ++ t.content - case Nil() => Set() - } - } - - def size: BigInt = { - this match { - case Cons(h, t) => BigInt(1) + t.size - case Nil() => BigInt(0) - } - } ensuring { _ >= 0 } - - def reverse: List[T] = { - this match { - case Cons(h, t) => t.reverse.append(Cons(h, Nil[T]())) - case Nil() => Nil[T]() - } - } ensuring { res => - this.content == res.content - } - - def append(r: List[T]): List[T] = { - this match { - case Cons(h, t) => Cons(h, t.append(r)) - case Nil() => r - } - } - - def tail: List[T] = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => t - } - } - - def head: T = { - require(this != Nil[T]()) - this match { - case Cons(h, t) => h - } - } - - def last: T = { - require(this != Nil[T]()) - this match { - case Cons(h, Nil()) => h - case Cons(h, t) => t.last - } - } - } - - case class Cons[T](h: T, t: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - case class Queue[T](f: List[T], r: List[T]) { - def content: Set[T] = f.content ++ r.content - def size: BigInt = f.size + r.size - - def invariant: Boolean = { - (f == Nil[T]()) ==> (r == Nil[T]()) - } - - def toList: List[T] = f.append(r.reverse) - - def enqueue(v: T): Queue[T] = { - require(invariant) - - ???[Queue[T]] - } ensuring { (res: Queue[T]) => - res.invariant && - res.toList.last == v && - res.size == size + 1 && - res.content == this.content ++ Set(v) - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/Diffs/Diffs.scala b/testcases/synthesis/synt2016/synthesis/Diffs/Diffs.scala deleted file mode 100644 index fb0e01afb2a761260be85f6e020de73d7e32172e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/Diffs/Diffs.scala +++ /dev/null @@ -1,16 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon.lang.synthesis._ - -object Diffs { - - def diffs(l: List[BigInt]): List[BigInt] = - choose((res: List[BigInt]) => - res.size == l.size && undiff(res) == l - ) - - def undiff(l: List[BigInt]) = { - l.scanLeft(BigInt(0))(_ + _).tail - } -} - diff --git a/testcases/synthesis/synt2016/synthesis/List/Delete.scala b/testcases/synthesis/synt2016/synthesis/List/Delete.scala deleted file mode 100644 index 30716c5919256f052d0a0e741a147d30c5bc82fa..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/List/Delete.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Delete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def delete(in: List, v: BigInt) = { - ???[List] - } ensuring { - (out : List) => - content(out) == content(in) -- Set(v) - } -} diff --git a/testcases/synthesis/synt2016/synthesis/List/Diff.scala b/testcases/synthesis/synt2016/synthesis/List/Diff.scala deleted file mode 100644 index 9fb3ade9558a7db175c6056efb9bf724f487d7ca..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/List/Diff.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Diff { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert(in1: List, v: BigInt): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - def delete(in1: List, v: BigInt): List = { - in1 match { - case Cons(h,t) => - if (h == v) { - delete(t, v) - } else { - Cons(h, delete(t, v)) - } - case Nil => - Nil - } - } ensuring { content(_) == content(in1) -- Set(v) } - - // def diff(in1: List, in2: List): List = { - // in2 match { - // case Nil => - // in1 - // case Cons(h, t) => - // diff(delete(in1, h), t) - // } - // } ensuring { content(_) == content(in1) -- content(in2) } - - def diff(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) -- content(in2) - } -} diff --git a/testcases/synthesis/synt2016/synthesis/List/Insert.scala b/testcases/synthesis/synt2016/synthesis/List/Insert.scala deleted file mode 100644 index 48c38f4df0098410814f3ed27038c9c36c0d6532..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/List/Insert.scala +++ /dev/null @@ -1,28 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Insert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - //def insert(in1: List, v: BigInt): List = { - // Cons(v, in1) - //} ensuring { content(_) == content(in1) ++ Set(v) } - - def insert(in1: List, v: BigInt) = choose { - (out : List) => - content(out) == content(in1) ++ Set(v) - } -} diff --git a/testcases/synthesis/synt2016/synthesis/List/ListOfSize.scala b/testcases/synthesis/synt2016/synthesis/List/ListOfSize.scala deleted file mode 100644 index 12a95b590ee97e1153f2b7610d81ff9195109236..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/List/ListOfSize.scala +++ /dev/null @@ -1,24 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object ListOfSize { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def listOfSize(s: BigInt) = { - require(s >= 0) - choose((l: List) => size(l) == s) - } -} diff --git a/testcases/synthesis/synt2016/synthesis/List/Split.scala b/testcases/synthesis/synt2016/synthesis/List/Split.scala deleted file mode 100644 index f37e68264a8b5c4030fa283abc630f22ef98cd6e..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/List/Split.scala +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def abs(i : BigInt) : BigInt = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def split(list : List) : (List,List) = { - choose { (res : (List,List)) => splitSpec(list, res) } - } - -} diff --git a/testcases/synthesis/synt2016/synthesis/List/Union.scala b/testcases/synthesis/synt2016/synthesis/List/Union.scala deleted file mode 100644 index d6a5fa579f5745f00e469f19ee853da15d4fece7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/List/Union.scala +++ /dev/null @@ -1,37 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object Union { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1)+ size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert(in1: List, v: BigInt): List = { - Cons(v, in1) - } ensuring { content(_) == content(in1) ++ Set(v) } - - // def union(in1: List, in2: List): List = { - // in1 match { - // case Cons(h, t) => - // Cons(h, union(t, in2)) - // case Nil => - // in2 - // } - // } ensuring { content(_) == content(in1) ++ content(in2) } - - def union(in1: List, in2: List) = choose { - (out : List) => - content(out) == content(in1) ++ content(in2) - } -} diff --git a/testcases/synthesis/synt2016/synthesis/RunLength/RunLength.scala b/testcases/synthesis/synt2016/synthesis/RunLength/RunLength.scala deleted file mode 100644 index 1969220be8bee9ad7fed57ff7070b1560d32ebe9..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/RunLength/RunLength.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ -import leon.collection._ - -object RunLength { - - def decode[A](l: List[(BigInt, A)]): List[A] = { - def fill[A](i: BigInt, a: A): List[A] = { - if (i > 0) a :: fill(i - 1, a) - else Nil[A]() - } - l match { - case Nil() => Nil[A]() - case Cons((i, x), xs) => - fill(i, x) ++ decode(xs) - } - } - - def legal[A](l: List[(BigInt, A)]): Boolean = l match { - case Nil() => true - case Cons((i, _), Nil()) => i > 0 - case Cons((i, x), tl@Cons((_, y), _)) => - i > 0 && x != y && legal(tl) - } - - def encode[A](l: List[A]): List[(BigInt, A)] = { - // Solution - /*l match { - case Nil() => Nil[(BigInt, A)]() - case Cons(x, xs) => - val rec = encode(xs) - rec match { - case Nil() => - Cons( (BigInt(1), x), Nil[(BigInt,A)]()) - case Cons( (recC, recEl), recTl) => - if (x == recEl) { - Cons( (1+recC, x), recTl) - } else { - Cons( (BigInt(1), x), rec ) - } - } - }*/ - ???[List[(BigInt, A)]] - } ensuring { - (res: List[(BigInt, A)]) => - legal(res) && decode(res) == l - } - -} diff --git a/testcases/synthesis/synt2016/synthesis/SortedList/Delete.scala b/testcases/synthesis/synt2016/synthesis/SortedList/Delete.scala deleted file mode 100644 index 788f232d35449cff75ac27442ce7e9cb50f42391..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/SortedList/Delete.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListDelete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in: List, v: BigInt) = { - require(isSorted(in)) - - choose( (res : List) => - (content(res) == content(in) -- Set(v)) && isSorted(res) - ) - } -} diff --git a/testcases/synthesis/synt2016/synthesis/SortedList/Diff.scala b/testcases/synthesis/synt2016/synthesis/SortedList/Diff.scala deleted file mode 100644 index d391b85ba60e2b405530ddb45b40d94071263725..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/SortedList/Diff.scala +++ /dev/null @@ -1,53 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListDiff { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - - def diff(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - - choose { - (out : List) => - (content(out) == content(in1) -- content(in2)) && isSorted(out) - } - } - -} diff --git a/testcases/synthesis/synt2016/synthesis/SortedList/Insert.scala b/testcases/synthesis/synt2016/synthesis/SortedList/Insert.scala deleted file mode 100644 index 0bf80d1e99cef290e602b0da905d6966713c77b7..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/SortedList/Insert.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - - choose { (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/SortedList/InsertAlways.scala b/testcases/synthesis/synt2016/synthesis/SortedList/InsertAlways.scala deleted file mode 100644 index 73e0b240d776780fab6ac8091a8f0c925c56e695..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/SortedList/InsertAlways.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsertAlways { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insertAlways(in1: List, v: BigInt) = { - require(isSorted(in1)) - - choose{ (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) && size(out) == size(in1) + 1 - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/SortedList/InsertionSort.scala b/testcases/synthesis/synt2016/synthesis/SortedList/InsertionSort.scala deleted file mode 100644 index 0752ad33fe2249de829d7180e6facaab8fb6e160..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/SortedList/InsertionSort.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListInsertionSort { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def insertionSort(in1: List): List = { - choose { (out: List) => - content(out) == content(in1) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/SortedList/Union.scala b/testcases/synthesis/synt2016/synthesis/SortedList/Union.scala deleted file mode 100644 index d3f11adcccc07e44d1b82c1c6aed7144cb30523c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/SortedList/Union.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object SortedListUnion { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/StrictSortedList/Delete.scala b/testcases/synthesis/synt2016/synthesis/StrictSortedList/Delete.scala deleted file mode 100644 index 23999d96c3577b80b00b252e0c07509f4b4b2176..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/StrictSortedList/Delete.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListDelete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in: List, v: BigInt) = { - require(isSorted(in)) - - choose( (res : List) => - (content(res) == content(in) -- Set(v)) && isSorted(res) - ) - } -} diff --git a/testcases/synthesis/synt2016/synthesis/StrictSortedList/Insert.scala b/testcases/synthesis/synt2016/synthesis/StrictSortedList/Insert.scala deleted file mode 100644 index 65f3c01f9d7b7d8d45136196a6289088df46fa22..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/StrictSortedList/Insert.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListInsert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - - choose { (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/StrictSortedList/Union.scala b/testcases/synthesis/synt2016/synthesis/StrictSortedList/Union.scala deleted file mode 100644 index c10ed419d3c2cc4fefc9690efb37bc723799ef1c..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/StrictSortedList/Union.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.lang.synthesis._ - -object StrictSortedListUnion { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List): BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => BigInt(1) + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list: List): Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { - (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Add.scala b/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Add.scala deleted file mode 100644 index a34d1834fbb5cc2418ca830c5576e64d74169b4f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Add.scala +++ /dev/null @@ -1,21 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsAdd { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) + value(y) - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Distinct.scala b/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Distinct.scala deleted file mode 100644 index 4287378d1f95225e4ff1ffae57b2d0579d72c3a5..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Distinct.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsDistinct { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - x match { - case S(p) => S(add(p, y)) - case Z => y - } - } ensuring { (r : Num) => - value(r) == value(x) + value(y) - } - - def distinct(x: Num, y: Num): Num = { - choose { (r : Num) => - r != x && r != y - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Mult.scala b/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Mult.scala deleted file mode 100644 index bfa39365e8a8b35555ddc2265f40c775251b8d17..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/UnaryNumerals/Mult.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ - -object UnaryNumeralsMult { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => BigInt(1) + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - x match { - case S(p) => S(add(p, y)) - case Z => y - } - } ensuring { (r : Num) => - value(r) == value(x) + value(y) - } - - def mult(x: Num, y: Num): Num = { - choose { (r : Num) => - value(r) == value(x) * value(y) - } - } -} diff --git a/testcases/synthesis/synt2016/synthesis/runTests.sh b/testcases/synthesis/synt2016/synthesis/runTests.sh deleted file mode 100755 index 6cb5fcecb39aaf93ca7405da69fa4cab5682c14f..0000000000000000000000000000000000000000 --- a/testcases/synthesis/synt2016/synthesis/runTests.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -function run { - cmd="./leon --debug=report --timeout=60 --synthesis --partial=off $1" - echo "Running " $cmd - echo "------------------------------------------------------------------------------------------------------------------" - $cmd; -} - -echo "==================================================================================================================" >> synthesis-report.txt -# List -run testcases/synthesis/synt2016/synthesis/List/Insert.scala -run testcases/synthesis/synt2016/synthesis/List/Delete.scala -run testcases/synthesis/synt2016/synthesis/List/Union.scala -run testcases/synthesis/synt2016/synthesis/List/Diff.scala -run testcases/synthesis/synt2016/synthesis/List/Split.scala -run testcases/synthesis/synt2016/synthesis/List/ListOfSize.scala - -# SortedList -run testcases/synthesis/synt2016/synthesis/SortedList/Insert.scala -run testcases/synthesis/synt2016/synthesis/SortedList/InsertAlways.scala -run testcases/synthesis/synt2016/synthesis/SortedList/Delete.scala -run testcases/synthesis/synt2016/synthesis/SortedList/Union.scala -run testcases/synthesis/synt2016/synthesis/SortedList/Diff.scala -run testcases/synthesis/synt2016/synthesis/SortedList/InsertionSort.scala - -# StrictSortedList -run testcases/synthesis/synt2016/synthesis/StrictSortedList/Insert.scala -run testcases/synthesis/synt2016/synthesis/StrictSortedList/Delete.scala -run testcases/synthesis/synt2016/synthesis/StrictSortedList/Union.scala - -# UnaryNumerals -run testcases/synthesis/synt2016/synthesis/UnaryNumerals/Add.scala -run testcases/synthesis/synt2016/synthesis/UnaryNumerals/Distinct.scala -run testcases/synthesis/synt2016/synthesis/UnaryNumerals/Mult.scala - -# BatchedQueue -run testcases/synthesis/synt2016/synthesis/BatchedQueue/Enqueue.scala -run testcases/synthesis/synt2016/synthesis/BatchedQueue/Dequeue.scala - -# AddressBook -run testcases/synthesis/synt2016/synthesis/AddressBook/Make.scala -run testcases/synthesis/synt2016/synthesis/AddressBook/Merge.scala - -# RunLength -run testcases/synthesis/synt2016/synthesis/RunLength/RunLength.scala - -# Diffs -run testcases/synthesis/synt2016/synthesis/Diffs/Diffs.scala - diff --git a/testcases/termination/List.scala b/testcases/termination/List.scala deleted file mode 100644 index 60a5f25ec44aa9487cf96fa74af69b3b514d9e35..0000000000000000000000000000000000000000 --- a/testcases/termination/List.scala +++ /dev/null @@ -1,613 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.collection - -import leon._ -import leon.lang._ -import leon.annotation._ -import leon.math._ - -@library -sealed abstract class List[T] { - - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => 1 + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { _ == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => - (res.content == this.content ++ that.content) && - (res.size == this.size + that.size) - } - - def head: T = { - require(this != Nil[T]()) - val Cons(h, _) = this - h - } - - def tail: List[T] = { - require(this != Nil[T]()) - val Cons(_, t) = this - t - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == BigInt(0)) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = { (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - if (i <= BigInt(0)) { - Nil[T]() - } else { - Cons(h, t.take(i-1)) - } - }} ensuring { res => - res.content.subsetOf(this.content) && (res.size == ( - if (i <= 0) BigInt(0) - else if (i >= this.size) this.size - else i - )) - } - - def drop(i: BigInt): List[T] = { (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - if (i <= BigInt(0)) { - Cons[T](h, t) - } else { - t.drop(i-1) - } - }} ensuring { res => - res.content.subsetOf(this.content) && (res.size == ( - if (i <= 0) this.size - else if (i >= this.size) BigInt(0) - else this.size - i - )) - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(0 <= from && from <= to && to <= size) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = { this match { - case Nil() => Nil[T]() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - }} ensuring { (res: List[T]) => - res.size == this.size && - res.content == ( - (this.content -- Set(from)) ++ - (if (this.content contains from) Set(to) else Set[T]()) - ) - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == BigInt(0)) { - chunk0(s, l, Nil(), res :+ acc, s) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = { (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case _ => - Nil[(T, B)]() - }} ensuring { _.size == ( - if (this.size <= that.size) this.size else that.size - )} - - def -(e: T): List[T] = { this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == this.content -- Set(e) - } - - def --(that: List[T]): List[T] = { this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == this.content -- that.content - } - - def &(that: List[T]): List[T] = { this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == (this.content & that.content) - } - - def padTo(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().padTo(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.padTo(s-1, e)) - }} ensuring { res => - if (s <= this.size) - res == this - else - res.size == s && - res.content == this.content ++ Set(e) - } - - def find(e: T): Option[BigInt] = { this match { - case Nil() => None[BigInt]() - case Cons(h, t) => - if (h == e) { - Some[BigInt](0) - } else { - t.find(e) match { - case None() => None[BigInt]() - case Some(i) => Some(i+1) - } - } - }} ensuring { _.isDefined == this.contains(e) } - - def init: List[T] = { - require(!isEmpty) - (this match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - }) - } ensuring ( (r: List[T]) => - r.size == this.size - 1 && - r.content.subsetOf(this.content) - ) - - def last: T = { - require(!isEmpty) - this match { - case Cons(h, Nil()) => h - case Cons(_, t) => t.last - } - } ensuring { this.contains _ } - - def lastOption: Option[T] = { this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None[T]() - }} ensuring { _.isDefined != this.isEmpty } - - def firstOption: Option[T] = { this match { - case Cons(h, t) => - Some(h) - case Nil() => - None[T]() - }} ensuring { _.isDefined != this.isEmpty } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - insertAt(size + pos, l) - } else if(pos == BigInt(0)) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAt(pos-1, l)) - case Nil() => - l - } - } - } ensuring { res => - res.size == this.size + l.size && - res.content == this.content ++ l.content - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - if(pos < 0) { - replaceAt(size + pos, l) - } else if(pos == BigInt(0)) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAt(pos-1, l)) - case Nil() => - l - } - } - } ensuring { res => - res.content.subsetOf(l.content ++ this.content) - } - - def rotate(s: BigInt): List[T] = { - if (s < 0) { - rotate(size + s) - } else if (s > size) { - rotate(s - size) - } else { - drop(s) ++ take(s) - } - } ensuring { res => - res.size == this.size - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - - // Higher-order API - def map[R](f: T => R): List[R] = { this match { - case Nil() => Nil[R]() - case Cons(h, t) => f(h) :: t.map(f) - }} ensuring { _.size == this.size } - - def foldLeft[R](z: R)(f: (R,T) => R): R = this match { - case Nil() => z - case Cons(h,t) => t.foldLeft(f(z,h))(f) - } - - def foldRight[R](z: R)(f: (T,R) => R): R = this match { - case Nil() => z - case Cons(h, t) => f(h, t.foldRight(z)(f)) - } - - def scanLeft[R](z: R)(f: (R,T) => R): List[R] = { this match { - case Nil() => z :: Nil() - case Cons(h,t) => z :: t.scanLeft(f(z,h))(f) - }} ensuring { !_.isEmpty } - - def scanRight[R](z: R)(f: (T,R) => R): List[R] = { this match { - case Nil() => z :: Nil[R]() - case Cons(h, t) => - val rest@Cons(h1,_) = t.scanRight(z)(f) - f(h, h1) :: rest - }} ensuring { !_.isEmpty } - - def flatMap[R](f: T => List[R]): List[R] = - ListOps.flatten(this map f) - - def filter(p: T => Boolean): List[T] = { this match { - case Nil() => Nil[T]() - case Cons(h, t) if p(h) => Cons(h, t.filter(p)) - case Cons(_, t) => t.filter(p) - }} ensuring { res => - res.size <= this.size && - res.content.subsetOf(this.content) && - res.forall(p) - } - - def filterNot(p: T => Boolean): List[T] = - filter(!p(_)) ensuring { res => - res.size <= this.size && - res.content.subsetOf(this.content) && - res.forall(!p(_)) - } - - def partition(p: T => Boolean): (List[T], List[T]) = { this match { - case Nil() => (Nil[T](), Nil[T]()) - case Cons(h, t) => - val (l1, l2) = t.partition(p) - if (p(h)) (h :: l1, l2) - else (l1, h :: l2) - }} ensuring { res => - res._1 == filter(p) && - res._2 == filterNot(p) - } - - // In case we implement for-comprehensions - def withFilter(p: T => Boolean) = filter(p) - - def forall(p: T => Boolean): Boolean = this match { - case Nil() => true - case Cons(h, t) => p(h) && t.forall(p) - } - - def exists(p: T => Boolean) = !forall(!p(_)) - - def find(p: T => Boolean): Option[T] = { this match { - case Nil() => None[T]() - case Cons(h, t) if p(h) => Some(h) - case Cons(_, t) => t.find(p) - }} ensuring { _.isDefined == exists(p) } - - def groupBy[R](f: T => R): Map[R, List[T]] = this match { - case Nil() => Map.empty[R, List[T]] - case Cons(h, t) => - val key: R = f(h) - val rest: Map[R, List[T]] = t.groupBy(f) - val prev: List[T] = if (rest isDefinedAt key) rest(key) else Nil[T]() - (rest ++ Map((key, h :: prev))) : Map[R, List[T]] - } - - def takeWhile(p: T => Boolean): List[T] = { this match { - case Cons(h,t) if p(h) => Cons(h, t.takeWhile(p)) - case _ => Nil[T]() - }} ensuring { res => - (res forall p) && - (res.size <= this.size) && - (res.content subsetOf this.content) - } - - def dropWhile(p: T => Boolean): List[T] = { this match { - case Cons(h,t) if p(h) => t.dropWhile(p) - case _ => this - }} ensuring { res => - (res.size <= this.size) && - (res.content subsetOf this.content) && - (res.isEmpty || !p(res.head)) - } - - def count(p: T => Boolean): BigInt = { this match { - case Nil() => BigInt(0) - case Cons(h, t) => - (if (p(h)) BigInt(1) else BigInt(0)) + t.count(p) - }} ensuring { - _ == this.filter(p).size - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = { - var l: List[T] = Nil[T]() - for (e <- elems) { - l = Cons(e, l) - } - l.reverse - } -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==BigInt(0)) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds - - //def associative[T,U](l1: List[T], l2: List[T], f: List[T] => U, op: (U,U) => U) = { - // f(l1 ++ l2) == op(f(l1), f(l2)) - //} - // - //def existsAssoc[T](l1: List[T], l2: List[T], p: T => Boolean) = { - // associative[T, Boolean](l1, l2, _.exists(p), _ || _ ) - //}.holds - // - //def forallAssoc[T](l1: List[T], l2: List[T], p: T => Boolean) = { - // associative[T, Boolean](l1, l2, _.exists(p), _ && _ ) - //}.holds - - //@induct - //def folds[T,R](l : List[T], z : R, f : (R,T) => R) = { - // { l match { - // case Nil() => true - // case Cons(h,t) => snocReverse[T](t, h) - // }} && - // l.foldLeft(z)(f) == l.reverse.foldRight((x:T,y:R) => f(y,x))(z) - //}.holds - // - - //Can't prove this - //@induct - //def scanVsFoldLeft[A,B](l : List[A], z: B, f: (B,A) => B): Boolean = { - // l.scanLeft(z)(f).last == l.foldLeft(z)(f) - //}.holds - - @induct - def scanVsFoldRight[A,B](l: List[A], z: B, f: (A,B) => B): Boolean = { - l.scanRight(z)(f).head == l.foldRight(z)(f) - }.holds - -} diff --git a/testcases/termination/pending/McCarthy91.scala b/testcases/termination/pending/McCarthy91.scala deleted file mode 100644 index 66a15d68fe20906c7ca3209810ac28ddff2eeb5f..0000000000000000000000000000000000000000 --- a/testcases/termination/pending/McCarthy91.scala +++ /dev/null @@ -1,10 +0,0 @@ - -/* -This function terminates for all inputs, see -http://en.wikipedia.org/wiki/McCarthy_91_function - -But the termination checker returns NoGuarantee after 75s. -*/ -object McCarthy91 { - def M(n: BigInt): BigInt = if (n > 100) n-10 else M(M(n+11)) -} diff --git a/testcases/termination/pending/lambdaDot.scala b/testcases/termination/pending/lambdaDot.scala deleted file mode 100644 index d3ea7ab54ed0057ae6346a9c631fc1325ee99ee0..0000000000000000000000000000000000000000 --- a/testcases/termination/pending/lambdaDot.scala +++ /dev/null @@ -1,112 +0,0 @@ -/* -A very much simplified implementation of the types in the -Dependent Object Calculus (http://lampwww.epfl.ch/~amin/dot/fool.pdf). - -It's interesting because expansion calls itself recursively (through -lookupInVar), and passes the results of this recursive call to another -recursive call. - -The termination checker loops forever [or at least longer than several -minutes ;-)] on this case. -*/ - -import leon.lang._ -import leon.collection._ -import leon._ - -object lambdaDot { - abstract class Label - case class TypLabel(id: BigInt) extends Label - case class MtdLabel(id: BigInt) extends Label - - abstract class Type - case class Top() extends Type - case class Bot() extends Type - case class Rcd(ds: List[Dec]) extends Type - case class TSel(x: BigInt, l: BigInt) extends Type - - abstract class Dec { - def label: Label = this match { - case TDec(l, _, _) => TypLabel(l) - case MDec(m, _, _) => MtdLabel(m) - } - } - case class TDec(l: BigInt, lowerBound: Type, upperBound: Type) extends Dec - case class MDec(m: BigInt, argType: Type, retType: Type) extends Dec - - abstract class Decs - case class FiniteDecs(l: List[Dec]) extends Decs - case class BotDecs() extends Decs - - def lookupInEnv(x: BigInt, env: List[(BigInt, Type)]): Option[Type] = env match { - case Cons((y, t), rest) => if (x == y) Some(t) else lookupInEnv(x, rest) - case Nil() => None() - } - - def lookupInDecList(name: Label, l: List[Dec]): Option[Dec] = (l match { - case Cons(d, ds) => if (d.label == name) Some(d) else lookupInDecList(name, ds) - case Nil() => None() - }) ensuring { res => res match { - case Some(d) => d.label == name - case None() => true - }} - - def lookupInDecs(name: Label, l: Decs): Option[Dec] = (l match { - case FiniteDecs(l) => lookupInDecList(name, l) - case BotDecs() => name match { - case TypLabel(l) => Some(TDec(l, Top(), Bot())) - case MtdLabel(m) => Some(MDec(m, Top(), Bot())) - } - }) ensuring { res => res match { - case Some(d) => d.label == name - case None() => true - }} - - def wfType(env: List[(BigInt, Type)], t: Type, shallow: Boolean): Boolean = t match { - case Top() => true - case Bot() => true - case Rcd(ds) => shallow || wfDecList(env, ds) - case TSel(x, l) => lookupInVar(env, x, TypLabel(l)) match { - case Some(TDec(l, lo, hi)) => wfType(env, lo, true) && wfType(env, hi, true) - case None() => false - } - } - - def wfDec(env: List[(BigInt, Type)], d: Dec): Boolean = d match { - case TDec(l, lo, hi) => wfType(env, lo, false) && wfType(env, hi, false) - case MDec(m, a, r) => wfType(env, a, false) && wfType(env, r, false) - } - - def wfDecList(env: List[(BigInt, Type)], ds: List[Dec]): Boolean = ds match { - case Cons(d, ds) => wfDec(env, d) && wfDecList(env, ds) - case Nil() => true - } - - def expansion(env: List[(BigInt, Type)], t: Type): Option[Decs] = { - //require(wfType(env, t, false)) - t match { - case Top() => Some(FiniteDecs(Nil())) - case Bot() => Some(FiniteDecs(Nil())) - case Rcd(ds) => Some(FiniteDecs(ds)) - case TSel(x, l) => lookupInVar(env, x, TypLabel(l)) match { - case Some(TDec(l, lo, hi)) => expansion(env, hi) - case None() => None() - } - } - } - - def lookupInVar(env: List[(BigInt, Type)], x: BigInt, l: Label): Option[Dec] = { - lookupInEnv(x, env) match { - case Some(tx) => expansion(env, tx) match { - case Some(dsx) => lookupInDecs(l, dsx) - case None() => None() - } - case None() => None() - } - } ensuring { res => res match { - case Some(d) => d.label == l - case None() => true - }} - -} - diff --git a/testcases/verification/Addresses.scala b/testcases/verification/Addresses.scala deleted file mode 100644 index b6f356fe2a58068847d325071b3959cf25a7d862..0000000000000000000000000000000000000000 --- a/testcases/verification/Addresses.scala +++ /dev/null @@ -1,144 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Addresses { - // list of integers - sealed abstract class List - case class Cons(a: BigInt,b: BigInt,c: BigInt, tail:List) extends List - case class Nil() extends List - - def setA(l:List) : Set[BigInt] = l match { - case Nil() => Set.empty[BigInt] - case Cons(a,b,c,l1) => Set(a) ++ setA(l1) - } - - def containsA(x:BigInt,l:List) : Boolean = (l match { - case Nil() => false - case Cons(a,b,c,t) => a==x || containsA(x,t) - }) ensuring (res => res == (setA(l) contains x)) - - def theseAunique1(as:Set[BigInt],l:List) : Boolean = l match { - case Nil() => true - case Cons(a,b,c,l1) => - theseAunique1(as,l1) && !(as contains a) && (setA(l1) contains a) - } - - def theseAunique2(as:Set[BigInt],l:List) : Boolean = (l match { - case Nil() => true - case Cons(a,b,c,l1) => - theseAunique2(as,l1) && !(as contains a) && containsA(a,l1) - }) ensuring (res => res==theseAunique1(as,l)) - - def disjoint(x:Set[BigInt],y:Set[BigInt]):Boolean = { - (x & y) == Set.empty[BigInt] - } - - def uniqueAbsentAs(unique:Set[BigInt],absent:Set[BigInt],l:List) : Boolean = (l match { - case Nil() => true - case Cons(a,b,c,l1) => { - !(absent contains a) && - (if (unique contains a) uniqueAbsentAs(unique -- Set(a), absent ++ Set(a), l1) - else uniqueAbsentAs(unique, absent, l1)) - } - }) ensuring (res => theseAunique1(unique,l) && disjoint(setA(l),absent)) - - def allPos(l:List) : Boolean = l match { - case Nil() => true - case Cons(a,b,c,l1) => 0 <= a && 0 <= b && 0 <= c && allPos(l1) - } - - def allEq(l:List,k:BigInt) : Boolean = l match { - case Nil() => true - case Cons(a,b,c,l1) => c==k && allEq(l1,k) - } - - def max(x:BigInt,y:BigInt) = if (x <= y) x else y - - def collectA(x:BigInt,l:List) : (BigInt,BigInt,List) = (l match { - case Nil() => (BigInt(0),BigInt(0),Nil()) - case Cons(a,b,c,l1) if (a==x) => { - val (b2,c2,l2) = collectA(x,l1) - (max(b,b2),max(c,c2),l2) - } - case Cons(a,b,c,l1) if (a!=x) => { - val (b2,c2,l2) = collectA(x,l1) - (b2,c2,Cons(a,b,c,l2)) - } - }) ensuring (res => { - val (b,c,l1) = res - !setA(l1).contains(x) - }) - -/* - def makeUniqueA(x:BigInt,l:List) : List = { - require(allPos(l)) - val (b,c,l1) = collectA(x,l) - Cons(x,b,c,l1) - } ensuring(res => theseAunique1(Set(x),res)) -*/ - - case class AddressBook(business : List, pers : List) - def isValidAB(ab:AddressBook) : Boolean = { - allEq(ab.business,0) && allEq(ab.pers,1) - } - def setAB(l:List) : Set[(BigInt,BigInt)] = l match { - case Nil() => Set.empty[(BigInt,BigInt)] - case Cons(a,b,c,l1) => Set((a,b)) ++ setAB(l1) - } - - def removeA(x:BigInt,l:List) : List = (l match { - case Nil() => Nil() - case Cons(a,b,c,l1) => - if (a==x) removeA(x,l1) - else Cons(a,b,c,removeA(x,l1)) - }) ensuring(res => !(setA(res) contains x)) - - def removeAg(x:BigInt,l:List,bg:BigInt) : List = (l match { - case Nil() => Nil() - case Cons(a,b,c,l1) => - if (a==x) removeAg(x,l1,bg) - else Cons(a,b,c,removeAg(x,l1,bg)) - }) ensuring (res => !(setAB(res) contains (x,bg))) - - def removeA1(x:BigInt,l:List) : List = removeAg(x,l,0) - - @induct - def removeAspec1(x:BigInt,l:List,bg:BigInt) : Boolean = { - removeAg(x,l,bg) == removeA(x,l) - } holds - - def removeAspec2(x:BigInt,l:List,k:BigInt) : Boolean = { - require(allEq(l,k)) - allEq(removeA(x,l),k) - } holds - - def updateABC(a:BigInt,b:BigInt,c:BigInt,l:List) : List = ({ - Cons(a,b,c,removeA(a,l)) - }) ensuring (res => setAB(res) contains (a,b)) - - def lookupA(x:BigInt,l:List) : (BigInt,BigInt,BigInt) = { - require(setA(l) contains x) - l match { - case Cons(a,b,c,l1) => { - if (a==x) (a,b,c) - else lookupA(x,l1) - } - } - } ensuring((res:(BigInt,BigInt,BigInt)) => { - val (a,b,c) = res - setAB(l) contains (a,b) - }) - - def makePers(ab:AddressBook, x:BigInt) : AddressBook = { - require(isValidAB(ab) && (setA(ab.business) contains x)) - val (a,b,c) = lookupA(x,ab.business) - val business1 = removeA(x, ab.business) - // assert(allEq(business1,0)) - val pers1 = Cons(a,b,1,ab.pers) - // assert(allEq(pers1,1)) - AddressBook(business1,pers1) - } ensuring (res => isValidAB(res) && - (setA(ab.pers) contains x) && - !(setA(ab.business) contains x)) - -} diff --git a/testcases/verification/algorithms/FiniteSort.scala b/testcases/verification/algorithms/FiniteSort.scala deleted file mode 100644 index 1b0ec964ed765cd642ce10cbdd42c2d7532006b2..0000000000000000000000000000000000000000 --- a/testcases/verification/algorithms/FiniteSort.scala +++ /dev/null @@ -1,80 +0,0 @@ -import leon.lang._ - -object FiniteSorting { - - // These finite sorting functions essentially implement insertion sort. - def sort2(x : BigInt, y : BigInt) : (BigInt,BigInt) = { - if(x < y) (x, y) else (y, x) - } ensuring (_ match { - case (a, b) => a <= b && Set(a,b) == Set(x,y) - }) - - def sort3(x1 : BigInt, x2 : BigInt, x3 : BigInt) : (BigInt, BigInt, BigInt) = { - val (x1s, x2s) = sort2(x1, x2) - - if(x2s <= x3) { - (x1s, x2s, x3) - } else if(x1s <= x3) { - (x1s, x3, x2s) - } else { - (x3, x1s, x2s) - } - } ensuring (_ match { - case (a, b, c) => a <= b && b <= c && Set(a,b,c) == Set(x1,x2,x3) - }) - - def sort4(x1 : BigInt, x2 : BigInt, x3 : BigInt, x4 : BigInt) : (BigInt, BigInt, BigInt, BigInt) = { - val (x1s, x2s, x3s) = sort3(x1, x2, x3) - - if(x3s <= x4) { - (x1s, x2s, x3s, x4) - } else if(x2s <= x4) { - (x1s, x2s, x4, x3s) - } else if(x1s <= x4) { - (x1s, x4, x2s, x3s) - } else { - (x4, x1s, x2s, x3s) - } - - } ensuring (_ match { - case (a, b, c, d) => a <= b && b <= c && c <= d && Set(a,b,c,d) == Set(x1,x2,x3,x4) - }) - - def sort5(x1 : BigInt, x2 : BigInt, x3 : BigInt, x4 : BigInt, x5 : BigInt) : (BigInt, BigInt, BigInt, BigInt, BigInt) = { - val (x1s, x2s, x3s, x4s) = sort4(x1, x2, x3, x4) - - if(x4s <= x5) { - (x1s, x2s, x3s, x4s, x5) - } else if(x3s <= x5) { - (x1s, x2s, x3s, x5, x4s) - } else if(x2s <= x5) { - (x1s, x2s, x5, x3s, x4s) - } else if(x1s <= x5) { - (x1s, x5, x2s, x3s, x4s) - } else { - (x5, x1s, x2s, x3s, x4s) - } - - } ensuring (_ match { - case (a, b, c, d, e) => a <= b && b <= c && c <= d && d <= e && Set(a,b,c,d,e) == Set(x1,x2,x3,x4,x5) - }) - - def sort5WrongSpec(x1 : BigInt, x2 : BigInt, x3 : BigInt, x4 : BigInt, x5 : BigInt) : (BigInt, BigInt, BigInt, BigInt, BigInt) = { - val (x1s, x2s, x3s, x4s) = sort4(x1, x2, x3, x4) - - if(x4s <= x5) { - (x1s, x2s, x3s, x4s, x5) - } else if(x3s <= x5) { - (x1s, x2s, x3s, x5, x4s) - } else if(x2s <= x5) { - (x1s, x2s, x5, x3s, x4s) - } else if(x1s <= x5) { - (x1s, x5, x2s, x3s, x4s) - } else { - (x5, x1s, x2s, x3s, x4s) - } - - } ensuring (_ match { - case (a, b, c, d, e) => a <= b && b <= c && c <= d && d <= e && Set(a,b,c,d,e) == Set(x1,x2,x3,x4,x4) - }) -} diff --git a/testcases/verification/algorithms/SecondsToTime.scala b/testcases/verification/algorithms/SecondsToTime.scala deleted file mode 100644 index 385a72921cce178325579ae098273bcce6cdeabe..0000000000000000000000000000000000000000 --- a/testcases/verification/algorithms/SecondsToTime.scala +++ /dev/null @@ -1,39 +0,0 @@ - -object SecondsToTime { - - def propSum(t: BigInt, h: BigInt, m: BigInt, s: BigInt) : Boolean = h * 3600 + m * 60 + s == t - def prop(t: BigInt, h: BigInt, m: BigInt, s: BigInt) : Boolean = propSum(t, h, m, s) && m >= 0 && m < 60 && s >= 0 && s < 60 - - def secondsToTime(total : BigInt) = { - require(total >= 0) - rec(total, total, 0, 0) - } ensuring(_ match { case (h,m,s) => prop(total, h, m, s) }) - - def secondsToTime2(total : BigInt) = { - require(total >= 0) - rec2(total, total, 0, 0) - } ensuring(_ match { case (h,m,s) => prop(total, h, m, s) }) - - def rec(total : BigInt, r : BigInt, h : BigInt, m : BigInt) : (BigInt, BigInt, BigInt) = { - require(propSum(total, h, m, r) && m >= 0 && h >= 0 && r >= 0 && m < 60 && (m == 0 || r + m * 60 < 3600)) - - if(r >= 3600) { - rec(total, r - 3600, h + 1, m) - } else if(r >= 60) { - rec(total, r - 60, h, m + 1) - } else { - (h, m, r) - } - } ensuring(_ match { case(h,m,s) => prop(total, h, m, s) }) - - def rec2(total : BigInt, r : BigInt, h : BigInt, m : BigInt) : (BigInt, BigInt, BigInt) = { - require(propSum(total, h, m, r) && m >= 0 && h >= 0 && r >= 0 && m < 60) - if(r >= 60 && m == 59) { - rec2(total, r - 60, h + 1, 0) - } else if(r >= 60) { - rec2(total, r - 60, h, m + 1) - } else { - (h, m, r) - } - } ensuring(_ match { case(h,m,s) => prop(total, h, m, s) }) -} diff --git a/testcases/verification/case-studies/Compiler.scala b/testcases/verification/case-studies/Compiler.scala deleted file mode 100644 index f0d70e3471b28f264222611241f69104861dc555..0000000000000000000000000000000000000000 --- a/testcases/verification/case-studies/Compiler.scala +++ /dev/null @@ -1,171 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Tokens { - abstract class Token - case object TPlus extends Token - case object TTimes extends Token - case object TLT extends Token - case object TIf extends Token - case object TElse extends Token - case object TLAnd extends Token - case object TLOr extends Token - case object TLeftBrace extends Token - case object TRightBrace extends Token - case object TLeftPar extends Token - case object TRightPar extends Token - case class TInt(v: Int) extends Token - case class TId(name: Int) extends Token // All variables are : Int -} - -object Trees { - abstract class Expr - case class Times(lhs: Expr, rhs: Expr) extends Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Var(id: Int) extends Expr - case class IntLiteral(v: Int) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - -object Parser { - import Tokens._ - import Trees._ - - def parsePhrase(ts: List[Token]): Option[Expr] = { - parseGoal(ts) match { - case Some((res, Nil())) => Some(res) - case _ => None() - } - } - - def parseGoal(ts: List[Token]): Option[(Expr, List[Token])] = { - parseOr(ts) - } - - def parseOr(ts: List[Token]): Option[(Expr, List[Token])] = { - parseAnd(ts) match { - case Some((lhs, Cons(TLOr, r))) => - parseAnd(r) match { - case Some((rhs, ts2)) => Some((Or(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parseAnd(ts: List[Token]): Option[(Expr, List[Token])] = { - parseLT(ts) match { - case Some((lhs, Cons(TLAnd, r))) => - parseLT(r) match { - case Some((rhs, ts2)) => Some((And(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parseLT(ts: List[Token]): Option[(Expr, List[Token])] = { - parsePlus(ts) match { - case Some((lhs, Cons(TLT, r))) => - parsePlus(r) match { - case Some((rhs, ts2)) => Some((LessThan(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parsePlus(ts: List[Token]): Option[(Expr, List[Token])] = { - parseTimes(ts) match { - case Some((lhs, Cons(TPlus, r))) => - parsePlus(r) match { - case Some((rhs, ts2)) => Some((Plus(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parseTimes(ts: List[Token]): Option[(Expr, List[Token])] = { - parseLits(ts) match { - case Some((lhs, Cons(t, r))) if (t == TTimes) => - parseTimes(r) match { - case Some((rhs, ts2)) => Some((Plus(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parseLits(ts: List[Token]): Option[(Expr, List[Token])] = ts match { - case Cons(TInt(v), r) => Some((IntLiteral(v), r)) - case Cons(TId(v), r) => Some((Var(v), r)) - case Cons(TLeftPar, r) => - parseGoal(r) match { - case Some((e, Cons(TRightPar, ts2))) => Some((e, ts2)) - case _ => None() - } - case Cons(TIf, Cons(TLeftPar, r)) => - parseGoal(r) match { - case Some((c, Cons(TRightPar, Cons(TLeftBrace, ts2)))) => - // Then - parseGoal(ts2) match { - case Some((th, Cons(TRightBrace, Cons(TElse, Cons(TLeftBrace, ts3))))) => - // Else - parseGoal(ts3) match { - case Some((el, Cons(TRightBrace, ts4))) => - Some((Ite(c, th, el), ts4)) - case _ => None() - } - case _ => None() - } - case _ => None() - } - case _ => None() - } -} - -object TypeChecker { - import Trees._ - import Types._ - - def typeChecks(e: Expr, exp: Option[Type]): Boolean = e match { - case Times(l, r) => (exp.getOrElse(IntType) == IntType) && typeChecks(l, Some(IntType)) && typeChecks(r, Some(IntType)) - case Plus(l, r) => (exp.getOrElse(IntType) == IntType) && typeChecks(l, Some(IntType)) && typeChecks(r, Some(IntType)) - case And(l, r) => (exp.getOrElse(BoolType) == BoolType) && typeChecks(l, Some(BoolType)) && typeChecks(r, Some(BoolType)) - case Or(l, r) => (exp.getOrElse(BoolType) == BoolType) && typeChecks(l, Some(BoolType)) && typeChecks(r, Some(BoolType)) - case LessThan(l, r) => (exp.getOrElse(BoolType) == BoolType) && typeChecks(l, Some(IntType)) && typeChecks(r, Some(IntType)) - case Ite(c, th, el) => typeChecks(c, Some(BoolType)) && typeChecks(th, exp) && typeChecks(el, exp) - case IntLiteral(_) => exp.getOrElse(IntType) == IntType - case Var(_) => exp.getOrElse(IntType) == IntType - } - - def typeChecks(e: Expr): Boolean = typeChecks(e, None()) -} - -object Compiler { - import Tokens._ - import Trees._ - import Types._ - import Parser._ - import TypeChecker._ - - - def parse(ts: List[Token]): Option[Expr] = { - parsePhrase(ts) - } ensuring { _ match { - case Some(tree) => typeChecks(tree) - case None() => true - }} -} diff --git a/testcases/verification/case-studies/Lambda.scala b/testcases/verification/case-studies/Lambda.scala deleted file mode 100644 index 05df4cf57332fced12b3dd1eda809816d71c6490..0000000000000000000000000000000000000000 --- a/testcases/verification/case-studies/Lambda.scala +++ /dev/null @@ -1,142 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.lang.synthesis._ -import leon._ - -object Lang { - case class Id(v: Int) - - def isLiteral(l: Expr) = l match { - case _: Var => true - case _: Abs => true - //case _: Record => true - case _ => false - } - - abstract class Expr - case class Var(id: Id) extends Expr - case class App(f: Expr, arg: Expr) extends Expr - case class Abs(b: Id, tpe: Type, e: Expr) extends Expr - //case class Record(fields: Map[Id, Expr]) extends Expr - //case class Select(r: Expr, f: Var) extends Expr - - abstract class Type - case class Param(k : Int) extends Type - case class TFunction(from: Type, to: Type) extends Type - //case class TRecord(fields: Map[Id, Type]) extends Type -} - - - -object TypeChecker { - import Lang._ - - def typeOf(e: Expr, exp: Option[Type], env: Map[Id, Type]): Option[Type] = { - val t: Option[Type] = e match { - case Var(id) => - if (env contains id) { - Some(env(id)) - } else { - None() - } - - case App(f, arg) => - typeOf(f, None(), env) match { - case Some(TFunction(from, to)) => - typeOf(arg, Some(from), env) match { - case Some(_) => Some(to) - case _ => None() - } - case _ => None() - } - case Abs(id, tpe, e) => - val nenv = env.updated(id, tpe) - (exp, typeOf(e, None(), nenv)) match { - case (Some(TFunction(from, to)), Some(to2)) if (from == tpe) && (to == to2) => - Some(TFunction(tpe, to2)) - case (None(), Some(to2)) => - Some(TFunction(tpe, to2)) - case _ => - None() - } - } - - if(exp.orElse(t) == t) { - t - } else { - None() - } - } - - def typeChecks(e: Expr): Boolean = { - typeOf(e, None(), Map[Id, Type]()).isDefined - } - - def typeOf(e: Expr): Option[Type] = { - typeOf(e, None(), Map[Id, Type]()) - } -} - -object Evaluator { - import Lang._ - import TypeChecker._ - - def subst(e: Expr, t: (Id, Expr)): Expr = e match { - case Var(id) if id == t._1 => t._2 - case App(f, arg) => App(subst(f, t), subst(arg, t)) - case Abs(b, id, e) => Abs(b, id, subst(e, t)) - case _ => e - } - - def eval(e: Expr): Expr = { - require(typeChecks(e)) - e match { - case App(f, arg) => - eval(f) match { - case Abs(id, _, e) => eval(subst(e, id -> arg)) - case _ => e // stuck - } - case _ => - e - }} ensuring { res => isLiteral(res) } -} - -object Main { - import Lang._ - import Evaluator._ - import TypeChecker._ - - def synthesize_identity() : Expr = { - choose { (e : Expr) => - val t_identity : Type = TFunction(Param(1), Param(1)) - typeOf(e) == Some(t_identity) - } - } - - def synthesize_K() : Expr = { - choose { (e : Expr) => - val t1 : Type = TFunction(Param(1), TFunction(Param(2), Param(1))) - typeOf(e) == Some(t1) - } - } - def synthesize_K2() : Expr = { - choose { (e : Expr) => - val t1 : Type = TFunction(Param(1), TFunction(Param(2), Param(2))) - typeOf(e) == Some(t1) - } - } - - - def synthesize_S() : Expr = { - choose { (e : Expr) => - val tz = Param(1) - val ty = TFunction(Param(1), Param(2)) - val tx = TFunction(Param(1), TFunction(Param(2), Param(3))) - val t1 : Type = TFunction(tx, - TFunction(ty, - TFunction(tz, Param(3)))) - typeOf(e) == Some(t1) - } - } -} diff --git a/testcases/verification/case-studies/LambdaSound.scala b/testcases/verification/case-studies/LambdaSound.scala deleted file mode 100644 index fa59efbc001614acbd338b83883248d07a736a2d..0000000000000000000000000000000000000000 --- a/testcases/verification/case-studies/LambdaSound.scala +++ /dev/null @@ -1,85 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.lang.synthesis._ -import leon._ - -object Lambda { - case class Id(v: BigInt) - - abstract class Expr - case class Var(id: Id) extends Expr - case class App(f: Expr, arg: Expr) extends Expr - case class Abs(b: Id, tpe: Type, e: Expr) extends Expr - - case class Env(binds: Map[Id, Expr]) - - abstract class Type - case object Tind extends Type - case object Tbool extends Type - case class Arrow(from: Type, to: Type) extends Type - - case class TEnv(binds: Map[Id, Type]) - - def fv(e: Expr): Set[Id] = e match { - case Var(id) => Set(id) - case App(f, arg) => fv(f) ++ fv(arg) - case Abs(b, _, e) => fv(e) -- Set(b) - } - - def subst(in: Expr, v: Id, by: Expr): Expr = { - in match { - case Var(id) => { - if (id==v) by - else in - } - case App(f, arg) => App(subst(f, v, by), subst(arg, v, by)) - case Abs(b, tpe, e) => { - if (b==v) in - else { // ADD CHECK FOR CAPTURE HERE - Abs(b, tpe, subst(e, v, by)) - } - } - } - } - - def id1 = Id(BigInt(1)) - def id2 = Id(BigInt(2)) - def exprId = Abs(id1, Tind, Var(id1)) - - abstract class Outcome - case class Ok(v: Expr) extends Outcome - case class Err(s: String, sub: Expr) extends Outcome - - def CBV(env: Env, e: Expr): Outcome = { - e match { - case Var(id) => { env.binds.get(id) match { - case None() => Err("Unknown identifier in environment", e) - case Some(expr) => Ok(expr) - }} - case Abs(b, tpe, body) => Ok(e) - case App(f, arg) => { CBV(env, f) match { - case Ok(Abs(b, t, fbody)) => { CBV(env, arg) match { - case Ok(argv) => CBV(env, subst(fbody, b, argv)) - case err => err - }} - case Ok(expr) => Err("Tried to apply non-function value", expr) - case err => err - }} - } - } - - def env1 : Env = Env(Map[Id,Expr](id2 -> Var(id2))) - def r1 = CBV(env1, App(exprId, Var(id2))) - - def substOk(in: Expr, v: Id, by: Expr, env: Env): Boolean = { - val vRes= CBV(env, Var(v)) - val byRes= CBV(env, by) - val inRes= CBV(env, in) - if (vRes==byRes && vRes.isInstanceOf[Ok] && inRes.isInstanceOf[Ok]) { - inRes==CBV(env, subst(in, v, by)) - } else true - }.holds - -} - diff --git a/testcases/verification/case-studies/Robot3po.scala b/testcases/verification/case-studies/Robot3po.scala deleted file mode 100644 index b189db5e98852b61f9463232d1036a5fa519a8aa..0000000000000000000000000000000000000000 --- a/testcases/verification/case-studies/Robot3po.scala +++ /dev/null @@ -1,673 +0,0 @@ -// Developed by Etienne Kneuss, 2015 -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -object Robot { - - // From top left - case class Position(x: BigInt, y: BigInt) { - def +(o: Orientation) = o match { - case North => Position(x, y-1) - case East => Position(x+1, y) - case South => Position(x, y+1) - case West => Position(x-1, y) - } - - def neighbors: List[Position] = { - List(this + North, this + East, this + South, this + West) - } - } - - abstract class Orientation { - def left = this match { - case North => West - case East => North - case South => East - case West => South - } - - def right = this match { - case North => East - case East => South - case South => West - case West => North - } - } - - case object North extends Orientation - case object East extends Orientation - case object South extends Orientation - case object West extends Orientation - - abstract class FireLevel { - def level: BigInt = this match { - case NoFire => 0 - case Fire1 => 1 - case Fire2 => 2 - case Fire3 => 3 - case Fire4 => 4 - case Fire5 => 5 - } - - def increase = this match { - case NoFire => NoFire - case Fire1 => Fire2 - case Fire2 => Fire3 - case Fire3 => Fire4 - case Fire4 => Fire5 - case Fire5 => Fire5 - } - - def temp:BigInt = level*100 - } - - case object NoFire extends FireLevel - case object Fire1 extends FireLevel - case object Fire2 extends FireLevel - case object Fire3 extends FireLevel - case object Fire4 extends FireLevel - case object Fire5 extends FireLevel - - case class World( - clock: BigInt, - dimentions: Position, - walls: Set[Position], - persons: Set[Position], - initFires: Set[Position], - rs: RobotState) { - - def personAt(pos: Position): Boolean = persons contains pos - - def wallAt(pos: Position): Boolean = walls contains pos - - def fireAt(pos: Position): FireLevel = { - val step = clock/50 - - if (wallAt(pos)) { - NoFire - } else if (initFires contains pos) { - fireLevel(clock/10+1) - } else if (step >= 1 && (pos.neighbors.exists { p => initFires contains p })) { - fireLevel((clock-50)/10+1) - } else { - NoFire - } - } - - def fireLevel(l: BigInt) = { - if (l <= 1) Fire1 - else if (l <= 2) Fire2 - else if (l <= 3) Fire3 - else if (l <= 4) Fire4 - else Fire5 - } - - def isWithinMap(p: Position): Boolean = { - p.x >= 0 && p.x < dimentions.x && - p.y >= 0 && p.y < dimentions.y - } - } - - - /******************************************************************* - * Engine Component - *******************************************************************/ - - case class EngineState(pos: Position, dim: Position, orient: Orientation) - - abstract class EngineTransition - case object EForward extends EngineTransition - case object ERotateLeft extends EngineTransition - case object ERotateRight extends EngineTransition - case object EIdle extends EngineTransition - - def engineStep(es: EngineState, t: EngineTransition) = t match { - case EForward => EngineState(es.pos + es.orient, es.dim, es.orient) - case ERotateRight => EngineState(es.pos, es.dim, es.orient.right) - case ERotateLeft => EngineState(es.pos, es.dim, es.orient.left) - case EIdle => es - } - - def engineSucc(es: EngineState): List[EngineTransition] = { - if ((es.pos.x <= 0 && es.orient == West) || - (es.pos.y <= 0 && es.orient == North) || - (es.pos.x >= es.dim.x && es.orient == East) || - (es.pos.y >= es.dim.y && es.orient == South)) { - List(ERotateLeft, ERotateRight, EIdle) - } else { - List(EForward, ERotateLeft, ERotateRight, EIdle) - } - } - - /******************************************************************* - * Navigation Sensor Component - *******************************************************************/ - - case class NavSensorState(wall: Option[Boolean], person: Option[Boolean]) { - def hasData = wall.isDefined && person.isDefined - - def validData(implicit w: World) = { - val posFront = w.rs.es.pos + w.rs.es.orient - - val wallOk = wall match { - case Some(wal) => wal == w.wallAt(posFront) - case None() => true - } - - val personOk = person match { - case Some(per) => per == w.personAt(posFront) - case None() => true - } - - wallOk && personOk - } - } - - abstract class NavSensorTransition - case object NSense extends NavSensorTransition - case object NForget extends NavSensorTransition - case object NIdle extends NavSensorTransition - - - def navSensorStep(ns: NavSensorState, t: NavSensorTransition)(implicit w: World) = t match { - case NSense => - // Driver call - val p = w.rs.es.pos + w.rs.es.orient - NavSensorState(Some(w.wallAt(p)), Some(w.personAt(p))) - - case NForget => - NavSensorState(None(), None()) - - case NIdle => - ns - } - - def navSensorSucc(ns: NavSensorState): List[NavSensorTransition] = { - if (ns.hasData) { - List(NForget, NIdle) - } else { - List(NSense, NIdle) - } - } - - /******************************************************************* - * Heat Sensor Component - *******************************************************************/ - - case class HeatSensorState(heat: Option[FireLevel]) { - def hasData = heat.isDefined - - def validData(implicit w: World) = { - heat match { - case Some(f) => - val realF = w.fireAt(w.rs.es.pos + w.rs.es.orient) - realF == f || realF == f.increase - case None() => - true - } - } - } - - abstract class HeatSensorTransition - case object HSense extends HeatSensorTransition - case object HForget extends HeatSensorTransition - case object HIdle extends HeatSensorTransition - - def heatSensorStep(hs: HeatSensorState, t: HeatSensorTransition)(implicit w: World) = t match { - case HSense => - // Driver call - val p = w.rs.es.pos+w.rs.es.orient - HeatSensorState(Some(w.fireAt(p))) - - case HForget => - HeatSensorState(None()) - - case HIdle => - hs - } - - def heatSensorSucc(hs: HeatSensorState): List[HeatSensorTransition] = { - if (hs.hasData) { - List(HForget, HIdle) - } else { - List(HSense, HIdle) - } - } - - /******************************************************************* - * Transmission Component - *******************************************************************/ - - case class TransmitterState(beacon: Option[Position]) { - def hasData = beacon.isDefined - } - - abstract class TransmitterTransition - case object TRepeat extends TransmitterTransition - case object TFound extends TransmitterTransition - case object TIdle extends TransmitterTransition - - def transmitterStep(ts: TransmitterState, es: EngineState, t: TransmitterTransition)(implicit w: World) = t match { - case TRepeat => - // Driver call to transmit - ts - - case TFound => - // Driver call to transmit - TransmitterState(Some(es.pos + es.orient)) - - case TIdle => - ts - } - - def transmitterSucc(ts: TransmitterState): List[TransmitterTransition] = { - if (ts.hasData) { - List(TRepeat, TFound) - } else { - List(TFound, TIdle) - } - } - - - /******************************************************************* - * Robot Component - *******************************************************************/ - - case class RobotState( - es: EngineState, - ns: NavSensorState, - hs: HeatSensorState, - ts: TransmitterState - ) - - case class RobotTransition( - et: EngineTransition, - nst: NavSensorTransition, - hst: HeatSensorTransition, - tt: TransmitterTransition - ) - - def robotSucc(rs: RobotState): List[RobotTransition] = { - val ess = engineSucc(rs.es) - val nss = navSensorSucc(rs.ns) - val hss = heatSensorSucc(rs.hs) - val ts = transmitterSucc(rs.ts) - - filterValid(rs, ||(ess, nss, hss, ts)) - } ensuring { - res => allValid(rs, res) - } - - def robotStep(rs: RobotState, rt: RobotTransition)(implicit w: World): RobotState = { - RobotState( - engineStep(rs.es, rt.et), - navSensorStep(rs.ns, rt.nst), - heatSensorStep(rs.hs, rt.hst), - transmitterStep(rs.ts, rs.es, rt.tt) - ) - } - - // Can wistand up to 300 degrees - def safetyTemp:BigInt = 300 - - // Temperature can increase by at most 100 degree while the robot moves - def dTempMax:BigInt = 100 - - // Glue that compose sensors, transmitter and engine to perform valid actions - def validTransition(rs: RobotState, rt: RobotTransition): Boolean = { - - // 6) Sensors must be based on recent data - val freshSensors = if (rt.et == EForward || rt.et == ERotateRight || rt.et == ERotateLeft) { - rt.nst == NForget && rt.hst == HForget - } else { - true - } - - val freshSensors2 = if(rs.hs.hasData) { - rt.hst == HForget - } else { - true - } - - // 2/3) We can move forward only if no wall was detected - val forwardIfNoWall = (!(rt.et == EForward) || rs.ns.wall == Some(false)) - - // 3) We don't exit the world - val forwardIfNotOutOfMap = if (rt.et == EForward) { - (rs.es.pos.x > 0 || rs.es.orient != West) && - (rs.es.pos.y > 0 || rs.es.orient != North) && - (rs.es.pos.x < rs.es.dim.x-1 || rs.es.orient != East) && - (rs.es.pos.y < rs.es.dim.y-1 || rs.es.orient != South) - } else { - true - } - - // 4) We can move forward only if the cell is within heat limits - val forwardIfNotHot = (!(rt.et == EForward) || rs.hs.heat.getOrElse(Fire5).temp <= safetyTemp-dTempMax*2) - - // 5) If we found, we read the position and transmit - val transmitIfFound = if (rs.ns.person == Some(true)) { - rt.tt == TFound - } else { - rt.tt == TRepeat || rt.tt == TIdle - } - - forwardIfNotOutOfMap && freshSensors && freshSensors2 && forwardIfNoWall && forwardIfNotHot && transmitIfFound - } - - def validWorld(implicit w: World): Boolean = { - val dim = w.dimentions - - dim.x > 0 && dim.y > 0 && dim == w.rs.es.dim && - w.isWithinMap(w.rs.es.pos) && - w.clock >= 0 - } - - def validState(rs: RobotState)(implicit w: World): Boolean = { - - // 6) Sensors have consistent data - val recentData = rs.ns.validData && rs.hs.validData - - // 2/3) We don't end up in a wall - val notInWall = !w.wallAt(rs.es.pos) - - // 2) We are in the map - val inMap = w.isWithinMap(rs.es.pos) - - validWorld && recentData && notInWall && inMap - } - - def validRobotStep(from: RobotState, to: RobotState)(implicit w: World): Boolean = { - val posFrom = from.es.pos - val posFromFront = from.es.pos + from.es.orient - val posTo = to.es.pos - val posToFront = to.es.pos +to.es.orient - - // 1) Robot must not rotate and move at the same time - val dontRotateAndMove = (from.es.pos == to.es.pos) || (from.es.orient == to.es.orient) - - // 4) We don't move to a cell that is too hot - val dontBeCrazy = (posFrom == posTo) || (w.fireAt(posTo).temp <= safetyTemp) - - // 5) If we found somebody, we record its position for transmission - val transmitWhenFound = (from.ns.person != Some(true)) || (to.ts.beacon == Some(posFromFront)) - - dontRotateAndMove && dontBeCrazy && transmitWhenFound - } - - def filterValid(rs: RobotState, rts: List[RobotTransition]): List[RobotTransition] = (rts match { - case Cons(rt, rtt) => - val ts = filterValid(rs, rtt) - - if (validTransition(rs, rt)) { - Cons(rt, ts) - } else { - ts - } - case Nil() => Nil[RobotTransition]() - }) ensuring { - res => allValid(rs, res) - } - - def allValid(rs: RobotState, rts: List[RobotTransition]): Boolean = rts match { - case Cons(rt, rtt) => validTransition(rs, rt) && allValid(rs, rtt) - case Nil() => true - } - - def worldStep(w: World): World = { - World(w.clock + 1, w.dimentions, w.walls, w.persons, w.initFires, w.rs) - } ensuring { - w2 => - w.fireAt(w2.rs.es.pos).level <= w2.fireAt(w2.rs.es.pos).level && - w2.fireAt(w2.rs.es.pos).level <= w.fireAt(w2.rs.es.pos).level+1 - } - - def fireEvolution(from: FireLevel, to: FireLevel): Boolean = { - (from.temp <= to.temp) && - (to.temp <= from.temp + dTempMax) - } - - def searchAlgorithm(rs: RobotState): EngineTransition = { - // Make a suggestion based on whatever kwnoledge you have, here we favor going forward - EForward - } - - def getBestTransition(rs: RobotState, ls: List[RobotTransition]): Option[RobotTransition] = { - require(allValid(rs, ls)) - - if (ls.isEmpty) { - None[RobotTransition]() - } else { - val sugg = searchAlgorithm(rs) - - ls.find(rt => (rt.et == sugg) && validTransition(rs, rt)).orElse { - Some(ls.head) - } - } - } ensuring { - res => res match { - case Some(t) => - (ls.content contains t) && validTransition(rs, t) - case None() => - ls.isEmpty - } - } - - def step(rs: RobotState)(implicit w: World) = { - require(validState(rs) && w.rs == rs) - - val transitions = robotSucc(rs) - - val ort = getBestTransition(rs, transitions) - - val nextRs = ort match { - case Some(rt) => - robotStep(rs, rt) - - case None() => - rs - } - - (nextRs, ort) - } ensuring { - res => - val (rs2, ort) = res; - validState(rs2) && - (ort match { - case Some(rt) => - validRobotStep(rs, rs2) - case None() => - true - - }) - } - - def globalSafe(implicit w: World): World = { - require(validState(w.rs)) - - // One step for the robot - val (rs2, otr) = step(w.rs) - - // One step for mankind - worldStep(World(w.clock, w.dimentions, w.walls, w.persons, w.initFires, rs2)) - } ensuring { - w2 => - val heatOk = if (w.rs.es.pos == w2.rs.es.pos) { - true - } else { - w2.fireAt(w2.rs.es.pos).temp <= safetyTemp - } - - // 2/3) We don't end up in a wall - val notInWall = !w2.wallAt(w2.rs.es.pos) - - // 2) We are in the map - val inMap = w2.isWithinMap(w2.rs.es.pos) - - heatOk && notInWall && inMap - } - - - @ignore - def main(a: Array[String]): Unit = { - val map0 = """|XXXXXXXXX - |XR FF X - |X PXXXX - |XXX F F X - |X X X - |XX FPXXXXX - |XXXXXX""".stripMargin - - val map1 = """|XXXXXXXXXXXXX - |X R X - |XP X X - |X X X - |X XXXXXXX X - |X PX X - |X X X - |XFF X X - |XXXXXXXXXXXXX""".stripMargin - - var initPos: Position = Position(0, 0) - - var walls = Set[Position]() - var mission = Set[Position]() - var persons = Set[Position]() - var fires = Set[Position]() - - for ((line, y) <- map1.split("\n").toSeq.zipWithIndex; - (c, x) <- line.zipWithIndex) { - - val p = Position(x, y) - - c match { - case 'R' => - initPos = p - - case 'X' => - walls += p - - case 'F' => - fires += p - - case 'P' => - persons += p - - case ' ' => - } - - if (c != 'X') { - mission += p - } - } - - - val dim = Position(walls.theSet.map(_.x).max+1, walls.theSet.map(_.y).max+1) - - val es = EngineState(initPos, dim, North) - val ns = NavSensorState(None(), None()) - val hs = HeatSensorState(None()) - val t = TransmitterState(None()) - - val rs = RobotState(es, ns, hs, t) - - implicit var w = World(0, dim, walls, persons, fires, rs) - - while(w.clock < 110) { - print("\u001b[2J") - val (rs2, otr) = step(w.rs) - w = w.copy(rs = rs2) - w = worldStep(w) - draw(w, otr) - Thread.sleep(120l) - } - } - - @ignore - def draw(w: World, ogt: Option[RobotTransition]): Unit = { - val rs = w.rs - - def navSens(ns: NavSensorState): String = { - ns.wall.map(v => if (v) "X" else "_").getOrElse("?") - } - - val o = (rs.es.orient match { - case North => "^" - case East => ">" - case South => "v" - case West => "<" - })+" "+rs.es.pos.x+","+rs.es.pos.y - - print("Last Action: ") - ogt match { - case Some(gt) => - println(s"E: ${gt.et}, NS: ${gt.nst}, HS: ${gt.hst}, T: ${gt.tt}") - - case None() => - println("<stuck>") - } - println() - println(s"World Clock: ${w.clock}") - println() - println("Robot State: ") - println(s" - Engine : ${rs.es}") - println(s" - Nav Sensor : ${rs.ns}") - println(s" - Heat Sensor : ${rs.hs}") - println(s" - Transmitter : ${rs.ts}") - - println() - println("Map:") - println() - - val colors = List(52, 124, 1, 160, 196); - - for (y <- BigInt(0) until w.dimentions.y) { - for(x <- BigInt(0) until w.dimentions.x) { - - val p = Position(x, y) - - val f = w.fireAt(p) - if (f != NoFire) { - val code = colors(f.level-1) - print("\u001b[48;5;"+code+"m") - } - - if (w.walls contains p) { - print("\u2593") - } else if (rs.es.pos == p) { - print((rs.es.orient match { - case North => "^" - case South => "v" - case East => ">" - case West => "<" - })) - } else if (w.persons contains p) { - print("P") - } else { - print(" ") - } - - if (f != NoFire) { - print(Console.RESET) - } - - } - println - } - } - - def ||(ets: List[EngineTransition], - nsts: List[NavSensorTransition], - hsts: List[HeatSensorTransition], - tts: List[TransmitterTransition]): List[RobotTransition] = { - - for { - et <- ets - nst <- nsts - hst <- hsts - tt <- tts - } yield RobotTransition(et, nst, hst, tt) - - } -} diff --git a/testcases/verification/case-studies/Sync.scala b/testcases/verification/case-studies/Sync.scala deleted file mode 100644 index abb9adea549342b3e3783aa53370e9eb7ab3c3c6..0000000000000000000000000000000000000000 --- a/testcases/verification/case-studies/Sync.scala +++ /dev/null @@ -1,95 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.collection._ - -case class Entry(id: Int, version: Int, versionSynced: Int, f1: Int, f2: Int) { - def update(f1: Int, f2: Int): Entry = { - Entry(id, version+1, versionSynced, f1, f2) - } - def markSynced = { - Entry(id, version, version, f1, f2) - } ensuring { _.isSynced } - - def isSynced = { - version == versionSynced - } -} - -object Sync { - def idSorted(l: List[Entry]): Boolean = l match { - case Cons(v1, Cons(v2, xs)) => v1.id < v2.id && idSorted(Cons(v2, xs)) - case _ => true - } - - // Raw content (ignoring version/versionSynced) - def content(l: List[Entry]): Set[(Int, Int, Int)] = l match { - case Cons(h, t) => Set((h.id, h.f1, h.f2)) ++ content(t) - case Nil() => Set() - } - - def ids(l: List[Entry]): Set[Int] = l match { - case Cons(h, t) => Set(h.id) ++ ids(t) - case _ => Set() - } - - def markSynced(l1: List[Entry]): List[Entry] = { - require(idSorted(l1)) - (l1 match { - case Cons(e1, t1) => Cons(e1.markSynced, markSynced(t1)) - case Nil() => Nil() - }) : List[Entry] - } ensuring { res => - idSorted(res) && - content(res) == content(l1) && - ids(res) == ids(l1) && - allSynced(res) - } - - def allSynced(l1: List[Entry]): Boolean = { - l1 match { - case Cons(h1, t1) => h1.isSynced && allSynced(t1) - case Nil() => true - } - } - - def sync(v1: List[Entry], v2: List[Entry]): List[Entry] = { - require(idSorted(v1) && idSorted(v2)) - - ((v1, v2) match { - case (Cons(e1, t1), Cons(e2, t2)) => - if (e1.id < e2.id) { - Cons(e1.markSynced, sync(t1, v2)) - } else if (e1.id > e2.id) { - Cons(e2.markSynced, sync(v1, t2)) - } else { - if (e1.version > e2.version) { - Cons(e1.markSynced, sync(t1, t2)) - } else { - Cons(e2.markSynced, sync(t1, t2)) - } - } - case (Nil(), l2) => markSynced(l2) - case (l1, Nil()) => markSynced(l1) - }): List[Entry] - - } ensuring { - res => - idSorted(res) && - (content(res) subsetOf (content(v1) ++ content(v2))) && - (ids(res) == ids(v1) ++ ids(v2)) && - allSynced(res) - } - - - def test() = { - val e1 = Entry(1, 1, 0, 1, 1) - val e2 = Entry(2, 1, 0, 2, 2) - val e3 = Entry(3, 1, 0, 3, 3) - - val l1 = Cons(e1, Cons(e2, Nil())) - val l2 = Cons(e2.update(5, 5), Cons(e3, Nil())) - - sync(l1, l2) - } -} - diff --git a/testcases/verification/case-studies/TreePaths.scala b/testcases/verification/case-studies/TreePaths.scala deleted file mode 100644 index 4e7f537dcc9f73f87ad9b0984716aaf058a79880..0000000000000000000000000000000000000000 --- a/testcases/verification/case-studies/TreePaths.scala +++ /dev/null @@ -1,179 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.collection._ -import leon.annotation._ -object Tree { - sealed abstract class Tree - case object Empty extends Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - - sealed abstract class Dir - case object Left extends Dir - case object Right extends Dir - - def nil[A]: List[A] = Nil[A] - def cons[A](x: A, lst: List[A]): List[A] = Cons[A](x,lst) - def some[A](x: A): Option[A] = Some[A](x) - def none[A]: Option[A] = None[A] - - case class Path(p: List[Dir]) extends AnyVal - def pnil = Path(nil) - - def inside(t: Tree, subtree: Tree): Boolean = { - if (t==subtree) true - else { - t match { - case Empty => false - case Node(left,_,right) => inside(left, subtree) || inside(right, subtree) - } - } - } - - def lookup(t: Tree, path : Path): Option[Tree] = { - (t,path.p) match { - case (_,Nil()) => some(t) - case (Empty,_) => none - case (Node(left,_,_), Cons(Left,rest)) => lookup(left,Path(rest)) - case (Node(_,_,right), Cons(Right,rest)) => lookup(right,Path(rest)) - } - } - - def valid(t: Tree, path: Path): Boolean = { - lookup(t, path) != none[Tree] - } - - // Function find1 has a counterexample. - def find1(t: Tree, subtree: Tree): Option[Path] = ({ - if (t==subtree) some(pnil) - else { - t match { - case Empty => none - case Node(left,_,right) => { - find1(left,subtree) match { - case None() => find1(right,subtree) - case v => v - } - } - } - } - }: Option[Path]).ensuring(res => (res match { - case None() => !inside(t, subtree) - case Some(path) => lookup(t, path)==Some(subtree) - })) - - // Function find is correct - def find(t: Tree, subtree: Tree): Option[Path] = ({ - if (t==subtree) some(pnil) - else { - t match { - case Empty => none - case Node(left,_,right) => { - find(left,subtree) match { - case None() => { find(right,subtree) match { - case None() => None() - case Some(Path(p)) => Some(Path(cons(Right,p))) - }} - case Some(Path(p)) => Some(Path(cons(Left, p))) - } - } - } - } - }: Option[Path]).ensuring(res => (res match { - case None() => !inside(t, subtree) - case Some(path) => lookup(t, path)==Some(subtree) - })) - - def replace(t: Tree, path: Path, newT: Tree): Tree = { - require(valid(t,path)) - (t,path.p) match { - case (_,Nil()) => newT - case (Node(left,v,right), Cons(Left, rest)) => Node(replace(left,Path(rest), newT), v, right) - case (Node(left,v,right), Cons(Right,rest)) => Node(left, v, replace(right, Path(rest), newT)) - } - } ensuring(res => lookup(res, path)==some(newT)) - - /* This has a counterexample, e.g. - path -> Path(Cons[Dir](Left, Cons[Dir](Left, Nil[Dir]()))) - path1 -> Path(Nil[Dir]()) - t -> Empty - */ - def replaceKeepsLemmaInvalid1(t: Tree, path: Path, newT: Tree, path1: Path): Boolean = { - require(path != path1) - lookup(replace(t, path, newT), path1)==lookup(t, path1) - } - - def prefix(p1: Path, p2: Path): Boolean = { - (p1.p, p2.p) match { - case (Nil(),_) => true - case (h1 :: r1, h2 :: r2) => { - (h1==h2) && prefix(Path(r1), Path(r2)) - } - } - } - - def replaceKeepsLemmaInvalid2(t: Tree, path: Path, newT: Tree, path1: Path): Boolean = { - require(!prefix(path1, path)) - lookup(replace(t, path, newT), path1)==lookup(t, path1) - }.holds - - //@induct - def replaceKeepsLemma(t: Tree, path: Path, newT: Tree, path1: Path): Boolean = { - require(valid(t, path) && !prefix(path, path1)) - lookup(replace(t, path, newT), path1)==lookup(t, path1) - }.holds - - case class Flat(trees: List[(Path, Tree)]) extends AnyVal - - def fnil = Flat(nil[(Path,Tree)]) - - def subtrees(t: Tree): Flat = { - t match { - case Empty => fnil - case Node(left,v,right) => - Flat(addLeft(subtrees(left)).trees ++ ((pnil,t) :: addRight(subtrees(right)).trees)) - } - } - def addLeft(f: Flat): Flat = { - f.trees match { - case Nil() => fnil - case (p,t) :: trees1 => Flat((Path(Left::p.p),t) :: addLeft(Flat(trees1)).trees) - } - } - def addRight(f: Flat): Flat = { - f.trees match { - case Nil() => fnil - case (p,t) :: trees1 => Flat((Path(Right::p.p),t) :: addRight(Flat(trees1)).trees) - } - } - - def unflat(f: Flat) : Option[Tree] = { - // TO IMPLEMENT - ???[Option[Tree]] - } ensuring(res => res match { - case None() => true - case Some(t) => equiv(subtrees(t), f) - }) - - def equiv(f1: Flat, f2: Flat): Boolean = { - f1.trees.content == f2.trees.content - } - -/* - def unsomep(po: Option[Path]): Path = { - require() - } - - def diff(t1: Tree, t2: Tree): Option[Path] = { - (t1, t2) match { - case (Empty, Empty) => none - case (Empty,Node(_,_,_)) => some(pnil) - case (Node(_,_,_),Empty) => some(pnil) - case (Node(l1,v1,r1),Node(l2,v2,r2)) => { - if (v1 != v2) some(pnil) - else if (l1==l2) Path(cons(Right,diff(r1,r2).p)) - else if (r1==r2) Path(cons(Left, diff(l1,l2).p)) - } - } - } - */ -} diff --git a/testcases/verification/compilation/ExprCompiler.scala b/testcases/verification/compilation/ExprCompiler.scala deleted file mode 100644 index d6b7d74caa52a4a49255e71781c86f1052c439db..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/ExprCompiler.scala +++ /dev/null @@ -1,85 +0,0 @@ -import leon.lang._ -import leon.lang.Option -import leon.collection._ -import leon.annotation._ -import leon.proof._ -import leon.lang.synthesis._ - -object TinyCertifiedCompiler { - abstract class ByteCode[A] - case class Load[A](c: A) extends ByteCode[A] // loads a constant in to the stack - case class OpInst[A]() extends ByteCode[A] - - abstract class ExprTree[A] - case class Const[A](c: A) extends ExprTree[A] - case class Op[A](e1: ExprTree[A], e2: ExprTree[A]) extends ExprTree[A] - - def compile[A](e: ExprTree[A]): List[ByteCode[A]] = { - e match { - case Const(c) => - Cons(Load(c), Nil()) - case Op(e1, e2) => - (compile(e1) ++ compile(e2)) ++ Cons(OpInst(), Nil()) - } - } - - def op[A](x: A, y: A): A = { // uninterpreted - ???[A] - } - - def run[A](bytecode: List[ByteCode[A]], S: List[A]): List[A] = { - (bytecode, S) match { - case (Cons(Load(c), tail), _) => - run(tail, c :: S) // adding elements to the head of the stack - case (Cons(OpInst(), tail), Cons(x, Cons(y, rest))) => - run(tail, op(y, x) :: rest) - case (Cons(_, tail), _) => - run(tail, S) - case (Nil(), _) => // no bytecode to execute - S - } - } - - def interpret[A](e: ExprTree[A]): A = { - e match { - case Const(c) => c - case Op(e1, e2) => op(interpret(e1), interpret(e2)) - } - } - - def runAppendLemma[A](l1: List[ByteCode[A]], l2: List[ByteCode[A]], S: List[A]): Boolean = { - // lemma - (run(l1 ++ l2, S) == run(l2, run(l1, S))) because - // induction scheme (induct over l1) - (l1 match { - case Nil() => true - case Cons(h, tail) => - (h, S) match { - case (Load(c), _) => - runAppendLemma(tail, l2, Cons[A](c, S)) - case (OpInst(), Cons(x, Cons(y, rest))) => - runAppendLemma(tail, l2, Cons[A](op(y, x), rest)) - case (_, _) => - runAppendLemma(tail, l2, S) - case _ => true - } - }) - }.holds - - def compileInterpretEquivalenceLemma[A](e: ExprTree[A], S: List[A]): Boolean = { - // lemma - (run(compile(e), S) == interpret(e) :: S) because - // induction scheme - (e match { - case Const(c) => true - case Op(e1, e2) => - // lemma instantiation - val c1 = compile(e1) - val c2 = compile(e2) - runAppendLemma((c1 ++ c2), Cons[ByteCode[A]](OpInst[A](), Nil()), S) && - runAppendLemma(c1, c2, S) && - compileInterpretEquivalenceLemma(e1, S) && - compileInterpretEquivalenceLemma(e2, Cons[A](interpret(e1), S)) - }) - }.holds -} diff --git a/testcases/verification/compilation/ForElimination.scala b/testcases/verification/compilation/ForElimination.scala deleted file mode 100644 index be5f6a6910c762644d347f1318f5de2e52cb30ff..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/ForElimination.scala +++ /dev/null @@ -1,121 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object ForElimination { - - sealed abstract class List - case class Nil() extends List - case class Cons(head: Statement, tail: List) extends List - - sealed abstract class Statement - case class Print(msg: Int, varID: Int) extends Statement - case class Assign(varID: Int, expr: Expression) extends Statement - case class Skip() extends Statement - case class Block(body: List) extends Statement - case class IfThenElse(expr: Expression, thenn: Statement, elze: Statement) extends Statement - case class While(expr: Expression, body: Statement) extends Statement - case class For(init: Statement, expr: Expression, step: Statement, body: Statement) extends Statement - - sealed abstract class Expression - case class Var(varID: Int) extends Expression - case class IntLiteral(value: Int) extends Expression - case class Plus(lhs: Expression, rhs: Expression) extends Expression - case class Minus(lhs: Expression, rhs: Expression) extends Expression - case class Times(lhs: Expression, rhs: Expression) extends Expression - case class Division(lhs: Expression, rhs: Expression) extends Expression - case class Modulo(lhs: Expression, rhs: Expression) extends Expression - case class Equals(lhs: Expression, rhs: Expression) extends Expression - case class GreaterThan(lhs: Expression, rhs: Expression) extends Expression - case class LessThan(lhs: Expression, rhs: Expression) extends Expression - case class And(lhs: Expression, rhs: Expression) extends Expression - case class Or(lhs: Expression, rhs: Expression) extends Expression - case class Neg(expr: Expression) extends Expression - case class Not(expr: Expression) extends Expression - - def forLoopsWellFormedList(l: List): Boolean = l match { - case Nil() => true - case Cons(x, xs) => forLoopsWellFormed(x) && forLoopsWellFormedList(xs) - } - - def forLoopsWellFormed(stat: Statement): Boolean = (stat match { - case Block(body) => forLoopsWellFormedList(body) - case IfThenElse(_, thenn, elze) => forLoopsWellFormed(thenn) && forLoopsWellFormed(elze) - case While(_, body) => forLoopsWellFormed(body) - case For(init, _, step, body) => isForFree(init) && isForFree(step) && forLoopsWellFormed(body) - case _ => true - }) - - def eliminateWhileLoopsList(l: List): List = { - l match { - case Nil() => Nil() - case Cons(x, xs) => Cons(eliminateWhileLoops(x), eliminateWhileLoopsList(xs)) - } - } ensuring(isWhileFreeList(_)) - - def eliminateWhileLoops(stat: Statement): Statement = (stat match { - case Block(body) => Block(eliminateWhileLoopsList(body)) - case IfThenElse(expr, thenn, elze) => IfThenElse(expr, eliminateWhileLoops(thenn), eliminateWhileLoops(elze)) - case While(expr, body) => For(Skip(), expr, Skip(), eliminateWhileLoops(body)) - case For(init, expr, step, body) => For(eliminateWhileLoops(init), expr, eliminateWhileLoops(step), eliminateWhileLoops(body)) - case other => other - }) ensuring(isWhileFree(_)) - - def eliminateForLoopsList(l: List): List = { - // require(forLoopsWellFormedList(l)) - l match { - case Nil() => Nil() - case Cons(x, xs) => Cons(eliminateForLoops(x), eliminateForLoopsList(xs)) - } - } ensuring(isForFreeList(_)) - - @induct - def eliminateForLoops(stat: Statement): Statement = { - // require(forLoopsWellFormed(stat)) - stat match { - case Block(body) => Block(eliminateForLoopsList(body)) - case IfThenElse(expr, thenn, elze) => IfThenElse(expr, eliminateForLoops(thenn), eliminateForLoops(elze)) - case While(expr, body) => While(expr, eliminateForLoops(body)) - case For(init, expr, step, body) => Block(Cons(eliminateForLoops(init), Cons(While(expr, Block(Cons(eliminateForLoops(body), Cons(eliminateForLoops(step), Nil())))), Nil()))) - case other => other - } - } ensuring(isForFree(_)) - - def isWhileFreeList(l: List): Boolean = l match { - case Nil() => true - case Cons(x, xs) => isWhileFree(x) && isWhileFreeList(xs) - } - - def isWhileFree(stat: Statement): Boolean = stat match { - case Block(body) => isWhileFreeList(body) - case IfThenElse(_, thenn, elze) => isWhileFree(thenn) && isWhileFree(elze) - case While(_, body) => false - case For(init,_,step,body) => isWhileFree(init) && isWhileFree(step) && isWhileFree(body) - case _ => true - } - - def isForFreeList(l: List): Boolean = l match { - case Nil() => true - case Cons(x, xs) => isForFree(x) && isForFreeList(xs) - } - - def isForFree(stat: Statement): Boolean = stat match { - case Block(body) => isForFreeList(body) - case IfThenElse(_, thenn, elze) => isForFree(thenn) && isForFree(elze) - case While(_, body) => isForFree(body) - case For(_,_,_,_) => false - case _ => true - } - - @induct - def forFreeEntailsWellFormed(stat: Statement): Boolean = { - require(isForFree(stat)) - forLoopsWellFormed(stat) - } // holds - - @induct - def eliminationIsStable(stat: Statement): Boolean = { - require(isWhileFree(stat)) - eliminateWhileLoops(stat) == stat - } holds - -} diff --git a/testcases/verification/compilation/IntExprCompiler.scala b/testcases/verification/compilation/IntExprCompiler.scala deleted file mode 100644 index b7f46a49a27cf4092518afa08f0cef5ff8f724c7..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/IntExprCompiler.scala +++ /dev/null @@ -1,107 +0,0 @@ -import leon.lang._ -import leon.lang.Option -import leon.collection._ -import leon.annotation._ -import leon.proof._ - -object TinyCertifiedCompiler { - - abstract class ByteCode - case class Load(c: BigInt) extends ByteCode // loads a constant in to the stack - case class OpInst() extends ByteCode - - abstract class ExprTree - case class Const(c: BigInt) extends ExprTree - case class Op(e1: ExprTree, e2: ExprTree) extends ExprTree - - def compile(e: ExprTree): List[ByteCode] = { - e match { - case Const(c) => - Cons(Load(c), Nil[ByteCode]()) - case Op(e1, e2) => - (compile(e1) ++ compile(e2)) ++ Cons(OpInst(), Nil[ByteCode]()) - } - } - - def op(x: BigInt, y: BigInt): BigInt = { - x - y - } - - def run(bytecode: List[ByteCode], S: List[BigInt]): List[BigInt] = { - (bytecode, S) match { - case (Cons(Load(c), tail), _) => - run(tail, Cons[BigInt](c, S)) // adding elements to the head of the stack - case (Cons(OpInst(), tail), Cons(x, Cons(y, rest))) => - run(tail, Cons[BigInt](op(y, x), rest)) - case (Cons(_, tail), _) => - run(tail, S) - case (Nil(), _) => // no bytecode to execute - S - } - } - - def interpret(e: ExprTree): BigInt = { - e match { - case Const(c) => c - case Op(e1, e2) => - op(interpret(e1), interpret(e2)) - } - } - - def runAppendLemma(l1: List[ByteCode], l2: List[ByteCode], S: List[BigInt]): Boolean = { - // lemma - (run(l1 ++ l2, S) == run(l2, run(l1, S))) because - // induction scheme (induct over l1) - (l1 match { - case Nil() => - true - case Cons(h, tail) => - (h, S) match { - case (Load(c), _) => - runAppendLemma(tail, l2, Cons[BigInt](c, S)) - case (OpInst(), Cons(x, Cons(y, rest))) => - runAppendLemma(tail, l2, Cons[BigInt](op(y, x), rest)) - case (_, _) => - runAppendLemma(tail, l2, S) - case _ => - true - } - }) - }.holds - - def run1(bytecode: List[ByteCode], S: List[BigInt]): List[BigInt] = { - (bytecode, S) match { - case (Cons(Load(c), tail), _) => - run1(tail, Cons[BigInt](c, S)) // adding elements to the head of the stack - case (Cons(OpInst(), tail), Cons(x, Cons(y, rest))) => - run1(tail, Cons[BigInt](op(x, y), rest)) - case (Cons(_, tail), _) => - run1(tail, S) - case (Nil(), _) => // no bytecode to execute - S - } - } - - def compileInterpretEquivalenceLemma1(e: ExprTree, S: List[BigInt]): Boolean = { - // lemma - (run1(compile(e), S) == interpret(e) :: S) - } holds - - def compileInterpretEquivalenceLemma(e: ExprTree, S: List[BigInt]): Boolean = { - // lemma - (run(compile(e), S) == interpret(e) :: S) because - // induction scheme - (e match { - case Const(c) => - true - case Op(e1, e2) => - // lemma instantiation - val c1 = compile(e1) - val c2 = compile(e2) - runAppendLemma((c1 ++ c2), Cons(OpInst(), Nil[ByteCode]()), S) && - runAppendLemma(c1, c2, S) && - compileInterpretEquivalenceLemma(e1, S) && - compileInterpretEquivalenceLemma(e2, Cons[BigInt](interpret(e1), S)) - }) - } holds -} diff --git a/testcases/verification/compilation/Interpreter.scala b/testcases/verification/compilation/Interpreter.scala deleted file mode 100644 index 1c8e3bbde2b6dc18ba42211f2bfc498a0bcfaf71..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/Interpreter.scala +++ /dev/null @@ -1,64 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Interpret { - abstract class BoolTree - case class Eq(t1 : IntTree, t2 : IntTree) extends BoolTree - case class And(t1 : BoolTree, t2 : BoolTree) extends BoolTree - case class Not(t : BoolTree) extends BoolTree - - abstract class IntTree - case class Const(c:Int) extends IntTree - case class Var(index:Int) extends IntTree - case class Plus(t1 : IntTree, t2 : IntTree) extends IntTree - case class Minus(t1 : IntTree, t2 : IntTree) extends IntTree - case class Less(t1 : IntTree, t2 : IntTree) extends BoolTree - case class If(cond : BoolTree, t : IntTree, e : IntTree) extends IntTree - - def repOk(t : IntTree) : Boolean = { - true - } - - def beval(t:BoolTree, x0 : Int) : Boolean = { - t match { - case Less(t1, t2) => ieval(t1,x0) < ieval(t2,x0) - case Eq(t1, t2) => ieval(t1,x0) == ieval(t2,x0) - case And(t1, t2) => beval(t1,x0) && beval(t2,x0) - case Not(t1) => !beval(t1,x0) - } - } - - def ieval(t:IntTree, x0 : Int) : Int = { - t match { - case Const(c) => c - case Var(v) => if (v == 0) x0 else 0 - case Plus(t1,t2) => ieval(t1,x0) + ieval(t2,x0) - case Minus(t1, t2) => ieval(t1,x0) - ieval(t2,x0) - case If(c,t1,t2) => if (beval(c,x0)) ieval(t1,x0) else ieval(t2,x0) - } - } - def computesPositive(t : IntTree) : Boolean = { - ieval(t,0) >= 0 && - ieval(t,1) >= 0 && -// ieval(t,-1) >= 0 && -// ieval(t,-2) >= 0 && - ieval(t,2) >= 0 - } - def identityForPositive(t : IntTree) : Boolean = { - ieval(t, 5) == 5 && - ieval(t, 33) == 33 - } - - def treeBad(t : IntTree) : Boolean = { - !(repOk(t) && computesPositive(t) && identityForPositive(t)) - } holds - - def thereIsGoodTree() : Boolean = { - !treeBad(If(Less(Const(0),Var(0)), Var(0), Minus(Const(0),Var(0)))) - } holds - - @ignore - def main(args : Array[String]) { - thereIsGoodTree() - } -} diff --git a/testcases/verification/compilation/LambdaEval.scala b/testcases/verification/compilation/LambdaEval.scala deleted file mode 100644 index 84ecf4737b43fbca5ea229495e71d7e048089f88..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/LambdaEval.scala +++ /dev/null @@ -1,161 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object LambdaEval { - sealed abstract class Expr - case class Const(value: Int) extends Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class Lam(x: Int, body: Expr) extends Expr - case class Pair(fst: Expr, snd: Expr) extends Expr - case class Var(name: Int) extends Expr - case class App(lhs: Expr, rhs: Expr) extends Expr - case class Fst(e: Expr) extends Expr - case class Snd(e: Expr) extends Expr - - // Checks whether the expression is a value - def isValue(expr: Expr): Boolean = expr match { - case Const(_) => true - case Lam(_,_) => true - case Pair(e1, e2) => isValue(e1) && isValue(e2) - case Var(_) => false - case Plus(_,_) => false - case App(_,_) => false - case Fst(_) => false - case Snd(_) => false - } - - sealed abstract class List - case class Cons(head: BindingPairAbs, tail: List) extends List - case class Nil() extends List - - sealed abstract class BindingPairAbs - case class BindingPair(key: Int, value: Expr) extends BindingPairAbs - - sealed abstract class StoreExprPairAbs - case class StoreExprPair(store: List, expr: Expr) extends StoreExprPairAbs - - def storeElems(store: List) : Set[Int] = store match { - case Nil() => Set.empty[Int] - case Cons(BindingPair(k,_), xs) => Set(k) ++ storeElems(xs) - } - - def freeVars(expr: Expr) : Set[Int] = expr match { - case Const(_) => Set.empty[Int] - case Plus(l,r) => freeVars(l) ++ freeVars(r) - case Lam(x, bdy) => freeVars(bdy) -- Set(x) - case Pair(f,s) => freeVars(f) ++ freeVars(s) - case Var(n) => Set(n) - case App(l,r) => freeVars(l) ++ freeVars(r) - case Fst(e) => freeVars(e) - case Snd(e) => freeVars(e) - } - - def storeHasValues(store: List): Boolean = store match { - case Nil() => true - case Cons(BindingPair(k, v), ss) => isValue(v) && storeHasValues(ss) - } - - def contains(store: List, key: Int): Boolean = store match { - case Nil() => false - case Cons(BindingPair(k, v), xs) => k == key || contains(xs, key) - } - - // Find first element in list that has first component 'x' and return its - // second component, analogous to List.assoc in OCaml - def find(x: Int, l: List): Expr = { - require( - contains(l, x) && - storeHasValues(l) - ) - l match { - case Cons(BindingPair(k,v), is) => if (k == x) v else find(x, is) - } - } ensuring(res => isValue(res)) - - def wellFormed(store: List, expr: Expr): Boolean = expr match { - case Const(_) => true - case Plus(e1, e2) => wellFormed(store, e1) && wellFormed(store, e2) && (eval(store, e1) match { - case StoreExprPair(_,Const(i1)) => - eval(store, e2) match { - case StoreExprPair(_,Const(i2)) => true - case _ => false - } - case _ => false - }) - case Lam(x, body) => wellFormed(Cons(BindingPair(x, Const(0)), store), body) - case Pair(e1, e2) => wellFormed(store, e1) && wellFormed(store, e2) - case Var(x) => contains(store, x) - case App(l, r) => wellFormed(store, l) && wellFormed(store, r) && (eval(store, l) match { - case StoreExprPair(_, Lam(_,_)) => true - case _ => false - }) - case Fst(e) => wellFormed(store, e) && (eval(store, e) match { - case StoreExprPair(_,Pair(e1, e2)) => true - case _ => false - }) - case Snd(e) => wellFormed(store, e) && (eval(store, e) match { - case StoreExprPair(_,Pair(e1, e2)) => true - case _ => false - }) - } - - // Evaluator - def eval(store: List, expr: Expr): StoreExprPairAbs = { - require( - wellFormed(store, expr) && - storeHasValues(store) - ) - - expr match { - case Const(i) => StoreExprPair(store, Const(i)) - case Var(x) => StoreExprPair(store, find(x, store)) - case Plus(e1, e2) => - val i1 = eval(store, e1) match { - case StoreExprPair(_, Const(i)) => i - } - val i2 = eval(store, e2) match { - case StoreExprPair(_, Const(i)) => i - } - StoreExprPair(store, Const(i1 + i2)) - case App(e1, e2) => - val store1 = eval(store, e1) match { - case StoreExprPair(resS,_) => resS - } - val x = eval(store, e1) match { - case StoreExprPair(_, Lam(resX, _)) => resX - } - val e = eval(store, e1) match { - case StoreExprPair(_, Lam(_, resE)) => resE - } - val v2 = eval(store, e2) match { - case StoreExprPair(_, v) => v - } - eval(Cons(BindingPair(x, v2), store1), e) - case Lam(x, e) => StoreExprPair(store, Lam(x, e)) - case Pair(e1, e2) => - val v1 = eval(store, e1) match { - case StoreExprPair(_, v) => v - } - val v2 = eval(store, e2) match { - case StoreExprPair(_, v) => v - } - StoreExprPair(store, Pair(v1, v2)) - case Fst(e) => - eval(store, e) match { - case StoreExprPair(_, Pair(v1, _)) => StoreExprPair(store, v1) - } - case Snd(e) => - eval(store, e) match { - case StoreExprPair(_, Pair(_, v2)) => StoreExprPair(store, v2) - } - } - } ensuring(res => res match { - case StoreExprPair(s, e) => storeHasValues(s) && isValue(e) - }) - - def property0() : Boolean = { - eval(Cons(BindingPair(358, Const(349)), Nil()), Const(1)) match { - case StoreExprPair(s, e) => isValue(e) - } - } holds -} diff --git a/testcases/verification/compilation/Parser.scala b/testcases/verification/compilation/Parser.scala deleted file mode 100644 index 8e580cbbba21fa9150e19677505cd744035e2c09..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/Parser.scala +++ /dev/null @@ -1,62 +0,0 @@ -object Parser { - sealed abstract class Token - case class IntLit(value : Boolean) extends Token - case class Plus() extends Token - case class Minus() extends Token - case class Times() extends Token - case class Div() extends Token - case class LParen() extends Token - case class RParen() extends Token - - sealed abstract class TokenList - case class Cons(head : Token, tail : TokenList) extends TokenList - case class Nil() extends TokenList - - def size(l : TokenList) : Int = (l match { - case Nil() => 0 - case Cons(x, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def append(l1 : TokenList, l2 : TokenList) : TokenList = (l1 match { - case Nil() => l2 - case Cons(t, ts) => Cons(t, append(ts, l2)) - }) ensuring(size(_) == size(l1) + size(l2)) - - sealed abstract class Tree - case class IntLitTree(value : Boolean) extends Tree - case class PlusTree(left : Tree, right : Tree) extends Tree - case class MinusTree(left : Tree, right : Tree) extends Tree - case class TimesTree(left : Tree, right : Tree) extends Tree - case class DivTree(left : Tree, right : Tree) extends Tree - - def treeSize(t : Tree) : Int = (t match { - case IntLitTree(_) => 1 - case PlusTree(l,r) => 1 + treeSize(l) + treeSize(r) - case MinusTree(l,r) => 1 + treeSize(l) + treeSize(r) - case TimesTree(l,r) => 1 + treeSize(l) + treeSize(r) - case DivTree(l,r) => 1 + treeSize(l) + treeSize(r) - }) ensuring(_ >= 0) - - def enclose(l : TokenList) : TokenList = - append(Cons(LParen(), l), Cons(RParen(), Nil())) - - def print(tree : Tree) : TokenList = tree match { - case IntLitTree(value) => Cons(IntLit(value), Nil()) - case PlusTree(l, r) => append(print(l), Cons(Plus(), print(r))) - case MinusTree(l, r) => append(print(l), Cons(Minus(), print(r))) - case TimesTree(l, r) => append(print(l), Cons(Times(), print(r))) - case DivTree(l, r) => append(print(l), Cons(Div(), print(r))) - } - - def printAlternative(tree : Tree, acc : TokenList) : TokenList = tree match { - case IntLitTree(value) => Cons(IntLit(value), acc) - case PlusTree(l, r) => printAlternative(l, Cons(Plus(), printAlternative(r, acc))) - case MinusTree(l, r) => printAlternative(l, Cons(Minus(), printAlternative(r, acc))) - case TimesTree(l, r) => printAlternative(l, Cons(Times(), printAlternative(r, acc))) - case DivTree(l, r) => printAlternative(l, Cons(Div(), printAlternative(r, acc))) - } - - def findTree(tree : Tree) : Boolean = { - print(tree) != Cons(IntLit(false), Cons(Plus(), Cons(IntLit(true), Nil()))) - } ensuring(res => res) -} diff --git a/testcases/verification/compilation/SemanticsPreservation.scala b/testcases/verification/compilation/SemanticsPreservation.scala deleted file mode 100644 index 0a10b118d235fb5f7d33f5309c782ea443415615..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/SemanticsPreservation.scala +++ /dev/null @@ -1,43 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object SemanticsPreservation { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Variable(id: Int) extends Formula - - @induct - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case n @ Not(_) => n - case v @ Variable(_) => v - }) ensuring(isNNF(_)) - - def isNNF(f: Formula): Boolean = f match { - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Not(_) => false - case Variable(_) => true - } - - @induct - def eval(formula: Formula): Boolean = (formula match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Variable(id) => id > 42 - }) ensuring(res => res == eval(nnf(formula))) - - @induct - def nnfPreservesSemantics(f: Formula): Boolean = { - eval(f) == eval(nnf(f)) - } holds - -} diff --git a/testcases/verification/compilation/SimpInterpret.scala b/testcases/verification/compilation/SimpInterpret.scala deleted file mode 100644 index 6c61bad49173ecc0ff9edafc432d11eb6ffbbadb..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/SimpInterpret.scala +++ /dev/null @@ -1,68 +0,0 @@ -//import scala.collection.immutable.Set -import leon.annotation._ -import leon.lang._ - -object Interpret { - abstract class BoolTree - case class Eq(t1 : IntTree, t2 : IntTree) extends BoolTree - case class And(t1 : BoolTree, t2 : BoolTree) extends BoolTree - case class Not(t : BoolTree) extends BoolTree - - abstract class IntTree - case class Const(c:Int) extends IntTree - case class Var() extends IntTree - case class Plus(t1 : IntTree, t2 : IntTree) extends IntTree - case class Minus(t1 : IntTree, t2 : IntTree) extends IntTree - case class Less(t1 : IntTree, t2 : IntTree) extends BoolTree - case class If(cond : BoolTree, t : IntTree, e : IntTree) extends IntTree - - def repOk(t : IntTree) : Boolean = { - true - } - - def beval(t:BoolTree, x0 : Int) : Boolean = { - t match { - case Less(t1, t2) => ieval(t1,x0) < ieval(t2,x0) - case Eq(t1, t2) => ieval(t1,x0) == ieval(t2,x0) - case And(t1, t2) => beval(t1,x0) && beval(t2,x0) - case Not(t1) => !beval(t1,x0) - } - } - - def ieval(t:IntTree, x0 : Int) : Int = { - t match { - case Const(c) => c - case Var() => x0 - case Plus(t1,t2) => ieval(t1,x0) + ieval(t2,x0) - case Minus(t1, t2) => ieval(t1,x0) - ieval(t2,x0) - case If(c,t1,t2) => if (beval(c,x0)) ieval(t1,x0) else ieval(t2,x0) - } - } - def computesPositive(t : IntTree) : Boolean = { - ieval(t,0) >= 0 && - ieval(t,1) >= 0 && - ieval(t,-1) >= 0 && - ieval(t,-2) >= 0 && - ieval(t,2) >= 0 - } - def identityForPositive(t : IntTree) : Boolean = { - ieval(t, 5) == 5 && - ieval(t, 33) == 33 && - ieval(t, 0) == 0 && - ieval(t, -1) == 1 && - ieval(t, -2) == 2 - } - - def treeBad(t : IntTree) : Boolean = { - !(repOk(t) && computesPositive(t) && identityForPositive(t)) - } holds - - def thereIsGoodTree() : Boolean = { - !treeBad(If(Less(Const(0),Var()), Var(), Minus(Const(0),Var()))) - } holds - - @ignore - def main(args : Array[String]) { - thereIsGoodTree() - } -} diff --git a/testcases/verification/compilation/TinyCertifiedCompiler-Parametric.scala b/testcases/verification/compilation/TinyCertifiedCompiler-Parametric.scala deleted file mode 100644 index 7518c21fb8ba7349e49c37c8acac6f99aaae2cdd..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/TinyCertifiedCompiler-Parametric.scala +++ /dev/null @@ -1,89 +0,0 @@ -import leon.lang._ -import leon.lang.Option -import leon.collection._ -import leon.annotation._ -import leon.proof._ -import leon.lang.synthesis._ - -object TinyCertifiedCompiler { - abstract class ByteCode[A] - case class Load[A](c: A) extends ByteCode[A] // loads a constant in to the stack - case class OpInst[A]() extends ByteCode[A] - - abstract class ExprTree[A] - case class Const[A](c: A) extends ExprTree[A] - case class Op[A](e1: ExprTree[A], e2: ExprTree[A]) extends ExprTree[A] - - def compile[A](e: ExprTree[A]): List[ByteCode[A]] = { - e match { - case Const(c) => - Cons(Load(c), Nil[ByteCode[A]]()) - case Op(e1, e2) => - (compile(e1) ++ compile(e2)) ++ Cons(OpInst(), Nil[ByteCode[A]]()) - } - } - - def op[A](x: A, y: A): A = { - ???[A] - } - - def run[A](bytecode: List[ByteCode[A]], S: List[A]): List[A] = { - (bytecode, S) match { - case (Cons(Load(c), tail), _) => - run(tail, Cons[A](c, S)) // adding elements to the head of the stack - case (Cons(OpInst(), tail), Cons(x, Cons(y, rest))) => - run(tail, Cons[A](op(y, x), rest)) - case (Cons(_, tail), _) => - run(tail, S) - case (Nil(), _) => // no bytecode to execute - S - } - } - - def interpret[A](e: ExprTree[A]): A = { - e match { - case Const(c) => c - case Op(e1, e2) => - op(interpret(e1), interpret(e2)) - } - } - - def runAppendLemma[A](l1: List[ByteCode[A]], l2: List[ByteCode[A]], S: List[A]): Boolean = { - // lemma - (run(l1 ++ l2, S) == run(l2, run(l1, S))) because - // induction scheme (induct over l1) - (l1 match { - case Nil() => - true - case Cons(h, tail) => - (h, S) match { - case (Load(c), _) => - runAppendLemma(tail, l2, Cons[A](c, S)) - case (OpInst(), Cons(x, Cons(y, rest))) => - runAppendLemma(tail, l2, Cons[A](op(y, x), rest)) - case (_, _) => - runAppendLemma(tail, l2, S) - case _ => - true - } - }) - }.holds - - def compileInterpretEquivalenceLemma[A](e: ExprTree[A], S: List[A]): Boolean = { - // lemma - (run(compile(e), S) == interpret(e) :: S) because - // induction scheme - (e match { - case Const(c) => - true - case Op(e1, e2) => - // lemma instantiation - val c1 = compile(e1) - val c2 = compile(e2) - runAppendLemma((c1 ++ c2), Cons[ByteCode[A]](OpInst[A](), Nil[ByteCode[A]]()), S) && - runAppendLemma(c1, c2, S) && - compileInterpretEquivalenceLemma(e1, S) && - compileInterpretEquivalenceLemma(e2, Cons[A](interpret(e1), S)) - }) - } holds -} diff --git a/testcases/verification/compilation/TinyCertifiedCompiler-with-errorOption.scala b/testcases/verification/compilation/TinyCertifiedCompiler-with-errorOption.scala deleted file mode 100644 index 912558e6a409a86fa9fe27761c4d265ef586f380..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/TinyCertifiedCompiler-with-errorOption.scala +++ /dev/null @@ -1,95 +0,0 @@ -import leon.lang._ -import leon.lang.Option -import leon.collection._ -import leon.annotation._ - -object TinyCertifiedCompiler { - - abstract class ByteCode - case class Load(c: BigInt) extends ByteCode // loads a constant in to the stack - case class OpInst() extends ByteCode - - abstract class ExprTree - case class Const(c: BigInt) extends ExprTree - case class OP(e1: ExprTree, e2: ExprTree) extends ExprTree - - def compile(e: ExprTree): List[ByteCode] = { - e match { - case Const(c) => - Cons(Load(c), Nil[ByteCode]()) - case OP(e1, e2) => - (compile(e1) ++ compile(e2)) ++ Cons(OpInst(), Nil[ByteCode]()) - } - } - - def op(x: BigInt, y: BigInt) : BigInt = { - x + y - } - - def run(bytecode: List[ByteCode], S: Option[List[BigInt]]) : Option[List[BigInt]] = { - (bytecode, S) match { - case (Cons(Load(c), tail), Some(stack)) => - run(tail, Some(Cons(c, stack))) // adding elements to the head of the stack - case (Cons(OpInst(), tail), Some(Cons(x, Cons(y, rest)))) => - run(tail, Some(Cons(op(x, y), rest))) - case (Nil(), _) => // no bytecode to execute - S - case _ => - // here, we have encountered a runtime error, so we return None to signal error - None[List[BigInt]] - } - } - - def interpret(e: ExprTree) : BigInt = { - e match { - case Const(c) => c - case OP(e1, e2) => - op(interpret(e1), interpret(e2)) - } - } - - def runAppendLemma(l1: List[ByteCode], l2: List[ByteCode], S: Option[List[BigInt]]) : Boolean = { - // lemma - run(l1 ++ l2, S) == run(l2, run(l1, S)) && - // induction scheme (induct over l1) - (l1 match { - case Nil() => - true - case Cons(h, tail) => - (h, S) match { - case (Load(c), Some(stk)) => - runAppendLemma(tail, l2, Some(Cons(c, stk))) - case (OpInst(), Some(Cons(x, Cons(y, rest)))) => - runAppendLemma(tail, l2, Some(Cons(op(x, y), rest))) - case _ => - true - } - }) - } holds - - def compileInterpretEquivalenceLemma(e: ExprTree, S: Option[List[BigInt]]) : Boolean = { - S match { - case None() => true - case Some(stk) => - // lemma - (run(compile(e), S) match { - case None() => true // here, there was a run-time error - case Some(rstk) => - rstk == Cons[BigInt](interpret(e), stk) - }) && - // induction scheme - (e match { - case Const(c) => - true - case OP(e1, e2) => - // lemma instantiation - val c1 = compile(e1) - val c2 = compile(e2) - runAppendLemma((c1 ++ c2), Cons(OpInst(), Nil[ByteCode]()), S) && - runAppendLemma(c1, c2, S) && - compileInterpretEquivalenceLemma(e1, S) && - compileInterpretEquivalenceLemma(e2, Some(Cons[BigInt](interpret(e1), stk))) - }) - } - } holds -} diff --git a/testcases/verification/compilation/TinyCertifiedCompiler.scala b/testcases/verification/compilation/TinyCertifiedCompiler.scala deleted file mode 100644 index b7f46a49a27cf4092518afa08f0cef5ff8f724c7..0000000000000000000000000000000000000000 --- a/testcases/verification/compilation/TinyCertifiedCompiler.scala +++ /dev/null @@ -1,107 +0,0 @@ -import leon.lang._ -import leon.lang.Option -import leon.collection._ -import leon.annotation._ -import leon.proof._ - -object TinyCertifiedCompiler { - - abstract class ByteCode - case class Load(c: BigInt) extends ByteCode // loads a constant in to the stack - case class OpInst() extends ByteCode - - abstract class ExprTree - case class Const(c: BigInt) extends ExprTree - case class Op(e1: ExprTree, e2: ExprTree) extends ExprTree - - def compile(e: ExprTree): List[ByteCode] = { - e match { - case Const(c) => - Cons(Load(c), Nil[ByteCode]()) - case Op(e1, e2) => - (compile(e1) ++ compile(e2)) ++ Cons(OpInst(), Nil[ByteCode]()) - } - } - - def op(x: BigInt, y: BigInt): BigInt = { - x - y - } - - def run(bytecode: List[ByteCode], S: List[BigInt]): List[BigInt] = { - (bytecode, S) match { - case (Cons(Load(c), tail), _) => - run(tail, Cons[BigInt](c, S)) // adding elements to the head of the stack - case (Cons(OpInst(), tail), Cons(x, Cons(y, rest))) => - run(tail, Cons[BigInt](op(y, x), rest)) - case (Cons(_, tail), _) => - run(tail, S) - case (Nil(), _) => // no bytecode to execute - S - } - } - - def interpret(e: ExprTree): BigInt = { - e match { - case Const(c) => c - case Op(e1, e2) => - op(interpret(e1), interpret(e2)) - } - } - - def runAppendLemma(l1: List[ByteCode], l2: List[ByteCode], S: List[BigInt]): Boolean = { - // lemma - (run(l1 ++ l2, S) == run(l2, run(l1, S))) because - // induction scheme (induct over l1) - (l1 match { - case Nil() => - true - case Cons(h, tail) => - (h, S) match { - case (Load(c), _) => - runAppendLemma(tail, l2, Cons[BigInt](c, S)) - case (OpInst(), Cons(x, Cons(y, rest))) => - runAppendLemma(tail, l2, Cons[BigInt](op(y, x), rest)) - case (_, _) => - runAppendLemma(tail, l2, S) - case _ => - true - } - }) - }.holds - - def run1(bytecode: List[ByteCode], S: List[BigInt]): List[BigInt] = { - (bytecode, S) match { - case (Cons(Load(c), tail), _) => - run1(tail, Cons[BigInt](c, S)) // adding elements to the head of the stack - case (Cons(OpInst(), tail), Cons(x, Cons(y, rest))) => - run1(tail, Cons[BigInt](op(x, y), rest)) - case (Cons(_, tail), _) => - run1(tail, S) - case (Nil(), _) => // no bytecode to execute - S - } - } - - def compileInterpretEquivalenceLemma1(e: ExprTree, S: List[BigInt]): Boolean = { - // lemma - (run1(compile(e), S) == interpret(e) :: S) - } holds - - def compileInterpretEquivalenceLemma(e: ExprTree, S: List[BigInt]): Boolean = { - // lemma - (run(compile(e), S) == interpret(e) :: S) because - // induction scheme - (e match { - case Const(c) => - true - case Op(e1, e2) => - // lemma instantiation - val c1 = compile(e1) - val c2 = compile(e2) - runAppendLemma((c1 ++ c2), Cons(OpInst(), Nil[ByteCode]()), S) && - runAppendLemma(c1, c2, S) && - compileInterpretEquivalenceLemma(e1, S) && - compileInterpretEquivalenceLemma(e2, Cons[BigInt](interpret(e1), S)) - }) - } holds -} diff --git a/testcases/verification/datastructures/AVLTree.scala b/testcases/verification/datastructures/AVLTree.scala deleted file mode 100644 index 02eed85a3d1a223fe926308eca78052ba0f9335a..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/AVLTree.scala +++ /dev/null @@ -1,213 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Manos (modified by Ravi) - * Date: 20.11.2013 - **/ - -import leon.lang._ - -object AVLTree { - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(left : Tree, value : Int, right: Tree, rank : Int) extends Tree - - sealed abstract class OptionInt - case class None() extends OptionInt - case class Some(i:Int) extends OptionInt - - - def smallerOption(o1:OptionInt,o2:OptionInt) : Boolean = { - (o1,o2) match { - case (Some(i1), Some(i2)) => i1 < i2 - case (_,_) => true - } - } - - def minOption(o1:OptionInt,o2:OptionInt) : OptionInt = ( - (o1,o2) match { - case (Some(i1), Some(i2)) => Some(if (i1<=i2) i1 else i2) - case (Some(_), _) => o1 - case (_, Some(_)) => o2 - case _ => None() - } - ) - - def maxOption(o1:OptionInt,o2:OptionInt) : OptionInt = ( - (o1,o2) match { - case (Some(i1), Some(i2)) => Some(if (i1>=i2) i1 else i2) - case (Some(_), _) => o1 - case (_, Some(_)) => o2 - case _ => None() - } - ) - - def min(i1:Int, i2:Int) : Int = if (i1<=i2) i1 else i2 - def max(i1:Int, i2:Int) : Int = if (i1>=i2) i1 else i2 - - def rank(t: Tree) : Int = { - t match { - case Leaf() => 0 - case Node(_,_,_,rk) => rk - } - } - - def size(t: Tree): Int = { - (t match { - case Leaf() => 0 - case Node(l, _, r,_) => size(l) + 1 + size(r) - }) - } ensuring (_ >= 0) - - def height(t: Tree): Int = { - t match { - case Leaf() => 0 - case Node(l, x, r, _) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } ensuring(_ >= 0) - - def treeMax(t:Tree) : OptionInt = { - t match { - case Leaf() => None() - case Node(l,v,r,_) => maxOption(Some(v), maxOption (treeMax(l), treeMax(r))) - } - } - - def treeMin(t:Tree) : OptionInt = { - t match { - case Leaf() => None() - case Node(l,v,r,_) => minOption(Some(v), minOption (treeMin(l), treeMin(r))) - } - } - - - def isBST(t:Tree) : Boolean = { - t match { - case Leaf() => true - case Node(l,v,r,_) => - if (isBST(l) && isBST(r)) { - smallerOption(Some(v),bstMin(r)) && - smallerOption(bstMax(l),Some(v)) - } - else false - } - } - - def rankHeight(t: Tree) : Boolean = t match { - case Leaf() => true - case Node(l,_,r,rk) => rankHeight(l) && rankHeight(r) && rk == height(t) - } - - def balanceFactor(t : Tree) : Int = { - t match{ - case Leaf() => 0 - case Node(l, _, r, _) => rank(l) - rank(r) - } - } - - def isAVL(t:Tree) : Boolean = { - t match { - case Leaf() => true - case Node(l,_,r,rk) => isAVL(l) && isAVL(r) && balanceFactor(t) >= -1 && balanceFactor(t) <= 1 && rankHeight(t) //isBST(t) && - } - } - - def bstMax(t:Tree) : OptionInt = { - require(isBST(t)) - t match { - case Leaf() => None() - case Node(_,v,Leaf(),_) => Some(v) - case Node(_,_,r,_) => bstMax(r) - } - } ensuring (res => res == treeMax(t)) - - def bstMin(t:Tree) : OptionInt = { - require(isBST(t)) - t match { - case Leaf() => None() - case Node(Leaf(),v,_,_) => Some(v) - case Node(l, _ ,_ ,_) => bstMin(l) - } - } ensuring (res => res == treeMin(t)) - - def offByOne(t : Tree) : Boolean = { - t match { - case Leaf() => true - case Node(l,_,r,_) => isAVL(l) && isAVL(r) && balanceFactor(t) >= -2 && balanceFactor(t) <= 2 - } - } - - def unbalancedInsert(t: Tree, e : Int) : Tree = { - require(isAVL(t)) - t match { - case Leaf() => Node(Leaf(), e, Leaf(), 1) - case Node(l,v,r,h) => - if (e == v) t - else if (e < v){ - val newl = avlInsert(l,e) - Node(newl, v, r, max(rank(newl), rank(r)) + 1) - } - else { - val newr = avlInsert(r,e) - Node(l, v, newr, max(rank(l), rank(newr)) + 1) - } - } - } - - def avlInsert(t: Tree, e : Int) : Tree = { - require(isAVL(t)) - - balance(unbalancedInsert(t,e)) - - } ensuring(res => isAVL(res) && rank(res) >= rank(t) && rank(res) <= rank(t) + 1 && size(res) <= size(t) + 1) - - def balance(t:Tree) : Tree = { - require(rankHeight(t) && offByOne(t)) //isBST(t) && - t match { - case Leaf() => Leaf() // impossible... - case Node(l, v, r, h) => - val bfactor = balanceFactor(t) - // at this point, the tree is unbalanced - if(bfactor > 1 ) { // left-heavy - val newL = - if (balanceFactor(l) < 0) { // l is right heavy - rotateLeft(l) - } - else l - rotateRight(Node(newL,v,r, max(rank(newL), rank(r)) + 1)) - } - else if(bfactor < -1) { - val newR = - if (balanceFactor(r) > 0) { // r is left heavy - rotateRight(r) - } - else r - rotateLeft(Node(l,v,newR, max(rank(newR), rank(l)) + 1)) - } else t - } - } ensuring(isAVL(_)) - - def rotateRight(t:Tree) = { - t match { - case Node(Node(ll, vl, rl, _),v,r, _) => - - val hr = max(rank(rl),rank(r)) + 1 - Node(ll, vl, Node(rl,v,r,hr), max(rank(ll),hr) + 1) - - case _ => t // this should not happen - } } - - - def rotateLeft(t:Tree) = { - t match { - case Node(l, v, Node(lr,vr,rr,_), _) => - - val hl = max(rank(l),rank(lr)) + 1 - Node(Node(l,v,lr,hl), vr, rr, max(hl, rank(rr)) + 1) - case _ => t // this should not happen - } } -} - diff --git a/testcases/verification/datastructures/AmortizedQueue.scala b/testcases/verification/datastructures/AmortizedQueue.scala deleted file mode 100644 index b7d436bc317c065e5cadb9caa44b72a98c1b9aac..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/AmortizedQueue.scala +++ /dev/null @@ -1,211 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object AmortizedQueue { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class AbsQueue - case class Queue(front : List, rear : List) extends AbsQueue - - def size(list : List) : Int = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def q2l(queue : AbsQueue) : List = queue match { - case Queue(front, rear) => concat(front, reverse(rear)) - } - - def nth(l:List, n:Int) : Int = { - require(0 <= n && n < size(l)) - l match { - case Cons(x,xs) => - if (n==0) x else nth(xs, n-1) - } - } - - def l2mFrom(k:Int, l:List) : Map[Int,Int] = (l match { - case Nil() => Map[Int,Int]() - case Cons(x,xs) => l2mFrom(k+1,xs).updated(k,x) - }) - - def l2m(l:List) : Map[Int,Int] = l2mFrom(0,l) - - def concat(l1 : List, l2 : List) : List = (l1 match { - case Nil() => l2 - case Cons(x,xs) => Cons(x, concat(xs, l2)) - }) ensuring (res => size(res) == size(l1) + size(l2) && content(res) == content(l1) ++ content(l2)) - - def concatTest(l1 : List, l2 : List, i:Int) : List = ({ - require(0 <= i && i < size(l1) + size(l2)) - l1 match { - case Nil() => l2 - case Cons(x,xs) => Cons(x, - if (i == 0) concat(xs, l2) - else concatTest(xs, l2, i-1)) - } - }) ensuring (res => size(res) == size(l1) + size(l2) && - content(res) == content(l1) ++ content(l2) && - nth(res,i) == (if (i < size(l1)) nth(l1,i) else nth(l2,i-size(l1))) && - res == concat(l1,l2)) - - def nthConcat(l1:List, l2:List, i:Int) : Boolean = { - require(0 <= i && i < size(l1) + size(l2)) - concatTest(l1, l2, i) == concatTest(l1, l2, i) && - nth(concat(l1,l2), i) == (if (i < size(l1)) nth(l1,i) else nth(l2,i-size(l1))) - } holds - - def sameUpto(l1:List, l2:List, k:Int) : Boolean = { - require(0 <= k) - (l1,l2) match { - case (Nil(),Nil()) => true - case (Nil(),_) => false - case (_,Nil()) => false - case (Cons(x,xs),Cons(y,ys)) => { - x==y && (if (k==0) true else sameUpto(xs,ys,k-1)) - } - } - } ensuring(res => !(size(l1)==k && size(l2)==k && res) || l1==l2) - - @induct - def concatAssoc(l1:List, l2:List, l3:List) : Boolean = { - concat(l1, concat(l2,l3)) == concat(concat(l1,l2), l3) - } holds - - def concatCons(x:Int, l2:List, l3:List) : Boolean = { - Cons(x, concat(l2,l3)) == concat(Cons(x,l2), l3) - } holds - - def isAmortized(queue : AbsQueue) : Boolean = queue match { - case Queue(front, rear) => size(front) >= size(rear) - } - - def reverse(l : List) : List = (l match { - case Nil() => Nil() - case Cons(x, xs) => concat(reverse(xs), Cons(x, Nil())) - }) ensuring (res => content(res) == content(l)) - - def revConcatNth(l1:List, l2:List, i:Int) : Boolean = { - require(0 <= i && i < size(l1)+size(l2)) - nth(reverse(concat(l1,l2)),i) == nth(concat(reverse(l2), reverse(l1)),i) - } holds - - def revrev(l:List) : Boolean = { - reverse(reverse(l)) == l - } holds - - def amortizedQueue(front : List, rear : List) : AbsQueue = { - if (size(rear) <= size(front)) - Queue(front, rear) - else - Queue(concat(front, reverse(rear)), Nil()) - } ensuring(res => isAmortized(res) && q2l(Queue(front, rear)) == q2l(res)) - - def isEmpty(queue : AbsQueue) : Boolean = (queue match { - case Queue(Nil(), Nil()) => true - case _ => false - }) ensuring(res => (res == (q2l(queue) == Nil()))) - - def enqueue(queue : AbsQueue, elem : Int) : AbsQueue = (queue match { - case Queue(front, rear) => amortizedQueue(front, Cons(elem, rear)) - }) ensuring(res => isAmortized(res) && q2l(res) == concat(q2l(queue), Cons(elem, Nil()))) - // this did not find a counterexample: - // ensuring(res => isAmortized(res) && q2l(res) == Cons(elem, q2l(queue))) - - def push(queue : AbsQueue, elem : Int) : AbsQueue = (queue match { - case Queue(front, rear) => amortizedQueue(Cons(elem,front), rear) - }) ensuring(res => isAmortized(res) && q2l(res) == Cons(elem, q2l(queue))) - - - // I did not know why this does not type check - def matchQ(queue : AbsQueue) : (Int, AbsQueue) = ({ - require(isAmortized(queue) && !isEmpty(queue)) - queue match { - case Queue(Cons(f, fs), rear) => (f, amortizedQueue(fs, rear)) - } - }) ensuring(res => { - val (f,q) = res - q2l(queue) == Cons(f, q2l(q)) - }) - - def tail(queue : AbsQueue) : AbsQueue = ({ - require(isAmortized(queue) && !isEmpty(queue)) - queue match { - case Queue(Cons(f, fs), rear) => amortizedQueue(fs, rear) - } - }) ensuring(res => isAmortized(res) && (q2l(queue) match { - case Nil() => false - case Cons(_,xs) => q2l(res)==xs - })) - - def front(queue : AbsQueue) : Int = ({ - require(isAmortized(queue) && !isEmpty(queue)) - queue match { - case Queue(Cons(f, _), _) => f - } - }) ensuring(res => q2l(queue) match { - case Nil() => false - case Cons(x,_) => x==res - }) - - // @induct - // def propEnqueue(rear : List, front : List, list : List, elem : Int) : Boolean = { - // require(isAmortized(Queue(front, rear))) - // val queue = Queue(front, rear) - // if (q2l(queue) == list) { - // q2l(enqueue(queue, elem)) == concat(list, Cons(elem, Nil())) - // } else - // true - // } holds - - @induct - def propFront(queue : AbsQueue, list : List, elem : Int) : Boolean = { - require(!isEmpty(queue) && isAmortized(queue)) - if (q2l(queue) == list) { - list match { - case Cons(x, _) => front(queue) == x - } - } else - true - } holds - - @induct - def propTail(rear : List, front : List, list : List, elem : Int) : Boolean = { - require(!isEmpty(Queue(front, rear)) && isAmortized(Queue(front, rear))) - if (q2l(Queue(front, rear)) == list) { - list match { - case Cons(_, xs) => q2l(tail(Queue(front, rear))) == xs - } - } else - true - } // holds - - def enqueueAndFront(queue : AbsQueue, elem : Int) : Boolean = { - if (isEmpty(queue)) - front(enqueue(queue, elem)) == elem - else - true - } holds - - def enqueueDequeueThrice(queue : AbsQueue, e1 : Int, e2 : Int, e3 : Int) : Boolean = { - if (isEmpty(queue)) { - val q1 = enqueue(queue, e1) - val q2 = enqueue(q1, e2) - val q3 = enqueue(q2, e3) - val e1prime = front(q3) - val q4 = tail(q3) - val e2prime = front(q4) - val q5 = tail(q4) - val e3prime = front(q5) - e1 == e1prime && e2 == e2prime && e3 == e3prime - } else - true - } holds -} diff --git a/testcases/verification/datastructures/AssociativeList.scala b/testcases/verification/datastructures/AssociativeList.scala deleted file mode 100644 index 36ec44a27c38329d56a9c5f02362d43a6ce2343e..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/AssociativeList.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object AssociativeList { - sealed abstract class KeyValuePairAbs - case class KeyValuePair(key: BigInt, value: BigInt) extends KeyValuePairAbs - - sealed abstract class List - case class Cons(head: KeyValuePairAbs, tail: List) extends List - case class Nil() extends List - - sealed abstract class OptionInt - case class Some(i: BigInt) extends OptionInt - case class None() extends OptionInt - - def domain(l: List): Set[BigInt] = l match { - case Nil() => Set.empty[BigInt] - case Cons(KeyValuePair(k,_), xs) => Set(k) ++ domain(xs) - } - - def find(l: List, e: BigInt): OptionInt = l match { - case Nil() => None() - case Cons(KeyValuePair(k, v), xs) => if (k == e) Some(v) else find(xs, e) - } - - def noDuplicates(l: List): Boolean = l match { - case Nil() => true - case Cons(KeyValuePair(k, v), xs) => find(xs, k) == None() && noDuplicates(xs) - } - - def update(l1: List, l2: List): List = (l2 match { - case Nil() => l1 - case Cons(x, xs) => update(updateElem(l1, x), xs) - }) ensuring(domain(_) == domain(l1) ++ domain(l2)) - - def updateElem(l: List, e: KeyValuePairAbs): List = (l match { - case Nil() => Cons(e, Nil()) - case Cons(KeyValuePair(k, v), xs) => e match { - case KeyValuePair(ek, ev) => if (ek == k) Cons(KeyValuePair(ek, ev), xs) else Cons(KeyValuePair(k, v), updateElem(xs, e)) - } - }) ensuring(res => e match { - case KeyValuePair(k, v) => domain(res) == domain(l) ++ Set[BigInt](k) - }) - - @induct - def readOverWrite(l: List, k1: BigInt, k2: BigInt, e: BigInt) : Boolean = { - find(updateElem(l, KeyValuePair(k2,e)), k1) == (if (k1 == k2) Some(e) else find(l, k1)) - } holds -} diff --git a/testcases/verification/datastructures/BinarySearchTree.scala b/testcases/verification/datastructures/BinarySearchTree.scala deleted file mode 100644 index ef87a00eab9b59870278a2291db888cfd82d9abc..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/BinarySearchTree.scala +++ /dev/null @@ -1,90 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object BSTSimpler { - sealed abstract class Tree - case class Node(left: Tree, value: Int, right: Tree) extends Tree - case class Leaf() extends Tree - - def size(t : Tree) : Int = (t match { - case Leaf() => 1 - case Node(l,_,r) => size(l) + 1 + size(r) - }) ensuring(_ >= 1) - - sealed abstract class IntOpt - case class Some(value: Int) extends IntOpt - case class None() extends IntOpt - - sealed abstract class TripleAbs - case class Triple(lmax: IntOpt, isSorted: Boolean, rmin: IntOpt) extends TripleAbs - - sealed abstract class TriplePairAbs - case class TriplePair(left: TripleAbs, right: TripleAbs) extends TriplePairAbs - - def isBST(tree: Tree) : Boolean = isBST0(tree) match { - case Triple(_, v, _) => v - } - - def isBST0(tree: Tree) : TripleAbs = tree match { - case Leaf() => Triple(None(), true, None()) - - case Node(l, v, r) => TriplePair(isBST0(l), isBST0(r)) match { - case TriplePair(Triple(None(),t1,None()),Triple(None(),t2,None())) - if(t1 && t2) => - Triple(Some(v),true,Some(v)) - case TriplePair(Triple(Some(minL),t1,Some(maxL)),Triple(None(),t2,None())) - if(t1 && t2 && minL <= maxL && maxL < v) => - Triple(Some(minL),true,Some(v)) - case TriplePair(Triple(None(),t1,None()),Triple(Some(minR),t2,Some(maxR))) - if(t1 && t2 && minR <= maxR && v < minR) => - Triple(Some(v),true,Some(maxR)) - case TriplePair(Triple(Some(minL),t1,Some(maxL)),Triple(Some(minR),t2,Some(maxR))) - if(t1 && t2 && minL <= maxL && minR <= maxR && maxL < v && v < minR) => - Triple(Some(minL),true,Some(maxR)) - - case _ => Triple(None(),false,None()) - } - } - - def emptySet(): Tree = Leaf() - - def insert(tree: Tree, value: Int): Node = { - require(isBST(tree)) - tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case Node(l, v, r) => (if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - Node(l, v, r) - }) - } - } ensuring(res => isBST(res) && content(res) == content(tree) ++ Set(value)) - -/* - def remove(tree : Tree, value : Int) : Tree = { - require(size(tree) <= 1 && isBST(tree)) - tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case Node(l, v, r) => (if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - Node(l, v, r) - }) - } - } -*/ - - def createRoot(v: Int): Node = { - Node(Leaf(), v, Leaf()) - } ensuring (content(_) == Set(v)) - - def content(tree: Tree): Set[Int] = tree match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } -} - diff --git a/testcases/verification/datastructures/BinarySearchTreeQuant.scala b/testcases/verification/datastructures/BinarySearchTreeQuant.scala deleted file mode 100644 index b5b072550da63b0760ebe55b2a5e5c2553249f86..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/BinarySearchTreeQuant.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object BSTSimpler { - case object Leaf extends Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - sealed abstract class Tree { - def isBST: Boolean = this match { - case Leaf => true - case Node(left, v, right) => { - left.isBST && right.isBST && - forall((x:BigInt) => (left.content.contains(x) ==> x < v)) && - forall((x:BigInt) => (right.content.contains(x) ==> v < x)) - } - } - - def content: Set[BigInt] = this match { - case Leaf => Set.empty[BigInt] - case Node(l, v, r) => l.content ++ Set(v) ++ r.content - } - - def insert(value: BigInt): Node = { - require(isBST) - this match { - case Leaf => Node(Leaf, value, Leaf) - case Node(l, v, r) => (if (v < value) { - Node(l, v, r.insert(value)) - } else if (v > value) { - Node(l.insert(value), v, r) - } else { - Node(l, v, r) - }) - } - } ensuring(res => res.isBST && res.content == content ++ Set(value)) - - def contains(value: BigInt): Boolean = { - require(isBST) - this match { - case Leaf => false - case Node(l,v,r) => (if (v < value) { - r.contains(value) - } else if (v > value) { - l.contains(value) - } else true) - } - } ensuring(res => (res == content.contains(value))) - - } - def empty: Tree = Leaf -} diff --git a/testcases/verification/datastructures/BinarySearchTreeSorted.scala b/testcases/verification/datastructures/BinarySearchTreeSorted.scala deleted file mode 100644 index 577e0e6a02a90260e484b33d2ce1f3f54a08c93d..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/BinarySearchTreeSorted.scala +++ /dev/null @@ -1,57 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object BinaryTree { - sealed abstract class Tree - case class Node(left: Tree, value: Int, right: Tree) extends Tree - case class Leaf() extends Tree - - case class SortedTriple(min: Option[Int], max: Option[Int], sorted: Boolean) - - def isSortedTriple(tree: Tree) : SortedTriple = (tree match { - case Leaf() => SortedTriple(None(), None(), true) - case Node(l, v, r) => - (isSortedTriple(l), isSortedTriple(r)) match { - case (SortedTriple(minl, maxl, sortedl), SortedTriple(minr, maxr, sortedr)) => - val sorted = sortedl && sortedr && (v > maxl.getOrElse(v-1)) && (v < minr.getOrElse(v+1)) - SortedTriple(minl.orElse(Some(v)), maxr.orElse(Some(v)), sorted) - } - }) ensuring { res => res match { - case SortedTriple(Some(min), Some(max), res) => !res || (min <= max) - case SortedTriple(None(), None(), res) => res - case _ => false - }} - - def isSorted(tree: Tree): Boolean = isSortedTriple(tree).sorted - - def insert(tree: Tree, value: Int): Tree = ({ - require(isSorted(tree)) - tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case Node(l, v, r) => if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - Node(l,v,r) - } - } - }) ensuring (res => isSorted(res)) - - def buggyMerge(t1 : Tree, t2 : Tree) : Tree = ({ - require(isSorted(t1) && isSorted(t2)) - (t1, t2) match { - case (Leaf(), _) => t2 - case (_, Leaf()) => t1 - case (t1 @ Node(l1, v1, r1), t2 @ Node(l2, v2, r2)) => - if (v1 < v2) { - Node(buggyMerge(t1, l2), v2, r2) - } else if (v2 < v1) { - Node(buggyMerge(l1, t2), v1, r1) - } else { - Node(buggyMerge(l1, l2), v1, buggyMerge(r1, r2)) - } - } - }) ensuring (res => isSorted(res)) -} diff --git a/testcases/verification/datastructures/BinarySearchTreeToList.scala b/testcases/verification/datastructures/BinarySearchTreeToList.scala deleted file mode 100644 index 86ccefaeb7febe704b515066684b0187c5570baa..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/BinarySearchTreeToList.scala +++ /dev/null @@ -1,132 +0,0 @@ -/* -Case study by Ravichandhran Kandhadai Madhavan, 2015 -Confirmed verified on 2015-09-22 using - --solvers=smt-z3 --timeout=15 -*/ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object BinaryTree { - sealed abstract class Tree { - /** - * Returns the contents of the tree in preorder - */ - def toList: List[BigInt] = { - this match { - case Node(l, v, r) => - (l.toList ++ sing(v)) ++ r.toList - case _ => - Nil[BigInt]() - } - } ensuring (res => this == Leaf() || res != Nil[BigInt]()) - - def toSet: Set[BigInt] = { - this match { - case Node(l, v, r) => - l.toSet ++ Set(v) ++ r.toSet - case _ => - Set[BigInt]() - } - } ensuring (res => this == Leaf() || res != Set[BigInt]()) - - } - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def BST(t: Tree): Boolean = t match { - case Leaf() => true - case Node(l, v, r) => - BST(l) && BST(r) && isSorted(t.toList) && - (l.toList == Nil[BigInt]() || l.toList.last < v) && - (r.toList == Nil[BigInt]() || v < first(r.toList)) - } - - def sing(x: BigInt): List[BigInt] = { - Cons[BigInt](x, Nil[BigInt]()) - } - - def min(x: BigInt, y: BigInt): BigInt = { - if (x <= y) x else y - } - - def max(x: BigInt, y: BigInt): BigInt = { - if (x >= y) x else y - } - - def insert(tree: Tree, value: BigInt): Tree = ({ - require(BST(tree)) - tree match { - case Leaf() => - Node(Leaf(), value, Leaf()) - case Node(l, v, r) => if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - Node(l, v, r) - } - } - }) ensuring (res => BST(res) && - res.toSet == tree.toSet ++ Set(value) && - res.toList != Nil[BigInt]() && - (tree match { - case Leaf() => (first(res.toList) == value) && - (res.toList.last == value) - case _ => - first(res.toList) == min(first(tree.toList), value) && - res.toList.last == max(tree.toList.last, value) - }) - && - instAppendSorted(tree, value)) - - def instAppendSorted(t: Tree, value: BigInt): Boolean = { - require(BST(t)) - t match { - case Leaf() => - true - case Node(l, v, r) => - appendSorted(l.toList, sing(v)) && - appendSorted(l.toList ++ sing(v), r.toList) && - (if (v < value) { - appendSorted(l.toList, sing(v)) && - appendSorted(l.toList ++ sing(v), insert(r, value).toList) - } else if (v > value) { - appendSorted(insert(l, value).toList, sing(v)) && - appendSorted(insert(l, value).toList ++ sing(v), r.toList) - } else true) - } - } - - // this computes strict sortedness - def isSorted(l: List[BigInt]): Boolean = { - l match { - case Nil() => true - case Cons(x, Nil()) => true - case Cons(x, tail @ Cons(y, _)) => - (x < y) && isSorted(tail) - } - } ensuring (res => !res || l == Nil[BigInt]() || first(l) <= l.last) - - def first(l: List[BigInt]): BigInt = { - require(l != Nil[BigInt]) - l match { - case Cons(x, _) => x - } - } - - // A lemma about `append` and `isSorted` - def appendSorted(l1: List[BigInt], l2: List[BigInt]): Boolean = { - require(isSorted(l1) && isSorted(l2) && - (l1 == Nil[BigInt]() || l2 == Nil[BigInt]() || l1.last < first(l2))) - // induction scheme - (l1 match { - case Nil() => true - case Cons(x, xs) => appendSorted(xs, l2) - }) && - (l1 == Nil[BigInt]() || first(l1 ++ l2) == first(l1)) && - (l2 == Nil[BigInt]() || (l1 ++ l2).last == l2.last) && - (l2 != Nil[BigInt]() || l1 == Nil[BigInt]() || (l1 ++ l2).last == l1.last) && - isSorted(l1 ++ l2) - }.holds -} diff --git a/testcases/verification/datastructures/BinaryTrie.scala b/testcases/verification/datastructures/BinaryTrie.scala deleted file mode 100644 index bf064f9366fbec6d6029d0b01107e2eca3fda02e..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/BinaryTrie.scala +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ - -object BinaryTrie { - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(nvalue: Int, left : Tree, right: Tree) extends Tree - - sealed abstract class IList - case class Cons(head: Int, tail: IList) extends IList - case class Nil() extends IList - - def listSize(l: IList): Int = (l match { - case Nil() => 0 - case Cons(x, xs) => 1 + listSize(xs) - }) ensuring(_ >= 0) - - def height(t: Tree): Int = { - t match{ - case Leaf() => 0 - case Node(x,l,r) => { - val hl = height(l) - val hr = height(r) - if(hl > hr) hl + 1 else hr + 1 - } - } - } ensuring(_ >= 0) - - def insert(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => t - case Cons(x ,xs) => { - val newch = insert(xs, Leaf()) - newch match { - case Leaf() => Node(x, Leaf(), Leaf()) - case Node(y, _, _) => if(y > 0) Node(x, newch, Leaf()) else Node(y, Leaf(), newch) - } - } - } - } - case Node(v, l, r) => { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x ,xs@Cons(y, _)) => { - val ch = if(y > 0) l else r - if(y > 0) - Node(v, insert(xs, ch), r) - else - Node(v, l, insert(xs, ch)) - } - case _ => t - } - } - } - } ensuring(res => height(res) + height(t) >= listSize(inp)) - - def create(inp: IList) : Tree = { - insert(inp, Leaf()) - }ensuring(res => height(res) >= listSize(inp)) -} diff --git a/testcases/verification/datastructures/HeapSort.scala b/testcases/verification/datastructures/HeapSort.scala deleted file mode 100644 index 935bf9efc1933ba7ae067c4b122120de09bbb2d3..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/HeapSort.scala +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ - -object HeapSort { - sealed abstract class List - case class Cons(head:Int,tail:List) extends List - case class Nil() extends List - - sealed abstract class Heap - case class Leaf() extends Heap - case class Node(rk : Int, value: Int, left: Heap, right: Heap) extends Heap - - private def rightHeight(h: Heap) : Int = {h match { - case Leaf() => 0 - case Node(_,_,_,r) => rightHeight(r) + 1 - }} ensuring(_ >= 0) - - private def rank(h: Heap) : Int = h match { - case Leaf() => 0 - case Node(rk,_,_,_) => rk - } - - private def hasLeftistProperty(h: Heap) : Boolean = (h match { - case Leaf() => true - case Node(_,_,l,r) => hasLeftistProperty(l) && hasLeftistProperty(r) && rightHeight(l) >= rightHeight(r) && (rank(h) == rightHeight(h)) - }) - - def heapSize(t: Heap): Int = { - require(hasLeftistProperty(t)) - (t match { - case Leaf() => 0 - case Node(_,v, l, r) => heapSize(l) + 1 + heapSize(r) - }) - } ensuring(_ >= 0) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2)) - h1 match { - case Leaf() => h2 - case Node(_, v1, l1, r1) => h2 match { - case Leaf() => h1 - case Node(_, v2, l2, r2) => - if(v1 > v2) - makeT(v1, l1, merge(r1, h2)) - else - makeT(v2, l2, merge(h1, r2)) - } - } - } ensuring(res => hasLeftistProperty(res) && heapSize(h1) + heapSize(h2) == heapSize(res)) - - - private def makeT(value: Int, left: Heap, right: Heap) : Heap = { - if(rank(left) >= rank(right)) - Node(rank(right) + 1, value, left, right) - else - Node(rank(left) + 1, value, right, left) - } - - def insert(element: Int, heap: Heap) : Heap = { - require(hasLeftistProperty(heap)) - - merge(Node(1, element, Leaf(), Leaf()), heap) - - } ensuring(res => heapSize(res) == heapSize(heap) + 1) - - def findMax(h: Heap) : Int = { - require(hasLeftistProperty(h)) - h match { - case Node(_,m,_,_) => m - case Leaf() => -1000 - } - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h)) - h match { - case Node(_,_,l,r) => merge(l, r) - case l @ Leaf() => l - } - } - - def listSize(l : List) : Int = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + listSize(xs) - }) ensuring(_ >= 0) - - def removeElements(h : Heap, l : List) : List = { - require(hasLeftistProperty(h)) - h match { - case Leaf() => l - case _ => removeElements(removeMax(h),Cons(findMax(h),l)) - - }} ensuring(res => heapSize(h) + listSize(l) == listSize(res)) - - def buildHeap(l : List, h: Heap) : Heap = { - require(hasLeftistProperty(h)) - l match { - case Nil() => h - case Cons(x,xs) => buildHeap(xs, insert(x, h)) - - }} ensuring(res => hasLeftistProperty(res) && heapSize(h) + listSize(l) == heapSize(res)) - - def sort(l: List): List = ({ - - val heap = buildHeap(l,Leaf()) - removeElements(heap, Nil()) - - }) ensuring(res => listSize(res) == listSize(l)) -} diff --git a/testcases/verification/datastructures/LeftistHeap.scala b/testcases/verification/datastructures/LeftistHeap.scala deleted file mode 100644 index 7617b981672829ec8d1940897f5ecbead0e57946..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/LeftistHeap.scala +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne - * - * Author: Ravi - * Date: 20.11.2013 - **/ - -import leon.lang._ - -object LeftistHeap { - sealed abstract class Heap - case class Leaf() extends Heap - case class Node(rk : Int, value: Int, left: Heap, right: Heap) extends Heap - - private def rightHeight(h: Heap) : Int = {h match { - case Leaf() => 0 - case Node(_,_,_,r) => rightHeight(r) + 1 - }} ensuring(_ >= 0) - - private def hasLeftistProperty(h: Heap) : Boolean = (h match { - case Leaf() => true - case Node(_,_,l,r) => hasLeftistProperty(l) && hasLeftistProperty(r) && rightHeight(l) >= rightHeight(r) - }) - - def size(t: Heap): Int = { - (t match { - case Leaf() => 0 - case Node(_,v, l, r) => size(l) + 1 + size(r) - }) - } - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h)) - h match { - case Node(_,_,l,r) => merge(l, r) - case l @ Leaf() => l - } - } ensuring(res => size(res) >= size(h) - 1) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2)) - h1 match { - case Leaf() => h2 - case Node(_, v1, l1, r1) => h2 match { - case Leaf() => h1 - case Node(_, v2, l2, r2) => - if(v1 > v2) - makeT(v1, l1, merge(r1, h2)) - else - makeT(v2, l2, merge(h1, r2)) - } - } - } ensuring(res => size(res) == size(h1) + size(h2)) - - private def makeT(value: Int, left: Heap, right: Heap) : Heap = { - if(rightHeight(left) >= rightHeight(right)) - Node(rightHeight(right) + 1, value, left, right) - else - Node(rightHeight(left) + 1, value, right, left) - } - - def insert(element: Int, heap: Heap) : Heap = { - require(hasLeftistProperty(heap)) - - merge(Node(1, element, Leaf(), Leaf()), heap) - - }ensuring(res => size(res) == size(heap) + 1) -} diff --git a/testcases/verification/datastructures/ListTree.scala b/testcases/verification/datastructures/ListTree.scala deleted file mode 100644 index edcd48650cb6a3da48d61d18c1e27829803e04a8..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/ListTree.scala +++ /dev/null @@ -1,143 +0,0 @@ -import leon.lang._ - -object ListTree { - /* Trees holding integers and internal lists */ - sealed abstract class IntTreeList - case class Cons(head: IntTree, tail: IntTreeList) extends IntTreeList - case class Nil() extends IntTreeList - - sealed abstract class IntTree - case class Leaf(value: Int) extends IntTree - case class Node(list: IntTreeList) extends IntTree - - /* Trees holding pairs of integers and internal lists */ - sealed abstract class IntIntTreeList - case class Cons2(head: IntIntTree, tail: IntIntTreeList) extends IntIntTreeList - case class Nil2() extends IntIntTreeList - - sealed abstract class IntIntTree - case class Leaf2(value: IntIntPair) extends IntIntTree - case class Node2(list: IntIntTreeList) extends IntIntTree - - /* Various tuples that are needed below */ - sealed abstract class Tuple - case class TreeIntPair(tree: IntTree, int: Int) extends Tuple - case class IntIntPair(fst: Int, snd: Int) extends Tuple - - // we are going to specialize fold, map, iter, and build2 for their uses - - // we specialize iter for v <= x - def iter1(t: IntTree, v: Int): Boolean = t match { - case Leaf(x) => v <= x - case Node(ts) => iter1list(ts, v) - } - // specialize for iter1 - def iter1list(l: IntTreeList, v: Int): Boolean = l match { - case Nil() => true - case Cons(x, xs) => iter1(x, v) && iter1list(xs, v) - } - - // specialize iter for (a, b) => k <= a && k <= b - def iter2(t: IntIntTree, k: Int): Boolean = t match { - case Leaf2(IntIntPair(a, b)) => k <= a && k <= b - case Node2(ts) => iter2list(ts, k) - } - - // specialize for iter2 - def iter2list(ts: IntIntTreeList, k: Int): Boolean = ts match { - case Nil2() => true - case Cons2(x, xs) => iter2(x, k) && iter2list(xs, k) - } - - // specialize build2 for f(x) = x + 1 - def build2(b: Int, d: Int): TreeIntPair = { - if (d <= 0) - TreeIntPair(Leaf(b), b + 1) - else { - val p1 = build2(b, d-1) - val p2 = build2(p1.int, d-1) - TreeIntPair(Node(Cons(p1.tree, Cons(p2.tree, Nil()))), p2.int) - } - } - - // specialize fold for function + - def fold1(b: Int, t: IntTree): Int = t match { - case Leaf(x) => x + b - case Node(ts) => foldLeft1(b, ts) - } - - // specialize for the fold1 method above - def foldLeft1(b: Int, ts: IntTreeList): Int = ts match { - case Nil() => b - case Cons(x, xs) => foldLeft1(fold1(b, x), xs) - } - - // specialize fold for function lub - def fold2(b: IntIntPair, t: IntIntTree): IntIntPair = t match { - case Leaf2(x) => lub(b, x) - case Node2(ts) => foldLeft2(b, ts) - } - - // specialize foldLeft for the fold2 function - def foldLeft2(b: IntIntPair, ts: IntIntTreeList): IntIntPair = ts match { - case Nil2() => b - case Cons2(x, xs) => foldLeft2(fold2(b, x), xs) - } - - // specialize map for demo2, with function x => (x, 2*x + 1) - def map1(t: IntTree): IntIntTree = t match { - case Leaf(x) => Leaf2(IntIntPair(x, 2*x + 1)) - case Node(ts) => Node2(map1list(ts)) - } - - // specialize for demo2, with function map1 above - def map1list(ts: IntTreeList): IntIntTreeList = ts match { - case Nil() => Nil2() - case Cons(x, xs) => Cons2(map1(x), map1list(xs)) - } - - /****/ - - def make(n: Int, v: Int): IntTree = { - if (n <= 0) - Leaf(v) - else { - val t1 = make(n-1, v+1) - val t2 = make(n-2, v+2) - val t3 = make(n-3, v+3) - Node(Cons(t1, Cons(t2, Cons(t3, Nil())))) - } - } ensuring(res => iter1(res, v)) /* all elements larger than v (demo0 test) */ - - /****/ - - def demo1(d: Int, k: Int): Int = { - require(k >= 0) - val t = build2(k+1, d).tree - fold1(k, t) - } ensuring(_ >= k) - - /****/ - - def mmin(x: Int, y: Int): Int = if (x <= y) x else y - def mmax(x: Int, y: Int): Int = if (x <= y) y else x - - def lub(p1: IntIntPair, p2: IntIntPair): IntIntPair = { - val newFst = mmin(p1.fst, p2.fst) - val newSnd = mmax(p1.snd, p2.snd) - IntIntPair(newFst, newSnd) - } - - def demo2a(d: Int, k: Int): IntIntTree = { - require(k >= 0) - val t = build2(k, d).tree - map1(t) - } ensuring(iter2(_, k)) - - def demo2b(d: Int, k: Int): IntIntPair = { - require(k >= 0) - val t = build2(k, d).tree - val t1 = map1(t) - fold2(IntIntPair(k, k), t1) - } ensuring(res => res.fst <= res.snd) -} diff --git a/testcases/verification/datastructures/ListWithSize.scala b/testcases/verification/datastructures/ListWithSize.scala deleted file mode 100644 index d826eae580e62dcd69a1b4f0a4c1806f92cd7b6b..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/ListWithSize.scala +++ /dev/null @@ -1,134 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object ListWithSize { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - sealed abstract class IntPairList - case class IPCons(head: IntPair, tail: IntPairList) extends IntPairList - case class IPNil() extends IntPairList - - sealed abstract class IntPair - case class IP(fst: Int, snd: Int) extends IntPair - - // proved with unrolling=0 - def size(l: List) : Int = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def iplSize(l: IntPairList) : Int = (l match { - case IPNil() => 0 - case IPCons(_, xs) => 1 + iplSize(xs) - }) ensuring(_ >= 0) - - def zip(l1: List, l2: List) : IntPairList = { - // try to comment this and see how pattern-matching becomes - // non-exhaustive and post-condition fails - require(size(l1) == size(l2)) - - l1 match { - case Nil() => IPNil() - case Cons(x, xs) => l2 match { - case Cons(y, ys) => IPCons(IP(x, y), zip(xs, ys)) - } - } - } ensuring(iplSize(_) == size(l1)) - - def sizeTailRec(l: List) : Int = sizeTailRecAcc(l, 0) - def sizeTailRecAcc(l: List, acc: Int) : Int = { - require(acc >= 0) - l match { - case Nil() => acc - case Cons(_, xs) => sizeTailRecAcc(xs, acc+1) - } - } ensuring(res => res == size(l) + acc) - - def sizesAreEquiv(l: List) : Boolean = { - size(l) == sizeTailRec(l) - } holds - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def sizeAndContent(l: List) : Boolean = { - size(l) == 0 || content(l) != Set.empty[Int] - } holds - - def drunk(l : List) : List = (l match { - case Nil() => Nil() - case Cons(x,l1) => Cons(x,Cons(x,drunk(l1))) - }) ensuring (size(_) == 2 * size(l)) - - // proved with unrolling=1 - def funnyCons(x: Int, l: List) : List = (l match { - case Nil() => Cons(x, Nil()) - case c @ Cons(_,_) => Cons(x, c) - }) ensuring(size(_) > 0) - - // proved with unrolling=2 - def reverse(l: List) : List = reverse0(l, Nil()) ensuring(content(_) == content(l)) - def reverse0(l1: List, l2: List) : List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverse0(xs, Cons(x, l2)) - }) ensuring(content(_) == content(l1) ++ content(l2)) - - def append(l1 : List, l2 : List) : List = (l1 match { - case Nil() => l2 - case Cons(x,xs) => Cons(x, append(xs, l2)) - }) ensuring(content(_) == content(l1) ++ content(l2)) - - @induct - def nilAppend(l : List) : Boolean = (append(l, Nil()) == l) holds - - // unclear if we needed this--it was meant to force folding - //def appendFold(x : Int, xs : List, ys : List) : Boolean = { - // true - //} ensuring (res => res && Cons(x,append(xs, ys)) == append(Cons(x,xs), ys)) - - @induct - def appendAssoc(xs : List, ys : List, zs : List) : Boolean = - (append(append(xs, ys), zs) == append(xs, append(ys, zs))) holds - - def revAuxBroken(l1 : List, e : Int, l2 : List) : Boolean = { - (append(reverse(l1), Cons(e,l2)) == reverse0(l1, l2)) - } // holds - - @induct - def reverse0exposed(l1 : List, l2 : List) : Boolean = { - (reverse0(l1, l2) == append(reverse(l1), l2)) - } // holds - - @induct - def sizeAppend(l1 : List, l2 : List) : Boolean = - (size(append(l1, l2)) == size(l1) + size(l2)) holds - - // proved with unrolling=4 - @induct - def concat(l1: List, l2: List) : List = - concat0(l1, l2, Nil()) ensuring(content(_) == content(l1) ++ content(l2)) - - @induct - def concat0(l1: List, l2: List, l3: List) : List = (l1 match { - case Nil() => l2 match { - case Nil() => reverse(l3) - case Cons(y, ys) => { - concat0(Nil(), ys, Cons(y, l3)) - } - } - case Cons(x, xs) => concat0(xs, l2, Cons(x, l3)) - }) ensuring(content(_) == content(l1) ++ content(l2) ++ content(l3)) - - def reverseConcat0(l1: List, l2: List) : Boolean = { - reverse(concat(l1, l2)) == concat(reverse(l2), reverse(l1)) - } // holds - - // proved with unrolling=2 ??? - def reverseConcat(l1: List, l2: List) : Boolean = { - reverse(concat(l1, l2)) == concat(reverse(l2), reverse(l1)) - } // holds -} diff --git a/testcases/verification/datastructures/RedBlackTree.scala b/testcases/verification/datastructures/RedBlackTree.scala deleted file mode 100644 index 43e4d6c9a28e4bc396c127bc0d217ca127fe2fd7..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/RedBlackTree.scala +++ /dev/null @@ -1,122 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - sealed abstract class OptionInt - case class Some(v : Int) extends OptionInt - case class None() extends OptionInt - - def content(t: Tree) : Set[Int] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : BigInt = (t match { - case Empty() => BigInt(0) - case Node(_, l, v, r) => size(l) + 1 + size(r) - }) ensuring(_ >= 0) - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t : Tree) : BigInt = t match { - case Empty() => BigInt(1) - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if (x < y) balance(c, ins(x, a), y, b) - else if (x == y) Node(c,a,y,b) - else balance(c,a,y,ins(x, b)) - } - } ensuring (res => content(res) == content(t) ++ Set(x) - && size(t) <= size(res) && size(res) <= size(t) + 1 - && redDescHaveBlackChildren(res) - && blackBalanced(res)) - - def makeBlack(n: Tree): Tree = { - require(redDescHaveBlackChildren(n) && blackBalanced(n)) - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } ensuring(res => redNodesHaveBlackChildren(res) && blackBalanced(res)) - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - makeBlack(ins(x, t)) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res) && blackBalanced(res)) - - def buggyAdd(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t)) - ins(x, t) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res)) - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b)))// && redDescHaveBlackChildren(res)) - - def buggyBalance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - // case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b)))// && redDescHaveBlackChildren(res)) - - def flip(t : Tree) : Tree = t match { - case Empty() => Empty() - case Node(color,l,e,r) => Node(color,flip(r),e,flip(l)) - } - -} diff --git a/testcases/verification/datastructures/RedBlackTreeDeletion.scala b/testcases/verification/datastructures/RedBlackTreeDeletion.scala deleted file mode 100644 index fed0247b6b4c746e6f576b997d9ba03ce2b3e940..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/RedBlackTreeDeletion.scala +++ /dev/null @@ -1,272 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - case class DoubleBlack() extends Color - case class NegativeBlack() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class DoubleBlackEmpty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - def hasRedBlackNodes(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),l,_,r) => hasRedBlackNodes(l) && hasRedBlackNodes(r) - case Node(Red(),l,_,r) => hasRedBlackNodes(l) && hasRedBlackNodes(r) - case _ => false - } - - def hasRedBlackDesc(t: Tree) : Boolean = t match { - case Node(_,l,_,r) => hasRedBlackNodes(l) && hasRedBlackNodes(r) - case Empty() => true - case DoubleBlackEmpty() => true - } - - def content(t: Tree) : Set[Int] = t match { - case Empty() => Set.empty - case DoubleBlackEmpty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : Int = t match { - case Empty() => 0 - case DoubleBlackEmpty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def isNode(t: Tree) : Boolean = t match { - case Node(_,_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = { - require(hasRedBlackNodes(t)) - t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = { - require(hasRedBlackNodes(t)) - t match { - case Empty() => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - } - - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && hasRedBlackNodes(t)) - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if (x < y) balance(c, ins(x, a), y, b) - else if (x == y) Node(c,a,y,b) - else balance(c,a,y,ins(x, b)) - } - } ensuring (res => content(res) == content(t) ++ Set(x) - && size(t) <= size(res) && size(res) <= size(t) + 1 - && redDescHaveBlackChildren(res) - && hasRedBlackNodes(res) - ) - - def makeBlack(n: Tree): Tree = { - require(redDescHaveBlackChildren(n) && hasRedBlackNodes(n)) - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } ensuring(res => redNodesHaveBlackChildren(res) && hasRedBlackNodes(res)) - - def makeRed(n: Tree) : Tree = { - n match { - case Node(_, l, v, r) => Node(Red(), l, v, r) - case _ => n - } - } - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && hasRedBlackNodes(t)) - makeBlack(ins(x, t)) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res) && hasRedBlackNodes(res)) - -// def buggyAdd(x: Int, t: Tree): Tree = { -// require(redNodesHaveBlackChildren(t)) -// // makeBlack(ins(x, t)) -// ins(x, t) -// } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res)) - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - // require( - // Node(c,a,x,b) match { - // case Node(Black(),Node(Red(),Node(Red(),a,_,b),_,c),_,d) => - // redNodesHaveBlackChildren(a) && - // redNodesHaveBlackChildren(b) && - // redNodesHaveBlackChildren(c) && - // redNodesHaveBlackChildren(d) - // case Node(Black(),Node(Red(),a,_,Node(Red(),b,_,c)),_,d) => - // redNodesHaveBlackChildren(a) && - // redNodesHaveBlackChildren(b) && - // redNodesHaveBlackChildren(c) && - // redNodesHaveBlackChildren(d) - // case Node(Black(),a,_,Node(Red(),Node(Red(),b,_,c),_,d)) => - // redNodesHaveBlackChildren(a) && - // redNodesHaveBlackChildren(b) && - // redNodesHaveBlackChildren(c) && - // redNodesHaveBlackChildren(d) - // case Node(Black(),a,_,Node(Red(),b,_,Node(Red(),c,_,d))) => - // redNodesHaveBlackChildren(a) && - // redNodesHaveBlackChildren(b) && - // redNodesHaveBlackChildren(c) && - // redNodesHaveBlackChildren(d) - // case t => redDescHaveBlackChildren(t) - // } - // ) - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - - case Node(DoubleBlack(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Black(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(DoubleBlack(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Black(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(DoubleBlack(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Black(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(DoubleBlack(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Black(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - - case Node(DoubleBlack(),a,xV,Node(NegativeBlack(),Node(Black(),b,yV,c),zV,d)) => - Node(Black(),Node(Black(),a,xV,b),yV,balance(Black(),c,zV,makeRed(d))) - case Node(DoubleBlack(),Node(NegativeBlack(),a,xV,Node(Black(),b,yV,c)),zV,d) => - Node(Black(),balance(Black(),makeRed(a),xV,b),yV,Node(Black(),c,zV,d)) - - case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b)) /*&& redDescHaveBlackChildren(res)*/) - - /* Deletion */ - def incColor(c: Color) : Color = { - require(c != DoubleBlack()) - c match { - case Black() => DoubleBlack() - case Red() => Black() - case NegativeBlack() => Red() - // case DoubleBlack() => throw new Exception("Incrementing double black color") - } - } ensuring(_ != NegativeBlack()) - - def incColor(t: Tree) : Tree = { - require(!isDoubleBlack(t)) - t match { - case Node(c, l, k, r) => Node(incColor(c), l, k, r) - case Empty() => DoubleBlackEmpty() - // case _ => throw new Exception("Incrementing double black leaf") - } - } ensuring(!isNegativeBlack(_)) - - def decColor(c: Color) : Color = { - require(c != NegativeBlack()) - c match { - case DoubleBlack() => Black() - case Black() => Red() - case Red() => NegativeBlack() - // case NegativeBlack() => throw new Exception("Decrementing negative black color") - } - } ensuring(_ != DoubleBlack()) - - def decColor(t: Tree) : Tree = { - require(!isNegativeBlack(t) && t != Empty()) - t match { - case Node(c, l, k, r) => Node(decColor(c), l, k, r) - case DoubleBlackEmpty() => Empty() - // case _ => throw new Exception("Decrementing black leaf") - } - } ensuring(!isDoubleBlack(_)) - - def del(node: Tree, key: Int) : Tree = { - require(redNodesHaveBlackChildren(node) && hasRedBlackNodes(node)) - node match { - case Node(c, l, k, r) => - if (key < k) bubble(c, del(l, key), k, r) - else if (key == k) remove(node) - else bubble(c, l, k, del(r, key)) - case _ => node - } - } ensuring(res => redNodesHaveBlackChildren(res) && hasRedBlackNodes(res)) - - def max(t: Tree) : Int = { - require(isNode(t)) - t match { - case Node(c, l, k, r @ Node(cr, lr, kr, rr)) => max(r) - case Node(c, l, k, r) => k - // case _ => throw new Exception("Searching for max in a leaf") - } - } - - // note: there are unnecessary cases in Racket code file - def remove(node: Tree) : Tree = { - require(redNodesHaveBlackChildren(node) && hasRedBlackNodes(node)) - node match { - // Leaves are easy to kill: - case Node(Red(), Empty(), k, Empty()) => Empty() - case Node(Black(), Empty(), k, Empty()) => DoubleBlackEmpty() - - // Killing a node with one child: - case Node(Black(), Node(Red(), l, k, r), _, Empty()) => Node(Black(), l, k, r) - case Node(Black(), Empty(), _, Node(Red(), l, k, r)) => Node(Black(), l, k, r) - - // Killing a node with two sub-trees: - case Node(c, l @ Node(_, _, _, _), _, r @ Node(_, _, _, _)) => - val maxV = max(l) - val newL = removeMax(l) - bubble(c, newL, maxV, r) - case _ => error[Tree]("Removing an unexpected tree") - } - } ensuring(res => hasRedBlackDesc(res)) - - def removeMax(node: Tree) : Tree = { - require(redNodesHaveBlackChildren(node) && isNode(node) && hasRedBlackNodes(node)) - node match { - case Node(_, l, _, Empty()) => remove(node) - case Node(c, l, k, r) => bubble(c, l, k, removeMax(r)) - // case _ => throw new Exception("Removing max from a leaf") - } - } ensuring(res => redNodesHaveBlackChildren(res)) - - def isDoubleBlack(t: Tree) : Boolean = t match { - case DoubleBlackEmpty() => true - case Node(DoubleBlack(), _, _, _) => true - case _ => false - } - - def isNegativeBlack(t: Tree) : Boolean = t match { - case Node(NegativeBlack(), _, _, _) => true - case _ => false - } - - def bubble(c: Color, l: Tree, k: Int, r: Tree) : Tree = { - if (isDoubleBlack(l) || isDoubleBlack(r)) { - balance(incColor(c), decColor(l), k, decColor(r)) - } else { - Node(c, l, k, r) - } - } -} diff --git a/testcases/verification/datastructures/RedBlackTreeWithOrder.scala b/testcases/verification/datastructures/RedBlackTreeWithOrder.scala deleted file mode 100644 index c7f380df8a91c0184c6dc8f6eac7a577cf821a85..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/RedBlackTreeWithOrder.scala +++ /dev/null @@ -1,166 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree - - sealed abstract class OptionInt - case class Some(v : Int) extends OptionInt - case class None() extends OptionInt - - def content(t: Tree) : Set[Int] = t match { - case Empty() => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : Int = t match { - case Empty() => 0 - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty() => true - } - - def blackHeight(t : Tree) : Int = t match { - case Empty() => 1 - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - } - - def orderedKeys(t : Tree) : Boolean = orderedKeys(t, None(), None()) - - def orderedKeys(t : Tree, min : OptionInt, max : OptionInt) : Boolean = t match { - case Empty() => true - case Node(c,a,v,b) => - val minOK = - min match { - case Some(minVal) => - v > minVal - case None() => true - } - val maxOK = - max match { - case Some(maxVal) => - v < maxVal - case None() => true - } - minOK && maxOK && orderedKeys(a, min, Some(v)) && orderedKeys(b, Some(v), max) - } - - // <<insert element x into the tree t>> - def ins(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && orderedKeys(t)) - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if (x < y) balance(c, ins(x, a), y, b) - else if (x == y) Node(c,a,y,b) - else balance(c,a,y,ins(x, b)) - } - } ensuring (res => content(res) == content(t) ++ Set(x) - && size(t) <= size(res) && size(res) <= size(t) + 1 - && redDescHaveBlackChildren(res) - && blackBalanced(res) - && orderedKeys(res) - ) - - def makeBlack(n: Tree): Tree = { - require(redDescHaveBlackChildren(n) && blackBalanced(n) && orderedKeys(n)) - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } ensuring(res => redNodesHaveBlackChildren(res) && blackBalanced(res) && orderedKeys(res)) - - def add(x: Int, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) && orderedKeys(t)) - makeBlack(ins(x, t)) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res) && blackBalanced(res) && orderedKeys(res)) - -// def buggyAdd(x: Int, t: Tree): Tree = { -// require(redNodesHaveBlackChildren(t)) -// // makeBlack(ins(x, t)) -// ins(x, t) -// } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res)) - - def balance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - require(orderedKeys(a, None(), Some(x)) && orderedKeys(b, Some(x), None())) - // require( - // Node(c,a,x,b) match { - // case Node(Black(),Node(Red(),Node(Red(),a,_,b),_,c),_,d) => - // redNodesHaveBlackChildren(a) && - // redNodesHaveBlackChildren(b) && - // redNodesHaveBlackChildren(c) && - // redNodesHaveBlackChildren(d) - // case Node(Black(),Node(Red(),a,_,Node(Red(),b,_,c)),_,d) => - // redNodesHaveBlackChildren(a) && - // redNodesHaveBlackChildren(b) && - // redNodesHaveBlackChildren(c) && - // redNodesHaveBlackChildren(d) - // case Node(Black(),a,_,Node(Red(),Node(Red(),b,_,c),_,d)) => - // redNodesHaveBlackChildren(a) && - // redNodesHaveBlackChildren(b) && - // redNodesHaveBlackChildren(c) && - // redNodesHaveBlackChildren(d) - // case Node(Black(),a,_,Node(Red(),b,_,Node(Red(),c,_,d))) => - // redNodesHaveBlackChildren(a) && - // redNodesHaveBlackChildren(b) && - // redNodesHaveBlackChildren(c) && - // redNodesHaveBlackChildren(d) - // case t => redDescHaveBlackChildren(t) - // } - // ) - Node(c,a,x,b) match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b)) && orderedKeys(res))// && redDescHaveBlackChildren(res)) - - // def buggyBalance(c: Color, a: Tree, x: Int, b: Tree): Tree = { - // Node(c,a,x,b) match { - // case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - // Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - // case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - // Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - // case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - // Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - // case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - // Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - // } - // } ensuring (res => content(res) == content(Node(c,a,x,b)) ) // && redDescHaveBlackChildren(res)) - - def generateRB(t : Tree) : Boolean = (blackHeight(t) != 3 || !blackBalanced(t) || !orderedKeys(t)) holds -} diff --git a/testcases/verification/datastructures/SearchLinkedList.scala b/testcases/verification/datastructures/SearchLinkedList.scala deleted file mode 100644 index f85d51421fa5620105bf402021e95d997315977e..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/SearchLinkedList.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object SearchLinkedList { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - def size(list : List) : Int = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contains(list : List, elem : Int) : Boolean = (list match { - case Nil() => false - case Cons(x, xs) => x == elem || contains(xs, elem) - }) - - def firstZero(list : List) : Int = (list match { - case Nil() => 0 - case Cons(x, xs) => if (x == 0) 0 else firstZero(xs) + 1 - }) ensuring (res => - res >= 0 && (if (contains(list, 0)) { - firstZeroAtPos(list, res) - } else { - res == size(list) - })) - - def firstZeroAtPos(list : List, pos : Int) : Boolean = { - list match { - case Nil() => false - case Cons(x, xs) => if (pos == 0) x == 0 else x != 0 && firstZeroAtPos(xs, pos - 1) - } - } - - def goal(list : List, i : Int) : Boolean = { - if(firstZero(list) == i) { - if(contains(list, 0)) { - firstZeroAtPos(list, i) - } else { - i == size(list) - } - } else { - true - } - } holds -} diff --git a/testcases/verification/datastructures/SortedList.scala b/testcases/verification/datastructures/SortedList.scala deleted file mode 100644 index 91b3e2af3998d53221ba89f90226643fc57dcae7..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/SortedList.scala +++ /dev/null @@ -1,126 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object SortedList { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - // proved with unrolling=0 - 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() - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert1(l: List, v: Int) = ( - Cons(v, l) - ) ensuring(res => content(res) == content(l) ++ Set(v) && size(res) >= size(l)) - - def insert2(l: List, v: Int): List = (l match { - case Nil() => Cons(v, Nil()) - case Cons(x, tail) => if (x == v) l else Cons(x, insert2(tail, v)) - }) ensuring(res => content(res) == content(l) ++ Set(v) && size(res) >= size(l)) - - def insert3(l: List, v: Int): List = { - require(isStrictlySorted(l)) - - l match { - case Nil() => Cons(v, Nil()) - case Cons(x, tail) => - if (v < x) { - Cons(v, l) - } else if (v == x) { - l - } else { - Cons(x, insert3(tail, v)) - } - } - } ensuring(res => content(res) == content(l) ++ Set(v) && size(res) >= size(l)) - - def delete1(l: List, v: Int): List = (l match { - case Nil() => Nil() - case Cons(x, tail) => if (x == v) delete1(tail, v) else Cons(x, delete1(tail, v)) - }) ensuring(res => !(content(res) contains v) && size(res) <= size(l)) - - //def delete2(l: List, v: Int): List = { - // require(isStrictlySorted(l)) - - // l match { - // case Nil() => Nil() - // case Cons(x, tail) => - // if (x == v) { - // tail - // } else { - // Cons(x, delete2(tail, v)) - // } - // } - //} ensuring(res => !(content(res) contains v) && size(res) <= size(l)) - - def contains(list : List, elem : Int) : Boolean = (list match { - case Nil() => false - case Cons(x, xs) => if(elem == x) true else contains(xs, elem) - }) ensuring(res => res == content(list).contains(elem)) - - def deleteMagic(head: Int, tail: List, toDelete: Int): List = ({ - //require(isStrictlySorted(Cons(head, tail)) && toDelete < head); - require(isStrictlySorted(Cons(toDelete, Cons(head, tail)))) - - Cons(head, tail) - })ensuring(res => !(content(res) contains toDelete)) - - def delete3(l: List, v: Int): List = { - require(isStrictlySorted(l)) - - l match { - case Nil() => Nil() - case Cons(x, tail) => - if (x == v) { - tail - } else if (v < x) { - deleteMagic(x, tail, v) - } else { - Cons(x, delete3(tail, v)) - } - } - } ensuring(res => !(content(res) contains v) && size(res) <= size(l)) - - @induct - def isStrictlySorted(l: List): Boolean = (l match { - case Nil() => true - case Cons(x, Nil()) => true - case Cons(x, xs @ Cons(y, ys)) => { - if(x < y) { - if(isStrictlySorted(xs)) discard(ltaLemma(x, y, ys)) else false - } else { - false - } - } - }) ensuring(res => !res || (l match { - case Nil() => true - case Cons(x, xs) => lessThanAll(x, xs) - })) - - def lessThanAll(x : Int, l : List) : Boolean = (l match { - case Nil() => true - case Cons(y, ys) => if(x < y) lessThanAll(x, ys) else false - }) ensuring(res => !res || !contains(l, x)) - - def discard(value : Boolean) = true - - @induct - def ltaLemma(x : Int, y : Int, l : List) : Boolean = { - require(lessThanAll(y, l) && x < y) - lessThanAll(x, Cons(y, l)) - } holds - - 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)) - } -} diff --git a/testcases/verification/datastructures/TraceInductTest.scala b/testcases/verification/datastructures/TraceInductTest.scala deleted file mode 100644 index 77e24e53055805e54f2f2263818e279a205c4cbd..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/TraceInductTest.scala +++ /dev/null @@ -1,69 +0,0 @@ -import leon.annotation._ -import leon.lang._ -import leon.collection._ - -object TraceInductTest { - sealed abstract class IList - case class ICons(head: BigInt, tail: IList) extends IList - case class INil() extends IList - - // proved with unrolling=0 - def size(l: IList): BigInt = (l match { - case INil() => BigInt(0) - case ICons(_, t) => 1 + size(t) - }) //ensuring(res => res >= 0) - - @traceInduct - def nonNegSize(l: IList): Boolean = { - size(l) >= 0 - } holds - - def reverse0(l1: IList, l2: IList): IList = (l1 match { - case INil() => l2 - case ICons(x, xs) => reverse0(xs, ICons(x, l2)) - }) - - def content(l: IList): Set[BigInt] = l match { - case INil() => Set.empty[BigInt] - case ICons(x, xs) => Set(x) ++ content(xs) - } - - @traceInduct("reverse0") - def revPreservesContent(l1: IList, l2: IList): Boolean = { - content(l1) ++ content(l2) == content(reverse0(l1, l2)) - } holds - - def insertAtIndex[T](l: List[T], i: BigInt, y: T): List[T] = { - require(0 <= i && i <= l.size) - l match { - case Nil() => - Cons[T](y, Nil()) - case _ if i == 0 => - Cons[T](y, l) - case Cons(x, tail) => - Cons[T](x, insertAtIndex(tail, i - 1, y)) - } - } - - // A lemma about `append` and `insertAtIndex` - @traceInduct("insertAtIndex") - def appendInsertIndex[T](l1: List[T], l2: List[T], i: BigInt, y: T): Boolean = { - require(0 <= i && i <= l1.size + l2.size) - (insertAtIndex((l1 ++ l2), i, y) == ( - if (i < l1.size) insertAtIndex(l1, i, y) ++ l2 - else l1 ++ insertAtIndex(l2, (i - l1.size), y))) - }.holds - - def power(x: BigInt, y: BigInt) : BigInt = { - require(y >= 0 && x >= 1) - if(y < 1) BigInt(1) - else - x * power(x, y - 1) - } ensuring(_ >= 1) - - @traceInduct - def powerMonotone(x1: BigInt, x2: BigInt, y: BigInt) = { - require(y >= 0) - (1 <= x1 && x1 <= x2) ==> power(x1, y) <= power(x2, y) - } holds -} diff --git a/testcases/verification/datastructures/TreeListSetNoDup.scala b/testcases/verification/datastructures/TreeListSetNoDup.scala deleted file mode 100644 index ef72d3a6839548d541df8cece6dd4c00169bf56d..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/TreeListSetNoDup.scala +++ /dev/null @@ -1,99 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object BinaryTree { - // list of integers - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - // set of elements from l - def l2s(l: List): Set[Int] = l match { - case Nil() => Set() - case Cons(i, t) => Set(i) ++ l2s(t) - } - - // l has no duplicates, nor elements from s - def noDupWith(l:List,s:Set[Int]) : Boolean = l match { - case Nil() => true - case Cons(h,l1) => !s.contains(h) && noDupWith(l1,Set(h) ++ s) - } - - // l has no duplicates - def noDup(l:List): Boolean = noDupWith(l,Set.empty[Int]) - - // removing duplicates from l1 gives l2 - def removeDupGives(l1:List,l2:List) : Boolean = - l2s(l1)==l2s(l2) && noDup(l2) - - def removeDupAnd(l:List,s0:Set[Int]) : List = (l match { - case Nil() => Nil() - case Cons(h,l1) => { - if (s0.contains(h)) removeDupAnd(l1,s0) - else Cons(h,removeDupAnd(l1,Set(h)++s0)) - } - }) ensuring (res => noDupWith(res,s0) && l2s(l) ++ s0 == l2s(res) ++ s0) - - def removeDup(l:List) : List = ({ - removeDupAnd(l,Set.empty[Int]) - }) ensuring (res => removeDupGives(l,res)) - - def revRemoveDupAnd(l:List,s0:Set[Int],l0:List) : List = ({ - require(l2s(l0).subsetOf(s0) && noDup(l0)) - l match { - case Nil() => l0 - case Cons(h,l1) => { - if (s0.contains(h)) revRemoveDupAnd(l1,s0,l0) - else revRemoveDupAnd(l1,Set(h)++s0,Cons(h,l0)) - } - } - }) ensuring (res => noDupWith(res,s0) && l2s(l) ++l2s(l0) ++ s0 == l2s(res) ++ s0) - - def revRemoveDup(l:List) : List = ({ - revRemoveDupAnd( - revRemoveDupAnd(l,Set.empty[Int],Nil()), - Set.empty[Int],Nil()) - }) ensuring (res => removeDupGives(l,res)) - - // tree of integers - sealed abstract class Tree - case class Node(left : Tree, value : Int, right : Tree) extends Tree - case class Leaf() extends Tree - - // set of elements from t - def t2s(t : Tree): Set[Int] = t match { - case Leaf() => Set.empty[Int] - case Node(l, v, r) => t2s(l) ++ Set(v) ++ t2s(r) - } - - // list of t, in order, in from of l0 - def seqWith(t:Tree,l0:List) : List = (t match { - case Leaf() => l0 - case Node(l, v, r) => seqWith(l,Cons(v,seqWith(r,l0))) - }) ensuring (res => l2s(res) == t2s(t) ++ l2s(l0)) - - // list of tree t - def t2l(t:Tree) : List = seqWith(t,Nil()) - - // list of elements of t, in order, without duplicates, in front of l0 - def seqNoDup(t:Tree,l0:List,s0:Set[Int]) : (List,Set[Int]) = ({ - require(l2s(l0).subsetOf(s0) && noDup(l0)) - t match { - case Leaf() => (l0,s0) - case Node(l, v, r) => { - val (rl,rs) = seqNoDup(r,l0,s0) - val (l1,s1) = if (rs.contains(v)) (rl,rs) else (Cons(v,rl),Set(v)++rs) - seqNoDup(l,l1,s1) - } - } - }) ensuring (res => { - val (lres,sres) = res - l2s(lres).subsetOf(sres) && - removeDupGives(t2l(t), lres) - }) - - // list of elements of t, without duplicates - def t2lNoDup(t:Tree) : List = ({ - seqNoDup(t,Nil(),Set.empty[Int])._1 - }) ensuring (res => removeDupGives(t2l(t), res)) -} diff --git a/testcases/verification/datastructures/TreeMap.scala b/testcases/verification/datastructures/TreeMap.scala deleted file mode 100644 index ce6fd7f8170eb2115d245390b4b82f55a5aa5535..0000000000000000000000000000000000000000 --- a/testcases/verification/datastructures/TreeMap.scala +++ /dev/null @@ -1,273 +0,0 @@ -import leon.lang._ - -object TreeMap { - sealed abstract class TreeMap - case class Empty() extends TreeMap - case class Node(key: Int, datum: Int, left: TreeMap, right: TreeMap, height: Int) extends TreeMap - - sealed abstract class RemoveMinTripleAbs - case class RemoveMinTriple(key: Int, datum: Int, tree: TreeMap) extends RemoveMinTripleAbs - - sealed abstract class IntList - case class Cons(head: Int, tail: IntList) extends IntList - case class Nil() extends IntList - - sealed abstract class IntOpt - case class Some(value: Int) extends IntOpt - case class None() extends IntOpt - - sealed abstract class TripleAbs - case class Triple(lmax: IntOpt, isSorted: Boolean, rmin: IntOpt) extends TripleAbs - - sealed abstract class TriplePairAbs - case class TriplePair(left: TripleAbs, right: TripleAbs) extends TriplePairAbs - - def mmax(i: Int, j: Int) : Int = if(i >= j) i else j - - // checks that the height field is set properly. - def nodeHeightsAreCorrect(tm: TreeMap) : Boolean = (tm match { - case Empty() => true - case n @ Node(_, _, l, r, h) => h == realHeight(n) && nodeHeightsAreCorrect(l) && nodeHeightsAreCorrect(r) - }) ensuring(res => !res || (height(tm) == realHeight(tm)) ) - - // measures "real height" - def realHeight(tm: TreeMap) : Int = (tm match { - case Empty() => 0 - case Node(_, _, l, r, _) => mmax(realHeight(l), realHeight(r)) + 1 - }) ensuring(_ >= 0) - - def height(tm: TreeMap): Int = (tm match { - case Empty() => 0 - case Node(_,_,_,_,h) => h - }) - - /* - def invariant0(tm : TreeMap) : Boolean = { - require(nodeHeightsAreCorrect(tm)) - height(tm) == realHeight(tm) - } holds - */ - - def isBST(tree: TreeMap) : Boolean = isBST0(tree) match { - case Triple(_, v, _) => v - } - - def isBST0(tree: TreeMap) : TripleAbs = tree match { - case Empty() => Triple(None(), true, None()) - - case Node(v, _, l, r, _) => TriplePair(isBST0(l), isBST0(r)) match { - case TriplePair(Triple(None(),t1,None()),Triple(None(),t2,None())) - if(t1 && t2) => - Triple(Some(v),true,Some(v)) - case TriplePair(Triple(Some(minL),t1,Some(maxL)),Triple(None(),t2,None())) - if(t1 && t2 && minL <= maxL && maxL < v) => - Triple(Some(minL),true,Some(v)) - case TriplePair(Triple(None(),t1,None()),Triple(Some(minR),t2,Some(maxR))) - if(t1 && t2 && minR <= maxR && v < minR) => - Triple(Some(v),true,Some(maxR)) - case TriplePair(Triple(Some(minL),t1,Some(maxL)),Triple(Some(minR),t2,Some(maxR))) - if(t1 && t2 && minL <= maxL && minR <= maxR && maxL < v && v < minR) => - Triple(Some(minL),true,Some(maxR)) - - case _ => Triple(None(),false,None()) - } - } - - def setOf(tm: TreeMap): Set[Int] = tm match { - case Empty() => Set.empty - case Node(d, _, l, r, _) => Set(d) ++ setOf(l) ++ setOf(r) - } - - def create(k: Int, d: Int, l: TreeMap, r: TreeMap): TreeMap = { - require( - nodeHeightsAreCorrect(l) && nodeHeightsAreCorrect(r) && isBalanced(l) && isBalanced(r) && - height(l) - height(r) <= 2 && height(r) - height(l) <= 2 && - isBST(l) && isBST(r) && - (TriplePair(isBST0(l),isBST0(r)) match { - case TriplePair(Triple(_,_,Some(lmax)), Triple(Some(rmin),_,_)) => lmax < k && k < rmin - case TriplePair(Triple(_,_,_),Triple(Some(rmin),_,_)) => k < rmin - case TriplePair(Triple(_,_,Some(lmax)),Triple(_,_,_)) => lmax < k - case _ => true - }) - ) - val hl = height(l) - val hr = height(r) - Node(k, d, l, r, mmax(hl, hr) + 1) - } ensuring( - res => setOf(res) == Set(k) ++ setOf(l) ++ setOf(r) && - isBalanced(res) && isBST(res) - ) - - def balance(x: Int, d: Int, l: TreeMap, r: TreeMap): TreeMap = { - require( - nodeHeightsAreCorrect(l) && nodeHeightsAreCorrect(r) && isBalanced(l) && isBalanced(r) && - height(l) - height(r) <= 3 && height(r) - height(l) <= 3 && - (r match { - case Empty() => false - case Node(_, _, Empty(), _, _) => false - case _ => true - }) && - (l match { - case Empty() => false - case Node(_, _, _, Empty(), _) => false - case _ => true - }) - ) - - val hl = height(l) - val hr = height(r) - if (hr > hl + 2) { - r match { - case Node(rv, rd, rl, rr, h) => - if (height(rr) >= height(rl)) { - create(rv, rd, create(x, d, l, rl), rr) - } else { - rl match { - case Node(rlv, rld, rll, rlr, h) => create(rlv, rld, create(x, d, l, rll), create(rv, rd, rlr, rr)) - } - } - } - } else if (hl > hr + 2) { - l match { - case Node(lv, ld, ll, lr, h) => - if (height(ll) >= height(lr)) { - create(lv, ld, ll, create(x, d, lr, r)) - } else { - lr match { - case Node(lrv, lrd, lrl, lrr, h) => create(lrv, lrd, create(lv, ld, ll, lrl), create(x, d, lrr, r)) - } - } - } - } else - Node(x, d, l, r, if(hl >= hr) hl + 1 else hr + 1) - } ensuring(res => isBalanced(res)) // && setOf(res) == Set[Int](x) ++ setOf(l) ++ setOf(r)) - - def add(x: Int, data: Int, tm: TreeMap): TreeMap = { - require(isBalanced(tm) && nodeHeightsAreCorrect(tm)) - tm match { - case Empty() => Node(x, data, Empty(), Empty(), 1) - case Node(v, d, l, r, h) => - if (x == v) - Node(x, data, l, r, h) - else if (x < v) - balance(v, d, add(x, data, l), r) - else - balance(v, d, l, add(x, data, r)) - } - } ensuring(res => isBalanced(res)) // && setOf(res) == Set(x) ++ setOf(tm)) - - def removeMinBinding(t: TreeMap): RemoveMinTripleAbs = { - require(isBalanced(t) && (t match { - case Empty() => false - case _ => true - })) - t match { - case Node(x, d, l, r, h) => - l match { - case Empty() => RemoveMinTriple(x, d, r) - case Node(_,_,ll, lr, h2) => - removeMinBinding(l) match { - case RemoveMinTriple(key, datum, tree) => - RemoveMinTriple(key, datum, balance(x, d, tree, r)) - } - } - } - } ensuring(res => res match { - case RemoveMinTriple(resKey, _, resTree) => isBalanced(resTree) // && (setOf(resTree) == setOf(t) -- Set(resKey)) && setOf(resTree) ++ Set(resKey) == setOf(t) - }) - - // m is not used here! - def merge(m: Int, t1: TreeMap, t2: TreeMap): TreeMap = { - require(isBalanced(t1) && isBalanced(t2)) - t1 match { - case Empty() => t2 - case Node(_, _, ll, lr, h1) => - t2 match { - case Empty() => t1 - case Node(r, _, rl, rr, h2) => - removeMinBinding(t2) match { - case RemoveMinTriple(key, datum, tree) => balance(key, datum, t1, tree) - } - } - } - } ensuring(res => isBalanced(res)) // && setOf(res) == setOf(t1) ++ setOf(t2)) - - def remove(x: Int, t: TreeMap): TreeMap = { - require(isBalanced(t)) - t match { - case Empty() => Empty() - case Node(v, d, l, r, h) => - if (x == v) - merge(x, l, r) - else if (x < v) - balance(v, d, remove(x, l), r) - else - balance(v, d, l, remove(x, r)) - } - } ensuring(res => isBalanced(res)) // && (setOf(res) == setOf(t) -- Set(x))) - - def find(t: TreeMap, x: Int): Int = { - require(t match { - case Empty() => false - case _ => true - }) - t match { - case Node(d, _, l, r, _) => - if (x == d) - d - else if (x < d) - find(l, x) - else - find(r, x) - } - } - - // let us specialize iter for the condition k < v - def iter1(t: TreeMap, v: Int): Boolean = t match { - case Empty() => true - case Node(k, d, l, r, _) => - k < v && iter1(l, v) && iter1(r, v) - } - - // also for the condition v < k - def iter2(t: TreeMap, v: Int): Boolean = t match { - case Empty() => true - case Node(k, d, l, r, _) => - v < k && iter2(l, v) && iter2(r, v) - } - - def isBSTold(t: TreeMap): Boolean = t match { - case Empty() => true - case Node(v, _, l, r, _) => - iter1(l, v) && iter2(r, v) && isBSTold(l) && isBSTold(r) - } - - // We have a variant of AVL trees where the heights of the subtrees differ at - // most by 2 - def isBalanced(t: TreeMap): Boolean = t match { - case Empty() => true - case Node(_, _, l, r, _) => (height(l) - height(r) <= 2 && height(r) - height(l) <= 2) && isBalanced(l) && isBalanced(r) - } - - /** list conversion **/ - - def append(k: Int, xs: IntList, ys: IntList): IntList = xs match { - case Nil() => Cons(k, ys) - case Cons(x, xss) => Cons(x, append(k, xss, ys)) - } - - def toList(t: TreeMap): IntList = t match { - case Empty() => Nil() - case Node(v, _, l, r, _) => - val ls = toList(l) - val rs = toList(r) - append(v, ls, rs) - } - - def isSorted(l: IntList): Boolean = l match { - case Nil() => true - case Cons(x, Nil()) => true - case Cons(x1, Cons(x2, xs)) => x1 <= x2 && isSorted(Cons(x2, xs)) - } - -} diff --git a/testcases/verification/editor/AsciiToPos.scala b/testcases/verification/editor/AsciiToPos.scala deleted file mode 100644 index 1514ccc13733e6e3571a51081a89a2c490a72f30..0000000000000000000000000000000000000000 --- a/testcases/verification/editor/AsciiToPos.scala +++ /dev/null @@ -1,46 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.collection._ - -object Justify { - def tokenize(ascii: List[Char]): List[String] = tokenize0(ascii, "") - def tokenize0(ascii: List[Char], wordAcc: String): List[String] = ascii match { - case Nil() => Nil() - case Cons(h, t) => if (h == ' ') { - if (wordAcc.length == 0) { - tokenize0(t, wordAcc) - } else { - Cons(wordAcc, tokenize0(t, "")) - } - } else { - tokenize0(t, h + wordAcc) - } - } - - def asciiToPos(in: List[Char], index: Int): List[Int] = in match { - case Nil() => Nil() - case Cons(head, tail) => if(head == ' ') Cons(index, asciiToPos(tail, index+1)) else asciiToPos(tail, index+1) - } - - def posToAscii(positions: List[Int], originalText: List[Char], currentPos: Int): List[Char] = positions match { - case Cons(start, rest) => - if(start > currentPos) { - Cons(' ', posToAscii(rest, originalText, currentPos+1)) - } else { - originalText match { - case Cons(l, ls) => - if(l == ' ') { - Cons(' ', posToAscii(rest, ls, currentPos+1)) - } else { - Cons(l, posToAscii(positions, ls, currentPos+1)) - } - case Nil() => Nil() - } - } - case Nil() => Nil() - } - - def posToAsciiKeepTokens(ascii: List[Char]) = { - posToAscii(asciiToPos(ascii, 0), ascii, 0) - } ensuring(res => tokenize(res) == tokenize(ascii)) -} diff --git a/testcases/verification/editor/TextJustifyNoPost.scala b/testcases/verification/editor/TextJustifyNoPost.scala deleted file mode 100644 index e5b06bc94aa7228c5d1fba9e411f410a6a7a4615..0000000000000000000000000000000000000000 --- a/testcases/verification/editor/TextJustifyNoPost.scala +++ /dev/null @@ -1,75 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.collection._ - -object Justify { - /* - * The Science of Programming from David Gries Section 20.1 - - * The goal is to justify a text. We are given a list of indices corresponding - * to the columns of the starting point of each word. Each words are already - * separated by one space. The parameter s is the additional number of spaces - * at the end of the line that we will need to add between words. We - * want the number of space on the same line to differ by at most one. - * - * If we denote by p and q the two number of spaces between words (p and q differ - * only by 1), then we want to only switch once the number of space between words - * on the line. This means that we first separate words using p, then we do it using - * q until the end of the line. - * - * z is the line number, the rule is for odd line number to have more spaces on the right (q=p+1) - * and for even line number to have more spaces on the left (p=q+1). We do not want trailing - * spaces. - * - * n is the number of words on the line. - * - * If we apply this justify to each line of a text separately, this should lead to a good looking - * justified text. - - * Here is an example: - * - * justifying lines by - * inserting extra blanks is - * one task of a text editor. - * - * results in: - * - * justifying lines by - * inserting extra blanks is - * one task of a text editor. - */ - - def addSpaces(words: List[BigInt], p: BigInt, q: BigInt, t: BigInt, n: BigInt, i: BigInt): List[BigInt] = words match { - case Nil() => Nil() - case Cons(head, tail) => - if(i <= t) Cons(head + p*(i-1), addSpaces(tail, p, q, t, n, i+1)) - else if(i > t && i <= n) Cons(head + p*(t-1) + q*(i-t), addSpaces(tail, p, q, t, n, i+1)) - else Nil() //this should never happen - } - - //this version implements the computation of parameters - def justifyParamsImpl(n: BigInt, z: BigInt, s: BigInt): (BigInt, BigInt, BigInt) = { - require(n >= 2 && s >= 0 && z >= 1) - val (q, t, p) = if(z % 2 == 0) { - val tmp = s / (n-1) - (tmp, 1 + (s % (n - 1)), tmp + 1) - } else { - val tmp = s / (n-1) - (tmp + 1, n - (s % (n - 1)), tmp) - } - (q, t, p) - } - - def justifyImpl(n: BigInt, z: BigInt, s: BigInt, words: List[BigInt]): (BigInt, BigInt, BigInt, List[BigInt]) = { - require(n >= 2 && s >= 0 && z >= 1) - val (q, t, p) = if(z % 2 == 0) { - val tmp = s / (n-1) - (tmp, 1 + (s % (n - 1)), tmp + 1) - } else { - val tmp = s / (n-1) - (tmp + 1, n - (s % (n - 1)), tmp) - } - (q, t, p, addSpaces(words, p, q, t, n, 0)) - } - -} diff --git a/testcases/verification/graph/MST/MSTMap.scala b/testcases/verification/graph/MST/MSTMap.scala deleted file mode 100644 index e718256b6d226dea77efddadc970ffc44c7dab0f..0000000000000000000000000000000000000000 --- a/testcases/verification/graph/MST/MSTMap.scala +++ /dev/null @@ -1,272 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object MSTMap { - - case class Graph(nVertices : Int, edges : Map[(Int,Int), Int]) - - /* - ----------------------------------------------------------------------------- - MST TESTS Map - ----------------------------------------------------------------------------- - */ - - // Kruskal's algorithm. Straightforward imperative implementation - def mst(g : Graph) : Map[(Int,Int), Int] = { - require(invariant(g) && isUndirected(g) && isConnected(g) && - g.nVertices <= 3) - - var uf_map = Map.empty[Int, Int] //map to represent parent - //relationship to model union find - - var spanningTree = Map.empty[(Int,Int), Int] - var alreadyTested = Map.empty[(Int, Int), Int] - - (while(!isConnected(spanningTree, g.nVertices)) { - val next_edge = getSmallestEdge(g.nVertices, g.edges, alreadyTested) - - val p1 = uFind(next_edge._1, uf_map) - val p2 = uFind(next_edge._2, uf_map) - if(p1 != p2) { - // Edge doesn't create a cycle -> add it to the current - // spanning tree (or actually forest) - spanningTree = spanningTree.updated((next_edge._1, next_edge._2), next_edge._3) - spanningTree = spanningTree.updated((next_edge._2, next_edge._1), next_edge._3) - uf_map = union(p1, p2, uf_map) - } - - alreadyTested = alreadyTested.updated((next_edge._1, next_edge._2), 1) - alreadyTested = alreadyTested.updated((next_edge._2, - next_edge._1), 1) - }) invariant(isAcyclic(spanningTree, g.nVertices)) - - spanningTree - } ensuring(x => isAcyclic(x, g.nVertices) && isConnected(x, g.nVertices)) - // We only verify that the edge set returned corresponds to some - // spanning tree, but not that it is of minimal weight. - - - // Here, we always take the smallest edge regardless whether it - // creates a cycle or not, - // Leon loops - def mstBogus(g : Graph) : Map[(Int,Int), Int] = { - require(invariant(g) && isUndirected(g) && isConnected(g) && - g.nVertices <= 4) - - var edges = g.edges - var spanningTree = Map.empty[(Int,Int), Int] - var alreadyTested = Map.empty[(Int, Int), Int] - - (while(!isConnected(spanningTree, g.nVertices)) { - val next_edge = getSmallestEdge(g.nVertices, edges, alreadyTested) - - // add edge to spanning tree, don't care whether it creates a - // cycle or not - spanningTree = spanningTree.updated((next_edge._1, next_edge._2), next_edge._3) - spanningTree = spanningTree.updated((next_edge._2, next_edge._1), next_edge._3) - - alreadyTested = alreadyTested.updated((next_edge._1, next_edge._2), 1) - alreadyTested = alreadyTested.updated((next_edge._2, - next_edge._1), 1) - }) invariant(isAcyclic(spanningTree, g.nVertices)) - - spanningTree - } ensuring(x => isAcyclic(x, g.nVertices) && isConnected(x, g.nVertices)) - - - /* - ----------------------------------------------------------------------------- - GRAPH FUNCTIONS - ----------------------------------------------------------------------------- - */ - - - def invariant(g : Graph) = { - def noSelfLoops(i : Int) : Boolean = { - if(i >= g.nVertices) true - else if(g.edges.isDefinedAt(i,i)) - false - else - noSelfLoops(i+1) - } - - g.nVertices >= 0 && noSelfLoops(0) - } - - /** - Tests, if g is undirected, that is if for every edge (i,j) there is - also and edge (j,i) - Ignoring weights for the moment - */ - def isUndirected(g: Graph) : Boolean = { - require(invariant(g)) - - val edgeSet = g.edges - var res = true - var i = 0 - while(i < g.nVertices && res) { - var j = 0 - while(j < g.nVertices && res) { - res = !edgeSet.isDefinedAt(i,j) || edgeSet.isDefinedAt(j,i) - - //If weights should considered - if(res && edgeSet.isDefinedAt(i,j)) - res = edgeSet(i,j) == edgeSet(j,i) - - j += 1 - } - i += 1 - } - - res - } - - /* - * Returns the smallest edge in "edges" but not in "forbidden" - * Returns (-1,-1,-1) if there are no more edges. - */ - def getSmallestEdge(nVertices : Int, edges : Map[(Int,Int), Int], - forbidden : Map[(Int,Int), Int]) : (Int, Int, Int) - = { - require (nVertices >= 0) - - /* - In the very specific context of MST, it could be useful to - somehow express that "edges"\"forbidden" is non-empty such that - it this function would always return a valid edge, however, this - property is not easily expressible in Leon. - */ - - var i = 0 - val big = 100000000 - var res = (-1,-1,big) - - while(i < nVertices) { - var j = 0 - while(j < nVertices) { - // leon doesnt recognize "shortcut optimizations", e.g. if - // both if statements were merged to one using &&, it finds - // a counter example - if(edges.isDefinedAt(i,j) && !forbidden.isDefinedAt(i,j)) { - if(edges(i,j) < res._3) - res = (i,j, edges(i,j)) - } - j += 1 - } - i += 1 - } - - if(res == (-1,-1,big)) - (-1,-1,-1) - else - res - } - - def isSpanningTree(g : Graph) : Boolean = { - require(invariant(g) && isUndirected(g)) - isConnected(g) && isAcyclic(g.edges, g.nVertices) - } - - def isConnected(g : Graph) : Boolean = { - require(g.nVertices >= 0 && isUndirected(g)) - isConnected(g.edges, g.nVertices) - } - - def isConnected(edges : Map[(Int,Int), Int], nVertices : Int) : Boolean = { - require(nVertices >= 0) - val uf = calculateUF(edges, nVertices)._1 - - val p = uFind(0, uf) - var i = 1 - - var ret = true - while(i < nVertices && ret) { - if(uFind(i, uf) != p) - ret = false // 0, i are not connected - i += 1 - } - - ret - } - - /* - * Tests, whether the subgraph induced by edges is cycle-free. - */ - def isAcyclic(edges : Map[(Int,Int), Int], nVertices : Int) : Boolean = { - require(nVertices >= 0 && isUndirected(Graph(nVertices, edges))) - !calculateUF(edges, nVertices)._2 - } - - /* - * Does union-find on edgeSet. - * Returns the union-find tree and a boolean set to true if a cycle was found - */ - def calculateUF(edgeSet : Map[(Int,Int), Int], nVertices : Int) : - (Map[Int, Int], Boolean)= { - require(nVertices >= 0) - - var i = 0 - var uf = Map.empty[Int, Int] - var cycle = false - var edges = edgeSet - while(i < nVertices) { - var j = 0 - while(j < nVertices) { - if(edges.isDefinedAt((i,j))) { - if(edges(i, j) != -1) { - val p1 = uFind(i, uf) - val p2 = uFind(j, uf) - if(p1 == p2) - cycle = true - else - uf = union(p1, p2, uf) - - //"remove" twin edge - edges = edges.updated((j,i), -1) - } - } - j += 1 - } - i += 1 - } - - (uf, cycle) - } - - /* ************************************* - Union find - *************************************** */ - def uFind(e : Int, s : Map[Int, Int]) : Int = { - if(!s.isDefinedAt(e)) e - else if(s(e) == e) e - else uFind(s(e), s) - } - - def union(e1 : Int, e2 : Int, s : Map[Int,Int]) : Map[Int, Int] = { - // naive union - val p1 = uFind(e1,s) - val p2 = uFind(e2, s) - - if(p1 != p2) - //naive union - s.updated(p1, p2) //only union if theiy are really in different trees - else - s - } - - - // fsc -d classes -classpath - // ../../leon-2.0/target/scala-2.9.1-1/classes MST.scala - // scala -classpath classes MST - @ignore - def main(args: Array[String]) { - val edges = Map((1,0) -> 10, (0,1) -> 10, (1,2) -> 12, (2,1) -> - 12, (0,2) -> 18, (2,0) -> 18, (3,1) -> 20, (1,3) -> 20) - - val g = Graph(4, edges) - - println(mst(g)); //works - println(mstBogus(g)); // crashes because postcondition doensn't hold - } - -} diff --git a/testcases/verification/graph/SimpleInduction.scala b/testcases/verification/graph/SimpleInduction.scala deleted file mode 100644 index f9bf0bf3de9f80f7c53042798a645146f782b162..0000000000000000000000000000000000000000 --- a/testcases/verification/graph/SimpleInduction.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -/** A simple example of inductive proofs. - * - * These require use of the @induct attribute. See SetIteration.scala for a - * conceptually similar example where Leon cannot use inductive reasoning. - */ -object SimpleInduction { - // a simple linked list - abstract class SimpleList - case class SimpleItem(v : Int, next : SimpleList) extends SimpleList - case class SimpleEnd() extends SimpleList - - // true if all elements have value at least x - def eltsAtLeast(list : SimpleList, x : Int) : Boolean = - list match { - case SimpleItem(v, next) => v >= x && eltsAtLeast(next, x) - case SimpleEnd() => true - } - - @induct - def simpleProposition(list : SimpleList) : Boolean = { - !eltsAtLeast(list, 5) || eltsAtLeast(list, 2) - } holds - - @induct - def noAction(list : SimpleList) : SimpleList = { - require(eltsAtLeast(list, 5)) - list - } ensuring (eltsAtLeast(list, 2)) - - - // A more explicit version of the above to more clearly illustrate where - // inductive reasoning is required. - - // try to prove that x≥a → x≥b for each element - def inductiveStep(list : SimpleList, a : Int, b : Int) : Boolean = - list match { - case SimpleItem(v, next) => (!(v >= a) || v >= b) && inductiveStep(next, a, b) - case SimpleEnd() => true - } - - // another encoding of simpleProposition - @induct - def inductiveProof(list : SimpleList) : Boolean = { - inductiveStep(list, 5, 2) - } holds -} diff --git a/testcases/verification/graph/SortedNDList.scala b/testcases/verification/graph/SortedNDList.scala deleted file mode 100644 index a6f5e11635dd3e9dc955f78e814b2dfc86d6aaac..0000000000000000000000000000000000000000 --- a/testcases/verification/graph/SortedNDList.scala +++ /dev/null @@ -1,103 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -/** Tests for SortedNDList - */ -object SortedNDList { - /** A list containing node, dist pairs. - * - * Sorted by distance, nearest first. Distance must be non-negative. Node - * values must be unique and non-negative. - */ - abstract class SortedNDList - case class ListNode(node: Int, dist: Int, next: SortedNDList) extends SortedNDList - case class ListEnd() extends SortedNDList - - /** List invariant (see description above) */ - @induct - def sndInvariant(list : SortedNDList) : Boolean = { - // Most conditions are commented out. Leon cannot even check adding or - // removing an element satisfies the invariant in this case! - def invRec(list : SortedNDList/*, elts : Set[Int], minDist : Int, len : Int*/) : Boolean = - list match { - case ListNode(n,d,next) => - if (d >= 0/*minDist*/ && n >= 0 /*&& !elts.contains(n)*/) - invRec(next/*,elts++Set(n),d, len + 1*/) - else - false - case ListEnd() => true //len <= 3 - } - - invRec(list/*, Set.empty, 0, 0*/) - } - - /** Simple test function: does adding an element at the start of the list - * maintain the invariant? */ - @induct def addStart(list : SortedNDList, node:Int, dist:Int) : SortedNDList ={ - require (sndInvariant(list) && node>=0 && dist>=0) - ListNode(node,dist,list) - } ensuring(sndInvariant(_)) // Leon cannot verify this even when all the invariant does is check that node and dist are non-negative! - - /* Further tests fail, if run. - - /** Look for node in list and remove, if it exists. */ - @induct - def removeFromList(list : SortedNDList, node : Int) : SortedNDList ={ - // something about this times out - require(sndInvariant(list)) - - //println("removeFromList: "+list) - - list match { - case ListNode(n,d,next) => - if (n == node) - // drop current node and continue search: - removeFromList(next, node) - else - ListNode(n,d,removeFromList(next, node)) - case ListEnd() => list - } - } ensuring(sndInvariant(_)) // something about this generates an error: is the precondition not checked for _all_ elements or something? - - /** Return true if list contains node */ - @induct - def listContains(list : SortedNDList, node : Int) : Boolean ={ - // something to do with this times out - require(sndInvariant(list)) - list match { - case ListNode(n,d,next) => - if (node == n) true - else listContains(next, node) - case ListEnd() => false - } - } - - /** Add a new node to the list, such that list remains sorted by distance. - * Assume node is not already in list. */ - @induct - def addSorted(list : SortedNDList, node : Int, dist : Int) : SortedNDList = { - // something to do with this times out - require(sndInvariant(list) && !listContains(list, node) && node >= 0 && dist >= 0) - - list match { - case ListNode(n,d,next) => - if (d > dist) // insert here - ListNode(node, dist, list) - else - ListNode(n,d, addSorted(next, node, dist)) - case ListEnd() => // insert at end - ListNode(node, dist, list) - } - } ensuring (sndInvariant(_)) // something to do with this times out - - /** Update node with distance minimum of dist and current value. Add if not - * in list, and maintain sorted order. */ - @induct - def updateDistInList(list : SortedNDList, node : Int, dist : Int) : SortedNDList = { - require(sndInvariant(list) && node >= 0 && dist >= 0) - - val listRemoved = removeFromList(list, node) - addSorted(listRemoved, node, dist) - } ensuring(sndInvariant(_)) - */ -} diff --git a/testcases/verification/graph/Subgraph.scala b/testcases/verification/graph/Subgraph.scala deleted file mode 100644 index 5e17811376e4b4f17a56dc53d22c5ca5fe7ca3ac..0000000000000000000000000000000000000000 --- a/testcases/verification/graph/Subgraph.scala +++ /dev/null @@ -1,266 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Subgraph { - /** Graph representation. - * - * A graph has vertices 0, 1, ..., nVertices-1. - * - * Vertices is a singly linked list with length nVertices, corresponding in - * order to the vertices 0, 1, ..., nVertices. - * - * Each vertex has a list of edges, representing edges from that vertex to - * the edge's toVertex field. This must not include the vertex itself. The - * representation is for directed graphs. - * - * Example: - * - * Graph(3, - * VertexItem( - * VertexItem( - * VertexItem(VertexEnd(), - * EdgeItem(EdgeItem(EdgeEnd(), 1), 0)), - * EdgeEnd()), - * EdgeItem(EdgeEnd(), 2)) - * ) - * - * represents a graph with vertices 0, 1 and 2 with edges (2,0), (2,1) and (0,2). - */ - case class Graph(nVertices : Int, vertices : Vertices) - sealed abstract class Vertices - case class VertexItem(next : Vertices, edges : Edges) extends Vertices - case class VertexEnd() extends Vertices - sealed abstract class Edges - case class EdgeItem(next : Edges, toVertex : Int, weight : Int) extends Edges - case class EdgeEnd() extends Edges - - /* - ----------------------------------------------------------------------------- - SUBGRAPH TESTS - ----------------------------------------------------------------------------- - */ - - /* - Empty graph is a subgraph of any other graph - Works. - */ - def emptyGraph(g : Graph) : Boolean = { - require(invariant(g)) - val empty = Graph(0, VertexEnd()) - isSubGraph(empty, g) - } holds - - /* - Graph with a single vertex is a subgraph of any other graph - Finds counter example (empty graph) quickly - */ - def singleGraphSubsetOfAnotherGraph(g : Graph) : Boolean = { - require(invariant(g)) - val single = Graph(1, VertexItem(VertexEnd(), EdgeEnd())) - isSubGraph(single, g) - } holds - - /* - // Leon times out - def subGraphIsReflexive(g : Graph) : Boolean = { - require(invariant(g) && g.nVertices <= 3) - isSubGraph(g,g) - } holds - */ - - /* - // Leon times out - def isSubGraphIsAntiSymmetric(g1 : Graph, g2 : Graph) : Boolean = { - require(invariant(g1) && invariant(g2)) // && g1.nVertices <= 3 && g2.nVertices <= 3) - !(isSubGraph(g1, g2) && isSubGraph(g2, g1)) || (g1 == g2) - } holds - */ - - /* - isSubGraphBogus does not check that g1 has equal or fewer - vertices than g2 (i.e. that the vertex set of g1 is a subset of - those of g2) - - Finds counter example often quickly, but needs sometimes more than 30s - */ - def subGraphIsAntiSymmetricBogus(g1 : Graph, g2 : Graph) : Boolean = { - require(invariant(g1) && invariant(g2)) - !(isSubGraphBogus(g1, g2) && isSubGraphBogus(g2, g1)) || (g1 == g2) - } holds - - /* - isSubGraphBogus2: The weights are ignored - - Leon times out. - */ - /* - def subGraphIsAntiSymmetricBogus2(g1 : Graph, g2 : Graph) : Boolean = { - require(invariant(g1) && invariant(g2)) // && g1.nVertices <= 3 && g2.nVertices <= 3) - !(isSubGraphBogus2(g1, g2) && isSubGraphBogus2(g2, g1)) || (g1 == g2) - } holds - */ - - /* - ----------------------------------------------------------------------------- - GRAPH FUNCTIONS - ----------------------------------------------------------------------------- - */ - - /* Helper function (for conditions). */ - def lenVertexList(vertices : Vertices) : Int = vertices match { - case VertexEnd() => 0 - case VertexItem(next, _) => 1+lenVertexList(next) - } - - /* * Return true if and only if the graph representation is valid. - * - * Checks: - * nVertices >= 0 - * length of vertex list is nVertices, - * there is no edge from a vertex to itself (no self-loops), - * there is not more than one edge from any vertex to any other, - * there are no edges to invalid vertices. - * */ - def invariant(g : Graph) : Boolean = { - - // Leon bug(?): cannot access g.nVertices from within this function: - def recEdges(edge : Edges, alreadyFound : Set[Int]) : Boolean = edge match { - case EdgeEnd() => true - case EdgeItem(next, toVertex, w) =>{ - 0 <= toVertex && toVertex < g.nVertices && - !alreadyFound.contains(toVertex) && - recEdges(next, alreadyFound++Set(toVertex)) - } - } - - def recVertices(i : Int, vertex : Vertices) : Boolean = vertex match { - case VertexEnd() => - i == g.nVertices // list should only be null if length is correct - case VertexItem(next,edges) => - if (i >= g.nVertices) - false - else - recEdges(edges, Set(i)) && recVertices(i+1, next) - } - - g.nVertices >= 0 && recVertices(0, g.vertices) - } - - - /* - * Returns the edges of a graph as a map - */ - def getEdges(g : Graph) : Map[(Int, Int), Int] = { - require(invariant(g)) - - def recEdges(from : Int, edge : Edges, acc : Map[(Int,Int), Int]) : Map[(Int, Int), Int] = edge match { - case EdgeEnd() => acc - case EdgeItem(next,toVertex,w) => - recEdges(from, next, acc.updated((from,toVertex), w)) - } - - def recVertices(i : Int, vertex : Vertices, acc : Map[(Int,Int), Int]) - : Map[(Int, Int), Int] = vertex match { - case VertexEnd() => acc - case VertexItem(next,edges) => { - val a = recEdges(i, edges, acc) - recVertices(i + 1, next, a) - } - } - - recVertices(0, g.vertices, Map.empty[(Int,Int), Int]) - } - - /* - * Tests if g1 is a subgraph of g2. - * We iterate over all edges in g1 and test if they also exist in g2 - */ - def isSubGraph(g1 : Graph, g2 : Graph) : Boolean = { - require(invariant(g1) && invariant(g2)) - - val edges2 = getEdges(g2) - - def recEdges(from : Int, edge : Edges, acc : Boolean) : Boolean = { - if(!acc) false //fail fast - else { - edge match { - case EdgeEnd() => acc - case EdgeItem(next,toVertex,w) => { - if(edges2.isDefinedAt(from, toVertex)) { - if(edges2(from, toVertex) != w) - false - else - acc - } - else false - } - } - } - } - - def recVertices(i : Int, vertex : Vertices, acc : Boolean) : Boolean = vertex match { - case VertexEnd () => acc - case VertexItem(next,edges) => { - val b = recEdges(i, edges, acc) - recVertices(i + 1, next, b) - } - } - - if(g1.nVertices > g2.nVertices) // Vertex set needs to be a subset - false - else - recVertices(0, g1.vertices, true) - } - - /* - Tests if g1 is a subgraph of g2. - Bogus version 1: number of vertices needs to be taken in account - */ - def isSubGraphBogus(g1 : Graph, g2 : Graph) : Boolean = { - require(invariant(g1) && invariant(g2)) - - val edges2 = getEdges(g2) - - def recEdges(from : Int, edge : Edges, acc : Boolean) : Boolean = edge match { - case EdgeEnd() => acc - case EdgeItem(next,toVertex,_) => acc && edges2.isDefinedAt(from, toVertex) - } - - def recVertices(i : Int, vertex : Vertices, acc : Boolean) : Boolean = vertex match { - case VertexEnd () => acc - case VertexItem(next,edges) => { - val b = recEdges(i, edges, acc) - recVertices(i + 1, next, b) - } - } - - recVertices(0, g1.vertices, true) - } - - /* - Bogus version 2: weights of edges also need to be considered - */ - def isSubGraphBogus2(g1 : Graph, g2 : Graph) : Boolean = { - require(invariant(g1) && invariant(g2)) - - val edges2 = getEdges(g2) - - def recEdges(from : Int, edge : Edges, acc : Boolean) : Boolean = edge match { - case EdgeEnd() => acc - case EdgeItem(next,toVertex,_) => acc && edges2.isDefinedAt(from, toVertex) - } - - def recVertices(i : Int, vertex : Vertices, acc : Boolean) : Boolean = vertex match { - case VertexEnd () => acc - case VertexItem(next,edges) => { - val b = recEdges(i, edges, acc) - recVertices(i + 1, next, b) - } - } - - if(g1.nVertices > g2.nVertices) // Vertex set needs to be a subset - false - else - recVertices(0, g1.vertices, true) - } -} diff --git a/testcases/verification/graph/SubgraphMap.scala b/testcases/verification/graph/SubgraphMap.scala deleted file mode 100644 index 3714d2eb7a2ab1ded4f2a01ed5aa72ef6c3f196c..0000000000000000000000000000000000000000 --- a/testcases/verification/graph/SubgraphMap.scala +++ /dev/null @@ -1,102 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object SubgraphSet { - case class Graph(nVertices : Int, edges : Map[(Int,Int), Int]) - - /* - ----------------------------------------------------------------------------- - SUBGRAPH TESTS - ----------------------------------------------------------------------------- - */ - - /* - Empty graph is a subgraph of any other graph - Works. - */ - def empty(g : Graph) : Boolean = { - require(invariant(g)) - val empty = Graph(0, Map.empty[(Int, Int), Int]) - isSubGraph(empty, g) - } holds - - /* - Graph with a single vertex is a subgraph of any other graph - Finds counter example (empty graph) quickly - */ - def singleGraphSubsetOfAnotherGraph(g : Graph) : Boolean = { - require(invariant(g)) - val single = Graph(1, Map.empty[(Int, Int), Int]) - isSubGraph(single, g) - } holds - - // Leon proves it quickly - def subGraphIsReflexive(g : Graph) : Boolean = { - require(invariant(g) && g.nVertices <=3) - isSubGraph(g,g) - } holds - - // Leon proves it within a few seconds (bounds!) - def isSubGraphIsAntiSymmetric(g1 : Graph, g2 : Graph) : Boolean = { - require(invariant(g1) && invariant(g2) && g1.nVertices <= 5 && g2.nVertices <= 5) - !(isSubGraph(g1, g2) && isSubGraph(g2, g1)) || isEqual(g1, g2) - } holds - - // Leon proves it within reasonable times (bounds!) - def equalsIsSymmetric(g1 : Graph, g2 : Graph) : Boolean = { - require(invariant(g1) && invariant(g2) && g1.nVertices <= 5 && g2.nVertices <= 5) - isEqual(g1,g2) == isEqual(g2, g1) - } holds - - - /* - ----------------------------------------------------------------------------- - GRAPH FUNCTIONS - ----------------------------------------------------------------------------- - */ - - // This rather weak invariant is good enough for our purposes here - def invariant(g : Graph) = g.nVertices >= 0 - - def isSubGraph(x : Graph, y : Graph) : Boolean = { - require(invariant(x) && invariant(y)) - - var ret : Boolean = (x.nVertices <= y.nVertices) - if (ret){ - var i = 0 - while(i<x.nVertices) { - var j = 0; - while(j < x.nVertices) { - ret &&= !x.edges.isDefinedAt((i,j)) || y.edges.isDefinedAt((i,j)) - - if(x.edges.isDefinedAt((i,j)) && y.edges.isDefinedAt((i,j))) - ret &&= (x.edges(i,j) == y.edges(i,j)) - - j += 1 - } - i += 1 - } - } - ret - } - - def isEqual(x : Graph, y : Graph) : Boolean = { - var ret = (x.nVertices == y.nVertices) - var i = 0 - while(i<x.nVertices && ret) { - var j = 0 - while(j < y.nVertices && ret) { - - ret &&= (!x.edges.isDefinedAt((i,j)) || - y.edges.isDefinedAt((i,j))) && (!y.edges.isDefinedAt((i,j)) || - x.edges.isDefinedAt((i,j))) - if(x.edges.isDefinedAt((i,j)) && y.edges.isDefinedAt((i,j))) - ret &&= (x.edges(i,j) == y.edges(i,j)) - j += 1 - - } - i += 1 - } - ret - } -} diff --git a/testcases/verification/graph/TreeEquivalence.scala b/testcases/verification/graph/TreeEquivalence.scala deleted file mode 100644 index a12c82ed337ef91ef839af1114fe0b81d15ace16..0000000000000000000000000000000000000000 --- a/testcases/verification/graph/TreeEquivalence.scala +++ /dev/null @@ -1,289 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object TreeEquivalence { - /** Graph representation. - * - * A graph has vertices 0, 1, ..., nVertices-1. - * - * Vertices is a singly linked list with length nVertices, corresponding in - * order to the vertices 0, 1, ..., nVertices. - * - * Each vertex has a list of edges, representing edges from that vertex to - * the edge's toVertex field. This must not include the vertex itself. The - * representation is for directed graphs. - * - * Example: - * - * Graph(3, - * VertexItem( - * VertexItem( - * VertexItem(VertexEnd(), - * EdgeItem(EdgeItem(EdgeEnd(), 1), 0)), - * EdgeEnd()), - * EdgeItem(EdgeEnd(), 2)) - * ) - * - * represents a graph with vertices 0, 1 and 2 with edges (2,0), (2,1) and (0,2). - */ - case class Graph(nVertices : Int, vertices : Vertices) - sealed abstract class Vertices - case class VertexItem(next : Vertices, edges : Edges) extends Vertices - case class VertexEnd() extends Vertices - sealed abstract class Edges - case class EdgeItem(next : Edges, toVertex : Int, weight : Int) extends Edges - case class EdgeEnd() extends Edges - - - /* - ----------------------------------------------------------------------------- - TREE EQUIVALENCE TESTS - ----------------------------------------------------------------------------- - */ - - - /* - Try to prove that a spanning tree has (g.nVertices - 1) edges - This is true for undirected graphs, but here we don't enforce the - condition. - - Finds a counter-example sometimes after quite some time. - */ - /* - def treeEquivalence(g:Graph) : Boolean = { - require(invariant(g) && isConnected(g) && g.nVertices > 0 && g.nVertices <=3) - (!isSpanningTree(g) || ((getNumberOfEdges(g) == g.nVertices - 1))) - } holds - */ - - - /* - Try to prove that every connected graph has (g.nVertices - 1) edges - - Finds counter example quickly (empty graph). No options - */ - def connectedGraph(g:Graph) : Boolean = { - require(invariant(g) && isConnected(g)) - (getNumberOfEdges(g) == g.nVertices - 1) - } holds - - - /* - * - Trying to prove that every connected, non-empty graph has - (g.nVertices - 1) edges - * - Since we left out some isUndirected condtion it finds a counter example - * sometimes (depends on the upper bound of - * g.nVertices, the larger the more time it needs to find a - * counter example) - */ - def nonEmptyConnectedGraph(g:Graph) : Boolean = { - require(invariant(g) && isConnected(g) && g.nVertices > 0 && - g.nVertices < 4) - (getNumberOfEdges(g) == g.nVertices - 1) - } holds - - - /* - ----------------------------------------------------------------------------- - GRAPH FUNCTIONS - ----------------------------------------------------------------------------- - */ - - /* Helper function (for conditions). */ - def lenVertexList(vertices : Vertices) : Int = vertices match { - case VertexEnd() => 0 - case VertexItem(next, _) => 1+lenVertexList(next) - } - - /* * Return true if and only if the graph representation is valid. - * - * Checks: - * nVertices >= 0 - * length of vertex list is nVertices, - * there is no edge from a vertex to itself (no self-loops), - * there is not more than one edge from any vertex to any other, - * there are no edges to invalid vertices. - * */ - def invariant(g : Graph) : Boolean = { - - def recEdges(edge : Edges, alreadyFound : Set[Int]) : Boolean = edge match { - case EdgeEnd() => true - case EdgeItem(next, toVertex, w) =>{ - 0 <= toVertex && toVertex < g.nVertices && - !alreadyFound.contains(toVertex) && - recEdges(next, alreadyFound++Set(toVertex)) - } - } - - def recVertices(i : Int, vertex : Vertices) : Boolean = vertex match { - case VertexEnd() => - i == g.nVertices // list should only be null if length is correct - case VertexItem(next,edges) => - if (i >= g.nVertices) - false - else - recEdges(edges, Set(i)) && recVertices(i+1, next) - } - - g.nVertices >= 0 && recVertices(0, g.vertices) - } - - - /* - * Returns the edges of a graph as a map - */ - def getEdges(g : Graph) : Map[(Int, Int), Int] = { - require(invariant(g)) - - def recEdges(from : Int, edge : Edges, acc : Map[(Int,Int), Int]) : Map[(Int, Int), Int] = edge match { - case EdgeEnd() => acc - case EdgeItem(next,toVertex,w) => - recEdges(from, next, acc.updated((from,toVertex), w)) - } - - def recVertices(i : Int, vertex : Vertices, acc : Map[(Int,Int), Int]) - : Map[(Int, Int), Int] = vertex match { - case VertexEnd() => acc - case VertexItem(next,edges) => { - val a = recEdges(i, edges, acc) - recVertices(i + 1, next, a) - } - } - - recVertices(0, g.vertices, Map.empty[(Int,Int), Int]) - } - - /* - Counts the number of edges in a graph - */ - def getNumberOfEdges(g : Graph) : Int = { - require(invariant(g)) - - def recEdges(from : Int, edge : Edges, acc : Int) : Int = edge - match { - case EdgeEnd() => acc - case EdgeItem(next,toVertex,_) => recEdges(from, next, acc + 1) - } - - def recVertices(i : Int, vertex : Vertices, acc : Int) - : Int = vertex match { - case VertexEnd () => acc - case VertexItem(next,edges) => { - val e = recEdges(i, edges, acc) - recVertices(i + 1, next, e) - } - } - - recVertices(0, g.vertices, 0) - } - - - /* - * Tests whether a given edge set forms a spanning tree using - union - find - */ - def isSpanningTree(g : Graph) : Boolean = { - require(invariant(g)) - isConnected(g) && isAcyclic(g) - } - - def isConnected(g : Graph) : Boolean = { - require(invariant(g)) - isConnected(getEdges(g), g.nVertices) - } - - def isConnected(edges : Map[(Int,Int), Int], nVertices : Int) : - Boolean = { - require(nVertices >= 0) - val uf = calculateUF(edges, nVertices)._1 - - val p = uFind(0, uf) - var i = 1 - - var ret = true - while(i < nVertices && ret) { - if(uFind(i, uf) != p) - ret = false // 0, i are not connected - i += 1 - } - - ret - } - - /* - * Tests, whether g is cycle-free - */ - def isAcyclic(g : Graph) : Boolean = { - require(invariant(g)) - !calculateUF(getEdges(g),g.nVertices)._2 - } - - /* - * Tests, whether the subgraph induced by edges is cycle-free. - * If directed==true, the edge set is interpreted as directed edges - * i.e. a->b and b->a are considered as two distinct edges. - */ - def isAcyclic(edges : Map[(Int,Int), Int], nVertices : Int) : Boolean = { - require(nVertices >= 0) - !calculateUF(edges, nVertices)._2 - } - - - /* - * Does union-find on edgeSet. - * Returns the union-find tree and a boolean set to true if a cycle was found - */ - def calculateUF(edgeSet : Map[(Int,Int), Int], nVertices : Int) : - (Map[Int, Int], Boolean)= { - require(nVertices >= 0) - - var i = 0 - var uf = Map.empty[Int, Int] - var cycle = false - var edges = edgeSet - while(i < nVertices) { - var j = 0 - while(j < nVertices) { - if(edges.isDefinedAt((i,j))) { - if(edges(i, j) != -1) { - val p1 = uFind(i, uf) - val p2 = uFind(j, uf) - if(p1 == p2) - cycle = true - else - uf = union(p1, p2, uf) - - //"remove" twin edge - edges = edges.updated((j,i), -1) - } - } - j += 1 - } - i += 1 - } - - (uf, cycle) - } - - - /* ************************************* - Union find - *************************************** */ - def uFind(e : Int, s : Map[Int, Int]) : Int = { - if(!s.isDefinedAt(e)) e - else if(s(e) == e) e - else uFind(s(e), s) - } - - def union(e1 : Int, e2 : Int, s : Map[Int,Int]) : Map[Int, Int] = { - // naive union - val p1 = uFind(e1,s) - val p2 = uFind(e2, s) - - if(p1 != p2) - //naive union - s.updated(p1, p2) //only union if theiy are really in different trees - else - s - } -} diff --git a/testcases/verification/graph/TreeEquivalenceMap.scala b/testcases/verification/graph/TreeEquivalenceMap.scala deleted file mode 100644 index 7c4a1103c0f3ef5a0974d2b034259ea4c39361fc..0000000000000000000000000000000000000000 --- a/testcases/verification/graph/TreeEquivalenceMap.scala +++ /dev/null @@ -1,206 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object TreeEquivalenceSet { - /* - ----------------------------------------------------------------------------- - TREE EQUIVALENCE TESTS ON SET REPRESENTATION - ----------------------------------------------------------------------------- - */ - - /* - Try to prove that a spanning tree has (g.nVertices - 1) edges - - Leon loops - */ - /* - def treeEquivalence(g:Graph) : Boolean = { - require(invariant(g) && isUndirected(g) && g.nVertices > 0 && g.nVertices <= 3) - (!isSpanningTree(g) || ((getNumberOfEdges(g) == g.nVertices - 1))) - } holds - */ - - /* - Try to prove that every connected graph has (g.nVertices - 1) edges - - Finds counter example with out of range edges (--noLuckyTests) - */ - def connectedGraph(g:Graph) : Boolean = { - require(invariant(g) && isConnected(g) && isUndirected(g)) - (getNumberOfEdges(g) == g.nVertices - 1) - } holds - - - /* - Trying to prove that every connected, non-empty graph has (g.nVertices - 1) edges - - Leon loops - */ - /* - def nonEmptyConnectedGraph(g:Graph) : Boolean = { - require(invariant(g) && isConnected(g) && isUndirected(g) && g.nVertices > 0 && - g.nVertices <= 3) - (getNumberOfEdges(g) == g.nVertices - 1) - } holds - */ - - /* - ----------------------------------------------------------------------------- - GRAPH FUNCTIONS - ----------------------------------------------------------------------------- - */ - - case class Graph(nVertices : Int, edges : Map[(Int,Int), Int]) - - def invariant(g : Graph) = { - def noSelfLoops(i : Int) : Boolean = { - if(i >= g.nVertices) true - else if(g.edges.isDefinedAt(i,i)) - false - else - noSelfLoops(i+1) - } - - g.nVertices >= 0 && noSelfLoops(0) - } - - /** - Tests, if g is undirected, that is if for every edge (i,j) there is - also and edge (j,i) - Ignoring weights for the moment - */ - - def isUndirected(g: Graph) : Boolean = { - require(invariant(g)) - - val edgeSet = g.edges - var res = true - var i = 0 - while(i < g.nVertices && res) { - var j = 0 - while(j < g.nVertices && res) { - res = !edgeSet.isDefinedAt(i,j) || edgeSet.isDefinedAt(j,i) - - //If weights should considered - if(res && edgeSet.isDefinedAt(i,j)) - res = edgeSet(i,j) == edgeSet(j,i) - - j += 1 - } - i += 1 - } - - res - } - - /* - Leon doesn't support size operators, so we need to count edges explicitely... - - Note that the upper bound on x can not be proven using this graph - representation since leon will then pick some out of range edges - */ - def getNumberOfEdges(g : Graph) : Int = { - require(invariant(g)) - - var i = 0 - var cnt = 0 - (while(i < g.nVertices) { - var j = 0 - (while(j < g.nVertices) { - if(g.edges.isDefinedAt(i,j)) - cnt += 1 - j += 1 - }) invariant(cnt >= 0) //&& cnt <= g.nVertices * g.nVertices) - i += 1 - }) invariant(cnt >= 0) //&& cnt <= g.nVertices * g.nVertices) - - cnt - } ensuring(x => x >= 0) //&& x <= g.nVertices * g.nVertices) - - def isSpanningTree(g : Graph) : Boolean = { - require(invariant(g) && isUndirected(g)) - isConnected(g) && isAcyclic(g.edges, g.nVertices) - } - - def isConnected(g : Graph) : Boolean = { - require(g.nVertices >= 0 && isUndirected(g)) - val uf = calculateUF(g.edges, g.nVertices)._1 - - val p = uFind(0, uf) - var i = 1 - - var ret = true - while(i < g.nVertices && ret) { - if(uFind(i, uf) != p) - ret = false // 0, i are not connected - i += 1 - } - - ret - } - - /* - * Tests, whether the subgraph induced by edges is cycle-free. - */ - def isAcyclic(edges : Map[(Int,Int), Int], nVertices : Int) : Boolean = { - require(nVertices >= 0 && isUndirected(Graph(nVertices, edges))) - !calculateUF(edges, nVertices)._2 - } - - /* - * Does union-find on edgeSet. - * Returns the union-find tree and a boolean set to true if a cycle was found - */ - def calculateUF(edgeSet : Map[(Int,Int), Int], nVertices : Int) : - (Map[Int, Int], Boolean)= { - require(nVertices >= 0) - - var i = 0 - var uf = Map.empty[Int, Int] - var cycle = false - var edges = edgeSet - while(i < nVertices) { - var j = 0 - while(j < nVertices) { - if(edges.isDefinedAt((i,j))) { - if(edges(i, j) != -1) { - val p1 = uFind(i, uf) - val p2 = uFind(j, uf) - if(p1 == p2) - cycle = true - else - uf = union(p1, p2, uf) - - //"remove" twin edge - edges = edges.updated((j,i), -1) - } - } - j += 1 - } - i += 1 - } - - (uf, cycle) - } - - /* ************************************* - Union find - *************************************** */ - def uFind(e : Int, s : Map[Int, Int]) : Int = { - if(!s.isDefinedAt(e)) e - else if(s(e) == e) e - else uFind(s(e), s) - } - - def union(e1 : Int, e2 : Int, s : Map[Int,Int]) : Map[Int, Int] = { - // naive union - val p1 = uFind(e1,s) - val p2 = uFind(e2, s) - - if(p1 != p2) - //naive union - s.updated(p1, p2) //only union if theiy are really in different trees - else - s - } -} diff --git a/testcases/verification/graph/dijkstras/DijkstrasSortedList.scala b/testcases/verification/graph/dijkstras/DijkstrasSortedList.scala deleted file mode 100644 index b79751c692cf8ebcd7c2f24a85804dc210568a50..0000000000000000000000000000000000000000 --- a/testcases/verification/graph/dijkstras/DijkstrasSortedList.scala +++ /dev/null @@ -1,235 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -/** Implementation of Dijkstra's algorithm. - * - * Complexity is a bit beyond what Leon can handle. See individual tests on - * SortedNDList. - */ -object DijkstrasSortedList { - /*************************************************************************** - * Graph representation and algorithms - **************************************************************************/ - case class Graph(nVertices : Int, edges : Map[(Int,Int), Int]) - - // Disallow self edges? Not actually important since they can be ignored. - def invariant(g : Graph) = g.nVertices >= 0 - - // true if x & y have same number of nodes and y has all x's edges - def isSubGraph(x : Graph, y : Graph) : Boolean = { - require(invariant(x) && invariant(y)) - - var ret : Boolean = (x.nVertices == y.nVertices) - if (ret){ - var i = 0 - while(i<x.nVertices) { - var j = 0; - while(j < x.nVertices) { - if (i != j) - ret &&= !x.edges.isDefinedAt((i,j)) || y.edges.isDefinedAt((i,j)) - j += 1 - } - i += 1 - } - } - ret - } - - // true if every edge has a weight of at least 0 - def nonnegativeWeights(g : Graph) : Boolean = { - require(invariant(g)) - - var ret : Boolean = true - var i = 0 - while(i<g.nVertices) { - var j = 0; - while(j < g.nVertices) { - ret = if (i != j && g.edges.isDefinedAt((i,j))){ - if (g.edges((i,j)) >= 0) ret - else false - } else ret - j += 1 - } - i += 1 - } - ret - } - - // true if b is reachable from a - def isReachable(g : Graph, a : Int, b : Int) : Boolean = { - require(invariant(g) && a >= 0 && a < g.nVertices && b >= 0 && b < g.nVertices) - - //TODO - false - } - - - /*************************************************************************** - * Sorted list representation and algorithims - **************************************************************************/ - - /** A list containing node, dist pairs. - * - * Sorted by distance, nearest first. Distance must be non-negative. Node - * values must be unique and non-negative. - */ - abstract class SortedNDList - case class ListNode(node : Int, dist : Int, next : SortedNDList) extends SortedNDList - case class ListEnd() extends SortedNDList - - /** List invariant (see description above) */ - @induct - def sndInvariant(list : SortedNDList) : Boolean = { - // Most conditions are commented out. Leon cannot even check adding or - // removing an element satisfies the invariant in this case! - def invRec(list : SortedNDList/*, elts : Set[Int], minDist : Int, len : Int*/) : Boolean = - list match { - case ListNode(n,d,next) => - if (d >= 0/*minDist*/ && n >= 0 /*&& !elts.contains(n)*/) - invRec(next/*,elts++Set(n),d, len + 1*/) - else - false - case ListEnd() => true //len <= 3 - } - - invRec(list/*, Set.empty, 0, 0*/) - } - - /** Look for node in list and remove, if it exists. */ - @induct - def removeFromList(list : SortedNDList, node : Int) : SortedNDList ={ - // something about this times out - require(sndInvariant(list)) - - //println("removeFromList: "+list) - - list match { - case ListNode(n,d,next) => - if (n == node) - // drop current node and continue search: - removeFromList(next, node) - else - ListNode(n,d,removeFromList(next, node)) - case ListEnd() => list - } - } ensuring(sndInvariant(_)) // something about this generates an error: is the precondition not checked for _all_ elements or something? - - /** Return true if list contains node */ - @induct - def listContains(list : SortedNDList, node : Int) : Boolean ={ - // something to do with this times out - require(sndInvariant(list)) - list match { - case ListNode(n,d,next) => - if (node == n) true - else listContains(next, node) - case ListEnd() => false - } - } - - /** Add a new node to the list, such that list remains sorted by distance. - * Assume node is not already in list. */ - @induct - def addSorted(list : SortedNDList, node : Int, dist : Int) : SortedNDList = { - // something to do with this times out - require(sndInvariant(list) && !listContains(list, node) && node >= 0 && dist >= 0) - - list match { - case ListNode(n,d,next) => - if (d > dist) // insert here - ListNode(node, dist, list) - else - ListNode(n,d, addSorted(next, node, dist)) - case ListEnd() => // insert at end - ListNode(node, dist, list) - } - } ensuring (sndInvariant(_)) // something to do with this times out - - /** Update node with distance minimum of dist and current value. Add if not - * in list, and maintain sorted order. */ - @induct - def updateDistInList(list : SortedNDList, node : Int, dist : Int) : SortedNDList = { - require(sndInvariant(list) && node >= 0 && dist >= 0) - - val listRemoved = removeFromList(list, node) - addSorted(listRemoved, node, dist) - } ensuring(sndInvariant(_)) - - - /*************************************************************************** - * Dijkstra's algorithm - **************************************************************************/ - - def isNodeNotB(list : SortedNDList, b : Int) : Boolean = - list match { - case ListNode(n, _, _) => n!=b - case ListEnd() => false - } - - // common precondition: g is a valid graph and a and b are valid nodes - def bounds(g : Graph, a : Int, b : Int) : Boolean = - invariant(g) && 0 <= a && a < g.nVertices && 0 <= b && b < g.nVertices - - // find the shortest path from a to b in g, and return its distance - // return -1 if the two aren't connected - def shortestPath(g : Graph, a : Int, b : Int) : Int = { - require(bounds(g,a,b) && nonnegativeWeights(g)) - - // We should always have at least some node if we haven't reached b (so - // long as b is in the graph and connected to a). - @induct - def spVisit (list : SortedNDList, visited : Set[Int]) : SortedNDList = { - require(bounds(g,a,b) && (!visited.contains(b) || listContains(list,b)) && sndInvariant(list)) - /* TODO: also check that all list nodes are less than g.nVertices. - * We should check same invariant at function exit. But there's no point: - * it's too much for Leon to reason about at once! - */ - - list match { - case ListNode(node, dist, next) if (node==b) => - list - case ListNode(node, dist, next) => - var n = 0 - var tail : SortedNDList = next - - (while (n < g.nVertices){ - if (n != node && !visited.contains(n) && g.edges.isDefinedAt((node,n))) - tail = updateDistInList(tail, n, dist+g.edges((node,n))) - n = n + 1 - }) invariant(sndInvariant(list) && n >= 0 && n <= g.nVertices) - - spVisit (tail, visited ++ Set(node)) - case ListEnd() => - list - } - } ensuring(res => res match { - case ListEnd() => !isReachable(g,a,b) - case ListNode(node,_,_) => node==b - }) - - // We start from a, which has distance 0. All other nodes implicitly have - // infinite distance. - val startingList : SortedNDList = ListNode(a, 0, ListEnd()) - spVisit(startingList, Set.empty) match { - case ListNode(n, d, _) => - //assert(n==b) - if (n != b) - -2 // Leon should prove this doesn't happen — what a way to do assert(false) - else - d - case ListEnd() => - -1 - } - } ensuring (res => res >= -1 /*(if (isReachable(g,a,b)) res>=0 else res== -1)*/) - - @ignore - def main(args: Array[String]) { - val spanningTreeE = Map((0,1) -> 1, (0,2) -> 2, (2,3) -> 5, (0,3) -> 10, (3,2) -> 0) - val spanningTree = Graph(4, spanningTreeE) - val singleGraph = Graph(1, Map.empty) - - println(spanningTree) - println("from 0 to 3 (should be 7): "+shortestPath(spanningTree,0,3)) - println("from 3 to 1 (no path): "+shortestPath(spanningTree,3,1)) - } -} diff --git a/testcases/verification/higher-order/invalid/Continuations1.scala b/testcases/verification/higher-order/invalid/Continuations1.scala deleted file mode 100644 index 0d65fc817fc2680b0127c89eb7bbd40da80ba384..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/Continuations1.scala +++ /dev/null @@ -1,28 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object Continuations1 { - def add_cps[T](x: BigInt, y: BigInt)(f: BigInt => T): T = { - f(x + y) - } - - def square_cps[T](x: BigInt)(f: BigInt => T): T = { - f(x * x) - } - - def pythagoras_cps[T](a: BigInt, b: BigInt)(f: BigInt => T): T = { - val a2 = square_cps(a)(x => x) - val b2 = square_cps(b)(x => x) - add_cps(a2, b2)(f) - } - - def lemma1(a: BigInt, b: BigInt): Boolean = { - require(a > 0 && b > 0) - pythagoras_cps(a, b)(_ == a*a + b*b) - }.holds - - def lemma2(a: BigInt, b: BigInt, c: BigInt): Boolean = { - require(a > 0 && b > 0 && c > 0) - pythagoras_cps(a, b)(_ == c*c) - }.holds -} diff --git a/testcases/verification/higher-order/invalid/HOInvocations.scala b/testcases/verification/higher-order/invalid/HOInvocations.scala deleted file mode 100644 index bf1f40a4373e6869d2813904b2798ef3224e16c6..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/HOInvocations.scala +++ /dev/null @@ -1,17 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object HOInvocations { - def switch(x: Int, f: (Int) => Int, g: (Int) => Int) = if(x > 0) f else g - - def failling_1(f: (Int) => Int) = { - switch(-10, (x: Int) => x + 1, f)(2) - } ensuring { res => res > 0 } - - def failling_2(x: Int, f: (Int) => Int, g: (Int) => Int) = { - require(x > 0) - switch(1, switch(x, f, g), g)(1) - } ensuring { res => res != f(1) } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/invalid/Lists1.scala b/testcases/verification/higher-order/invalid/Lists1.scala deleted file mode 100644 index 7fc938a51918461f68e6e4ef1ec611c216731802..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/Lists1.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object Lists1 { - abstract class List[T] - case class Cons[T](head: T, tail: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - def forall[T](list: List[T], f: T => Boolean): Boolean = list match { - case Cons(head, tail) => f(head) && forall(tail, f) - case Nil() => true - } - - def positive(list: List[Int]): Boolean = list match { - case Cons(head, tail) => if (head < 0) false else positive(tail) - case Nil() => true - } - - def gt(i: Int): Int => Boolean = x => x > i - - def positive_lemma(list: List[Int]): Boolean = { - positive(list) == forall(list, gt(0)) - }.holds -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/invalid/Lists2.scala b/testcases/verification/higher-order/invalid/Lists2.scala deleted file mode 100644 index 29285c8a91ccf3f163595fb38028b72b172fd59d..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/Lists2.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.lang._ -import leon.collection._ - - -object Lists2 { - - /** - * SORTING - **/ - - def isSorted[A](l: List[A])(implicit ord: (A, A) => Boolean): Boolean = l match { - case Cons(h1, Cons(h2, _)) if !ord(h1, h2) => false - case Cons(h, t) => isSorted(t) - case Nil() => true - } - - def sort[A](l: List[A])(implicit ord: (A, A) => Boolean): List[A] = { - val (res, sres) = bubble(l) - res - /* - if (sres) { - sort(res) - } else { - res - } - */ - } ensuring { - isSorted(_) - } - - def bubble[A](l: List[A])(implicit ord: (A, A) => Boolean): (List[A], Boolean) = { - l match { - case Cons(h1, t1 @ Cons(h2, t2)) if !ord(h1, h2) => (Cons(h2, Cons(h1, t2)), true) - case Cons(h1, t1) => - val (tres, sres) = bubble(t1) - (Cons(h1, tres), sres) - case Nil() => - (Nil[A](), false) - } - } ensuring { _ match { - /*res => - res match {*/ - case (lr, sr) => if (!sr) isSorted(lr) else true - //} - } - } - -} - diff --git a/testcases/verification/higher-order/invalid/Map.scala b/testcases/verification/higher-order/invalid/Map.scala deleted file mode 100644 index 3179604eab1f68fe160fc0bdd960b3e97f1b353d..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/Map.scala +++ /dev/null @@ -1,20 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object Map { - - def failure1[T](l: List[T], f: T => T): Boolean = { - l.map(f) == l.map(f).map(f) - }.holds - - def failure2[T](l: List[T], f: T => T): Boolean = { - l.map(f) == (l match { - case Cons(head, tail) => Cons(head, tail.map(f)) - case Nil() => Nil[T]() - }) - }.holds - - def failure3[T](l: List[T], f: T => List[T]): Boolean = { - l == l.flatMap(f) - }.holds -} diff --git a/testcases/verification/higher-order/invalid/ParBalance.scala b/testcases/verification/higher-order/invalid/ParBalance.scala deleted file mode 100644 index 62eca559db1e139d719e5b4215b0867ea91e9c35..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/ParBalance.scala +++ /dev/null @@ -1,133 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object ParBalance { - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - sealed abstract class Option - case class Some(x: BigInt) extends Option - case class None() extends Option - - val openPar : BigInt = BigInt(1) - val closePar : BigInt = BigInt(2) - - def balanced(list: List, counter: BigInt): Boolean = { - if (counter < 0) false else list match { - case Cons(head, tail) => - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced(tail, c) - case Nil() => counter == 0 - } - } - - def balanced_nonEarly(list: List, counter: BigInt): Boolean = { - list match { - case Cons(head, tail) => - if (counter < 0) balanced_nonEarly(tail, counter) else { - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced_nonEarly(tail, c) - } - case Nil() => counter == 0 - } - } ensuring { res => res == balanced(list, counter) } - - def balanced_withFailure(list: List, counter: BigInt, failed: Boolean): Boolean = { - require(counter >= 0 || failed) - list match { - case Cons(head, tail) => - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced_withFailure(tail, c, failed || c < 0) - case Nil() => !failed && counter == 0 - } - } ensuring { res => - if (failed) { - res == balanced_nonEarly(list, -1) - } else { - res == balanced_nonEarly(list, counter) - } - } - - def balanced_withReduce(list: List, p: (BigInt, BigInt)): Boolean = { - require(p._1 >= 0 && p._2 >= 0) - list match { - case Cons(head, tail) => - val p2 = reduce(p, parPair(head)) - balanced_withReduce(tail, p2) - case Nil() => - p._1 == 0 && p._2 == 0 - } - } ensuring { res => res == balanced_withFailure(list, p._1 - p._2, p._2 > 0) } - - def balanced_foldLeft_equivalence(list: List, p: (BigInt, BigInt)): Boolean = { - require(p._1 >= 0 && p._2 >= 0) - val f = (s: (BigInt, BigInt), x: BigInt) => reduce(s, parPair(x)) - (foldLeft(list, p, f) == (BigInt(0), BigInt(0))) == balanced_withReduce(list, p) && (list match { - case Cons(head, tail) => - val p2 = f(p, head) - balanced_foldLeft_equivalence(tail, p2) - case Nil() => true - }) - }.holds - - def foldRight[A](list: List, state: A, f: (BigInt, A) => A): A = list match { - case Cons(head, tail) => - val tailState = foldRight(tail, state, f) - f(head, tailState) - case Nil() => state - } - - def foldLeft[A](list: List, state: A, f: (A, BigInt) => A): A = list match { - case Cons(head, tail) => - val nextState = f(state, head) - foldLeft(tail, nextState, f) - case Nil() => state - } - - def reduce(p1: (BigInt, BigInt), p2: (BigInt, BigInt)): (BigInt, BigInt) = { - if (p1._1 >= p2._2) { - (p1._1 - p2._2 + p2._1, p1._2) - } else { - (p2._1, p2._2 - p1._1 + p1._2) - } - } - - def reduce_associative(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(p1, reduce(p2, p3)) == reduce(reduce(p1, p2), p3) - }.holds - - def swap(p: (BigInt, BigInt)): (BigInt, BigInt) = (p._2, p._1) - - def reduce_inverse(p1: (BigInt, BigInt), p2: (BigInt, BigInt)): Boolean = { - reduce(p1, p2) == swap(reduce(swap(p2), swap(p1))) - }.holds - - def reduce_associative_inverse(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(p1, reduce(p2, p3)) == swap(reduce(reduce(swap(p3), swap(p2)), swap(p1))) - }.holds - - def reduce_associative_inverse2(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(reduce(p1, p2), p3) == swap(reduce(swap(p3), reduce(swap(p2), swap(p1)))) - }.holds - - def parPair(x: BigInt): (BigInt, BigInt) = { - if (x == openPar) (1, 0) else if (x == closePar) (0, 1) else (0, 0) - } - - def fold_equivalence(list: List): Boolean = { - val s = (BigInt(0), BigInt(0)) - val fl = (s: (BigInt, BigInt), x: BigInt) => reduce(s, parPair(x)) - val fr = (x: BigInt, s: (BigInt, BigInt)) => reduce(swap(parPair(x)), s) - - foldLeft(list, s, fl) == swap(foldRight(list, swap(s), fr)) - }.holds - -} diff --git a/testcases/verification/higher-order/invalid/PositiveMap.scala b/testcases/verification/higher-order/invalid/PositiveMap.scala deleted file mode 100644 index 7fb002360005248db3f752eec9d77214b7e0a316..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/PositiveMap.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object PositiveMap { - - abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def positive(list: List): Boolean = list match { - case Cons(head, tail) => if (head < 0) false else positive(tail) - case Nil() => true - } - - def positiveMap_failling_1(f: (Int) => Int, list: List): List = { - list match { - case Cons(head, tail) => - val fh = f(head) - val nh = if (fh < -1) 0 else fh - Cons(nh, positiveMap_failling_1(f, tail)) - case Nil() => Nil() - } - } ensuring { res => positive(res) } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/invalid/Sets1.scala b/testcases/verification/higher-order/invalid/Sets1.scala deleted file mode 100644 index 62d1409b0eea5f895f35808a57ec21d7600edf5d..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/Sets1.scala +++ /dev/null @@ -1,17 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object Sets1 { - def set(i: Int): Int => Boolean = x => x == i - - def complement(s: Int => Boolean): Int => Boolean = x => !s(x) - - def union(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) || s2(x) - - def intersection(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) && s2(x) - - def failing(s1: Int => Boolean, s2: Int => Boolean): Boolean = { - complement(intersection(union(s1, s2), s1)) == s2 - }.holds - -} diff --git a/testcases/verification/higher-order/invalid/Transformation.scala b/testcases/verification/higher-order/invalid/Transformation.scala deleted file mode 100644 index 9c9bf86bcb2e2965522bb81463d7b124d7fadea3..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/invalid/Transformation.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object Transformation { - - abstract class Expr - case class If(cond: Expr, t: Expr, e: Expr) extends Expr - case class Add(e1: Expr, e2: Expr) extends Expr - case class Equals(e1: Expr, e2: Expr) extends Expr - case class Literal(i: BigInt) extends Expr - - def transform(f: Expr => Option[Expr])(expr: Expr): Expr = { - val rec = (x: Expr) => transform(f)(x) - val newExpr = expr match { - case If(cond, t, e) => If(rec(cond), rec(t), rec(e)) - case Add(e1, e2) => Add(rec(e1), rec(e2)) - case Equals(e1, e2) => Equals(rec(e1), rec(e2)) - case Literal(i) => Literal(i) - } - - f(newExpr) match { - case Some(e) => e - case None() => newExpr - } - } - - def exists(f: Expr => Boolean)(expr: Expr): Boolean = { - val rec = (x: Expr) => exists(f)(x) - f(expr) || (expr match { - case If(cond, t, e) => rec(cond) || rec(t) || rec(e) - case Add(e1, e2) => rec(e1) || rec(e2) - case Equals(e1, e2) => rec(e1) || rec(e2) - case Literal(i) => false - }) - } - - def test(expr: Expr) = { - val t = transform(e => e match { - case Equals(Add(Literal(i), Literal(j)), e2) => Some(Equals(Literal(i + j), e2)) - case Equals(e1, Add(Literal(i), Literal(j))) => Some(Equals(e1, Literal(i + j))) - case _ => None[Expr]() - })(expr) - - !exists(e => e match { - case Equals(_, Add(Literal(i), Literal(j))) => true - case _ => false - })(t) - }.holds -} diff --git a/testcases/verification/higher-order/valid/Anonymous.scala b/testcases/verification/higher-order/valid/Anonymous.scala deleted file mode 100644 index d69b1f8423c3ae681527e2a49fb75d6c54672b4f..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Anonymous.scala +++ /dev/null @@ -1,9 +0,0 @@ -import leon.lang._ - -object Anonymous { - def test(x: BigInt) = { - require(x > 0) - val i = (a: BigInt) => a + 1 - i(x) + i(2) - } ensuring { res => res > 0 } -} diff --git a/testcases/verification/higher-order/valid/Closures.scala b/testcases/verification/higher-order/valid/Closures.scala deleted file mode 100644 index 5e191cf814e4c66b2df0a3fa16fe19d78a1c343d..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Closures.scala +++ /dev/null @@ -1,15 +0,0 @@ -import leon.lang._ - -object Closures { - def addX(x: Int): Int => Int = { - (a: Int) => a + x - } - - def test(x: Int): Boolean = { - val add1 = addX(1) - val add2 = addX(2) - add1(add2(1)) == 4 - }.holds -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/Closures2.scala b/testcases/verification/higher-order/valid/Closures2.scala deleted file mode 100644 index b791965d1e06edd872d747a68fe084efed52a206..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Closures2.scala +++ /dev/null @@ -1,35 +0,0 @@ -import leon.lang._ - -object Closures2 { - def set(i: Int): Int => Boolean = x => x == i - - def union(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) || s2(x) - - def intersection(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) && s2(x) - - def diff(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) && !s2(x) - - def set123(): Int => Boolean = union(set(1), union(set(2), set(3))) - - def test1(): Boolean = { - val s1 = set123() - val s2 = union(s1, set(4)) - s2(1) && s2(2) && s2(3) && s2(4) - }.holds - - def test2(): Boolean = { - val s1 = set123() - val s2 = intersection(s1, union(set(1), set(3))) - val s3 = diff(s1, s2) - s3(2) && !s3(1) && !s3(3) - }.holds - - def test3(): Boolean = { - val s1 = set123() - val s2 = set123() - val s3 = union(s1, s2) - s3(1) && s3(2) && s3(3) - }.holds -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/FlatMap.scala b/testcases/verification/higher-order/valid/FlatMap.scala deleted file mode 100644 index 06d356c5fe5b1e7443831e7d541450c36449ef18..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/FlatMap.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.proof._ -import leon.collection._ - -object FlatMap { - - def append[T](l1: List[T], l2: List[T]): List[T] = l1 match { - case Cons(head, tail) => Cons(head, append(tail, l2)) - case Nil() => l2 - } - - def associative_append_lemma[T](l1: List[T], l2: List[T], l3: List[T]): Boolean = { - append(append(l1, l2), l3) == append(l1, append(l2, l3)) - } - - def associative_append_lemma_induct[T](l1: List[T], l2: List[T], l3: List[T]): Boolean = { - associative_append_lemma(l1, l2, l3) because (l1 match { - case Nil() => true - case Cons(head, tail) => associative_append_lemma_induct(tail, l2, l3) - }) - }.holds - - def flatMap[T,U](list: List[T], f: T => List[U]): List[U] = list match { - case Cons(head, tail) => append(f(head), flatMap(tail, f)) - case Nil() => Nil() - } - - def associative_lemma[T,U,V](list: List[T], f: T => List[U], g: U => List[V]): Boolean = { - flatMap(flatMap(list, f), g) == flatMap(list, (x: T) => flatMap(f(x), g)) - } - - def associative_lemma_induct[T,U,V](list: List[T], flist: List[U], glist: List[V], f: T => List[U], g: U => List[V]): Boolean = { - associative_lemma(list, f, g) because { - append(glist, flatMap(append(flist, flatMap(list, f)), g)) == append(append(glist, flatMap(flist, g)), flatMap(list, (x: T) => flatMap(f(x), g))) because - (glist match { - case Cons(ghead, gtail) => - associative_lemma_induct(list, flist, gtail, f, g) - case Nil() => flist match { - case Cons(fhead, ftail) => - associative_lemma_induct(list, ftail, g(fhead), f, g) - case Nil() => list match { - case Cons(head, tail) => associative_lemma_induct(tail, f(head), Nil(), f, g) - case Nil() => true - } - } - }) - } - }.holds - -} diff --git a/testcases/verification/higher-order/valid/FoldAssociative.scala b/testcases/verification/higher-order/valid/FoldAssociative.scala deleted file mode 100644 index 261d15c0fcd6419f5a2d024d2155257726ba8394..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/FoldAssociative.scala +++ /dev/null @@ -1,101 +0,0 @@ -import leon._ -import leon.lang._ - -object FoldAssociative { - - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - sealed abstract class Option - case class Some(x: Int) extends Option - case class None() extends Option - - def foldRight[A](list: List, state: A, f: (Int, A) => A): A = list match { - case Cons(head, tail) => - val tailState = foldRight(tail, state, f) - f(head, tailState) - case Nil() => state - } - - def take(list: List, count: Int): List = { - require(count >= 0) - list match { - case Cons(head, tail) if count > 0 => Cons(head, take(tail, count - 1)) - case _ => Nil() - } - } - - def drop(list: List, count: Int): List = { - require(count >= 0) - list match { - case Cons(head, tail) if count > 0 => drop(tail, count - 1) - case _ => list - } - } - - def append(l1: List, l2: List): List = { - l1 match { - case Cons(head, tail) => Cons(head, append(tail, l2)) - case Nil() => l2 - } - } - - def lemma_split(list: List, x: Int): Boolean = { - require(x >= 0) - val f = (x: Int, s: Int) => x + s - val l1 = take(list, x) - val l2 = drop(list, x) - foldRight(list, 0, f) == foldRight(l1, foldRight(l2, 0, f), f) - } - - def lemma_split_induct(list: List, x: Int): Boolean = { - require(x >= 0) - val f = (x: Int, s: Int) => x + s - val l1 = take(list, x) - val l2 = drop(list, x) - lemma_split(list, x) && (list match { - case Cons(head, tail) if x > 0 => - lemma_split_induct(tail, x - 1) - case _ => true - }) - }.holds - - def lemma_reassociative(list: List, x: Int): Boolean = { - require(x >= 0) - val f = (x: Int, s: Int) => x + s - val l1 = take(list, x) - val l2 = drop(list, x) - - foldRight(list, 0, f) == foldRight(l1, 0, f) + foldRight(l2, 0, f) - } - - def lemma_reassociative_induct(list: List, x: Int): Boolean = { - require(x >= 0) - val f = (x: Int, s: Int) => x + s - val l1 = take(list, x) - val l2 = drop(list, x) - lemma_reassociative(list, x) && (list match { - case Cons(head, tail) if x > 0 => - lemma_reassociative_induct(tail, x - 1) - case _ => true - }) - }.holds - - def lemma_reassociative_presplit(l1: List, l2: List): Boolean = { - val f = (x: Int, s: Int) => x + s - val list = append(l1, l2) - foldRight(list, 0, f) == foldRight(l1, 0, f) + foldRight(l2, 0, f) - } - - def lemma_reassociative_presplit_induct(l1: List, l2: List): Boolean = { - val f = (x: Int, s: Int) => x + s - val list = append(l1, l2) - lemma_reassociative_presplit(l1, l2) && (l1 match { - case Cons(head, tail) => - lemma_reassociative_presplit_induct(tail, l2) - case Nil() => true - }) - }.holds - -} diff --git a/testcases/verification/higher-order/valid/HOInvocations.scala b/testcases/verification/higher-order/valid/HOInvocations.scala deleted file mode 100644 index 0f2fbda2ff6e892e200b475f06d8e1876bd6ed64..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/HOInvocations.scala +++ /dev/null @@ -1,17 +0,0 @@ -import leon.lang._ - -object HOInvocations { - def switch(x: Int, f: (Int) => Int, g: (Int) => Int) = if(x > 0) f else g - - def passing_1(f: (Int) => Int) = { - switch(10, (x: Int) => x + 1, f)(2) - } ensuring { res => res > 0 } - - def passing_2(x: Int, f: (Int) => Int, g: (Int) => Int) = { - require(x > 0) - switch(1, switch(x, f, g), g)(1) - } ensuring { res => res == f(1) } - -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/Lambdas.scala b/testcases/verification/higher-order/valid/Lambdas.scala deleted file mode 100644 index 36ae0c7ad7f8a68e36358d9e5adb885e7bb108da..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Lambdas.scala +++ /dev/null @@ -1,15 +0,0 @@ -import leon.lang._ - -object Lambdas { - def gen(x: Int): (Int) => Int = { - val f = (x: Int) => x + 1 - val g = (x: Int) => x + 2 - if (x > 0) g else f - } - - def test(x: Int): Boolean = { - require(x > 0) - val f = gen(x) - f(x) == x + 2 - }.holds -} diff --git a/testcases/verification/higher-order/valid/ListOps1.scala b/testcases/verification/higher-order/valid/ListOps1.scala deleted file mode 100644 index 8d02e9bea274559aa4cf27bfd738a821f1068e9d..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/ListOps1.scala +++ /dev/null @@ -1,111 +0,0 @@ -import leon._ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - - -object ListOps1 { - - /** - * * Simple List operations - * **/ - - def partition[A](f: A => Boolean, l: List[A]): (List[A], List[A]) = { - l match { - case Cons(h, t) => - val (h1, h2) = if (f(h)) (Cons(h, Nil()), Nil[A]()) - else (Nil[A](), Cons(h, Nil())) - val (t1, t2) = partition(f, t) - (h1 ++ t1, h2 ++ t2) - case Nil() => (Nil[A](), Nil[A]()) - } - } ensuring { x: (List[A], List[A]) => x match { - case (a, b) => a.forall(f) && - b.forall(x => !f(x)) && - a.size + b.size == l.size && - a.content ++ b.content == l.content - }} - - def collect[A, B](f: A => Option[B], l: List[A]): List[B] = { - l match { - case Cons(h, t) => - f(h) match { - case Some(b) => Cons(b, collect(f, t)) - case None() => collect(f, t) - } - case Nil() => Nil[B]() - } - } ensuring { - res => res.size <= l.size - } - - def collectFirst[A, B](f: A => Option[B], l: List[A]): Option[B] = { - l match { - case Cons(h, t) => - f(h).orElse(collectFirst(f, t)) - case Nil() => None[B]() - } - } ensuring { - res => !l.isEmpty || res.isEmpty - } - - - def count[A](f: A => Boolean, l: List[A]): Int = { - l match { - case Cons(h, t) => - (if (f(h)) 1 else 0) + count(f, t) - case Nil() => 0 - } - } ensuring { - res => !(res > 0) || !l.isEmpty - } - - def dropWhile[A](f: A => Boolean, l: List[A]): List[A] = { - l match { - case Cons(h, t) if f(h) => dropWhile(f, t) - case Cons(h, t) if !f(h) => l - case Nil() => Nil[A]() - } - } ensuring { - res => - if(res.size < l.size) { - f(l.head) - } else { - l.isEmpty || !f(l.head) - } - } - - def forall[A](f: A => Boolean, l: List[A]): Boolean = { - l match { - case Cons(h, t) if f(h) => forall(f, t) - case Cons(_, t) => false - case Nil() => true - } - } ensuring { - res => res == !exists[A]({ x => !f(x) }, l) - } - - def exists[A](f: A => Boolean, l: List[A]): Boolean = { - l match { - case Cons(h, t) if f(h) => true - case Cons(_, t) => exists(f, t) - case Nil() => false - } - } ensuring { - res => res == res - } - - - /** - * * Map with universal quantifier in post as a witness argument - * **/ - - def mapWitness[A,B](f: A => B, l: List[A], w: A): List[B] = { - l match { - case Cons(h, t) => f(h) :: mapWitness(f, t, w) - case Nil() => Nil[B]() - } - } ensuring { - res => if (l.content contains w) res.content contains f(w) else true - } -} diff --git a/testcases/verification/higher-order/valid/Lists1.scala b/testcases/verification/higher-order/valid/Lists1.scala deleted file mode 100644 index 719c3d236009c96aa62986725df47ea20e3a906a..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Lists1.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -object Lists1 { - - def exists[T](list: List[T], f: T => Boolean): Boolean = list match { - case Cons(head, tail) => f(head) || exists(tail, f) - case Nil() => false - } - - def forall[T](list: List[T], f: T => Boolean): Boolean = list match { - case Cons(head, tail) => f(head) && forall(tail, f) - case Nil() => true - } - - def exists_lemma[T](list: List[T], f: T => Boolean): Boolean = { - exists(list, f) == !forall(list, (x: T) => !f(x)) - } - - def exists_lemma_induct[T](list: List[T], f: T => Boolean): Boolean = { - list match { - case Nil() => exists_lemma(list, f) - case Cons(head, tail) => exists_lemma(list, f) && exists_lemma_induct(tail, f) - } - }.holds - -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/Lists2.scala b/testcases/verification/higher-order/valid/Lists2.scala deleted file mode 100644 index 654046ba0dbf59fba888ec4975b35135a18c88d7..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Lists2.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.lang._ - -object Lists2 { - abstract class List[T] - case class Cons[T](head: T, tail: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - def forall[T](list: List[T], f: T => Boolean): Boolean = list match { - case Cons(head, tail) => f(head) && forall(tail, f) - case Nil() => true - } - - def positive(list: List[Int]): Boolean = list match { - case Cons(head, tail) => if (head < 0) false else positive(tail) - case Nil() => true - } - - def positive_lemma(list: List[Int]): Boolean = { - positive(list) == forall(list, (x: Int) => x >= 0) - } - - def positive_lemma_induct(list: List[Int]): Boolean = { - list match { - case Nil() => positive_lemma(list) - case Cons(head, tail) => positive_lemma(list) && positive_lemma_induct(tail) - } - }.holds - - def remove[T](list: List[T], e: T) : List[T] = { - list match { - case Nil() => Nil() - case Cons(x, xs) if x == e => remove(xs, e) - case Cons(x, xs) => Cons(x, remove(xs, e)) - } - } //ensuring { (res: List[T]) => forall(res, (x : T) => x != e) } - - def remove_lemma[T](list: List[T], e: T): Boolean = { - forall(remove(list, e), (x : T) => x != e) - } - - def remove_lemma_induct[T](list: List[T], e: T): Boolean = { - list match { - case Nil() => remove_lemma(list, e) - case Cons(head, tail) => remove_lemma(list, e) && remove_lemma_induct(tail, e) - } - }.holds -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/Lists3.scala b/testcases/verification/higher-order/valid/Lists3.scala deleted file mode 100644 index 67060133a65e1661b32757ff98b0857e71897d12..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Lists3.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.lang._ - -object Lists3 { - abstract class List[T] - case class Cons[T](head: T, tail: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - def forall[T](list: List[T], f: T => Boolean): Boolean = list match { - case Cons(head, tail) => f(head) && forall(tail, f) - case Nil() => true - } - - def positive(list: List[Int]): Boolean = list match { - case Cons(head, tail) => if (head < 0) false else positive(tail) - case Nil() => true - } - - def gt(i: Int): Int => Boolean = x => x > i - - def gte(i: Int): Int => Boolean = x => gt(i)(x) || x == i - - def positive_lemma(list: List[Int]): Boolean = { - positive(list) == forall(list, gte(0)) - } - - def positive_lemma_induct(list: List[Int]): Boolean = { - list match { - case Nil() => positive_lemma(list) - case Cons(head, tail) => positive_lemma(list) && positive_lemma_induct(tail) - } - }.holds -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/Lists4.scala b/testcases/verification/higher-order/valid/Lists4.scala deleted file mode 100644 index 02c24111d2a9936ba14764355f7c51d4cfc9e1fa..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Lists4.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.lang._ - -object Lists4 { - abstract class List[T] - case class Cons[T](head: T, tail: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - def map[F,T](list: List[F], f: F => T): List[T] = list match { - case Cons(head, tail) => Cons(f(head), map(tail, f)) - case Nil() => Nil() - } - - def map_lemma[A,B,C](list: List[A], f: A => B, g: B => C): Boolean = { - map(list, (x: A) => g(f(x))) == map(map(list, f), g) - } - - def map_lemma_induct[D,E,F](list: List[D], f: D => E, g: E => F): Boolean = { - list match { - case Nil() => map_lemma(list, f, g) - case Cons(head, tail) => map_lemma(list, f, g) && map_lemma_induct(tail, f, g) - } - }.holds - -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/Lists5.scala b/testcases/verification/higher-order/valid/Lists5.scala deleted file mode 100644 index 51ff810c6bcae4ebcb8bb7273dca57b6e0fe3fdd..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Lists5.scala +++ /dev/null @@ -1,32 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object Lists5 { - abstract class Option[T] - case class Some[T](value: T) extends Option[T] - case class None[T]() extends Option[T] - - def find[T](f: T => Boolean, list: List[T]): Option[T] = list match { - case Cons(head, tail) => if (f(head)) Some(head) else find(f, tail) - case Nil() => None() - } - - def exists[T](f: T => Boolean, list: List[T]): Boolean = list match { - case Cons(head, tail) => f(head) || exists(f, tail) - case Nil() => false - } - - def equivalence_lemma[T](f: T => Boolean, list: List[T]): Boolean = { - find(f, list) match { - case Some(e) => exists(f, list) - case None() => !exists(f, list) - } - } - - def equivalence_lemma_induct[T](f: T => Boolean, list: List[T]): Boolean = { - list match { - case Cons(head, tail) => equivalence_lemma(f, list) && equivalence_lemma_induct(f, tail) - case Nil() => equivalence_lemma(f, list) - } - }.holds -} diff --git a/testcases/verification/higher-order/valid/Lists6.scala b/testcases/verification/higher-order/valid/Lists6.scala deleted file mode 100644 index f70d523c7f9139cef806bb6549c06c14c057e6d1..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Lists6.scala +++ /dev/null @@ -1,22 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object Lists6 { - def exists[T](list: List[T], f: T => Boolean): Boolean = { - list match { - case Cons(head, tail) => f(head) || exists(tail, f) - case Nil() => false - } - } - - def associative_lemma[T](list: List[T], f: T => Boolean, g: T => Boolean): Boolean = { - exists(list, (x: T) => f(x) || g(x)) == (exists(list, f) || exists(list, g)) - } - - def associative_lemma_induct[T](list: List[T], f: T => Boolean, g: T => Boolean): Boolean = { - associative_lemma(list, f, g) && (list match { - case Cons(head, tail) => associative_lemma_induct(tail, f, g) - case Nil() => true - }) - }.holds -} diff --git a/testcases/verification/higher-order/valid/Monads1.scala b/testcases/verification/higher-order/valid/Monads1.scala deleted file mode 100644 index da9cd6cec6cd3ff2e802beeaabcf8e4b4f20a939..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Monads1.scala +++ /dev/null @@ -1,24 +0,0 @@ -import leon.lang._ - -object Monads1 { - abstract class Try[T] - case class Success[T](value: T) extends Try[T] - case class Failure[T](error: Int) extends Try[T] - - def flatMap[T,U](t: Try[T], f: T => Try[U]): Try[U] = t match { - case Success(value) => f(value) - case fail @ Failure(error) => Failure(error) - } - - def associative_law[T,U,V](t: Try[T], f: T => Try[U], g: U => Try[V]): Boolean = { - flatMap(flatMap(t, f), g) == flatMap(t, (x: T) => flatMap(f(x), g)) - }.holds - - def left_unit_law[T,U](x: T, f: T => Try[U]): Boolean = { - flatMap(Success(x), f) == f(x) - }.holds - - def right_unit_law[T,U](t: Try[T]): Boolean = { - flatMap(t, (x: T) => Success(x)) == t - }.holds -} diff --git a/testcases/verification/higher-order/valid/Monads2.scala b/testcases/verification/higher-order/valid/Monads2.scala deleted file mode 100644 index f89b2b7f7b71d6b5260bc87b861cd1b3fef9355b..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Monads2.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.lang._ - -object Monads2 { - abstract class Option[T] - case class Some[T](t: T) extends Option[T] - case class None[T]() extends Option[T] - - def flatMap[T,U](opt: Option[T], f: T => Option[U]): Option[U] = opt match { - case Some(x) => f(x) - case None() => None() - } - - def add[T](o1: Option[T], o2: Option[T]): Option[T] = o1 match { - case Some(x) => o1 - case None() => o2 - } - - def associative_law[T,U,V](opt: Option[T], f: T => Option[U], g: U => Option[V]): Boolean = { - flatMap(flatMap(opt, f), g) == flatMap(opt, (x: T) => flatMap(f(x), g)) - }.holds - - def left_unit_law[T,U](x: T, f: T => Option[U]): Boolean = { - flatMap(Some(x), f) == f(x) - }.holds - - def right_unit_law[T,U](opt: Option[T]): Boolean = { - flatMap(opt, (x: T) => Some(x)) == opt - }.holds - - def flatMap_zero_law[T,U](none: None[T], f: T => Option[U]): Boolean = { - flatMap(none, f) == None[U]() - }.holds - - def flatMap_to_zero_law[T,U](opt: Option[T]): Boolean = { - flatMap(opt, (x: T) => None[U]()) == None[U]() - }.holds - - def add_zero_law[T](opt: Option[T]): Boolean = { - add(opt, None[T]()) == opt - }.holds - - def zero_add_law[T](opt: Option[T]): Boolean = { - add(None[T](), opt) == opt - }.holds -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/Monads3.scala b/testcases/verification/higher-order/valid/Monads3.scala deleted file mode 100644 index a2911c98793e1d487b5338bc2d07010b52170ace..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Monads3.scala +++ /dev/null @@ -1,77 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object FlatMap { - - def append[T](l1: List[T], l2: List[T]): List[T] = { - l1 match { - case Cons(head, tail) => Cons(head, append(tail, l2)) - case Nil() => l2 - } - } ensuring { res => (res == l1) || (l2 != Nil[T]()) } - - def flatMap[T,U](list: List[T], f: T => List[U]): List[U] = list match { - case Cons(head, tail) => append(f(head), flatMap(tail, f)) - case Nil() => Nil() - } - - def associative_lemma[T,U,V](list: List[T], f: T => List[U], g: U => List[V]): Boolean = { - flatMap(flatMap(list, f), g) == flatMap(list, (x: T) => flatMap(f(x), g)) - } - - def associative_lemma_induct[T,U,V](list: List[T], flist: List[U], glist: List[V], f: T => List[U], g: U => List[V]): Boolean = { - associative_lemma(list, f, g) && - append(glist, flatMap(append(flist, flatMap(list, f)), g)) == append(append(glist, flatMap(flist, g)), flatMap(list, (x: T) => flatMap(f(x), g))) && - (glist match { - case Cons(ghead, gtail) => - associative_lemma_induct(list, flist, gtail, f, g) - case Nil() => flist match { - case Cons(fhead, ftail) => - associative_lemma_induct(list, ftail, g(fhead), f, g) - case Nil() => list match { - case Cons(head, tail) => associative_lemma_induct(tail, f(head), Nil(), f, g) - case Nil() => true - } - } - }) - }.holds - - def left_unit_law[T,U](x: T, f: T => List[U]): Boolean = { - flatMap(Cons(x, Nil()), f) == f(x) - }.holds - - def right_unit_law[T](list: List[T]): Boolean = { - flatMap(list, (x: T) => Cons(x, Nil())) == list - } - - def right_unit_induct[T,U](list: List[T]): Boolean = { - right_unit_law(list) && (list match { - case Cons(head, tail) => right_unit_induct(tail) - case Nil() => true - }) - }.holds - - def flatMap_zero_law[T,U](f: T => List[U]): Boolean = { - flatMap(Nil[T](), f) == Nil[U]() - }.holds - - def flatMap_to_zero_law[T](list: List[T]): Boolean = { - flatMap(list, (x: T) => Nil[T]()) == Nil[T]() - } - - def flatMap_to_zero_induct[T,U](list: List[T]): Boolean = { - flatMap_to_zero_law(list) && (list match { - case Cons(head, tail) => flatMap_to_zero_induct(tail) - case Nil() => true - }) - }.holds - - def add_zero_law[T](list: List[T]): Boolean = { - append(list, Nil()) == list - }.holds - - def zero_add_law[T](list: List[T]): Boolean = { - append(Nil(), list) == list - }.holds - -} diff --git a/testcases/verification/higher-order/valid/MonadsException.scala b/testcases/verification/higher-order/valid/MonadsException.scala deleted file mode 100644 index 27c87d26177ef8c0d42f49766ab56a2c1e68b13c..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/MonadsException.scala +++ /dev/null @@ -1,61 +0,0 @@ -import leon.lang._ - -object TryMonad { - - // Exception monad similar to Option monad, with a message for None - - sealed abstract class M[T] { - def bind[S](f: T => M[S]): M[S] = { - this match { - case Exc(str) => Exc[S](str) - case Success(t) => f(t) - } - } - } - case class Exc[T](err: BigInt) extends M[T] - case class Success[T](t: T) extends M[T] - - // unit is success - def unit[T](t:T) = Success(t) - - // all laws hold - def leftIdentity[T,S](t: T, f: T => M[S]): Boolean = { - unit(t).bind(f) == f(t) - }.holds - - def rightIdentity[T](m: M[T]): Boolean = { - m.bind(unit(_)) == m - }.holds - - def associativity[T,S,R](m: M[T], f: T => M[S], g: S => M[R]): Boolean = { - m.bind(f).bind(g) == m.bind((t:T) => f(t).bind(g)) - }.holds - - // here is how we can use it - - def plus(x: M[BigInt], y: M[BigInt]) = { - x.bind(xv => y.bind(yv => unit(xv+yv))) - } - - def minus(x: M[BigInt], y: M[BigInt]) = { - x.bind(xv => y.bind(yv => unit(xv - yv))) - } - - def mul(x: M[BigInt], y: M[BigInt]): M[BigInt] = { - x.bind(xv => - if (xv==0) x - else y.bind(yv => unit(xv * yv))) - } - - def mydiv(x: M[BigInt], y: M[BigInt]) = { - x.bind(xv => y.bind(yv => - if (yv==0) Exc[BigInt](1001) - else unit(xv/yv))) - } - - - def test1 = plus(unit(10), unit(32)) - def test2 = plus(mydiv(unit(10), unit(0)), unit(32)) - def test3 = plus(unit(3), plus(mydiv(unit(10), minus(unit(7), unit(7))), unit(32))) - def test4 = mul(unit(0), test3) -} diff --git a/testcases/verification/higher-order/valid/ParBalance.scala b/testcases/verification/higher-order/valid/ParBalance.scala deleted file mode 100644 index 6943d3268a97ebadb5e2b49619ce119478d56c65..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/ParBalance.scala +++ /dev/null @@ -1,206 +0,0 @@ -import leon._ -import leon.lang._ - -object ParBalance { - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - sealed abstract class Option - case class Some(x: BigInt) extends Option - case class None() extends Option - - val openPar : BigInt = BigInt(1) - val closePar : BigInt = BigInt(2) - - def balanced(list: List, counter: BigInt): Boolean = { - if (counter < 0) false else list match { - case Cons(head, tail) => - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced(tail, c) - case Nil() => counter == 0 - } - } - - def balanced_nonEarly(list: List, counter: BigInt): Boolean = { - list match { - case Cons(head, tail) => - if (counter < 0) balanced_nonEarly(tail, counter) else { - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced_nonEarly(tail, c) - } - case Nil() => counter == 0 - } - } ensuring { res => res == balanced(list, counter) } - - def balanced_withFailure(list: List, counter: BigInt, failed: Boolean): Boolean = { - require(counter >= 0 || failed) - list match { - case Cons(head, tail) => - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced_withFailure(tail, c, failed || c < 0) - case Nil() => !failed && counter == 0 - } - } ensuring { res => - if (failed) { - res == balanced_nonEarly(list, -1) - } else { - res == balanced_nonEarly(list, counter) - } - } - - def balanced_withReduce(list: List, p: (BigInt, BigInt)): Boolean = { - require(p._1 >= 0 && p._2 >= 0) - list match { - case Cons(head, tail) => - val p2 = reduce(p, parPair(head)) - balanced_withReduce(tail, p2) - case Nil() => - p._1 == 0 && p._2 == 0 - } - } ensuring { res => res == balanced_withFailure(list, p._1 - p._2, p._2 > 0) } - - def balanced_foldLeft_equivalence(list: List, p: (BigInt, BigInt)): Boolean = { - require(p._1 >= 0 && p._2 >= 0) - val f = (s: (BigInt, BigInt), x: BigInt) => reduce(s, parPair(x)) - (foldLeft(list, p, f) == (BigInt(0), BigInt(0))) == balanced_withReduce(list, p) && (list match { - case Cons(head, tail) => - val p2 = f(p, head) - balanced_foldLeft_equivalence(tail, p2) - case Nil() => true - }) - }.holds - - def foldRight[A](list: List, state: A, f: (BigInt, A) => A): A = list match { - case Cons(head, tail) => - val tailState = foldRight(tail, state, f) - f(head, tailState) - case Nil() => state - } - - def foldLeft[A](list: List, state: A, f: (A, BigInt) => A): A = list match { - case Cons(head, tail) => - val nextState = f(state, head) - foldLeft(tail, nextState, f) - case Nil() => state - } - - def reduce(p1: (BigInt, BigInt), p2: (BigInt, BigInt)): (BigInt, BigInt) = { - if (p1._1 >= p2._2) { - (p1._1 - p2._2 + p2._1, p1._2) - } else { - (p2._1, p2._2 - p1._1 + p1._2) - } - } - - def reduce_associative(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(p1, reduce(p2, p3)) == reduce(reduce(p1, p2), p3) - }.holds - - def swap(p: (BigInt, BigInt)): (BigInt, BigInt) = (p._2, p._1) - - def reduce_inverse(p1: (BigInt, BigInt), p2: (BigInt, BigInt)): Boolean = { - reduce(p1, p2) == swap(reduce(swap(p2), swap(p1))) - }.holds - - def reduce_associative_inverse(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(p1, reduce(p2, p3)) == swap(reduce(reduce(swap(p3), swap(p2)), swap(p1))) - }.holds - - def reduce_associative_inverse2(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(reduce(p1, p2), p3) == swap(reduce(swap(p3), reduce(swap(p2), swap(p1)))) - }.holds - - def parPair(x: BigInt): (BigInt, BigInt) = { - if (x == openPar) (1, 0) else if (x == closePar) (0, 1) else (0, 0) - } - - def headOption(list: List): Option = list match { - case Cons(head, tail) => Some(head) - case Nil() => None() - } - - def lastOption(list: List): Option = list match { - case Cons(head, Nil()) => Some(head) - case Cons(head, tail) => lastOption(tail) - case Nil() => None() - } - - def init(list: List): List = list match { - case Cons(head, Nil()) => Nil() - case Cons(head, tail) => Cons(head, init(tail)) - case Nil() => Nil() - } - - def tail(list: List): List = list match { - case Cons(head, tail) => tail - case Nil() => Nil() - } - - def addLast(list: List, x: BigInt): List = { - list match { - case Cons(head, tail) => Cons(head, addLast(tail, x)) - case Nil() => Cons(x, Nil()) - } - } ensuring { res => lastOption(res) == Some(x) && init(res) == list } - - def reverse(list: List): List = { - list match { - case Cons(head, tail) => addLast(reverse(tail), head) - case Nil() => Nil() - } - } ensuring { res => - lastOption(res) == headOption(list) && - lastOption(list) == headOption(res) - } - - def reverse_tail_equivalence(list: List): Boolean = { - reverse(tail(list)) == init(reverse(list)) - }.holds - - def reverse_init_equivalence(list: List): Boolean = { - reverse(init(list)) == tail(reverse(list)) && (list match { - case Cons(head, tail) => reverse_init_equivalence(tail) - case Nil() => true - }) - }.holds - - def reverse_equality_equivalence(l1: List, l2: List): Boolean = { - (l1 == l2) == (reverse(l1) == reverse(l2)) && ((l1, l2) match { - case (Cons(h1, t1), Cons(h2, t2)) => reverse_equality_equivalence(t1, t2) - case _ => true - }) - }.holds - - def reverse_reverse_equivalence(list: List): Boolean = { - reverse(reverse(list)) == list && ((list, reverse(list)) match { - case (Cons(h1, t1), Cons(h2, t2)) => - reverse_reverse_equivalence(t1) && reverse_reverse_equivalence(t2) - case _ => true - }) - }.holds - - /* - def fold_equivalence(list: List): Boolean = { - val s = (0, 0) - val fl = (s: (BigInt, BigInt), x: BigInt) => reduce(s, parPair(x)) - val fr = (x: BigInt, s: (BigInt, BigInt)) => reduce(parPair(x), s) - - foldLeft(list, s, fl) == foldRight(list, s, fr) - }.holds - - def lemma(list: List): Boolean = { - val f = (x: BigInt, s: (BigInt, BigInt)) => reduce(parPair(x), s) - fold_equivalence(list) && balanced_foldLeft_equivalence(list, (0, 0)) && - (foldRight(list, (0, 0), f) == (0, 0)) == balanced(list, 0) - }.holds - */ - -} diff --git a/testcases/verification/higher-order/valid/PositiveMap.scala b/testcases/verification/higher-order/valid/PositiveMap.scala deleted file mode 100644 index 0441ec26ca74f98dec17e05e91e487f0756b78ad..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/PositiveMap.scala +++ /dev/null @@ -1,36 +0,0 @@ -import leon.lang._ - -object PositiveMap { - - abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def positive(list: List): Boolean = list match { - case Cons(head, tail) => if (head < 0) false else positive(tail) - case Nil() => true - } - - def positiveMap_passing_1(f: (BigInt) => BigInt, list: List): List = { - list match { - case Cons(head, tail) => - val fh = f(head) - val nh = if (fh <= 0) -fh else fh - Cons(nh, positiveMap_passing_1(f, tail)) - case Nil() => Nil() - } - } ensuring { res => positive(res) } - - def positiveMap_passing_2(f: (BigInt) => BigInt, list: List): List = { - list match { - case Cons(head, tail) => - val fh = f(head) - val nh = if (fh < 0) -fh else fh - Cons(nh, positiveMap_passing_2(f, tail)) - case Nil() => Nil() - } - } ensuring { res => positive(res) } - -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/higher-order/valid/Relations.scala b/testcases/verification/higher-order/valid/Relations.scala deleted file mode 100644 index 8a84b2d8e693f1043ee7522ecd67bbeab01dc807..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Relations.scala +++ /dev/null @@ -1,39 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object Relations { - sealed case class G[A](domain: List[A]) - - def forall[A](p: A => Boolean)(implicit g: G[A]) : Boolean = { - g.domain.forall(p) - } - def exists[A](p: A => Boolean)(implicit g: G[A]) : Boolean = { - g.domain.exists(p) - } - - def circ[A](r1: ((A,A)) ⇒ Boolean, r2: ((A,A)) ⇒ Boolean)(implicit g: G[A]) : (((A,A)) => Boolean) = { - case (x,z) => exists((y:A) => r1(x,y) && r2(y,z)) - } - - def eq[A](s1: A ⇒ Boolean, s2: A ⇒ Boolean)(implicit g: G[A]): Boolean = { - forall((x:A) => s1(x)==s2(x)) - } - - def setOf[A](l: List[A]): (A => Boolean) = (l.contains(_)) - - def test(r1: ((Int,Int)) => Boolean, r2: ((Int,Int)) => Boolean): Boolean = { - implicit val g1: G[Int] = G[Int](List(1,2)) - implicit val g2: G[(Int,Int)] = G(List(1 -> 1, 1 -> 2, 2 -> 2, 2 -> 1, 3 -> 2, 3 -> 1)) - //val r1: ((Int,Int)) => Boolean = setOf(List(1 -> 2, 2 -> 3, 3 -> 1)) - //val r2: ((Int,Int)) => Boolean = setOf(List(1 -> 1, 2 -> 3, 3 -> 2)) - val commutative = - eq(circ(r1, r2), circ(r2, r1)) - - val r3: ((Int,Int)) => Boolean = setOf(List(1 -> 5, 2 -> 2, 1 -> 2)) - val associative = - eq(circ(circ(r1,r2), r3), circ(r1, circ(r2, r3))) - associative - }.holds - -} diff --git a/testcases/verification/higher-order/valid/Sets1.scala b/testcases/verification/higher-order/valid/Sets1.scala deleted file mode 100644 index 4cfca4890810e544407f2200aaae8ab4ca5381ec..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Sets1.scala +++ /dev/null @@ -1,23 +0,0 @@ -import leon.lang._ - -object Sets1 { - def set(i: Int): Int => Boolean = x => x == i - - def complement(s: Int => Boolean): Int => Boolean = x => !s(x) - - def union(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) || s2(x) - - def intersection(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) && s2(x) - - def de_morgan_1(s1: Int => Boolean, s2: Int => Boolean, x: Int): Boolean = { - val u1 = union(s1, s2) - val u2 = complement(intersection(complement(s1), complement(s2))) - u1(x) == u2(x) - }.holds - - def de_morgan_2(s1: Int => Boolean, s2: Int => Boolean, x: Int): Boolean = { - val u1 = intersection(s1, s2) - val u2 = complement(union(complement(s1), complement(s2))) - u1(x) == u2(x) - }.holds -} diff --git a/testcases/verification/higher-order/valid/Sets2.scala b/testcases/verification/higher-order/valid/Sets2.scala deleted file mode 100644 index f25449028f2a5c5975d46ff889ee3a352b13d941..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Sets2.scala +++ /dev/null @@ -1,23 +0,0 @@ -import leon.lang._ - -object Sets1 { - def set(i: Int): Int => Boolean = x => x == i - - def complement(s: Int => Boolean): Int => Boolean = x => !s(x) - - def union(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) || s2(x) - - def intersection(s1: Int => Boolean, s2: Int => Boolean): Int => Boolean = x => s1(x) && s2(x) - - def union_associativity(sa1: Int => Boolean, sa2: Int => Boolean, sa3: Int => Boolean, x: Int): Boolean = { - val u1 = union(union(sa1, sa2), sa3) - val u2 = union(sa1, union(sa2, sa3)) - u1(x) == u2(x) - }.holds - - def intersection_associativity(sa1: Int => Boolean, sa2: Int => Boolean, sa3: Int => Boolean, x: Int): Boolean = { - val u1 = intersection(intersection(sa1, sa2), sa3) - val u2 = intersection(sa1, intersection(sa2, sa3)) - u1(x) == u2(x) - }.holds -} diff --git a/testcases/verification/higher-order/valid/SubtreeSearch.scala b/testcases/verification/higher-order/valid/SubtreeSearch.scala deleted file mode 100644 index a84fe04c4a413038ac522e173203362bd01f8537..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/SubtreeSearch.scala +++ /dev/null @@ -1,37 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon.annotation._ -object Tree { - sealed abstract class Tree - case object Empty extends Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - - sealed abstract class Dir - case object Left extends Dir - case object Right extends Dir - - def lookup(t: Tree, path : List[Dir]): Option[Tree] = { - (t,path) match { - case (_,Nil()) => Some[Tree](t) - case (Empty,_) => None[Tree]() - case (Node(left,_,_), Cons(Left,rest)) => lookup(left,rest) - case (Node(_,_,right), Cons(Right,rest)) => lookup(right,rest) - } - } - - def cons[A](x: A, lst: List[A]): List[A] = Cons[A](x,lst) - - def find(t: Tree, subtree: Tree): List[List[Dir]] = ({ - if (t==subtree) - List(Nil[Dir]) - else { - t match { - case Empty => Nil[List[Dir]] - case Node(left,_,right) => { - find(left,subtree).map(cons(Left,_)) ++ - find(right,subtree).map(cons(Right,_)) - } - } - } - } : List[List[Dir]]).ensuring((res:List[List[Dir]]) => res.forall((path:List[Dir]) => true)) -} diff --git a/testcases/verification/higher-order/valid/Trees1.scala b/testcases/verification/higher-order/valid/Trees1.scala deleted file mode 100644 index 4c01ae06ef89aeed1e13a4c2baf63df776607322..0000000000000000000000000000000000000000 --- a/testcases/verification/higher-order/valid/Trees1.scala +++ /dev/null @@ -1,23 +0,0 @@ -import leon.lang._ - -object Trees1 { - abstract class Tree[T] - case class Node[T](left: Tree[T], right: Tree[T]) extends Tree[T] - case class Leaf[T](value: T) extends Tree[T] - - def map[T,U](tree: Tree[T], f: T => U): Tree[U] = tree match { - case Node(left, right) => Node(map(left, f), map(right, f)) - case Leaf(value) => Leaf(f(value)) - } - - def associative_lemma[T,U,V](tree: Tree[T], f: T => U, g: U => V): Boolean = { - map(map(tree, f), g) == map(tree, (x: T) => g(f(x))) - } - - def associative_lemma_induct[T,U,V](tree: Tree[T], f: T => U, g: U => V): Boolean = { - tree match { - case Node(left, right) => associative_lemma_induct(left, f, g) && associative_lemma_induct(right, f, g) && associative_lemma(tree, f, g) - case Leaf(value) => associative_lemma(tree, f, g) - } - }.holds -} diff --git a/testcases/verification/isabelle/Functions.scala b/testcases/verification/isabelle/Functions.scala deleted file mode 100644 index bb7503d724042e69b6c7db1a3facb1c957cfbdcc..0000000000000000000000000000000000000000 --- a/testcases/verification/isabelle/Functions.scala +++ /dev/null @@ -1,19 +0,0 @@ -import leon._ -import leon.annotation._ -import leon.collection._ -import leon.lang._ - -object Functions { - - def zero: BigInt = 0 - - def length[A](xs: List[A]): BigInt = { - val ys = xs - val zs = ys - ys match { - case Nil() => zero - case Cons(_, xs) => BigInt(1) + length(xs) - } - } ensuring (_ >= zero) - -} diff --git a/testcases/verification/isabelle/Simple.scala b/testcases/verification/isabelle/Simple.scala deleted file mode 100644 index 802f9530ce46c0a472c0169c0a21ceb9f3378909..0000000000000000000000000000000000000000 --- a/testcases/verification/isabelle/Simple.scala +++ /dev/null @@ -1,18 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object Simple { - - val truth: Boolean = true holds - val contradiction: Boolean = false holds - - val equality = { val x = (); val y = (); x == y } holds - - def ints(x: BigInt, y: BigInt) = { - require { x > 0 && y > 0 } - x + y - } ensuring { _ > 0 } - - val chars = { val x = 'a'; val y = 'a'; x == y } holds - -} diff --git a/testcases/verification/list-algorithms/BasicMergeSort.scala b/testcases/verification/list-algorithms/BasicMergeSort.scala deleted file mode 100644 index 67fadf7dd7e7569107c4a6802b849f7844b66bd1..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/BasicMergeSort.scala +++ /dev/null @@ -1,41 +0,0 @@ -package listalgorithms - -import leon._ -import lang._ -import collection._ - -object MergeSort { - - def merge[T](less: (T, T) => Boolean)(xs: List[T], ys: List[T]): List[T] = { - (xs, ys) match { - case (Nil(), _) => ys - case (_, Nil()) => xs - case (Cons(x, xtail), Cons(y, ytail)) => - if (less(x, y)) - x :: merge(less)(xtail, ys) - else - y :: merge(less)(xs, ytail) - } - } ensuring { res => res.content == xs.content ++ ys.content && - res.size == xs.size + ys.size } - - def split[T](list: List[T]): (List[T], List[T]) = { - list match { - case Nil() => (Nil(), Nil()) - case Cons(x, Nil()) => (Cons(x, Nil()), Nil()) - case Cons(x1, Cons(x2, xs)) => - val (s1, s2) = split(xs) - (Cons(x1, s1), Cons(x2, s2)) - } - } - - def msort[T](less: (T, T) => Boolean)(l: List[T]): List[T] = { - l match { - case Nil() => Nil[T]() - case Cons(x, Nil()) => Cons(x, Nil()) - case _ => - val (first, second) = split(l) - merge(less)(msort(less)(first), msort(less)(second)) - } - } ensuring { res => res.content == l.content && res.size == l.size } -} diff --git a/testcases/verification/list-algorithms/BasicMergeSortPar.scala b/testcases/verification/list-algorithms/BasicMergeSortPar.scala deleted file mode 100644 index 843a617eed5c7002400fab47d4e57892c198ea8f..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/BasicMergeSortPar.scala +++ /dev/null @@ -1,36 +0,0 @@ -/* Basic parallel Merge sort that: - * shows use of 'par' construct - * uses a higher-order comparison function - * relies on a strong spec for a list library function splitAtIndex - Warning: spec does not check sortedness or multiplicity. -*/ -import leon.lang._ -import leon.collection._ -import leon.par._ -object MergeSortPar { - - def merge[T](less: (T, T) => Boolean)(xs: List[T], ys: List[T]): List[T] = { - (xs, ys) match { - case (Nil(), _) => ys - case (_, Nil()) => xs - case (Cons(x,xtail), Cons(y,ytail)) => - if (less(x, y)) - x :: merge(less)(xtail, ys) - else - y :: merge(less)(xs, ytail) - } - } ensuring { res => res.content == xs.content ++ ys.content && - res.size == xs.size + ys.size } - - def msort[T](less: (T, T) => Boolean)(l: List[T], len : BigInt): List[T] = { - require(len == l.length) - if (l.size <= 1) l - else { - val c = len/2 - val (first, second) = l.splitAtIndex(c) // evenSplit - val (s1, s2) = parallel(msort(less)(first, c), msort(less)(second, len - c)) - merge(less)(s1, s2) - } - } ensuring { res => res.content == l.content && - res.size == l.size } -} diff --git a/testcases/verification/list-algorithms/InsertionSort.scala b/testcases/verification/list-algorithms/InsertionSort.scala deleted file mode 100644 index 980927204dad1e609e93dd8dcf8a364d027e113d..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/InsertionSort.scala +++ /dev/null @@ -1,99 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object InsertionSort { - sealed abstract class List - case class Cons(head: BigInt,tail: List) extends List - case class Nil() extends List - - sealed abstract class OptInt - case class Some(value: BigInt) extends OptInt - case class None() extends OptInt - - def size(l : List) : BigInt = (l match { - case Nil() => BigInt(0) - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contents(l: List): Set[BigInt] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def min(l : List) : OptInt = l match { - case Nil() => None() - case Cons(x, xs) => min(xs) match { - case None() => Some(x) - case Some(x2) => if(x < x2) Some(x) else Some(x2) - } - } - - def minProp0(l : List) : Boolean = (l match { - case Nil() => true - case c @ Cons(x, xs) => min(c) match { - case None() => false - case Some(m) => x >= m - } - }) holds - - def minProp1(l : List) : Boolean = { - require(isSorted(l) && size(l) <= 5) - l match { - case Nil() => true - case c @ Cons(x, xs) => min(c) match { - case None() => false - case Some(m) => x == m - } - } - } holds - - 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)) - } - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def sortedIns(e: BigInt, l: List): List = { - require(isSorted(l)) - l match { - case Nil() => Cons(e,Nil()) - case Cons(x,xs) => if (x <= e) Cons(x,sortedIns(e, xs)) else Cons(e, l) - } - } ensuring(res => contents(res) == contents(l) ++ Set(e) - && isSorted(res) - && size(res) == size(l) + 1 - ) - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def buggySortedIns(e: BigInt, l: List): List = { - // require(isSorted(l)) - l match { - case Nil() => Cons(e,Nil()) - case Cons(x,xs) => if (x <= e) Cons(x,buggySortedIns(e, xs)) else Cons(e, l) - } - } ensuring(res => contents(res) == contents(l) ++ Set(e) - && isSorted(res) - && size(res) == size(l) + 1 - ) - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort(l: List): List = (l match { - case Nil() => Nil() - case Cons(x,xs) => sortedIns(x, sort(xs)) - }) ensuring(res => contents(res) == contents(l) - && isSorted(res) - && size(res) == size(l) - ) - - @ignore - def main(args: Array[String]): Unit = { - val ls: List = Cons(5, Cons(2, Cons(4, Cons(5, Cons(1, Cons(8,Nil())))))) - - println(ls) - println(sort(ls)) - } -} diff --git a/testcases/verification/list-algorithms/MergeSort.scala b/testcases/verification/list-algorithms/MergeSort.scala deleted file mode 100644 index 9ba13b7893787c9b8c77ed9f2793c891ef319acb..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/MergeSort.scala +++ /dev/null @@ -1,58 +0,0 @@ -import leon.lang._ -import synthesis._ -import leon.collection._ - -object MergeSort { - - def isSorted(l: List[BigInt]): Boolean = l match { - case Cons(x, t@Cons(y, _)) => x <= y && isSorted(t) - case _ => true - } - - def merge(l1: List[BigInt], l2: List[BigInt]): List[BigInt] = { - require(isSorted(l1) && isSorted(l2)) - (l1, l2) match { - case (Nil(), _) => l2 - case (_, Nil()) => l1 - case (Cons(h1,t1), Cons(h2, t2)) => - if (h1 <= h2) Cons(h1, merge(t1, l2)) - else Cons(h2, merge(l1, t2)) - } - } ensuring { - (res: List[BigInt]) => - isSorted(res) && - res.content == l1.content ++ l2.content && - res.size == l1.size + l2.size - } - - def split(l: List[BigInt]): (List[BigInt], List[BigInt]) = { - require(l.size > 1) - l match { - case Cons(h1, Cons(h2, Nil())) => - (List(h1), List(h2)) - case Cons(h1, Cons(h2, Cons(h3, Nil()))) => - (List(h1, h3), List(h2)) - case Cons(h1, Cons(h2, tail)) => - val (rec1, rec2) = split(tail) - (h1 :: rec1, h2 :: rec2) - case _ => (l, Nil[BigInt]()) - } - } ensuring { (res: (List[BigInt], List[BigInt])) => - val (r1, r2) = res - r1.size < l.size && r2.size < l.size && - r1.size + r2.size == l.size && - r1.content ++ r2.content == l.content - } - - def mergeSort(l: List[BigInt]): List[BigInt] = { - if (l.size <= 1) l else { - val (l1, l2) = split(l) - merge(mergeSort(l1), mergeSort(l2)) - } - } ensuring ( res => - isSorted(res) && - res.content == l.content && - res.size == l.size - ) - -} diff --git a/testcases/verification/list-algorithms/QuickSort.scala b/testcases/verification/list-algorithms/QuickSort.scala deleted file mode 100644 index 1afbc3a2b4d7c5f5a54560a6aa401d396646390c..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/QuickSort.scala +++ /dev/null @@ -1,127 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object QuickSort { - sealed abstract class List - case class Cons(head:Int,tail:List) extends List - case class Nil() extends List - - sealed abstract class OptInt - case class Some(i: Int) extends OptInt - case class None() extends OptInt - - def content(l: List): Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => content(xs) ++ Set(x) - } - - def contains(l: List, e: Int): Boolean = l match { - case Nil() => false - case Cons(x, xs) => x == e || contains(xs, e) - } - - def isSorted(l: List): Boolean = l match { - case Nil() => true - case Cons(x,Nil()) => true - case Cons(x,Cons(y,xs)) => x<=y && isSorted(Cons(y,xs)) - } - - def min(l: List): OptInt = l match { - case Nil() => None() - case Cons(x, xs) => min(xs) match { - case Some(m) => if (x <= m) Some(x) else Some(m) - case None() => Some(x) - } - } - - def max(l: List): OptInt = l match { - case Nil() => None() - case Cons(x, xs) => max(xs) match { - case Some(m) => if (x >= m) Some(x) else Some(m) - case None() => Some(x) - } - } - - def rev_append(aList:List,bList:List): List = (aList match { - case Nil() => bList - case Cons(x,xs) => rev_append(xs,Cons(x,bList)) - }) ensuring(content(_) == content(aList) ++ content(bList)) - - def reverse(list:List): List = rev_append(list,Nil()) ensuring(content(_) == content(list)) - - def append(aList:List,bList:List): List = (aList match { - case Nil() => bList - case _ => rev_append(reverse(aList),bList) - }) ensuring(content(_) == content(aList) ++ content(bList)) - - def greater(n:Int,list:List) : List = list match { - case Nil() => Nil() - case Cons(x,xs) => if (n < x) Cons(x,greater(n,xs)) else greater(n,xs) - } - - @induct - def greaterProp(n: Int, list: List): Boolean = (min(greater(n, list)) match { - case Some(m) => n < m - case None() => true - }) holds - - def smaller(n:Int,list:List) : List = list match { - case Nil() => Nil() - case Cons(x,xs) => if (n>x) Cons(x,smaller(n,xs)) else smaller(n,xs) - } - - @induct - def smallerProp(n: Int, list: List): Boolean = (max(smaller(n, list)) match { - case Some(m) => n > m - case None() => true - }) holds - - def equals(n:Int,list:List) : List = list match { - case Nil() => Nil() - case Cons(x,xs) => if (n==x) Cons(x,equals(n,xs)) else equals(n,xs) - } - - @induct - def equalsProp1(n: Int, list: List): Boolean = (max(equals(n, list)) match { - case Some(m) => n == m - case None() => true - }) holds - - @induct - def equalsProp2(n: Int, list: List): Boolean = (min(equals(n, list)) match { - case Some(m) => n == m - case None() => true - }) holds - - @induct - def smallerContent(n: Int, e: Int, l: List): Boolean = { - !(contains(l, e) && e < n) || contains(smaller(n, l),e) - } holds - - @induct - def greaterContent(n: Int, e: Int, l: List): Boolean = { - !(contains(l, e) && e > n) || contains(greater(n, l),e) - } holds - - @induct - def equalsContent(n: Int, e: Int, l: List): Boolean = { - !(contains(l, e) && e == n) || contains(equals(n, l),e) - } holds - - def partitionProp(n: Int, e: Int, l: List): Boolean = - (!contains(l, e) || (contains(smaller(n, l), e) || contains(equals(n,l), e) || contains(greater(n, l), e))) // holds - - def quickSort(list:List): List = (list match { - case Nil() => Nil() - case Cons(x,Nil()) => list - case Cons(x,xs) => append(append(quickSort(smaller(x,xs)),Cons(x,equals(x,xs))),quickSort(greater(x,xs))) - }) ensuring(res => content(res) == content(list)) // && isSorted(res)) - - @ignore - def main(args: Array[String]): Unit = { - val ls: List = Cons(5, Cons(2, Cons(4, Cons(5, Cons(1, Cons(8,Nil())))))) - - println(ls) - println(quickSort(ls)) - } -} diff --git a/testcases/verification/list-algorithms/SearchLinkedList.scala b/testcases/verification/list-algorithms/SearchLinkedList.scala deleted file mode 100644 index 14e36d3e4e829b6ed5694a83f17cc80a57d9cdf1..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/SearchLinkedList.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object SearchLinkedList { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - def size(list : List) : BigInt = (list match { - case Nil() => BigInt(0) - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contains(list : List, elem : Int) : Boolean = (list match { - case Nil() => false - case Cons(x, xs) => x == elem || contains(xs, elem) - }) - - def firstZero(list : List) : BigInt = (list match { - case Nil() => BigInt(0) - case Cons(x, xs) => if (x == 0) BigInt(0) else firstZero(xs) + 1 - }) ensuring (res => - res >= 0 && (if (contains(list, 0)) { - firstZeroAtPos(list, res) - } else { - res == size(list) - })) - - def firstZeroAtPos(list : List, pos : BigInt) : Boolean = { - list match { - case Nil() => false - case Cons(x, xs) => if (pos == 0) x == 0 else x != 0 && firstZeroAtPos(xs, pos - 1) - } - } - - def goal(list : List, i : BigInt) : Boolean = { - if(firstZero(list) == i) { - if(contains(list, 0)) { - firstZeroAtPos(list, i) - } else { - i == size(list) - } - } else { - true - } - } holds -} diff --git a/testcases/verification/list-algorithms/Sorting.scala b/testcases/verification/list-algorithms/Sorting.scala deleted file mode 100644 index faae0add05e87d0eda6b8fb46f4c4faca0b901ce..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/Sorting.scala +++ /dev/null @@ -1,198 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -// Sorting lists is a fundamental problem in CS. -object Sorting { - // Data types - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class LList - case class LCons(head : List, tail : LList) extends LList - case class LNil() extends LList - - // Abstraction functions - def content(list : List) : Set[Int] = list match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def lContent(llist : LList) : Set[Int] = llist match { - case LNil() => Set.empty[Int] - case LCons(x, xs) => content(x) ++ lContent(xs) - } - - def size(list : List) : Int = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def isSorted(list : List) : Boolean = list match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def lIsSorted(llist : LList) : Boolean = llist match { - case LNil() => true - case LCons(x, xs) => isSorted(x) && lIsSorted(xs) - } - - @induct - def sortedLemma(a: Int, x: Int, b: List) = { - !(isSorted(Cons(a,b)) && (content(b) contains x)) || (x >= a) - } holds - - def abs(i : Int) : Int = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - /*************************** - * * - * I N S E R T I O N * - * * - ***************************/ - - def insertSpec(elem : Int, list : List, res : List) : Boolean = { -// isSorted(list) && // Part of precondition, really. - isSorted(res) && content(res) == content(list) ++ Set(elem) - } - - def insertImpl(elem : Int, list : List) : List = { - require(isSorted(list)) - list match { - case Nil() => Cons(elem, Nil()) - case c @ Cons(x, _) if(elem <= x) => Cons(elem, c) - case Cons(x, xs) => Cons(x, insertImpl(elem, xs)) - } - } ensuring(insertSpec(elem, list, _)) - - /********************************** - * * - * M E R G I N G (slow+fast) * - * * - **********************************/ - - def mergeSpec(list1 : List, list2 : List, res : List) : Boolean = { - // isSorted(list1) && isSorted(list2) && // Part of precondition, really. - isSorted(res) && content(res) == content(list1) ++ content(list2) - } - - def mergeImpl(list1 : List, list2 : List) : List = { - require(isSorted(list1) && isSorted(list2)) - - list1 match { - case Nil() => list2 - case Cons(x, xs) => insertImpl(x, mergeImpl(xs, list2)) - } - } ensuring(res => mergeSpec(list1, list2, res)) - - def mergeFastImpl(list1 : List, list2 : List) : List = { - require(isSorted(list1) && isSorted(list2)) - - (list1, list2) match { - case (_, Nil()) => list1 - case (Nil(), _) => list2 - case (Cons(x, xs), Cons(y, ys)) => - if(x <= y) { - Cons(x, mergeFastImpl(xs, list2)) - } else { - Cons(y, mergeFastImpl(list1, ys)) - } - } - } ensuring(res => mergeSpec(list1, list2, res)) - - /*************************** - * * - * S P L I T T I N G * - * * - ***************************/ - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def splitImpl(list : List) : (List,List) = (list match { - case Nil() => (Nil(), Nil()) - case Cons(x, Nil()) => (Cons(x, Nil()), Nil()) - case Cons(x1, Cons(x2, xs)) => - val (s1,s2) = splitImpl(xs) - (Cons(x1, s1), Cons(x2, s2)) - }) ensuring(res => splitSpec(list, res)) - - /*********************** - * * - * S O R T I N G * - * * - ***********************/ - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - def insertSorted(in: List, v: Int): List = { - require(isSorted(in)); - - in match { - case Cons(h, t) => - val r = insertSorted(t, v) - if (h < v) { - Cons(h, r) - } else if (h > v) { - Cons(v, Cons(h, t)) - } else { - Cons(h, t) - } - case _ => - Cons(v, Nil()) - } - } ensuring { res => isSorted(res) && content(res) == content(in) ++ Set(v) } - - def insertionSortImpl(in : List) : List = (in match { - case Nil() => Nil() - case Cons(x, xs) => insertImpl(x, insertionSortImpl(xs)) - }) ensuring(res => sortSpec(in, res)) - - // Not really quicksort, neither mergesort. - def weirdSortImpl(in : List) : List = (in match { - case Nil() => Nil() - case Cons(x, Nil()) => Cons(x, Nil()) - case _ => - val (s1,s2) = splitImpl(in) - mergeFastImpl(weirdSortImpl(s1), weirdSortImpl(s2)) - }) ensuring(res => sortSpec(in, res)) - - def toLList(list : List) : LList = (list match { - case Nil() => LNil() - case Cons(x, xs) => LCons(Cons(x, Nil()), toLList(xs)) - }) ensuring(res => lContent(res) == content(list) && lIsSorted(res)) - - def mergeMap(llist : LList) : LList = { - require(lIsSorted(llist)) - - llist match { - case LNil() => LNil() - case o @ LCons(x, LNil()) => o - case LCons(x, LCons(y, ys)) => LCons(mergeFastImpl(x, y), mergeMap(ys)) - } - } ensuring(res => lContent(res) == lContent(llist) && lIsSorted(res)) - - def mergeReduce(llist : LList) : List = { - require(lIsSorted(llist)) - - llist match { - case LNil() => Nil() - case LCons(x, LNil()) => x - case _ => mergeReduce(mergeMap(llist)) - } - } ensuring(res => content(res) == lContent(llist) && isSorted(res)) - - def mergeSortImpl(in : List) : List = { - mergeReduce(toLList(in)) - } ensuring(res => sortSpec(in, res)) -} diff --git a/testcases/verification/list-algorithms/SumAndMax.scala b/testcases/verification/list-algorithms/SumAndMax.scala deleted file mode 100644 index 0fe57b67a2101aca59a192f5392e255e2786fb12..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/SumAndMax.scala +++ /dev/null @@ -1,46 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object SumAndMax { - sealed abstract class List - case class Cons(head : BigInt, tail : List) extends List - case class Nil() extends List - - def max(list : List) : BigInt = { - require(list != Nil()) - list match { - case Cons(x, Nil()) => x - case Cons(x, xs) => { - val m2 = max(xs) - if(m2 > x) m2 else x - } - } - } - - def sum(list : List) : BigInt = list match { - case Nil() => BigInt(0) - case Cons(x, xs) => x + sum(xs) - } - - def size(list : List) : BigInt = (list match { - case Nil() => BigInt(0) - case Cons(_, xs) => size(xs) + 1 - }) ensuring(_ >= 0) - - def allPos(list : List) : Boolean = list match { - case Nil() => true - case Cons(x, xs) => x >= 0 && allPos(xs) - } - - def prop0(list : List) : Boolean = { - require(list != Nil()) - !allPos(list) || max(list) >= 0 - } holds - - @induct - def property(list : List) : Boolean = { - // This precondition was given in the problem but isn't actually useful :D - // require(allPos(list)) - sum(list) <= size(list) * (if(list == Nil()) 0 else max(list)) - } holds -} diff --git a/testcases/verification/list-algorithms/TwoSizeFunctions.scala b/testcases/verification/list-algorithms/TwoSizeFunctions.scala deleted file mode 100644 index b28e5456160468696ab73e8ea31e9469749e0778..0000000000000000000000000000000000000000 --- a/testcases/verification/list-algorithms/TwoSizeFunctions.scala +++ /dev/null @@ -1,38 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object TwoSizeFunctions { - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def size1(l: List) : BigInt = (l match { - case Cons(_, xs) => size1(xs) + 1 - case Nil() => BigInt(0) - }) ensuring(_ >= 0) - - def size2(l: List) : BigInt = size2acc(l, 0) - def size2acc(l: List, acc: BigInt) : BigInt = { - require(acc >= 0) - l match { - case Nil() => acc - case Cons(_, xs) => size2acc(xs, acc+1) - } - } ensuring(res => res == size1(l) + acc) - - def sizesAreEquiv(l : List) : Boolean = - (size1(l) == size2(l)) holds - -/* - def sizesAreEquiv1(l: List) : Boolean = { - require(size1(l) < 25) // remove and it can't find it. - size1(l) == size2(l) - } holds - - @induct - def sizesAreEquiv(l: List, k : Int) : Boolean = { - require (k >= 0) - size1(l) + k == size2acc(l, k) - } holds -*/ -} diff --git a/testcases/verification/map/BasicMap.scala b/testcases/verification/map/BasicMap.scala deleted file mode 100644 index 2cb3a907e24c66ec139239d91ee017aee5019bdd..0000000000000000000000000000000000000000 --- a/testcases/verification/map/BasicMap.scala +++ /dev/null @@ -1,17 +0,0 @@ -import scala.collection.immutable.Set -import leon.annotation._ -import leon.lang._ - -object BasicMap { - - def insert(m: Map[BigInt, BigInt], key: BigInt, value: BigInt): Map[BigInt, BigInt] = { - require(!m.isDefinedAt(key)) - m + (key -> value) - } ensuring(res => res(key) == value) - - def unionWorks(m1: Map[BigInt, BigInt], m2: Map[BigInt, BigInt], key: BigInt): Boolean = { - require(m1.isDefinedAt(key) || m2.isDefinedAt(key)) - (m1 ++ m2).isDefinedAt(key) - }.holds - -} diff --git a/testcases/verification/math/BitsTricks.scala b/testcases/verification/math/BitsTricks.scala deleted file mode 100644 index 993c7e5150e73c32b2a4d131f4da25c046504ba4..0000000000000000000000000000000000000000 --- a/testcases/verification/math/BitsTricks.scala +++ /dev/null @@ -1,103 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object BitsTricks { - - def bitAt(x: Int, n: Int): Boolean = { - require(n >= 0 && n < 32) - ((x >> n) & 1) == 1 - } - - def isEven(x: Int): Boolean = { - (x & 1) == 0 - } ensuring(res => res == (x % 2 == 0)) - - def isNegative(x: Int): Boolean = { - (x >>> 31) == 1 - } ensuring(b => b == x < 0) - - def isBitNSet(x: Int, n: Int): Int = { - require(n >= 0 && n < 32) - (x & (1 << n)) - } - - def testBitSet1(): Int = { - isBitNSet(122, 3) - } ensuring(_ != 0) - def testBitSet2(): Int = { - isBitNSet(-33, 5) - } ensuring(_ == 0) - - def setBitN(x: Int, n: Int): Int = { - require(n >= 0 && n < 32) - x | (1 << n) - } ensuring(res => isBitNSet(res, n) != 0) - - def toggleBitN(x: Int, n: Int): Int = { - require(n >= 0 && n < 32) - x ^ (1 << n) - } ensuring(res => - if(isBitNSet(x, n) != 0) isBitNSet(res, n) == 0 - else isBitNSet(res, n) != 0) - - - def checkDoubleXor(x: Int, y: Int): Int = { - x ^ y ^ x - } ensuring(res => res == y) - - - def turnOffRightmostOneRec(x: Int, index: Int): Int = { - require(index >= 0 && index < 32) - if(bitAt(x, index)) toggleBitN(x, index)//(x ^ (1 << index)) - else if(index == 31) x - else turnOffRightmostOneRec(x, index + 1) - } - - /* - * loops forever on the proof - */ - def turnOffRightmostOne(x: Int): Int = { - x & (x - 1) - } ensuring(_ == turnOffRightmostOneRec(x, 0)) - - // 010100 -> 010111 - def rightPropagateRightmostOne(x: Int): Int = { - x | (x - 1) - } - - def property1(x: Int): Boolean = { - val y = rightPropagateRightmostOne(x) - y == rightPropagateRightmostOne(y) - } ensuring(b => b) - - def isRotationLeft(x: Int, y: Int, n: Int, i: Int): Boolean = { - require(i >= 0 && i <= 32 && n >= 0 && n < 32) - if(i == 32) - true - else bitAt(x, i) == bitAt(y, (i + n) % 32) && isRotationLeft(x, y, n, i+1) - } - - //rotateLeft proves in 1 minute (on very powerful computer) - def rotateLeft(x: Int, n: Int): Int = { - require(n >= 0 && n < 32) - val front = x >>> (32 - n) - (x << n) | front - } ensuring(res => isRotationLeft(x, res, n, 0)) - - //careful with overflows, case definition, truncated - def safeMean(x: Int, y: Int): Int = { - if(x >= 0 && y <= 0 || x <= 0 && y >= 0) (x + y)/2 - else if(x >= 0 && x <= y) x + (y - x)/2 - else if(x >= 0 && y <= x) y + (x - y)/2 - else if(x <= 0 && x <= y) y + (x - y)/2 - else x + (y - x)/2 - } - - //proves in 45 seconds - def magicMean(x: Int, y: Int): Int = { - val t = (x&y)+((x^y) >> 1) - t + ((t >>> 31) & (x ^ y)) - } ensuring(res => res == safeMean(x, y)) - - -} diff --git a/testcases/verification/math/DivisionSemantic.scala b/testcases/verification/math/DivisionSemantic.scala deleted file mode 100644 index 006fd5364d9186d59ab3d206acc57bf738b9e305..0000000000000000000000000000000000000000 --- a/testcases/verification/math/DivisionSemantic.scala +++ /dev/null @@ -1,61 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon._ - -object DivSemantics { - - def identity1(x: BigInt, y: BigInt): Boolean = { - require(y > 0) - - (x / y) == (-x)/y - } ensuring(res => res) - - def identity2(x: BigInt): Boolean = { - -(x / 2) == -x/2 - } ensuring(res => res) - - def identity3(x: BigInt): Boolean = { - -(x / 2) == x / -2 - } ensuring(res => res) - - //def identity4(x: BigInt, y: BigInt): Boolean = { - // require(y > 0) - // - (x % y) == (-x)%y - //} ensuring(res => res) - - def identity5(x: BigInt): Boolean = { - x % 2 == x % -2 - } ensuring(res => res) - - def identity6(x: BigInt): Boolean = { - require(x != 0) - 5 % x == 5 % -x - } ensuring(res => res) - - def identity1Scoped(x: BigInt, y: BigInt): Boolean = { - require(y > 0) - val r1 = x / y - val r2 = (-x) / y - - r1 == r2 - } ensuring(res => res) - - - def basic1(): Boolean = { - -3 / 2 == -1 - } ensuring(res => res) - def basic2(): Boolean = { - -3 / -2 == 1 - } ensuring(res => res) - def basic3(): Boolean = { - 3 / -2 == -1 - } ensuring(res => res) - def basic4(): Boolean = { - 3 % -2 == 1 - } ensuring(res => res) - def basic5(): Boolean = { - -3 % -2 == -1 - } ensuring(res => res) - def basic6(): Boolean = { - -3 % 2 == -1 - } ensuring(res => res) - -} diff --git a/testcases/verification/math/Fibonacci.scala b/testcases/verification/math/Fibonacci.scala deleted file mode 100644 index 82e3483dbf30f693e13f0d31370d673456026aca..0000000000000000000000000000000000000000 --- a/testcases/verification/math/Fibonacci.scala +++ /dev/null @@ -1,34 +0,0 @@ -object Fibonacci { - - def fib(x: BigInt) : BigInt = { - require(x >= 0) - if(x < 2) { - x - } else { - fib(x - 1) + fib(x - 2) - } - } - - // requires that fib is universally quantified to work... - def check() : Boolean = { - fib(5) == 5 - } ensuring(_ == true) - - - def f(n : BigInt) : BigInt = { - require(n >= 0) - if(n <= 0) - BigInt(1) - else - f(n-1) + g(n-1) - } - - def g(n : BigInt) : BigInt = { - require(n >= 0) - if(n <= 0) - BigInt(1) - else - f(n-1) - } ensuring(_ == fib(n + 1)) - -} diff --git a/testcases/verification/math/Naturals.scala b/testcases/verification/math/Naturals.scala deleted file mode 100644 index 1f9131c9cab2d50a2b26f1a055f4c1b4bf28d75d..0000000000000000000000000000000000000000 --- a/testcases/verification/math/Naturals.scala +++ /dev/null @@ -1,58 +0,0 @@ -import scala.collection.immutable.Set -import leon.annotation._ -import leon.lang._ - -object Naturals { - sealed abstract class Nat - case class Zero() extends Nat - case class Succ(x : Nat) extends Nat - - def plus(x : Nat, y : Nat) : Nat = { - x match { - case Zero() => y - case Succ(x1) => Succ(plus(x1, y)) - } - } - - def leftZero(y : Nat) : Boolean = { - plus(Zero(), y) == y - } holds - - @induct - def rightZero(x : Nat) : Boolean = { - plus(x, Zero()) == x - } holds - - @induct - def assoc(x : Nat, y : Nat, z : Nat) : Boolean = { - plus(x, plus(y,z)) == plus(plus(x, y), z) - } holds - - @induct - def zeroCommutes(x : Nat) : Boolean = { - plus(Zero(), x) == plus(x, Zero()) - } holds - - -// induction is made on first parameter -//induction on x works here! -//induction on y = stack overflow - @induct - def oneCommut(x : Nat, y : Nat) : Boolean = { - Succ(plus(x,y)) == plus(x, Succ(y)) - } holds - - @induct - def inductionStep1(x : Nat, y : Nat) : Boolean = { - plus(Succ(y),x) == Succ(plus(y,x)) - } holds - - - //we need simplification ! - //(x.isInstanceOf[Zero] ==> (plus(x, y) == plus(y, x))) this base case does not work even if it is above!! - // we do not know why this inductive proof fails - @induct - def commut(x : Nat, y : Nat) : Boolean = { - plus(x,y) == plus(y, x) - } holds -} diff --git a/testcases/verification/math/Prime.scala b/testcases/verification/math/Prime.scala deleted file mode 100644 index 1e928dcff5af0eb281f2b192bdd0a88a4cbe0fb5..0000000000000000000000000000000000000000 --- a/testcases/verification/math/Prime.scala +++ /dev/null @@ -1,54 +0,0 @@ -import leon.annotation._ - -object Prime { - // an attempt at defining isPrime in PureScala... - - // for positive numbers only - def isPrime(i : BigInt) : Boolean = { - (i >= 2 && noneDivides(2, i)) - } - - def noneDivides(start : BigInt, number : BigInt) : Boolean = { - if(start == number) { - true - } else { - !divides(start, number) && noneDivides(start + 1, number) - } - } - - // for positive numbers only - def divides(i : BigInt, j : BigInt) : Boolean = { - val result = i == j || (i < j && ((j / i) * i == j)) - result - } - - // no a problem - def allTheseArePrime() : Boolean = { - isPrime(2) && isPrime(31) && isPrime(2) && isPrime(17) && isPrime(53) - } ensuring(res => res) - - // Can't seem to get that one to work in reasonable time - // def findTwoLargePrimes(x : BigInt, y : BigInt) : Boolean = { - // x > 200 && y > x && isPrime(x) && isPrime(y) - // } ensuring(res => !res) - - // Seems to work with lucky tests only :) - def findLargePrime(x : BigInt) : Boolean = { - x > 200 && isPrime(x) - } ensuring(res => !res) - - // Just for testing. - @ignore - def main(args : Array[String]) : Unit = { - def test(n : BigInt) : Unit = { - println("Is " + n + " prime ? -> " + isPrime(n)) - } - test(119) - test(31) - test(1) - test(2) - test(0) - - println(allTheseArePrime) - } -} diff --git a/testcases/verification/math/PropositionalLogic.scala b/testcases/verification/math/PropositionalLogic.scala deleted file mode 100644 index e0acdb6fe543af05befad45198a551779e7b7d51..0000000000000000000000000000000000000000 --- a/testcases/verification/math/PropositionalLogic.scala +++ /dev/null @@ -1,93 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object PropositionalLogic { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Implies(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Literal(id: Int) extends Formula - - def size(f : Formula) : BigInt = (f match { - case And(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Or(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Implies(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Not(f) => size(f) + 1 - case _ => BigInt(1) - }) - - def simplify(f: Formula): Formula = (f match { - case And(lhs, rhs) => And(simplify(lhs), simplify(rhs)) - case Or(lhs, rhs) => Or(simplify(lhs), simplify(rhs)) - case Implies(lhs, rhs) => Or(Not(simplify(lhs)), simplify(rhs)) - case Not(f) => Not(simplify(f)) - case Literal(_) => f - }) ensuring(isSimplified(_)) - - def isSimplified(f: Formula): Boolean = f match { - case And(lhs, rhs) => isSimplified(lhs) && isSimplified(rhs) - case Or(lhs, rhs) => isSimplified(lhs) && isSimplified(rhs) - case Implies(_,_) => false - case Not(f) => isSimplified(f) - case Literal(_) => true - } - - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Implies(lhs, rhs) => Implies(nnf(lhs), nnf(rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Implies(lhs, rhs)) => And(nnf(lhs), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case Not(Literal(_)) => formula - case Literal(_) => formula - }) ensuring(res => isNNF(res) && size(res) <= 2*size(formula) - 1) - - def isNNF(f: Formula): Boolean = f match { - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Implies(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Not(Literal(_)) => true - case Not(_) => false - case Literal(_) => true - } - - def vars(f: Formula): Set[Int] = { - require(isNNF(f)) - f match { - case And(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Or(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Implies(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Not(Literal(i)) => Set[Int](i) - case Literal(i) => Set[Int](i) - } - } - - def fv(f : Formula) = { vars(nnf(f)) } - - // @induct - // def wrongCommutative(f: Formula) : Boolean = { - // nnf(simplify(f)) == simplify(nnf(f)) - // } holds - - @induct - def simplifyBreaksNNF(f: Formula) : Boolean = { - require(isNNF(f)) - isNNF(simplify(f)) - } holds - - @induct - def nnfIsStable(f: Formula) : Boolean = { - require(isNNF(f)) - nnf(f) == f - } holds - - @induct - def simplifyIsStable(f: Formula) : Boolean = { - require(isSimplified(f)) - simplify(f) == f - } holds -} diff --git a/testcases/verification/math/RationalProps.scala b/testcases/verification/math/RationalProps.scala deleted file mode 100644 index 0b13ff1aa3b665bdcfdc6fcb15180a1fa86eaa2d..0000000000000000000000000000000000000000 --- a/testcases/verification/math/RationalProps.scala +++ /dev/null @@ -1,82 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon._ - -import scala.language.postfixOps - -object RationalProps { - - def squarePos(r: Rational): Rational = { - r * r - } ensuring(_ >= Rational(0)) - - def additionIsCommutative(p: Rational, q: Rational): Boolean = { - p + q == q + p - } holds - - def multiplicationIsCommutative(p: Rational, q: Rational): Boolean = { - p * q == q * p - } holds - - def lessThanIsTransitive(p: Rational, q: Rational, r: Rational): Boolean = { - require(p < q && q < r) - p < r - } holds - - def lessEqualsIsTransitive(p: Rational, q: Rational, r: Rational): Boolean = { - require(p <= q && q <= r) - p <= r - } holds - - def greaterThanIsTransitive(p: Rational, q: Rational, r: Rational): Boolean = { - require(p > q && q > r) - p > r - } holds - - def greaterEqualsIsTransitive(p: Rational, q: Rational, r: Rational): Boolean = { - require(p >= q && q >= r) - p >= r - } holds - - def distributionMult(p: Rational, q: Rational, r: Rational): Boolean = { - (p*(q + r)) ~ (p*q + p*r) - } holds - - def reciprocalIsCorrect(p: Rational): Boolean = { - require(p.nonZero) - (p * p.reciprocal) ~ Rational(1) - } holds - - def additiveInverseIsCorrect(p: Rational): Boolean = { - (p + (-p)) ~ Rational(0) - } holds - - //should not hold because q could be 0 - def divByZero(p: Rational, q: Rational): Boolean = { - ((p / q) * q) ~ p - } holds - - def divByNonZero(p: Rational, q: Rational): Boolean = { - require(q.nonZero) - ((p / q) * q) ~ p - } holds - - - /* - * properties of equivalence - */ - - def equivalentIsReflexive(p: Rational): Boolean = { - p ~ p - } holds - - def equivalentIsSymmetric(p: Rational, q: Rational): Boolean = { - require(p ~ q) - q ~ p - } holds - - def equivalentIsTransitive(p: Rational, q: Rational, r: Rational): Boolean = { - require(p ~ q && q ~ r) - p ~ r - } holds -} diff --git a/testcases/verification/math/RealProps.scala b/testcases/verification/math/RealProps.scala deleted file mode 100644 index 0530ab97aadac7a0a1ea70ddfcfea9d2524e5ffb..0000000000000000000000000000000000000000 --- a/testcases/verification/math/RealProps.scala +++ /dev/null @@ -1,72 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon._ - -import scala.language.postfixOps - -object RealProps { - - def plusIsCommutative(a: Real, b: Real): Boolean = { - a + b == b + a - } holds - - def plusIsAssociative(a: Real, b: Real, c: Real): Boolean = { - (a + b) + c == a + (b + c) - } holds - - def timesIsCommutative(a: Real, b: Real): Boolean = { - a * b == b * a - } holds - - def timesIsAssociative(a: Real, b: Real, c: Real): Boolean = { - (a * b) * c == a * (b * c) - } holds - - def distributivity(a: Real, b: Real, c: Real): Boolean = { - a*(b + c) == a*b + a*c - } holds - - def lessEqualsTransitive(a: Real, b: Real, c: Real): Boolean = { - require(a <= b && b <= c) - a <= c - } holds - - def lessThanTransitive(a: Real, b: Real, c: Real): Boolean = { - require(a < b && b < c) - a < c - } holds - - def greaterEqualsTransitive(a: Real, b: Real, c: Real): Boolean = { - require(a >= b && b >= c) - a >= c - } holds - - def greaterThanTransitive(a: Real, b: Real, c: Real): Boolean = { - require(a > b && b > c) - a > c - } holds - - /* between any two real, there is another real */ - def density(a: Real, b: Real): Boolean = { - require(a < b) - val mid = (a + b) / Real(2) - a < mid && mid < b - } holds - - def identity1(a: Real): Boolean = { - require(a != Real(0)) - a/a == Real(1) - } holds - - def test(r: Real): Real = { - r - } ensuring(res => res >= Real(0)) - - def findRoot(r: Real): Real = { - r * r - } ensuring(res => res != Real(4)) - - //def findSqrt2(r: Real): Real = { - // r * r - //} ensuring(res => res != Real(2)) -} diff --git a/testcases/verification/monads/Counter.scala b/testcases/verification/monads/Counter.scala deleted file mode 100644 index 26991d2be1e6c2528163b88ebf9a2bdda0a412d6..0000000000000000000000000000000000000000 --- a/testcases/verification/monads/Counter.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.monads.state._ - -object Counter { - - import State._ - - def counter(init: BigInt) = { - - @inline - def tick = modify[BigInt](_ + 1) - - init >:: (for { - _ <- tick - _ <- tick - _ <- tick - r <- get - } yield r) - - } ensuring( _ == init + 3 ) -} \ No newline at end of file diff --git a/testcases/verification/monads/Freshen.scala b/testcases/verification/monads/Freshen.scala deleted file mode 100644 index 6fe0ef38f7e673f4e0f9ffbee8bbf0e7e7a5eafa..0000000000000000000000000000000000000000 --- a/testcases/verification/monads/Freshen.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.monads.state._ -import leon.lang._ - -object Freshen { - - import State._ - - case class Id(name: String, id: BigInt) - - abstract class Expr - case class EVar(id: Id) extends Expr - case class EAbs(v: Id, body: Expr) extends Expr - case class EApp(f: Expr, arg: Expr) extends Expr - - case class EState(counters: Map[String, BigInt]) - - def addVar(name: String): State[EState, Id] = for { - s <- get[EState] - newId = if (s.counters.contains(name)) s.counters(name) + 1 else BigInt(0) - _ <- put( EState(s.counters + (name -> newId) ) ) - } yield Id(name, newId) - - def freshen(e: Expr): State[EState, Expr] = e match { - case EVar(Id(name, id)) => - for { - s <- get - } yield { - val newId = if (s.counters.contains(name)) s.counters(name) else id - EVar(Id(name, newId)) - } - case EAbs(v, body) => - for { - v2 <- addVar(v.name) - body2 <- freshen(body) - } yield EAbs(v2, body2) - case EApp(f, arg) => - for { - // We need to freshen both f and arg with the initial state, - // so we save it here - init <- get - f2 <- freshen(f) - _ <- put(init) - arg2 <- freshen(arg) - } yield EApp(f2, arg2) - } - - val empty = EState(Map[String, BigInt]()) - - def freshenNames(e: Expr): Expr = empty >:: freshen(e) - -} \ No newline at end of file diff --git a/testcases/verification/monads/StackEvaluator.scala b/testcases/verification/monads/StackEvaluator.scala deleted file mode 100644 index b4dcea50f138b3a08fc79968cd387c55ae3414a1..0000000000000000000000000000000000000000 --- a/testcases/verification/monads/StackEvaluator.scala +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.monads.state._ -import leon.collection._ - -object StackEvaluator { - - import State._ - - abstract class Expr - case class Plus(e1: Expr, e2: Expr) extends Expr - case class Minus(e1: Expr, e2: Expr) extends Expr - case class UMinus(e: Expr) extends Expr - case class Lit(i: BigInt) extends Expr - - def push(i: BigInt) = State[List[BigInt], Unit]( s => ( (), i :: s) ) - def pop: State[List[BigInt], BigInt] = for { - l <- get - _ <- put(l.tailOption.getOrElse(Nil[BigInt]())) - } yield l.headOption.getOrElse(0) - - - def evalM(e: Expr): State[List[BigInt], Unit] = e match { - case Plus(e1, e2) => - for { - _ <- evalM(e1) - _ <- evalM(e2) - i2 <- pop - i1 <- pop - _ <- push(i1 + i2) - } yield(()) - case Minus(e1, e2) => - for { - _ <- evalM(e1) - _ <- evalM(e2) - i2 <- pop - i1 <- pop - _ <- push(i1 - i2) - } yield(()) - case UMinus(e) => - evalM(e) >> pop >>= (i => push(-i)) - case Lit(i) => - push(i) - } - - def eval(e: Expr): BigInt = e match { - case Plus(e1, e2) => - eval(e1) + eval(e2) - case Minus(e1, e2) => - eval(e1) - eval(e2) - case UMinus(e) => - -eval(e) - case Lit(i) => - i - } - - def empty = List[BigInt]() - - //def evalVsEval(e: Expr) = { - // evalM(e).exec(empty).head == eval(e) - //}.holds - -} diff --git a/testcases/verification/monads/TicTacToe.scala b/testcases/verification/monads/TicTacToe.scala deleted file mode 100644 index 49a8366bb3e13147f75623f2b099f885117aa365..0000000000000000000000000000000000000000 --- a/testcases/verification/monads/TicTacToe.scala +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.lang._ -import leon.monads.state._ -import leon.collection._ - -object TicTacToe { - - import State._ - - abstract class Square - case object UL extends Square - case object U extends Square - case object UR extends Square - case object L extends Square - case object C extends Square - case object R extends Square - case object DL extends Square - case object D extends Square - case object DR extends Square - - @inline - val winningSets: List[Set[Square]] = List( - Set(UL, U, UR), - Set( L, C, R), - Set(DL, D, DR), - Set(UL, L, DL), - Set( U, C, D), - Set(UR, R, DR), - Set(UR, C, DL), - Set(UL, C, DR) - ) - - @inline - def wins(sqs: Set[Square]) = winningSets exists { _ subsetOf sqs} - - case class Board(xs: Set[Square], os: Set[Square]) - case class TState(b: Board, xHasMove: Boolean) // true = X, false = O - - @inline - val init = TState(Board(Set.empty[Square], Set.empty[Square]), true) - - @inline - def legalMove(b: Board, sq: Square) = !(b.xs ++ b.os).contains(sq) - - @inline - def move(sq: Square): State[TState, Unit] = { - modify[TState] { case TState(board, xHasMove) => - TState( - if (xHasMove) - Board(board.xs ++ Set(sq), board.os) - else - Board(board.xs, board.os ++ Set(sq)), - if (legalMove(board, sq)) - !xHasMove - else - xHasMove - ) - } - } - - @inline - def play(moves: List[Square]): Option[Boolean] = { - val b = foldLeftM_ (move, moves).exec(init).b - if (wins(b.xs)) Some(true) - else if (wins(b.os)) Some(false) - else None[Boolean]() - } - - //def ex = { - // play(List(UL, UR, C, D, DR)) == Some(true) - //}.holds - - //def gameEnds(moves: List[Square], oneMore: Square) = { - // val res1 = play(moves) - // val res2 = play(moves :+ oneMore) - // res1.isDefined ==> (res1 == res2) - //}.holds -} \ No newline at end of file diff --git a/testcases/verification/proof-goals/Goals01_induct.scala b/testcases/verification/proof-goals/Goals01_induct.scala deleted file mode 100644 index a359f4e09782598403689de583a93268b00177c5..0000000000000000000000000000000000000000 --- a/testcases/verification/proof-goals/Goals01_induct.scala +++ /dev/null @@ -1,523 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object Benchmark { - -//----------------------------------------------------------------------------- -// Axioms -//----------------------------------------------------------------------------- - - sealed abstract class Nat - case class succ(pred:Nat) extends Nat - case class zero() extends Nat - def pred(n:Nat): Nat = { - require(n!=zero()) - n match { - case succ(p) => p - } - } - - sealed abstract class Lst - case class cons(head:Nat,tail:Lst) extends Lst - case class nil() extends Lst - def head(l:Lst): Nat = { - require(l!=nil()) - l match { - case cons(a,_) => a - } - } - def tail(l:Lst): Lst = { - require(l!=nil()) - l match { - case cons(_,a) => a - } - } - - sealed abstract class Pair - case class mkpair(first:Nat,second:Nat) extends Pair - def first(p:Pair): Nat = { - p match { - case mkpair(r,_) => r - } - } - def second(p:Pair): Nat = { - p match { - case mkpair(_,r) => r - } - } - - sealed abstract class ZLst - case class zcons(zhead:Pair,ztail:ZLst) extends ZLst - case class znil() extends ZLst - def zhead(l:ZLst): Pair = { - require(l!=znil()) - l match { - case zcons(a,_) => a - } - } - def ztail(l:ZLst): ZLst = { - require(l!=znil()) - l match { - case zcons(_,a) => a - } - } - - sealed abstract class Tree - case class node(data:Nat,left:Tree,right:Tree) extends Tree - case class leaf() extends Tree - def data(t:Tree): Nat = { - require(t!=leaf()) - t match { - case node(r,_,_) => r - } - } - def left(t:Tree): Tree = { - require(t!=leaf()) - t match { - case node(_,r,_) => r - } - } - def right(t:Tree): Tree = { - require(t!=leaf()) - t match { - case node(_,_,r) => r - } - } - - //def P(n:Nat): Boolean = {???} - //def f(n:Nat): Nat = {???} - - - - def less(x:Nat,y:Nat): Boolean = { - (x,y) match { - case (_,zero()) => false - case (zero(),succ(_)) => true - case (succ(a),succ(b)) => less(a,b) - } - } - - def leq(x:Nat,y:Nat): Boolean = { - x==y || less(x,y) - } - - def plus(x:Nat,y:Nat): Nat = { - (x,y) match { - case (zero(),n) => n - case (succ(n),m) => succ(plus(n,m)) - } - } - - def minus(x:Nat,y:Nat): Nat = { - (x,y) match { - case (zero(),n) => zero() - case (n,zero()) => n - case (succ(n),succ(m)) => minus(n,m) - } - } - - def mult(x:Nat,y:Nat): Nat = { - (x,y) match { - case (zero(),n) => zero() - case (succ(n),m) => plus(mult(n,m),m) - } - } - - def nmax(n:Nat,m:Nat): Nat = { - if(less(n,m)) m else n - } - - def nmin(n:Nat,m:Nat): Nat = { - if(less(n,m)) n else m - } - - def append(l1:Lst,l2:Lst): Lst = { - (l1,l2) match { - case (nil(),x) => x - case (cons(x,y),z) => cons(x,append(y,z)) - } - } - - def len(l:Lst): Nat = { - (l) match { - case (nil()) => zero() - case (cons(_,y)) => succ(len(y)) - } - } - - def drop(n:Nat,l:Lst): Lst = { - (n,l) match { - case (_,nil()) => nil() - case (zero(),x) => x - case (succ(x),cons(_,z)) => drop(x,z) - } - } - - def take(n:Nat,l:Lst): Lst = { - (n,l) match { - case (_,nil()) => nil() - case (zero(),x) => nil() - case (succ(x),cons(y,z)) => cons(y,take(x,z)) - } - } - - def count(n:Nat,l:Lst): Nat = { - (n,l) match { - case (_,nil()) => zero() - case (x,cons(y,z)) => if (x == y) succ(count(x,z)) else count(x,z) - } - } - - def last(l:Lst): Nat = { - (l) match { - case (nil()) => zero() - case (cons(x,y)) => if (y==nil()) x else last(y) - } - } - - def butlast(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => if (y==nil()) nil() else cons(x,butlast(y)) - } - } - - def mem(n:Nat,l:Lst): Boolean = { - (n,l) match { - case (_,nil()) => false - case (x,cons(y,z)) => (x==y) || (mem(x,z)) - } - } - - def delete(n:Nat,l:Lst): Lst = { - (n,l) match { - case (_,nil()) => nil() - case (x,cons(y,z)) => if (x==y) delete(x,z) else cons(y,delete(x,z)) - } - } - - def rev(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => append(rev(y),cons(x,nil())) - } - } -/* - def lmap(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => cons(f(x),lmap(y)) - } - } - - def filter(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => if(P(x)) cons(x,filter(y)) else filter(y) - } - } - - def dropWhile(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => if(P(x)) dropWhile(y) else cons(x,y) - } - } - - def takeWhile(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => if(P(x)) cons(x,takeWhile(y)) else nil() - } - } -*/ - def ins1(n:Nat,l:Lst): Lst = { - (n,l) match { - case (i,nil()) => cons(i,nil()) - case (i,cons(x,y)) => if (i==x) cons(x,y) else cons(x,ins1(i,y)) - } - } - - def insort(n:Nat,l:Lst): Lst = { - (n,l) match { - case (i,nil()) => cons(i,nil()) - case (i,cons(x,y)) => if (less(i,x)) cons(i,cons(x,y)) else cons(x,insort(i,y)) - } - } - - def sorted(l:Lst): Boolean = { - (l) match { - case (nil()) => true - case (cons(_,nil())) => true - case (cons(x,cons(z,y))) => sorted(cons(z,y)) && leq(x,z) - } - } - - def sort(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => insort(x,sort(y)) - } - } - - def zip(l1:Lst,l2:Lst): ZLst = { - (l1,l2) match { - case (nil(),_) => znil() - case (_,nil()) => znil() - case (cons(x,y),cons(z,w)) => zcons(mkpair(x,z),zip(y,w)) - } - } - - def zappend(l1:ZLst,l2:ZLst): ZLst = { - (l1,l2) match { - case (znil(),x) => x - case (zcons(x,y),z) => zcons(x,zappend(y,z)) - } - } - - def zdrop(n:Nat,l:ZLst): ZLst = { - (n,l) match { - case (_,znil()) => znil() - case (zero(),x) => x - case (succ(x),zcons(_,z)) => zdrop(x,z) - } - } - - def ztake(n:Nat,l:ZLst): ZLst = { - (n,l) match { - case (_,znil()) => znil() - case (zero(),_) => znil() - case (succ(x),zcons(y,z)) => zcons(y,ztake(x,z)) - } - } - - def zrev(l:ZLst): ZLst = { - (l) match { - case (znil()) => znil() - case (zcons(x,y)) => zappend(zrev(y),zcons(x,znil())) - } - } - - def mirror(t:Tree): Tree = { - (t) match { - case (leaf()) => leaf() - case (node(x,y,z)) => node(x,mirror(z),mirror(y)) - } - } - - def height(t:Tree): Nat = { - (t) match { - case (leaf()) => zero() - case (node(x,y,z)) => succ(nmax(height(y),height(z))) - } - } - - - - -//----------------------------------------------------------------------------- -// GOALS -//----------------------------------------------------------------------------- - -@induct -def G1(n:Nat, xs:Lst): Boolean = { (append(take(n, xs), drop(n, xs)) == xs) }.holds -@induct -def G2(n:Nat, l:Lst, m:Lst): Boolean = { (plus(count(n, l), count(n, m)) == count(n, append(l, m))) }.holds -@induct -def G3(n:Nat, l:Lst, m:Lst): Boolean = { leq(count(n, l), count(n, append(l, m))) }.holds -@induct -def G4(n:Nat, l:Lst): Boolean = { (plus(succ(zero()), count(n, l)) == count(n, cons(n, l))) }.holds -@induct -def G5(n:Nat, x:Nat, l:Lst): Boolean = { (!(n == x) || (plus(succ(zero()), count(n, l)) == count(n, cons(x, l)))) }.holds -@induct -def G6(n:Nat, m:Nat): Boolean = { (minus(n, plus(n, m)) == zero()) }.holds -@induct -def G7(n:Nat, m:Nat): Boolean = { (minus(plus(n, m), n) == m) }.holds -@induct -def G8(k:Nat, n:Nat, m:Nat): Boolean = { (minus(plus(k, m), plus(k, n)) == minus(m, n)) }.holds -@induct -def G9(i:Nat, j:Nat, k:Nat): Boolean = { (minus(minus(i, j), k) == minus(i, plus(j, k))) }.holds -@induct -def G10(m:Nat): Boolean = { (minus(m, m) == zero()) }.holds -@induct -def G11(xs:Lst): Boolean = { (drop(zero(), xs) == xs) }.holds - //def G12(n:Nat, xs:Lst): Boolean = { (drop(n, lmap(xs)) == lmap(drop(n, xs))) }.holds -@induct -def G13(n:Nat, x:Nat, xs:Lst): Boolean = { (drop(succ(n), cons(x, xs)) == drop(n, xs)) }.holds - //def G14(xs:Lst, ys:Lst): Boolean = { (filter(append(xs, ys)) == append(filter(xs), filter(ys))) }.holds -@induct -def G15(x:Nat, l:Lst): Boolean = { (len(insort(x, l)) == succ(len(l))) }.holds -@induct -def G16(xs:Lst, x:Nat): Boolean = { (!(xs == nil()) || (last(cons(x, xs)) == x)) }.holds -@induct -def G17(n:Nat): Boolean = { (leq(n, zero()) == (n == zero())) }.holds -@induct -def G18(i:Nat, m:Nat): Boolean = { less(i, succ(plus(i, m))) }.holds -@induct -def G19(n:Nat, xs:Lst): Boolean = { (len(drop(n, xs)) == minus(len(xs), n)) }.holds -@induct -def G20(l:Lst): Boolean = { (len(sort(l)) == len(l)) }.holds -@induct -def G21(n:Nat, m:Nat): Boolean = { leq(n, plus(n, m)) }.holds -@induct -def G22(a:Nat, b:Nat, c:Nat): Boolean = { (nmax(nmax(a, b), c) == nmax(a, nmax(b, c))) }.holds -@induct -def G23(a:Nat, b:Nat): Boolean = { (nmax(a, b) == nmax(b, a)) }.holds -@induct -def G24(a:Nat, b:Nat): Boolean = { ((nmax(a, b) == a) == leq(b, a)) }.holds -@induct -def G25(a:Nat, b:Nat): Boolean = { ((nmax(a, b) == b) == leq(a, b)) }.holds -@induct -def G26(x:Nat, l:Lst, t:Lst): Boolean = { (!mem(x, l) || mem(x, append(l, t))) }.holds -@induct -def G27(x:Nat, l:Lst, t:Lst): Boolean = { (!mem(x, t) || mem(x, append(l, t))) }.holds -@induct -def G28(x:Nat, l:Lst): Boolean = { mem(x, append(l, cons(x, nil()))) }.holds -@induct -def G29(x:Nat, l:Lst): Boolean = { mem(x, ins1(x, l)) }.holds -@induct -def G30(x:Nat, l:Lst): Boolean = { mem(x, insort(x, l)) }.holds -@induct -def G31(a:Nat, b:Nat, c:Nat): Boolean = { (nmin(nmin(a, b), c) == nmin(a, nmin(b, c))) }.holds -@induct -def G32(a:Nat, b:Nat): Boolean = { (nmin(a, b) == nmin(b, a)) }.holds -@induct -def G33(a:Nat, b:Nat): Boolean = { ((nmin(a, b) == a) == leq(a, b)) }.holds -@induct -def G34(a:Nat, b:Nat): Boolean = { ((nmin(a, b) == b) == leq(b, a)) }.holds - //def G35(xs:Lst): Boolean = { (!(???) || (dropWhile(xs) == xs)) }.holds - //def G36(xs:Lst): Boolean = { (!(???) || (takeWhile(xs) == xs)) }.holds -@induct -def G37(x:Nat, l:Lst): Boolean = { (!mem(x, delete(x, l))) }.holds -@induct -def G38(n:Nat, x:Lst): Boolean = { (count(n, append(x, cons(n, nil()))) == succ(count(n, x))) }.holds -@induct -def G39(n:Nat, h:Nat, t:Lst): Boolean = { (plus(count(n, cons(h, nil())), count(n, t)) == count(n, cons(h, t))) }.holds -@induct -def G40(xs:Lst): Boolean = { (take(zero(), xs) == nil()) }.holds - //def G41(n:Nat, xs:Lst): Boolean = { (take(n, lmap(xs)) == lmap(take(n, xs))) }.holds -@induct -def G42(n:Nat, x:Nat, xs:Lst): Boolean = { (take(succ(n), cons(x, xs)) == cons(x, take(n, xs))) }.holds - //def G43(xs:Lst): Boolean = { (append(takeWhile(xs), dropWhile(xs)) == xs) }.holds -@induct -def G44(x:Nat, xs:Lst, ys:Lst): Boolean = { (zip(cons(x, xs), ys) == (if ((ys == nil())) znil() else zcons(mkpair(x, head(ys)), zip(xs, tail(ys))))) }.holds -@induct -def G45(x:Nat, xs:Lst, y:Nat, ys:Lst): Boolean = { (zip(cons(x, xs), cons(y, ys)) == zcons(mkpair(x, y), zip(xs, ys))) }.holds -@induct -def G46(ys:Lst): Boolean = { (zip(nil(), ys) == znil()) }.holds -@induct -def G47(a:Tree): Boolean = { (height(mirror(a)) == height(a)) }.holds -@induct -def G48(xs:Lst): Boolean = { (xs == nil() || (butlast(append(xs, cons(last(xs), nil()))) == xs)) }.holds -@induct -def G49(xs:Lst, ys:Lst): Boolean = { (butlast(append(xs, ys)) == (if ((ys == nil())) butlast(xs) else append(xs, butlast(ys)))) }.holds -@induct -def G50(xs:Lst): Boolean = { (butlast(xs) == take(minus(len(xs), succ(zero())), xs)) }.holds -@induct -def G51(xs:Lst, x:Nat): Boolean = { (butlast(append(xs, cons(x, nil()))) == xs) }.holds -@induct -def G52(n:Nat, l:Lst): Boolean = { (count(n, l) == count(n, rev(l))) }.holds -@induct -def G53(x:Nat, l:Lst): Boolean = { (count(x, l) == count(x, sort(l))) }.holds -@induct -def G54(m:Nat, n:Nat): Boolean = { (minus(plus(m, n), n) == m) }.holds -@induct -def G55(i:Nat, j:Nat, k:Nat): Boolean = { (minus(minus(i, j), k) == minus(minus(i, k), j)) }.holds -@induct -def G56(n:Nat, xs:Lst, ys:Lst): Boolean = { (drop(n, append(xs, ys)) == append(drop(n, xs), drop(minus(n, len(xs)), ys))) }.holds -@induct -def G57(n:Nat, m:Nat, xs:Lst): Boolean = { (drop(n, drop(m, xs)) == drop(plus(n, m), xs)) }.holds -@induct -def G58(n:Nat, m:Nat, xs:Lst): Boolean = { (drop(n, take(m, xs)) == take(minus(m, n), drop(n, xs))) }.holds -@induct -def G59(n:Nat, xs:Lst, ys:Lst): Boolean = { (zdrop(n, zip(xs, ys)) == zip(drop(n, xs), drop(n, ys))) }.holds -@induct -def G60(xs:Lst, ys:Lst): Boolean = { (!(ys == nil()) || (last(append(xs, ys)) == last(xs))) }.holds -@induct -def G61(xs:Lst, ys:Lst): Boolean = { (ys == nil() || (last(append(xs, ys)) == last(ys))) }.holds -@induct -def G62(xs:Lst, ys:Lst): Boolean = { (last(append(xs, ys)) == (if ((ys == nil())) last(xs) else last(ys))) }.holds -@induct -def G63(x:Nat, xs:Lst): Boolean = { (xs == nil() || (last(cons(x, xs)) == last(xs))) }.holds -@induct -def G64(n:Nat, xs:Lst): Boolean = { (!less(n, len(xs)) || (last(drop(n, xs)) == last(xs))) }.holds -@induct -def G65(x:Nat, xs:Lst): Boolean = { (last(append(xs, cons(x, nil()))) == x) }.holds -@induct -def G66(i:Nat, m:Nat): Boolean = { less(i, succ(plus(m, i))) }.holds - //def G67(xs:Lst): Boolean = { leq(len(filter(xs)), len(xs)) }.holds -@induct -def G68(xs:Lst): Boolean = { (len(butlast(xs)) == minus(len(xs), succ(zero()))) }.holds -@induct -def G69(x:Nat, l:Lst): Boolean = { leq(len(delete(x, l)), len(l)) }.holds -@induct -def G70(n:Nat, m:Nat): Boolean = { leq(n, plus(m, n)) }.holds -@induct -def G71(n:Nat, m:Nat): Boolean = { (!leq(m, n) || leq(m, succ(n))) }.holds -@induct -def G72(x:Nat, y:Nat, l:Lst): Boolean = { (!less(x, y) || (mem(x, insort(y, l)) == mem(x, l))) }.holds -@induct -def G73(x:Nat, y:Nat, l:Lst): Boolean = { (x == y || (mem(x, insort(y, l)) == mem(x, l))) }.holds -@induct -def G74(i:Nat, xs:Lst): Boolean = { (rev(drop(i, xs)) == take(minus(len(xs), i), rev(xs))) }.holds - //def G75(xs:Lst): Boolean = { (rev(filter(xs)) == filter(rev(xs))) }.holds -@induct -def G76(i:Nat, xs:Lst): Boolean = { (rev(take(i, xs)) == drop(minus(len(xs), i), rev(xs))) }.holds -@induct -def G77(n:Nat, h:Nat, x:Lst): Boolean = { (n == h || (count(n, append(x, cons(h, nil()))) == count(n, x))) }.holds -@induct -def G78(n:Nat, h:Nat, t:Lst): Boolean = { (plus(count(n, t), count(n, cons(h, nil()))) == count(n, cons(h, t))) }.holds -@induct -def G79(x:Nat, l:Lst): Boolean = { (!sorted(l) || sorted(insort(x, l))) }.holds -@induct -def G80(l:Lst): Boolean = { sorted(sort(l)) }.holds -@induct -def G81(m:Nat, n:Nat, k:Nat): Boolean = { (minus(minus(succ(m), n), succ(k)) == minus(minus(m, n), k)) }.holds -@induct -def G82(n:Nat, xs:Lst, ys:Lst): Boolean = { (take(n, append(xs, ys)) == append(take(n, xs), take(minus(n, len(xs)), ys))) }.holds -@induct -def G83(n:Nat, m:Nat, xs:Lst): Boolean = { (take(n, drop(m, xs)) == drop(m, take(plus(n, m), xs))) }.holds -@induct -def G84(n:Nat, xs:Lst, ys:Lst): Boolean = { (ztake(n, zip(xs, ys)) == zip(take(n, xs), take(n, ys))) }.holds -@induct -def G85(xs:Lst, ys:Lst, zs:Lst): Boolean = { (zip(append(xs, ys), zs) == zappend(zip(xs, take(len(xs), zs)), zip(ys, drop(len(xs), zs)))) }.holds -@induct -def G86(xs:Lst, ys:Lst, zs:Lst): Boolean = { (zip(xs, append(ys, zs)) == zappend(zip(take(len(ys), xs), ys), zip(drop(len(ys), xs), zs))) }.holds -@induct -def G87(xs:Lst, ys:Lst): Boolean = { (!(len(xs) == len(ys)) || (zip(rev(xs), rev(ys)) == zrev(zip(xs, ys)))) }.holds - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/testcases/verification/proof-goals/Goals01_noinduct.scala b/testcases/verification/proof-goals/Goals01_noinduct.scala deleted file mode 100644 index d13624a4fe6e85fdaecbdb41f7497effad920964..0000000000000000000000000000000000000000 --- a/testcases/verification/proof-goals/Goals01_noinduct.scala +++ /dev/null @@ -1,444 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object Benchmark { - -//----------------------------------------------------------------------------- -// Axioms -//----------------------------------------------------------------------------- - - sealed abstract class Nat - case class succ(pred:Nat) extends Nat - case class zero() extends Nat - def pred(n:Nat): Nat = { - require(n!=zero()) - n match { - case succ(p) => p - } - } - - sealed abstract class Lst - case class cons(head:Nat,tail:Lst) extends Lst - case class nil() extends Lst - def head(l:Lst): Nat = { - require(l!=nil()) - l match { - case cons(a,_) => a - } - } - def tail(l:Lst): Lst = { - require(l!=nil()) - l match { - case cons(_,a) => a - } - } - - sealed abstract class Pair - case class mkpair(first:Nat,second:Nat) extends Pair - def first(p:Pair): Nat = { - p match { - case mkpair(r,_) => r - } - } - def second(p:Pair): Nat = { - p match { - case mkpair(_,r) => r - } - } - - sealed abstract class ZLst - case class zcons(zhead:Pair,ztail:ZLst) extends ZLst - case class znil() extends ZLst - def zhead(l:ZLst): Pair = { - require(l!=znil()) - l match { - case zcons(a,_) => a - } - } - def ztail(l:ZLst): ZLst = { - require(l!=znil()) - l match { - case zcons(_,a) => a - } - } - - sealed abstract class Tree - case class node(data:Nat,left:Tree,right:Tree) extends Tree - case class leaf() extends Tree - def data(t:Tree): Nat = { - require(t!=leaf()) - t match { - case node(r,_,_) => r - } - } - def left(t:Tree): Tree = { - require(t!=leaf()) - t match { - case node(_,r,_) => r - } - } - def right(t:Tree): Tree = { - require(t!=leaf()) - t match { - case node(_,_,r) => r - } - } - - //def P(n:Nat): Boolean = {???} - //def f(n:Nat): Nat = {???} - - - - def less(x:Nat,y:Nat): Boolean = { - (x,y) match { - case (_,zero()) => false - case (zero(),succ(_)) => true - case (succ(a),succ(b)) => less(a,b) - } - } - - def leq(x:Nat,y:Nat): Boolean = { - x==y || less(x,y) - } - - def plus(x:Nat,y:Nat): Nat = { - (x,y) match { - case (zero(),n) => n - case (succ(n),m) => succ(plus(n,m)) - } - } - - def minus(x:Nat,y:Nat): Nat = { - (x,y) match { - case (zero(),n) => zero() - case (n,zero()) => n - case (succ(n),succ(m)) => minus(n,m) - } - } - - def mult(x:Nat,y:Nat): Nat = { - (x,y) match { - case (zero(),n) => zero() - case (succ(n),m) => plus(mult(n,m),m) - } - } - - def nmax(n:Nat,m:Nat): Nat = { - if(less(n,m)) m else n - } - - def nmin(n:Nat,m:Nat): Nat = { - if(less(n,m)) n else m - } - - def append(l1:Lst,l2:Lst): Lst = { - (l1,l2) match { - case (nil(),x) => x - case (cons(x,y),z) => cons(x,append(y,z)) - } - } - - def len(l:Lst): Nat = { - (l) match { - case (nil()) => zero() - case (cons(_,y)) => succ(len(y)) - } - } - - def drop(n:Nat,l:Lst): Lst = { - (n,l) match { - case (_,nil()) => nil() - case (zero(),x) => x - case (succ(x),cons(_,z)) => drop(x,z) - } - } - - def take(n:Nat,l:Lst): Lst = { - (n,l) match { - case (_,nil()) => nil() - case (zero(),x) => nil() - case (succ(x),cons(y,z)) => cons(y,take(x,z)) - } - } - - def count(n:Nat,l:Lst): Nat = { - (n,l) match { - case (_,nil()) => zero() - case (x,cons(y,z)) => if (x == y) succ(count(x,z)) else count(x,z) - } - } - - def last(l:Lst): Nat = { - (l) match { - case (nil()) => zero() - case (cons(x,y)) => if (y==nil()) x else last(y) - } - } - - def butlast(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => if (y==nil()) nil() else cons(x,butlast(y)) - } - } - - def mem(n:Nat,l:Lst): Boolean = { - (n,l) match { - case (_,nil()) => false - case (x,cons(y,z)) => (x==y) || (mem(x,z)) - } - } - - def delete(n:Nat,l:Lst): Lst = { - (n,l) match { - case (_,nil()) => nil() - case (x,cons(y,z)) => if (x==y) delete(x,z) else cons(y,delete(x,z)) - } - } - - def rev(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => append(rev(y),cons(x,nil())) - } - } -/* - def lmap(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => cons(f(x),lmap(y)) - } - } - - def filter(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => if(P(x)) cons(x,filter(y)) else filter(y) - } - } - - def dropWhile(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => if(P(x)) dropWhile(y) else cons(x,y) - } - } - - def takeWhile(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => if(P(x)) cons(x,takeWhile(y)) else nil() - } - } -*/ - def ins1(n:Nat,l:Lst): Lst = { - (n,l) match { - case (i,nil()) => cons(i,nil()) - case (i,cons(x,y)) => if (i==x) cons(x,y) else cons(x,ins1(i,y)) - } - } - - def insort(n:Nat,l:Lst): Lst = { - (n,l) match { - case (i,nil()) => cons(i,nil()) - case (i,cons(x,y)) => if (less(i,x)) cons(i,cons(x,y)) else cons(x,insort(i,y)) - } - } - - def sorted(l:Lst): Boolean = { - (l) match { - case (nil()) => true - case (cons(_,nil())) => true - case (cons(x,cons(z,y))) => sorted(cons(z,y)) && leq(x,z) - } - } - - def sort(l:Lst): Lst = { - (l) match { - case (nil()) => nil() - case (cons(x,y)) => insort(x,sort(y)) - } - } - - def zip(l1:Lst,l2:Lst): ZLst = { - (l1,l2) match { - case (nil(),_) => znil() - case (_,nil()) => znil() - case (cons(x,y),cons(z,w)) => zcons(mkpair(x,z),zip(y,w)) - } - } - - def zappend(l1:ZLst,l2:ZLst): ZLst = { - (l1,l2) match { - case (znil(),x) => x - case (zcons(x,y),z) => zcons(x,zappend(y,z)) - } - } - - def zdrop(n:Nat,l:ZLst): ZLst = { - (n,l) match { - case (_,znil()) => znil() - case (zero(),x) => x - case (succ(x),zcons(_,z)) => zdrop(x,z) - } - } - - def ztake(n:Nat,l:ZLst): ZLst = { - (n,l) match { - case (_,znil()) => znil() - case (zero(),_) => znil() - case (succ(x),zcons(y,z)) => zcons(y,ztake(x,z)) - } - } - - def zrev(l:ZLst): ZLst = { - (l) match { - case (znil()) => znil() - case (zcons(x,y)) => zappend(zrev(y),zcons(x,znil())) - } - } - - def mirror(t:Tree): Tree = { - (t) match { - case (leaf()) => leaf() - case (node(x,y,z)) => node(x,mirror(z),mirror(y)) - } - } - - def height(t:Tree): Nat = { - (t) match { - case (leaf()) => zero() - case (node(x,y,z)) => succ(nmax(height(y),height(z))) - } - } - - - - -//----------------------------------------------------------------------------- -// GOALS -//----------------------------------------------------------------------------- - -def G1(n:Nat, xs:Lst): Boolean = { (append(take(n, xs), drop(n, xs)) == xs) }.holds -def G2(n:Nat, l:Lst, m:Lst): Boolean = { (plus(count(n, l), count(n, m)) == count(n, append(l, m))) }.holds -def G3(n:Nat, l:Lst, m:Lst): Boolean = { leq(count(n, l), count(n, append(l, m))) }.holds -def G4(n:Nat, l:Lst): Boolean = { (plus(succ(zero()), count(n, l)) == count(n, cons(n, l))) }.holds -def G5(n:Nat, x:Nat, l:Lst): Boolean = { (!(n == x) || (plus(succ(zero()), count(n, l)) == count(n, cons(x, l)))) }.holds -def G6(n:Nat, m:Nat): Boolean = { (minus(n, plus(n, m)) == zero()) }.holds -def G7(n:Nat, m:Nat): Boolean = { (minus(plus(n, m), n) == m) }.holds -def G8(k:Nat, n:Nat, m:Nat): Boolean = { (minus(plus(k, m), plus(k, n)) == minus(m, n)) }.holds -def G9(i:Nat, j:Nat, k:Nat): Boolean = { (minus(minus(i, j), k) == minus(i, plus(j, k))) }.holds -def G10(m:Nat): Boolean = { (minus(m, m) == zero()) }.holds -def G11(xs:Lst): Boolean = { (drop(zero(), xs) == xs) }.holds - //def G12(n:Nat, xs:Lst): Boolean = { (drop(n, lmap(xs)) == lmap(drop(n, xs))) }.holds -def G13(n:Nat, x:Nat, xs:Lst): Boolean = { (drop(succ(n), cons(x, xs)) == drop(n, xs)) }.holds - //def G14(xs:Lst, ys:Lst): Boolean = { (filter(append(xs, ys)) == append(filter(xs), filter(ys))) }.holds -def G15(x:Nat, l:Lst): Boolean = { (len(insort(x, l)) == succ(len(l))) }.holds -def G16(xs:Lst, x:Nat): Boolean = { (!(xs == nil()) || (last(cons(x, xs)) == x)) }.holds -def G17(n:Nat): Boolean = { (leq(n, zero()) == (n == zero())) }.holds -def G18(i:Nat, m:Nat): Boolean = { less(i, succ(plus(i, m))) }.holds -def G19(n:Nat, xs:Lst): Boolean = { (len(drop(n, xs)) == minus(len(xs), n)) }.holds -def G20(l:Lst): Boolean = { (len(sort(l)) == len(l)) }.holds -def G21(n:Nat, m:Nat): Boolean = { leq(n, plus(n, m)) }.holds -def G22(a:Nat, b:Nat, c:Nat): Boolean = { (nmax(nmax(a, b), c) == nmax(a, nmax(b, c))) }.holds -def G23(a:Nat, b:Nat): Boolean = { (nmax(a, b) == nmax(b, a)) }.holds -def G24(a:Nat, b:Nat): Boolean = { ((nmax(a, b) == a) == leq(b, a)) }.holds -def G25(a:Nat, b:Nat): Boolean = { ((nmax(a, b) == b) == leq(a, b)) }.holds -def G26(x:Nat, l:Lst, t:Lst): Boolean = { (!mem(x, l) || mem(x, append(l, t))) }.holds -def G27(x:Nat, l:Lst, t:Lst): Boolean = { (!mem(x, t) || mem(x, append(l, t))) }.holds -def G28(x:Nat, l:Lst): Boolean = { mem(x, append(l, cons(x, nil()))) }.holds -def G29(x:Nat, l:Lst): Boolean = { mem(x, ins1(x, l)) }.holds -def G30(x:Nat, l:Lst): Boolean = { mem(x, insort(x, l)) }.holds -def G31(a:Nat, b:Nat, c:Nat): Boolean = { (nmin(nmin(a, b), c) == nmin(a, nmin(b, c))) }.holds -def G32(a:Nat, b:Nat): Boolean = { (nmin(a, b) == nmin(b, a)) }.holds -def G33(a:Nat, b:Nat): Boolean = { ((nmin(a, b) == a) == leq(a, b)) }.holds -def G34(a:Nat, b:Nat): Boolean = { ((nmin(a, b) == b) == leq(b, a)) }.holds - //def G35(xs:Lst): Boolean = { (!(???) || (dropWhile(xs) == xs)) }.holds - //def G36(xs:Lst): Boolean = { (!(???) || (takeWhile(xs) == xs)) }.holds -def G37(x:Nat, l:Lst): Boolean = { (!mem(x, delete(x, l))) }.holds -def G38(n:Nat, x:Lst): Boolean = { (count(n, append(x, cons(n, nil()))) == succ(count(n, x))) }.holds -def G39(n:Nat, h:Nat, t:Lst): Boolean = { (plus(count(n, cons(h, nil())), count(n, t)) == count(n, cons(h, t))) }.holds -def G40(xs:Lst): Boolean = { (take(zero(), xs) == nil()) }.holds - //def G41(n:Nat, xs:Lst): Boolean = { (take(n, lmap(xs)) == lmap(take(n, xs))) }.holds -def G42(n:Nat, x:Nat, xs:Lst): Boolean = { (take(succ(n), cons(x, xs)) == cons(x, take(n, xs))) }.holds - //def G43(xs:Lst): Boolean = { (append(takeWhile(xs), dropWhile(xs)) == xs) }.holds -def G44(x:Nat, xs:Lst, ys:Lst): Boolean = { (zip(cons(x, xs), ys) == (if ((ys == nil())) znil() else zcons(mkpair(x, head(ys)), zip(xs, tail(ys))))) }.holds//73 (74-75) -def G45(x:Nat, xs:Lst, y:Nat, ys:Lst): Boolean = { (zip(cons(x, xs), cons(y, ys)) == zcons(mkpair(x, y), zip(xs, ys))) }.holds -def G46(ys:Lst): Boolean = { (zip(nil(), ys) == znil()) }.holds -def G47(a:Tree): Boolean = { (height(mirror(a)) == height(a)) }.holds -def G48(xs:Lst): Boolean = { (xs == nil() || (butlast(append(xs, cons(last(xs), nil()))) == xs)) }.holds -def G49(xs:Lst, ys:Lst): Boolean = { (butlast(append(xs, ys)) == (if ((ys == nil())) butlast(xs) else append(xs, butlast(ys)))) }.holds -def G50(xs:Lst): Boolean = { (butlast(xs) == take(minus(len(xs), succ(zero())), xs)) }.holds -def G51(xs:Lst, x:Nat): Boolean = { (butlast(append(xs, cons(x, nil()))) == xs) }.holds -def G52(n:Nat, l:Lst): Boolean = { (count(n, l) == count(n, rev(l))) }.holds -def G53(x:Nat, l:Lst): Boolean = { (count(x, l) == count(x, sort(l))) }.holds -def G54(m:Nat, n:Nat): Boolean = { (minus(plus(m, n), n) == m) }.holds -def G55(i:Nat, j:Nat, k:Nat): Boolean = { (minus(minus(i, j), k) == minus(minus(i, k), j)) }.holds -def G56(n:Nat, xs:Lst, ys:Lst): Boolean = { (drop(n, append(xs, ys)) == append(drop(n, xs), drop(minus(n, len(xs)), ys))) }.holds -def G57(n:Nat, m:Nat, xs:Lst): Boolean = { (drop(n, drop(m, xs)) == drop(plus(n, m), xs)) }.holds -def G58(n:Nat, m:Nat, xs:Lst): Boolean = { (drop(n, take(m, xs)) == take(minus(m, n), drop(n, xs))) }.holds -def G59(n:Nat, xs:Lst, ys:Lst): Boolean = { (zdrop(n, zip(xs, ys)) == zip(drop(n, xs), drop(n, ys))) }.holds -def G60(xs:Lst, ys:Lst): Boolean = { (!(ys == nil()) || (last(append(xs, ys)) == last(xs))) }.holds -def G61(xs:Lst, ys:Lst): Boolean = { (ys == nil() || (last(append(xs, ys)) == last(ys))) }.holds -def G62(xs:Lst, ys:Lst): Boolean = { (last(append(xs, ys)) == (if ((ys == nil())) last(xs) else last(ys))) }.holds -def G63(x:Nat, xs:Lst): Boolean = { (xs == nil() || (last(cons(x, xs)) == last(xs))) }.holds -def G64(n:Nat, xs:Lst): Boolean = { (!less(n, len(xs)) || (last(drop(n, xs)) == last(xs))) }.holds -def G65(x:Nat, xs:Lst): Boolean = { (last(append(xs, cons(x, nil()))) == x) }.holds -def G66(i:Nat, m:Nat): Boolean = { less(i, succ(plus(m, i))) }.holds - //def G67(xs:Lst): Boolean = { leq(len(filter(xs)), len(xs)) }.holds -def G68(xs:Lst): Boolean = { (len(butlast(xs)) == minus(len(xs), succ(zero()))) }.holds -def G69(x:Nat, l:Lst): Boolean = { leq(len(delete(x, l)), len(l)) }.holds -def G70(n:Nat, m:Nat): Boolean = { leq(n, plus(m, n)) }.holds -def G71(n:Nat, m:Nat): Boolean = { (!leq(m, n) || leq(m, succ(n))) }.holds -def G72(x:Nat, y:Nat, l:Lst): Boolean = { (!less(x, y) || (mem(x, insort(y, l)) == mem(x, l))) }.holds -def G73(x:Nat, y:Nat, l:Lst): Boolean = { (x == y || (mem(x, insort(y, l)) == mem(x, l))) }.holds -def G74(i:Nat, xs:Lst): Boolean = { (rev(drop(i, xs)) == take(minus(len(xs), i), rev(xs))) }.holds - //def G75(xs:Lst): Boolean = { (rev(filter(xs)) == filter(rev(xs))) }.holds -def G76(i:Nat, xs:Lst): Boolean = { (rev(take(i, xs)) == drop(minus(len(xs), i), rev(xs))) }.holds -def G77(n:Nat, h:Nat, x:Lst): Boolean = { (n == h || (count(n, append(x, cons(h, nil()))) == count(n, x))) }.holds -def G78(n:Nat, h:Nat, t:Lst): Boolean = { (plus(count(n, t), count(n, cons(h, nil()))) == count(n, cons(h, t))) }.holds -def G79(x:Nat, l:Lst): Boolean = { (!sorted(l) || sorted(insort(x, l))) }.holds -def G80(l:Lst): Boolean = { sorted(sort(l)) }.holds -def G81(m:Nat, n:Nat, k:Nat): Boolean = { (minus(minus(succ(m), n), succ(k)) == minus(minus(m, n), k)) }.holds -def G82(n:Nat, xs:Lst, ys:Lst): Boolean = { (take(n, append(xs, ys)) == append(take(n, xs), take(minus(n, len(xs)), ys))) }.holds -def G83(n:Nat, m:Nat, xs:Lst): Boolean = { (take(n, drop(m, xs)) == drop(m, take(plus(n, m), xs))) }.holds -def G84(n:Nat, xs:Lst, ys:Lst): Boolean = { (ztake(n, zip(xs, ys)) == zip(take(n, xs), take(n, ys))) }.holds -def G85(xs:Lst, ys:Lst, zs:Lst): Boolean = { (zip(append(xs, ys), zs) == zappend(zip(xs, take(len(xs), zs)), zip(ys, drop(len(xs), zs)))) }.holds -def G86(xs:Lst, ys:Lst, zs:Lst): Boolean = { (zip(xs, append(ys, zs)) == zappend(zip(take(len(ys), xs), ys), zip(drop(len(ys), xs), zs))) }.holds -def G87(xs:Lst, ys:Lst): Boolean = { (!(len(xs) == len(ys)) || (zip(rev(xs), rev(ys)) == zrev(zip(xs, ys)))) }.holds - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/testcases/verification/proof/Exponential.scala b/testcases/verification/proof/Exponential.scala deleted file mode 100644 index d4bd7d61856dc5c49537b745f1263cb9319b20ce..0000000000000000000000000000000000000000 --- a/testcases/verification/proof/Exponential.scala +++ /dev/null @@ -1,205 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.testcases.verification.proof - -import leon.annotation._ -import leon.lang._ -import leon.proof._ - -object Exponential { - - /** A simple, but slow function for computing exponentials. */ - def exp(x: BigInt, y: BigInt): BigInt = { - require(y >= 0) - if (x == 0) 0 - else if (y == 0) 1 - else x * exp(x, y - 1) - } - - /** Exponentials of positive numbers are positive. */ - def positive(x: BigInt, y: BigInt): Boolean = { - require(y >= 0 && x >= 0) - exp(x, y) >= 0 because { - if (x == 0) trivial - else if (y == 0) trivial - else check { - x * exp(x, y - 1) >= 0 because positive(x, y - 1) - } - } - }.holds - - /** The exponential function is positive (shorter proof). */ - def positiveShort(x: BigInt, y: BigInt): Boolean = { - require(y >= 0 && x > 0) - exp(x, y) >= 0 because { - if (x == 0) trivial - else if (y == 0) trivial - else positiveShort(x, y - 1) - } - }.holds - - /** - * The exponential function (with respect to a fixed base) is a - * homomorphism between the commutative monoids of addition and - * multiplication over integers. - */ - def monoidHom(x: BigInt, y: BigInt, z: BigInt): Boolean = { - require(y >= 0 && z >= 0) - exp(x, y + z) == exp(x, y) * exp(x, z) because { - if (x == 0) trivial - else if (y == 0) trivial - else { - exp(x, y + z) ==| (y + z != 0) | - x * exp(x, y + z - 1) ==| monoidHom(x, y - 1, z) | - x * exp(x, y - 1) * exp(x, z) - }.qed - } - }.holds - - /** - * Exponentiation (by a fixed exponent) commutes with - * multiplication. - */ - def expMultCommute(x: BigInt, y: BigInt, z: BigInt): Boolean = { - require(z >= 0) - exp(x * y, z) == exp(x, z) * exp(y, z) because { - if (x == 0) trivial - else if (y == 0) trivial - else if (z == 0) trivial - else check { - x * y * exp(x * y, z - 1) == - x * exp(x, z - 1) * y * exp(y, z - 1) because - expMultCommute(x, y, z - 1) - } - } - }.holds - - /** A combination of the previous two lemmas. */ - def square(x: BigInt, y: BigInt): Boolean = { - require(y >= 0) - exp(x, 2 * y) == exp(x * x, y) because - monoidHom(x, y, y) && expMultCommute(x, x, y) - }.holds - - /** A more efficient function for computing exponentials. */ - def fastExp(x: BigInt, y: BigInt): BigInt = { - require(y >= 0) - if (x == 0) 0 - else if (y == 0) 1 - else if (y % 2 == 0) fastExp(x * x, y / 2) - else x * fastExp(x, y - 1) - } - - /** - * The two versions of the exponential function are equivalent. - * - * NOTE: Leon is able to verify most of the individual sub-goals of - * this correctness proof in fractions of a second using Z3-F, but - * often times out after >30s when trying to verify the overall - * post-condition (Intel core i7, Ubuntu 14.04.2 LTS, x86-64, - * 2015-06-04). - */ - def fastExpCorrect(x: BigInt, y: BigInt): Boolean = { - require(y >= 0) - fastExp(x, y) == exp(x, y) because { - if (x == 0) trivial - else if (y == 0) trivial - else if (y % 2 == 0) { - val z = y / 2; { - fastExp(x, y) ==| trivial | - fastExp(x * x, z) ==| fastExpCorrect(x * x, z) | - exp(x * x, z) ==| square(x, z) | - exp(x, y) - }.qed - } - else { - val z = (y - 1) / 2; { - fastExp(x, y) ==| (y % 2 != 0) | - x * fastExp(x * x, z) ==| { - fastExp(x * x, z) ==| fastExpCorrect(x * x, z) | - exp(x * x, z) ==| square(x, z) | - exp(x, 2 * z) ==| trivial | - exp(x, y - 1) }.qed | - x * exp(x, y - 1) ==| (y != 0) | - exp(x, y) - }.qed - } - } - }.holds - - /** - * The two versions of the exponential function are equivalent. - * - * NOTE: this version of the correctness proof is more verbose but - * easier to debug. Leon is able to verify most of the individual - * sub-goals in fractions of a second using Z3-F, but often times - * out after >30s when trying to verify the overall post-condition - * (Intel core i7, Ubuntu 14.04.2 LTS, x86-64, 2015-06-04). - */ - def fastExpCorrect2(x: BigInt, y: BigInt): Boolean = { - require(y >= 0) - fastExp(x, y) == exp(x, y) because { - if (x == 0) trivial - else if (y == 0) trivial - else if (y % 2 == 0) { - val z = y / 2 - check { fastExp(x, y) == fastExp(x * x, z) } && - check { fastExp(x * x, z) == exp(x * x, z) because fastExpCorrect2(x * x, z) } && - check { exp(x * x, z) == exp(x, y) because square(x, z) } - } - else { - val z = (y - 1) / 2; - check { fastExp(x, y) == x * fastExp(x * x, z) because (y % 2 != 0) } && - check { x * fastExp(x * x, z) == x * exp(x, y - 1) because { - check { fastExp(x * x, z) == exp(x * x, z) because fastExpCorrect2(x * x, z) } && - check { exp(x * x, z) == exp(x, 2 * z) because square(x, z) } && - check { exp(x, 2 * z) == exp(x, y - 1) } - } } && - check { x * exp(x, y - 1) == exp(x, y) because (y != 0) } - } - } - }.holds - - /** - * A more efficient function for computing exponentials. - * - * NOTE: this version of fastExp incorporates the correctness proof - * directly into the post condition. Leon is sometimes able to - * verify the post-condition in seconds using Z3-F, but often times - * out after >30s (Intel core i7, Ubuntu 14.04.2 LTS, x86-64, - * 2015-06-04). - */ - def fastExp2(x: BigInt, y: BigInt): BigInt = { - require(y >= 0) - if (x == 0) BigInt(0) - else if (y == 0) BigInt(1) - else if (y % 2 == 0) fastExp2(x * x, y / 2) - else x * fastExp2(x, y - 1) - } ensuring { res => - res == exp(x, y) because { - if (x == 0) trivial - else if (y == 0) trivial - else if (y % 2 == 0) { - val z = y / 2; { - res ==| trivial | - fastExp2(x * x, z) ==| trivial /* ind. hyp. */ | - exp(x * x, z) ==| square(x, z) | - exp(x, y) - }.qed - } - else { - val z = (y - 1) / 2; { - res ==| (y % 2 != 0) | - x * fastExp2(x * x, z) ==| { - fastExp2(x * x, z) ==| trivial /* ind. hyp. */ | - exp(x * x, z) ==| square(x, z) | - exp(x, 2 * z) ==| trivial | - exp(x, y - 1) }.qed | - x * exp(x, y - 1) ==| (y != 0) | - exp(x, y) - }.qed - } - } - } -} - diff --git a/testcases/verification/proof/NotWellFounded.scala b/testcases/verification/proof/NotWellFounded.scala deleted file mode 100644 index f97c16e1b1e1ec2146f3de4f2321024202f3453c..0000000000000000000000000000000000000000 --- a/testcases/verification/proof/NotWellFounded.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.testcases.verification.proof - -import leon.collection._ -import leon.lang._ -import leon.proof._ - -object NotWellFounded { - - // This proof is not well-founded. Since Leon doesn't run the - // termination checker by default, it will accept the proof as - // valid. - def allListsAreEmpty[T](xs: List[T]): Boolean = { - xs.isEmpty because { - xs match { - case Nil() => trivial - case Cons(x, xs) => allListsAreEmpty(x :: xs) - } - } - }.holds -} diff --git a/testcases/verification/proof/implication.scala b/testcases/verification/proof/implication.scala deleted file mode 100644 index b2e394ba241b4ad0b5791b45ca871b63407c1549..0000000000000000000000000000000000000000 --- a/testcases/verification/proof/implication.scala +++ /dev/null @@ -1,59 +0,0 @@ -package test - -import leon.lang._ -import leon.proof._ - -object ImplicationExample { - /* - * Some implication example. - * - * This example actually is based on incorrect premises but - * the proof in itself should correct. - */ - - sealed abstract class Animal - case class Insect() extends Animal - case class Mamal() extends Animal - - sealed abstract class AnimalKind - case object InsectKind extends AnimalKind - case object MamalKind extends AnimalKind - - sealed abstract class LegsProperty - case object HasEigthLegs extends LegsProperty - //case object HasTwoLegs extends LegsProperty - - sealed abstract class PlayerKind - case object PockerKind extends PlayerKind - // - - val jeff = Insect() - - def isEqual(a: Animal, b: Animal): Boolean = a == b - - def isKindOf(a: Animal, k: AnimalKind): Boolean = a match { - case Insect() => k == InsectKind - case Mamal() => k == MamalKind - } - - def hasLegsProperty(k: AnimalKind, l: LegsProperty): Boolean = k match { - case InsectKind => l == HasEigthLegs - case MamalKind => l != HasEigthLegs - } - - def isKindOf(l: LegsProperty, p: PlayerKind): Boolean = l match { - case HasEigthLegs => p == PockerKind - } - - def implies(a: Boolean, b: Boolean) = a ==> b - - // Jeff plays Poker - def lemma(animal: Animal): Boolean = { - isEqual(animal, jeff) ==> - isKindOf(jeff, InsectKind) ==> - hasLegsProperty(InsectKind, HasEigthLegs) ==> - isKindOf(HasEigthLegs, PockerKind) - }.holds - -} - diff --git a/testcases/verification/proof/measure/Meas.scala b/testcases/verification/proof/measure/Meas.scala deleted file mode 100644 index 1b36b0d360676a7f54ef3ca9bdf95ed34bde2798..0000000000000000000000000000000000000000 --- a/testcases/verification/proof/measure/Meas.scala +++ /dev/null @@ -1,441 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -package leon.testcases.verification.proof.measure - -import leon.annotation._ -import leon.collection._ -import leon.lang._ -import leon.proof._ -import scala.language.implicitConversions - -object Rational { - implicit def bigInt2Rational(x: BigInt) = Rational(x, 1) -} - -/** - * Represents rational number 'n / d', where 'n' is the numerator and - * 'd' the denominator. - */ -case class Rational (n: BigInt, d: BigInt) { - - def +(that: Rational): Rational = { - require(isRational && that.isRational) - Rational(n * that.d + that.n * d, d * that.d) - } ensuring { res => - res.isRational && - ((this.isPositive == that.isPositive) ==> - (res.isPositive == this.isPositive)) - } - - def -(that: Rational): Rational = { - require(isRational && that.isRational) - Rational(n * that.d - that.n * d, d * that.d) - } ensuring { res => - res.isRational && - ((this.isPositive != that.isPositive) ==> - (res.isPositive == this.isPositive)) - } - - def *(that: Rational): Rational = { - require(isRational && that.isRational) - Rational(n * that.n, d * that.d) - } ensuring { res => - res.isRational && - (res.isNonZero == (this.isNonZero && that.isNonZero)) && - (res.isPositive == (!res.isNonZero || this.isPositive == that.isPositive)) - } - - def /(that: Rational): Rational = { - require(isRational && that.isRational && that.isNonZero) - Rational(n * that.d, d * that.n) - } ensuring { res => - res.isRational && - (res.isNonZero == this.isNonZero) && - (res.isPositive == (!res.isNonZero || this.isPositive == that.isPositive)) - } - - def <=(that: Rational): Boolean = { - require(isRational && that.isRational) - if (that.d * d > 0) - n * that.d <= d * that.n - else - n * that.d >= d * that.n - } - - def <(that: Rational): Boolean = { - require(isRational && that.isRational) - if (that.d * d > 0) - n * that.d < d * that.n - else - n * that.d > d * that.n - } - - def >=(that: Rational): Boolean = { - require(isRational && that.isRational) - that <= this - } - - def >(that: Rational): Boolean = { - require(isRational && that.isRational) - that < this - } - - // Equivalence of two rationals, true if they represent the same real number - def ~(that: Rational): Boolean = { - require(isRational && that.isRational) - n * that.d == that.n * d - } - - def isRational = d != 0 - def isPositive = isRational && (n * d >= 0) - def isNonZero = isRational && (n != 0) -} - -object RationalSpecs { - - def equivalenceOverAddition(a1: Rational, a2: Rational, b1: Rational, b2: Rational): Boolean = { - require( - a1.isRational && a2.isRational && b1.isRational && b2.isRational && - a1 ~ a2 && b1 ~ b2 - ) - - (a1 + b1) ~ (a2 + b2) - }.holds - - def equivalenceOverSubstraction(a1: Rational, a2: Rational, b1: Rational, b2: Rational): Boolean = { - require( - a1.isRational && a2.isRational && b1.isRational && b2.isRational && - a1 ~ a2 && b1 ~ b2 - ) - - (a1 - b1) ~ (a2 - b2) - }.holds - - def equivalenceOverMultiplication(a1: Rational, a2: Rational, b1: Rational, b2: Rational): Boolean = { - require( - a1.isRational && a2.isRational && b1.isRational && b2.isRational && - a1 ~ a2 && b1 ~ b2 - ) - - (a1 * b1) ~ (a2 * b2) - }.holds - - def equivalenceOverDivision(a1: Rational, a2: Rational, b1: Rational, b2: Rational): Boolean = { - require( - a1.isRational && a2.isRational && b1.isRational && b2.isRational && - a1 ~ a2 && b1 ~ b2 && - b1.isNonZero // in addition to the usual requirements - ) - - (a1 / b1) ~ (a2 / b2) - }.holds - - def additionPreservesOrdering(a: Rational, b: Rational, c: Rational): Boolean = { - require(a.isRational && b.isRational && c.isRational) - - (a <= b) ==> (a + c <= b + c) && - (a <= b) ==> (c + a <= c + b) - }.holds - - def orderingTransitivity(a: Rational, b: Rational, c: Rational): Boolean = { - require(a.isRational && b.isRational && c.isRational) - - ((a < b) && (b < c)) ==> (a < c) && - (((a <= b) && (b <= c)) ==> (a <= c)) - }.holds - - def orderingAntisymmetry(a: Rational, b: Rational): Boolean = { - require(a.isRational && b.isRational) - - (a <= b && b <= a) ==> a ~ b - }.holds - - def orderingReflexivity(a: Rational): Boolean = { - require(a.isRational) - - a <= a - }.holds - - def orderingIrreflexivity(a: Rational): Boolean = { - require(a.isRational) - - !(a < a) - }.holds - - def orderingExtra(a: Rational, b: Rational): Boolean = { - require(a.isRational && b.isRational) - - ((a < b) == !(b <= a)) && - ((a < b) == (a <= b && !(a ~ b))) - }.holds - - def plusAssoc(a: Rational, b: Rational, c: Rational): Boolean = { - require(a.isRational && b.isRational && c.isRational) - - (a + b) + c == a + (b + c) - }.holds - - def plusComm(a: Rational, b: Rational): Boolean = { - require(a.isRational && b.isRational) - - a + b == b + a - }.holds -} - -/** - * Measures on discrete probability spaces. - * - * NOTE: - * - * This class is a rather limited model of (discrete) measures in - * that weights can only be rationals. However, attention has been - * payed to not rely on the properties of rationals, so that, in - * principle, the class could be re-implemented using 'Real' instead - * of 'Rational'. - */ - -sealed abstract class Meas[A] { - - /** Compute the value of this measure on the space 'A'. */ - def apply(): Rational = { - require(this.isMeasure) - this match { - case Empty() => Rational(0, 1) - case Cons(x, w, m) => w + m() - } - } ensuring { res => - res.isPositive because { - this match { - case Empty() => trivial - case Cons(x, w, m) => m().isPositive - } - } - } - - /** Compute the value of this measure on a subset of the space 'A'. */ - def apply(xs: Set[A]): Rational = { - require (isMeasure) - this match { - case Empty() => Rational(0, 1) - case Cons(x, w, m) => if (xs contains x) w + m(xs) else m(xs) - } - } ensuring { res => - res.isPositive because { - this match { - case Empty() => trivial - case Cons(x, w, m) => m(xs).isPositive - } - } - } - - /** Compute the support of this measure. */ - def support: Set[A] = { - require (isMeasure) - this match { - case Empty() => Set() - case Cons(x, w, m) => - if (w > BigInt(0)) m.support ++ Set(x) else m.support - } - } - - /** Restrict the measure to a subset of 'A'. */ - def filter(p: A => Boolean): Meas[A] = { - require (isMeasure) - this match { - case Empty() => Empty[A]() - case Cons(x, w, m) => if (p(x)) Cons(x, w, m filter p) else m filter p - } - } ensuring (_.isMeasure) - - /** Change the space underlying this measure. */ - def map[B](f: A => B): Meas[B] = { - require (isMeasure) - this match { - case Empty() => Empty[B]() - case Cons(x, w, m) => Cons(f(x), w, m map f) - } - } ensuring (_.isMeasure) - - /** Scalar multiplication. */ - def *(a: Rational): Meas[A] = { - require(a.isRational && a.isPositive && isMeasure) - this match { - case Empty() => Empty[A]() - case Cons(x, w, m) => Cons(x, w * a, m * a) - } - } ensuring (_.isMeasure) - - /** Union/sum. */ - def +(that: Meas[A]): Meas[A] = { - require (this.isMeasure && that.isMeasure) - this match { - case Empty() => that - case Cons(x, w, m) => Cons(x, w, m + that) - } - } ensuring (_.isMeasure) - - /** Compute the product of this measure and 'that'. */ - def *[B](that: Meas[B]): Meas[(A, B)] = { - require (this.isMeasure && that.isMeasure) - this match { - case Empty() => Empty[(A, B)]() - case Cons(x, w, m) => (that map { y: B => (x, y) }) * w + m * that - } - } ensuring (_.isMeasure) - - /** Independence of two events in 'A'. */ - def indep(xs: Set[A], ys: Set[A]): Boolean = { - require (this.isMeasure) - this(xs ++ ys) ~ (this(xs) * this(ys)) - } - - /** Check if this measure is a probability. */ - def isProb: Boolean = isMeasure && this() ~ BigInt(1) - - /* - - TODO: the following need additional lemmas to be verified. - - /** - * Compute the expected value/integral of a function 'f' with - * respect to this measure. - */ - def expect(f: A => Rational): Rational = { - require(this.isMeasure && - setForall(this.support, { x: A => f(x).isRational })) - this match { - case Empty() => BigInt(0) - case Cons(x, w, m) => f(x) * w + m.expect(f) - } - } - - /** Convert this measure into a map. */ - def toMap: Map[A, Rational] = { - this match { - case Empty() => Map() - case Cons(x, w, m) => { - val res: Map[A, Rational] = m.toMap - val y = if (res isDefinedAt x) res(x) + w else w - res.updated(x, y) - } - } - } ensuring { res => - val sup = this.support - setForall(sup, { x: A => (sup contains x) ==> (res isDefinedAt x) }) - } - - */ - - /** All weights must be positive. */ - def isMeasure: Boolean = this match { - case Empty() => true - case Cons(x, w, m) => w.isPositive && m.isMeasure - } -} - -/** The empty measure maps every subset of the space A to 0. */ -case class Empty[A]() extends Meas[A] - -/** - * The 'Cons' measure adjoins an additional element 'x' of type 'A' - * to an existing measure 'm' over 'A'. Note that 'x' might already - * be present in 'm'. - */ -case class Cons[A](x: A, w: Rational, m: Meas[A]) extends Meas[A] - -import RationalSpecs._ - -object MeasSpecs { - - def additivity[A](m: Meas[A], xs: Set[A], ys: Set[A]): Boolean = { - require(m.isMeasure && (xs & ys).isEmpty) - m(xs ++ ys) == m(xs) + m(ys) because { - m match { - case Empty() => trivial - case Cons(x, w, n) => if (xs contains x) { - w + n(xs ++ ys) ==| additivity(n, xs, ys) | - w + (n(xs) + n(ys)) ==| plusAssoc(w, n(xs), n(ys)) | - (w + n(xs)) + n(ys) ==| !(ys contains x) | - m(xs) + m(ys) - }.qed else if (ys contains x) { - w + n(xs ++ ys) ==| additivity(n, xs, ys) | - w + (n(xs) + n(ys)) ==| plusComm(w, (n(xs) + n(ys))) | - (n(xs) + n(ys)) + w ==| plusAssoc(n(xs), n(ys), w) | - n(xs) + (n(ys) + w) ==| plusComm(n(ys), w) | - n(xs) + (w + n(ys)) ==| !(xs contains x) | - m(xs) + m(ys) - }.qed else { - n(xs ++ ys) ==| additivity(n, xs, ys) | - n(xs) + n(ys) - }.qed - } - } - }.holds - - /** - * Subaddititivity of measures. - * - * NOTE: the proof of this lemma could greatly benefit from a DSL - * for relational reasoning on rationals. However, the out-of-the- - * box support for relational reasoning doesn't work here because - * - * a) relations such as '<=' and '~' on rationals have - * preconditions that seem to interact badly with the generic - * relational reasoning DSL, and - * - * b) although relations such as '<=' and '~' are transitive, this - * fact isn't obvious to Leon. Consequently, one needs to - * establish that the composition of e.g. two '<='-reasoning - * steps is again in '<=' explicitly by calls to - * 'orderingTransitivity' and the like. - */ - def subAdditivity[A](m: Meas[A], xs: Set[A], ys: Set[A]): Boolean = { - require(m.isMeasure) - m(xs ++ ys) <= m(xs) + m(ys) because { - m match { - case Empty() => trivial - case Cons(x, w, n) => if (xs contains x) check { - w + n(xs ++ ys) <= w + (n(xs) + n(ys)) because - subAdditivity(n, xs, ys) && - additionPreservesOrdering(n(xs ++ ys), n(xs) + n(ys), w) - } && check { - if (ys contains x) check { - w + (n(xs) + n(ys)) <= w + (n(xs) + n(ys)) + w because - w + (n(xs) + n(ys)) == w + (n(xs) + n(ys)) + BigInt(0) && - additionPreservesOrdering(BigInt(0), w, w + (n(xs) + n(ys))) - } && check { - w + n(xs ++ ys) <= w + (n(xs) + n(ys)) + w because - orderingTransitivity( - w + n(xs ++ ys), - w + (n(xs) + n(ys)), - w + (n(xs) + n(ys)) + w) - } && { - w + (n(xs) + n(ys)) + w ==| plusAssoc(w, n(xs), n(ys)) | - (w + n(xs)) + n(ys) + w ==| plusAssoc(w + n(xs), n(ys), w) | - (w + n(xs)) + (n(ys) + w) ==| trivial | - m(xs) + m(ys) - }.qed else { - w + (n(xs) + n(ys)) ==| plusAssoc(w, n(xs), n(ys)) | - (w + n(xs)) + n(ys) ==| !(ys contains x) | - m(xs) + m(ys) - }.qed - } else { - if (ys contains x) check { - w + n(xs ++ ys) <= w + (n(xs) + n(ys)) because - subAdditivity(n, xs, ys) && - additionPreservesOrdering(n(xs ++ ys), n(xs) + n(ys), w) - } && { - w + (n(xs) + n(ys)) ==| plusComm(w, (n(xs) + n(ys))) | - (n(xs) + n(ys)) + w ==| plusAssoc(n(xs), n(ys), w) | - n(xs) + (n(ys) + w) ==| plusComm(n(ys), w) | - n(xs) + (w + n(ys)) ==| !(xs contains x) | - m(xs) + m(ys) - }.qed else { - n(xs ++ ys) <= n(xs) + n(ys) because subAdditivity(n, xs, ys) - } - } - } - } - }.holds -} - diff --git a/testcases/verification/quantification/invalid/BinarySearchTreeQuant.scala b/testcases/verification/quantification/invalid/BinarySearchTreeQuant.scala deleted file mode 100644 index 849de7d15c180c8d8ed945e2420043b36ba92152..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/invalid/BinarySearchTreeQuant.scala +++ /dev/null @@ -1,42 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object BSTSimpler { - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def content(tree: Tree): Set[BigInt] = tree match { - case Leaf() => Set.empty[BigInt] - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def isBST(tree: Tree) : Boolean = tree match { - case Leaf() => true - case Node(left, v, right) => { - isBST(left) && isBST(right) && - forall((x:BigInt) => (content(left).contains(x) ==> x < v - 10)) && - forall((x:BigInt) => (content(right).contains(x) ==> v < x)) - } - } - - def emptySet(): Tree = Leaf() - - def insert(tree: Tree, value: BigInt): Node = { - require(isBST(tree)) - tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case Node(l, v, r) => (if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - Node(l, v, r) - }) - } - } ensuring(res => isBST(res) && content(res) == content(tree) ++ Set(value)) - - def createRoot(v: BigInt): Node = { - Node(Leaf(), v, Leaf()) - } ensuring (content(_) == Set(v)) -} diff --git a/testcases/verification/quantification/invalid/HOInvocations.scala b/testcases/verification/quantification/invalid/HOInvocations.scala deleted file mode 100644 index 5cd0afc42e447404d227dbfa43b3ea3f7f260678..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/invalid/HOInvocations.scala +++ /dev/null @@ -1,16 +0,0 @@ -import leon.lang._ - -object HOInvocations { - def switch(x: BigInt, f: (BigInt) => BigInt, g: (BigInt) => BigInt) = if(x > 0) f else g - - def failling_1(f: (BigInt) => BigInt) = { - switch(-10, (x: BigInt) => x + 1, f)(2) - } ensuring { res => res > 0 } - - def failling_2(x: BigInt, f: (BigInt) => BigInt, g: (BigInt) => BigInt) = { - require(x > 0 && forall((a: BigInt) => a > 0 ==> f(a) > 0)) - switch(1, switch(x, f, g), g)(0) - } ensuring { res => res > 0 } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/quantification/invalid/Monotonic.scala b/testcases/verification/quantification/invalid/Monotonic.scala deleted file mode 100644 index bc9a1bc76855e21d514a10ebdf257235480b1e10..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/invalid/Monotonic.scala +++ /dev/null @@ -1,10 +0,0 @@ -import leon.lang._ - -object Monotonic { - def failling_1(f: BigInt => BigInt, g: BigInt => BigInt): BigInt => BigInt = { - require(forall((a: BigInt, b: BigInt) => (a > b ==> f(a) > f(b)))) - (x: BigInt) => f(g(x)) - } ensuring { res => forall((a: BigInt, b: BigInt) => a > b ==> res(a) > res(b)) } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/quantification/invalid/PositiveMap.scala b/testcases/verification/quantification/invalid/PositiveMap.scala deleted file mode 100644 index 7b15cb2576e9119d27f77e158fddfee0e6e4bc98..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/invalid/PositiveMap.scala +++ /dev/null @@ -1,23 +0,0 @@ -import leon.lang._ - -object PositiveMap { - - abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def positive(list: List): Boolean = list match { - case Cons(head, tail) => if (head < 0) false else positive(tail) - case Nil() => true - } - - def positiveMap_failling_1(f: (BigInt) => BigInt, list: List): List = { - require(forall((a: BigInt) => f(a) > -2)) - list match { - case Cons(head, tail) => Cons(f(head), positiveMap_failling_1(f, tail)) - case Nil() => Nil() - } - } ensuring { res => positive(res) } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/quantification/invalid/Postcondition.scala b/testcases/verification/quantification/invalid/Postcondition.scala deleted file mode 100644 index d942f446e9ce75f42545e4078b56b89962df540c..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/invalid/Postcondition.scala +++ /dev/null @@ -1,14 +0,0 @@ -import leon.lang._ - -object Postconditions { - def failling_1(f: BigInt => BigInt) = { - require(forall((a: BigInt) => a > 0 ==> f(a) > 0)) - f(10) - } ensuring { res => forall((a: BigInt) => res > f(a)) } - - def failling_2(f: BigInt => BigInt, x: BigInt) = { - require(x >= 0 && forall((a: BigInt) => a > 0 ==> f(a) < 0)) - x - } ensuring { res => forall((a: BigInt) => res > f(a)) } - -} diff --git a/testcases/verification/quantification/invalid/Simple.scala b/testcases/verification/quantification/invalid/Simple.scala deleted file mode 100644 index 7a3446612bd910dfbe7389b0d83001606640457c..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/invalid/Simple.scala +++ /dev/null @@ -1,20 +0,0 @@ -import leon.lang._ - -object Simple { - - def failling_1(f: BigInt => BigInt) = { - require(forall((a: BigInt) => a > 0 ==> f(a) > 0)) - f(-1) - } ensuring { res => res > 0 } - - def failling_2(f: BigInt => BigInt) = { - require(forall((a: BigInt) => a > 0 ==> f(a) > 1)) - f(1) + f(2) - } ensuring { res => res > 4 } - - def failling_4(f: BigInt => BigInt, g: BigInt => BigInt, x: BigInt) = { - require(forall((a: BigInt, b: BigInt) => f(a) + g(a) > 0)) - if(x < 0) f(x) + g(x) - else x - } ensuring { res => res > 0 } -} diff --git a/testcases/verification/quantification/valid/BinarySearchTreeQuant.scala b/testcases/verification/quantification/valid/BinarySearchTreeQuant.scala deleted file mode 100644 index a435e69ca7a0574937f7368e499c5750983133b3..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/BinarySearchTreeQuant.scala +++ /dev/null @@ -1,42 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object BSTSimpler { - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def content(tree: Tree): Set[BigInt] = tree match { - case Leaf() => Set.empty[BigInt] - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def isBST(tree: Tree) : Boolean = tree match { - case Leaf() => true - case Node(left, v, right) => { - isBST(left) && isBST(right) && - forall((x:BigInt) => (content(left).contains(x) ==> x < v)) && - forall((x:BigInt) => (content(right).contains(x) ==> v < x)) - } - } - - def emptySet(): Tree = Leaf() - - def insert(tree: Tree, value: BigInt): Node = { - require(isBST(tree)) - tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case Node(l, v, r) => (if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - Node(l, v, r) - }) - } - } ensuring(res => isBST(res) && content(res) == content(tree) ++ Set(value)) - - def createRoot(v: BigInt): Node = { - Node(Leaf(), v, Leaf()) - } ensuring (content(_) == Set(v)) -} diff --git a/testcases/verification/quantification/valid/BinarySearchTreeQuant2.scala b/testcases/verification/quantification/valid/BinarySearchTreeQuant2.scala deleted file mode 100644 index 0c72b1018865912316a402c812bb08bccc2050cd..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/BinarySearchTreeQuant2.scala +++ /dev/null @@ -1,35 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object BSTSimpler { - - sealed abstract class Tree { - def content: Set[BigInt] = this match { - case Leaf() => Set.empty[BigInt] - case Node(l, v, r) => l.content ++ Set(v) ++ r.content - } - } - - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree { - require(forall((x:BigInt) => (left.content.contains(x) ==> x < value)) && - forall((x:BigInt) => (right.content.contains(x) ==> value < x))) - } - - case class Leaf() extends Tree - - def emptySet(): Tree = Leaf() - - def insert(tree: Tree, value: BigInt): Node = { - tree match { - case Leaf() => Node(Leaf(), value, Leaf()) - case Node(l, v, r) => (if (v < value) { - Node(l, v, insert(r, value)) - } else if (v > value) { - Node(insert(l, value), v, r) - } else { - Node(l, v, r) - }) - } - } ensuring(res => res.content == tree.content ++ Set(value)) - -} diff --git a/testcases/verification/quantification/valid/Composition.scala b/testcases/verification/quantification/valid/Composition.scala deleted file mode 100644 index cd62eb8da69132b1825630d6a6d3885a06e951aa..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/Composition.scala +++ /dev/null @@ -1,14 +0,0 @@ - -import leon.lang._ - -object Composition { - def passing_1(f: (Int) => Int, g: (Int) => Int, x: Int): Int = { - require(g(1) == 2 && forall((a: Int) => f(g(a)) == a)) - val a = g(x) - if(x == 1) - f(g(a)) - else 2 - } ensuring { _ == 2 } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/quantification/valid/HOInvocations.scala b/testcases/verification/quantification/valid/HOInvocations.scala deleted file mode 100644 index ba44b8fdc3e38542dd6e84664a717517a7392f5f..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/HOInvocations.scala +++ /dev/null @@ -1,17 +0,0 @@ -import leon.lang._ - -object HOInvocations { - def switch(x: Int, f: (Int) => Int, g: (Int) => Int) = if(x > 0) f else g - - def passing_1(f: (Int) => Int) = { - switch(10, (x: Int) => x + 1, f)(2) - } ensuring { res => res > 0 } - - def passing_2(x: Int, f: (Int) => Int, g: (Int) => Int) = { - require(x > 0 && forall((a: Int) => a > 0 ==> f(a) > 0)) - switch(1, switch(x, f, g), g)(1) - } ensuring { res => res > 0 } - -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/quantification/valid/Monotonic.scala b/testcases/verification/quantification/valid/Monotonic.scala deleted file mode 100644 index cef6be60f2d6d27ffd2eae005f649a44b9d94a2a..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/Monotonic.scala +++ /dev/null @@ -1,10 +0,0 @@ -import leon.lang._ - -object Monotonic { - def composeMonotonic(f: BigInt => BigInt, g: BigInt => BigInt): BigInt => BigInt = { - require(forall((a: BigInt, b: BigInt) => (a > b ==> f(a) > f(b)) && (a > b ==> g(a) > g(b)))) - (x: BigInt) => f(g(x)) - } ensuring { res => forall((a: BigInt, b: BigInt) => a > b ==> res(a) > res(b)) } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/quantification/valid/PositiveMap.scala b/testcases/verification/quantification/valid/PositiveMap.scala deleted file mode 100644 index 030e7095954a063b0d9b0e19ed15c0d6958e2304..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/PositiveMap.scala +++ /dev/null @@ -1,33 +0,0 @@ - -import leon.lang._ - -object PositiveMap { - - abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def positive(list: List): Boolean = list match { - case Cons(head, tail) => if (head < 0) false else positive(tail) - case Nil() => true - } - - def positiveMap_passing_1(f: (BigInt) => BigInt, list: List): List = { - require(forall((a: BigInt) => f(a) > 0)) - list match { - case Cons(head, tail) => Cons(f(head), positiveMap_passing_1(f, tail)) - case Nil() => Nil() - } - } ensuring { res => positive(res) } - - def positiveMap_passing_2(f: (BigInt) => BigInt, list: List): List = { - require(forall((a: BigInt) => f(a) > -1)) - list match { - case Cons(head, tail) => Cons(f(head), positiveMap_passing_2(f, tail)) - case Nil() => Nil() - } - } ensuring { res => positive(res) } - -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/quantification/valid/Postcondition.scala b/testcases/verification/quantification/valid/Postcondition.scala deleted file mode 100644 index e044a9a3adc1214bb1ce917b6be3785be1fd93fe..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/Postcondition.scala +++ /dev/null @@ -1,23 +0,0 @@ -import leon.lang._ - -object Postconditions { - - def passing_1(f: BigInt => BigInt, x: BigInt) = { - require(x >= 0 && forall((a: BigInt) => f(a) < 0)) - x - } ensuring { res => forall((a: BigInt) => res > f(a)) } - - def passing_2(f: BigInt => BigInt, x: BigInt) = { - require(x >= 0 && forall((a: BigInt) => a > 0 ==> f(a) < 0)) - x - } ensuring { res => forall((a: BigInt) => a > 0 ==> res > f(a)) } - - def passing_3(f: BigInt => BigInt) = { - require(forall((a: BigInt) => f(a) > 0)) - f - } ensuring { res => forall((a: BigInt) => res(a) > 0) } - - def passing_4() = { - (x: BigInt) => x + 1 - } ensuring { res => forall((a: BigInt) => res(a) > a) } -} diff --git a/testcases/verification/quantification/valid/Relations.scala b/testcases/verification/quantification/valid/Relations.scala deleted file mode 100644 index ebce8d5b595b68fe866c050436486087cac47476..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/Relations.scala +++ /dev/null @@ -1,31 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.proof._ - -object Relations { - - case class Relation[A](r: (A, A) => Boolean) - - def reflexive[A](rel: Relation[A]) = - forall( (x: A) => rel.r(x, x) ) - - def symmetric[A](rel: Relation[A]) = - forall( (x:A, y:A) => rel.r(x, y) == rel.r(y, x) ) - - def antisymmetric[A](rel: Relation[A]) = - forall( (x:A, y:A) => ( rel.r(x,y) && rel.r(y,x) ) ==> (x == y) ) - - def transitive[A](rel: Relation[A]) = - forall( (x:A, y:A, z:A) => ( rel.r(x,y) && rel.r(y,z) ) ==> rel.r(x,z) ) - - def po[A](rel: Relation[A]) = - reflexive(rel) && - antisymmetric(rel) && - transitive(rel) - - def test = po(Relation[BigInt](_ <= _)).holds - -} - - - diff --git a/testcases/verification/quantification/valid/Simple.scala b/testcases/verification/quantification/valid/Simple.scala deleted file mode 100644 index 5e7e9cb339037a0acc73a4f66e4c07bac61e7df1..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/Simple.scala +++ /dev/null @@ -1,44 +0,0 @@ -import leon.lang._ - -object Simple { - - def passing_1(f: BigInt => BigInt) = { - require(forall((a: BigInt) => a > 0 ==> f(a) > 0)) - f(10) - } ensuring { res => res > 0 } - - def passing_2(f: BigInt => BigInt) = { - require(forall((a: BigInt) => a > 0 ==> f(a) > 1)) - f(1) + f(2) - } ensuring { res => res > 2 } - - def passing_3(f: BigInt => BigInt) = { - require(forall((a: BigInt) => f(a) > 0 || f(a) < 0)) - f(8) - } ensuring { res => res != 0 } - - def passing_4(f: BigInt => BigInt, g: BigInt => BigInt, x: BigInt) = { - require(forall((a: BigInt, b: BigInt) => f(a) + f(b) > 0)) - if(x <= 0) f(x) + f(x) - else x - } ensuring { res => res > 0 } - - def passing_5(f: BigInt => BigInt, g: BigInt => Boolean): BigInt = { - require(forall((a: BigInt) => if(g(a)) { f(a) > 0 || f(a) < 0 } else { f(a) == 0 })) - if(g(8)) f(8) - else BigInt(1) - } ensuring { res => res != 0 } - - def passing_6(f: BigInt => BigInt, x: BigInt) = { - require(x > 0 && forall((a: BigInt) => a > 0 ==> f(a) > 0)) - if(x > 0) f(1) - else f(-1) - } ensuring { res => res > 0 } - - def passing_7(f: BigInt => BigInt) = { - require(forall((a: BigInt) => a > 0 ==> f(a) > 0)) - val a = f(-1) - f(2) - } ensuring { res => res > 0 } - -} diff --git a/testcases/verification/quantification/valid/Transitive.scala b/testcases/verification/quantification/valid/Transitive.scala deleted file mode 100644 index 5e7bb03cd858c34f9876de1ecc723e010fdab162..0000000000000000000000000000000000000000 --- a/testcases/verification/quantification/valid/Transitive.scala +++ /dev/null @@ -1,12 +0,0 @@ -import leon.lang._ - -object Transitive { - - def multiAssoc(f: (Int, Int, Int) => Int): Boolean = { - require(forall { (a: Int, b: Int, c: Int, d: Int, e: Int) => - f(f(a,b,c),d,e) == f(a,f(b,c,d),e) && f(a,f(b,c,d),e) == f(a,b,f(c,d,e)) - }) - f(f(1,2,3),4,5) == f(1,2,f(3,4,5)) - }.holds - -} diff --git a/testcases/verification/quantifiers/Relations.scala b/testcases/verification/quantifiers/Relations.scala deleted file mode 100644 index 353009fa67ca6f44caf4befd79993e142b7dee64..0000000000000000000000000000000000000000 --- a/testcases/verification/quantifiers/Relations.scala +++ /dev/null @@ -1,68 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.proof._ - -object Relations { - - case class Relation[A](r: (A, A) => Boolean) - - def reflexive[A](rel: Relation[A]) = - forall( (x: A) => rel.r(x, x) ) - - def symmetric[A](rel: Relation[A]) = - forall( (x:A, y:A) => rel.r(x, y) == rel.r(y, x) ) - - def antisymmetric[A](rel: Relation[A]) = - forall( (x:A, y:A) => ( rel.r(x,y) && rel.r(y,x) ) ==> (x == y) ) - - def transitive[A](rel: Relation[A]) = - forall( (x:A, y:A, z:A) => ( rel.r(x,y) && rel.r(y,z) ) ==> rel.r(x,z) ) - - def po[A](rel: Relation[A]) = - reflexive(rel) && - antisymmetric(rel) && - transitive(rel) - -} - - -object Proofs { - import Relations._ - - def int = { - val rel = Relation[BigInt](_ <= _) - po(rel) because {{ - po(rel) ==| trivial | - ( - reflexive(rel) && - antisymmetric(rel) && - transitive(rel) - ) ==| trivial | - ( - forall( (x:BigInt) => - rel.r(x, x) - ) && - forall( (x:BigInt, y:BigInt) => - ( rel.r(x,y) && rel.r(y,x) ) ==> (x == y) - ) && - forall( (x:BigInt, y:BigInt, z:BigInt) => - ( rel.r(x,y) && rel.r(y,z) ) ==> rel.r(x,z) - ) - ) ==| trivial | - ( - forall( (x: BigInt) => - x <= x - ) && - forall( (x: BigInt, y:BigInt) => - ( x <= y && y <= x ) ==> ( x == y ) - ) && - forall( (x: BigInt, y: BigInt, z: BigInt) => - ( x <= y && y <= z ) ==> x <= z - ) - ) ==| trivial | - true - }.qed } - }.holds - -} - diff --git a/testcases/verification/strings/invalid/CompatibleListChar.scala b/testcases/verification/strings/invalid/CompatibleListChar.scala deleted file mode 100644 index 86eec34cddcee8055c34d5ffc791b7bbf7a397e7..0000000000000000000000000000000000000000 --- a/testcases/verification/strings/invalid/CompatibleListChar.scala +++ /dev/null @@ -1,29 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object CompatibleListChar { - def rec[T](l : List[T], f : T => String): String = l match { - case Cons(head, tail) => f(head) + rec(tail, f) - case Nil() => "" - } - def customToString[T](l : List[T], p: List[Char], d: String, fd: String => String, fp: List[Char] => String, pf: String => List[Char], f : T => String): String = rec(l, f) ensuring { - (res : String) => (p == Nil[Char]() || d == "" || fd(d) == "" || fp(p) == "" || pf(d) == Nil[Char]()) && ((l, res) passes { - case Cons(a, Nil()) => f(a) - }) - } - def customPatternMatching(s: String): Boolean = { - s match { - case "" => true - case b => List(b) match { - case Cons("", Nil()) => true - case Cons(s, Nil()) => false // StrOps.length(s) < BigInt(2) // || (s == "\u0000") //+ "a" - case Cons(_, Cons(_, Nil())) => true - case _ => false - } - case _ => false - } - } holds -} \ No newline at end of file diff --git a/testcases/verification/xlang/AbsArray.scala b/testcases/verification/xlang/AbsArray.scala deleted file mode 100644 index 9b00259c1405fe974a4bbf03678be32fe75020cf..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/AbsArray.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.lang._ - -object AbsArray { - - - def abs(tab: Map[Int, Int], size: Int): Map[Int, Int] = ({ - require(size <= 5 && isArray(tab, size)) - var k = 0 - var tabres = Map.empty[Int, Int] - (while(k < size) { - if(tab(k) < 0) - tabres = tabres.updated(k, -tab(k)) - else - tabres = tabres.updated(k, tab(k)) - k = k + 1 - }) invariant(isArray(tabres, k) && k >= 0 && k <= size && isPositive(tabres, k)) - tabres - }) ensuring(res => isArray(res, size) && isPositive(res, size)) - - def isPositive(a: Map[Int, Int], size: Int): Boolean = { - require(size <= 10 && isArray(a, size)) - def rec(i: Int): Boolean = { - require(i >= 0) - if(i >= size) - true - else { - if(a(i) < 0) - false - else - rec(i+1) - } - } - rec(0) - } - - def isArray(a: Map[Int, Int], size: Int): Boolean = { - - def rec(i: Int): Boolean = { - require(i >= 0) - if(i >= size) true else { - if(a.isDefinedAt(i)) rec(i+1) else false - } - } - - if(size < 0) - false - else - rec(0) - } - -} diff --git a/testcases/verification/xlang/AbsFun.scala b/testcases/verification/xlang/AbsFun.scala deleted file mode 100644 index a6ff9679e27fc32ff4dd8b62a1cf2170386083d8..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/AbsFun.scala +++ /dev/null @@ -1,57 +0,0 @@ -import leon.lang._ - -object AbsFun { - - - def isPositive(a : Array[Int], size : Int) : Boolean = { - require(a.length >= 0 && size <= a.length) - rec(0, a, size) - } - - def rec(i: Int, a: Array[Int], size: Int) : Boolean = { - require(a.length >= 0 && size <= a.length && i >= 0) - - if(i >= size) true - else { - if (a(i) < 0) - false - else - rec(i + 1, a, size) - } - } - - def abs(tab: Array[Int]): Array[Int] = { - require(tab.length >= 0) - val t = while0(Array.fill(tab.length)(0), 0, tab) - t._1 - } ensuring(res => isPositive(res, res.length)) - - - def while0(t: Array[Int], k: Int, tab: Array[Int]): (Array[Int], Int) = { - require(tab.length >= 0 && - t.length == tab.length && - k >= 0 && - k <= tab.length && - isPositive(t, k)) - - if(k < tab.length) { - val nt = t.updated(k, if(tab(k) < 0) -tab(k) else tab(k)) - while0(nt, k+1, tab) - } else { - (t, k) - } - } ensuring(res => - res._2 >= tab.length && - res._1.length == tab.length && - res._2 >= 0 && - res._2 <= tab.length && - isPositive(res._1, res._2)) - - def property(t: Array[Int], k: Int): Boolean = { - require(isPositive(t, k) && t.length >= 0 && k >= 0) - if(k < t.length) { - val nt = t.updated(k, if(t(k) < 0) -t(k) else t(k)) - isPositive(nt, k+1) - } else true - } holds -} diff --git a/testcases/verification/xlang/AmortizedQueue.scala b/testcases/verification/xlang/AmortizedQueue.scala deleted file mode 100644 index fb3d5497098e7519e9581e735386581116fce39e..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/AmortizedQueue.scala +++ /dev/null @@ -1,137 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object AmortizedQueue { - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class AbsQueue - case class Queue(front : List, rear : List) extends AbsQueue - - def size(list : List) : Int = (list match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def asList(queue : AbsQueue) : List = queue match { - case Queue(front, rear) => concat(front, reverse(rear)) - } - - def concat(l1 : List, l2 : List) : List = { - var r: List = l2 - var tmp: List = reverse(l1) - - (while(!tmp.isInstanceOf[Nil]) { - val Cons(head, tail) = tmp - tmp = tail - r = Cons(head, r) - }) invariant(content(r) ++ content(tmp) == content(l1) ++ content(l2) && size(r) + size(tmp) == size(l1) + size(l2)) - - r - } ensuring(res => content(res) == content(l1) ++ content(l2) && size(res) == size(l1) + size(l2)) - - def isAmortized(queue : AbsQueue) : Boolean = queue match { - case Queue(front, rear) => size(front) >= size(rear) - } - - def isEmpty(queue : AbsQueue) : Boolean = queue match { - case Queue(Nil(), Nil()) => true - case _ => false - } - - def reverse(l: List): List = { - var r: List = Nil() - var l2: List = l - - (while(!l2.isInstanceOf[Nil]) { - val Cons(head, tail) = l2 - l2 = tail - r = Cons(head, r) - }) invariant(content(r) ++ content(l2) == content(l) && size(r) + size(l2) == size(l)) - - r - } ensuring(res => content(res) == content(l) && size(res) == size(l)) - - def amortizedQueue(front : List, rear : List) : AbsQueue = { - if (size(rear) <= size(front)) - Queue(front, rear) - else - Queue(concat(front, reverse(rear)), Nil()) - } ensuring(isAmortized(_)) - - def enqueue(queue : AbsQueue, elem : Int) : AbsQueue = (queue match { - case Queue(front, rear) => amortizedQueue(front, Cons(elem, rear)) - }) ensuring(isAmortized(_)) - - def tail(queue : AbsQueue) : AbsQueue = { - require(isAmortized(queue) && !isEmpty(queue)) - queue match { - case Queue(Cons(f, fs), rear) => amortizedQueue(fs, rear) - } - } ensuring (isAmortized(_)) - - def front(queue : AbsQueue) : Int = { - require(isAmortized(queue) && !isEmpty(queue)) - queue match { - case Queue(Cons(f, _), _) => f - } - } - - // @induct - // def propEnqueue(rear : List, front : List, list : List, elem : Int) : Boolean = { - // require(isAmortized(Queue(front, rear))) - // val queue = Queue(front, rear) - // if (asList(queue) == list) { - // asList(enqueue(queue, elem)) == concat(list, Cons(elem, Nil())) - // } else - // true - // } holds - - @induct - def propFront(queue : AbsQueue, list : List, elem : Int) : Boolean = { - require(!isEmpty(queue) && isAmortized(queue)) - if (asList(queue) == list) { - list match { - case Cons(x, _) => front(queue) == x - } - } else - true - } //holds - - @induct - def propTail(rear : List, front : List, list : List, elem : Int) : Boolean = { - require(!isEmpty(Queue(front, rear)) && isAmortized(Queue(front, rear))) - if (asList(Queue(front, rear)) == list) { - list match { - case Cons(_, xs) => asList(tail(Queue(front, rear))) == xs - } - } else - true - } // holds - - def enqueueAndFront(queue : AbsQueue, elem : Int) : Boolean = { - if (isEmpty(queue)) - front(enqueue(queue, elem)) == elem - else - true - } holds - - def enqueueDequeueTwice(queue : AbsQueue, e1 : Int, e2 : Int, e3 : Int) : Boolean = { - if (isEmpty(queue)) { - val q1 = enqueue(queue, e1) - val q2 = enqueue(q1, e2) - val e1prime = front(q2) - val q3 = tail(q2) - val e2prime = front(q3) - val q4 = tail(q3) - e1 == e1prime && e2 == e2prime - } else - true - } holds -} diff --git a/testcases/verification/xlang/Arithmetic.scala b/testcases/verification/xlang/Arithmetic.scala deleted file mode 100644 index 99efb822289bce4640dd92cbcfb94f26c9cc59c5..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/Arithmetic.scala +++ /dev/null @@ -1,84 +0,0 @@ -import leon.lang._ - -object Arithmetic { - - /* VSTTE 2008 - Dafny paper */ - def mult(x : BigInt, y : BigInt): BigInt = ({ - var r: BigInt = 0 - if(y < 0) { - var n = y - (while(n != 0) { - r = r - x - n = n + 1 - }) invariant(r == x * (y - n) && 0 <= -n) - } else { - var n = y - (while(n != 0) { - r = r + x - n = n - 1 - }) invariant(r == x * (y - n) && 0 <= n) - } - r - }) ensuring(_ == x*y) - - /* VSTTE 2008 - Dafny paper */ - def add(x : BigInt, y : BigInt): BigInt = ({ - var r = x - if(y < 0) { - var n = y - (while(n != 0) { - r = r - 1 - n = n + 1 - }) invariant(r == x + y - n && 0 <= -n) - } else { - var n = y - (while(n != 0) { - r = r + 1 - n = n - 1 - }) invariant(r == x + y - n && 0 <= n) - } - r - }) ensuring(_ == x+y) - - /* VSTTE 2008 - Dafny paper */ - def addBuggy(x : BigInt, y : BigInt): BigInt = ({ - var r = x - if(y < 0) { - var n = y - (while(n != 0) { - r = r + 1 - n = n + 1 - }) invariant(r == x + y - n && 0 <= -n) - } else { - var n = y - (while(n != 0) { - r = r + 1 - n = n - 1 - }) invariant(r == x + y - n && 0 <= n) - } - r - }) ensuring(_ == x+y) - - def sum(n: BigInt): BigInt = { - require(n >= 0) - var r: BigInt = 0 - var i: BigInt = 0 - (while(i < n) { - i = i + 1 - r = r + i - }) invariant(r >= i && i >= 0 && r >= 0) - r - } ensuring(_ >= n) - - def divide(x: BigInt, y: BigInt): (BigInt, BigInt) = { - require(x >= 0 && y > 0) - var r = x - var q = BigInt(0) - (while(r >= y) { - r = r - y - q = q + 1 - }) invariant(x == y*q + r && r >= 0) - (q, r) - } ensuring(res => x == y*res._1 + res._2 && res._2 >= 0 && res._2 < y) - -} diff --git a/testcases/verification/xlang/ArrayBinarySearch.scala b/testcases/verification/xlang/ArrayBinarySearch.scala deleted file mode 100644 index cfeec91ea3400cf37364cd53266ad5d18838ddef..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/ArrayBinarySearch.scala +++ /dev/null @@ -1,59 +0,0 @@ -import leon.lang._ - -object BinarySearchFun { - - def binarySearch(a: Array[Int], key: Int, low: Int, high: Int): Int = ({ - require(a.length > 0 && sorted(a, low, high) && - 0 <= low && low <= high + 1 && high < a.length - ) - - if(low <= high) { - val i = (high + low) / 2 - val v = a(i) - - if(v == key) i - else if (v > key) binarySearch(a, key, low, i - 1) - else binarySearch(a, key, i + 1, high) - } else -1 - }) ensuring(res => - res >= -1 && - res < a.length && - (if (res >= 0) - a(res) == key else - (high < 0 || (!occurs(a, low, (high+low)/2, key) && !occurs(a, (high+low)/2, high, key))) - ) - ) - - - def occurs(a: Array[Int], from: Int, to: Int, key: Int): Boolean = { - require(a.length >= 0 && to <= a.length && from >= 0) - def rec(i: Int): Boolean = { - require(i >= 0) - if(i >= to) - false - else { - if(a(i) == key) true else rec(i+1) - } - } - if(from >= to) - false - else - rec(from) - } - - - def sorted(a: Array[Int], l: Int, u: Int) : Boolean = { - require(a.length >= 0 && l >= 0 && l <= u + 1 && u < a.length) - val t = sortedWhile(true, l, l, u, a) - t._1 - } - - def sortedWhile(isSorted: Boolean, k: Int, l: Int, u: Int, a: Array[Int]): (Boolean, Int) = { - require(a.length >= 0 && l >= 0 && l <= u+1 && u < a.length && k >= l && k <= u + 1) - if(k < u) { - sortedWhile(if(a(k) > a(k + 1)) false else isSorted, k + 1, l, u, a) - } else (isSorted, k) - } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/xlang/ArrayBinarySearchProcedural.scala b/testcases/verification/xlang/ArrayBinarySearchProcedural.scala deleted file mode 100644 index e1495e2d8bf302e29ad52f81d891ce417730717f..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/ArrayBinarySearchProcedural.scala +++ /dev/null @@ -1,72 +0,0 @@ -import leon.lang._ - -/* VSTTE 2008 - Dafny paper */ - -object BinarySearch { - - def binarySearch(a: Array[Int], key: Int): Int = ({ - require(a.length > 0 && sorted(a, 0, a.length - 1)) - var low = 0 - var high = a.length - 1 - var res = -1 - - (while(low <= high && res == -1) { - val i = (high + low) / 2 - val v = a(i) - - if(v == key) - res = i - - if(v > key) - high = i - 1 - else if(v < key) - low = i + 1 - }) invariant( - res >= -1 && - res < a.length && - 0 <= low && - low <= high + 1 && - high >= -1 && - high < a.length && - (if (res >= 0) - a(res) == key else - (!occurs(a, 0, low, key) && !occurs(a, high + 1, a.length, key)) - ) - ) - res - }) ensuring(res => - res >= -1 && - res < a.length && - (if(res >= 0) a(res) == key else !occurs(a, 0, a.length, key))) - - - def occurs(a: Array[Int], from: Int, to: Int, key: Int): Boolean = { - require(a.length >= 0 && to <= a.length && from >= 0) - def rec(i: Int): Boolean = { - require(i >= 0) - if(i >= to) - false - else { - if(a(i) == key) true else rec(i+1) - } - } - if(from >= to) - false - else - rec(from) - } - - - def sorted(a: Array[Int], l: Int, u: Int) : Boolean = { - require(a.length >= 0 && l >= 0 && l <= u && u < a.length) - val t = sortedWhile(true, l, l, u, a) - t._1 - } - - def sortedWhile(isSorted: Boolean, k: Int, l: Int, u: Int, a: Array[Int]): (Boolean, Int) = { - require(a.length >= 0 && l >= 0 && l <= u && u < a.length && k >= l && k <= u) - if(k < u) { - sortedWhile(if(a(k) > a(k + 1)) false else isSorted, k + 1, l, u, a) - } else (isSorted, k) - } -} diff --git a/testcases/verification/xlang/AssociativeList.scala b/testcases/verification/xlang/AssociativeList.scala deleted file mode 100644 index 3810203c003589a036fb64fd8b949b737d4c2eaa..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/AssociativeList.scala +++ /dev/null @@ -1,97 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object AssociativeListImp { - sealed abstract class KeyValuePairAbs - case class KeyValuePair(key: Int, value: Int) extends KeyValuePairAbs - - sealed abstract class List - case class Cons(head: KeyValuePairAbs, tail: List) extends List - case class Nil() extends List - - sealed abstract class OptionInt - case class Some(i: Int) extends OptionInt - case class None() extends OptionInt - - def domain(l: List): Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(KeyValuePair(k,_), xs) => Set(k) ++ domain(xs) - } - - def findSpec(l: List, e: Int): OptionInt = l match { - case Nil() => None() - case Cons(KeyValuePair(k, v), xs) => if (k == e) Some(v) else find(xs, e) - } - - def findLast(l: List, e: Int): OptionInt = { - var res: OptionInt = None() - var l2 = l - while(!l2.isInstanceOf[Nil]) { - val Cons(KeyValuePair(k, v), tail) = l2 - l2 = tail - if(k == e) - res = Some(v) - } - res - } ensuring(res => findSpec(l, e) == res) - - def find(l: List, e: Int): OptionInt = { - var res: OptionInt = None() - var l2 = l - var seen: List = Nil() - (while(!l2.isInstanceOf[Nil]) { - val Cons(head@KeyValuePair(k, v), tail) = l2 - seen = Cons(head, seen) - l2 = tail - if(res == None() && k == e) - res = Some(v) - }) invariant((res match { - case Some(_) => domain(seen).contains(e) - case None() => !domain(seen).contains(e) - }) && domain(seen) ++ domain(l2) == domain(l)) - - res - } ensuring(res => res match { - case Some(_) => domain(l).contains(e) - case None() => !domain(l).contains(e) - }) - - def noDuplicates(l: List): Boolean = l match { - case Nil() => true - case Cons(KeyValuePair(k, v), xs) => find(xs, k) == None() && noDuplicates(xs) - } - - def updateElem(l: List, e: KeyValuePairAbs): List = { - var res: List = Nil() - var l2 = l - var found = false - val KeyValuePair(ek, ev) = e - (while(!l2.isInstanceOf[Nil]) { - val Cons(KeyValuePair(k, v), tail) = l2 - l2 = tail - if(k == ek) { - res = Cons(KeyValuePair(ek, ev), res) - found = true - } else { - res = Cons(KeyValuePair(k, v), res) - } - }) invariant( - (if(found) - domain(res) ++ domain(l2) == domain(l) ++ Set(ek) - else - domain(res) ++ domain(l2) == domain(l) - )) - if(!found) - Cons(KeyValuePair(ek, ev), res) - else - res - } ensuring(res => e match { - case KeyValuePair(k, v) => domain(res) == domain(l) ++ Set[Int](k) - }) - - @induct - def readOverWrite(l: List, k1: Int, k2: Int, e: Int) : Boolean = { - find(updateElem(l, KeyValuePair(k2,e)), k1) == (if (k1 == k2) Some(e) else find(l, k1)) - } //holds -} - diff --git a/testcases/verification/xlang/BankSimpleTransactions.scala b/testcases/verification/xlang/BankSimpleTransactions.scala deleted file mode 100644 index 46a4d6a2be909b548e9064455f10b6c095080b90..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/BankSimpleTransactions.scala +++ /dev/null @@ -1,73 +0,0 @@ -import leon.lang._ - -object BankSimpleTransactions { - - def okTransaction(): Unit = { - var balance: BigInt = 0 - - def balanceInvariant: Boolean = balance >= 0 - - def deposit(x: BigInt): Unit = { - require(balanceInvariant && x >= 0) - balance += x - } ensuring(_ => balance == old(balance) + x && balanceInvariant) - - def withdrawal(x: BigInt): Unit = { - require(balanceInvariant && x >= 0 && x <= balance) - balance -= x - } ensuring(_ => balance == old(balance) - x && balanceInvariant) - - deposit(35) - withdrawal(30) - } - - def invalidTransaction(): Unit = { - var balance: BigInt = 0 - - def balanceInvariant: Boolean = balance >= 0 - - def deposit(x: BigInt): Unit = { - require(balanceInvariant && x >= 0) - balance += x - } ensuring(_ => balance == old(balance) + x && balanceInvariant) - - def withdrawal(x: BigInt): Unit = { - require(balanceInvariant && x >= 0 && x <= balance) - balance -= x - } ensuring(_ => balance == old(balance) - x && balanceInvariant) - - deposit(35) - withdrawal(40) - } - - - def internalTransfer(): Unit = { - var checking: BigInt = 0 - var saving: BigInt = 0 - - def balance = checking + saving - - def balanceInvariant: Boolean = balance >= 0 - - def deposit(x: BigInt): Unit = { - require(balanceInvariant && x >= 0) - checking += x - } ensuring(_ => checking == old(checking) + x && balanceInvariant) - - def withdrawal(x: BigInt): Unit = { - require(balanceInvariant && x >= 0 && x <= checking) - checking -= x - } ensuring(_ => checking == old(checking) - x && balanceInvariant) - - def checkingToSaving(x: BigInt): Unit = { - require(balanceInvariant && x >= 0 && checking >= x) - checking -= x - saving += x - } ensuring(_ => checking + saving == old(checking) + old(saving) && balanceInvariant) - - deposit(50) - withdrawal(30) - checkingToSaving(10) - } - -} diff --git a/testcases/verification/xlang/BankTransfer.scala b/testcases/verification/xlang/BankTransfer.scala deleted file mode 100644 index 2044df06ae01907a0df26e876ae4784feab6b0ce..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/BankTransfer.scala +++ /dev/null @@ -1,40 +0,0 @@ -import leon.lang._ - -object BankTransfer { - - case class BankAccount(var checking: BigInt, var saving: BigInt) { - require(checking >= 0 && saving >= 0) - - def balance: BigInt = checking + saving - } - - //TODO: support for map references to mutable items - //case class Bank(accounts: Map[BigInt, BankAccount]) - - - def deposit(x: BigInt, account: BankAccount): Unit = { - require(x > 0) - account.checking = account.checking + x - } ensuring(_ => account.balance == old(account).balance + x) - - def withdrawal(x: BigInt, account: BankAccount): Unit = { - require(x > 0 && account.checking >= x) - account.checking = account.checking - x - } ensuring(_ => account.balance == old(account).balance - x) - - def transfer(x: BigInt, a1: BankAccount, a2: BankAccount): Unit = { - require(x > 0 && a1.checking >= x) - withdrawal(x, a1) - deposit(x, a2) - } ensuring(_ => a1.balance + a2.balance == old(a1).balance + old(a2).balance && - a1.balance == old(a1).balance - x && - a2.balance == old(a2).balance + x) - - - def save(x: BigInt, account: BankAccount): Unit = { - require(x > 0 && account.checking >= x) - account.checking = account.checking - x - account.saving = account.saving + x - } ensuring(_ => account.balance == old(account).balance) - -} diff --git a/testcases/verification/xlang/BinaryTreeImp.scala b/testcases/verification/xlang/BinaryTreeImp.scala deleted file mode 100644 index b731586da823e78bb590ecc92f856442f9f7ce2c..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/BinaryTreeImp.scala +++ /dev/null @@ -1,100 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object BinaryTree { - - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(left: Tree, value: Int, right: Tree) extends Tree - - sealed abstract class OptionInt - case class Some(v : Int) extends OptionInt - case class None() extends OptionInt - - def content(t: Tree) : Set[Int] = t match { - case Leaf() => Set.empty - case Node(l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : Int = (t match { - case Leaf() => 0 - case Node(l, v, r) => size(l) + 1 + size(r) - }) ensuring(_ >= 0) - - def binaryTreeProp(t: Tree): Boolean = t match { - case Leaf() => true - case Node(left, value, right) => { - val b1 = left match { - case Leaf() => true - case Node(a,b,c) => value >= treeMax(Node(a,b,c)) - } - val b2 = right match { - case Leaf() => true - case Node(a,b,c) => value <= treeMin(Node(a,b,c)) - } - binaryTreeProp(left) && binaryTreeProp(right) && b1 && b2 - } - } - - def treeMin(tree: Node): Int = { - require(binaryTreeProp(tree)) - tree match { - case Node(left, value, _) => left match { - case Leaf() => value - case Node(l, v, r) => treeMin(Node(l, v, r)) - } - } - } ensuring(content(tree).contains(_)) - - //def treeMin(tree: Node): Int = { - // require(binaryTreeProp(tree)) - // val Node(left, value, _) = tree - // var res = value - // var tmpLeft = left - // (while(!tmpLeft.isInstanceOf[Leaf]) { - // val Node(left, value, _) = tmpLeft - // res = value - // tmpLeft = left - // }) invariant(content(tmpLeft).contains(res)) - // res - //} ensuring(content(tree).contains(_)) - - def treeMax(tree: Node): Int = { - require(binaryTreeProp(tree)) - tree match { - case Node(_, v, right) => right match { - case Leaf() => v - case Node(l, v, r) => treeMax(Node(l, v, r)) - } - } - } ensuring(content(tree).contains(_)) - - - def search(t: Tree, x: Int): Boolean = { - require(binaryTreeProp(t)) - t match { - case Leaf() => false - case Node(left, value, right) => - if(value == x) true - else if(value < x) search(right, x) - else search(left, x) - } - } ensuring(res => res == content(t).contains(x)) - - def searchImp(t: Tree, x: Int): Boolean = { - require(binaryTreeProp(t)) - var res = false - var t2: Tree = t - (while(!t2.isInstanceOf[Leaf]) { - val Node(left, value, right) = t2 - if(value == x) - res = true - else if(value < x) - t2 = right - else - t2 = left - }) - res - } ensuring(res => res == content(t).contains(x)) - -} diff --git a/testcases/verification/xlang/BubbleFun.scala b/testcases/verification/xlang/BubbleFun.scala deleted file mode 100644 index a7c72648cd6c5ca3d26584ab33bcb6624d5e8432..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/BubbleFun.scala +++ /dev/null @@ -1,157 +0,0 @@ -import leon.lang._ - -object BubbleFun { - - // --------------------- sort ---------------------- - - def sort(a: Map[Int,Int], size: Int): Map[Int,Int] = ({ - require(isArray(a, size) && size < 5) - - val i = size - 1 - val t = sortWhile(0, a, i, size) - t._2 - }) ensuring(res => isArray(res, size) && sorted(res, size, 0, size-1) /*&& content(res, size) == content(a, size)*/) - - def sortWhile(j: Int, sortedArray: Map[Int,Int], i: Int, size: Int) : (Int, Map[Int,Int], Int) = ({ - require(i >= 0 && i < size && isArray(sortedArray, size) && size < 5 && - sorted(sortedArray, size, i, size - 1) && - partitioned(sortedArray, size, 0, i, i+1, size-1)) - - if (i > 0) { - val t = sortNestedWhile(sortedArray, 0, i, size) - sortWhile(t._2, t._1, i - 1, size) - } else (j, sortedArray, i) - }) ensuring(res => isArray(res._2, size) && - sorted(res._2, size, res._3, size - 1) && - partitioned(res._2, size, 0, res._3, res._3+1, size-1) && - res._3 >= 0 && res._3 <= 0 /*&& content(res._2, size) == content(sortedArray, size)*/ - ) - - - def sortNestedWhile(sortedArray: Map[Int,Int], j: Int, i: Int, size: Int) : (Map[Int,Int], Int) = ({ - require(j >= 0 && j <= i && i < size && isArray(sortedArray, size) && size < 5 && - sorted(sortedArray, size, i, size - 1) && - partitioned(sortedArray, size, 0, i, i+1, size-1) && - partitioned(sortedArray, size, 0, j-1, j, j)) - if(j < i) { - val newSortedArray = - if(sortedArray(j) > sortedArray(j + 1)) - sortedArray.updated(j, sortedArray(j + 1)).updated(j+1, sortedArray(j)) - else - sortedArray - sortNestedWhile(newSortedArray, j + 1, i, size) - } else (sortedArray, j) - }) ensuring(res => isArray(res._1, size) && - sorted(res._1, size, i, size - 1) && - partitioned(res._1, size, 0, i, i+1, size-1) && - partitioned(res._1, size, 0, res._2-1, res._2, res._2) && - res._2 >= i && res._2 >= 0 && res._2 <= i /*&& content(res._1, size) == content(sortedArray, size)*/) - - - //some intermediate results - def lemma1(a: Map[Int, Int], size: Int, i: Int): Boolean = ({ - require(isArray(a, size) && size < 5 && sorted(a, size, i, size-1) && partitioned(a, size, 0, i, i+1, size-1) && i >= 0 && i < size) - val t = sortNestedWhile(a, 0, i, size) - val newJ = t._2 - i == newJ - }) ensuring(_ == true) - def lemma2(a: Map[Int, Int], size: Int, i: Int): Boolean = ({ - require(isArray(a, size) && size < 5 && sorted(a, size, i, size-1) && partitioned(a, size, 0, i, i+1, size-1) && i >= 0 && i < size) - val t = sortNestedWhile(a, 0, i, size) - val newA = t._1 - val newJ = t._2 - partitioned(newA, size, 0, i-1, i, i) - }) ensuring(_ == true) - def lemma3(a: Map[Int, Int], size: Int, i: Int): Boolean = ({ - require(partitioned(a, size, 0, i, i+1, size-1) && partitioned(a, size, 0, i-1, i, i) && isArray(a, size) && size < 5 && i >= 0 && i < size) - partitioned(a, size, 0, i-1, i, size-1) - }) ensuring(_ == true) - def lemma4(a: Map[Int, Int], size: Int, i: Int): Boolean = ({ - require(isArray(a, size) && size < 5 && sorted(a, size, i, size-1) && partitioned(a, size, 0, i, i+1, size-1) && i >= 0 && i < size) - val t = sortNestedWhile(a, 0, i, size) - val newA = t._1 - partitioned(newA, size, 0, i-1, i, size-1) - }) ensuring(_ == true) - - - // --------------------- sorted -------------------- - def sorted(a: Map[Int,Int], size: Int, l: Int, u: Int) : Boolean = { - require(isArray(a, size) && size < 5 && l >= 0 && l <= u && u < size) - val t = sortedWhile(true, l, l, u, a, size) - t._1 - } - - def sortedWhile(isSorted: Boolean, k: Int, l: Int, u: Int, a: Map[Int,Int], size: Int) : (Boolean, Int) = { - require(isArray(a, size) && size < 5 && l >= 0 && l <= u && u < size && k >= l && k <= u) - if(k < u) { - sortedWhile(if(a(k) > a(k + 1)) false else isSorted, k + 1, l, u, a, size) - } else (isSorted, k) - } - - - - // ------------- partitioned ------------------ - def partitioned(a: Map[Int,Int], size: Int, l1: Int, u1: Int, l2: Int, u2: Int) : Boolean = { - require(isArray(a, size) && size < 5 && l1 >= 0 && u1 < l2 && u2 < size) - if(l2 > u2 || l1 > u1) - true - else { - val t = partitionedWhile(l2, true, l1, l1, size, u2, l2, u1, a) - t._2 - } - } - def partitionedWhile(j: Int, isPartitionned: Boolean, i: Int, l1: Int, size: Int, u2: Int, l2: Int, u1: Int, a: Map[Int,Int]) : (Int, Boolean, Int) = { - require(isArray(a, size) && size < 5 && l1 >= 0 && l1 <= u1 && u1 < l2 && l2 <= u2 && u2 < size && i >= l1) - - if(i <= u1) { - val t = partitionedNestedWhile(isPartitionned, l2, i, l1, u1, size, u2, a, l2) - partitionedWhile(t._2, t._1, i + 1, l1, size, u2, l2, u1, a) - } else (j, isPartitionned, i) - } - def partitionedNestedWhile(isPartitionned: Boolean, j: Int, i: Int, l1: Int, u1: Int, size: Int, u2: Int, a: Map[Int,Int], l2: Int): (Boolean, Int) = { - require(isArray(a, size) && size < 5 && l1 >= 0 && l1 <= u1 && u1 < l2 && l2 <= u2 && u2 < size && j >= l2 && i >= l1 && i <= u1) - - if (j <= u2) { - partitionedNestedWhile( - (if (a(i) > a(j)) - false - else - isPartitionned), - j + 1, i, l1, u1, size, u2, a, l2) - } else (isPartitionned, j) - } - - - //------------ isArray ------------------- - def isArray(a: Map[Int,Int], size: Int): Boolean = - if(size <= 0) - false - else - isArrayRec(0, size, a) - - def isArrayRec(i: Int, size: Int, a: Map[Int,Int]): Boolean = - if (i >= size) - true - else { - if(a.isDefinedAt(i)) - isArrayRec(i + 1, size, a) - else - false - } - - - // ----------------- content ------------------ - def content(a: Map[Int, Int], size: Int): Set[Int] = { - require(isArray(a, size) && size < 5) - contentRec(a, size, 0) - } - - def contentRec(a: Map[Int, Int], size: Int, i: Int): Set[Int] = { - require(isArray(a, size) && i >= 0) - if(i < size) - Set(a(i)) ++ contentRec(a, size, i+1) - else - Set.empty[Int] - } - -} diff --git a/testcases/verification/xlang/BubbleWeakInvariant.scala b/testcases/verification/xlang/BubbleWeakInvariant.scala deleted file mode 100644 index 36b88b1f30221b737e7118ea779a05b18f4dafea..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/BubbleWeakInvariant.scala +++ /dev/null @@ -1,132 +0,0 @@ -import leon.lang._ - -/* The calculus of Computation textbook */ - -object Bubble { - - def sort(a: Map[Int, Int], size: Int): Map[Int, Int] = ({ - require(size < 5 && isArray(a, size)) - var i = size - 1 - var j = 0 - var sortedArray = a - (while(i > 0) { - j = 0 - (while(j < i) { - if(sortedArray(j) > sortedArray(j+1)) { - val tmp = sortedArray(j) - sortedArray = sortedArray.updated(j, sortedArray(j+1)) - sortedArray = sortedArray.updated(j+1, tmp) - } - j = j + 1 - }) invariant( - j >= 0 && - j <= i && - i < size && - isArray(sortedArray, size) && - partitioned(sortedArray, size, 0, i, i+1, size-1) && - //partitioned(sortedArray, size, 0, j-1, j, j) && - sorted(sortedArray, size, i, size-1) - ) - i = i - 1 - }) invariant( - i >= 0 && - i < size && - isArray(sortedArray, size) && - partitioned(sortedArray, size, 0, i, i+1, size-1) && - sorted(sortedArray, size, i, size-1) - ) - sortedArray - }) ensuring(res => sorted(res, size, 0, size-1)) - - def sorted(a: Map[Int, Int], size: Int, l: Int, u: Int): Boolean = { - require(isArray(a, size) && size < 5 && l >= 0 && u < size && l <= u) - var k = l - var isSorted = true - (while(k < u) { - if(a(k) > a(k+1)) - isSorted = false - k = k + 1 - }) invariant(k <= u && k >= l) - isSorted - } - /* - // --------------------- sorted -------------------- - def sorted(a: Map[Int,Int], size: Int, l: Int, u: Int) : Boolean = { - require(isArray(a, size) && size < 5 && l >= 0 && l <= u && u < size) - val t = sortedWhile(true, l, l, u, a, size) - t._1 - } - - def sortedWhile(isSorted: Boolean, k: Int, l: Int, u: Int, a: Map[Int,Int], size: Int) : (Boolean, Int) = { - require(isArray(a, size) && size < 5 && l >= 0 && l <= u && u < size && k >= l && k <= u) - if(k < u) { - sortedWhile(if(a(k) > a(k + 1)) false else isSorted, k + 1, l, u, a, size) - } else (isSorted, k) - } - */ - - /* - // ------------- partitioned ------------------ - def partitioned(a: Map[Int,Int], size: Int, l1: Int, u1: Int, l2: Int, u2: Int) : Boolean = { - require(isArray(a, size) && size < 5 && l1 >= 0 && u1 < l2 && u2 < size) - if(l2 > u2 || l1 > u1) - true - else { - val t = partitionedWhile(l2, true, l1, l1, size, u2, l2, u1, a) - t._2 - } - } - def partitionedWhile(j: Int, isPartitionned: Boolean, i: Int, l1: Int, size: Int, u2: Int, l2: Int, u1: Int, a: Map[Int,Int]) : (Int, Boolean, Int) = { - require(isArray(a, size) && size < 5 && l1 >= 0 && l1 <= u1 && u1 < l2 && l2 <= u2 && u2 < size && i >= l1) - - if(i <= u1) { - val t = partitionedNestedWhile(isPartitionned, l2, i, l1, u1, size, u2, a, l2) - partitionedWhile(t._2, t._1, i + 1, l1, size, u2, l2, u1, a) - } else (j, isPartitionned, i) - } - def partitionedNestedWhile(isPartitionned: Boolean, j: Int, i: Int, l1: Int, u1: Int, size: Int, u2: Int, a: Map[Int,Int], l2: Int): (Boolean, Int) = { - require(isArray(a, size) && size < 5 && l1 >= 0 && l1 <= u1 && u1 < l2 && l2 <= u2 && u2 < size && j >= l2 && i >= l1 && i <= u1) - - if (j <= u2) { - partitionedNestedWhile( - (if (a(i) > a(j)) - false - else - isPartitionned), - j + 1, i, l1, u1, size, u2, a, l2) - } else (isPartitionned, j) - } - */ - - def partitioned(a: Map[Int, Int], size: Int, l1: Int, u1: Int, l2: Int, u2: Int): Boolean = { - require(l1 >= 0 && u1 < l2 && u2 < size && isArray(a, size) && size < 5) - if(l2 > u2 || l1 > u1) - true - else { - var i = l1 - var j = l2 - var isPartitionned = true - (while(i <= u1) { - j = l2 - (while(j <= u2) { - if(a(i) > a(j)) - isPartitionned = false - j = j + 1 - }) invariant(j >= l2 && i <= u1) - i = i + 1 - }) invariant(i >= l1) - isPartitionned - } - } - - def isArray(a: Map[Int, Int], size: Int): Boolean = { - def rec(i: Int): Boolean = if(i >= size) true else { - if(a.isDefinedAt(i)) rec(i+1) else false - } - if(size <= 0) - false - else - rec(0) - } - -} diff --git a/testcases/verification/xlang/DataRacing.scala b/testcases/verification/xlang/DataRacing.scala deleted file mode 100644 index f709c2be6eb30a6b2df5b6f25250b9542bcf54db..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/DataRacing.scala +++ /dev/null @@ -1,48 +0,0 @@ -import leon.lang._ -import leon.lang.xlang._ -import leon.util.Random - -import leon.collection._ - -object DataRacing { - - case class SharedState(var i: Int) - - case class AtomicInstr(instr: (SharedState) => Unit) - - implicit def toInstr(instr: (SharedState) => Unit): AtomicInstr = AtomicInstr(instr) - - abstract class Runnable - case class RunnableCons(instr: AtomicInstr, tail: Runnable) extends Runnable - case class RunnableNil() extends Runnable - - def execute(t1: Runnable, t2: Runnable, state: SharedState)(implicit randomState: Random.State): Unit = (t1, t2) match { - case (RunnableCons(x,xs), RunnableCons(y,ys)) => - if(Random.nextBoolean) { - x.instr(state) - execute(xs, RunnableCons(y,ys), state) - } else { - y.instr(state) - execute(RunnableCons(x,xs), ys, state) - } - case (RunnableNil(), RunnableCons(y,ys)) => - y.instr(state) - execute(RunnableNil(), ys, state) - case (RunnableCons(x,xs), RunnableNil()) => - x.instr(state) - execute(xs, RunnableNil(), state) - case (RunnableNil(), RunnableNil()) => () - } - - //z3 finds counterexample in 0.5 - //cvc4 needs 130 seconds - def main(): Int = { - implicit val randomState = Random.newState - val state = SharedState(0) - val t1 = RunnableCons((s: SharedState) => s.i = s.i + 1, RunnableNil()) - val t2 = RunnableCons((s: SharedState) => s.i = s.i * 2, RunnableNil()) - execute(t1, t2, state) - state.i - } ensuring(_ == 2) - -} diff --git a/testcases/verification/xlang/FunctionCaching.scala b/testcases/verification/xlang/FunctionCaching.scala deleted file mode 100644 index 75c73e822831a5d7da9a209f1964d36e10298359..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/FunctionCaching.scala +++ /dev/null @@ -1,40 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object FunctionCaching { - - case class CachedFun[A,B](fun: (A) => B, var cached: Map[A, B], var cacheHit: Set[A]) { - - def call(a: A): B = { - cached.get(a) match { - case None() => - val res = fun(a) - cached = cached.updated(a, res) - res - case Some(res) => - cacheHit = cacheHit ++ Set(a) - res - } - } - - } - - def funProperlyCached(x: BigInt, fun: (BigInt) => BigInt, trash: List[BigInt]): Boolean = { - val cachedFun = CachedFun[BigInt, BigInt](fun, Map(), Set()) - val res1 = cachedFun.call(x) - multipleCalls(trash, cachedFun, x) - val res2 = cachedFun.call(x) - res1 == res2 && cachedFun.cacheHit.contains(x) - } holds - - def multipleCalls(args: List[BigInt], cachedFun: CachedFun[BigInt, BigInt], x: BigInt): Unit = { - require(cachedFun.cached.isDefinedAt(x)) - args match { - case Nil() => () - case y::ys => - cachedFun.call(x) - multipleCalls(ys, cachedFun, x) - } - } ensuring(_ => old(cachedFun).cached.get(x) == cachedFun.cached.get(x)) - -} diff --git a/testcases/verification/xlang/HashTables.scala b/testcases/verification/xlang/HashTables.scala deleted file mode 100644 index b70cc9dc1deffcb4964a7e949d8ba97eb78135bd..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/HashTables.scala +++ /dev/null @@ -1,75 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -object HashTables { - - @extern - def hashingWrapper(x: BigInt, length: Int)(hashFun: (BigInt) => Int): Int = { - hashFun(x) % length - } ensuring(res => res >= 0 && res < length) - - - case class HashTable(table: Array[List[BigInt]], hashFun: (BigInt) => Int, var content: Set[BigInt]) { - require(table.length > 0 && table.length < 6 && - forall((i:Int, x: BigInt) => - ((0 <= i && i < table.length && table(i).content.contains(x)) ==> (hashing(x) == i))) - //this extra forall makes the unrolling step too slow - //forall((x: BigInt) => - //content.contains(x) ==> table(hashing(x)).content.contains(x)) - ) - - //def content: Set[BigInt] = { - // def rec(index: Int): Set[BigInt] = { - // require(index >= 0 && index <= table.length) - // if(index == table.length) Set() else table(index).content ++ rec(index+1) - // } - // rec(0) - //} - - //this has issues, first the % sometimes return negative number. If we - //try to fix by annotating with @extern, the method gets lifted to a - //function that takes this (HashTable) as a parameter, and will not be - //deterministic (return a different value after an insert in the HT) - //def hashing(x: BigInt) : Int = { - // hashFun(x) % table.length - //} ensuring(res => res >= 0 && res < table.length) - - def hashing(x: BigInt): Int = hashingWrapper(x, table.length)(hashFun) - - def apply(index: Int): List[BigInt] = { - require(index >= 0 && index < table.length) - table(index) - } - - def insert(x: BigInt): Unit = { - val index = hashing(x) - table(index) = (x::table(index)) - content += x - } ensuring(_ => table(hashing(x)).contains(x) && this.content == old(this).content ++ Set(x)) - - def contains(x: BigInt): Boolean = { - val index = hashing(x) - table(index).contains(x) - } ensuring(res => res == this.content.contains(x)) - } - - def test(ht: HashTable): Boolean = { - ht.insert(4) - ht.insert(6) - ht.insert(7) - ht.insert(5) - ht.contains(4) - } ensuring(res => res) - - def testHarness(ht: HashTable, x1: BigInt, x2: BigInt, x3: BigInt): Boolean = { - ht.insert(x1) - ht.insert(x2) - ht.insert(x3) - ht.contains(x1) && ht.contains(x2) && ht.contains(x3) - } holds - - - //case class HashTableMap(table: Array[List[BigInt]], hashFun: (BigInt) => Int) { - // def content: Map[BigInt, Int] -} diff --git a/testcases/verification/xlang/InsertionSort.scala b/testcases/verification/xlang/InsertionSort.scala deleted file mode 100644 index 71dab126cda6927380c9395b39dcc49f3a550801..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/InsertionSort.scala +++ /dev/null @@ -1,107 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object InsertionSort { - sealed abstract class List - case class Cons(head:Int,tail:List) extends List - case class Nil() extends List - - sealed abstract class OptInt - case class Some(value: Int) extends OptInt - case class None() extends OptInt - - def size(l : List) : Int = (l match { - case Nil() => 0 - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contents(l: List): Set[Int] = l match { - case Nil() => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - def min(l : List) : OptInt = l match { - case Nil() => None() - case Cons(x, xs) => min(xs) match { - case None() => Some(x) - case Some(x2) => if(x < x2) Some(x) else Some(x2) - } - } - - 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 isReversedSorted(l: List): Boolean = l match { - case Nil() => true - case Cons(x, Nil()) => true - case Cons(x, Cons(y, ys)) => x >= y && isReversedSorted(Cons(y, ys)) - } - - def reverse(l: List): List = { - var r: List = Nil() - var l2: List = l - - (while(!l2.isInstanceOf[Nil]) { - val Cons(head, tail) = l2 - l2 = tail - r = Cons(head, r) - }) invariant(contents(r) ++ contents(l2) == contents(l) && size(r) + size(l2) == size(l) && - (if(isSorted(l)) isReversedSorted(r) else true)) - - r - } ensuring(res => contents(res) == contents(l) && size(res) == size(l) && - (if(isSorted(l)) isReversedSorted(res) else true)) - - def reverseSortedSpec(l: List): List = { - require(isSorted(l)) - reverse(l) - } ensuring(res => isReversedSorted(res)) - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def sortedIns(e: Int, l: List): List = { - require(isSorted(l)) - l match { - case Nil() => Cons(e,Nil()) - case Cons(x,xs) => if (x <= e) Cons(x,sortedIns(e, xs)) else Cons(e, l) - } - } ensuring(res => contents(res) == contents(l) ++ Set(e) - && isSorted(res) - && size(res) == size(l) + 1 - ) - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def buggySortedIns(e: Int, l: List): List = { - // require(isSorted(l)) - l match { - case Nil() => Cons(e,Nil()) - case Cons(x,xs) => if (x <= e) Cons(x,buggySortedIns(e, xs)) else Cons(e, l) - } - } ensuring(res => contents(res) == contents(l) ++ Set(e) - && isSorted(res) - && size(res) == size(l) + 1 - ) - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort(l: List): List = (l match { - case Nil() => Nil() - case Cons(x,xs) => sortedIns(x, sort(xs)) - }) ensuring(res => contents(res) == contents(l) - && isSorted(res) - && size(res) == size(l) - ) - - @ignore - def main(args: Array[String]): Unit = { - val ls: List = Cons(5, Cons(2, Cons(4, Cons(5, Cons(1, Cons(8,Nil())))))) - - println(ls) - println(sort(ls)) - } -} - -// vim: set ts=4 sw=4 et: diff --git a/testcases/verification/xlang/IntOperations.scala b/testcases/verification/xlang/IntOperations.scala deleted file mode 100644 index 91b3b636c23c59c4bc1b7d313ef419e41e3b9912..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/IntOperations.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.lang._ - -object IntOperations { - def sum(a: Int, b: Int) : Int = { - require(b >= 0) - val b2 = b - 1 - val b3 = b2 + 1 - a + b3 - } ensuring(_ >= a) - - - // The body of the following function is not in PureScala - // It will still get extracted, with "unknown body". - // To disable the warnings, run with -P:leon:tolerant - // (if it has a postcondition, you'll still get warnings - // about the impossibility of verifying them) - def factorial(v: Int) : Int = { - require(v >= 0) - var c = 2 - var t = 1 - while(c <= v) { - t = t * c - } - t - } ensuring(_ >= v) -} diff --git a/testcases/verification/xlang/LinearSearch.scala b/testcases/verification/xlang/LinearSearch.scala deleted file mode 100644 index 904a7c68a65ed777313eb0902dce503b2dafef7b..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/LinearSearch.scala +++ /dev/null @@ -1,39 +0,0 @@ -import leon.lang._ - -/* The calculus of Computation textbook */ - -object LinearSearch { - - def linearSearch(a: Array[Int], c: Int): Boolean = ({ - require(a.length >= 0) - var i = 0 - var found = false - (while(i < a.length) { - if(a(i) == c) - found = true - i = i + 1 - }) invariant( - i <= a.length && - i >= 0 && - (if(found) contains(a, i, c) else !contains(a, i, c)) - ) - found - }) ensuring(res => if(res) contains(a, a.length, c) else !contains(a, a.length, c)) - - def contains(a: Array[Int], size: Int, c: Int): Boolean = { - require(a.length >= 0 && size >= 0 && size <= a.length) - content(a, size).contains(c) - } - - def content(a: Array[Int], size: Int): Set[Int] = { - require(a.length >= 0 && size >= 0 && size <= a.length) - var set = Set.empty[Int] - var i = 0 - (while(i < size) { - set = set ++ Set(a(i)) - i = i + 1 - }) invariant(i >= 0 && i <= size) - set - } - -} diff --git a/testcases/verification/xlang/ListImp.scala b/testcases/verification/xlang/ListImp.scala deleted file mode 100644 index 620615321aca110ba25460987dc6076d0945f7ef..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/ListImp.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.lang._ - -object ListImp { - - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def size(l: List) : Int = { - var r = 0 - (while(!l.isInstanceOf[Nil]) { - r = r+1 - }) invariant(r >= 0) - r - } ensuring(res => res >= 0) - - def reverse(l: List): List = { - var r: List = Nil() - var l2: List = l - - (while(!l2.isInstanceOf[Nil]) { - val Cons(head, tail) = l2 - l2 = tail - r = Cons(head, r) - }) invariant(content(r) ++ content(l2) == content(l)) - - r - } ensuring(res => content(res) == content(l)) - - def append(l1 : List, l2 : List) : List = { - var r: List = l2 - var tmp: List = reverse(l1) - - (while(!tmp.isInstanceOf[Nil]) { - val Cons(head, tail) = tmp - tmp = tail - r = Cons(head, r) - }) invariant(content(r) ++ content(tmp) == content(l1) ++ content(l2)) - - r - } ensuring(content(_) == content(l1) ++ content(l2)) - - -} diff --git a/testcases/verification/xlang/ListOperations.scala b/testcases/verification/xlang/ListOperations.scala deleted file mode 100644 index 542129826108d067501c5298a0bf34ad125ac25a..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/ListOperations.scala +++ /dev/null @@ -1,146 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object ListOperationsImp { - - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - sealed abstract class IPList - case class IPCons(head: (Int, Int), tail: IPList) extends IPList - case class IPNil() extends IPList - - def content(l: List) : Set[Int] = l match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def iplContent(l: IPList) : Set[(Int, Int)] = l match { - case IPNil() => Set.empty[(Int, Int)] - case IPCons(x, xs) => Set(x) ++ iplContent(xs) - } - - def size(l: List) : Int = { - var r = 0 - var l2 = l - (while(!l2.isInstanceOf[Nil]) { - val Cons(_, tail) = l2 - l2 = tail - r = r+1 - }) invariant(r >= 0) - r - } ensuring(res => res >= 0) - - def sizeBuggy(l: List) : Int = { - var r = -1 - var l2 = l - (while(!l2.isInstanceOf[Nil]) { - val Cons(_, tail) = l2 - l2 = tail - r = r+1 - }) invariant(r >= 0) - r - } ensuring(res => res >= 0) - - //just to help for specification, makes sense since specification are not executed - def sizeFun(l: List) : Int = l match { - case Nil() => 0 - case Cons(_, t) => 1 + sizeFun(t) - } - def iplSizeFun(l: IPList) : Int = l match { - case IPNil() => 0 - case IPCons(_, t) => 1 + iplSizeFun(t) - } - - def iplSize(l: IPList) : Int = { - var r = 0 - var l2 = l - (while(!l2.isInstanceOf[IPNil]) { - val IPCons(_, tail) = l2 - l2 = tail - r = r+1 - }) invariant(r >= 0) - r - } ensuring(_ >= 0) - - def sizeStrongSpec(l: List): Int = { - var r = 0 - var l2 = l - (while(!l2.isInstanceOf[Nil]) { - val Cons(head, tail) = l2 - l2 = tail - r = r+1 - }) invariant(r == sizeFun(l) - sizeFun(l2)) - r - } ensuring(res => res == sizeFun(l)) - - def zip(l1: List, l2: List) : IPList = ({ - require(sizeFun(l1) == sizeFun(l2)) - var r: IPList = IPNil() - var ll1: List = l1 - var ll2 = l2 - - (while(!ll1.isInstanceOf[Nil]) { - val Cons(l1head, l1tail) = ll1 - val Cons(l2head, l2tail) = if(!ll2.isInstanceOf[Nil]) ll2 else Cons(0, Nil()) - r = IPCons((l1head, l2head), r) - ll1 = l1tail - ll2 = l2tail - }) invariant(iplSizeFun(r) + sizeFun(ll1) == sizeFun(l1)) - - iplReverse(r) - }) ensuring(res => iplSizeFun(res) == sizeFun(l1)) - - def drunk(l : List) : List = { - var r: List = Nil() - var l2 = l - (while(!l2.isInstanceOf[Nil]) { - val Cons(head, tail) = l2 - l2 = tail - r = Cons(head, Cons(head, r)) - }) invariant(sizeFun(r) == 2 * sizeFun(l) - 2 * sizeFun(l2)) - r - } ensuring (sizeFun(_) == 2 * sizeFun(l)) - - - def iplReverse(l: IPList): IPList = { - var r: IPList = IPNil() - var l2: IPList = l - - (while(!l2.isInstanceOf[IPNil]) { - val IPCons(head, tail) = l2 - l2 = tail - r = IPCons(head, r) - }) invariant(iplContent(r) ++ iplContent(l2) == iplContent(l) && iplSizeFun(r) + iplSizeFun(l2) == iplSizeFun(l)) - - r - } ensuring(res => iplContent(res) == iplContent(l) && iplSizeFun(res) == iplSizeFun(l)) - - def reverse(l: List): List = { - var r: List = Nil() - var l2: List = l - - (while(!l2.isInstanceOf[Nil]) { - val Cons(head, tail) = l2 - l2 = tail - r = Cons(head, r) - }) invariant(content(r) ++ content(l2) == content(l) && sizeFun(r) + sizeFun(l2) == sizeFun(l)) - - r - } ensuring(res => content(res) == content(l) && sizeFun(res) == sizeFun(l)) - - def append(l1 : List, l2 : List) : List = { - var r: List = l2 - var tmp: List = reverse(l1) - - (while(!tmp.isInstanceOf[Nil]) { - val Cons(head, tail) = tmp - tmp = tail - r = Cons(head, r) - }) invariant(content(r) ++ content(tmp) == content(l1) ++ content(l2)) - - r - } ensuring(content(_) == content(l1) ++ content(l2)) - -} diff --git a/testcases/verification/xlang/MaxSum.scala b/testcases/verification/xlang/MaxSum.scala deleted file mode 100644 index e00ea1c129ed0e80ccfb1550f6eb66b539fec6c0..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/MaxSum.scala +++ /dev/null @@ -1,23 +0,0 @@ -import leon.lang._ - -/* VSTTE 2010 challenge 1 */ - -object MaxSum { - - //not valid because of Int, unfortunately conversion between big int and - //int does not work and we cannot compute a.length * Max (Int * BigInt) - def maxSum(a: Array[Int]): (Int, Int) = { - require(a.length >= 0) - var sum = 0 - var max = 0 - var i = 0 - (while(i < a.length) { - if(max < a(i)) - max = a(i) - sum = sum + a(i) - i = i + 1 - }) invariant (sum <= i * max && i >= 0 && i <= a.length) - (sum, max) - } ensuring(res => res._1 <= a.length * res._2) - -} diff --git a/testcases/verification/xlang/MyArrays.scala b/testcases/verification/xlang/MyArrays.scala deleted file mode 100644 index 3c3cb7bb65d1e886340f358d49fbdd30db653fe1..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/MyArrays.scala +++ /dev/null @@ -1,32 +0,0 @@ -import leon.lang.Map - -object MyArrays { - - case class MyArray(var content: Map[BigInt, BigInt], size: BigInt) { - require(size >= 0) - - def apply(i: BigInt): BigInt = { - require(i >= 0 && i < size) - content(i) - } - - def set(i: BigInt, v: BigInt) = { - require(i >= 0 && i < size) - content = content + (i -> v) - } - - /* - * update seems to create a bug in Leon due to Scala magic syntax - * and some rewriting to updated inside leon. - */ - //def update(i: BigInt, v: BigInt) = { content = content + (i -> v) } - - } - - - def update(a: MyArray): Unit = { - require(a.size > 0) - a.set(0, 10) - } ensuring(_ => a(0) == 10) - -} diff --git a/testcases/verification/xlang/SFun.scala b/testcases/verification/xlang/SFun.scala deleted file mode 100644 index ff710bbdc5f65cd12749ce28f28281e57f011c46..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/SFun.scala +++ /dev/null @@ -1,87 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ - -object SFuns { - - case class State[A](var x: A) - - case class SFun[A, S, B](state: State[S], f: (A, State[S]) => B) { - def apply(x: A): B = f(x, state) - } - - - def counter(init: BigInt): SFun[BigInt, BigInt, BigInt] = { - val closure = SFun(State(init), (n: BigInt, s: State[BigInt]) => { - s.x += 1 - (s.x - 1) - }) - closure - } - - - def test(init: BigInt): Unit = { - val gen = counter(init) - val x1 = gen(0) - assert(x1 == init) - val x2 = gen(0) - assert(x2 == init+1) - val x3 = gen(0) - assert(x3 == init+2) - } - - - def window2(init: (BigInt, BigInt)): SFun[BigInt, (BigInt, BigInt), BigInt] = { - - //state is used to remember last 2 numbers seen, and return sum of last 3 - val closure = (n: BigInt, s: State[(BigInt, BigInt)]) => { - val res = n + s.x._1 + s.x._2 - s.x = (n, s.x._1) - res - } - - SFun(State(init), closure) - } - - def testWindow2(): Unit = { - val gen = window2((0, 0)) - val x1 = gen(1) - assert(x1 == 1) - val x2 = gen(1) - assert(x2 == 2) - val x3 = gen(2) - assert(x3 == 4) - val x4 = gen(2) - assert(x4 == 5) - } - - - def foreach[A, S](l: List[A], sf: SFun[A, S, Unit]): Unit = l match { - case x::xs => - sf(x) - foreach(xs, sf) - case Nil() => () - } - - def testForeach(): Unit = { - val l = List[BigInt](1,2,3,4,5) - val closure = SFun(State[BigInt](0), (n: BigInt, s: State[BigInt]) => { s.x += n }) - foreach(l, closure) - assert(closure.state.x == 15) - } - - - def makeCounter: SFun[Unit, BigInt, BigInt] = { - SFun(State(0), - (_: Unit, s: State[BigInt]) => { s.x += 1; s.x }) - } - def testCounter(): Unit = { - val counter = makeCounter - val x1 = counter(()) - assert(x1 == 1) - val x2 = counter(()) - assert(x2 == 2) - } - - -} diff --git a/testcases/verification/xlang/Sums.scala b/testcases/verification/xlang/Sums.scala deleted file mode 100644 index 1d6ad2e94f52a538b41f94b694e184fdfa2aa893..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/Sums.scala +++ /dev/null @@ -1,28 +0,0 @@ -import leon.lang._ - -object Sums { - - def summ(to : BigInt): BigInt = ({ - require(to >= 0) - var i: BigInt = 0 - var s: BigInt = 0 - (while (i < to) { - s = s + i - i = i + 1 - }) invariant (s >= 0 && i >= 0 && s == i*(i-1)/2 && i <= to) - s - }) ensuring(res => res >= 0 && res == to*(to-1)/2) - - - def sumsq(to : BigInt): BigInt = ({ - require(to >= 0) - var i: BigInt = 0 - var s: BigInt = 0 - (while (i < to) { - s = s + i*i - i = i + 1 - }) invariant (s >= 0 && i >= 0 && s == (i-1)*i*(2*i-1)/6 && i <= to) - s - }) ensuring(res => res >= 0 && res == (to-1)*to*(2*to-1)/6) - -} diff --git a/testcases/verification/xlang/io/GuessNumber.scala b/testcases/verification/xlang/io/GuessNumber.scala deleted file mode 100644 index 46bf0d99a556aef8e49bab51bbfa05553b89993b..0000000000000000000000000000000000000000 --- a/testcases/verification/xlang/io/GuessNumber.scala +++ /dev/null @@ -1,73 +0,0 @@ -import leon.lang._ -import leon.lang.xlang._ -import leon.io.StdIn - -import leon.annotation._ - -object GuessNumber { - - @extern - def pickBetween(bot: BigInt, top: BigInt): BigInt = { - require(bot <= top) - bot + (top - bot)/2 //works for execution - } ensuring(res => res >= bot && res <= top) - - def guessNumber(choice: Option[BigInt])(implicit state: StdIn.State): BigInt = { - require(choice match { case Some(c) => c >= 0 && c <= 10 case None() => true }) - var bot: BigInt = 0 - var top: BigInt = 10 - - (while(bot < top) { - val prevDec = top - bot - - val guess = pickBetween(bot, top-1) //never pick top, wouldn't learn anyting if pick top and if guess >= choice - if(isSmaller(guess, choice)) { - bot = guess+1 - } else { - top = guess - } - val dec = top - bot - assert(dec >= 0 && dec < prevDec) - }) invariant(choice match { - case Some(c) => bot >= 0 && top <= 10 && bot <= top && c >= bot && c <= top - case None() => true - }) - bot - } ensuring(answer => choice match { - case Some(c) => c == answer - case None() => true - }) - - @extern - def isGreater(guess: BigInt, choice: Option[BigInt])(implicit state: StdIn.State): Boolean = (choice match { - case None() => - print("Is it (strictly) smaller than " + guess + ": ") - StdIn.readBoolean - case Some(c) => guess > c - }) ensuring(res => choice match { case Some(c) => res == guess > c case None() => true }) - - @extern - def isSmaller(guess: BigInt, choice: Option[BigInt])(implicit state: StdIn.State): Boolean = (choice match { - case None() => - print("Is it (strictly) greater than " + guess + ": ") - StdIn.readBoolean - case Some(c) => guess < c - }) ensuring(res => choice match { case Some(c) => res == guess < c case None() => true }) - - def guessNumberValid(choice: BigInt): BigInt = { - require(choice >= 0 && choice <= 10) - implicit val ioState = StdIn.newState - guessNumber(Some(choice)) - } ensuring(_ == choice) - - @extern - def main(args: Array[String]): Unit = { - implicit val ioState = StdIn.newState - println("Think of a number between 0 and 10...") - println("Leon will try to guess it...") - val answer = guessNumber(None()) - println("Found: " + answer) - println("Goodbye") - } - -} diff --git a/testcases/web/demos/001_Tutorial-Max.scala b/testcases/web/demos/001_Tutorial-Max.scala deleted file mode 100644 index ba1aaca110227613b4a4e8a792f666e61119f440..0000000000000000000000000000000000000000 --- a/testcases/web/demos/001_Tutorial-Max.scala +++ /dev/null @@ -1,63 +0,0 @@ -import leon.lang.synthesis._ -import leon.annotation._ -object Max { - def max(x: Int, y: Int): Int = { - val d = x - y - if (d > 0) x - else y - } - // ensuring(res => (res == x || res == y)) - // x <= res && y <= res - - def test1 = max(10, 5) - def test2 = max(-5, 5) - def test3 = max(-5, -7) - - //def test4 = max(-1639624704, 1879048192) - -/* - def max(x: BigInt, y: BigInt): BigInt = { - val d = x - y - if (d > 0) x - else y - } ensuring(res => - x <= res && y <= res && (res == x || res == y)) - */ - -/* - def rmax(x: BigInt, y: BigInt) = - if (x <= y) x else y - - def max(x: BigInt, y: BigInt): BigInt = { - val d = x - y - if (d > 0) x - else y - } ensuring(res => res==rmax(x,y)) -*/ - -/* - def max_lemma(x: BigInt, y: BigInt, z: BigInt): Boolean = { - max(x,x) == x && - max(x,y) == max(y,x) && - max(x,max(y,z)) == max(max(x,y), z) && - max(x,y) + z == max(x + z, y + z) - } ensuring(_ == true) - // holds -*/ - -/* - def max(x: Int, y: Int): Int = { - require(0 <= x && 0 <= y) - val d = x - y - if (d > 0) x - else y - } ensuring (res => - x <= res && y <= res && (res == x || res == y)) -*/ - -/* - def max(x: BigInt, y: BigInt): BigInt = { - ???[BigInt] - } ensuring(res => (res == x || res == y) && x <= res && y <= res) -*/ -} diff --git a/testcases/web/demos/002_Tutorial-TwoSort.scala b/testcases/web/demos/002_Tutorial-TwoSort.scala deleted file mode 100644 index 5a20fc6e6b9557904ae8b3971006e55d36338a46..0000000000000000000000000000000000000000 --- a/testcases/web/demos/002_Tutorial-TwoSort.scala +++ /dev/null @@ -1,52 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ -object TwoSort { -/* - def sort2(x : BigInt, y : BigInt) = choose{(res: (BigInt,BigInt)) => - Set(x,y) == Set(res._1, res._2) && res._1 <= res._2 - } -*/ - -/* - def sort2(x : BigInt, y : BigInt) = { - ???[(BigInt, BigInt)] - } ensuring{(res: (BigInt,BigInt)) => - Set(x,y) == Set(res._1, res._2) && res._1 <= res._2 - } -*/ - - -// def testSort2 = sort2(30, 4) - -/* - def sort2(x: BigInt, y: BigInt) = choose{(res: (BigInt,BigInt)) => - sort2spec(x,y,res) - } - - def sort2spec(x: BigInt, y: BigInt, res: (BigInt, BigInt)): Boolean = { - Set(x,y) == Set(res._1, res._2) && res._1 <= res._2 - } - - def unique2(x: BigInt, y: BigInt, - res1: (BigInt, BigInt), - res2: (BigInt, BigInt)): Boolean = { - require(sort2spec(x,y,res1) && sort2spec(x,y,res2)) - res1 == res2 - } holds - */ - -/* - def sort3spec(x: BigInt, y: BigInt, z: BigInt, res: (BigInt,BigInt,BigInt)): Boolean = { - Set(x,y,z) == Set(res._1, res._2, res._3) && - res._1 <= res._2 && res._2 <= res._3 - } - - def unique3(x: BigInt, y: BigInt, z: BigInt, - res1: (BigInt,BigInt,BigInt), - res2: (BigInt,BigInt,BigInt)): Boolean = { - require(sort3spec(x,y,z,res1) && sort3spec(x,y,z,res2)) - res1 == res2 - }.holds - */ -} diff --git a/testcases/web/demos/003_Tutorial-Sort.scala b/testcases/web/demos/003_Tutorial-Sort.scala deleted file mode 100644 index aa5629f9b676f63c968972fb0a0b61b0696df1fa..0000000000000000000000000000000000000000 --- a/testcases/web/demos/003_Tutorial-Sort.scala +++ /dev/null @@ -1,74 +0,0 @@ -import leon.lang.Set -import leon.lang.synthesis._ -object Sort { - sealed abstract class List - case object Nil extends List - case class Cons(head: BigInt, tail: List) extends List - - def content(l: List): Set[BigInt] = l match { - case Nil => Set() - case Cons(i, t) => Set(i) ++ content(t) - } - def c1 = content(Cons(15, Cons(5, Cons(15, Nil)))) - - def isSorted(l: List): Boolean = l match { - case Nil => true - case Cons(_,Nil) => true - case Cons(x1, Cons(x2, rest)) => - x1 < x2 && isSorted(Cons(x2,rest)) - } - def t1 = isSorted(Cons(10, Cons(20, Nil))) - def t2 = isSorted(Cons(15, Cons(15, Nil))) - -/* - def sortMagic(l: List) = { - ???[List] - } ensuring((res:List) => - isSorted(res) && content(res) == content(l)) -*/ - - // def mm = sortMagic(Cons(20, Cons(5, Cons(50, Cons(2, Nil))))) - // try replacing 50 with 5 - - - - - -/* - def sInsert(x: BigInt, l: List): List = { - require(isSorted(l)) - l match { - case Nil => Cons(x, Nil) - case Cons(e, rest) if (x == e) => l - case Cons(e, rest) if (x < e) => Cons(x, Cons(e,rest)) - case Cons(e, rest) if (x > e) => Cons(e, sInsert(x,rest)) - } - } ensuring {(res:List) => - isSorted(res) && content(res) == content(l) ++ Set(x)} -*/ - - // We can also synthesize the body of sInsert interactively - -/* - def sInsert(x: BigInt, l: List): List = { - require(isSorted(l)) - ???[List] - } ensuring {(res:List) => - isSorted(res) && content(res) == content(l) ++ Set(x)} - */ - - // Fully automatic synthesis of sInsert also works - -/* - // Or, we can repair an incorrect (overly simplified) program - def sInsert(x: BigInt, l: List): List = { - require(isSorted(l)) - l match { - case Nil => Cons(x, Nil) - case Cons(e, rest) => Cons(e, sInsert(x,rest)) - } - } ensuring {(res:List) => - isSorted(res) && content(res) == content(l) ++ Set(x)} - */ - -} diff --git a/testcases/web/demos/004_Tutorial-ListA.scala b/testcases/web/demos/004_Tutorial-ListA.scala deleted file mode 100644 index 3adf03f7a470f9691edb5a1aaaba1f76b61eacfe..0000000000000000000000000000000000000000 --- a/testcases/web/demos/004_Tutorial-ListA.scala +++ /dev/null @@ -1,701 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ -import leon.annotation._ -import leon.math._ - -sealed abstract class List[T] { - - def size: BigInt = (this match { - case Nil() => BigInt(0) - case Cons(h, t) => 1 + t.size - }) ensuring (_ >= 0) - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def contains(v: T): Boolean = (this match { - case Cons(h, t) if h == v => true - case Cons(_, t) => t.contains(v) - case Nil() => false - }) ensuring { _ == (content contains v) } - - def ++(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(x, xs) => Cons(x, xs ++ that) - }) ensuring { res => - (res.content == this.content ++ that.content) && - (res.size == this.size + that.size) && - (that != Nil[T]() || res == this) - } - - def head: T = { - require(this != Nil[T]()) - val Cons(h, _) = this - h - } - - def tail: List[T] = { - require(this != Nil[T]()) - val Cons(_, t) = this - t - } - - def apply(index: BigInt): T = { - require(0 <= index && index < size) - if (index == BigInt(0)) { - head - } else { - tail(index-1) - } - } - - def ::(t:T): List[T] = Cons(t, this) - - def :+(t:T): List[T] = { - this match { - case Nil() => Cons(t, this) - case Cons(x, xs) => Cons(x, xs :+ (t)) - } - } ensuring(res => (res.size == size + 1) && (res.content == content ++ Set(t))) - - def reverse: List[T] = { - this match { - case Nil() => this - case Cons(x,xs) => xs.reverse :+ x - } - } ensuring (res => (res.size == size) && (res.content == content)) - - def take(i: BigInt): List[T] = { (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - if (i <= BigInt(0)) { - Nil[T]() - } else { - Cons(h, t.take(i-1)) - } - }} ensuring { res => - res.content.subsetOf(this.content) && (res.size == ( - if (i <= 0) BigInt(0) - else if (i >= this.size) this.size - else i - )) - } - - def drop(i: BigInt): List[T] = { (this, i) match { - case (Nil(), _) => Nil[T]() - case (Cons(h, t), i) => - if (i <= BigInt(0)) { - Cons[T](h, t) - } else { - t.drop(i-1) - } - }} ensuring { res => - res.content.subsetOf(this.content) && (res.size == ( - if (i <= 0) this.size - else if (i >= this.size) BigInt(0) - else this.size - i - )) - } - - def slice(from: BigInt, to: BigInt): List[T] = { - require(0 <= from && from <= to && to <= size) - drop(from).take(to-from) - } - - def replace(from: T, to: T): List[T] = { this match { - case Nil() => Nil[T]() - case Cons(h, t) => - val r = t.replace(from, to) - if (h == from) { - Cons(to, r) - } else { - Cons(h, r) - } - }} ensuring { (res: List[T]) => - res.size == this.size && - res.content == ( - (this.content -- Set(from)) ++ - (if (this.content contains from) Set(to) else Set[T]()) - ) - } - - private def chunk0(s: BigInt, l: List[T], acc: List[T], res: List[List[T]], s0: BigInt): List[List[T]] = { - require(s > 0 && s0 >= 0) - l match { - case Nil() => - if (acc.size > 0) { - res :+ acc - } else { - res - } - case Cons(h, t) => - if (s0 == BigInt(0)) { - chunk0(s, t, Cons(h, Nil()), res :+ acc, s-1) - } else { - chunk0(s, t, acc :+ h, res, s0-1) - } - } - } - - def chunks(s: BigInt): List[List[T]] = { - require(s > 0) - - chunk0(s, this, Nil(), Nil(), s) - } - - def zip[B](that: List[B]): List[(T, B)] = { (this, that) match { - case (Cons(h1, t1), Cons(h2, t2)) => - Cons((h1, h2), t1.zip(t2)) - case _ => - Nil[(T, B)]() - }} ensuring { _.size == ( - if (this.size <= that.size) this.size else that.size - )} - - def -(e: T): List[T] = { this match { - case Cons(h, t) => - if (e == h) { - t - e - } else { - Cons(h, t - e) - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == this.content -- Set(e) - } - - def --(that: List[T]): List[T] = { this match { - case Cons(h, t) => - if (that.contains(h)) { - t -- that - } else { - Cons(h, t -- that) - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == this.content -- that.content - } - - def &(that: List[T]): List[T] = { this match { - case Cons(h, t) => - if (that.contains(h)) { - Cons(h, t & that) - } else { - t & that - } - case Nil() => - Nil[T]() - }} ensuring { res => - res.size <= this.size && - res.content == (this.content & that.content) - } - - def padTo(s: BigInt, e: T): List[T] = { (this, s) match { - case (_, s) if s <= 0 => - this - case (Nil(), s) => - Cons(e, Nil().padTo(s-1, e)) - case (Cons(h, t), s) => - Cons(h, t.padTo(s-1, e)) - }} ensuring { res => - if (s <= this.size) - res == this - else - res.size == s && - res.content == this.content ++ Set(e) - } - - def find(e: T): Option[BigInt] = { this match { - case Nil() => None[BigInt]() - case Cons(h, t) => - if (h == e) { - Some[BigInt](0) - } else { - t.find(e) match { - case None() => None[BigInt]() - case Some(i) => Some(i+1) - } - } - }} ensuring { res => !res.isDefined || (this.content contains e) } - - def init: List[T] = { - require(!isEmpty) - ((this : @unchecked) match { - case Cons(h, Nil()) => - Nil[T]() - case Cons(h, t) => - Cons[T](h, t.init) - }) - } ensuring ( (r: List[T]) => - r.size == this.size - 1 && - r.content.subsetOf(this.content) - ) - - def last: T = { - require(!isEmpty) - (this : @unchecked) match { - case Cons(h, Nil()) => h - case Cons(_, t) => t.last - } - } ensuring { this.contains _ } - - def lastOption: Option[T] = { this match { - case Cons(h, t) => - t.lastOption.orElse(Some(h)) - case Nil() => - None[T]() - }} ensuring { _.isDefined != this.isEmpty } - - def firstOption: Option[T] = { this match { - case Cons(h, t) => - Some(h) - case Nil() => - None[T]() - }} ensuring { _.isDefined != this.isEmpty } - - def unique: List[T] = this match { - case Nil() => Nil() - case Cons(h, t) => - Cons(h, t.unique - h) - } - - def splitAt(e: T): List[List[T]] = split(Cons(e, Nil())) - - def split(seps: List[T]): List[List[T]] = this match { - case Cons(h, t) => - if (seps.contains(h)) { - Cons(Nil(), t.split(seps)) - } else { - val r = t.split(seps) - Cons(Cons(h, r.head), r.tail) - } - case Nil() => - Cons(Nil(), Nil()) - } - - def evenSplit: (List[T], List[T]) = { - val c = size/2 - (take(c), drop(c)) - } - - def updated(i: BigInt, y: T): List[T] = { - require(0 <= i && i < this.size) - this match { - case Cons(x, tail) if i == 0 => - Cons[T](y, tail) - case Cons(x, tail) => - Cons[T](x, tail.updated(i - 1, y)) - } - } - - private def insertAtImpl(pos: BigInt, l: List[T]): List[T] = { - require(0 <= pos && pos <= size) - if(pos == BigInt(0)) { - l ++ this - } else { - this match { - case Cons(h, t) => - Cons(h, t.insertAtImpl(pos-1, l)) - case Nil() => - l - } - } - } ensuring { res => - res.size == this.size + l.size && - res.content == this.content ++ l.content - } - - def insertAt(pos: BigInt, l: List[T]): List[T] = { - require(-pos <= size && pos <= size) - if(pos < 0) { - insertAtImpl(size + pos, l) - } else { - insertAtImpl(pos, l) - } - } ensuring { res => - res.size == this.size + l.size && - res.content == this.content ++ l.content - } - - def insertAt(pos: BigInt, e: T): List[T] = { - require(-pos <= size && pos <= size) - insertAt(pos, Cons[T](e, Nil())) - } ensuring { res => - res.size == this.size + 1 && - res.content == this.content ++ Set(e) - } - - private def replaceAtImpl(pos: BigInt, l: List[T]): List[T] = { - require(0 <= pos && pos <= size) - if (pos == BigInt(0)) { - l ++ this.drop(l.size) - } else { - this match { - case Cons(h, t) => - Cons(h, t.replaceAtImpl(pos-1, l)) - case Nil() => - l - } - } - } ensuring { res => - res.content.subsetOf(l.content ++ this.content) - } - - def replaceAt(pos: BigInt, l: List[T]): List[T] = { - require(-pos <= size && pos <= size) - if(pos < 0) { - replaceAtImpl(size + pos, l) - } else { - replaceAtImpl(pos, l) - } - } ensuring { res => - res.content.subsetOf(l.content ++ this.content) - } - - def rotate(s: BigInt): List[T] = { - if (isEmpty) { - Nil[T]() - } else { - drop(s mod size) ++ take(s mod size) - } - } ensuring { res => - res.size == this.size - } - - def isEmpty = this match { - case Nil() => true - case _ => false - } - - // Higher-order API - def map[R](f: T => R): List[R] = { this match { - case Nil() => Nil[R]() - case Cons(h, t) => f(h) :: t.map(f) - }} ensuring { _.size == this.size } - - def foldLeft[R](z: R)(f: (R,T) => R): R = this match { - case Nil() => z - case Cons(h,t) => t.foldLeft(f(z,h))(f) - } - - def foldRight[R](z: R)(f: (T,R) => R): R = this match { - case Nil() => z - case Cons(h, t) => f(h, t.foldRight(z)(f)) - } - - def scanLeft[R](z: R)(f: (R,T) => R): List[R] = { this match { - case Nil() => z :: Nil() - case Cons(h,t) => z :: t.scanLeft(f(z,h))(f) - }} ensuring { !_.isEmpty } - - def scanRight[R](z: R)(f: (T,R) => R): List[R] = { this match { - case Nil() => z :: Nil[R]() - case Cons(h, t) => - val rest@Cons(h1,_) = t.scanRight(z)(f) - f(h, h1) :: rest - }} ensuring { !_.isEmpty } - - def flatMap[R](f: T => List[R]): List[R] = - ListOps.flatten(this map f) - - def filter(p: T => Boolean): List[T] = { this match { - case Nil() => Nil[T]() - case Cons(h, t) if p(h) => Cons(h, t.filter(p)) - case Cons(_, t) => t.filter(p) - }} ensuring { res => - res.size <= this.size && - res.content.subsetOf(this.content) && - res.forall(p) - } - - def filterNot(p: T => Boolean): List[T] = - filter(!p(_)) ensuring { res => - res.size <= this.size && - res.content.subsetOf(this.content) && - res.forall(!p(_)) - } - - def partition(p: T => Boolean): (List[T], List[T]) = { this match { - case Nil() => (Nil[T](), Nil[T]()) - case Cons(h, t) => - val (l1, l2) = t.partition(p) - if (p(h)) (h :: l1, l2) - else (l1, h :: l2) - }} ensuring { res => - res._1 == filter(p) && - res._2 == filterNot(p) - } - - // In case we implement for-comprehensions - def withFilter(p: T => Boolean) = filter(p) - - def forall(p: T => Boolean): Boolean = this match { - case Nil() => true - case Cons(h, t) => p(h) && t.forall(p) - } - - def exists(p: T => Boolean) = !forall(!p(_)) - - def find(p: T => Boolean): Option[T] = { this match { - case Nil() => None[T]() - case Cons(h, t) if p(h) => Some(h) - case Cons(_, t) => t.find(p) - }} ensuring { res => res match { - case Some(r) => (content contains r) && p(r) - case None() => true - }} - - def groupBy[R](f: T => R): Map[R, List[T]] = this match { - case Nil() => Map.empty[R, List[T]] - case Cons(h, t) => - val key: R = f(h) - val rest: Map[R, List[T]] = t.groupBy(f) - val prev: List[T] = if (rest isDefinedAt key) rest(key) else Nil[T]() - (rest ++ Map((key, h :: prev))) : Map[R, List[T]] - } - - def takeWhile(p: T => Boolean): List[T] = { this match { - case Cons(h,t) if p(h) => Cons(h, t.takeWhile(p)) - case _ => Nil[T]() - }} ensuring { res => - (res forall p) && - (res.size <= this.size) && - (res.content subsetOf this.content) - } - - def dropWhile(p: T => Boolean): List[T] = { this match { - case Cons(h,t) if p(h) => t.dropWhile(p) - case _ => this - }} ensuring { res => - (res.size <= this.size) && - (res.content subsetOf this.content) && - (res.isEmpty || !p(res.head)) - } - - def count(p: T => Boolean): BigInt = { this match { - case Nil() => BigInt(0) - case Cons(h, t) => - (if (p(h)) BigInt(1) else BigInt(0)) + t.count(p) - }} ensuring { - _ == this.filter(p).size - } - -} - -@ignore -object List { - def apply[T](elems: T*): List[T] = { - var l: List[T] = Nil[T]() - for (e <- elems) { - l = Cons(e, l) - } - l.reverse - } -} - -@library -object ListOps { - def flatten[T](ls: List[List[T]]): List[T] = ls match { - case Cons(h, t) => h ++ flatten(t) - case Nil() => Nil() - } - - def isSorted(ls: List[BigInt]): Boolean = ls match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(h1, Cons(h2, _)) if(h1 > h2) => false - case Cons(_, t) => isSorted(t) - } - - def sorted(ls: List[BigInt]): List[BigInt] = ls match { - case Cons(h, t) => insSort(sorted(t), h) - case Nil() => Nil() - } - - def insSort(ls: List[BigInt], v: BigInt): List[BigInt] = ls match { - case Nil() => Cons(v, Nil()) - case Cons(h, t) => - if (v <= h) { - Cons(v, t) - } else { - Cons(h, insSort(t, v)) - } - } -} - -case class Cons[T](h: T, t: List[T]) extends List[T] -case class Nil[T]() extends List[T] - -@library -object ListSpecs { - def snocIndex[T](l : List[T], t : T, i : BigInt) : Boolean = { - require(0 <= i && i < l.size + 1) - // proof: - (l match { - case Nil() => true - case Cons(x, xs) => if (i > 0) snocIndex[T](xs, t, i-1) else true - }) && - // claim: - ((l :+ t).apply(i) == (if (i < l.size) l(i) else t)) - }.holds - - def reverseIndex[T](l : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l.size) - (l match { - case Nil() => true - case Cons(x,xs) => snocIndex(l, x, i) && reverseIndex[T](l,i) - }) && - (l.reverse.apply(i) == l.apply(l.size - 1 - i)) - }.holds - - def appendIndex[T](l1 : List[T], l2 : List[T], i : BigInt) : Boolean = { - require(0 <= i && i < l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x,xs) => if (i==BigInt(0)) true else appendIndex[T](xs,l2,i-1) - }) && - ((l1 ++ l2).apply(i) == (if (i < l1.size) l1(i) else l2(i - l1.size))) - }.holds - - def appendAssoc[T](l1 : List[T], l2 : List[T], l3 : List[T]) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => appendAssoc(xs,l2,l3) - }) && - (((l1 ++ l2) ++ l3) == (l1 ++ (l2 ++ l3))) - }.holds - - def snocIsAppend[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocIsAppend(xs,t) - }) && - ((l :+ t) == l ++ Cons[T](t, Nil())) - }.holds - - def snocAfterAppend[T](l1 : List[T], l2 : List[T], t : T) : Boolean = { - (l1 match { - case Nil() => true - case Cons(x,xs) => snocAfterAppend(xs,l2,t) - }) && - ((l1 ++ l2) :+ t == (l1 ++ (l2 :+ t))) - }.holds - - def snocReverse[T](l : List[T], t : T) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => snocReverse(xs,t) - }) && - ((l :+ t).reverse == Cons(t, l.reverse)) - }.holds - - def reverseReverse[T](l : List[T]) : Boolean = { - (l match { - case Nil() => true - case Cons(x,xs) => reverseReverse[T](xs) && snocReverse[T](xs.reverse, x) - }) && - (l.reverse.reverse == l) - }.holds - - //// my hand calculation shows this should work, but it does not seem to be found - //def reverseAppend[T](l1 : List[T], l2 : List[T]) : Boolean = { - // (l1 match { - // case Nil() => true - // case Cons(x,xs) => { - // reverseAppend(xs,l2) && - // snocAfterAppend[T](l2.reverse, xs.reverse, x) && - // l1.reverse == (xs.reverse :+ x) - // } - // }) && - // ((l1 ++ l2).reverse == (l2.reverse ++ l1.reverse)) - //}.holds - - //def associative[T,U](l1: List[T], l2: List[T], f: List[T] => U, op: (U,U) => U) = { - // f(l1 ++ l2) == op(f(l1), f(l2)) - //} - // - //def existsAssoc[T](l1: List[T], l2: List[T], p: T => Boolean) = { - // associative[T, Boolean](l1, l2, _.exists(p), _ || _ ) - //}.holds - // - //def forallAssoc[T](l1: List[T], l2: List[T], p: T => Boolean) = { - // associative[T, Boolean](l1, l2, _.exists(p), _ && _ ) - //}.holds - - //@induct - //def folds[T,R](l : List[T], z : R, f : (R,T) => R) = { - // { l match { - // case Nil() => true - // case Cons(h,t) => snocReverse[T](t, h) - // }} && - // l.foldLeft(z)(f) == l.reverse.foldRight((x:T,y:R) => f(y,x))(z) - //}.holds - // - - //Can't prove this - //@induct - //def scanVsFoldLeft[A,B](l : List[A], z: B, f: (B,A) => B): Boolean = { - // l.scanLeft(z)(f).last == l.foldLeft(z)(f) - //}.holds - - @induct - def scanVsFoldRight[A,B](l: List[A], z: B, f: (A,B) => B): Boolean = { - l.scanRight(z)(f).head == l.foldRight(z)(f) - }.holds - - // A lemma about `append` and `updated` - def appendUpdate[T](l1: List[T], l2: List[T], i: BigInt, y: T): Boolean = { - require(0 <= i && i < l1.size + l2.size) - // induction scheme - (l1 match { - case Nil() => true - case Cons(x, xs) => if (i == 0) true else appendUpdate[T](xs, l2, i - 1, y) - }) && - // lemma - ((l1 ++ l2).updated(i, y) == ( - if (i < l1.size) - l1.updated(i, y) ++ l2 - else - l1 ++ l2.updated(i - l1.size, y))) - }.holds - - // a lemma about `append`, `take` and `drop` - def appendTakeDrop[T](l1: List[T], l2: List[T], n: BigInt): Boolean = { - //induction scheme - (l1 match { - case Nil() => true - case Cons(x, xs) => if (n <= 0) true else appendTakeDrop[T](xs, l2, n - 1) - }) && - // lemma - ((l1 ++ l2).take(n) == ( - if (n < l1.size) l1.take(n) - else if (n > l1.size) l1 ++ l2.take(n - l1.size) - else l1)) && - ((l1 ++ l2).drop(n) == ( - if (n < l1.size) l1.drop(n) ++ l2 - else if (n > l1.size) l2.drop(n - l1.size) - else l2)) - }.holds - - // A lemma about `append` and `insertAt` - def appendInsert[T](l1: List[T], l2: List[T], i: BigInt, y: T): Boolean = { - require(0 <= i && i <= l1.size + l2.size) - (l1 match { - case Nil() => true - case Cons(x, xs) => if (i == 0) true else appendInsert[T](xs, l2, i - 1, y) - }) && - // lemma - ((l1 ++ l2).insertAt(i, y) == ( - if (i < l1.size) l1.insertAt(i, y) ++ l2 - else l1 ++ l2.insertAt((i - l1.size), y))) - }.holds - -} diff --git a/testcases/web/demos/005_Tutorial-Monad.scala b/testcases/web/demos/005_Tutorial-Monad.scala deleted file mode 100644 index ba08a0e1f3f18af7c954c2a06b7c06cc26522369..0000000000000000000000000000000000000000 --- a/testcases/web/demos/005_Tutorial-Monad.scala +++ /dev/null @@ -1,43 +0,0 @@ -import leon.annotation._ - -sealed abstract class Outcome[T] { - def map[S](f: T => S): Outcome[S] = { - this match { - case ReturnOK(v) => ReturnOK[S](f(v)) - case Throw(msg) => Throw[S](msg) - } - } - def flatMap[S](f: T => Outcome[S]): Outcome[S] = { - this match { - case ReturnOK(v) => f(v) - case Throw(msg) => Throw[S](msg) - } - } - -} -case class ReturnOK[T](v: T) extends Outcome[T] -case class Throw[T](msg: String) extends Outcome[T] - -object Test { - def test : Outcome[BigInt] = { - val c1 = ReturnOK[BigInt](32) - val c2 = ReturnOK[BigInt](20) - for (v1 <- c1; v2 <- c2) - yield (v1 + v2) - } - def foo : BigInt = test match { - case ReturnOK(v) => v - case _ => 0 - } - - def associative_lemma[T,U,V](m: Outcome[T], f: T => Outcome[U], g: U => Outcome[V]): Boolean = { - m.flatMap(f).flatMap(g) == m.flatMap((x:T) => f(x).flatMap(g)) - } - - def associative_lemma_for[T,U,V](m: Outcome[T], f: T => Outcome[U], g: U => Outcome[V]): Boolean = { - (for (x <- m; y <- f(x); z <- g(y)) yield z) == - (for (y1 <- (for (x <- m; y <- f(x)) yield y); z <- g(y1)) yield z) && - (for (x <- m; y <- f(x); z <- g(y)) yield z) == - (for (x <- m; z1 <- (for (y <- f(x); z <- g(y)) yield z)) yield z1) - } -} diff --git a/testcases/web/demos/008_Tutorial-Robot.scala b/testcases/web/demos/008_Tutorial-Robot.scala deleted file mode 100644 index bca1f367a26df843e65cea76de7029652f0b4906..0000000000000000000000000000000000000000 --- a/testcases/web/demos/008_Tutorial-Robot.scala +++ /dev/null @@ -1,675 +0,0 @@ -// Developed by Etienne Kneuss, 2015 -import leon.lang._ -import leon.collection._ -import leon.annotation._ - -object Robot { - - // From top left - case class Position(x: BigInt, y: BigInt) { - def +(o: Orientation) = o match { - case North => Position(x, y-1) - case East => Position(x+1, y) - case South => Position(x, y+1) - case West => Position(x-1, y) - } - - def neighbors: List[Position] = { - List(this + North, this + East, this + South, this + West) - } - } - - abstract class Orientation { - def left = this match { - case North => West - case East => North - case South => East - case West => South - } - - def right = this match { - case North => East - case East => South - case South => West - case West => North - } - } - - case object North extends Orientation - case object East extends Orientation - case object South extends Orientation - case object West extends Orientation - - abstract class FireLevel { - def level: BigInt = this match { - case NoFire => 0 - case Fire1 => 1 - case Fire2 => 2 - case Fire3 => 3 - case Fire4 => 4 - case Fire5 => 5 - } - - def increase = this match { - case NoFire => NoFire - case Fire1 => Fire2 - case Fire2 => Fire3 - case Fire3 => Fire4 - case Fire4 => Fire5 - case Fire5 => Fire5 - } - - def temp:BigInt = level*100 - } - - case object NoFire extends FireLevel - case object Fire1 extends FireLevel - case object Fire2 extends FireLevel - case object Fire3 extends FireLevel - case object Fire4 extends FireLevel - case object Fire5 extends FireLevel - - case class World( - clock: BigInt, - dimentions: Position, - walls: Set[Position], - persons: Set[Position], - initFires: Set[Position], - rs: RobotState) { - - def personAt(pos: Position): Boolean = persons contains pos - - def wallAt(pos: Position): Boolean = walls contains pos - - def fireAt(pos: Position): FireLevel = { - val step = clock/50 - - if (wallAt(pos)) { - NoFire - } else if (initFires contains pos) { - fireLevel(clock/10+1) - } else if (step >= 1 && (pos.neighbors.exists { p => initFires contains p })) { - fireLevel((clock-50)/10+1) - } else { - NoFire - } - } - - def fireLevel(l: BigInt) = { - if (l <= 1) Fire1 - else if (l <= 2) Fire2 - else if (l <= 3) Fire3 - else if (l <= 4) Fire4 - else Fire5 - } - - def isWithinMap(p: Position): Boolean = { - p.x >= 0 && p.x < dimentions.x && - p.y >= 0 && p.y < dimentions.y - } - } - - - /******************************************************************* - * Engine Component - *******************************************************************/ - - case class EngineState(pos: Position, dim: Position, orient: Orientation) - - abstract class EngineTransition - case object EForward extends EngineTransition - case object ERotateLeft extends EngineTransition - case object ERotateRight extends EngineTransition - case object EIdle extends EngineTransition - - def engineStep(es: EngineState, t: EngineTransition) = t match { - case EForward => EngineState(es.pos + es.orient, es.dim, es.orient) - case ERotateRight => EngineState(es.pos, es.dim, es.orient.right) - case ERotateLeft => EngineState(es.pos, es.dim, es.orient.left) - case EIdle => es - } - - def engineSucc(es: EngineState): List[EngineTransition] = { - if ((es.pos.x <= 0 && es.orient == West) || - (es.pos.y <= 0 && es.orient == North) || - (es.pos.x >= es.dim.x && es.orient == East) || - (es.pos.y >= es.dim.y && es.orient == South)) { - List(ERotateLeft, ERotateRight, EIdle) - } else { - List(EForward, ERotateLeft, ERotateRight, EIdle) - } - } - - /******************************************************************* - * Navigation Sensor Component - *******************************************************************/ - - case class NavSensorState(wall: Option[Boolean], person: Option[Boolean]) { - def hasData = wall.isDefined && person.isDefined - - def validData(implicit w: World) = { - val posFront = w.rs.es.pos + w.rs.es.orient - - val wallOk = wall match { - case Some(wal) => wal == w.wallAt(posFront) - case None() => true - } - - val personOk = person match { - case Some(per) => per == w.personAt(posFront) - case None() => true - } - - wallOk && personOk - } - } - - abstract class NavSensorTransition - case object NSense extends NavSensorTransition - case object NForget extends NavSensorTransition - case object NIdle extends NavSensorTransition - - - def navSensorStep(ns: NavSensorState, t: NavSensorTransition)(implicit w: World) = t match { - case NSense => - // Driver call - val p = w.rs.es.pos + w.rs.es.orient - NavSensorState(Some(w.wallAt(p)), Some(w.personAt(p))) - - case NForget => - NavSensorState(None(), None()) - - case NIdle => - ns - } - - def navSensorSucc(ns: NavSensorState): List[NavSensorTransition] = { - if (ns.hasData) { - List(NForget, NIdle) - } else { - List(NSense, NIdle) - } - } - - /******************************************************************* - * Heat Sensor Component - *******************************************************************/ - - case class HeatSensorState(heat: Option[FireLevel]) { - def hasData = heat.isDefined - - def validData(implicit w: World) = { - heat match { - case Some(f) => - val realF = w.fireAt(w.rs.es.pos + w.rs.es.orient) - realF == f || realF == f.increase - case None() => - true - } - } - } - - abstract class HeatSensorTransition - case object HSense extends HeatSensorTransition - case object HForget extends HeatSensorTransition - case object HIdle extends HeatSensorTransition - - def heatSensorStep(hs: HeatSensorState, t: HeatSensorTransition)(implicit w: World) = t match { - case HSense => - // Driver call - val p = w.rs.es.pos+w.rs.es.orient - HeatSensorState(Some(w.fireAt(p))) - - case HForget => - HeatSensorState(None()) - - case HIdle => - hs - } - - def heatSensorSucc(hs: HeatSensorState): List[HeatSensorTransition] = { - if (hs.hasData) { - List(HForget, HIdle) - } else { - List(HSense, HIdle) - } - } - - /******************************************************************* - * Transmission Component - *******************************************************************/ - - case class TransmitterState(beacon: Option[Position]) { - def hasData = beacon.isDefined - } - - abstract class TransmitterTransition - case object TRepeat extends TransmitterTransition - case object TFound extends TransmitterTransition - case object TIdle extends TransmitterTransition - - def transmitterStep(ts: TransmitterState, es: EngineState, t: TransmitterTransition)(implicit w: World) = t match { - case TRepeat => - // Driver call to transmit - ts - - case TFound => - // Driver call to transmit - TransmitterState(Some(es.pos + es.orient)) - - case TIdle => - ts - } - - def transmitterSucc(ts: TransmitterState): List[TransmitterTransition] = { - if (ts.hasData) { - List(TRepeat, TFound) - } else { - List(TFound, TIdle) - } - } - - - /******************************************************************* - * Robot Component - *******************************************************************/ - - case class RobotState( - es: EngineState, - ns: NavSensorState, - hs: HeatSensorState, - ts: TransmitterState - ) - - case class RobotTransition( - et: EngineTransition, - nst: NavSensorTransition, - hst: HeatSensorTransition, - tt: TransmitterTransition - ) - - def robotSucc(rs: RobotState): List[RobotTransition] = { - val ess = engineSucc(rs.es) - val nss = navSensorSucc(rs.ns) - val hss = heatSensorSucc(rs.hs) - val ts = transmitterSucc(rs.ts) - - filterValid(rs, ||(ess, nss, hss, ts)) - } ensuring { - res => allValid(rs, res) - } - - def robotStep(rs: RobotState, rt: RobotTransition)(implicit w: World): RobotState = { - RobotState( - engineStep(rs.es, rt.et), - navSensorStep(rs.ns, rt.nst), - heatSensorStep(rs.hs, rt.hst), - transmitterStep(rs.ts, rs.es, rt.tt) - ) - } - - // Can wistand up to 300 degrees - def safetyTemp:BigInt = 300 - - // Temperature can increase by at most 100 degree while the robot moves - def dTempMax:BigInt = 100 - - // Glue that compose sensors, transmitter and engine to perform valid actions - def validTransition(rs: RobotState, rt: RobotTransition): Boolean = { - - // 6) Sensors must be based on recent data - val freshSensors = if (rt.et == EForward || rt.et == ERotateRight || rt.et == ERotateLeft) { - rt.nst == NForget && rt.hst == HForget - } else { - true - } - - val freshSensors2 = if(rs.hs.hasData) { - rt.hst == HForget - } else { - true - } - - // 2/3) We can move forward only if no wall was detected - val forwardIfNoWall = (!(rt.et == EForward) || rs.ns.wall == Some(false)) - - // 3) We don't exit the world - val forwardIfNotOutOfMap = if (rt.et == EForward) { - (rs.es.pos.x > 0 || rs.es.orient != West) && - (rs.es.pos.y > 0 || rs.es.orient != North) && - (rs.es.pos.x < rs.es.dim.x-1 || rs.es.orient != East) && - (rs.es.pos.y < rs.es.dim.y-1 || rs.es.orient != South) - } else { - true - } - - // 4) We can move forward only if the cell is within heat limits - val forwardIfNotHot = (!(rt.et == EForward) || rs.hs.heat.getOrElse(Fire5).temp <= safetyTemp-dTempMax*2) - - // 5) If we found, we read the position and transmit - val transmitIfFound = if (rs.ns.person == Some(true)) { - rt.tt == TFound - } else { - rt.tt == TRepeat || rt.tt == TIdle - } - - forwardIfNotOutOfMap && freshSensors && freshSensors2 && forwardIfNoWall && forwardIfNotHot && transmitIfFound - } - - def validWorld(implicit w: World): Boolean = { - val dim = w.dimentions - - dim.x > 0 && dim.y > 0 && dim == w.rs.es.dim && - w.isWithinMap(w.rs.es.pos) && - w.clock >= 0 - } - - def validState(rs: RobotState)(implicit w: World): Boolean = { - - // 6) Sensors have consistent data - val recentData = rs.ns.validData && rs.hs.validData - - // 2/3) We don't end up in a wall - val notInWall = !w.wallAt(rs.es.pos) - - // 2) We are in the map - val inMap = w.isWithinMap(rs.es.pos) - - validWorld && recentData && notInWall && inMap - } - - def validRobotStep(from: RobotState, to: RobotState)(implicit w: World): Boolean = { - val posFrom = from.es.pos - val posFromFront = from.es.pos + from.es.orient - val posTo = to.es.pos - val posToFront = to.es.pos +to.es.orient - - // 1) Robot must not rotate and move at the same time - val dontRotateAndMove = (from.es.pos == to.es.pos) || (from.es.orient == to.es.orient) - - // 4) We don't move to a cell that is too hot - val dontBeCrazy = (posFrom == posTo) || (w.fireAt(posTo).temp <= safetyTemp) - - // 5) If we found somebody, we record its position for transmission - val transmitWhenFound = (from.ns.person != Some(true)) || (to.ts.beacon == Some(posFromFront)) - - dontRotateAndMove && dontBeCrazy && transmitWhenFound - } - - def filterValid(rs: RobotState, rts: List[RobotTransition]): List[RobotTransition] = (rts match { - case Cons(rt, rtt) => - val ts = filterValid(rs, rtt) - - if (validTransition(rs, rt)) { - Cons(rt, ts) - } else { - ts - } - case Nil() => Nil[RobotTransition]() - }) ensuring { - res => allValid(rs, res) - } - - def allValid(rs: RobotState, rts: List[RobotTransition]): Boolean = rts match { - case Cons(rt, rtt) => validTransition(rs, rt) && allValid(rs, rtt) - case Nil() => true - } - - def worldStep(w: World): World = { - World(w.clock + 1, w.dimentions, w.walls, w.persons, w.initFires, w.rs) - } ensuring { - w2 => - w.fireAt(w2.rs.es.pos).level <= w2.fireAt(w2.rs.es.pos).level && - w2.fireAt(w2.rs.es.pos).level <= w.fireAt(w2.rs.es.pos).level+1 - } - - def fireEvolution(from: FireLevel, to: FireLevel): Boolean = { - (from.temp <= to.temp) && - (to.temp <= from.temp + dTempMax) - } - - def searchAlgorithm(rs: RobotState): EngineTransition = { - // Make a suggestion based on whatever kwnoledge you have, here we favor going forward - EForward - } - - def getBestTransition(rs: RobotState, ls: List[RobotTransition]): Option[RobotTransition] = { - require(allValid(rs, ls)) - - if (ls.isEmpty) { - None[RobotTransition]() - } else { - val sugg = searchAlgorithm(rs) - - ls.find(rt => (rt.et == sugg) && validTransition(rs, rt)).orElse { - Some(ls.head) - } - } - } ensuring { - res => res match { - case Some(t) => - (ls.content contains t) && validTransition(rs, t) - case None() => - ls.isEmpty - } - } - - def step(rs: RobotState)(implicit w: World) = { - require(validState(rs) && w.rs == rs) - - val transitions = robotSucc(rs) - - val ort = getBestTransition(rs, transitions) - - val nextRs = ort match { - case Some(rt) => - robotStep(rs, rt) - - case None() => - rs - } - - (nextRs, ort) - } ensuring { - res => - val (rs2, ort) = res; - validState(rs2) && - (ort match { - case Some(rt) => - validRobotStep(rs, rs2) - case None() => - true - - }) - } - - def globalSafe(implicit w: World): World = { - require(validState(w.rs)) - - // One step for the robot - val (rs2, otr) = step(w.rs) - - // One step for mankind - worldStep(World(w.clock, w.dimentions, w.walls, w.persons, w.initFires, rs2)) - } ensuring { - w2 => - val heatOk = if (w.rs.es.pos == w2.rs.es.pos) { - true - } else { - w2.fireAt(w2.rs.es.pos).temp <= safetyTemp - } - - // 2/3) We don't end up in a wall - val notInWall = !w2.wallAt(w2.rs.es.pos) - - // 2) We are in the map - val inMap = w2.isWithinMap(w2.rs.es.pos) - - heatOk && notInWall && inMap - } - - - @ignore - def main(a: Array[String]): Unit = { - val map0 = """|XXXXXXXXX - |XR FF X - |X PXXXX - |XXX F F X - |X X X - |XX FPXXXXX - |XXXXXX""".stripMargin - - val map1 = """|XXXXXXXXXXXXX - |X R X - |XP X X - |X X X - |X XXXXXXX X - |X PX X - |X X X - |XFF X X - |XXXXXXXXXXXXX""".stripMargin - - var initPos: Position = Position(0, 0) - - var walls = Set[Position]() - var mission = Set[Position]() - var persons = Set[Position]() - var fires = Set[Position]() - - for ((line, y) <- map1.split("\n").toSeq.zipWithIndex; - (c, x) <- line.zipWithIndex) { - - val p = Position(x, y) - - c match { - case 'R' => - initPos = p - - case 'X' => - walls += p - - case 'F' => - fires += p - - case 'P' => - persons += p - - case ' ' => - } - - if (c != 'X') { - mission += p - } - } - - - val dim = Position(walls.theSet.map(_.x).max+1, walls.theSet.map(_.y).max+1) - - val es = EngineState(initPos, dim, North) - val ns = NavSensorState(None(), None()) - val hs = HeatSensorState(None()) - val t = TransmitterState(None()) - - val rs = RobotState(es, ns, hs, t) - - implicit var w = World(0, dim, walls, persons, fires, rs) - - while(w.clock < 110) { - print("\u001b[2J") - val (rs2, otr) = step(w.rs) - w = w.copy(rs = rs2) - w = worldStep(w) - draw(w, otr) - Thread.sleep(120l) - } - } - - @ignore - def draw(w: World, ogt: Option[RobotTransition]): Unit = { - val rs = w.rs - - def navSens(ns: NavSensorState): String = { - ns.wall.map(v => if (v) "X" else "_").getOrElse("?") - } - - val o = (rs.es.orient match { - case North => "^" - case East => ">" - case South => "v" - case West => "<" - })+" "+rs.es.pos.x+","+rs.es.pos.y - - print("Last Action: ") - ogt match { - case Some(gt) => - println(s"E: ${gt.et}, NS: ${gt.nst}, HS: ${gt.hst}, T: ${gt.tt}") - - case None() => - println("<stuck>") - } - println() - println(s"World Clock: ${w.clock}") - println() - println("Robot State: ") - println(s" - Engine : ${rs.es}") - println(s" - Nav Sensor : ${rs.ns}") - println(s" - Heat Sensor : ${rs.hs}") - println(s" - Transmitter : ${rs.ts}") - - println() - println("Map:") - println() - - val colors = List(52, 124, 1, 160, 196); - - for (y <- BigInt(0) until w.dimentions.y) { - for(x <- BigInt(0) until w.dimentions.x) { - - val p = Position(x, y) - - val f = w.fireAt(p) - if (f != NoFire) { - val code = colors(f.level-1) - print("\u001b[48;5;"+code+"m") - } - - if (w.walls contains p) { - print("\u2593") - } else if (rs.es.pos == p) { - print((rs.es.orient match { - case North => "^" - case South => "v" - case East => ">" - case West => "<" - })) - } else if (w.persons contains p) { - print("P") - } else { - print(" ") - } - - if (f != NoFire) { - print(Console.RESET) - } - - } - println - } - } - - def ||(ets: List[EngineTransition], - nsts: List[NavSensorTransition], - hsts: List[HeatSensorTransition], - tts: List[TransmitterTransition]): List[RobotTransition] = { - - ets.flatMap { et => - nsts.flatMap { nst => - hsts.flatMap { hst => - tts.map { tt => - RobotTransition(et, nst, hst, tt) - } - } - } - } - } -} diff --git a/testcases/web/demos/009_Repair1.scala b/testcases/web/demos/009_Repair1.scala deleted file mode 100644 index cf43631002f6e469e90aaf7f020b0ef6a9a53184..0000000000000000000000000000000000000000 --- a/testcases/web/demos/009_Repair1.scala +++ /dev/null @@ -1,55 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.collection._ -import leon.annotation._ - -object Running { - abstract class Formula - case class And(a: Formula, b: Formula) extends Formula - case class Or (a: Formula, b: Formula) extends Formula - case class Implies(a: Formula, b: Formula) extends Formula - case class Not(a: Formula) extends Formula - case object LitFalse extends Formula - case object LitTrue extends Formula - - def desugar(f: Formula): Formula = { - f match { - case And(a, b) => - And(desugar(a), desugar(b)) - case Or(a, b) => - Or(desugar(a), desugar(b)) - case Implies(a, b) => - if (a == LitFalse) { - LitTrue - } else { - Or(Not(a), b) - } - case Not(Not(a)) => - desugar(a) - case Not(a) => - Not(desugar(a)) - case f => - f - } - } ensuring { - res => !existsImplies(res) && eval(res) == eval(f) - } - - def existsImplies(f: Formula): Boolean = f match { - case Implies(a, b) => true - case And(a, b) => existsImplies(a) || existsImplies(b) - case Or(a, b) => existsImplies(a) || existsImplies(b) - case Not(a) => existsImplies(a) - case _ => false - } - - def eval(f: Formula): Boolean = f match { - case Implies(a, b) => !eval(a) || eval(b) - case And(a, b) => eval(a) && eval(b) - case Or(a, b) => eval(a) || eval(b) - case Not(a) => !eval(a) - case LitFalse => false - case LitTrue => true - } - -} diff --git a/testcases/web/demos/00_Tutorial.scala b/testcases/web/demos/00_Tutorial.scala deleted file mode 100644 index 17512d1b2f687a68c07d4b11157948cbfd3a0570..0000000000000000000000000000000000000000 --- a/testcases/web/demos/00_Tutorial.scala +++ /dev/null @@ -1,197 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ -object Sort { -// ================================================================== -// Max -// ================================================================== - -/* - def max(x: Int, y: Int): Int = { - val d = x - y - if (d > 0) x - else y - } ensuring(res => - x <= res && y <= res && (res == x || res == y)) - - def test1 = max(10, 5) - def test2 = max(-5, 5) - def test3 = max(-5, -7) - - def test4 = max(-1639624704, 1879048192) - */ - -/* -def max(x: BigInt, y: BigInt): BigInt = { - val d = x - y - if (d > 0) x - else y -} ensuring(res => - x <= res && y <= res && (res == x || res == y)) - */ - -/* -def max(x: BigInt, y: BigInt): BigInt = { - val d = x - y - if (d > 0) x - else y -} ensuring(res => res==rmax(x,y)) - -def rmax(x: BigInt, y: BigInt) = - if (x <= y) x else y - */ - -/* -def max_lemma(x: BigInt, y: BigInt, z: BigInt): Boolean = { - max(x,x) == x && - max(x,y) == max(y,x) && - max(x,max(y,z)) == max(max(x,y), z) && - max(x,y) + z == max(x + z, y + z) -} holds - */ - -/* -def max(x: Int, y: Int): Int = { - require(0 <= x && 0 <= y) - val d = x - y - if (d > 0) x - else y -} ensuring (res => - x <= res && y <= res && (res == x || res == y)) - */ - -// ================================================================== -// Sort 2-3 ELements -// ================================================================== - -/* - def sort2(x : BigInt, y : BigInt) = choose{(res: (BigInt,BigInt)) => - Set(x,y) == Set(res._1, res._2) && res._1 <= res._2 - } -*/ - -/* - def sort2(x : BigInt, y : BigInt) = { - ???[(BigInt, BigInt)] - } ensuring{(res: (BigInt,BigInt)) => - Set(x,y) == Set(res._1, res._2) && res._1 <= res._2 - } -*/ - - -// def testSort2 = sort2(30, 4) - -/* - def sort2(x: BigInt, y: BigInt) = choose{(res: (BigInt,BigInt)) => - sort2spec(x,y,res) - } - - def sort2spec(x: BigInt, y: BigInt, res: (BigInt, BigInt)): Boolean = { - Set(x,y) == Set(res._1, res._2) && res._1 <= res._2 - } - - def unique2(x: BigInt, y: BigInt, - res1: (BigInt, BigInt), - res2: (BigInt, BigInt)): Boolean = { - require(sort2spec(x,y,res1) && sort2spec(x,y,res2)) - res1 == res2 - } holds - */ - -/* - def sort3spec(x: BigInt, y: BigInt, z: BigInt, res: (BigInt,BigInt,BigInt)): Boolean = { - Set(x,y,z) == Set(res._1, res._2, res._3) && - res._1 <= res._2 && res._2 <= res._3 - } - - def unique3(x: BigInt, y: BigInt, z: BigInt, - res1: (BigInt,BigInt,BigInt), - res2: (BigInt,BigInt,BigInt)): Boolean = { - require(sort3spec(x,y,z,res1) && sort3spec(x,y,z,res2)) - res1 == res2 - }.holds - */ - -// ================================================================== -// Sort a List -// ================================================================== - -/* - sealed abstract class List - case object Nil extends List - case class Cons(head: BigInt, tail: List) extends List - - def size(l: List): BigInt = (l match { - case Nil => 0 - case Cons(x, rest) => x + size(rest) - }) -*/ - // ensuring(res => res > 0) - - // def s1 = size(Cons(10, Cons(1000, Nil))) - -/* - def content(l: List): Set[BigInt] = l match { - case Nil => Set() - case Cons(i, t) => Set(i) ++ content(t) - } -*/ - -/* - def isSorted(l: List): Boolean = l match { - case Nil => true - case Cons(_,Nil) => true - case Cons(x1, Cons(x2, rest)) => - x1 < x2 && isSorted(Cons(x2,rest)) - } -*/ - //def t1 = isSorted(Cons(10, Cons(20, Nil))) - //def t2 = isSorted(Cons(15, Cons(15, Nil))) - -/* - def sInsert(x: BigInt, l: List): List = { - require(isSorted(l)) - l match { - case Nil => Cons(x, Nil) - case Cons(e, rest) if (x == e) => l - case Cons(e, rest) if (x < e) => Cons(x, Cons(e,rest)) - case Cons(e, rest) if (x > e) => Cons(e, sInsert(x,rest)) - } - } ensuring {(res:List) => - isSorted(res) && content(res) == content(l) ++ Set(x)} - - // size(res) == size(l) + 1 -*/ - -/* - def insertMagic(x: BigInt, l: List): List = { - require(isSorted(l)) - choose {(res: List) => - isSorted(res) && content(res) == content(l) ++ Set[BigInt](x) - } - } -*/ - - //def m = insertMagic(17, Cons(10, Cons(15, Cons(20, Nil)))) - -/* - def sortMagic(l: List) = { - ???[List] - } ensuring((res:List) => - isSorted(res) && content(res) == content(l)) -*/ - - // def mm = sortMagic(Cons(20, Cons(5, Cons(50, Cons(2, Nil))))) - -/* - def sInsert(x: BigInt, l: List): List = { - require(isSorted(l)) - l match { - case Nil => Cons(x, Nil) - case Cons(e, rest) => Cons(e, sInsert(x,rest)) - } - } ensuring {(res:List) => - isSorted(res) && content(res) == content(l) ++ Set(x)} - */ - -} diff --git a/testcases/web/demos/01_Compiler.scala b/testcases/web/demos/01_Compiler.scala deleted file mode 100644 index a38c57f425cab0fc6b143a842276231ee7a759ba..0000000000000000000000000000000000000000 --- a/testcases/web/demos/01_Compiler.scala +++ /dev/null @@ -1,201 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon._ - -object Tokens { - abstract class Token - case object TPlus extends Token - case object TTimes extends Token - case object TLT extends Token - case object TIf extends Token - case object TElse extends Token - case object TLAnd extends Token - case object TLOr extends Token - case object TLeftBrace extends Token - case object TRightBrace extends Token - case object TLeftPar extends Token - case object TRightPar extends Token - case class TInt(v: BigInt) extends Token - case class TId(name: BigInt) extends Token // All variables are : BigInt -} - -object Trees { - abstract class Expr - case class Times(lhs: Expr, rhs: Expr) extends Expr - case class Plus(lhs: Expr, rhs: Expr) extends Expr - case class And(lhs: Expr, rhs: Expr) extends Expr - case class Or(lhs: Expr, rhs: Expr) extends Expr - case class Var(id: BigInt) extends Expr - case class IntLiteral(v: BigInt) extends Expr - case class LessThan(lhs: Expr, rhs: Expr) extends Expr - case class Ite(cond: Expr, thn: Expr, els: Expr) extends Expr -} - -object Types { - abstract class Type - case object IntType extends Type - case object BoolType extends Type -} - -object Parser { - import Tokens._ - import Trees._ - - def parsePhrase(ts: List[Token]): Option[Expr] = { - parseGoal(ts) match { - case Some((res, Nil())) => Some(res) - case _ => None() - } - } - - def parseGoal(ts: List[Token]): Option[(Expr, List[Token])] = { - parseOr(ts) - } - - def parseOr(ts: List[Token]): Option[(Expr, List[Token])] = { - parseAnd(ts) match { - case Some((lhs, Cons(TLOr, r))) => - parseAnd(r) match { - case Some((rhs, ts2)) => Some((Or(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parseAnd(ts: List[Token]): Option[(Expr, List[Token])] = { - parseLT(ts) match { - case Some((lhs, Cons(TLAnd, r))) => - parseLT(r) match { - case Some((rhs, ts2)) => Some((And(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parseLT(ts: List[Token]): Option[(Expr, List[Token])] = { - parsePlus(ts) match { - case Some((lhs, Cons(TLT, r))) => - parsePlus(r) match { - case Some((rhs, ts2)) => Some((LessThan(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parsePlus(ts: List[Token]): Option[(Expr, List[Token])] = { - parseTimes(ts) match { - case Some((lhs, Cons(TPlus, r))) => - parsePlus(r) match { - case Some((rhs, ts2)) => Some((Plus(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parseTimes(ts: List[Token]): Option[(Expr, List[Token])] = { - parseLits(ts) match { - case Some((lhs, Cons(t, r))) if (t == TTimes) => - parseTimes(r) match { - case Some((rhs, ts2)) => Some((Plus(lhs, rhs), ts2)) - case None() => None() - } - case r => r - } - } - - def parseLits(ts: List[Token]): Option[(Expr, List[Token])] = ts match { - case Cons(TInt(v), r) => Some((IntLiteral(v), r)) - case Cons(TId(v), r) => Some((Var(v), r)) - case Cons(TLeftPar, r) => - parseGoal(r) match { - case Some((e, Cons(TRightPar, ts2))) => Some((e, ts2)) - case _ => None() - } - case Cons(TIf, Cons(TLeftPar, r)) => - parseGoal(r) match { - case Some((c, Cons(TRightPar, Cons(TLeftBrace, ts2)))) => - // Then - parseGoal(ts2) match { - case Some((th, Cons(TRightBrace, Cons(TElse, Cons(TLeftBrace, ts3))))) => - // Else - parseGoal(ts3) match { - case Some((el, Cons(TRightBrace, ts4))) => - Some((Ite(c, th, el), ts4)) - case _ => None() - } - case _ => None() - } - case _ => None() - } - case _ => None() - } -} - -object TypeChecker { - import Trees._ - import Types._ - - def typeChecks(e: Expr, exp: Option[Type]): Boolean = e match { - case Times(l, r) => (exp.getOrElse(IntType) == IntType) && typeChecks(l, Some(IntType)) && typeChecks(r, Some(IntType)) - case Plus(l, r) => (exp.getOrElse(IntType) == IntType) && typeChecks(l, Some(IntType)) && typeChecks(r, Some(IntType)) - case And(l, r) => (exp.getOrElse(BoolType) == BoolType) && typeChecks(l, Some(BoolType)) && typeChecks(r, Some(BoolType)) - case Or(l, r) => (exp.getOrElse(BoolType) == BoolType) && typeChecks(l, Some(BoolType)) && typeChecks(r, Some(BoolType)) - case LessThan(l, r) => (exp.getOrElse(BoolType) == BoolType) && typeChecks(l, Some(IntType)) && typeChecks(r, Some(IntType)) - case Ite(c, th, el) => typeChecks(c, Some(BoolType)) && typeChecks(th, exp) && typeChecks(el, exp) - case IntLiteral(_) => exp.getOrElse(IntType) == IntType - case Var(_) => exp.getOrElse(IntType) == IntType - } - - def typeChecks(e: Expr): Boolean = typeChecks(e, None()) -} - -object Simplifier { - import Trees._ - import Runtime._ - - // Constant folding + tautologies - def simplify(e: Expr)(implicit m: Map[BigInt, BigInt]): Expr = (e match { - // Special cases - case Plus(IntLiteral(a), IntLiteral(b)) => IntLiteral(a+b) - case LessThan(Var(id1), Var(id2)) if id1 == id2 => IntLiteral(0) - - // Recursion - case Times(lhs, rhs) => Times(simplify(lhs), simplify(rhs)) - case Plus(lhs, rhs) => Plus(simplify(lhs), simplify(rhs)) - case And(lhs, rhs) => And(simplify(lhs), simplify(rhs)) - case Or(lhs, rhs) => And(simplify(lhs), simplify(rhs)) - case LessThan(lhs, rhs) => LessThan(simplify(lhs), simplify(rhs)) - case Ite(cond, thn, elze) => Ite(simplify(cond), simplify(thn), simplify(elze)) - case _ => e - }) ensuring { - res => run(res)(m) == run(e)(m) - } - -} - -object Runtime { - import Trees._ - - def run(e: Expr)(implicit m: Map[BigInt, BigInt]): BigInt = e match { - case Times(lhs, rhs) => run(lhs) * run(rhs) - case Plus(lhs, rhs) => run(lhs) + run(rhs) - case And(lhs, rhs) => run(lhs) * run(rhs) - case Or(lhs, rhs) => if ((run(lhs) + run(rhs)) > 0) 1 else 0 - case IntLiteral(v) => v - case Var(id) => if (m contains id) m(id) else 0 - case LessThan(lhs, rhs) => if (run(lhs) < run(rhs)) 1 else 0 - case Ite(cond, thn, elze) => if (run(cond) != 0) run(thn) else run(elze) - } - - def test() = { - run(Plus(IntLiteral(42), Var(0)))(Map(BigInt(0) -> BigInt(1))) - } -} - - - diff --git a/testcases/web/demos/02_Lists.scala b/testcases/web/demos/02_Lists.scala deleted file mode 100644 index 59d3175ba803a0cfcffaf4dac80a3f9521e3681a..0000000000000000000000000000000000000000 --- a/testcases/web/demos/02_Lists.scala +++ /dev/null @@ -1,46 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object List { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set() - case Cons(i, t) => Set(i) ++ content(t) - } - - - - def insertUnique(l: List, v: BigInt): List = (l match { - case Cons(h, t) => - if (h == v) { - l - } else { - Cons(h, insertUnique(t, v)) - } - case Nil => - Cons(v, Nil) - }) ensuring { (res: List) => - true - //content(res) == content(l) ++ Set(v) && - //size(res) >= size(l) - } - - - - - def delete(l: List, v: BigInt): List = { - choose{ (res: List) => - content(res) == content(l) -- Set(v) - } - } - -} diff --git a/testcases/web/demos/03_Splits.scala b/testcases/web/demos/03_Splits.scala deleted file mode 100644 index a2bb904d05681d022d698b16f0470d8e5c11bec3..0000000000000000000000000000000000000000 --- a/testcases/web/demos/03_Splits.scala +++ /dev/null @@ -1,46 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object List { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def abs(i : BigInt) : BigInt = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def split1(list: List): (List,List) = { - choose { (res: (List,List)) => - (content(res._1) ++ content(res._2) == content(list)) - } - } - - def split2(list: List): (List,List) = { - choose { (res: (List,List)) => - (content(res._1) ++ content(res._2) == content(list)) && - abs(size(res._1) - size(res._2)) <= 1 - } - } - - def split3(list: List): (List,List) = { - choose { (res: (List,List)) => - (content(res._1) ++ content(res._2) == content(list)) && - abs(size(res._1) - size(res._2)) <= 1 && - size(res._1)+size(res._2) == size(list) - } - } - -} - diff --git a/testcases/web/demos/04_Sort.scala b/testcases/web/demos/04_Sort.scala deleted file mode 100644 index a53a8987055fe802e75aaadd602589ab47d074fd..0000000000000000000000000000000000000000 --- a/testcases/web/demos/04_Sort.scala +++ /dev/null @@ -1,77 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ -object Sort { -/* - def sort2(x : BigInt, y : BigInt) = choose{(res: (BigInt,BigInt)) => - Set(x,y) == Set(res._1, res._2) && res._1 <= res._2 - } -*/ - -/* - sealed abstract class List - case object Nil extends List - case class Cons(head: BigInt, tail: List) extends List - - def size(l: List) : BigInt = (l match { - case Nil => 0 - case Cons(x, rest) => x + size(rest) - }) -*/ - // ensuring(res => res > 0) - - // def s1 = size(Cons(10, Cons(1000, Nil))) - -/* - def content(l: List): Set[BigInt] = l match { - case Nil => Set() - case Cons(i, t) => Set(i) ++ content(t) - } -*/ - -/* - def isSorted(l : List) : Boolean = l match { - case Nil => true - case Cons(_,Nil) => true - case Cons(x1, Cons(x2, rest)) => - x1 < x2 && isSorted(Cons(x2,rest)) - } -*/ - //def t1 = isSorted(Cons(10, Cons(20, Nil))) - //def t2 = isSorted(Cons(15, Cons(15, Nil))) - -/* - def sInsert(x : BigInt, l : List) : List = { - require(isSorted(l)) - l match { - case Nil => Cons(x, Nil) - case Cons(e, rest) if (x == e) => l - case Cons(e, rest) if (x < e) => Cons(x, Cons(e,rest)) - case Cons(e, rest) if (x > e) => Cons(e, sInsert(x,rest)) - } - } ensuring {(res:List) => - isSorted(res) && content(res) == content(l) ++ Set(x)} - - // size(res) == size(l) + 1 -*/ - -/* - def insertMagic(x: BigInt, l: List): List = { - require(isSorted(l)) - choose {(res: List) => - isSorted(res) && content(res) == content(l) ++ Set[BigInt](x) - } - } -*/ - - //def m = insertMagic(17, Cons(10, Cons(15, Cons(20, Nil)))) - -/* - def sortMagic(l : List) = choose{(res:List) => - isSorted(res) && content(res) == content(l) - } -*/ - - // def mm = sortMagic(Cons(20, Cons(5, Cons(50, Cons(2, Nil))))) - -} diff --git a/testcases/web/demos/05_OpenDays.scala b/testcases/web/demos/05_OpenDays.scala deleted file mode 100644 index 9314e4b7585aa19fd66c4f736f81db05b9f3ee76..0000000000000000000000000000000000000000 --- a/testcases/web/demos/05_OpenDays.scala +++ /dev/null @@ -1,74 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object EpflOpenDays { - - sealed abstract class Liste - case object Vide extends Liste - case class Elem(e: BigInt, reste: Liste) extends Liste - - def taille(l: Liste): BigInt = (l match { - case Vide => 0 - case Elem(x, reste) => x + taille(reste) - }) - - //def s0 = taille(Elem(10, Elem(1000, Vide))) - - //ensuring(res => res >= 0) - - //def s1 = taille(Elem(10, Elem(1000, Vide))) - - def contenu(l: Liste): Set[BigInt] = l match { - case Vide => Set() - case Elem(e, reste) => Set(e) ++ contenu(reste) - } - -/* - def estTriée(l: Liste): Boolean = l match { - case Vide => true - case Elem(_, Vide) => true - case Elem(e1, Elem(e2, reste)) => - e1 < e2 && estTriée(Elem(e2, reste)) - } -*/ - - //def t1 = estTriée(Elem(10, Elem(14, Elem(20, Elem(25, Vide))))) - //def t2 = estTriée(Elem(10, Elem(14, Elem(1, Elem(2, Vide))))) - -/* - def insertion(x: BigInt, l: Liste): Liste = { - require(estTriée(l)) - l match { - case Vide => Elem(x, Vide) - case Elem(e, reste) if (x == e) => l - case Elem(e, reste) if (x < e) => Elem(x, Elem(e,reste)) - case Elem(e, reste) if (x > e) => Elem(e, insertion(x, reste)) - } - } ensuring { (res: Liste) => - estTriée(res) && - contenu(res) == contenu(l) ++ Set(x) - } -*/ -/* - def insertionMagique(x: BigInt, l: Liste): Liste = { - require(estTriée(l)) - choose { (res: Liste) => - estTriée(res) && - contenu(res) == contenu(l) ++ Set(x) - } - } -*/ - - //def m1 = insertionMagique(17, Elem(10, Elem(14, Elem(20, Elem(25, Vide))))) - -/* - def trier(l: Liste) = choose{ (res: Liste) => - estTriée(res) && contenu(res) == contenu(l) - } -*/ - - //def mm = trier(Elem(10, Elem(14, Elem(1, Elem(2, Vide))))) - -} - diff --git a/testcases/web/demos/05_OpenDays1.scala b/testcases/web/demos/05_OpenDays1.scala deleted file mode 100644 index 6a08b6138710efc005e6127cf0d72cea1dbf44ce..0000000000000000000000000000000000000000 --- a/testcases/web/demos/05_OpenDays1.scala +++ /dev/null @@ -1,24 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object EpflOpenDays { - - def max3(a: BigInt, b: BigInt, c: BigInt): BigInt = { - if (a > b) { - if (c > a) { - c - } else { - a - } - } else { - if (c > b) { - c - } else { - a - } - } - } ensuring { - res => res >= a && res >= b && res >= c - } -} diff --git a/testcases/web/demos/05_OpenDays2.scala b/testcases/web/demos/05_OpenDays2.scala deleted file mode 100644 index 480d0208070d85f85ca0287de911f976f97e655d..0000000000000000000000000000000000000000 --- a/testcases/web/demos/05_OpenDays2.scala +++ /dev/null @@ -1,82 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object EpflOpenDays { - @library - sealed abstract class Piece { - def valeur: BigInt = this match { - case Cent5 => 5 - case Cent10 => 10 - case Cent20 => 20 - case Cent50 => 50 - case Fr1 => 100 - case Fr2 => 200 - case Fr5 => 500 - case Bi10 => 1000 - case Bi20 => 2000 - case Bi50 => 5000 - case Bi100 => 10000 - case Bi200 => 20000 - case Bi1000 => 100000 - } - } - case object Cent5 extends Piece - case object Cent10 extends Piece - case object Cent20 extends Piece - case object Cent50 extends Piece - case object Fr1 extends Piece - case object Fr2 extends Piece - case object Fr5 extends Piece - case object Bi10 extends Piece - case object Bi20 extends Piece - case object Bi50 extends Piece - case object Bi100 extends Piece - case object Bi200 extends Piece - case object Bi1000 extends Piece - - - @library - sealed abstract class Liste { - def somme: BigInt = { - this match { - case Vide => BigInt(0) - case Elem(p, reste) => p.valeur + reste.somme - } - } ensuring { _ >= 0 } - } - case object Vide extends Liste - case class Elem(e: Piece, reste: Liste) extends Liste - - def pieceMax(v: BigInt): Piece = { - require(v > 0 && v%5 == 0) - if (v >= Bi1000.valeur) Bi1000 - else if (v >= Bi200.valeur ) Bi200 - else if (v >= Bi100.valeur ) Bi100 - else if (v >= Bi50.valeur ) Bi50 - else if (v >= Bi20.valeur ) Bi100 // *wink* *wink* - else if (v >= Bi10.valeur ) Bi10 - else if (v >= Fr5.valeur ) Fr5 - else if (v >= Fr2.valeur ) Fr2 - else if (v >= Fr1.valeur ) Fr1 - else if (v >= Cent50.valeur ) Cent50 - else if (v >= Cent20.valeur ) Cent20 - else if (v >= Cent10.valeur ) Cent10 - else Cent5 - } ensuring { _.valeur <= v } - - def pieces(v: BigInt): Liste = { - require(v >= 0 && v%5 == 0) - if (v == 0) { - Vide - } else { - val p = pieceMax(v) - Elem(p, pieces(v - p.valeur)) - } - } ensuring { res => - res.somme == v - } - - - def t = pieces(18440) -} diff --git a/testcases/web/invariant/01_InsertionSort.scala b/testcases/web/invariant/01_InsertionSort.scala deleted file mode 100644 index bcf4b8d98f5b37ad1afd229454990d71f24c8b07..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/01_InsertionSort.scala +++ /dev/null @@ -1,26 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object InsertionSort { - sealed abstract class List - case class Cons(head: BigInt, tail:List) extends List - case class Nil() extends List - - def size(l : List) : BigInt = (l match { - case Cons(_, xs) => 1 + size(xs) - case _ => 0 - }) - - def sortedIns(e: BigInt, l: List): List = { - l match { - case Cons(x,xs) => if (x <= e) Cons(x,sortedIns(e, xs)) else Cons(e, l) - case _ => Cons(e,Nil()) - } - } ensuring(res => size(res) == size(l) + 1 && time <= ? * size(l) + ?) - - def sort(l: List): List = (l match { - case Cons(x,xs) => sortedIns(x, sort(xs)) - case _ => Nil() - - }) ensuring(res => size(res) == size(l) && time <= ? * (size(l)*size(l)) + ?) -} diff --git a/testcases/web/invariant/02_ListOps.scala b/testcases/web/invariant/02_ListOps.scala deleted file mode 100644 index 23ca52bbd72b971c0b6915fa9c3fb7576c155a47..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/02_ListOps.scala +++ /dev/null @@ -1,60 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object ListOperations { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def append(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => Cons(x, append(xs, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && time <= ? *size(l1) + ?) - - def reverseRec(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => reverseRec(xs, Cons(x, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && time <= ? *size(l1) + ?) - - def reverse(l: List): List = { - reverseRec(l, Nil()) - - } ensuring (res => size(l) == size(res) && time <= ? * size(l) + ?) - - def reverse2(l: List): List = { - l match { - case Nil() => l - case Cons(hd, tl) => append(reverse2(tl), Cons(hd, Nil())) - } - } ensuring (res => size(res) == size(l) && time <= ? *(size(l)*size(l)) + ?) - - def remove(elem: BigInt, l: List): List = { - l match { - case Nil() => Nil() - case Cons(hd, tl) => if (hd == elem) remove(elem, tl) else Cons(hd, remove(elem, tl)) - } - } ensuring (res => size(l) >= size(res) && time <= ? *size(l) + ?) - - def contains(list: List, elem: BigInt): Boolean = (list match { - case Nil() => false - case Cons(x, xs) => x == elem || contains(xs, elem) - - }) ensuring (res => true && time <= ? *size(list) + ?) - - def distinct(l: List): List = ( - l match { - case Nil() => Nil() - case Cons(x, xs) => { - val newl = distinct(xs) - if (contains(newl, x)) newl - else Cons(x, newl) - } - }) ensuring (res => size(l) >= size(res) && time <= ? *(size(l)*size(l)) + ?) -} diff --git a/testcases/web/invariant/03_TreeOps.scala b/testcases/web/invariant/03_TreeOps.scala deleted file mode 100644 index 6d13fcef7a45ce58846c985daceacb36ae67ca5c..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/03_TreeOps.scala +++ /dev/null @@ -1,93 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - - -object TreeOperations { - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def listSize(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + listSize(t) - }) - - def size(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - size(l) + size(r) + 1 - } - } - } - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def insert(elem: BigInt, t: Tree): Tree = { - t match { - case Leaf() => Node(Leaf(), elem, Leaf()) - case Node(l, x, r) => if (x <= elem) Node(l, x, insert(elem, r)) - else Node(insert(elem, l), x, r) - } - } ensuring (res => height(res) <= height(t) + 1 && time <= ? *height(t) + ?) - - def addAll(l: List, t: Tree): Tree = { - l match { - case Nil() => t - case Cons(x, xs) =>{ - val newt = insert(x, t) - addAll(xs, newt) - } - } - } ensuring(_ => time <= ? *(listSize(l) * (height(t) + listSize(l))) + ? *listSize(l) + ?) - - def remove(elem: BigInt, t: Tree): Tree = { - t match { - case Leaf() => Leaf() - case Node(l, x, r) => { - - if (x < elem) Node(l, x, remove(elem, r)) - else if (x > elem) Node(remove(elem, l), x, r) - else { - t match { - case Node(Leaf(), x, Leaf()) => Leaf() - case Node(Leaf(), x, Node(_, rx, _)) => Node(Leaf(), rx, remove(rx, r)) - case Node(Node(_, lx, _), x, r) => Node(remove(lx, l), lx, r) - case _ => Leaf() - } - } - } - } - } ensuring (res => height(res) <= height(t) && time <= ? *height(t) + ?) - - def removeAll(l: List, t: Tree): Tree = { - l match { - case Nil() => t - case Cons(x, xs) => removeAll(xs, remove(x, t)) - } - } ensuring(_ => time <= ? *(listSize(l) * height(t)) + ? *listSize(l) + ?) - - def contains(elem : BigInt, t : Tree) : Boolean = { - t match { - case Leaf() => false - case Node(l, x, r) => - if(x == elem) true - else if (x < elem) contains(elem, r) - else contains(elem, l) - } - } ensuring (_ => time <= ? * height(t) + ?) -} \ No newline at end of file diff --git a/testcases/web/invariant/04_PropositionalLogic.scala b/testcases/web/invariant/04_PropositionalLogic.scala deleted file mode 100644 index afae7b0a0114f64974060c0885dd6d3feff01f2f..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/04_PropositionalLogic.scala +++ /dev/null @@ -1,114 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object PropositionalLogic { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Implies(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Literal(id: BigInt) extends Formula - case class True() extends Formula - case class False() extends Formula - - case class Pair(f: Formula, b: Boolean) - - sealed abstract class List - case class Cons(x: Pair, xs: List) extends List - case class Nil() extends List - - def size(f : Formula) : BigInt = (f match { - case And(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Or(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Implies(lhs, rhs) => size(lhs) + size(rhs) + 1 - case Not(f) => size(f) + 1 - case _ => 1 - }) - - def removeImplies(f: Formula): Formula = (f match { - case And(lhs, rhs) => And(removeImplies(lhs), removeImplies(rhs)) - case Or(lhs, rhs) => Or(removeImplies(lhs), removeImplies(rhs)) - case Implies(lhs, rhs) => Or(Not(removeImplies(lhs)),removeImplies(rhs)) - case Not(f) => Not(removeImplies(f)) - case _ => f - - }) ensuring(_ => time <= ? * size(f) + ?) - - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Implies(lhs, rhs) => Implies(nnf(lhs), nnf(rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Implies(lhs, rhs)) => And(nnf(lhs), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case Not(Literal(_)) => formula - case Literal(_) => formula - case Not(True()) => False() - case Not(False()) => True() - case _ => formula - }) ensuring(_ => time <= ? * size(formula) + ?) - - def isNNF(f: Formula): Boolean = { f match { - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Implies(lhs, rhs) => false - case Not(Literal(_)) => true - case Not(_) => false - case _ => true - }} ensuring(_ => time <= ? * size(f) + ?) - - def simplify(f: Formula): Formula = (f match { - case And(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs or rhs is false, return false - //if lhs is true return rhs - //if rhs is true return lhs - (sl,sr) match { - case (False(), _) => False() - case (_, False()) => False() - case (True(), _) => sr - case (_, True()) => sl - case _ => And(sl, sr) - } - } - case Or(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs or rhs is true, return true - //if lhs is false return rhs - //if rhs is false return lhs - (sl,sr) match { - case (True(), _) => True() - case (_, True()) => True() - case (False(), _) => sr - case (_, False()) => sl - case _ => Or(sl, sr) - } - } - case Implies(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs is false return true - //if rhs is true return true - //if lhs is true return rhs - //if rhs is false return Not(rhs) - (sl,sr) match { - case (False(), _) => True() - case (_, True()) => True() - case (True(), _) => sr - case (_, False()) => Not(sl) - case _ => Implies(sl, sr) - } - } - case Not(True()) => False() - case Not(False()) => True() - case _ => f - - }) ensuring(_ => time <= ? *size(f) + ?) -} diff --git a/testcases/web/invariant/05_BinaryTrie.scala b/testcases/web/invariant/05_BinaryTrie.scala deleted file mode 100644 index 38ff37b950b4229ba1ae17c959f75574ec00853b..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/05_BinaryTrie.scala +++ /dev/null @@ -1,116 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object BinaryTrie { - sealed abstract class Tree - case class Leaf() extends Tree - case class Node(nvalue: BigInt, left: Tree, right: Tree) extends Tree - - sealed abstract class IList - case class Cons(head: BigInt, tail: IList) extends IList - case class Nil() extends IList - - def listSize(l: IList): BigInt = (l match { - case Nil() => 0 - case Cons(x, xs) => 1 + listSize(xs) - }) - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(x, l, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def find(inp: IList, t: Tree): Tree = { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x, xs @ Cons(y, _)) => { - t match { - case Leaf() => t - case Node(v, l, r) => { - if (y > 0) find(xs, l) else find(xs, r) - } - } - } - case _ => t - } - } ensuring (_ => time <= ? * listSize(inp) + ?) - - def insert(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => t - case Cons(x, xs) => { - val newch = insert(xs, Leaf()) - newch match { - case Leaf() => Node(x, Leaf(), Leaf()) - case Node(y, _, _) => if (y > 0) Node(x, newch, Leaf()) else Node(y, Leaf(), newch) - } - } - } - - } - case Node(v, l, r) => { - inp match { - case Nil() => t - case Cons(x, Nil()) => t - case Cons(x, xs @ Cons(y, _)) => { - val ch = if (y > 0) l else r - if (y > 0) - Node(v, insert(xs, ch), r) - else - Node(v, l, insert(xs, ch)) - } - case _ => t - } - } - } - } ensuring (_ => time <= ? * listSize(inp) + ?) - - def create(inp: IList): Tree = { - insert(inp, Leaf()) - } ensuring (res => time <= ? * listSize(inp) + ?) - - def delete(inp: IList, t: Tree): Tree = { - t match { - case Leaf() => { - inp match { - case Nil() => Leaf() - case Cons(x ,xs) => { - Leaf() - } - } - } - case Node(v, l, r) => { - inp match { - case Nil() => { - t - } - case Cons(x, Nil()) => { - if(l == Leaf() && r == Leaf()) Leaf() - else t - } - case Cons(x ,xs@Cons(y, _)) => { - val ch = if(y > 0) l else r - val newch = delete(xs, ch) - if(newch == Leaf() && ((y > 0 && r == Leaf()) || (y <= 0 && l == Leaf()))) Leaf() - else { - if(y > 0) - Node(v, newch, r) - else - Node(v, l, newch) - } - } - case _ => t - } - } - } - } ensuring (_ => time <= ? * listSize(inp) + ?) -} \ No newline at end of file diff --git a/testcases/web/invariant/06_StringBuffer.scala b/testcases/web/invariant/06_StringBuffer.scala deleted file mode 100644 index c5f7dcf9015c5f576ae9d9a59a997f8e45ec9f32..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/06_StringBuffer.scala +++ /dev/null @@ -1,63 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object StringBuffer { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - sealed abstract class StringBuffer - case class Chunk(str: List, next: StringBuffer) extends StringBuffer - case class Empty() extends StringBuffer - - def length(sb: StringBuffer) : BigInt = sb match { - case Chunk(_, next) => 1 + length(next) - case _ => 0 - } - - def sizeBound(sb: StringBuffer, k: BigInt) : Boolean ={ - sb match { - case Chunk(str, next) => size(str) <= k && sizeBound(next, k) - case _ => 0 <= k - } - } - - def Equals(str1: List, str2: List, s1: StringBuffer, s2: StringBuffer, k: BigInt) : Boolean = { - require(sizeBound(s1, k) && sizeBound(s2, k) && size(str1) <= k && size(str2) <= k && k >= 0) - - (str1, str2) match { - case (Cons(h1,t1), Cons(h2,t2)) => { - - if(h1 != h2) false - else Equals(t1,t2, s1,s2, k) - } - case (Cons(_,_), Nil()) => { - s2 match { - case Chunk(str, next) => Equals(str1, str, s1, next, k) - case Empty() => false - } - } - case (Nil(), Cons(_,_)) => { - s1 match { - case Chunk(str, next) => Equals(str, str2, next, s2, k) - case Empty() => false - } - } - case _ =>{ - (s1,s2) match { - case (Chunk(nstr1, next1),Chunk(nstr2, next2)) => Equals(nstr1, nstr2, next1, next2, k) - case (Empty(),Chunk(nstr2, next2)) => Equals(str1, nstr2, s1, next2, k) - case (Chunk(nstr1, next1), Empty()) => Equals(nstr1, str2, next1, s2, k) - case _ => true - } - } - } - } ensuring(res => true && tmpl((a,b,c,d,e) => time <= a*((k+1)*(length(s1) + length(s2))) + b*size(str1) + e)) - - def max(x: BigInt, y: BigInt) : BigInt = if(x >= y) x else y -} diff --git a/testcases/web/invariant/07_ConcatVariations.scala b/testcases/web/invariant/07_ConcatVariations.scala deleted file mode 100644 index 44b8e0fb239222cdf7f4263adcdfd25c40bcf076..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/07_ConcatVariations.scala +++ /dev/null @@ -1,41 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object ConcatVariations { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def genL(n: BigInt): List = { - require(n >= 0) - if (n == 0) Nil() - else - Cons(n, genL(n - 1)) - } ensuring (res => size(res) == n && time <= ? *n + ?) - - def append(l1: List, l2: List): List = (l1 match { - case Nil() => l2 - case Cons(x, xs) => Cons(x, append(xs, l2)) - - }) ensuring (res => size(l1) + size(l2) == size(res) && time <= ? *size(l1) + ?) - - def f_good(m: BigInt, n: BigInt): List = { - require(0 <= m && 0 <= n) - if (m == 0) Nil() - else append(genL(n), f_good(m - 1, n)) - - } ensuring(res => size(res) == n*m && time <= ? *(n*m) + ? *n + ? *m + ?) - - def f_worst(m: BigInt, n: BigInt): List = { - require(0 <= m && 0 <= n) - - if (m == 0) Nil() - else append(f_worst(m - 1, n), genL(n)) - - } ensuring(res => size(res) == n*m && time <= ? *((n*m)*m)+ ? *(n*m)+ ? *n+ ? *m+ ?) -} diff --git a/testcases/web/invariant/08_LeftistHeap.scala b/testcases/web/invariant/08_LeftistHeap.scala deleted file mode 100644 index b938b3807fc4fcaf35c45bf43f74730aa8c565ca..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/08_LeftistHeap.scala +++ /dev/null @@ -1,82 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -import leon.annotation._ - -object LeftistHeap { - sealed abstract class Heap - case class Leaf() extends Heap - case class Node(rk : BigInt, value: BigInt, left: Heap, right: Heap) extends Heap - - private def rightHeight(h: Heap) : BigInt = h match { - case Leaf() => 0 - case Node(_,_,_,r) => rightHeight(r) + 1 - } - - private def rank(h: Heap) : BigInt = h match { - case Leaf() => 0 - case Node(rk,_,_,_) => rk - } - - private def hasLeftistProperty(h: Heap) : Boolean = (h match { - case Leaf() => true - case Node(_,_,l,r) => hasLeftistProperty(l) && hasLeftistProperty(r) && rightHeight(l) >= rightHeight(r) && (rank(h) == rightHeight(h)) - }) - - @monotonic - def twopower(x: BigInt) : BigInt = { - require(x >= 0) - if(x < 1) 1 - else - 2* twopower(x - 1) - } - - def size(t: Heap): BigInt = { - require(hasLeftistProperty(t)) - (t match { - case Leaf() => BigInt(0) - case Node(_,v, l, r) => size(l) + 1 + size(r) - }) - } ensuring (res => twopower(rightHeight(t)) <= ? *res + ?) - - def leftRightHeight(h: Heap) : BigInt = {h match { - case Leaf() => 0 - case Node(_,_,l,r) => rightHeight(l) - }} - - def removeMax(h: Heap) : Heap = { - require(hasLeftistProperty(h)) - h match { - case Node(_,_,l,r) => merge(l, r) - case l @ Leaf() => l - } - } ensuring(res => time <= ? *leftRightHeight(h) + ?) - - private def merge(h1: Heap, h2: Heap) : Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2)) - h1 match { - case Leaf() => h2 - case Node(_, v1, l1, r1) => h2 match { - case Leaf() => h1 - case Node(_, v2, l2, r2) => - if(v1 > v2) - makeT(v1, l1, merge(r1, h2)) - else - makeT(v2, l2, merge(h1, r2)) - } - } - } ensuring(res => time <= ? *rightHeight(h1) + ? *rightHeight(h2) + ?) - - private def makeT(value: BigInt, left: Heap, right: Heap) : Heap = { - if(rank(left) >= rank(right)) - Node(rank(right) + 1, value, left, right) - else - Node(rank(left) + 1, value, right, left) - } - - def insert(element: BigInt, heap: Heap) : Heap = { - require(hasLeftistProperty(heap)) - - merge(Node(1, element, Leaf(), Leaf()), heap) - - } ensuring(res => time <= ? *rightHeight(heap) + ?) -} diff --git a/testcases/web/invariant/09_RedBlackTree.scala b/testcases/web/invariant/09_RedBlackTree.scala deleted file mode 100644 index 43f3c7248bdc5a551d44fb5e6186109c7b1b3b4a..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/09_RedBlackTree.scala +++ /dev/null @@ -1,108 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ -import scala.collection.immutable.Set - -object RedBlackTree { - sealed abstract class Color - case class Red() extends Color - case class Black() extends Color - - sealed abstract class Tree - case class Empty() extends Tree - case class Node(color: Color, left: Tree, value: BigInt, right: Tree) extends Tree - - def twopower(x: BigInt) : BigInt = { - require(x >= 0) - if(x < 1) 1 - else - 2* twopower(x - 1) - } - - def size(t: Tree): BigInt = { - require(blackBalanced(t)) - (t match { - case Empty() => BigInt(0) - case Node(_, l, v, r) => size(l) + 1 + size(r) - }) - } ensuring (res => twopower(blackHeight(t)) <= ? *res + ?) - - def blackHeight(t : Tree) : BigInt = { - t match { - case Node(Black(), l, _, _) => blackHeight(l) + 1 - case Node(Red(), l, _, _) => blackHeight(l) - case _ => 0 - } - } - - def isBlack(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(),_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty() => true - case Node(Black(), l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red(), l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case _ => false - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case _ => true - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case _ => true - } - - def ins(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - - t match { - case Empty() => Node(Red(),Empty(),x,Empty()) - case Node(c,a,y,b) => - if(x < y) { - val t1 = ins(x, a) - balance(c, t1, y, b) - } - else if (x == y){ - Node(c,a,y,b) - } - else{ - val t1 = ins(x, b) - balance(c,a,y,t1) - } - } - } ensuring(res => time <= ? *blackHeight(t) + ?) - - def makeBlack(n: Tree): Tree = { - n match { - case Node(Red(),l,v,r) => Node(Black(),l,v,r) - case _ => n - } - } - - def add(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t) ) - val t1 = ins(x, t) - makeBlack(t1) - - } ensuring(res => time <= ? *blackHeight(t) + ?) - - def balance(co: Color, l: Tree, x: BigInt, r: Tree): Tree = { - Node(co,l,x,r) - match { - case Node(Black(),Node(Red(),Node(Red(),a,xV,b),yV,c),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),Node(Red(),a,xV,Node(Red(),b,yV,c)),zV,d) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),Node(Red(),b,yV,c),zV,d)) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case Node(Black(),a,xV,Node(Red(),b,yV,Node(Red(),c,zV,d))) => - Node(Red(),Node(Black(),a,xV,b),yV,Node(Black(),c,zV,d)) - case _ => Node(co,l,x,r) - } - } -} diff --git a/testcases/web/invariant/10_BinomialHeap.scala b/testcases/web/invariant/10_BinomialHeap.scala deleted file mode 100644 index 905ab01461e0c8b6fd2558a6573e8a53f0b57c84..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/10_BinomialHeap.scala +++ /dev/null @@ -1,154 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object BinomialHeap { - case class TreeNode(rank: BigInt, elem: Element, children: BinomialHeap) - case class Element(n: BigInt) - - sealed abstract class BinomialHeap - case class ConsHeap(head: TreeNode, tail: BinomialHeap) extends BinomialHeap - case class NilHeap() extends BinomialHeap - - sealed abstract class List - case class NodeL(head: BinomialHeap, tail: List) extends List - case class NilL() extends List - - sealed abstract class OptionalTree - case class Some(t : TreeNode) extends OptionalTree - case class None() extends OptionalTree - - private def leq(a: Element, b: Element) : Boolean = { - a match { - case Element(a1) => { - b match { - case Element(a2) => { - if(a1 <= a2) true - else false - } - } - } - } - } - - def isEmpty(t: BinomialHeap) = t match { - case ConsHeap(_,_) => false - case _ => true - } - - def rank(t: TreeNode) : BigInt = t.rank - - def root(t: TreeNode) : Element = t.elem - - def link(t1: TreeNode, t2: TreeNode): TreeNode = { - if (leq(t1.elem, t2.elem)) { - TreeNode(t1.rank + 1, t1.elem, ConsHeap(t2, t1.children)) - } else { - TreeNode(t1.rank + 1, t2.elem, ConsHeap(t1, t2.children)) - } - } - - def treeNum(h: BinomialHeap) : BigInt = { - h match { - case ConsHeap(head, tail) => 1 + treeNum(tail) - case _ => 0 - } - } - - def insTree(t: TreeNode, h: BinomialHeap) : BinomialHeap = { - h match { - case ConsHeap(head, tail) => { - if (rank(t) < rank(head)) { - ConsHeap(t, h) - } else if (rank(t) > rank(head)) { - ConsHeap(head, insTree(t,tail)) - } else { - insTree(link(t,head), tail) - } - } - case _ => ConsHeap(t, NilHeap()) - } - } ensuring(_ => time <= ? * treeNum(h) + ?) - - def merge(h1: BinomialHeap, h2: BinomialHeap): BinomialHeap = { - h1 match { - case ConsHeap(head1, tail1) => { - h2 match { - case ConsHeap(head2, tail2) => { - if (rank(head1) < rank(head2)) { - ConsHeap(head1, merge(tail1, h2)) - } else if (rank(head2) < rank(head1)) { - ConsHeap(head2, merge(h1, tail2)) - } else { - mergeWithCarry(link(head1, head2), tail1, tail2) - } - } - case _ => h1 - } - } - case _ => h2 - } - } ensuring(_ => time <= ? * treeNum(h1) + ? * treeNum(h2) + ?) - - def mergeWithCarry(t: TreeNode, h1: BinomialHeap, h2: BinomialHeap): BinomialHeap = { - h1 match { - case ConsHeap(head1, tail1) => { - h2 match { - case ConsHeap(head2, tail2) => { - if (rank(head1) < rank(head2)) { - if (rank(t) < rank(head1)) - ConsHeap(t, ConsHeap(head1, merge(tail1, h2))) - else - mergeWithCarry(link(t, head1), tail1, h2) - } else if (rank(head2) < rank(head1)) { - if (rank(t) < rank(head2)) - ConsHeap(t, ConsHeap(head2, merge(h1, tail2))) - else - mergeWithCarry(link(t, head2), h1, tail2) - } else { - ConsHeap(t, mergeWithCarry(link(head1, head2), tail1, tail2)) - } - } - case _ => { - insTree(t, h1) - } - } - } - case _ => insTree(t, h2) - } - } ensuring (_ => time <= ? * treeNum(h1) + ? * treeNum(h2) + ?) - - def removeMinTree(h: BinomialHeap): (OptionalTree, BinomialHeap) = { - h match { - case ConsHeap(head, NilHeap()) => (Some(head), NilHeap()) - case ConsHeap(head1, tail1) => { - val (opthead2, tail2) = removeMinTree(tail1) - opthead2 match { - case Some(head2) => - if (leq(root(head1), root(head2))) { - (Some(head1), tail1) - } else { - (Some(head2), ConsHeap(head1, tail2)) - } - case _ => (Some(head1), tail1) - } - } - case _ => (None(), NilHeap()) - } - } ensuring (res => treeNum(res._2) <= treeNum(h) && time <= ? * treeNum(h) + ?) - - def minTreeChildren(h: BinomialHeap) : BigInt = { - val (min, _) = removeMinTree(h) - min match { - case Some(TreeNode(_,_,ch)) => treeNum(ch) - case _ => 0 - } - } - - def deleteMin(h: BinomialHeap) : BinomialHeap = { - val (min, ts2) = removeMinTree(h) - min match { - case Some(TreeNode(_,_,ts1)) => merge(ts1, ts2) - case _ => h - } - } ensuring(_ => time <= ? * minTreeChildren(h) + ? * treeNum(h) + ?) -} diff --git a/testcases/web/invariant/11_Amortized_BigNums.scala b/testcases/web/invariant/11_Amortized_BigNums.scala deleted file mode 100644 index 883d1f45ab8752668070699c840edd7a3de160b9..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/11_Amortized_BigNums.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.invariant._ -import leon.instrumentation._ - -object BigNums { - sealed abstract class BigNum - case class Cons(head: BigInt, tail: BigNum) extends BigNum - case class Nil() extends BigNum - - def incrTime(l: BigNum) : BigInt = { - l match { - case Nil() => 1 - case Cons(x, tail) => - if(x == 0) 1 - else 1 + incrTime(tail) - } - } - - def potentialIncr(l: BigNum) : BigInt = { - l match { - case Nil() => 0 - case Cons(x, tail) => - if(x == 0) potentialIncr(tail) - else 1 + potentialIncr(tail) - } - } - - def increment(l: BigNum) : BigNum = { - l match { - case Nil() => Cons(1,l) - case Cons(x, tail) => - if(x == 0) Cons(1, tail) - else Cons(0, increment(tail)) - } - } ensuring (res => time <= ? * incrTime(l) + ? && incrTime(l) + potentialIncr(res) - potentialIncr(l) <= ?) - - /** - * Nop is the number of operations - */ - def incrUntil(nop: BigInt, l: BigNum) : BigNum = { - if(nop == 0) l - else { - incrUntil(nop-1, increment(l)) - } - } ensuring (res => time <= ? * nop + ? * potentialIncr(l) + ?) - - def count(nop: BigInt) : BigNum = { - incrUntil(nop, Nil()) - } ensuring (res => time <= ? * nop + ?) - -} diff --git a/testcases/web/invariant/12_Par_Folds.scala b/testcases/web/invariant/12_Par_Folds.scala deleted file mode 100755 index 5c4f51d119e18aa74d1fc0c263094a5cf6966a42..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/12_Par_Folds.scala +++ /dev/null @@ -1,81 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - -object TreeMaps { - - sealed abstract class Tree - case class Node(left: Tree, value: BigInt, right: Tree) extends Tree - case class Leaf() extends Tree - - def height(t: Tree): BigInt = { - t match { - case Leaf() => 0 - case Node(l, x, r) => { - val hl = height(l) - val hr = height(r) - if (hl > hr) hl + 1 else hr + 1 - } - } - } - - def parallelSearch(elem : BigInt, t : Tree) : Boolean = { - t match { - case Leaf() => false - case Node(l, x, r) => - if(x == elem) true - else { - val r1 = parallelSearch(elem, r) - val r2 = parallelSearch(elem, l) - if(r1 || r2) true - else false - } - } - } ensuring(_ => depth <= ? * height(t) + ?) - - - def squareMap(t : Tree) : Tree = { - t match { - case Leaf() => t - case Node(l, x, r) => - val nl = squareMap(l) - val nr = squareMap(r) - Node(nl, x*x, nr) - } - } ensuring (_ => depth <= ? * height(t) + ?) - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = (l match { - case Nil() => 0 - case Cons(_, t) => 1 + size(t) - }) - - def fact(n : BigInt) : BigInt = { - require(n >= 0) - - if(n == 1 || n == 0) BigInt(1) - else n * fact(n-1) - - } ensuring(_ => depth <= ? * n + ?) - - def descending(l: List, k: BigInt) : Boolean = { - l match { - case Nil() => true - case Cons(x, t) => x > 0 && x <= k && descending(t, x-1) - } - } - - def factMap(l: List, k: BigInt): List = { - require(descending(l, k) && k >= 0) - - l match { - case Nil() => Nil() - case Cons(x, t) => { - val f = fact(x) - Cons(f, factMap(t, x-1)) - } - - }} ensuring(_ => depth <= ? * k + ?) -} \ No newline at end of file diff --git a/testcases/web/invariant/13_Par_MSort.scala b/testcases/web/invariant/13_Par_MSort.scala deleted file mode 100644 index 8a818137eb32a3f9eb63297a6219faf219cec4eb..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/13_Par_MSort.scala +++ /dev/null @@ -1,57 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ - -object MergeSort { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - def size(l: List): BigInt = { - l match { - case Nil() => BigInt(0) - case Cons(x, xs) => 1 + size(xs) - } - } ensuring (res => res >= 0) - - def length(l: List): BigInt = { - l match { - case Nil() => BigInt(0) - case Cons(x, xs) => 1 + length(xs) - } - } ensuring (res => res >= 0 && res == size(l) && depth <= ? * size(l) + ?) - - def split(l: List, n: BigInt): (List, List) = { - require(n >= 0 && n <= size(l)) - if (n <= 0) (Nil(), l) - else - l match { - case Nil() => (Nil(), l) - case Cons(x, xs) => { - val (fst, snd) = split(xs, n - 1) - (Cons(x, fst), snd) - } - } - } ensuring (res => size(res._2) == size(l) - n && size(res._1) == n && depth <= ? * n + ?) - - def merge(l1: List, l2: List): List = (l2 match { - case Nil() => l1 - case Cons(x, xs) => - l1 match { - case Nil() => l2 - case Cons(y, ys) => - if (y < x) - Cons(y, merge(ys, l2)) - else - Cons(x, merge(l1, xs)) - } - }) ensuring (res => size(l1) + size(l2) == size(res) && depth <= ? * size(l1) + ? * size(l2) + ?) - - def mergeSort(l: List): List = (l match { - case Nil() => l - case Cons(x, Nil()) => l - case _ => - val (fst, snd) = split(l, length(l) / 2) - merge(mergeSort(fst), mergeSort(snd)) - - }) ensuring (res => size(res) == size(l) && depth <= ? * size(l) + ?) -} diff --git a/testcases/web/invariant/14_Par_PropLogic.scala b/testcases/web/invariant/14_Par_PropLogic.scala deleted file mode 100644 index 096dc8f60377a5dd10ad94f3fbd0ddf33c3f6481..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/14_Par_PropLogic.scala +++ /dev/null @@ -1,113 +0,0 @@ -import leon.instrumentation._ -import leon.invariant._ -import leon.annotation._ - -object PropLogicDepth { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Implies(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Literal(id: BigInt) extends Formula - case class True() extends Formula - case class False() extends Formula - - def max(x: BigInt, y: BigInt) = if (x >= y) x else y - - def nestingDepth(f: Formula): BigInt = (f match { - case And(lhs, rhs) => max(nestingDepth(lhs), nestingDepth(rhs)) + 1 - case Or(lhs, rhs) => max(nestingDepth(lhs), nestingDepth(rhs)) + 1 - case Implies(lhs, rhs) => max(nestingDepth(lhs), nestingDepth(rhs)) + 1 - case Not(f) => nestingDepth(f) + 1 - case _ => 1 - }) - - def removeImplies(f: Formula): Formula = (f match { - case And(lhs, rhs) => And(removeImplies(lhs), removeImplies(rhs)) - case Or(lhs, rhs) => Or(removeImplies(lhs), removeImplies(rhs)) - case Implies(lhs, rhs) => Or(Not(removeImplies(lhs)), removeImplies(rhs)) - case Not(f) => Not(removeImplies(f)) - case _ => f - - }) ensuring (_ => depth <= ? * nestingDepth(f) + ?) - - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Implies(lhs, rhs) => Implies(nnf(lhs), nnf(rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Implies(lhs, rhs)) => And(nnf(lhs), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case Not(Literal(_)) => formula - case Literal(_) => formula - case Not(True()) => False() - case Not(False()) => True() - case _ => formula - }) ensuring (_ => depth <= ? * nestingDepth(formula) + ?) - - def isNNF(f: Formula): Boolean = { - f match { - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Implies(lhs, rhs) => false - case Not(Literal(_)) => true - case Not(_) => false - case _ => true - } - } ensuring (_ => depth <= ? * nestingDepth(f) + ?) - - def simplify(f: Formula): Formula = (f match { - case And(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs or rhs is false, return false - //if lhs is true return rhs - //if rhs is true return lhs - (sl, sr) match { - case (False(), _) => False() - case (_, False()) => False() - case (True(), _) => sr - case (_, True()) => sl - case _ => And(sl, sr) - } - } - case Or(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs or rhs is true, return true - //if lhs is false return rhs - //if rhs is false return lhs - (sl, sr) match { - case (True(), _) => True() - case (_, True()) => True() - case (False(), _) => sr - case (_, False()) => sl - case _ => Or(sl, sr) - } - } - case Implies(lhs, rhs) => { - val sl = simplify(lhs) - val sr = simplify(rhs) - - //if lhs is false return true - //if rhs is true return true - //if lhs is true return rhs - //if rhs is false return Not(rhs) - (sl, sr) match { - case (False(), _) => True() - case (_, True()) => True() - case (True(), _) => sr - case (_, False()) => Not(sl) - case _ => Implies(sl, sr) - } - } - case Not(True()) => False() - case Not(False()) => True() - case _ => f - - }) ensuring (_ => depth <= ? * nestingDepth(f) + ?) -} \ No newline at end of file diff --git a/testcases/web/invariant/15_Numerical_SeeSaw.scala b/testcases/web/invariant/15_Numerical_SeeSaw.scala deleted file mode 100644 index bb08b70e78145a64d2eadc7e9ca4eec721b0babb..0000000000000000000000000000000000000000 --- a/testcases/web/invariant/15_Numerical_SeeSaw.scala +++ /dev/null @@ -1,15 +0,0 @@ -object SeeSaw { - def s(x: BigInt, y: BigInt, z: BigInt): BigInt = { - require(y >= 0) - if (x >= 100) { - y - } else if (x <= z) { - s(x + 1, y + 2, z) - } else if (x <= z + 9) { - s(x + 1, y + 3, z) - } else { - s(x + 2, y + 1, z) - } - } ensuring (res => (100 - x <= 2 * res)) - // postcondition is not inductive -} \ No newline at end of file diff --git a/testcases/web/sav15/01_Exercise1.scala b/testcases/web/sav15/01_Exercise1.scala deleted file mode 100644 index 2b5e433c01dae897db69a303f59500f215232b15..0000000000000000000000000000000000000000 --- a/testcases/web/sav15/01_Exercise1.scala +++ /dev/null @@ -1,19 +0,0 @@ -object Bank1 { - case class Acc(checking : BigInt, savings : BigInt) - - def putAside(x: BigInt, a: Acc): Acc = { - require (notRed(a) && a.checking >= x) - Acc(a.checking - x, a.savings + x) - } ensuring { - r => notRed(r) && sameTotal(a, r) - } - - - def sameTotal(a1: Acc, a2: Acc): Boolean = { - a1.checking + a1.savings == a2.checking + a2.savings - } - - def notRed(a: Acc) : Boolean = { - a.checking >= 0 && a.savings >= 0 - } -} diff --git a/testcases/web/sav15/02_Exercise2.scala b/testcases/web/sav15/02_Exercise2.scala deleted file mode 100644 index e13db4ca70d29b2334c2573f588c191379256b90..0000000000000000000000000000000000000000 --- a/testcases/web/sav15/02_Exercise2.scala +++ /dev/null @@ -1,40 +0,0 @@ -import leon.lang._ - -object PropositionalLogic { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Implies(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Literal(id: BigInt) extends Formula - - - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Implies(lhs, rhs) => nnf(Or(Not(lhs), rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Implies(lhs, rhs)) => And(nnf(lhs), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case Not(Literal(_)) => formula - case Literal(_) => formula - }) ensuring(isNNF(_)) - - def isNNF(f: Formula): Boolean = f match { - case _ => false - /* TODO: Implement isNNF */ - } - - // Note that matching should be exhaustive due to precondition. - def vars(f: Formula): Set[BigInt] = { - require(isNNF(f)) - f match { - case And(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Or(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Not(Literal(i)) => Set[BigInt](i) - case Literal(i) => Set[BigInt](i) - } - } -} diff --git a/testcases/web/sav15/03_Exercise3.scala b/testcases/web/sav15/03_Exercise3.scala deleted file mode 100644 index ca9d23efbe4a22cf6cdb1fa355da16de65702dbb..0000000000000000000000000000000000000000 --- a/testcases/web/sav15/03_Exercise3.scala +++ /dev/null @@ -1,100 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object ListWithSize { - sealed abstract class List[T] { - def size: BigInt = { - this match { - case Cons(h, t) => 1 + t.size - case Nil() => BigInt(0) - } - } // TODO: Add appropriate post-condition - - def sizeTailRec: BigInt = sizeTailRec0(0) - - def sizeTailRec0(acc: BigInt): BigInt = { - require(acc >= 0) - this match { - case Cons(h, t) => t.sizeTailRec0(acc + 1) - case Nil() => acc - } - } // TODO: Add appropriate post-condition - - // Verify - def zip[U](that: List[U]): List[(T, U)] = { - // TODO: Add appropriate pre-condition - this match { - case Nil() => Nil[(T,U)]() - case Cons(h1, t1) => that match { - case Cons(h2, t2) => Cons((h1, h2), t1.zip(t2)) - } - } - } ensuring(_.size == this.size) - - - def content: Set[T] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - // Verify - def reverse: List[T] = { - reverse0(Nil()) - } ensuring(_.content == this.content) - - def reverse0(acc: List[T]): List[T] = (this match { - case Nil() => acc - case Cons(h, t) => t.reverse0(Cons(h, acc)) - }) // TODO: Add appropriate post-condition - - - def append(that: List[T]): List[T] = (this match { - case Nil() => that - case Cons(h, t) => Cons(h, t.append(that)) - }) ensuring(_.content == this.content ++ that.content) - - - } - case class Cons[T](head: T, tail: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - - // Verify - def sizesAreEquiv[T](l: List[T]): Boolean = { - l.size == l.sizeTailRec - }.holds - - - def sizeAndContent[T](l: List[T]): Boolean = { - l.size == 0 || l.content != Set[T]() - }.holds - - def drunk[T](l: List[T]): List[T] = (l match { - case Nil() => Nil[T]() - case Cons(x,l1) => Cons(x,Cons(x,drunk(l1))) - }) ensuring { - res => true // TODO: find postcondition - } - - - def funnyCons[T](x: T, l: List[T]): List[T] = (l match { - case Nil() => Cons(x, Nil()) - case c @ Cons(_,_) => Cons(x, c) - }) ensuring(_.size > 0) - - - @induct - def nilAppend[T](l: List[T]): Boolean = { - l.append(Nil()) == l - }.holds - - @induct - def appendAssoc[T](xs: List[T], ys: List[T], zs: List[T]) : Boolean = { - false // find predicate - }.holds - - @induct - def sizeAppend[T](l1: List[T], l2 : List[T]) : Boolean = { - (l1.append(l2).size == l1.size + l2.size) - }.holds -} diff --git a/testcases/web/sav15/04_Exercise4.scala b/testcases/web/sav15/04_Exercise4.scala deleted file mode 100644 index 411a731137072dc0da6d8ace59620e3ab4c9c63e..0000000000000000000000000000000000000000 --- a/testcases/web/sav15/04_Exercise4.scala +++ /dev/null @@ -1,68 +0,0 @@ -import leon.annotation._ -import leon.lang._ - -object InsertionSort { - - sealed abstract class Option[T] - case class Some[T](value: T) extends Option[T] - case class None[T]() extends Option[T] - - - sealed abstract class List { - def size: BigInt = (this match { - case Nil() => 0 - case Cons(_, t) => 1 + t.size - }) - - def content: Set[BigInt] = this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - - def min: Option[BigInt] = this match { - case Nil() => None() - case Cons(h, t) => t.min match { - case None() => Some(h) - case Some(m) => if(h < m) Some(h) else Some(m) - } - } - - def isSorted: Boolean = this match { - case Nil() => true - case Cons(h, Nil()) => true - case Cons(h1, t1 @ Cons(h2, t2)) => h1 <= h2 && t1.isSorted - } - - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def insert(e: BigInt): List = { - require(isSorted) - this match { - case Nil() => Cons(e, Nil()) - case Cons(h, t) => - if (h <= e) { - Cons(h, t.insert(e)) - } else { - Cons(e, this) - } - } - } - - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort: List = (this match { - case Nil() => Nil() - case Cons(h, t) => t.sort.insert(h) - }) ensuring(res => res.content == this.content - && res.isSorted - && res.size == this.size - ) - - } - case class Cons(h: BigInt, t: List) extends List - case class Nil() extends List - - -} diff --git a/testcases/web/sav15/05_Exercise5.scala b/testcases/web/sav15/05_Exercise5.scala deleted file mode 100644 index a76401c2622bc4cec14b4703e43f01bd8eca4db4..0000000000000000000000000000000000000000 --- a/testcases/web/sav15/05_Exercise5.scala +++ /dev/null @@ -1,67 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object SearchList { - sealed abstract class List[T] { - def size: BigInt = { - this match { - case Nil() => BigInt(0) - case Cons(h, t) => 1 + t.size - } - } ensuring { _ >= 0 } - - def content: Set[T] = { - this match { - case Nil() => Set() - case Cons(h, t) => Set(h) ++ t.content - } - } - - def firstPosOf(v: T): BigInt = { - this match { - case Nil() => BigInt(-1) - case Cons(h, t) if h == v => BigInt(0) - case Cons(h, t) => - val p = t.firstPosOf(v) - if (p >= 0) { - p + 1 - } else { - p - } - } - } ensuring { - res => false // TODO: Ensure that if (and only if) res is non-negative, the list contains v. - - } - - def take(n: BigInt): List[T] = { - require(n >= 0) - this match { - case Nil() => Nil[T]() - case Cons(h, t) if n == 0 => Nil[T]() - case Cons(h, t) => Cons(h, t.take(n - 1)) - } - } ensuring { - res => res.size <= n - } - - def contains(v: T): Boolean = { - this match { - case Nil() => false - case Cons(h, _) if h == v => true - case Cons(_, t) => t.contains(v) - } - } ensuring { - res => res == (content contains v) - } - } - - case class Cons[T](h: T, t: List[T]) extends List[T] - case class Nil[T]() extends List[T] - - @induct - def wtf[T](l: List[T], v: T): Boolean = { - !((l.contains(v)) && (l.take(l.firstPosOf(v)).contains(v))) // What is this function checking? Translate to english. Can you remove the l.contains(v) part? Why? - }.holds -} - diff --git a/testcases/web/sav15/06_Exercise6.scala b/testcases/web/sav15/06_Exercise6.scala deleted file mode 100644 index 01aa1d62a13eeb7bc0b7da2fb7268277177323d1..0000000000000000000000000000000000000000 --- a/testcases/web/sav15/06_Exercise6.scala +++ /dev/null @@ -1,104 +0,0 @@ -import leon.lang._ -import leon.collection._ -import leon._ -/** - * 1) Implement the isSearchTree property that checks bounds of elements in a - * search tree. Assume that the tree is strictly sorted (no dupplicates) - * - * 2) Implement operations on Binary Search Trees as efficiently as you can. - * These operations will likely not verify, but make sure that leon does not - * find counter-examples within a reasonnable timeout (e.g. --timeout=5 ) - * - * You do not need to change the pre-/post-conditions - * - * 3) Implement toList to return a sorted list from a search tree. - */ - -object BinaryTree { - - abstract class Tree { - def content: Set[BigInt] = { - this match { - case Empty => Set() - case Node(l, v, r) => l.content ++ Set(v) ++ r.content - } - } - - def size: BigInt = { - this match { - case Empty => BigInt(0) - case Node(l, _, r) => l.size + r.size + 1 - } - } ensuring { _ >= 0 } - - - def +(x: BigInt): Tree = { - require(isBT) - this // TODO - } ensuring { - res => res.isBT && - res.content == this.content ++ Set(x) && - res.size >= this.size && - res.size <= this.size + 1 - } - - def -(x: BigInt): Tree = { - require(isBT) - this // TODO - } ensuring { - res => res.isBT && - res.content == this.content -- Set(x) && - res.size <= this.size && - res.size >= this.size - 1 - } - - def ++(that: Tree): Tree = { - require(this.isBT && that.isBT) - this // TODO - } ensuring { - res => res.isBT && res.content == this.content ++ that.content - } - - def contains(x: BigInt): Boolean = { - require(isBT) - false // TODO - } ensuring { - res => res == (content contains x) - } - - def toList: List[BigInt] = { - require(isBT) - Nil[BigInt]() // TODO - } ensuring { - res => res.content == this.content && isSorted(res) - } - - // Properties - - def isBT: Boolean = { - isSearchTree(None(), None()) - } - - def isSearchTree(min: Option[BigInt], max: Option[BigInt]): Boolean = { - this match { - case Empty => true - case Node(l, v, r) => - true // TODO - } - } - } - - case object Empty extends Tree - case class Node(l: Tree, v: BigInt, r: Tree) extends Tree - - - def isSorted(l: List[BigInt]): Boolean = { - l match { - case Cons(v1, t @ Cons(v2, _)) if v1 >= v2 => false - case Cons(h, t) => isSorted(t) - case Nil() => true - } - } -} - - diff --git a/testcases/web/sav15/07_Exercise7.scala b/testcases/web/sav15/07_Exercise7.scala deleted file mode 100644 index dab1fcb5ea47b415810d5fddf1c72cf447c4a11d..0000000000000000000000000000000000000000 --- a/testcases/web/sav15/07_Exercise7.scala +++ /dev/null @@ -1,32 +0,0 @@ -import leon.lang._ - -/** - * 1) Implement operations on rationals: addition, substraction, multiplication and division - * Ensure that the results are rationals, add necessary preconditions. - * 2) Implement rational equivalence (~). - * 3) Write lemmas that show that if a1 ~ a2, and b1 ~ b2, then (a1 <op> b1) ~ (a2 <op> b2), for each <op> - */ -object Rationals { - // Represents n/d - case class Q(n: BigInt, d: BigInt) { - - def +(that: Q):Q = this // TODO - - def -(that: Q):Q = this // TODO - - def *(that: Q):Q = this // TODO - - def /(that: Q):Q = this // TODO - - // Equivalence of two rationals - def ~(that: Q): Boolean = false // TODO - - def isRational = !(d == 0) - def nonZero = !(n == 0) - } - - def lemma1(a1: Q, a2: Q, b1: Q, b2: Q): Boolean = { - true // TODO - }.holds -} - diff --git a/testcases/web/sav15/08_Exercise8.scala b/testcases/web/sav15/08_Exercise8.scala deleted file mode 100644 index 1483670b6f5590daa43bc2cd1af9d3781155a823..0000000000000000000000000000000000000000 --- a/testcases/web/sav15/08_Exercise8.scala +++ /dev/null @@ -1,118 +0,0 @@ -/** - * In this exercise, you will have to implement a packed representation of a set of numbers. - * This representation uses a chained list of sorted ranges to represent the stored values. - * - * [0, 10] :: [15, 15] :: Empty - * - * stores - * - * Set(0,1,2,3,4,5,6,7,8,9,10,15) - * - * You need to implement + and - that adds and deletes single elements from the set. - * Leon will not generally be able to verify everything, but it should give you - * counter-examples in case you do something wrong. - */ - -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object PackedSet { - case class Range(min: BigInt, max: BigInt) { - def size: BigInt = { - if (max >= min) max-min+1 - else 0 - } - - def content: Set[BigInt] = { - if (max == min) Set(min) - else if (max > min) Set(min) ++ Range(min+1, max).content - else Set() - } - - def contains(v: BigInt): Boolean = { - min <= v && max >= v - } - - def <(that: Range) = { - this.min < that.min - } - - def merge(that: Range): Range = { - require(this.min == that.min) - Range(min, if (this.max > that.max) this.max else that.max) - } ensuring { - res => res.content == this.content ++ that.content - } - } - - - abstract class PackedSet { - def size: BigInt = { - this match { - case Empty => 0 - case NonEmpty(r, t) => r.size + t.size - } - } - - def depth: BigInt = { - this match { - case Empty => 0 - case NonEmpty(_, t) => 1 + t.depth - } - } - - def content: Set[BigInt] = { - this match { - case Empty => Set() - case NonEmpty(r, t) => r.content ++ t.content - } - } - - def contains(v: BigInt): Boolean = { - this match { - case Empty => false - case NonEmpty(r, t) => - if (r.min > v) false - else r.contains(v) || t.contains(v) - } - } - - def isPackedSet = isSorted && isPacked - - def isSorted: Boolean = { - this match { - case NonEmpty(r1, t @ NonEmpty(r2, _)) => r1 < r2 && t.isSorted - case _ => true - } - } - - def isPacked: Boolean = { - this match { - case Empty => true - case NonEmpty(r, t) => r.size >= 1 && t.isPacked - } - } - - def +(v: BigInt): PackedSet = { - require(this.isPackedSet) - this // TODO - } ensuring { - res => res.content == this.content ++ Set(v) && - res.isPackedSet - } - - def -(v: BigInt): PackedSet = { - require(this.isPackedSet) - this // TODO - } ensuring { - res => res.content == this.content -- Set(v) && - res.isPackedSet - } - - } - case class NonEmpty(r: Range, tail: PackedSet) extends PackedSet - case object Empty extends PackedSet - - -} diff --git a/testcases/web/synthesis/01_List_Insert.scala b/testcases/web/synthesis/01_List_Insert.scala deleted file mode 100644 index 40b7b0c74411d4912d45006f539d0defba125a17..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/01_List_Insert.scala +++ /dev/null @@ -1,25 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Insert { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def insert(in1: List, v: BigInt) = { - choose { (out : List) => - content(out) == content(in1) ++ Set(v) - } - } -} diff --git a/testcases/web/synthesis/02_List_Delete.scala b/testcases/web/synthesis/02_List_Delete.scala deleted file mode 100644 index 8230af747b9aba872e2281ff1c9cd630b962a7be..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/02_List_Delete.scala +++ /dev/null @@ -1,25 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Delete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def delete(in1: List, v: BigInt) = { - choose { (out : List) => - content(out) == content(in1) -- Set(v) - } - } -} diff --git a/testcases/web/synthesis/03_List_Union.scala b/testcases/web/synthesis/03_List_Union.scala deleted file mode 100644 index b03d4e5a24f18daabb07226d94801bbbd7920163..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/03_List_Union.scala +++ /dev/null @@ -1,25 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Union { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def union(in1: List, in2: List) = { - choose { (out : List) => - content(out) == content(in1) ++ content(in2) - } - } -} diff --git a/testcases/web/synthesis/04_List_Diff.scala b/testcases/web/synthesis/04_List_Diff.scala deleted file mode 100644 index 775d440833bf5b545dcb699d041554871a3de669..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/04_List_Diff.scala +++ /dev/null @@ -1,38 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Diff { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def delete(in1: List, v: BigInt): List = { - in1 match { - case Cons(h,t) => - if (h == v) { - delete(t, v) - } else { - Cons(h, delete(t, v)) - } - case Nil => - Nil - } - } ensuring { content(_) == content(in1) -- Set(v) } - - def diff(in1: List, in2: List) = { - choose { (out : List) => - content(out) == content(in1) -- content(in2) - } - } -} diff --git a/testcases/web/synthesis/05_List_Split1.scala b/testcases/web/synthesis/05_List_Split1.scala deleted file mode 100644 index 1838a6bb0471df20c25e3d2ad94d85ef80fa1362..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/05_List_Split1.scala +++ /dev/null @@ -1,30 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object List { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def abs(i: BigInt) : BigInt = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def split(list: List): (List, List) = { - choose { (res: (List, List)) => - (content(res._1) ++ content(res._2) == content(list)) - } - } - -} diff --git a/testcases/web/synthesis/06_List_Split2.scala b/testcases/web/synthesis/06_List_Split2.scala deleted file mode 100644 index 0b917467f8eeb2ec0ba6e3251813e18a56369058..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/06_List_Split2.scala +++ /dev/null @@ -1,31 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object List { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def abs(i: BigInt) : BigInt = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def split(list: List): (List, List) = { - choose { (res : (List, List)) => - (content(res._1) ++ content(res._2) == content(list)) && - (abs(size(res._1) - size(res._2)) <= 1) - } - } - -} diff --git a/testcases/web/synthesis/07_List_Split3.scala b/testcases/web/synthesis/07_List_Split3.scala deleted file mode 100644 index 8a7897ebbb25faea765cd4487ef33fe54d144fba..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/07_List_Split3.scala +++ /dev/null @@ -1,36 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object List { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def abs(i: BigInt): BigInt = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def tcons(h1: BigInt, h2: BigInt, tl: (List, List)) = { - (Cons(h1, tl._1), Cons(h2, tl._2)) - } - - def split(list : List): (List,List) = { - choose { (res: (List,List)) => - (content(res._1) ++ content(res._2) == content(list)) && - (abs(size(res._1) - size(res._2)) <= 1) && - (size(res._1) + size(res._2) == size(list)) - } - } - -} diff --git a/testcases/web/synthesis/09_SortedList_Insert1.scala b/testcases/web/synthesis/09_SortedList_Insert1.scala deleted file mode 100644 index 891c55cae60d9f07e3a949dfacb6e1264763dda4..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/09_SortedList_Insert1.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt) = { - require(isSorted(in1)) - choose { (out: List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } - -} diff --git a/testcases/web/synthesis/10_SortedList_Insert2.scala b/testcases/web/synthesis/10_SortedList_Insert2.scala deleted file mode 100644 index a199c7f28b8198c8b4644cf177919b4e6c16fd7d..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/10_SortedList_Insert2.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt) = { - require(isSorted(in1)) - choose { (out: List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) && size(out) == size(in1) + 1 - } - } - -} diff --git a/testcases/web/synthesis/11_SortedList_Delete.scala b/testcases/web/synthesis/11_SortedList_Delete.scala deleted file mode 100644 index 1438555d16120a19d43adb87b2320a6759d584be..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/11_SortedList_Delete.scala +++ /dev/null @@ -1,33 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in1: List, v: BigInt) = { - require(isSorted(in1)) - choose { (out: List) => - (content(out) == content(in1) -- Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/web/synthesis/12_SortedList_Diff.scala b/testcases/web/synthesis/12_SortedList_Diff.scala deleted file mode 100644 index 33d5dc69339048baa2b9e3c178a2c415ec86cb98..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/12_SortedList_Diff.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h,t) => - if (h < v) { - Cons(h, delete(t, v)) - } else if (h == v) { - delete(t, v) - } else { - in1 - } - case Nil => - Nil - } - } ensuring { res => content(res) == content(in1) -- Set(v) && isSorted(res) } - - def diff(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { (out: List) => - (content(out) == content(in1) -- content(in2)) && isSorted(out) - } - } - -} diff --git a/testcases/web/synthesis/13_SortedList_InsertSort.scala b/testcases/web/synthesis/13_SortedList_InsertSort.scala deleted file mode 100644 index 5f4076ac08c4942029549e41d6e56998b79e563e..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/13_SortedList_InsertSort.scala +++ /dev/null @@ -1,51 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def sort(list: List): List = { - choose { (res: List) => - isSorted(res) && - content(list) == content(res) - } - } - -} diff --git a/testcases/web/synthesis/14_SortedList_Union.scala b/testcases/web/synthesis/14_SortedList_Union.scala deleted file mode 100644 index a5c4de9c6501de2549cd25257aa0e81294d38342..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/14_SortedList_Union.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { (out: List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } -} diff --git a/testcases/web/synthesis/15_StrictSortedList_Insert.scala b/testcases/web/synthesis/15_StrictSortedList_Insert.scala deleted file mode 100644 index 378ae688eee95f8f17bab2cd56e81d68107e6fc7..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/15_StrictSortedList_Insert.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt) = { - require(isSorted(in1)) - choose { (out : List) => - (content(out) == content(in1) ++ Set(v)) && isSorted(out) - } - } - -} diff --git a/testcases/web/synthesis/16_StrictSortedList_Delete.scala b/testcases/web/synthesis/16_StrictSortedList_Delete.scala deleted file mode 100644 index 6a79ccc11b28cf5ebbc8dfcecb519a896f8d37d4..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/16_StrictSortedList_Delete.scala +++ /dev/null @@ -1,33 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Delete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def delete(in1: List, v: BigInt) = { - require(isSorted(in1)) - choose { (out : List) => - (content(out) == content(in1) -- Set(v)) && isSorted(out) - } - } -} diff --git a/testcases/web/synthesis/17_StrictSortedList_Union.scala b/testcases/web/synthesis/17_StrictSortedList_Union.scala deleted file mode 100644 index c4e7d45e0e55eb41a5bc8bb07cc17e2cf959b86a..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/17_StrictSortedList_Union.scala +++ /dev/null @@ -1,50 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Complete { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def content(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(i, t) => Set(i) ++ content(t) - } - - def isSorted(list : List) : Boolean = list match { - case Nil => true - case Cons(_, Nil) => true - case Cons(x1, Cons(x2, _)) if(x1 >= x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def insert(in1: List, v: BigInt): List = { - require(isSorted(in1)) - in1 match { - case Cons(h, t) => - if (v < h) { - Cons(v, in1) - } else if (v == h) { - in1 - } else { - Cons(h, insert(t, v)) - } - case Nil => - Cons(v, Nil) - } - - } ensuring { res => (content(res) == content(in1) ++ Set(v)) && isSorted(res) } - - def union(in1: List, in2: List) = { - require(isSorted(in1) && isSorted(in2)) - choose { (out : List) => - (content(out) == content(in1) ++ content(in2)) && isSorted(out) - } - } -} diff --git a/testcases/web/synthesis/18_UnaryNumerals_Add.scala b/testcases/web/synthesis/18_UnaryNumerals_Add.scala deleted file mode 100644 index 7bf58114b5c9f4cdeb008f1220af9ab6a7139dac..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/18_UnaryNumerals_Add.scala +++ /dev/null @@ -1,22 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Numerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = { - choose { (r: Num) => - value(r) == value(x) + value(y) - } - } -} diff --git a/testcases/web/synthesis/19_UnaryNumerals_Distinct.scala b/testcases/web/synthesis/19_UnaryNumerals_Distinct.scala deleted file mode 100644 index d41ef8a03d03782707e993d82e18e11c87f82405..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/19_UnaryNumerals_Distinct.scala +++ /dev/null @@ -1,27 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Numerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = (x match { - case Z => y - case S(p) => add(p, S(y)) - }) ensuring (value(_) == value(x) + value(y)) - - def distinct(x: Num, y: Num): Num = { - choose { (r : Num) => - r != x && r != y - } - } -} diff --git a/testcases/web/synthesis/20_UnaryNumerals_Mult.scala b/testcases/web/synthesis/20_UnaryNumerals_Mult.scala deleted file mode 100644 index 800812e5714e468bdc0bf320dd6491c0e9e4304c..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/20_UnaryNumerals_Mult.scala +++ /dev/null @@ -1,27 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Numerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n: Num): BigInt = { - n match { - case Z => BigInt(0) - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = (x match { - case Z => y - case S(p) => add(p, S(y)) - }) ensuring (value(_) == value(x) + value(y)) - - def mult(x: Num, y: Num): Num = { - choose { (r: Num) => - value(r) == value(x) * value(y) - } - } -} diff --git a/testcases/web/synthesis/21_UnaryNumerals_Squared.scala b/testcases/web/synthesis/21_UnaryNumerals_Squared.scala deleted file mode 100644 index 9dd48fbc1e6d60b0bfe70e8d70fe3fdc6d8f36f7..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/21_UnaryNumerals_Squared.scala +++ /dev/null @@ -1,34 +0,0 @@ -import leon.lang._ -import leon.lang.synthesis._ -import leon.annotation._ - -object Numerals { - sealed abstract class Num - case object Z extends Num - case class S(pred: Num) extends Num - - def value(n:Num) : BigInt = { - n match { - case Z => BigInt(0) - case S(p) => 1 + value(p) - } - } ensuring (_ >= 0) - - def add(x: Num, y: Num): Num = (x match { - case Z => y - case S(p) => add(p, S(y)) - }) ensuring (value(_) == value(x) + value(y)) - - def mult(x: Num, y: Num): Num = (y match { - case S(p) => - add(mult(x, p), x) - case Z => - Z - }) ensuring { value(_) == value(x) * value(y) } - - def squared(x: Num): Num = { - choose { (r: Num) => - value(r) == value(x) * value(x) - } - } -} diff --git a/testcases/web/synthesis/22_String_List.scala b/testcases/web/synthesis/22_String_List.scala deleted file mode 100644 index 089d57484e3b881a01852e2ae6fae156c27fdd93..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/22_String_List.scala +++ /dev/null @@ -1,19 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object ListsToString { - - def allListsAreEmpty(t: List[Int]): Boolean = (t.isEmpty || t.tail.isEmpty || t.tail.tail.isEmpty || t.tail.head == 0) holds - - def listToString(p : List[Int]): String = { - ??? - } ensuring { - (res : String) => (p, res) passes { - case Cons(1, Cons(2, Nil())) => - "[1, 2]" - } - } -} diff --git a/testcases/web/synthesis/23_String_Grammar.scala b/testcases/web/synthesis/23_String_Grammar.scala deleted file mode 100644 index 1c97e4b502d608ad579d1d38da7bdedca4475f2b..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/23_String_Grammar.scala +++ /dev/null @@ -1,19 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object GrammarRender { - abstract class Symbol - case class Terminal(i: Int) extends Symbol - case class NonTerminal(i: Int) extends Symbol - - case class Rule(left: Symbol, right: List[Symbol]) - case class Grammar(start: Symbol, rules: List[Rule]) - - ////////////////////////////////////////////// - // Non-incremental examples: pure synthesis // - ////////////////////////////////////////////// - def grammarToString(s : Grammar): String = ???[String] ask s -} \ No newline at end of file diff --git a/testcases/web/synthesis/24_String_DoubleList.scala b/testcases/web/synthesis/24_String_DoubleList.scala deleted file mode 100644 index 021a11bcef87e883ea01424ed2024ca44bd255cd..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/24_String_DoubleList.scala +++ /dev/null @@ -1,60 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object DoubleListRender { - abstract class A - case class B(i: AA, a: A) extends A - case class N() extends A - - abstract class AA - case class BB(i: A, a: AA) extends AA - case class NN() extends AA - - // Two elements which do not contain each other but are in the same A should be the same. - // Obviously wrong, but for the sake of displaying counter-examples. - def lemma1(a: A, b: A, c: A): Boolean = { - require(containsA_A(a, b) && containsA_A(a, c) && !containsA_A(b, c) && !containsA_A(c, b)) - b == c - } holds - - def AtoString(a : A): String = { - ???[String] ask a - } - - def AAtoString(a : AA): String = { - ???[String] ask a - } - - def structurallyEqualA(a: A, b: A): Boolean = (a, b) match { - case (N(), N()) => true - case (B(i, k), B(j, l)) => structurallyEqualA(k, l) && structurallyEqualAA(i, j) - } - - def structurallyEqualAA(a: AA, b: AA): Boolean = (a, b) match { - case (NN(), NN()) => true - case (BB(i, k), BB(j, l)) => structurallyEqualAA(k, l) && structurallyEqualA(i, j) - } - - def containsA_A(a: A, b: A): Boolean = (a match { - case N() => false - case B(i, k) => containsAA_A(i, b) || containsA_A(k, b) - }) - - def containsAA_A(a: AA, b: A): Boolean = (a match { - case NN() => false - case BB(i, k) => i == b || containsA_A(i, b) || containsAA_A(k, b) - }) - - def containsA_AA(a: A, b: AA): Boolean = (a match { - case N() => false - case B(i, k) => i == b || containsAA_AA(i, b) || containsA_AA(k, b) - }) - - def containsAA_AA(a: AA, b: AA): Boolean = (a match { - case NN() => false - case BB(i, k) => containsA_AA(i, b) || containsAA_AA(k, b) - }) -} \ No newline at end of file diff --git a/testcases/web/synthesis/25_String_Matrix.scala b/testcases/web/synthesis/25_String_Matrix.scala deleted file mode 100644 index 06bf203530c6a2757913d596a3ac18244cdea4e1..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/25_String_Matrix.scala +++ /dev/null @@ -1,66 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import synthesis._ -import leon.collection._ - -object Matrix { - case class CList[T](head: T, tail: Option[CList[T]]) { - def +:(el: T) = CList(el, Some(this)) - } - - // Built-in function for printing non-empty lists CList - def clistMkString[T](in: CList[T], infix: String, f: T => String): String = { - in match { - case CList(head, Some(tail)) => f(head) + infix + clistMkString(tail, infix, f) - case CList(head, None()) => f(head) - } - } - - /** Shows how to use custom pretty printers to pretty print a custom list of a list. */ - def CListStringToString(in: CList[CList[String]]): String = { - ???[String] - } ensuring { - (res: String) => (in, res) passes { - case CList(CList(a, Some(CList(b, None()))), Some(CList(CList(c, Some(CList(d, None()))), None()))) => - a + "," + b + "\n" + c + "," + d - } - } - - - /** Shows how to use built-in function to pretty print a list of a list as a 2D matrix. */ - def matrixToString(in : List[List[Int]]): String = { - ???[String] - } ensuring { - (res : String) => (in, res) passes { - case x if x == List( - List(2, 3), - List(4, 5) - ) => -"""<table border="1"><tr><td>2</td><td>3</td></tr> -<tr><td>4</td><td>5</td></tr></table>""" - } - } - - def isMatrix(in: List[List[Int]], width: BigInt, height: BigInt): Boolean = { - in match { - case Nil() if height == 0 => true - case Cons(row, remaining) => row.length == width && isMatrix(remaining, width, height - 1) - case _ => false - } - } - - - def wrongMatrixConjecture(in: List[List[Int]]) = { - require(isMatrix(in, 3, 3)) - in(0)(0) == in(0)(1) || - in(0)(1) == in(0)(2) || - in(0)(2) == in(0)(0) || - in(1)(0) == in(1)(1) || - in(1)(1) == in(1)(2) || - in(1)(2) == in(1)(0) || - in(2)(0) == in(2)(1) || - in(2)(1) == in(2)(2) || - in(2)(2) == in(2)(0) - } holds - -} diff --git a/testcases/web/synthesis/26_String_Modular_Render.scala b/testcases/web/synthesis/26_String_Modular_Render.scala deleted file mode 100644 index d180d7e4c8ac4b217136b023afe9bd9c0d833005..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/26_String_Modular_Render.scala +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Name: ModularRender.scala - * Creation: 26.01.2015 - * Author: Mikael Mayer (mikael.mayer@epfl.ch) - * Comments: Modular rendering, in one order or the other. - */ -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object ModularRender { - - def booleanToString(b: Boolean) = if(b) "Up" else "Down" - - def intToString(b: BigInt) = b.toString - - def customToString[T](l : List[T], f : (T) => String): String = - ???[String] ask l - - case class Configuration(flags: List[Boolean], strokes: List[BigInt]) - - // We want to write - // Solution: - // [Up, Down, Up....] - // [1, 2, 5, ...] - def ConfigToString(config : Configuration): String = - ???[String] ask config - - /** Wrong lemma for demonstration */ - def configurationsAreSimple(c: Configuration) = - (c.flags.size < 3 || c.strokes.size < 2 || c.flags(0) == c.flags(1) || c.strokes(0) == c.strokes(1)) holds -} diff --git a/testcases/web/synthesis/27_String_Json.scala b/testcases/web/synthesis/27_String_Json.scala deleted file mode 100644 index 05d0b7c9ef58e9afbc9c4dd1717315e84c445bcc..0000000000000000000000000000000000000000 --- a/testcases/web/synthesis/27_String_Json.scala +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Name: JsonRender.scala - * Creation: 25.11.2015 - * Author: Mikael Mayer (mikael.mayer@epfl.ch) - * Comments: Json specifications - */ - -import leon.lang._ -import leon.annotation._ -import leon.collection._ -import leon.collection.ListOps._ -import leon.lang.synthesis._ - -object JsonRender { - abstract class JSON - abstract class JCompositeValue extends JSON - abstract class JFinalValue extends JSON - case class JDict(values: Map[String, JSON]) extends JCompositeValue - case class JArray(values: List[JSON]) extends JCompositeValue - case class JString(value: String) extends JFinalValue - case class JBoolean(value: Boolean) extends JFinalValue - case class JInt(value: Int) extends JFinalValue - - def JStringToString(j: JString) = "\"" + StrOps.escape(j.value) + "\"" - - def test = json_render(JDict(Map("title" -> JString("\"test\""), "flags" -> JArray(List(JInt(1), JBoolean(true)))))) - - /** Synthesize this function by example to have a JSON serializer. */ - def json_render(j: JSON): String = ???[String] -} \ No newline at end of file diff --git a/testcases/web/verification/01_Amortized_Queue.scala b/testcases/web/verification/01_Amortized_Queue.scala deleted file mode 100644 index e67f9c4c937ae70b1ea2b1a97f129eda49d0a167..0000000000000000000000000000000000000000 --- a/testcases/web/verification/01_Amortized_Queue.scala +++ /dev/null @@ -1,102 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object AmortizedQueue { - sealed abstract class List - case class Cons(head : BigInt, tail : List) extends List - case object Nil extends List - - sealed abstract class AbsQueue - case class Queue(front : List, rear : List) extends AbsQueue - - def size(list : List) : BigInt = (list match { - case Nil => BigInt(0) - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def content(l: List) : Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def asList(queue : AbsQueue) : List = queue match { - case Queue(front, rear) => concat(front, reverse(rear)) - } - - def concat(l1 : List, l2 : List) : List = (l1 match { - case Nil => l2 - case Cons(x,xs) => Cons(x, concat(xs, l2)) - }) ensuring (res => size(res) == size(l1) + size(l2) && content(res) == content(l1) ++ content(l2)) - - def isAmortized(queue : AbsQueue) : Boolean = queue match { - case Queue(front, rear) => size(front) >= size(rear) - } - - def isEmpty(queue : AbsQueue) : Boolean = queue match { - case Queue(Nil, Nil) => true - case _ => false - } - - def reverse(l : List) : List = (l match { - case Nil => Nil - case Cons(x, xs) => concat(reverse(xs), Cons(x, Nil)) - }) ensuring (content(_) == content(l)) - - def amortizedQueue(front : List, rear : List) : AbsQueue = { - if (size(rear) <= size(front)) - Queue(front, rear) - else - Queue(concat(front, reverse(rear)), Nil) - } ensuring(isAmortized(_)) - - def enqueue(queue : AbsQueue, elem : BigInt) : AbsQueue = (queue match { - case Queue(front, rear) => amortizedQueue(front, Cons(elem, rear)) - }) ensuring(isAmortized(_)) - - def tail(queue : AbsQueue) : AbsQueue = { - require(isAmortized(queue) && !isEmpty(queue)) - queue match { - case Queue(Cons(f, fs), rear) => amortizedQueue(fs, rear) - } - } ensuring (isAmortized(_)) - - def front(queue : AbsQueue) : BigInt = { - require(isAmortized(queue) && !isEmpty(queue)) - queue match { - case Queue(Cons(f, _), _) => f - } - } - - @induct - def propFront(queue : AbsQueue, list : List, elem : BigInt) : Boolean = { - require(!isEmpty(queue) && isAmortized(queue)) - if (asList(queue) == list) { - list match { - case Cons(x, _) => front(queue) == x - } - } else - true - } holds - - def enqueueAndFront(queue : AbsQueue, elem : BigInt) : Boolean = { - if (isEmpty(queue)) - front(enqueue(queue, elem)) == elem - else - true - } holds - - def enqueueDequeueThrice(queue : AbsQueue, e1 : BigInt, e2 : BigInt, e3 : BigInt) : Boolean = { - if (isEmpty(queue)) { - val q1 = enqueue(queue, e1) - val q2 = enqueue(q1, e2) - val q3 = enqueue(q2, e3) - val e1prime = front(q3) - val q4 = tail(q3) - val e2prime = front(q4) - val q5 = tail(q4) - val e3prime = front(q5) - e1 == e1prime && e2 == e2prime && e3 == e3prime - } else - true - } holds -} diff --git a/testcases/web/verification/02_Associative_List.scala b/testcases/web/verification/02_Associative_List.scala deleted file mode 100644 index 7dea8f3edb778457621606bb13907d6d5ac24977..0000000000000000000000000000000000000000 --- a/testcases/web/verification/02_Associative_List.scala +++ /dev/null @@ -1,49 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object AssociativeList { - sealed abstract class KeyValuePairAbs - case class KeyValuePair(key: BigInt, value: BigInt) extends KeyValuePairAbs - - sealed abstract class List - case class Cons(head: KeyValuePairAbs, tail: List) extends List - case object Nil extends List - - sealed abstract class OptionInt - case class Some(i: BigInt) extends OptionInt - case object None extends OptionInt - - def domain(l: List): Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(KeyValuePair(k,_), xs) => Set(k) ++ domain(xs) - } - - def find(l: List, e: BigInt): OptionInt = l match { - case Nil => None - case Cons(KeyValuePair(k, v), xs) => if (k == e) Some(v) else find(xs, e) - } - - def noDuplicates(l: List): Boolean = l match { - case Nil => true - case Cons(KeyValuePair(k, v), xs) => find(xs, k) == None && noDuplicates(xs) - } - - def updateList(l1: List, l2: List): List = (l2 match { - case Nil => l1 - case Cons(x, xs) => updateList(updateElem(l1, x), xs) - }) ensuring(domain(_) == domain(l1) ++ domain(l2)) - - def updateElem(l: List, e: KeyValuePairAbs): List = (l match { - case Nil => Cons(e, Nil) - case Cons(KeyValuePair(k, v), xs) => e match { - case KeyValuePair(ek, ev) => if (ek == k) Cons(KeyValuePair(ek, ev), xs) else Cons(KeyValuePair(k, v), updateElem(xs, e)) - } - }) ensuring(res => e match { - case KeyValuePair(k, v) => domain(res) == domain(l) ++ Set[BigInt](k) - }) - - @induct - def readOverWrite(l: List, k1: BigInt, k2: BigInt, e: BigInt) : Boolean = { - find(updateElem(l, KeyValuePair(k2,e)), k1) == (if (k1 == k2) Some(e) else find(l, k1)) - } holds -} diff --git a/testcases/web/verification/03_Insertion_Sort.scala b/testcases/web/verification/03_Insertion_Sort.scala deleted file mode 100644 index 4b1c8ef7cd0b61ab0c2f91533598be792dd1b809..0000000000000000000000000000000000000000 --- a/testcases/web/verification/03_Insertion_Sort.scala +++ /dev/null @@ -1,79 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object InsertionSort { - sealed abstract class List - case class Cons(head:BigInt,tail:List) extends List - case object Nil extends List - - sealed abstract class OptInt - case class Some(value: BigInt) extends OptInt - case object None extends OptInt - - def size(l : List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contents(l: List): Set[BigInt] = l match { - case Nil => Set.empty - case Cons(x,xs) => contents(xs) ++ Set(x) - } - - 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)) - } - - /* Inserting element 'e' into a sorted list 'l' produces a sorted list with - * the expected content and size */ - def sortedIns(e: BigInt, l: List): List = { - require(isSorted(l)) - l match { - case Nil => Cons(e,Nil) - case Cons(x,xs) => if (x <= e) Cons(x,sortedIns(e, xs)) else Cons(e, l) - } - } ensuring(res => contents(res) == contents(l) ++ Set(e) - && isSorted(res) - && size(res) == size(l) + 1 - ) - - /* A counterexample is found when we forget to specify the precondition */ - def buggySortedIns(e: BigInt, l: List): List = { - l match { - case Nil => Cons(e,Nil) - case Cons(x,xs) => if (x <= e) Cons(x,buggySortedIns(e, xs)) else Cons(e, l) - } - } ensuring(res => contents(res) == contents(l) ++ Set(e) - && isSorted(res) - && size(res) == size(l) + 1 - ) - - /* Insertion sort yields a sorted list of same size and content as the input - * list */ - def sort(l: List): List = (l match { - case Nil => Nil - case Cons(x,xs) => sortedIns(x, sort(xs)) - }) ensuring(res => contents(res) == contents(l) - && isSorted(res) - && size(res) == size(l) - ) - - /* Merges one (unsorted) list into another, sorted, list. */ - def mergeInto(l1 : List, l2 : List) : List = { - require(isSorted(l2)) - l1 match { - case Nil => l2 - case Cons(x, xs) => mergeInto(xs, sortedIns(x, l2)) - } - } ensuring(res => contents(res) == contents(l1) ++ contents(l2) && isSorted(res)) - - @ignore - def main(args: Array[String]): Unit = { - val ls: List = Cons(5, Cons(2, Cons(4, Cons(5, Cons(1, Cons(8,Nil)))))) - - println(ls) - println(sort(ls)) - } -} diff --git a/testcases/web/verification/04_List_Operations.scala b/testcases/web/verification/04_List_Operations.scala deleted file mode 100644 index 982b0cefb73805929e2e4a81f9a7e9e328e989ca..0000000000000000000000000000000000000000 --- a/testcases/web/verification/04_List_Operations.scala +++ /dev/null @@ -1,106 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object ListOperations { - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case object Nil extends List - - sealed abstract class IntPairList - case class IPCons(head: IntPair, tail: IntPairList) extends IntPairList - case object IPNil extends IntPairList - - sealed abstract class IntPair - case class IP(fst: BigInt, snd: BigInt) extends IntPair - - def size(l: List) : BigInt = (l match { - case Nil => BigInt(0) - case Cons(_, t) => 1 + size(t) - }) ensuring(res => res >= 0) - - def iplSize(l: IntPairList) : BigInt = (l match { - case IPNil => BigInt(0) - case IPCons(_, xs) => 1 + iplSize(xs) - }) ensuring(_ >= 0) - - def zip(l1: List, l2: List) : IntPairList = { - // try to comment this and see how pattern-matching becomes - // non-exhaustive and post-condition fails - require(size(l1) == size(l2)) - - l1 match { - case Nil => IPNil - case Cons(x, xs) => l2 match { - case Cons(y, ys) => IPCons(IP(x, y), zip(xs, ys)) - } - } - } ensuring(iplSize(_) == size(l1)) - - def sizeTailRec(l: List) : BigInt = sizeTailRecAcc(l, 0) - def sizeTailRecAcc(l: List, acc: BigInt) : BigInt = { - require(acc >= 0) - l match { - case Nil => acc - case Cons(_, xs) => sizeTailRecAcc(xs, acc+1) - } - } ensuring(res => res == size(l) + acc) - - def sizesAreEquiv(l: List) : Boolean = { - size(l) == sizeTailRec(l) - } holds - - def content(l: List) : Set[BigInt] = l match { - case Nil => Set.empty[BigInt] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def sizeAndContent(l: List) : Boolean = { - size(l) == 0 || content(l) != Set.empty[BigInt] - } holds - - def drunk(l : List) : List = (l match { - case Nil => Nil - case Cons(x,l1) => Cons(x,Cons(x,drunk(l1))) - }) ensuring (size(_) == 2 * size(l)) - - def reverse(l: List) : List = reverse0(l, Nil) ensuring(content(_) == content(l)) - def reverse0(l1: List, l2: List) : List = (l1 match { - case Nil => l2 - case Cons(x, xs) => reverse0(xs, Cons(x, l2)) - }) ensuring(content(_) == content(l1) ++ content(l2)) - - def append(l1 : List, l2 : List) : List = (l1 match { - case Nil => l2 - case Cons(x,xs) => Cons(x, append(xs, l2)) - }) ensuring(content(_) == content(l1) ++ content(l2)) - - @induct - def nilAppend(l : List) : Boolean = (append(l, Nil) == l) holds - - @induct - def appendAssoc(xs : List, ys : List, zs : List) : Boolean = - (append(append(xs, ys), zs) == append(xs, append(ys, zs))) holds - - def revAuxBroken(l1 : List, e : BigInt, l2 : List) : Boolean = { - (append(reverse(l1), Cons(e,l2)) == reverse0(l1, l2)) - } holds - - @induct - def sizeAppend(l1 : List, l2 : List) : Boolean = - (size(append(l1, l2)) == size(l1) + size(l2)) holds - - @induct - def concat(l1: List, l2: List) : List = - concat0(l1, l2, Nil) ensuring(content(_) == content(l1) ++ content(l2)) - - @induct - def concat0(l1: List, l2: List, l3: List) : List = (l1 match { - case Nil => l2 match { - case Nil => reverse(l3) - case Cons(y, ys) => { - concat0(Nil, ys, Cons(y, l3)) - } - } - case Cons(x, xs) => concat0(xs, l2, Cons(x, l3)) - }) ensuring(content(_) == content(l1) ++ content(l2) ++ content(l3)) -} diff --git a/testcases/web/verification/05_Propositional_Logic.scala b/testcases/web/verification/05_Propositional_Logic.scala deleted file mode 100644 index 9f8a7c94a5d4a7bb61d6c4c3f26cd7de055ffd5f..0000000000000000000000000000000000000000 --- a/testcases/web/verification/05_Propositional_Logic.scala +++ /dev/null @@ -1,178 +0,0 @@ -import leon.lang._ -import leon.annotation._ -import leon.proof._ - -object PropositionalLogic { - - sealed abstract class Formula - case class And(lhs: Formula, rhs: Formula) extends Formula - case class Or(lhs: Formula, rhs: Formula) extends Formula - case class Implies(lhs: Formula, rhs: Formula) extends Formula - case class Not(f: Formula) extends Formula - case class Literal(id: BigInt) extends Formula - - def simplify(f: Formula): Formula = (f match { - case And(lhs, rhs) => And(simplify(lhs), simplify(rhs)) - case Or(lhs, rhs) => Or(simplify(lhs), simplify(rhs)) - case Implies(lhs, rhs) => Or(Not(simplify(lhs)), simplify(rhs)) - case Not(f) => Not(simplify(f)) - case Literal(_) => f - }) ensuring(isSimplified(_)) - - def isSimplified(f: Formula): Boolean = f match { - case And(lhs, rhs) => isSimplified(lhs) && isSimplified(rhs) - case Or(lhs, rhs) => isSimplified(lhs) && isSimplified(rhs) - case Implies(_,_) => false - case Not(f) => isSimplified(f) - case Literal(_) => true - } - - def nnf(formula: Formula): Formula = (formula match { - case And(lhs, rhs) => And(nnf(lhs), nnf(rhs)) - case Or(lhs, rhs) => Or(nnf(lhs), nnf(rhs)) - case Implies(lhs, rhs) => nnf(Or(Not(lhs), rhs)) - case Not(And(lhs, rhs)) => Or(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Or(lhs, rhs)) => And(nnf(Not(lhs)), nnf(Not(rhs))) - case Not(Implies(lhs, rhs)) => And(nnf(lhs), nnf(Not(rhs))) - case Not(Not(f)) => nnf(f) - case Not(Literal(_)) => formula - case Literal(_) => formula - }) ensuring(isNNF(_)) - - def isNNF(f: Formula): Boolean = f match { - case And(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Or(lhs, rhs) => isNNF(lhs) && isNNF(rhs) - case Implies(lhs, rhs) => false - case Not(Literal(_)) => true - case Not(_) => false - case Literal(_) => true - } - - def evalLit(id : BigInt) : Boolean = (id == 42) // could be any function - def eval(f: Formula) : Boolean = f match { - case And(lhs, rhs) => eval(lhs) && eval(rhs) - case Or(lhs, rhs) => eval(lhs) || eval(rhs) - case Implies(lhs, rhs) => !eval(lhs) || eval(rhs) - case Not(f) => !eval(f) - case Literal(id) => evalLit(id) - } - - @induct - def simplifySemantics(f: Formula) : Boolean = { - eval(f) == eval(simplify(f)) - } holds - - // Note that matching is exhaustive due to precondition. - def vars(f: Formula): Set[BigInt] = { - require(isNNF(f)) - f match { - case And(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Or(lhs, rhs) => vars(lhs) ++ vars(rhs) - case Not(Literal(i)) => Set[BigInt](i) - case Literal(i) => Set[BigInt](i) - } - } - - def fv(f : Formula) = { vars(nnf(f)) } - - @induct - def simplifyPreservesNNF(f: Formula) : Boolean = { - require(isNNF(f)) - isNNF(simplify(f)) - } holds - - @induct - def nnfIsStable(f: Formula) : Boolean = { - require(isNNF(f)) - nnf(f) == f - } holds - - @induct - def simplifyIsStable(f: Formula) : Boolean = { - require(isSimplified(f)) - simplify(f) == f - } holds - - def and(lhs: Formula, rhs: Formula): Formula = And(lhs, rhs) - def or(lhs: Formula, rhs: Formula): Formula = Or(lhs, rhs) - - def simplifyPreserveNNFNot(f: Formula): Boolean = { - (nnf(Not(simplify(f))) == nnf(Not(f))) because { - f match { - case And(lhs, rhs) => { - nnf(Not(simplify(f))) ==| trivial | - nnf(Not(And(simplify(lhs), simplify(rhs)))) ==| trivial | - or(nnf(Not(simplify(lhs))), nnf(Not(simplify(rhs)))) ==| simplifyPreserveNNFNot(lhs) | - or(nnf(Not(lhs)), nnf(Not(simplify(rhs)))) ==| simplifyPreserveNNFNot(rhs) | - or(nnf(Not(lhs)), nnf(Not(rhs))) ==| trivial | - nnf(Not(And(lhs, rhs))) ==| trivial | - nnf(Not(f)) - } qed - case Or(lhs, rhs) => { - nnf(Not(simplify(f))) ==| trivial | - nnf(Not(Or(simplify(lhs), simplify(rhs)))) ==| trivial | - and(nnf(Not(simplify(lhs))), nnf(Not(simplify(rhs)))) ==| simplifyPreserveNNFNot(lhs) | - and(nnf(Not(lhs)), nnf(Not(simplify(rhs)))) ==| simplifyPreserveNNFNot(rhs) | - and(nnf(Not(lhs)), nnf(Not(rhs))) ==| trivial | - nnf(Not(Or(lhs, rhs))) ==| trivial | - nnf(Not(f)) - } qed - case Implies(lhs, rhs) => { - nnf(Not(simplify(f))) ==| trivial | - nnf(Not(Or(Not(simplify(lhs)), simplify(rhs)))) ==| trivial | - and(nnf(Not(Not(simplify(lhs)))), nnf(Not(simplify(rhs)))) ==| trivial | - and(nnf(simplify(lhs)), nnf(Not(simplify(rhs)))) ==| simplifyPreserveNNFNot(rhs) | - and(nnf(simplify(lhs)), nnf(Not(rhs))) ==| simplifyPreserveNNF(lhs) | - and(nnf(lhs), nnf(Not(rhs))) ==| trivial | - nnf(Not(Implies(lhs, rhs))) - } qed - case Not(g) => { - nnf(Not(simplify(f))) ==| trivial | - nnf(Not(Not(simplify(g)))) ==| trivial | - nnf(simplify(g)) ==| simplifyPreserveNNF(g) | - nnf(g) ==| trivial | - nnf(Not(Not(g))) ==| trivial | - nnf(Not(f)) - } qed - case Literal(_) => trivial - } - } - } holds - - def simplifyPreserveNNF(f: Formula): Boolean = { - (nnf(simplify(f)) == nnf(f)) because { - f match { - case And(lhs, rhs) => { - nnf(simplify(f)) ==| trivial | - and(nnf(simplify(lhs)), nnf(simplify(rhs))) ==| simplifyPreserveNNF(lhs) | - and(nnf(lhs), nnf(simplify(rhs))) ==| simplifyPreserveNNF(rhs) | - and(nnf(lhs), nnf(rhs)) ==| trivial | - nnf(f) - } qed - case Or(lhs, rhs) => { - nnf(simplify(f)) ==| trivial | - or(nnf(simplify(lhs)), nnf(simplify(rhs))) ==| simplifyPreserveNNF(lhs) | - or(nnf(lhs), nnf(simplify(rhs))) ==| simplifyPreserveNNF(rhs) | - or(nnf(lhs), nnf(rhs)) ==| trivial | - nnf(f) - } qed - case Implies(lhs, rhs) => { - nnf(simplify(f)) ==| trivial | - nnf(or(Not(simplify(lhs)), simplify(rhs))) ==| trivial | - or(nnf(Not(simplify(lhs))), nnf(simplify(rhs))) ==| simplifyPreserveNNF(rhs) | - or(nnf(Not(simplify(lhs))), nnf(rhs)) ==| trivial | - or(nnf(simplify(Not(lhs))), nnf(rhs)) ==| simplifyPreserveNNF(Not(lhs)) | - or(nnf(Not(lhs)), nnf(rhs)) ==| trivial | - nnf(f) - } qed - case Not(g) => { - nnf(simplify(f)) ==| trivial | - nnf(Not(simplify(g))) ==| simplifyPreserveNNFNot(g) | - nnf(Not(g)) ==| trivial | - nnf(f) - } qed - case Literal(_) => trivial - } - } - } holds -} diff --git a/testcases/web/verification/06_Red-Black_Tree.scala b/testcases/web/verification/06_Red-Black_Tree.scala deleted file mode 100644 index 9a9553146ef799a91649363c8dbda140f772379d..0000000000000000000000000000000000000000 --- a/testcases/web/verification/06_Red-Black_Tree.scala +++ /dev/null @@ -1,115 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object RedBlackTree { - sealed abstract class Color - case object Red extends Color - case object Black extends Color - - sealed abstract class Tree - case object Empty extends Tree - case class Node(color: Color, left: Tree, value: BigInt, right: Tree) extends Tree - - sealed abstract class OptionInt - case class Some(v : BigInt) extends OptionInt - case object None extends OptionInt - - def content(t: Tree) : Set[BigInt] = t match { - case Empty => Set.empty - case Node(_, l, v, r) => content(l) ++ Set(v) ++ content(r) - } - - def size(t: Tree) : BigInt = t match { - case Empty => BigInt(0) - case Node(_, l, v, r) => size(l) + 1 + size(r) - } - - /* We consider leaves to be black by definition */ - def isBlack(t: Tree) : Boolean = t match { - case Empty => true - case Node(Black,_,_,_) => true - case _ => false - } - - def redNodesHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(Black, l, _, r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - case Node(Red, l, _, r) => isBlack(l) && isBlack(r) && redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def redDescHaveBlackChildren(t: Tree) : Boolean = t match { - case Empty => true - case Node(_,l,_,r) => redNodesHaveBlackChildren(l) && redNodesHaveBlackChildren(r) - } - - def blackBalanced(t : Tree) : Boolean = t match { - case Node(_,l,_,r) => blackBalanced(l) && blackBalanced(r) && blackHeight(l) == blackHeight(r) - case Empty => true - } - - def blackHeight(t : Tree) : BigInt = t match { - case Empty => 1 - case Node(Black, l, _, _) => blackHeight(l) + 1 - case Node(Red, l, _, _) => blackHeight(l) - } - - // <<insert element x into the tree t>> - def ins(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - t match { - case Empty => Node(Red,Empty,x,Empty) - case Node(c,a,y,b) => - if (x < y) balance(c, ins(x, a), y, b) - else if (x == y) Node(c,a,y,b) - else balance(c,a,y,ins(x, b)) - } - } ensuring (res => content(res) == content(t) ++ Set(x) - && size(t) <= size(res) && size(res) <= size(t) + 1 - && redDescHaveBlackChildren(res) - && blackBalanced(res)) - - def makeBlack(n: Tree): Tree = { - require(redDescHaveBlackChildren(n) && blackBalanced(n)) - n match { - case Node(Red,l,v,r) => Node(Black,l,v,r) - case _ => n - } - } ensuring(res => redNodesHaveBlackChildren(res) && blackBalanced(res)) - - def add(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t) && blackBalanced(t)) - makeBlack(ins(x, t)) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res) && blackBalanced(res)) - - def buggyAdd(x: BigInt, t: Tree): Tree = { - require(redNodesHaveBlackChildren(t)) - ins(x, t) - } ensuring (res => content(res) == content(t) ++ Set(x) && redNodesHaveBlackChildren(res)) - - def balance(c: Color, a: Tree, x: BigInt, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black,Node(Red,Node(Red,a,xV,b),yV,c),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,Node(Red,a,xV,Node(Red,b,yV,c)),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,Node(Red,b,yV,c),zV,d)) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,b,yV,Node(Red,c,zV,d))) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(c,a,xV,b) => Node(c,a,xV,b) - } - } ensuring (res => content(res) == content(Node(c,a,x,b))) - - def buggyBalance(c: Color, a: Tree, x: BigInt, b: Tree): Tree = { - Node(c,a,x,b) match { - case Node(Black,Node(Red,Node(Red,a,xV,b),yV,c),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,Node(Red,a,xV,Node(Red,b,yV,c)),zV,d) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,Node(Red,b,yV,c),zV,d)) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - case Node(Black,a,xV,Node(Red,b,yV,Node(Red,c,zV,d))) => - Node(Red,Node(Black,a,xV,b),yV,Node(Black,c,zV,d)) - } - } ensuring (res => content(res) == content(Node(c,a,x,b))) -} diff --git a/testcases/web/verification/07_Search_Linked-List.scala b/testcases/web/verification/07_Search_Linked-List.scala deleted file mode 100644 index 8d743bd21791f50383ade1c933b0ff2f0b57a20e..0000000000000000000000000000000000000000 --- a/testcases/web/verification/07_Search_Linked-List.scala +++ /dev/null @@ -1,47 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object SearchLinkedList { - sealed abstract class List - case class Cons(head : BigInt, tail : List) extends List - case object Nil extends List - - def size(list : List) : BigInt = (list match { - case Nil => BigInt(0) - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def contains(list : List, elem : BigInt) : Boolean = (list match { - case Nil => false - case Cons(x, xs) => x == elem || contains(xs, elem) - }) - - def firstZero(list : List) : BigInt = (list match { - case Nil => BigInt(0) - case Cons(x, xs) => if (x == 0) BigInt(0) else firstZero(xs) + 1 - }) ensuring (res => - res >= 0 && (if (contains(list, 0)) { - firstZeroAtPos(list, res) - } else { - res == size(list) - })) - - def firstZeroAtPos(list : List, pos : BigInt) : Boolean = { - list match { - case Nil => false - case Cons(x, xs) => if (pos == 0) x == 0 else x != 0 && firstZeroAtPos(xs, pos - 1) - } - } - - def goal(list : List, i : BigInt) : Boolean = { - if(firstZero(list) == i) { - if(contains(list, 0)) { - firstZeroAtPos(list, i) - } else { - i == size(list) - } - } else { - true - } - } holds -} diff --git a/testcases/web/verification/08_Sum_and_Max.scala b/testcases/web/verification/08_Sum_and_Max.scala deleted file mode 100644 index 9dcc6d333c1c8015581ae2ba1879030220dc9772..0000000000000000000000000000000000000000 --- a/testcases/web/verification/08_Sum_and_Max.scala +++ /dev/null @@ -1,46 +0,0 @@ -import leon.lang._ -import leon.annotation._ - -object SumAndMax { - sealed abstract class List - case class Cons(head : BigInt, tail : List) extends List - case object Nil extends List - - def max(list : List) : BigInt = { - require(list != Nil) - list match { - case Cons(x, Nil) => x - case Cons(x, xs) => { - val m2 = max(xs) - if(m2 > x) m2 else x - } - } - } - - def sum(list : List) : BigInt = list match { - case Nil => BigInt(0) - case Cons(x, xs) => x + sum(xs) - } - - def size(list : List) : BigInt = (list match { - case Nil => BigInt(0) - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def allPos(list : List) : Boolean = list match { - case Nil => true - case Cons(x, xs) => x >= 0 && allPos(xs) - } - - def prop0(list : List) : Boolean = { - require(list != Nil) - !allPos(list) || max(list) >= 0 - } holds - - @induct - def property(list : List) : Boolean = { - // This precondition was given in the problem but isn't actually useful :D - // require(allPos(list)) - sum(list) <= size(list) * (if(list == Nil) 0 else max(list)) - } holds -} diff --git a/testcases/web/verification/09_Heap.scala b/testcases/web/verification/09_Heap.scala deleted file mode 100644 index aa66ca2f2a5e40ce80165a9cf0f0db8e00aa4d43..0000000000000000000000000000000000000000 --- a/testcases/web/verification/09_Heap.scala +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.annotation._ -import leon.lang._ - -object Heaps { - /*~~~~~~~~~~~~~~~~~~~~~~~*/ - /* Data type definitions */ - /*~~~~~~~~~~~~~~~~~~~~~~~*/ - private case class Node(rank : BigInt, elem : Int, nodes : Heap) - - sealed abstract class Heap - private case class Nodes(head : Node, tail : Heap) extends Heap - private case object Empty extends Heap - - sealed abstract class OptInt - case class Some(value : Int) extends OptInt - case object None extends OptInt - - /*~~~~~~~~~~~~~~~~~~~~~~~*/ - /* Abstraction functions */ - /*~~~~~~~~~~~~~~~~~~~~~~~*/ - def heapContent(h : Heap) : Set[Int] = h match { - case Empty => Set.empty[Int] - case Nodes(n, ns) => nodeContent(n) ++ heapContent(ns) - } - - def nodeContent(n : Node) : Set[Int] = n match { - case Node(_, e, h) => Set(e) ++ heapContent(h) - } - - /*~~~~~~~~~~~~~~~~~~~~~~~~*/ - /* Helper/local functions */ - /*~~~~~~~~~~~~~~~~~~~~~~~~*/ - private def reverse(h : Heap) : Heap = reverse0(h, Empty) - private def reverse0(h : Heap, acc : Heap) : Heap = (h match { - case Empty => acc - case Nodes(n, ns) => reverse0(ns, Nodes(n, acc)) - }) ensuring(res => heapContent(res) == heapContent(h) ++ heapContent(acc)) - - private def link(t1 : Node, t2 : Node) = (t1, t2) match { - case (Node(r, e1, ns1), Node(_, e2, ns2)) => - if(e1 <= e2) { - Node(r + 1, e1, Nodes(t2, ns1)) - } else { - Node(r + 1, e2, Nodes(t1, ns2)) - } - } - - private def insertNode(t : Node, h : Heap) : Heap = (h match { - case Empty => Nodes(t, Empty) - case Nodes(t2, h2) => - if(t.rank < t2.rank) { - Nodes(t, h) - } else { - insertNode(link(t, t2), h2) - } - }) ensuring(res => heapContent(res) == nodeContent(t) ++ heapContent(h)) - - private def getMin(h : Heap) : (Node, Heap) = { - require(h != Empty) - h match { - case Nodes(t, Empty) => (t, Empty) - case Nodes(t, ts) => - val (t0, ts0) = getMin(ts) - if(t.elem < t0.elem) { - (t, ts) - } else { - (t0, Nodes(t, ts0)) - } - } - } ensuring(_ match { - case (n,h2) => nodeContent(n) ++ heapContent(h2) == heapContent(h) - }) - - /*~~~~~~~~~~~~~~~~*/ - /* Heap interface */ - /*~~~~~~~~~~~~~~~~*/ - def empty() : Heap = { - Empty - } ensuring(res => heapContent(res) == Set.empty[Int]) - - def isEmpty(h : Heap) : Boolean = { - (h == Empty) - } ensuring(res => res == (heapContent(h) == Set.empty[Int])) - - def insert(e : Int, h : Heap) : Heap = { - insertNode(Node(0, e, Empty), h) - } ensuring(res => heapContent(res) == heapContent(h) ++ Set(e)) - - def merge(h1 : Heap, h2 : Heap) : Heap = ((h1,h2) match { - case (_, Empty) => h1 - case (Empty, _) => h2 - case (Nodes(t1, ts1), Nodes(t2, ts2)) => - if(t1.rank < t2.rank) { - Nodes(t1, merge(ts1, h2)) - } else if(t2.rank < t1.rank) { - Nodes(t2, merge(h1, ts2)) - } else { - insertNode(link(t1, t2), merge(ts1, ts2)) - } - }) ensuring(res => heapContent(res) == heapContent(h1) ++ heapContent(h2)) - - def findMin(h : Heap) : OptInt = (h match { - case Empty => None - case Nodes(Node(_, e, _), ns) => - findMin(ns) match { - case None => Some(e) - case Some(e2) => Some(if(e < e2) e else e2) - } - }) ensuring(_ match { - case None => isEmpty(h) - case Some(v) => heapContent(h).contains(v) - }) - - def deleteMin(h : Heap) : Heap = (h match { - case Empty => Empty - case ts : Nodes => - val (Node(_, e, ns1), ns2) = getMin(ts) - merge(reverse(ns1), ns2) - }) ensuring(res => heapContent(res).subsetOf(heapContent(h))) - - def sanity0() : Boolean = { - val h0 : Heap = Empty - val h1 = insert(42, h0) - val h2 = insert(72, h1) - val h3 = insert(0, h2) - findMin(h0) == None && - findMin(h1) == Some(42) && - findMin(h2) == Some(42) && - findMin(h3) == Some(0) - }.holds - - def sanity1() : Boolean = { - val h0 = insert(42, Empty) - val h1 = insert(0, Empty) - val h2 = merge(h0, h1) - findMin(h2) == Some(0) - }.holds - - def sanity3() : Boolean = { - val h0 = insert(42, insert(0, insert(12, Empty))) - val h1 = deleteMin(h0) - findMin(h1) == Some(12) - }.holds -} - diff --git a/testcases/web/verification/10_FoldAssociative.scala b/testcases/web/verification/10_FoldAssociative.scala deleted file mode 100644 index 6920231115fea93a1b7c7cefc27691a0ee2471bb..0000000000000000000000000000000000000000 --- a/testcases/web/verification/10_FoldAssociative.scala +++ /dev/null @@ -1,104 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ -import leon.proof._ - -object FoldAssociative { - - sealed abstract class List - case class Cons(head: Int, tail: List) extends List - case class Nil() extends List - - sealed abstract class Option - case class Some(x: Int) extends Option - case class None() extends Option - - def foldRight[A](list: List, state: A, f: (Int, A) => A): A = list match { - case Cons(head, tail) => - val tailState = foldRight(tail, state, f) - f(head, tailState) - case Nil() => state - } - - def take(list: List, count: Int): List = { - require(count >= 0) - list match { - case Cons(head, tail) if count > 0 => Cons(head, take(tail, count - 1)) - case _ => Nil() - } - } - - def drop(list: List, count: Int): List = { - require(count >= 0) - list match { - case Cons(head, tail) if count > 0 => drop(tail, count - 1) - case _ => list - } - } - - def append(l1: List, l2: List): List = { - l1 match { - case Cons(head, tail) => Cons(head, append(tail, l2)) - case Nil() => l2 - } - } - - def lemma_split(list: List, x: Int): Boolean = { - require(x >= 0) - val f = (x: Int, s: Int) => x + s - val l1 = take(list, x) - val l2 = drop(list, x) - foldRight(list, 0, f) == foldRight(l1, foldRight(l2, 0, f), f) - } - - def lemma_split_induct(list: List, x: Int): Boolean = { - require(x >= 0) - val f = (x: Int, s: Int) => x + s - val l1 = take(list, x) - val l2 = drop(list, x) - lemma_split(list, x) because (list match { - case Cons(head, tail) if x > 0 => - lemma_split_induct(tail, x - 1) - case _ => true - }) - }.holds - - def lemma_reassociative(list: List, x: Int): Boolean = { - require(x >= 0) - val f = (x: Int, s: Int) => x + s - val l1 = take(list, x) - val l2 = drop(list, x) - - foldRight(list, 0, f) == foldRight(l1, 0, f) + foldRight(l2, 0, f) - } - - def lemma_reassociative_induct(list: List, x: Int): Boolean = { - require(x >= 0) - val f = (x: Int, s: Int) => x + s - val l1 = take(list, x) - val l2 = drop(list, x) - lemma_reassociative(list, x) because (list match { - case Cons(head, tail) if x > 0 => - lemma_reassociative_induct(tail, x - 1) - case _ => true - }) - }.holds - - def lemma_reassociative_presplit(l1: List, l2: List): Boolean = { - val f = (x: Int, s: Int) => x + s - val list = append(l1, l2) - foldRight(list, 0, f) == foldRight(l1, 0, f) + foldRight(l2, 0, f) - } - - def lemma_reassociative_presplit_induct(l1: List, l2: List): Boolean = { - val f = (x: Int, s: Int) => x + s - val list = append(l1, l2) - lemma_reassociative_presplit(l1, l2) because (l1 match { - case Cons(head, tail) => - lemma_reassociative_presplit_induct(tail, l2) - case Nil() => true - }) - }.holds - -} diff --git a/testcases/web/verification/11_MergeSort.scala b/testcases/web/verification/11_MergeSort.scala deleted file mode 100644 index 9a1cb71fe0368c6b2ef6021b4f11a2eac961fea5..0000000000000000000000000000000000000000 --- a/testcases/web/verification/11_MergeSort.scala +++ /dev/null @@ -1,122 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.annotation._ -import leon.lang._ - -object MergeSort { - // Data types - sealed abstract class List - case class Cons(head : Int, tail : List) extends List - case class Nil() extends List - - sealed abstract class LList - case class LCons(head : List, tail : LList) extends LList - case class LNil() extends LList - - def content(list : List) : Set[Int] = list match { - case Nil() => Set.empty[Int] - case Cons(x, xs) => Set(x) ++ content(xs) - } - - def lContent(llist : LList) : Set[Int] = llist match { - case LNil() => Set.empty[Int] - case LCons(x, xs) => content(x) ++ lContent(xs) - } - - def size(list : List) : BigInt = (list match { - case Nil() => BigInt(0) - case Cons(_, xs) => 1 + size(xs) - }) ensuring(_ >= 0) - - def isSorted(list : List) : Boolean = list match { - case Nil() => true - case Cons(_, Nil()) => true - case Cons(x1, Cons(x2, _)) if(x1 > x2) => false - case Cons(_, xs) => isSorted(xs) - } - - def lIsSorted(llist : LList) : Boolean = llist match { - case LNil() => true - case LCons(x, xs) => isSorted(x) && lIsSorted(xs) - } - - def abs(i : BigInt) : BigInt = { - if(i < 0) -i else i - } ensuring(_ >= 0) - - def mergeSpec(list1 : List, list2 : List, res : List) : Boolean = { - isSorted(res) && content(res) == content(list1) ++ content(list2) - } - - def mergeFast(list1 : List, list2 : List) : List = { - require(isSorted(list1) && isSorted(list2)) - - (list1, list2) match { - case (_, Nil()) => list1 - case (Nil(), _) => list2 - case (Cons(x, xs), Cons(y, ys)) => - if(x <= y) { - Cons(x, mergeFast(xs, list2)) - } else { - Cons(y, mergeFast(list1, ys)) - } - } - } ensuring(res => mergeSpec(list1, list2, res)) - - def splitSpec(list : List, res : (List,List)) : Boolean = { - val s1 = size(res._1) - val s2 = size(res._2) - abs(s1 - s2) <= 1 && s1 + s2 == size(list) && - content(res._1) ++ content(res._2) == content(list) - } - - def split(list : List) : (List,List) = (list match { - case Nil() => (Nil(), Nil()) - case Cons(x, Nil()) => (Cons(x, Nil()), Nil()) - case Cons(x1, Cons(x2, xs)) => - val (s1,s2) = split(xs) - (Cons(x1, s1), Cons(x2, s2)) - }) ensuring(res => splitSpec(list, res)) - - def sortSpec(in : List, out : List) : Boolean = { - content(out) == content(in) && isSorted(out) - } - - // Not really quicksort, neither mergesort. - def weirdSort(in : List) : List = (in match { - case Nil() => Nil() - case Cons(x, Nil()) => Cons(x, Nil()) - case _ => - val (s1,s2) = split(in) - mergeFast(weirdSort(s1), weirdSort(s2)) - }) ensuring(res => sortSpec(in, res)) - - def toLList(list : List) : LList = (list match { - case Nil() => LNil() - case Cons(x, xs) => LCons(Cons(x, Nil()), toLList(xs)) - }) ensuring(res => lContent(res) == content(list) && lIsSorted(res)) - - def mergeMap(llist : LList) : LList = { - require(lIsSorted(llist)) - - llist match { - case LNil() => LNil() - case o @ LCons(x, LNil()) => o - case LCons(x, LCons(y, ys)) => LCons(mergeFast(x, y), mergeMap(ys)) - } - } ensuring(res => lContent(res) == lContent(llist) && lIsSorted(res)) - - def mergeReduce(llist : LList) : List = { - require(lIsSorted(llist)) - - llist match { - case LNil() => Nil() - case LCons(x, LNil()) => x - case _ => mergeReduce(mergeMap(llist)) - } - } ensuring(res => content(res) == lContent(llist) && isSorted(res)) - - def mergeSort(in : List) : List = { - mergeReduce(toLList(in)) - } ensuring(res => sortSpec(in, res)) -} diff --git a/testcases/web/verification/12_ParBalance.scala b/testcases/web/verification/12_ParBalance.scala deleted file mode 100644 index d1ddfd3f69baee993c9e01a622217236e27226ca..0000000000000000000000000000000000000000 --- a/testcases/web/verification/12_ParBalance.scala +++ /dev/null @@ -1,208 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon._ -import leon.lang._ - -object ParBalance { - - sealed abstract class List - case class Cons(head: BigInt, tail: List) extends List - case class Nil() extends List - - sealed abstract class Option - case class Some(x: BigInt) extends Option - case class None() extends Option - - val openPar : BigInt = BigInt(1) - val closePar : BigInt = BigInt(2) - - def balanced(list: List, counter: BigInt): Boolean = { - if (counter < 0) false else list match { - case Cons(head, tail) => - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced(tail, c) - case Nil() => counter == 0 - } - } - - def balanced_nonEarly(list: List, counter: BigInt): Boolean = { - list match { - case Cons(head, tail) => - if (counter < 0) balanced_nonEarly(tail, counter) else { - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced_nonEarly(tail, c) - } - case Nil() => counter == 0 - } - } ensuring { res => res == balanced(list, counter) } - - def balanced_withFailure(list: List, counter: BigInt, failed: Boolean): Boolean = { - require(counter >= 0 || failed) - list match { - case Cons(head, tail) => - val c = if (head == openPar) counter + 1 - else if (head == closePar) counter - 1 - else counter - balanced_withFailure(tail, c, failed || c < 0) - case Nil() => !failed && counter == 0 - } - } ensuring { res => - if (failed) { - res == balanced_nonEarly(list, -1) - } else { - res == balanced_nonEarly(list, counter) - } - } - - def balanced_withReduce(list: List, p: (BigInt, BigInt)): Boolean = { - require(p._1 >= 0 && p._2 >= 0) - list match { - case Cons(head, tail) => - val p2 = reduce(p, parPair(head)) - balanced_withReduce(tail, p2) - case Nil() => - p._1 == 0 && p._2 == 0 - } - } ensuring { res => res == balanced_withFailure(list, p._1 - p._2, p._2 > 0) } - - def balanced_foldLeft_equivalence(list: List, p: (BigInt, BigInt)): Boolean = { - require(p._1 >= 0 && p._2 >= 0) - val f = (s: (BigInt, BigInt), x: BigInt) => reduce(s, parPair(x)) - (foldLeft(list, p, f) == (BigInt(0), BigInt(0))) == balanced_withReduce(list, p) && (list match { - case Cons(head, tail) => - val p2 = f(p, head) - balanced_foldLeft_equivalence(tail, p2) - case Nil() => true - }) - }.holds - - def foldRight[A](list: List, state: A, f: (BigInt, A) => A): A = list match { - case Cons(head, tail) => - val tailState = foldRight(tail, state, f) - f(head, tailState) - case Nil() => state - } - - def foldLeft[A](list: List, state: A, f: (A, BigInt) => A): A = list match { - case Cons(head, tail) => - val nextState = f(state, head) - foldLeft(tail, nextState, f) - case Nil() => state - } - - def reduce(p1: (BigInt, BigInt), p2: (BigInt, BigInt)): (BigInt, BigInt) = { - if (p1._1 >= p2._2) { - (p1._1 - p2._2 + p2._1, p1._2) - } else { - (p2._1, p2._2 - p1._1 + p1._2) - } - } - - def reduce_associative(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(p1, reduce(p2, p3)) == reduce(reduce(p1, p2), p3) - }.holds - - def swap(p: (BigInt, BigInt)): (BigInt, BigInt) = (p._2, p._1) - - def reduce_inverse(p1: (BigInt, BigInt), p2: (BigInt, BigInt)): Boolean = { - reduce(p1, p2) == swap(reduce(swap(p2), swap(p1))) - }.holds - - def reduce_associative_inverse(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(p1, reduce(p2, p3)) == swap(reduce(reduce(swap(p3), swap(p2)), swap(p1))) - }.holds - - def reduce_associative_inverse2(p1: (BigInt, BigInt), p2: (BigInt, BigInt), p3: (BigInt, BigInt)): Boolean = { - reduce(reduce(p1, p2), p3) == swap(reduce(swap(p3), reduce(swap(p2), swap(p1)))) - }.holds - - def parPair(x: BigInt): (BigInt, BigInt) = { - if (x == openPar) (1, 0) else if (x == closePar) (0, 1) else (0, 0) - } - - def headOption(list: List): Option = list match { - case Cons(head, tail) => Some(head) - case Nil() => None() - } - - def lastOption(list: List): Option = list match { - case Cons(head, Nil()) => Some(head) - case Cons(head, tail) => lastOption(tail) - case Nil() => None() - } - - def init(list: List): List = list match { - case Cons(head, Nil()) => Nil() - case Cons(head, tail) => Cons(head, init(tail)) - case Nil() => Nil() - } - - def tail(list: List): List = list match { - case Cons(head, tail) => tail - case Nil() => Nil() - } - - def addLast(list: List, x: BigInt): List = { - list match { - case Cons(head, tail) => Cons(head, addLast(tail, x)) - case Nil() => Cons(x, Nil()) - } - } ensuring { res => lastOption(res) == Some(x) && init(res) == list } - - def reverse(list: List): List = { - list match { - case Cons(head, tail) => addLast(reverse(tail), head) - case Nil() => Nil() - } - } ensuring { res => - lastOption(res) == headOption(list) && - lastOption(list) == headOption(res) - } - - def reverse_tail_equivalence(list: List): Boolean = { - reverse(tail(list)) == init(reverse(list)) - }.holds - - def reverse_init_equivalence(list: List): Boolean = { - reverse(init(list)) == tail(reverse(list)) && (list match { - case Cons(head, tail) => reverse_init_equivalence(tail) - case Nil() => true - }) - }.holds - - def reverse_equality_equivalence(l1: List, l2: List): Boolean = { - (l1 == l2) == (reverse(l1) == reverse(l2)) && ((l1, l2) match { - case (Cons(h1, t1), Cons(h2, t2)) => reverse_equality_equivalence(t1, t2) - case _ => true - }) - }.holds - - def reverse_reverse_equivalence(list: List): Boolean = { - reverse(reverse(list)) == list && ((list, reverse(list)) match { - case (Cons(h1, t1), Cons(h2, t2)) => - reverse_reverse_equivalence(t1) && reverse_reverse_equivalence(t2) - case _ => true - }) - }.holds - - /* - def fold_equivalence(list: List): Boolean = { - val s = (0, 0) - val fl = (s: (BigInt, BigInt), x: BigInt) => reduce(s, parPair(x)) - val fr = (x: BigInt, s: (BigInt, BigInt)) => reduce(parPair(x), s) - - foldLeft(list, s, fl) == foldRight(list, s, fr) - }.holds - - def lemma(list: List): Boolean = { - val f = (x: BigInt, s: (BigInt, BigInt)) => reduce(parPair(x), s) - fold_equivalence(list) && balanced_foldLeft_equivalence(list, (0, 0)) && - (foldRight(list, (0, 0), f) == (0, 0)) == balanced(list, 0) - }.holds - */ - -} diff --git a/testcases/web/verification/13_Monads.scala b/testcases/web/verification/13_Monads.scala deleted file mode 100644 index 05b46ceb0f02a96811b7ca8a4606b4b4b30de3e3..0000000000000000000000000000000000000000 --- a/testcases/web/verification/13_Monads.scala +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright 2009-2015 EPFL, Lausanne */ - -import leon.lang._ -import leon.collection._ - -object Monads3 { - - def append[T](l1: List[T], l2: List[T]): List[T] = { - l1 match { - case Cons(head, tail) => Cons(head, append(tail, l2)) - case Nil() => l2 - } - } ensuring { res => (res == l1) || (l2 != Nil[T]()) } - - def flatMap[T,U](list: List[T], f: T => List[U]): List[U] = list match { - case Cons(head, tail) => append(f(head), flatMap(tail, f)) - case Nil() => Nil() - } - - def associative_lemma[T,U,V](list: List[T], f: T => List[U], g: U => List[V]): Boolean = { - flatMap(flatMap(list, f), g) == flatMap(list, (x: T) => flatMap(f(x), g)) - } - - def associative_lemma_induct[T,U,V](list: List[T], flist: List[U], glist: List[V], f: T => List[U], g: U => List[V]): Boolean = { - associative_lemma(list, f, g) && - append(glist, flatMap(append(flist, flatMap(list, f)), g)) == append(append(glist, flatMap(flist, g)), flatMap(list, (x: T) => flatMap(f(x), g))) && - (glist match { - case Cons(ghead, gtail) => - associative_lemma_induct(list, flist, gtail, f, g) - case Nil() => flist match { - case Cons(fhead, ftail) => - associative_lemma_induct(list, ftail, g(fhead), f, g) - case Nil() => list match { - case Cons(head, tail) => associative_lemma_induct(tail, f(head), Nil(), f, g) - case Nil() => true - } - } - }) - }.holds - - def left_unit_law[T,U](x: T, f: T => List[U]): Boolean = { - flatMap(Cons(x, Nil()), f) == f(x) - }.holds - - def right_unit_law[T](list: List[T]): Boolean = { - flatMap(list, (x: T) => Cons(x, Nil())) == list - } - - def right_unit_induct[T,U](list: List[T]): Boolean = { - right_unit_law(list) && (list match { - case Cons(head, tail) => right_unit_induct(tail) - case Nil() => true - }) - }.holds - - def flatMap_zero_law[T,U](f: T => List[U]): Boolean = { - flatMap(Nil[T](), f) == Nil[U]() - }.holds - - def flatMap_to_zero_law[T](list: List[T]): Boolean = { - flatMap(list, (x: T) => Nil[T]()) == Nil[T]() - } - - def flatMap_to_zero_induct[T,U](list: List[T]): Boolean = { - flatMap_to_zero_law(list) && (list match { - case Cons(head, tail) => flatMap_to_zero_induct(tail) - case Nil() => true - }) - }.holds - - def add_zero_law[T](list: List[T]): Boolean = { - append(list, Nil()) == list - }.holds - - def zero_add_law[T](list: List[T]): Boolean = { - append(Nil(), list) == list - }.holds - -} diff --git a/testcases/web/verification/14_HeapSort.scala b/testcases/web/verification/14_HeapSort.scala deleted file mode 100644 index 4537664e7b89a6ae51488843192f353d45d4ba6b..0000000000000000000000000000000000000000 --- a/testcases/web/verification/14_HeapSort.scala +++ /dev/null @@ -1,147 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object HeapSort { - sealed abstract class Heap - case class Leaf() extends Heap - case class Node(rk: BigInt, value: BigInt, left: Heap, right: Heap) extends Heap - - def rightHeight(h: Heap): BigInt = { - h match { - case Leaf() => BigInt(0) - case Node(_, _, _, r) => rightHeight(r) + 1 - } - } ensuring (_ >= 0) - - def rank(h: Heap): BigInt = h match { - case Leaf() => 0 - case Node(rk, _, _, _) => rk - } - - def max(x: BigInt, y: BigInt): BigInt = { - if (x <= y) y else x - } - - def rootVal(h: Heap): BigInt = { - require(h != Leaf()) - h match { - case Node(_, v, _, _) => v - } - } - - private def hasLeftistProperty(h: Heap): Boolean = (h match { - case Leaf() => true - case Node(_, v, l, r) => hasLeftistProperty(l) && hasLeftistProperty(r) && - // properties about rank (necessary for proving running time) - rightHeight(l) >= rightHeight(r) && (rank(h) == rightHeight(h)) && - // properties of a max heap - (l == Leaf() || v >= rootVal(l)) && (r == Leaf() || v >= rootVal(r)) - }) - - def heapSize(t: Heap): BigInt = { - (t match { - case Leaf() => BigInt(0) - case Node(_, v, l, r) => heapSize(l) + 1 + heapSize(r) - }) - } ensuring (_ >= 0) - - def heapContents(t: Heap): Set[BigInt] = { - t match { - case Leaf() => Set() - case Node(_, v, l, r) => - Set(v) ++ heapContents(l) ++ heapContents(r) - } - } - - def merge(h1: Heap, h2: Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2)) - h1 match { - case Leaf() => h2 - case Node(_, v1, l1, r1) => h2 match { - case Leaf() => h1 - case Node(_, v2, l2, r2) => - if (v1 > v2) - makeT(v1, l1, merge(r1, h2)) - else - makeT(v2, l2, merge(h1, r2)) - } - } - } ensuring (res => - //the root value is one of the root values of the merged heaps - (res match { - case Leaf() => h1 == Leaf() && h2 == Leaf() - case Node(_, v, _, _) => - (h1 != Leaf() && rootVal(h1) == v) || (h2 != Leaf() && rootVal(h2) == v) - }) && - hasLeftistProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - heapContents(h1) ++ heapContents(h2) == heapContents(res)) - - private def makeT(value: BigInt, left: Heap, right: Heap): Heap = { - if (rank(left) >= rank(right)) - Node(rank(right) + 1, value, left, right) - else - Node(rank(left) + 1, value, right, left) - } - - def insert(element: BigInt, heap: Heap): Heap = { - require(hasLeftistProperty(heap)) - - merge(Node(1, element, Leaf(), Leaf()), heap) - - } ensuring (res => heapSize(res) == heapSize(heap) + 1 && - heapContents(res) == Set(element) ++ heapContents(heap)) - - def findMax(h: Heap): BigInt = { - require(hasLeftistProperty(h) && h != Leaf()) - rootVal(h) - } - - def removeMax(h: Heap): Heap = { - require(hasLeftistProperty(h)) - h match { - case Node(_, _, l, r) => merge(l, r) - case l @ Leaf() => l - } - } ensuring (res => hasLeftistProperty(res) && - (h == Leaf() || heapContents(h) == heapContents(res) ++ Set(findMax(h))) && - (res == Leaf() || findMax(res) <= findMax(h))) - - def sortedDescending(l: List[BigInt]): Boolean = { - l match { - case Nil() => true - case Cons(x, Nil()) => true - case Cons(x, tail @ Cons(y, _)) => - (x >= y) && sortedDescending(tail) - } - } - - def removeElements(h: Heap): List[BigInt] = { - require(hasLeftistProperty(h)) - h match { - case Leaf() => Nil[BigInt]() - case _ => - Cons(findMax(h), removeElements(removeMax(h))) - } - } ensuring (res => sortedDescending(res) && - heapSize(h) == res.size && //sizes are preserved - heapContents(h) == res.content //contents are preserved - ) - - def buildHeap(l: List[BigInt]): Heap = { - l match { - case Nil() => Leaf() - case Cons(x, xs) => insert(x, buildHeap(xs)) - } - } ensuring (res => hasLeftistProperty(res) && - heapContents(res) == l.content && //contents are preserved - heapSize(res) == l.size) //sizes are preserved - - def heapSort(l: List[BigInt]): List[BigInt] = ({ - - val heap = buildHeap(l) - removeElements(heap) - - }) ensuring (res => sortedDescending(res) && //elements are in descending order - res.size == l.size && res.content == l.content) //contents and sizes are preserved -} diff --git a/testcases/web/verification/15_LeftistHeap.scala b/testcases/web/verification/15_LeftistHeap.scala deleted file mode 100644 index 9ab1a583afb739cdd079c8014ad0c897cc87b7f6..0000000000000000000000000000000000000000 --- a/testcases/web/verification/15_LeftistHeap.scala +++ /dev/null @@ -1,141 +0,0 @@ -import leon.lang._ -import leon.collection._ - -object HeapSort { - sealed abstract class Heap - case class Leaf() extends Heap - case class Node(rk: BigInt, value: BigInt, left: Heap, right: Heap) extends Heap - - def rightHeight(h: Heap): BigInt = { - h match { - case Leaf() => BigInt(0) - case Node(_, _, _, r) => rightHeight(r) + 1 - } - } ensuring (_ >= 0) - - def rank(h: Heap): BigInt = h match { - case Leaf() => 0 - case Node(rk, _, _, _) => rk - } - - def max(x: BigInt, y: BigInt): BigInt = { - if (x <= y) y else x - } - - def rootVal(h: Heap): BigInt = { - require(h != Leaf()) - h match { - case Node(_, v, _, _) => v - } - } - - private def hasLeftistProperty(h: Heap): Boolean = (h match { - case Leaf() => true - case Node(_, v, l, r) => hasLeftistProperty(l) && hasLeftistProperty(r) && - // properties about rank (necessary for proving running time) - rightHeight(l) >= rightHeight(r) && (rank(h) == rightHeight(h)) && - // properties of a max heap - (l == Leaf() || v >= rootVal(l)) && (r == Leaf() || v >= rootVal(r)) - }) - - def heapSize(t: Heap): BigInt = { - (t match { - case Leaf() => BigInt(0) - case Node(_, v, l, r) => heapSize(l) + 1 + heapSize(r) - }) - } ensuring (_ >= 0) - - def heapContents(t: Heap): Set[BigInt] = { - t match { - case Leaf() => Set() - case Node(_, v, l, r) => - Set(v) ++ heapContents(l) ++ heapContents(r) - } - } - - def merge(h1: Heap, h2: Heap): Heap = { - require(hasLeftistProperty(h1) && hasLeftistProperty(h2)) - h1 match { - case Leaf() => h2 - case Node(_, v1, l1, r1) => h2 match { - case Leaf() => h1 - case Node(_, v2, l2, r2) => - if (v1 > v2) - makeT(v1, l1, merge(r1, h2)) - else - makeT(v2, l2, merge(h1, r2)) - } - } - } ensuring (res => - //the root value is one of the root values of the merged heaps - (res match { - case Leaf() => h1 == Leaf() && h2 == Leaf() - case Node(_, v, _, _) => - (h1 != Leaf() && rootVal(h1) == v) || (h2 != Leaf() && rootVal(h2) == v) - }) && - hasLeftistProperty(res) && - heapSize(h1) + heapSize(h2) == heapSize(res) && - heapContents(h1) ++ heapContents(h2) == heapContents(res)) - - private def makeT(value: BigInt, left: Heap, right: Heap): Heap = { - if (rank(left) >= rank(right)) - Node(rank(right) + 1, value, left, right) - else - Node(rank(left) + 1, value, right, left) - } - - def insert(element: BigInt, heap: Heap): Heap = { - require(hasLeftistProperty(heap)) - - merge(Node(1, element, Leaf(), Leaf()), heap) - - } ensuring (res => heapSize(res) == heapSize(heap) + 1 && - heapContents(res) == Set(element) ++ heapContents(heap)) - - def listMax(l: List[BigInt]): BigInt = { - require(l != Nil[BigInt]()) - l match { - case Cons(x, Nil()) => - x - case Cons(x, tail) => - max(x, listMax(tail)) - } - } - - def append(l1: List[BigInt], l2: List[BigInt]): List[BigInt] = { - l1 match { - case Nil() => l2 - case Cons(x, tail) => - Cons(x, append(tail, l2)) - } - } ensuring (res => (l2 != Nil[BigInt]() || res == l1) && - (res == Nil[BigInt]() || - ((l1 == Nil[BigInt]() && listMax(res) == listMax(l2)) || - (l2 == Nil[BigInt]() && listMax(res) == listMax(l1)) || - (listMax(res) == max(listMax(l1), listMax(l2)))))) - - def heapElements(t: Heap): List[BigInt] = { - require(hasLeftistProperty(t)) - t match { - case Leaf() => Nil[BigInt]() - case Node(_, v, l, r) => - v :: append(heapElements(l), heapElements(r)) - } - } ensuring (res => t == Leaf() || - (res != Nil[BigInt]() && rootVal(t) == listMax(res))) - - def findMax(h: Heap): BigInt = { - require(hasLeftistProperty(h) && h != Leaf()) - rootVal(h) - } ensuring (res => res == listMax(heapElements(h))) // max heap property - - def removeMax(h: Heap): Heap = { - require(hasLeftistProperty(h)) - h match { - case Node(_, _, l, r) => merge(l, r) - case l @ Leaf() => l - } - } ensuring (res => hasLeftistProperty(res) && - (h == Leaf() || heapContents(h) == heapContents(res) ++ Set(findMax(h))) && - (res == Leaf() || findMax(res) <= findMax(h))) -} diff --git a/travis/fetchCVC4.sh b/travis/fetchCVC4.sh deleted file mode 100755 index 6c894862c86fe3a2f57fbbb099ef0dfae00c97d0..0000000000000000000000000000000000000000 --- a/travis/fetchCVC4.sh +++ /dev/null @@ -1,7 +0,0 @@ -dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) -mkdir -p $dir/builds -curl http://lara.epfl.ch/~ekneuss/cvc4-builds/cvc4-2015-04-17-x86_64-linux-opt -o $dir/builds/cvc4 - -chmod u+x $dir/builds/cvc4 - -export PATH=$dir/builds/:$PATH