Search in sources :

Example 1 with RationalFormula

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

the class OptimizationIntReal method optimizeWithRationals.

/**
 * Solve the problem with rational logic.
 */
private static void optimizeWithRationals(Configuration config, LogManager logger, ShutdownNotifier notifier, Solvers solver) throws InterruptedException, SolverException {
    // create solver context
    try (SolverContext context = SolverContextFactory.createSolverContext(config, logger, notifier, solver);
        OptimizationProverEnvironment prover = context.newOptimizationProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        BooleanFormulaManager bmgr = context.getFormulaManager().getBooleanFormulaManager();
        RationalFormulaManager nmgr = context.getFormulaManager().getRationalFormulaManager();
        RationalFormula x = nmgr.makeVariable("x");
        prover.addConstraint(bmgr.and(nmgr.greaterOrEquals(x, nmgr.makeNumber(0)), nmgr.lessThan(x, nmgr.makeNumber(10))));
        logger.log(Level.INFO, "optimizing with rational logic");
        printUpperAndLowerBound(prover, x, logger);
    } 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 : SolverContext(org.sosy_lab.java_smt.api.SolverContext) RationalFormula(org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) OptimizationProverEnvironment(org.sosy_lab.java_smt.api.OptimizationProverEnvironment) RationalFormulaManager(org.sosy_lab.java_smt.api.RationalFormulaManager) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException)

Example 2 with RationalFormula

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

the class ArrayFormulaManagerTest method testRationalIndexRationalValue.

/*
   *  Test whether or not Rational Arrays are possible with Rational index
   */
@Test
public void testRationalIndexRationalValue() throws SolverException, InterruptedException {
    requireRationals();
    // (arr2 = store(arr1, 4, 2)) & !(select(arr2, 4) = 2)
    RationalFormula num2 = rmgr.makeNumber(2);
    RationalFormula num4 = rmgr.makeNumber(4);
    ArrayFormula<RationalFormula, RationalFormula> arr1 = amgr.makeArray("arr1", RationalType, RationalType);
    ArrayFormula<RationalFormula, RationalFormula> arr2 = amgr.makeArray("arr2", RationalType, RationalType);
    BooleanFormula query = bmgr.and(amgr.equivalence(arr2, amgr.store(arr1, num4, num2)), bmgr.not(rmgr.equal(num2, amgr.select(arr2, num4))));
    assertThatFormula(query).isUnsatisfiable();
}
Also used : RationalFormula(org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 3 with RationalFormula

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

the class SolverTheoriesTest method testNestedRationalArray.

@Test
public void testNestedRationalArray() {
    requireArrays();
    requireRationals();
    requireIntegers();
    IntegerFormula _i = imgr.makeVariable("i");
    ArrayFormula<IntegerFormula, ArrayFormula<IntegerFormula, RationalFormula>> multi = amgr.makeArray("multi", FormulaType.IntegerType, FormulaType.getArrayType(FormulaType.IntegerType, FormulaType.RationalType));
    RationalFormula valueInMulti = amgr.select(amgr.select(multi, _i), _i);
    switch(solver) {
        case MATHSAT5:
            assertThat(valueInMulti.toString()).isEqualTo("(`read_int_rat` (`read_int_<Array, Int, Real, >` multi i) i)");
            break;
        default:
            assertThat(valueInMulti.toString()).isEqualTo("(select (select multi i) i)");
    }
}
Also used : RationalFormula(org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) Test(org.junit.Test)

Example 4 with RationalFormula

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

the class UFManagerTest method testDeclareAndCallUFWithRational.

@Test
public void testDeclareAndCallUFWithRational() throws SolverException, InterruptedException {
    requireRationals();
    RationalFormula x = rmgr.makeVariable("x");
    RationalFormula value = rmgr.makeNumber(0.5);
    for (String name : VALID_NAMES) {
        Formula f = fmgr.declareAndCallUF(name, FormulaType.RationalType, ImmutableList.of(rmgr.makeNumber(1.5)));
        FunctionDeclaration<?> declaration = getDeclaration(f);
        Truth.assertThat(declaration.getName()).isEqualTo(name);
        Formula f2 = mgr.makeApplication(declaration, rmgr.makeNumber(1.5));
        Truth.assertThat(f2).isEqualTo(f);
        assertThatFormula(rmgr.equal(value, x)).implies(rmgr.equal((RationalFormula) mgr.makeApplication(declaration, value), (RationalFormula) mgr.makeApplication(declaration, x)));
    }
}
Also used : IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) Formula(org.sosy_lab.java_smt.api.Formula) RationalFormula(org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula) RationalFormula(org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula) Test(org.junit.Test)

Example 5 with RationalFormula

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

the class RationalFormulaManagerTest method forallFloorIsLessThanValueTest.

@Test
public void forallFloorIsLessThanValueTest() throws SolverException, InterruptedException {
    requireRationals();
    requireQuantifiers();
    RationalFormula v = rmgr.makeVariable("v");
    // counterexample: all integers
    assertThatFormula(qmgr.forall(v, rmgr.lessThan(rmgr.floor(v), v))).isUnsatisfiable();
}
Also used : RationalFormula(org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula) Test(org.junit.Test)

Aggregations

RationalFormula (org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula)17 Test (org.junit.Test)16 IntegerFormula (org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula)5 OptimizationProverEnvironment (org.sosy_lab.java_smt.api.OptimizationProverEnvironment)5 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)4 Formula (org.sosy_lab.java_smt.api.Formula)3 OptStatus (org.sosy_lab.java_smt.api.OptimizationProverEnvironment.OptStatus)3 InvalidConfigurationException (org.sosy_lab.common.configuration.InvalidConfigurationException)1 Rational (org.sosy_lab.common.rationals.Rational)1 ArrayFormula (org.sosy_lab.java_smt.api.ArrayFormula)1 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)1 FormulaType (org.sosy_lab.java_smt.api.FormulaType)1 FunctionDeclaration (org.sosy_lab.java_smt.api.FunctionDeclaration)1 RationalFormulaManager (org.sosy_lab.java_smt.api.RationalFormulaManager)1 SolverContext (org.sosy_lab.java_smt.api.SolverContext)1