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());
}
}
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();
}
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)");
}
}
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)));
}
}
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();
}
Aggregations