Search in sources :

Example 1 with ArrayFormula

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);
}
Also used : BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) CVC4BitvectorFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4BitvectorFormula) FloatingPointType(org.sosy_lab.java_smt.api.FormulaType.FloatingPointType) CVC4.vectorType(edu.stanford.CVC4.vectorType) Type(edu.stanford.CVC4.Type) BitVectorType(edu.stanford.CVC4.BitVectorType) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType) ArrayType(edu.stanford.CVC4.ArrayType) FunctionType(edu.stanford.CVC4.FunctionType) FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) CVC4FloatingPointFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4FloatingPointFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) CVC4ArrayFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4ArrayFormula) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType) FloatingPointType(org.sosy_lab.java_smt.api.FormulaType.FloatingPointType)

Example 2 with ArrayFormula

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)");
    }
}
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 3 with ArrayFormula

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);
}
Also used : BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) ITerm(ap.parser.ITerm) Sort(ap.types.Sort) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType)

Example 4 with ArrayFormula

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);
}
Also used : IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 5 with ArrayFormula

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;
}
Also used : BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) NumeralFormula(org.sosy_lab.java_smt.api.NumeralFormula) FloatingPointFormulaManager(org.sosy_lab.java_smt.api.FloatingPointFormulaManager) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) StringFormula(org.sosy_lab.java_smt.api.StringFormula) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) CheckReturnValue(com.google.errorprone.annotations.CheckReturnValue)

Aggregations

ArrayFormula (org.sosy_lab.java_smt.api.ArrayFormula)6 BitvectorFormula (org.sosy_lab.java_smt.api.BitvectorFormula)4 IntegerFormula (org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula)4 Test (org.junit.Test)3 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)2 FloatingPointFormula (org.sosy_lab.java_smt.api.FloatingPointFormula)2 FormulaType (org.sosy_lab.java_smt.api.FormulaType)2 ArrayFormulaType (org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType)2 ITerm (ap.parser.ITerm)1 Sort (ap.types.Sort)1 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 ArrayType (edu.stanford.CVC4.ArrayType)1 BitVectorType (edu.stanford.CVC4.BitVectorType)1 FunctionType (edu.stanford.CVC4.FunctionType)1 Type (edu.stanford.CVC4.Type)1 CVC4.vectorType (edu.stanford.CVC4.vectorType)1 FloatingPointFormulaManager (org.sosy_lab.java_smt.api.FloatingPointFormulaManager)1 FloatingPointType (org.sosy_lab.java_smt.api.FormulaType.FloatingPointType)1 NumeralFormula (org.sosy_lab.java_smt.api.NumeralFormula)1 RationalFormula (org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula)1