Search in sources :

Example 1 with FloatingPointFormula

use of org.sosy_lab.java_smt.api.FloatingPointFormula 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 FloatingPointFormula

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

the class FloatingPointFormulaManagerTest method fpToBv.

private void fpToBv(int i, FloatingPointType prec) throws SolverException, InterruptedException {
    BitvectorFormula bv = bvmgr.makeBitvector(prec.getTotalSize(), i);
    FloatingPointFormula fp = fpmgr.makeNumber(i, prec);
    BitvectorFormula fpToBv = fpmgr.castTo(fp, FormulaType.getBitvectorTypeWithSize(prec.getTotalSize()));
    assertThatFormula(bvmgr.equal(bv, fpToBv)).isTautological();
}
Also used : BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula)

Example 3 with FloatingPointFormula

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

the class FloatingPointFormulaManagerTest method cast.

@Test
public void cast() throws SolverException, InterruptedException {
    FloatingPointFormula doublePrecNumber = fpmgr.makeNumber(1.5, doublePrecType);
    FloatingPointFormula singlePrecNumber = fpmgr.makeNumber(1.5, singlePrecType);
    FloatingPointFormula narrowedNumber = fpmgr.castTo(doublePrecNumber, singlePrecType);
    FloatingPointFormula widenedNumber = fpmgr.castTo(singlePrecNumber, doublePrecType);
    assertThatFormula(fpmgr.equalWithFPSemantics(narrowedNumber, singlePrecNumber)).isTautological();
    assertThatFormula(fpmgr.equalWithFPSemantics(widenedNumber, doublePrecNumber)).isTautological();
    FloatingPointFormula doublePrecSmallNumber = fpmgr.makeNumber(5.8774717541114375E-39, doublePrecType);
    FloatingPointFormula singlePrecSmallNumber = fpmgr.makeNumber(5.8774717541114375E-39, singlePrecType);
    FloatingPointFormula widenedSmallNumber = fpmgr.castTo(singlePrecSmallNumber, doublePrecType);
    assertThatFormula(fpmgr.equalWithFPSemantics(widenedSmallNumber, doublePrecSmallNumber)).isTautological();
}
Also used : FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) Test(org.junit.Test)

Example 4 with FloatingPointFormula

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

the class FloatingPointFormulaManagerTest method specialValueFunctions.

@Test
public void specialValueFunctions() throws SolverException, InterruptedException {
    assertThatFormula(fpmgr.isInfinity(posInf)).isTautological();
    assertThatFormula(fpmgr.isNormal(posInf)).isUnsatisfiable();
    assertThatFormula(fpmgr.isSubnormal(posInf)).isUnsatisfiable();
    assertThatFormula(fpmgr.isInfinity(negInf)).isTautological();
    assertThatFormula(fpmgr.isNormal(negInf)).isUnsatisfiable();
    assertThatFormula(fpmgr.isSubnormal(negInf)).isUnsatisfiable();
    assertThatFormula(fpmgr.isNaN(nan)).isTautological();
    assertThatFormula(fpmgr.isNormal(nan)).isUnsatisfiable();
    assertThatFormula(fpmgr.isSubnormal(nan)).isUnsatisfiable();
    assertThatFormula(fpmgr.isZero(zero)).isTautological();
    assertThatFormula(fpmgr.isSubnormal(zero)).isUnsatisfiable();
    assertThatFormula(fpmgr.isSubnormal(zero)).isUnsatisfiable();
    FloatingPointFormula negZero = fpmgr.makeNumber(-0.0, singlePrecType);
    assertThatFormula(fpmgr.isZero(negZero)).isTautological();
    assertThatFormula(fpmgr.isSubnormal(negZero)).isUnsatisfiable();
    assertThatFormula(fpmgr.isSubnormal(negZero)).isUnsatisfiable();
    FloatingPointFormula minPosNormalValue = fpmgr.makeNumber(Float.MIN_NORMAL, singlePrecType);
    assertThatFormula(fpmgr.isSubnormal(minPosNormalValue)).isUnsatisfiable();
    assertThatFormula(fpmgr.isNormal(minPosNormalValue)).isSatisfiable();
    assertThatFormula(fpmgr.isZero(minPosNormalValue)).isUnsatisfiable();
}
Also used : FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) Test(org.junit.Test)

Example 5 with FloatingPointFormula

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

the class FloatingPointFormulaManagerTest method parser.

@Test
public void parser() throws SolverException, InterruptedException {
    for (String s : new String[] { "-1", "-Infinity", "-0", "-0.0", "-0.000" }) {
        FloatingPointFormula formula = fpmgr.makeNumber(s, singlePrecType);
        assertThatFormula(fpmgr.isNegative(formula)).isTautological();
        assertThatFormula(fpmgr.isNegative(fpmgr.negate(formula))).isUnsatisfiable();
        assertThatFormula(fpmgr.equalWithFPSemantics(fpmgr.negate(formula), fpmgr.abs(formula))).isTautological();
    }
    for (String s : new String[] { "1", "Infinity", "0", "0.0", "0.000" }) {
        FloatingPointFormula formula = fpmgr.makeNumber(s, singlePrecType);
        assertThatFormula(fpmgr.isNegative(formula)).isUnsatisfiable();
        assertThatFormula(fpmgr.isNegative(fpmgr.negate(formula))).isTautological();
        assertThatFormula(fpmgr.equalWithFPSemantics(formula, fpmgr.abs(formula))).isTautological();
    }
    for (String s : new String[] { "+1", "+Infinity", "+0", "+0.0", "+0.000" }) {
        FloatingPointFormula formula = fpmgr.makeNumber(s, singlePrecType);
        assertThatFormula(fpmgr.isNegative(formula)).isUnsatisfiable();
        assertThatFormula(fpmgr.isNegative(fpmgr.negate(formula))).isTautological();
        assertThatFormula(fpmgr.equalWithFPSemantics(formula, fpmgr.abs(formula))).isTautological();
    }
    // NaN is not positive and not negative.
    for (String s : new String[] { "NaN", "-NaN", "+NaN" }) {
        FloatingPointFormula formula = fpmgr.makeNumber(s, singlePrecType);
        assertThatFormula(fpmgr.isNegative(formula)).isUnsatisfiable();
        assertThatFormula(fpmgr.isNegative(fpmgr.negate(formula))).isUnsatisfiable();
    }
}
Also used : FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) Test(org.junit.Test)

Aggregations

FloatingPointFormula (org.sosy_lab.java_smt.api.FloatingPointFormula)29 Test (org.junit.Test)21 BitvectorFormula (org.sosy_lab.java_smt.api.BitvectorFormula)7 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)7 FloatingPointType (org.sosy_lab.java_smt.api.FormulaType.FloatingPointType)7 NumeralFormula (org.sosy_lab.java_smt.api.NumeralFormula)5 ArrayFormula (org.sosy_lab.java_smt.api.ArrayFormula)2 InterpolatingProverEnvironment (org.sosy_lab.java_smt.api.InterpolatingProverEnvironment)2 IntegerFormula (org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula)2 StringFormula (org.sosy_lab.java_smt.api.StringFormula)2 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 ExtendedRational (org.sosy_lab.common.rationals.ExtendedRational)1 FloatingPointFormulaManager (org.sosy_lab.java_smt.api.FloatingPointFormulaManager)1 Formula (org.sosy_lab.java_smt.api.Formula)1 FormulaType (org.sosy_lab.java_smt.api.FormulaType)1