Skip to content
Snippets Groups Projects
Commit ac1cabcc authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Attach preconditions

parent 1ae8d9ec
Branches
Tags
No related merge requests found
...@@ -46,7 +46,15 @@ class IntInduction(synth: Synthesizer) extends Rule("Int Induction", synth, 80) ...@@ -46,7 +46,15 @@ class IntInduction(synth: Synthesizer) extends Rule("Int Induction", synth, 80)
val onSuccess: List[Solution] => Solution = { val onSuccess: List[Solution] => Solution = {
case List(base, gt, lt) => case List(base, gt, lt) =>
val preIn = Or(Seq(And(Equals(Variable(inductOn), IntLiteral(0)), base.pre),
And(GreaterThan(Variable(inductOn), IntLiteral(0)), gt.pre),
And(LessThan(Variable(inductOn), IntLiteral(0)), lt.pre)))
val preOut = subst(inductOn -> Variable(origId), preIn)
val newFun = new FunDef(FreshIdentifier("rec", true), tpe, Seq(VarDecl(inductOn, inductOn.getType))) val newFun = new FunDef(FreshIdentifier("rec", true), tpe, Seq(VarDecl(inductOn, inductOn.getType)))
newFun.precondition = Some(preIn)
newFun.body = Some( newFun.body = Some(
IfExpr(Equals(Variable(inductOn), IntLiteral(0)), IfExpr(Equals(Variable(inductOn), IntLiteral(0)),
base.toExpr, base.toExpr,
...@@ -55,13 +63,8 @@ class IntInduction(synth: Synthesizer) extends Rule("Int Induction", synth, 80) ...@@ -55,13 +63,8 @@ class IntInduction(synth: Synthesizer) extends Rule("Int Induction", synth, 80)
, LetTuple(postXs, FunctionInvocation(newFun, Seq(Plus(Variable(inductOn), IntLiteral(1)))), lt.toExpr))) , LetTuple(postXs, FunctionInvocation(newFun, Seq(Plus(Variable(inductOn), IntLiteral(1)))), lt.toExpr)))
) )
val pre =
subst( inductOn -> Variable(origId),
Or(Seq(And(Equals(Variable(inductOn), IntLiteral(0)), base.pre),
And(GreaterThan(Variable(inductOn), IntLiteral(0)), gt.pre),
And(LessThan(Variable(inductOn), IntLiteral(0)), lt.pre))))
Solution(pre, LetDef(newFun, FunctionInvocation(newFun, Seq(Variable(origId))))) Solution(preOut, LetDef(newFun, FunctionInvocation(newFun, Seq(Variable(origId)))))
case _ => case _ =>
Solution.none Solution.none
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment