use of org.sosy_lab.java_smt.api.ArrayFormula in project java-smt by sosy-lab.
the class CVC4FormulaCreator method getFormulaType.
@SuppressWarnings("unchecked")
@Override
public <T extends Formula> FormulaType<T> getFormulaType(T pFormula) {
Type t = extractInfo(pFormula).getType();
if (pFormula instanceof BitvectorFormula) {
checkArgument(t.isBitVector(), "BitvectorFormula with actual type %s: %s", t, pFormula);
return (FormulaType<T>) getFormulaType(extractInfo(pFormula));
} else if (pFormula instanceof FloatingPointFormula) {
checkArgument(t.isFloatingPoint(), "FloatingPointFormula with actual type %s: %s", t, pFormula);
edu.stanford.CVC4.FloatingPointType fpType = new edu.stanford.CVC4.FloatingPointType(t);
return (FormulaType<T>) FormulaType.getFloatingPointType((int) fpType.getExponentSize(), // without sign bit
(int) fpType.getSignificandSize() - 1);
} else if (pFormula instanceof ArrayFormula<?, ?>) {
FormulaType<T> arrayIndexType = getArrayFormulaIndexType((ArrayFormula<T, T>) pFormula);
FormulaType<T> arrayElementType = getArrayFormulaElementType((ArrayFormula<T, T>) pFormula);
return (FormulaType<T>) FormulaType.getArrayType(arrayIndexType, arrayElementType);
}
return super.getFormulaType(pFormula);
}
use of org.sosy_lab.java_smt.api.ArrayFormula 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.ArrayFormula in project java-smt by sosy-lab.
the class PrincessFormulaCreator method getFormulaType.
@SuppressWarnings("unchecked")
@Override
public <T extends Formula> FormulaType<T> getFormulaType(final T pFormula) {
if (pFormula instanceof BitvectorFormula) {
ITerm input = (ITerm) extractInfo(pFormula);
Sort sort = Sort$.MODULE$.sortOf(input);
scala.Option<Object> bitWidth = PrincessEnvironment.getBitWidth(sort);
checkArgument(bitWidth.isDefined(), "BitvectorFormula with actual type %s: %s", sort, pFormula);
return (FormulaType<T>) FormulaType.getBitvectorTypeWithSize((Integer) bitWidth.get());
} else if (pFormula instanceof ArrayFormula<?, ?>) {
final FormulaType<?> arrayIndexType = getArrayFormulaIndexType((ArrayFormula<?, ?>) pFormula);
final FormulaType<?> arrayElementType = getArrayFormulaElementType((ArrayFormula<?, ?>) pFormula);
return (FormulaType<T>) new ArrayFormulaType<>(arrayIndexType, arrayElementType);
}
return super.getFormulaType(pFormula);
}
use of org.sosy_lab.java_smt.api.ArrayFormula in project java-smt by sosy-lab.
the class ModelTest method testGetArrays3.
@Test
public void testGetArrays3() throws SolverException, InterruptedException {
requireParser();
requireArrays();
assume().withMessage("As of now, only Princess does not support multi-dimensional arrays").that(solver).isNotSameInstanceAs(Solvers.PRINCESS);
// create formula for "arr[5][3][1]==x && x==123"
BooleanFormula f = mgr.parse("(declare-fun x () Int)\n" + "(declare-fun arr () (Array Int (Array Int (Array Int Int))))\n" + "(assert (and" + " (= (select (select (select arr 5) 3) 1) x)" + " (= x 123)" + "))");
testModelIterator(f);
testModelGetters(f, imgr.makeVariable("x"), BigInteger.valueOf(123), "x");
ArrayFormulaType<IntegerFormula, ArrayFormula<IntegerFormula, ArrayFormula<IntegerFormula, IntegerFormula>>> arrType = FormulaType.getArrayType(IntegerType, FormulaType.getArrayType(IntegerType, ARRAY_TYPE_INT_INT));
testModelGetters(f, amgr.select(amgr.select(amgr.select(amgr.makeArray("arr", arrType), imgr.makeNumber(5)), imgr.makeNumber(3)), imgr.makeNumber(1)), BigInteger.valueOf(123), "arr", true);
}
use of org.sosy_lab.java_smt.api.ArrayFormula in project java-smt by sosy-lab.
the class UfElimination method makeEqual.
@SuppressWarnings("unchecked")
@CheckReturnValue
private BooleanFormula makeEqual(Formula pLhs, Formula pRhs) {
BooleanFormula t;
if (pLhs instanceof BooleanFormula && pRhs instanceof BooleanFormula) {
t = bfmgr.equivalence((BooleanFormula) pLhs, (BooleanFormula) pRhs);
} else if (pLhs instanceof IntegerFormula && pRhs instanceof IntegerFormula) {
t = fmgr.getIntegerFormulaManager().equal((IntegerFormula) pLhs, (IntegerFormula) pRhs);
} else if (pLhs instanceof StringFormula && pRhs instanceof StringFormula) {
t = fmgr.getStringFormulaManager().equal((StringFormula) pLhs, (StringFormula) pRhs);
} else if (pLhs instanceof NumeralFormula && pRhs instanceof NumeralFormula) {
t = fmgr.getRationalFormulaManager().equal((NumeralFormula) pLhs, (NumeralFormula) pRhs);
} else if (pLhs instanceof BitvectorFormula) {
t = fmgr.getBitvectorFormulaManager().equal((BitvectorFormula) pLhs, (BitvectorFormula) pRhs);
} else if (pLhs instanceof FloatingPointFormula && pRhs instanceof FloatingPointFormula) {
FloatingPointFormulaManager fpfmgr = fmgr.getFloatingPointFormulaManager();
t = fpfmgr.equalWithFPSemantics((FloatingPointFormula) pLhs, (FloatingPointFormula) pRhs);
} else if (pLhs instanceof ArrayFormula<?, ?> && pRhs instanceof ArrayFormula<?, ?>) {
ArrayFormula<?, ?> lhs = (ArrayFormula<?, ?>) pLhs;
@SuppressWarnings("rawtypes") ArrayFormula rhs = (ArrayFormula) pRhs;
t = fmgr.getArrayFormulaManager().equivalence(lhs, rhs);
} else {
throw new IllegalArgumentException("Not supported interface");
}
return t;
}
Aggregations