Skip to content
Snippets Groups Projects
Commit 5233f3ee authored by Utkarsh Upadhyay's avatar Utkarsh Upadhyay
Browse files

Fixed a bug which created different Fresh Variables Collxx for the same...

Fixed a bug which created different Fresh Variables Collxx for the same \alpha(txx). Unification seems to be working.


parent 8c2f4243
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,8 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -23,6 +23,8 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
var program:Program = null var program:Program = null
override def setProgram(p: Program) = program = p override def setProgram(p: Program) = program = p
var freshVarMap = Map.empty[Variable, Variable]
// checks for V-A-L-I-D-I-T-Y ! // checks for V-A-L-I-D-I-T-Y !
// Some(true) means formula is valid (negation is unsat) // Some(true) means formula is valid (negation is unsat)
// Some(false) means formula is not valid (negation is sat) // Some(false) means formula is not valid (negation is sat)
...@@ -33,6 +35,8 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -33,6 +35,8 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
try { try {
var counter = 0 var counter = 0
for (conjunction <- dnf(negate(expr))) { for (conjunction <- dnf(negate(expr))) {
// Refresh the Coll_i for each conjunct
freshVarMap = Map.empty
counter += 1 counter += 1
reporter.info("Solving conjunction " + counter) reporter.info("Solving conjunction " + counter)
//conjunction foreach println //conjunction foreach println
...@@ -46,16 +50,8 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -46,16 +50,8 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
// TODO: Might contain multiple c_i ~= {} for a fixed i // TODO: Might contain multiple c_i ~= {} for a fixed i
val noAlphas = restFormula flatMap expandAlphas(varMap) val noAlphas = restFormula flatMap expandAlphas(varMap)
reporter.info("The resulting formula is " + noAlphas) reporter.info("The resulting formula is " + noAlphas)
// Extracting only the needed equalities Fe (to avoid unnecessary relaxations)
// Assuming that all the inequalities which did not involve TermAlgebra are already
// in restFormula
val usefulEqns = substTable.filter(x => ExprToASTConverter.isAcceptableType(x._1.getType)).map(x => ExprToASTConverter.makeEq(x._1, x._2))
reporter.info("The useful equations are: " + substTable)
reporter.info("The tree equations are: " + treeEquations)
// OrdBAPA finds the formula satisfiable // OrdBAPA finds the formula satisfiable
if((new Main(reporter)).solve(ExprToASTConverter(And(noAlphas.toList ++ usefulEqns.toList ++ treeEquations.toList)))) { if((new Main(reporter)).solve(ExprToASTConverter(And(noAlphas.toList)))) {
throw(new SatException(null)) throw(new SatException(null))
} }
} catch { } catch {
...@@ -86,6 +82,12 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -86,6 +82,12 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
} }
} }
def getVars(t: Expr) = {
var varNames = Set.empty[String]
searchAndReplace({ case Variable(id) => varNames += id.uniqueName; None; case _ => None })(t)
varNames
}
def isAlpha(varMap: Variable => Expr)(t: Expr): Option[Expr] = t match { def isAlpha(varMap: Variable => Expr)(t: Expr): Option[Expr] = t match {
case FunctionInvocation(fd, arg) => asCatamorphism(program, fd) match { case FunctionInvocation(fd, arg) => asCatamorphism(program, fd) match {
case None => None case None => None
...@@ -99,9 +101,13 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -99,9 +101,13 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
Some(repRHS) Some(repRHS)
} }
case u @ Variable(_) => { case u @ Variable(_) => {
val c = Variable(FreshIdentifier("Coll", true)).setType(t.getType) if(freshVarMap.contains(u)) Some(freshVarMap(u))
// TODO: Keep track of these variables for M1(t, c) else {
Some(c) val c = Variable(FreshIdentifier("Coll", true)).setType(t.getType)
// TODO: Keep track of these variables for M1(t, c)
freshVarMap += (u -> c)
Some(c)
}
} }
case _ => error("Bad substitution") case _ => error("Bad substitution")
} }
...@@ -115,12 +121,6 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -115,12 +121,6 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
case _ => None case _ => None
} }
def getVars(t: Expr) = {
var varNames = Set.empty[String]
searchAndReplace({ case Variable(id) => varNames += id.uniqueName; None; case _ => None })(t)
varNames
}
def expandAlphas(varMap: Variable => Expr)(e: Expr) : Seq[Expr] = { def expandAlphas(varMap: Variable => Expr)(e: Expr) : Seq[Expr] = {
val partiallyEvaluated = searchAndReplace(isAlpha(varMap))(e) val partiallyEvaluated = searchAndReplace(isAlpha(varMap))(e)
if(partiallyEvaluated == e) { if(partiallyEvaluated == e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment