Search in sources :

Example 1 with ProverEnvironment

use of org.sosy_lab.java_smt.api.ProverEnvironment in project java-smt by sosy-lab.

the class AllSatExample method main.

public static void main(String... args) throws InvalidConfigurationException, SolverException, InterruptedException {
    Configuration config = Configuration.defaultConfiguration();
    LogManager logger = BasicLogManager.create(config);
    ShutdownNotifier notifier = ShutdownNotifier.createDummy();
    for (Solvers solver : Solvers.values()) {
        try (SolverContext context = SolverContextFactory.createSolverContext(config, logger, notifier, solver);
            ProverEnvironment prover = context.newProverEnvironment(ProverOptions.GENERATE_MODELS, ProverOptions.GENERATE_ALL_SAT)) {
            logger.log(Level.WARNING, "Using solver " + solver + " in version " + context.getVersion());
            AllSatExample ase = new AllSatExample(context, prover);
            prover.push();
            logger.log(Level.INFO, ase.allSatBooleans1());
            prover.pop();
            prover.push();
            logger.log(Level.INFO, ase.allSatBooleans2());
            prover.pop();
            if (SOLVERS_WITH_INTEGERS.contains(solver)) {
                prover.push();
                logger.log(Level.INFO, ase.allSatIntegers());
                prover.pop();
                prover.push();
                logger.log(Level.INFO, ase.allSatIntegers2());
                prover.pop();
            }
            if (SOLVERS_WITH_BITVECTORS.contains(solver)) {
                prover.push();
                logger.log(Level.INFO, ase.allSatBitvectors());
                prover.pop();
            }
        } catch (InvalidConfigurationException | UnsatisfiedLinkError e) {
            // on some machines we support only some solvers,
            // thus we can ignore these errors.
            logger.logUserException(Level.INFO, e, "Solver " + solver + " is not available.");
        } catch (UnsupportedOperationException e) {
            logger.logUserException(Level.INFO, e, e.getMessage());
        }
    }
}
Also used : ShutdownNotifier(org.sosy_lab.common.ShutdownNotifier) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Configuration(org.sosy_lab.common.configuration.Configuration) Solvers(org.sosy_lab.java_smt.SolverContextFactory.Solvers) LogManager(org.sosy_lab.common.log.LogManager) BasicLogManager(org.sosy_lab.common.log.BasicLogManager) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException)

Example 2 with ProverEnvironment

use of org.sosy_lab.java_smt.api.ProverEnvironment in project java-smt by sosy-lab.

the class BoolectorNativeApiTest method satSolverBackendTest.

/**
 * For each available solver, we build a context and solver a small formula.
 *
 * <p>This should be sufficient to test whether the sat-solver can be loaded.
 */
@Test
public void satSolverBackendTest() throws InvalidConfigurationException, InterruptedException, SolverException {
    for (SatSolver satsolver : BoolectorSolverContext.SatSolver.values()) {
        ConfigurationBuilder config = Configuration.builder().setOption("solver.boolector.satSolver", satsolver.name());
        try (BoolectorSolverContext context = BoolectorSolverContext.create(config.build(), ShutdownNotifier.createDummy(), null, 1, NativeLibraries::loadLibrary)) {
            BooleanFormulaManager bfmgr = context.getFormulaManager().getBooleanFormulaManager();
            BooleanFormula fa = bfmgr.makeVariable("a");
            BooleanFormula fb = bfmgr.makeVariable("b");
            BooleanFormula fc = bfmgr.makeVariable("c");
            BooleanFormula f1 = bfmgr.or(fa, fb, fc);
            BooleanFormula f2 = bfmgr.and(fa, fb, fc);
            try (ProverEnvironment prover = context.newProverEnvironment()) {
                prover.addConstraint(bfmgr.equivalence(f1, f2));
                assertThat(prover.isUnsat()).isFalse();
            }
        }
    }
}
Also used : ConfigurationBuilder(org.sosy_lab.common.configuration.ConfigurationBuilder) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) NativeLibraries(org.sosy_lab.common.NativeLibraries) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) SatSolver(org.sosy_lab.java_smt.solvers.boolector.BoolectorSolverContext.SatSolver) Test(org.junit.Test)

Example 3 with ProverEnvironment

use of org.sosy_lab.java_smt.api.ProverEnvironment in project java-smt by sosy-lab.

the class BoolectorNativeApiTest method dumpVariableWithAssertionsOnStackTest.

@Test
public void dumpVariableWithAssertionsOnStackTest() throws InvalidConfigurationException, InterruptedException {
    ConfigurationBuilder config = Configuration.builder();
    try (BoolectorSolverContext context = BoolectorSolverContext.create(config.build(), ShutdownNotifier.createDummy(), null, 1, NativeLibraries::loadLibrary)) {
        FormulaManager mgr = context.getFormulaManager();
        BooleanFormulaManager bfmgr = mgr.getBooleanFormulaManager();
        try (ProverEnvironment prover = context.newProverEnvironment()) {
            prover.push(bfmgr.makeVariable("x"));
            for (String name : ImmutableList.of("a", "a", "b", "abc", "ABC")) {
                BooleanFormula f = bfmgr.makeVariable(name);
                String s = mgr.dumpFormula(f).toString();
                // TODO why is there a prefix "BTOR_2@"?
                // Possible reason: we are on the second level of the solver stack.
                // - first level comes from the constructor of ReusableStackTheoremProver.
                // - second level comes from the PUSH above.
                // We do actually not want to have such names in the dump.
                assertThat(s).contains(String.format("(declare-fun BTOR_2@%s () (_ BitVec 1))", name));
            // assertThat(s).contains(String.format("(assert "));
            }
        }
    }
}
Also used : ConfigurationBuilder(org.sosy_lab.common.configuration.ConfigurationBuilder) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) FormulaManager(org.sosy_lab.java_smt.api.FormulaManager) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) NativeLibraries(org.sosy_lab.common.NativeLibraries) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 4 with ProverEnvironment

use of org.sosy_lab.java_smt.api.ProverEnvironment in project java-smt by sosy-lab.

the class BooleanFormulaSubject method checkIsUnsat.

private void checkIsUnsat(final BooleanFormula subject, final Fact expected) throws SolverException, InterruptedException {
    try (ProverEnvironment prover = context.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        prover.push(subject);
        if (prover.isUnsat()) {
            // success
            return;
        }
        // get model for failure message
        try (Model model = prover.getModel()) {
            List<Fact> facts = new ArrayList<>();
            facts.add(Fact.fact("but was", formulaUnderTest));
            if (!subject.equals(formulaUnderTest)) {
                facts.add(Fact.fact("checked formula was", subject));
            }
            facts.add(Fact.fact("which has model", model));
            failWithoutActual(expected, facts.toArray(new Fact[0]));
        }
    }
}
Also used : Model(org.sosy_lab.java_smt.api.Model) ArrayList(java.util.ArrayList) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) Fact(com.google.common.truth.Fact)

Example 5 with ProverEnvironment

use of org.sosy_lab.java_smt.api.ProverEnvironment in project java-smt by sosy-lab.

the class SolverTheoriesTest method multiplicationSquares.

@Test
public void multiplicationSquares() throws SolverException, InterruptedException {
    requireIntegers();
    IntegerFormula i2 = imgr.makeNumber(2);
    IntegerFormula i3 = imgr.makeNumber(3);
    IntegerFormula i4 = imgr.makeNumber(4);
    IntegerFormula i5 = imgr.makeNumber(5);
    IntegerFormula x = imgr.makeVariable("x");
    IntegerFormula y = imgr.makeVariable("y");
    IntegerFormula z = imgr.makeVariable("z");
    IntegerFormula xx;
    IntegerFormula yy;
    IntegerFormula zz;
    try {
        xx = imgr.multiply(x, x);
        yy = imgr.multiply(y, y);
        zz = imgr.multiply(z, z);
    } catch (UnsupportedOperationException e) {
        // to support non-linear arithmetic, we can then skip the test completely
        throw new AssumptionViolatedException("Support for non-linear arithmetic is optional", e);
    }
    try (ProverEnvironment env = context.newProverEnvironment()) {
        // check x*x + y*y = z*z
        env.push(imgr.equal(zz, imgr.add(xx, yy)));
        {
            // SAT with x=4 and y=3
            env.push(imgr.equal(x, i3));
            env.push(imgr.equal(y, i4));
            assertThat(env).isSatisfiable();
            env.pop();
            env.pop();
        }
        {
            // SAT with z=5
            env.push(imgr.equal(z, i5));
            assertThat(env).isSatisfiable();
            env.pop();
        }
        {
            // UNSAT with z=5 and x=2
            env.push(imgr.equal(z, i5));
            env.push(imgr.equal(x, i2));
            assertThat(env).isUnsatisfiable();
            env.pop();
            env.pop();
        }
        {
            // UNSAT with z=5 and x>3 and y>3
            env.push(imgr.equal(z, i5));
            env.push(imgr.greaterThan(x, i3));
            env.push(imgr.greaterThan(y, i3));
            assertThat(env).isUnsatisfiable();
            env.pop();
            env.pop();
            env.pop();
        }
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) Test(org.junit.Test)

Aggregations

ProverEnvironment (org.sosy_lab.java_smt.api.ProverEnvironment)65 Test (org.junit.Test)53 BasicProverEnvironment (org.sosy_lab.java_smt.api.BasicProverEnvironment)37 Model (org.sosy_lab.java_smt.api.Model)36 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)24 IntegerFormula (org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula)22 ValueAssignment (org.sosy_lab.java_smt.api.Model.ValueAssignment)17 BitvectorFormula (org.sosy_lab.java_smt.api.BitvectorFormula)8 SolverContext (org.sosy_lab.java_smt.api.SolverContext)8 AssumptionViolatedException (org.junit.AssumptionViolatedException)6 VerificationTask (com.dat3m.dartagnan.verification.VerificationTask)5 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)5 ProgramParser (com.dat3m.dartagnan.parsers.program.ProgramParser)4 Program (com.dat3m.dartagnan.program.Program)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Result (com.dat3m.dartagnan.utils.Result)3 Configuration (org.sosy_lab.common.configuration.Configuration)3 InterpolatingProverEnvironment (org.sosy_lab.java_smt.api.InterpolatingProverEnvironment)3 ParserCat (com.dat3m.dartagnan.parsers.cat.ParserCat)2