Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,28 @@ lazy val smtParser = (project in file("smt-parser")).
).
disablePlugins(AssemblyPlugin)

lazy val core = (project in file("core")).
settings(commonSettings: _*).
settings(
name := "Princess-core",
libraryDependencies +=
"org.scalacheck" %% "scalacheck" % "1.15.2" % Test,
Compile / scalacOptions ++=
List("-feature",
"-language:implicitConversions,postfixOps,reflectiveCalls"),
scalacOptions += (scalaVersion map { sv => sv match {
case "2.11.12" => "-optimise"
case "2.12.20" => "-opt:_"
}}).value
).
disablePlugins(AssemblyPlugin)

// Actual project

lazy val root = (project in file(".")).
enablePlugins(NativeImagePlugin).
aggregate(parser, smtParser).
dependsOn(parser, smtParser).
aggregate(core, parser, smtParser).
dependsOn(core, parser, smtParser).
settings(commonSettings: _*).
//
settings(
Expand Down Expand Up @@ -129,4 +145,3 @@ lazy val root = (project in file(".")).

nativeImageAgentMerge := true
)

File renamed without changes.
23 changes: 23 additions & 0 deletions core/src/main/scala/ap/core/ImplicationChecker.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ap.core

import ap.PresburgerTools
import ap.parser.{IFormula, IExpression, SymbolCollector, InputAbsy2Internal, IBoolLit}
import ap.terfor.TermOrder
import ap.terfor.conjunctions.Conjunction

object ImplicationChecker {

import IExpression._

def implies(assumptions : Seq[IFormula], conclusion : IFormula) : Boolean = {
val premise = assumptions.foldLeft[IFormula](IBoolLit(true))(_ & _)
isValid(premise ==> conclusion)
}

def isValid(formula : IFormula) : Boolean = {
val order =
TermOrder.EMPTY.extend(SymbolCollector.constantsSorted(formula))
val internal = InputAbsy2Internal(formula, order)
PresburgerTools.isValid(Conjunction.conj(internal, order))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import java.io.PrintStream
object SMTLineariser {

import SMTTypes._
import SMTParser2InputAbsy.SMTFunctionType
import SMTSupport.SMTFunctionType

private val AC = Debug.AC_PARSER

Expand Down Expand Up @@ -631,9 +631,9 @@ object SMTLineariser {
constantType :
ConstantTerm => Option[SMTTypes.SMTType],
functionType :
IFunction => Option[SMTParser2InputAbsy.SMTFunctionType],
IFunction => Option[SMTSupport.SMTFunctionType],
predType :
Predicate => Option[SMTParser2InputAbsy.SMTFunctionType],
Predicate => Option[SMTSupport.SMTFunctionType],
prettyBitvectors : Boolean = true) : Unit =
formula match {
case IBoolLit(value) => print(value)
Expand Down Expand Up @@ -671,11 +671,21 @@ object SMTLineariser {
case t : ITerm => asString(t)
}

private def captureString(comp : => Unit) : String = {
val out = new java.io.ByteArrayOutputStream
val ps = new java.io.PrintStream(out)
Console.withOut(ps) {
comp
}
ps.flush()
out.toString("UTF-8")
}

def asString(formula : IFormula) : String =
ap.DialogUtil.asString { apply(formula) }
captureString { apply(formula) }

def asString(t : ITerm) : String =
ap.DialogUtil.asString { apply(t) }
captureString { apply(t) }

//////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -946,9 +956,9 @@ class SMTLineariser(benchmarkName : String,
constantType :
ConstantTerm => Option[SMTTypes.SMTType],
functionType :
IFunction => Option[SMTParser2InputAbsy.SMTFunctionType],
IFunction => Option[SMTSupport.SMTFunctionType],
predType :
Predicate => Option[SMTParser2InputAbsy.SMTFunctionType],
Predicate => Option[SMTSupport.SMTFunctionType],
prettyBitvectors : Boolean = true) {

import SMTTypes._
Expand Down Expand Up @@ -1065,7 +1075,7 @@ class SMTLineariser(benchmarkName : String,

//////////////////////////////////////////////////////////////////////////////

import SMTParser2InputAbsy.SMTFunctionType
import SMTSupport.SMTFunctionType

private def getTermType(t : ITerm)
(implicit variableType : Int => Option[SMTType])
Expand Down Expand Up @@ -1484,4 +1494,3 @@ class SMTLineariser(benchmarkName : String,
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
package ap.parser

import ap.theories.Theory
import ap.parser.smtlib.Absyn.{Sort => SSort, SymbolRef}
import ap.types.Sort

/**
Expand Down Expand Up @@ -89,18 +88,21 @@ trait SMTParseableTheory {

import SMTTypes.SMTType

type SMTSortAST = Any
type SMTSymbolRefAST = Any

/**
* Translate a sort AST.
*/
def translateSMTSortAST(s : SSort) : Option[SMTType] = None
def translateSMTSortAST(s : SMTSortAST) : Option[SMTType] = None

/**
* Translate the application of a function or predicate. The
* arguments can be translated recursively, given their polarity as
* argument.
*/
def translateSMTOperatorAST(
sym : SymbolRef,
sym : SMTSymbolRefAST,
arguments : Seq[(Int) => (IExpression, SMTType)],
polarity : Int)
: Option[(IExpression, SMTType)] = None
Expand Down
21 changes: 21 additions & 0 deletions core/src/main/scala/ap/parser/SMTSupport.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Shared SMT helper types that are independent from concrete frontends.
*/
package ap.parser

object SMTSupport {

import IExpression.{Sort => TSort}
import SMTTypes._

def toNormalBool(s : TSort) : TSort = s match {
case TSort.MultipleValueBool => TSort.Bool
case other => other
}

case class SMTFunctionType(arguments : List[SMTType],
result : SMTType)

val SMTBoolVariableType : SMTFunctionType =
SMTFunctionType(List(), SMTBool)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
package ap.parser;

import ap.basetypes.IdealInt
import ap.DialogUtil
import ap.types.Sort
import ap.theories.{ADT, ModuloArithmetic, TheoryRegistry}
import ap.theories.sequences.SeqTheory
Expand All @@ -53,7 +52,17 @@ object SMTTypes {

private val AC = Debug.AC_PARSER

import SMTParser2InputAbsy.toNormalBool
import SMTSupport.toNormalBool

private def asString(comp : => Unit) : String = {
val out = new java.io.ByteArrayOutputStream
val ps = new java.io.PrintStream(out)
Console.withOut(ps) {
comp
}
ps.flush()
out.toString("UTF-8")
}

abstract class SMTType {
def toSort : Sort
Expand All @@ -80,7 +89,7 @@ object SMTTypes {
val theory = ExtArray(arguments map { t => toNormalBool(t.toSort) },
toNormalBool(result.toSort))
def toSort = theory.sort
def toSMTLIBString = DialogUtil asString {
def toSMTLIBString = asString {
print("(Array")
for (s <- arguments) {
print(" ")
Expand Down Expand Up @@ -190,7 +199,7 @@ object SMTTypes {
elementType : SMTType) extends SMTType {
def toSort = theory.sort
override def toString = theory.toString
def toSMTLIBString = DialogUtil asString {
def toSMTLIBString = asString {
print("(Seq ")
print(elementType.toSMTLIBString)
print(")")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ abstract class ConstraintSimplifier {

class SimpleSimplifier(lemmas : Boolean, ground2DNF : Boolean, output : Boolean)
extends ConstraintSimplifier {

private val NullStream =
new java.io.PrintStream(new java.io.OutputStream {
def write(b : Int) : Unit = ()
})

private lazy val posProver =
new ExhaustiveProver(false,
Expand Down Expand Up @@ -155,10 +160,10 @@ class SimpleSimplifier(lemmas : Boolean, ground2DNF : Boolean, output : Boolean)
private def simplify(f : Conjunction, order : TermOrder) : Conjunction =
Timeout.unfinishedValue(None) {
println("Simplify: " + f + " (positive)")
val res = if (lemmas) Console.withOut(ap.CmdlMain.NullStream) {
val res = if (lemmas) Console.withOut(NullStream) {
QuantifierElimProver(f, false, order)
} else {
val tree = Console.withOut(ap.CmdlMain.NullStream) { posProver(f, order) }
val tree = Console.withOut(NullStream) { posProver(f, order) }
TestProofTree.assertNormalisedTree(tree)
tree.closingConstraint
}
Expand All @@ -169,10 +174,10 @@ class SimpleSimplifier(lemmas : Boolean, ground2DNF : Boolean, output : Boolean)
private def negSimplify(f : Conjunction, order : TermOrder) : Conjunction =
Timeout.unfinishedValue(None) {
println("Simplify: " + f + " (negative)")
val res = if (lemmas) Console.withOut(ap.CmdlMain.NullStream) {
val res = if (lemmas) Console.withOut(NullStream) {
QuantifierElimProver(f.negate, ground2DNF, order).negate
} else {
val tree = Console.withOut(ap.CmdlMain.NullStream) { negProver(f.negate, order) }
val tree = Console.withOut(NullStream) { negProver(f.negate, order) }
TestProofTree.assertNormalisedTree(tree)
tree.closingConstraint.negate
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,53 +326,9 @@ class ModelSearchProver(defaultSettings : GoalSettings) {
//////////////////////////////////////////////////////////////////////////////

private def verifyCertificate(cert : Certificate,
disjuncts : Seq[Conjunction]) : Boolean = {

// verify assumptions
(cert.assumedFormulas subsetOf
(for (d <- disjuncts.iterator) yield CertFormula(d.negate)).toSet) &&
//
// verify theory axioms
(true || SimpleAPI.withProver { p =>
import p._

def traverse(c : Certificate) : Boolean =
(c match {
case BranchInferenceCertificate(inferences, _, order) =>
inferences forall {
case TheoryAxiomInference(axiom, GroebnerMultiplication) =>
scope {
Console.err.println("Verifying: " + axiom)
addTheory(GroebnerMultiplication)
addConclusion(axiom.toConj)

try {
withTimeout(3000) {
??? match {
case SimpleAPI.ProverStatus.Valid =>
true
case _ =>
Console.err.println("FAILED")
true
}
}
} catch {
case SimpleAPI.TimeoutException =>
Console.err.println("T/O")
true
}
}
case _ =>
true
}
case _ =>
true
}) &&
(c.subCertificates forall (traverse _))

traverse(cert)
})
}
disjuncts : Seq[Conjunction]) : Boolean =
cert.assumedFormulas subsetOf
(for (d <- disjuncts.iterator) yield CertFormula(d.negate)).toSet

//////////////////////////////////////////////////////////////////////////////

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ import ap.terfor.conjunctions.{Conjunction, ReduceWithConjunction,
import ap.terfor.{TermOrder, TerForConvenience, Formula, OneTerm, Term}
import ap.terfor.preds.Atom
import ap.terfor.substitutions.{VariableShiftSubst, VariableSubst}
import ap.{SimpleAPI, PresburgerTools}
import SimpleAPI.ProverStatus
import ap.PresburgerTools
import ap.types.{Sort, ProxySort, MonoSortedIFunction, SortedPredicate,
SortedConstantTerm, MonoSortedPredicate}
import ap.proof.theoryPlugins.Plugin
Expand Down
Loading