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