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

Changelist:

1. Added isUnsat to Extensions.scala
2. Added a few more conditions to BinarySearchTree.scala
3. Made calls to underlying solvers (involving double negation, etc) from the unifier
4. Fixed a minor bug in Expression Parsing in Main.scala

parent 9ff7ddd1
Branches
Tags
No related merge requests found
...@@ -208,7 +208,7 @@ object ExprToASTConverter { ...@@ -208,7 +208,7 @@ object ExprToASTConverter {
formulaRelaxed = false; formulaRelaxed = false;
expr match { expr match {
case And(exprs) => AST.And((exprs map toRelaxedFormula).toList) case And(exprs) => AST.And((exprs map toRelaxedFormula).toList)
case _ => toFormula(expr) case _ => toRelaxedFormula(expr)
} }
} }
......
...@@ -50,14 +50,9 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -50,14 +50,9 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
val (varMap, restFormula) = solve(conjunction) val (varMap, restFormula) = solve(conjunction)
// TODO: Might contain multiple c_i ~= {} for a fixed i // TODO: Might contain multiple c_i ~= {} for a fixed i
val noAlphas = And(restFormula flatMap expandAlphas(varMap)) val noAlphas = And(restFormula flatMap expandAlphas(varMap))
//reporter.info("The resulting formula is\n" + rpp(noAlphas)) reporter.info("The resulting formula is\n" + rpp(noAlphas))
// OrdBAPA finds the formula satisfiable tryAllSolvers(noAlphas)
if ((new Main(reporter)).solve(ExprToASTConverter(noAlphas))) { } catch {
throw (new SatException(null))
} else {
reporter.info("Conjunction " + counter + " is UNSAT, proved by BAPA<")
}
} catch {
case ex@ConversionException(badExpr, msg) => case ex@ConversionException(badExpr, msg) =>
reporter.info("Conjunction " + counter + " is UNKNOWN, could not be parsed") reporter.info("Conjunction " + counter + " is UNKNOWN, could not be parsed")
throw ex throw ex
...@@ -68,7 +63,7 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -68,7 +63,7 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
case UnificationImpossible(msg) => case UnificationImpossible(msg) =>
reporter.info("Conjunction " + counter + " is UNSAT, proved by Unifier") // (" + msg + ")") reporter.info("Conjunction " + counter + " is UNSAT, proved by Unifier") // (" + msg + ")")
case ex@SatException(_) => case ex@SatException(_) =>
reporter.info("Conjunction " + counter + " is SAT, proved by BAPA<") reporter.info("Conjunction " + counter + " is SAT")
throw ex throw ex
} }
} }
...@@ -93,6 +88,21 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -93,6 +88,21 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
} }
} }
def tryAllSolvers(f : Expr): Unit = {
for(solver <- Extensions.loadedSolverExtensions; if solver != this) {
reporter.info("Trying solver: " + solver.shortDescription + " from inside the unifier.")
solver.isUnsat(f) match {
case Some(true) =>
reporter.info("Solver: " + solver.shortDescription + " proved the formula unsatisfiable")
return
case Some(false) =>
reporter.warning("Solver: " + solver.shortDescription + " proved the formula satisfiable")
throw (new SatException(null))
case None =>
reporter.info("Solver: " + solver.shortDescription + " was unable to conclusively determine the correctness of the formula")
}
}; throw IncompleteException("All the solvers were unable to prove the formula unsatisfiable, giving up.") }
def checkIsSupported(expr: Expr) { def checkIsSupported(expr: Expr) {
def check(ex: Expr): Option[Expr] = ex match { def check(ex: Expr): Option[Expr] = ex match {
case Let(_, _, _) | MatchExpr(_, _) => case Let(_, _, _) | MatchExpr(_, _) =>
...@@ -229,7 +239,7 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) { ...@@ -229,7 +239,7 @@ class UnifierMain(reporter: Reporter) extends Solver(reporter) {
//reporter.warning("Result:\n" + rpp(res)) //reporter.warning("Result:\n" + rpp(res))
Some(res) Some(res)
} }
case _ => error("Bad argument/substitution to catamorphism") case _ => error("Bad argument/substitution to catamorphism: " + substArg(arg))
} }
case None => // Not a catamorphism case None => // Not a catamorphism
warning("Function " + fd.id + " is not a catamorphism.") warning("Function " + fd.id + " is not a catamorphism.")
......
...@@ -19,7 +19,7 @@ object Extensions { ...@@ -19,7 +19,7 @@ object Extensions {
// None if unknown. // None if unknown.
def solve(expression: Expr) : Option[Boolean] def solve(expression: Expr) : Option[Boolean]
def isSat(expression: Expr) : Option[Boolean] = solve(expression).map(!_) def isUnsat(expression: Expr) : Option[Boolean] = solve(negate(expression))
} }
abstract class Analyser(reporter: Reporter) extends Extension(reporter) { abstract class Analyser(reporter: Reporter) extends Extension(reporter) {
......
...@@ -57,22 +57,24 @@ object BinarySearchTree { ...@@ -57,22 +57,24 @@ object BinarySearchTree {
} }
def treeMin(tree: Node): Int = tree match { def treeMin(tree: Node): Int = {
require(isSorted(tree).sorted)
tree match {
case Node(left, v, _) => left match { case Node(left, v, _) => left match {
case Leaf() => v case Leaf() => v
case n@Node(_, _, _) => treeMin(n) case n@Node(_, _, _) => treeMin(n)
} }
} }} ensuring (_ == contents(tree).min)
def treeMax(tree: Node): Int = { def treeMax(tree: Node): Int = {
// requires(isSorted(tree)) require(isSorted(tree).sorted)
tree match { tree match {
case Node(_, v, right) => right match { case Node(_, v, right) => right match {
case Leaf() => v case Leaf() => v
case n@Node(_, _, _) => treeMax(n) case n@Node(_, _, _) => treeMax(n)
} }
} }
} //ensuring (_ == contents(tree).max) } ensuring (_ == contents(tree).max)
def insert(tree: Tree, value: Int): Node = { def insert(tree: Tree, value: Int): Node = {
require(isSorted(tree).sorted) require(isSorted(tree).sorted)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment