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

optimization that does not introduce variables when the modulo is smaller than B - A

parent acd77b90
Branches
Tags
No related merge requests found
...@@ -43,6 +43,7 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities ...@@ -43,6 +43,7 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
val otherVars: List[Identifier] = problem.xs.filterNot(_ == processedVar) val otherVars: List[Identifier] = problem.xs.filterNot(_ == processedVar)
val normalizedLhs: List[List[Expr]] = lhsSides.map(linearArithmeticForm(_, Array(processedVar)).toList) val normalizedLhs: List[List[Expr]] = lhsSides.map(linearArithmeticForm(_, Array(processedVar)).toList)
var upperBounds: List[(Expr, Int)] = Nil // (t, c) means c*x <= t var upperBounds: List[(Expr, Int)] = Nil // (t, c) means c*x <= t
var lowerBounds: List[(Expr, Int)] = Nil // (t, c) means t <= c*x var lowerBounds: List[(Expr, Int)] = Nil // (t, c) means t <= c*x
...@@ -54,15 +55,30 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities ...@@ -54,15 +55,30 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
case err => sys.error("unexpected from normal form: " + err) case err => sys.error("unexpected from normal form: " + err)
} }
//optimization when coef = 1 val L = if(upperBounds.isEmpty && lowerBounds.isEmpty) -1 else lcm((upperBounds ::: lowerBounds).map(_._2))
println("LCM: " + L)
//optimization when coef = 1 and when ub - lb is a constant greater than LCM
upperBounds = upperBounds.filterNot{case (ub, uc) => if(uc == 1) { upperBounds = upperBounds.filterNot{case (ub, uc) => if(uc == 1) {
exprNotUsed ++= lowerBounds.map{case (lb, lc) => LessEquals(lb, Times(IntLiteral(lc), ub))} exprNotUsed ++= lowerBounds.map{case (lb, lc) => LessEquals(lb, Times(IntLiteral(lc), ub))}
true true
} else false } } else
false
}
lowerBounds = lowerBounds.filterNot{case (lb, lc) => if(lc == 1) { lowerBounds = lowerBounds.filterNot{case (lb, lc) => if(lc == 1) {
exprNotUsed ++= upperBounds.map{case (ub, uc) => LessEquals(Times(IntLiteral(uc), lb), ub)} exprNotUsed ++= upperBounds.map{case (ub, uc) => LessEquals(Times(IntLiteral(uc), lb), ub)}
true true
} else false } } else
false
}
upperBounds = upperBounds.filterNot{case (ub, uc) => {
lowerBounds.forall{case (lb, lc) => {
println(simplifyArithmetic(Minus(ub, lb)))
simplifyArithmetic(Minus(ub, lb)) match {
case IntLiteral(n) => println("found N: " + n); L - 1 <= n
case _ => false
}}}
}}
println("lowerBounds: " + lowerBounds) println("lowerBounds: " + lowerBounds)
println("upperBounds: " + upperBounds) println("upperBounds: " + upperBounds)
...@@ -142,7 +158,6 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities ...@@ -142,7 +158,6 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
val remainderIds: List[Identifier] = upperBounds.map(_ => FreshIdentifier("k", true).setType(Int32Type)) val remainderIds: List[Identifier] = upperBounds.map(_ => FreshIdentifier("k", true).setType(Int32Type))
val quotientIds: List[Identifier] = lowerBounds.map(_ => FreshIdentifier("l", true).setType(Int32Type)) val quotientIds: List[Identifier] = lowerBounds.map(_ => FreshIdentifier("l", true).setType(Int32Type))
val L = if(remainderIds.isEmpty) -1 else lcm((upperBounds ::: lowerBounds).map(_._2))
val newUpperBounds: List[Expr] = upperBounds.map{case (bound, coef) => Times(IntLiteral(L/coef), bound)} val newUpperBounds: List[Expr] = upperBounds.map{case (bound, coef) => Times(IntLiteral(L/coef), bound)}
val newLowerBounds: List[Expr] = lowerBounds.map{case (bound, coef) => Times(IntLiteral(L/coef), bound)} val newLowerBounds: List[Expr] = lowerBounds.map{case (bound, coef) => Times(IntLiteral(L/coef), bound)}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment