Skip to content
Snippets Groups Projects
Commit 4128518c authored by Manos Koukoutos's avatar Manos Koukoutos
Browse files

Filter tests in EqSplit

parent b5717ddb
Branches
Tags
No related merge requests found
...@@ -61,7 +61,7 @@ case class TestBank(valids: Seq[Example], invalids: Seq[Example]) { ...@@ -61,7 +61,7 @@ case class TestBank(valids: Seq[Example], invalids: Seq[Example]) {
def mapIns(f: Seq[Expr] => List[Seq[Expr]]) = { def mapIns(f: Seq[Expr] => List[Seq[Expr]]) = {
map { map {
case InExample(in) => case InExample(in) =>
f(in).map(InExample(_)) f(in).map(InExample)
case InOutExample(in, out) => case InOutExample(in, out) =>
f(in).map(InOutExample(_, out)) f(in).map(InOutExample(_, out))
...@@ -155,17 +155,19 @@ case class ProblemTestBank(p: Problem, tb: TestBank)(implicit hctx: SearchContex ...@@ -155,17 +155,19 @@ case class ProblemTestBank(p: Problem, tb: TestBank)(implicit hctx: SearchContex
tb mapIns { in => List(toKeep.map(in)) } tb mapIns { in => List(toKeep.map(in)) }
} }
def filterIns(expr: Expr) = { def filterIns(expr: Expr): TestBank = {
val ev = new DefaultEvaluator(hctx.sctx.context, hctx.sctx.program) val ev = new DefaultEvaluator(hctx.sctx.context, hctx.sctx.program)
filterIns(m => ev.eval(expr, m).result == Some(BooleanLiteral(true)))
}
def filterIns(pred: Map[Identifier, Expr] => Boolean): TestBank = {
tb mapIns { in => tb mapIns { in =>
val m = (p.as zip in).toMap val m = (p.as zip in).toMap
if(pred(m)) {
ev.eval(expr, m) match { List(in)
case EvaluationResults.Successful(BooleanLiteral(true)) => } else {
List(in) Nil
case _ =>
Nil
} }
} }
} }
......
...@@ -4,6 +4,7 @@ package leon ...@@ -4,6 +4,7 @@ package leon
package synthesis package synthesis
package rules package rules
import leon.purescala.Common.Identifier
import purescala.Expressions._ import purescala.Expressions._
import purescala.Constructors._ import purescala.Constructors._
...@@ -40,8 +41,14 @@ case object EqualitySplit extends Rule("Eq. Split") { ...@@ -40,8 +41,14 @@ case object EqualitySplit extends Rule("Eq. Split") {
candidates.flatMap { candidates.flatMap {
case List(a1, a2) => case List(a1, a2) =>
val sub1 = p.copy(pc = and(Equals(Variable(a1), Variable(a2)), p.pc)) val sub1 = p.copy(
val sub2 = p.copy(pc = and(not(Equals(Variable(a1), Variable(a2))), p.pc)) pc = and(Equals(Variable(a1), Variable(a2)), p.pc),
tb = p.tbOps.filterIns( (m: Map[Identifier, Expr]) => m(a1) == m(a2))
)
val sub2 = p.copy(
pc = and(not(Equals(Variable(a1), Variable(a2))), p.pc),
tb = p.tbOps.filterIns( (m: Map[Identifier, Expr]) => m(a1) != m(a2))
)
val onSuccess: List[Solution] => Option[Solution] = { val onSuccess: List[Solution] => Option[Solution] = {
case List(s1, s2) => case List(s1, s2) =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment