Skip to content
Snippets Groups Projects
Commit f7c035fe authored by Régis Blanc's avatar Régis Blanc
Browse files

fixing some bug with the substitution of vars in the postcondition

parent a61a9ffe
Branches
Tags
No related merge requests found
...@@ -3,19 +3,22 @@ import leon.Utils._ ...@@ -3,19 +3,22 @@ import leon.Utils._
object Abs { object Abs {
def abs(tab: Map[Int, Int], size: Int, j: Int): Map[Int, Int] = { def abs(tab: Map[Int, Int], size: Int, j: Int): Map[Int, Int] = ({
require(j >= 0 && j < size && tab.isDefinedAt(j) && size > 0) require(j >= 0 && j < size && size > 0)
var k = 0 var k = 0
var tabres = Map.empty[Int, Int] var tabres = Map.empty[Int, Int]
(while(k < size) { (while(k < size) {
if(tab(k) < 0) if(tab.isDefinedAt(k)) {
tabres = tabres.updated(k, -tab(k)) if(tab(k) < 0)
else tabres = tabres.updated(k, -tab(k))
tabres = tabres.updated(k, tab(k)) else
tabres = tabres.updated(k, tab(k))
} else {
tabres = tabres.updated(k, 0)
}
k = k + 1 k = k + 1
}) invariant(k >= 0) }) invariant(k >= 0 && (if(j < k) tabres(j) >= 0 else true))
tabres tabres
}) ensuring(res => res(j) >= 0)
}
} }
...@@ -91,14 +91,15 @@ object ImperativeCodeElimination extends Pass { ...@@ -91,14 +91,15 @@ object ImperativeCodeElimination extends Pass {
Map(whileFunVars.head.toVariable -> resVar) Map(whileFunVars.head.toVariable -> resVar)
else else
whileFunVars.zipWithIndex.map{ case (v, i) => (v.toVariable, TupleSelect(resVar, i+1).setType(v.getType)) }.toMap whileFunVars.zipWithIndex.map{ case (v, i) => (v.toVariable, TupleSelect(resVar, i+1).setType(v.getType)) }.toMap
val modifiedVars2ResultVars: Map[Expr, Expr] = modifiedVars.map(v => (v.toVariable, modifiedVars2WhileFunVars(v.toVariable))).toMap val modifiedVars2ResultVars: Map[Expr, Expr] = modifiedVars.map(v => (v.toVariable, whileFunVars2ResultVars(modifiedVars2WhileFunVars(v.toVariable)))).toMap
val trivialPostcondition: Option[Expr] = Some(Not(replace(whileFunVars2ResultVars, whileFunCond))) val trivialPostcondition: Option[Expr] = Some(Not(replace(whileFunVars2ResultVars, whileFunCond)))
val invariantPrecondition: Option[Expr] = wh.invariant.map(expr => replace(modifiedVars2WhileFunVars, expr)) val invariantPrecondition: Option[Expr] = wh.invariant.map(expr => replace(modifiedVars2WhileFunVars, expr))
val invariantPostcondition: Option[Expr] = wh.invariant.map(expr => replace(modifiedVars2ResultVars, expr))
whileFunDef.precondition = invariantPrecondition whileFunDef.precondition = invariantPrecondition
whileFunDef.postcondition = trivialPostcondition.map(expr => whileFunDef.postcondition = trivialPostcondition.map(expr =>
And(expr, invariantPrecondition match { And(expr, invariantPostcondition match {
case Some(e) => replace(modifiedVars2ResultVars, e) case Some(e) => e
case None => BooleanLiteral(true) case None => BooleanLiteral(true)
})) }))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment