use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.
the class CVC4BitvectorFormulaManager method divide.
@Override
protected Expr divide(Expr numerator, Expr denumerator, boolean signed) {
final Kind operator = signed ? Kind.BITVECTOR_SDIV : Kind.BITVECTOR_UDIV;
final Expr division = exprManager.mkExpr(operator, numerator, denumerator);
// CVC4 does not align with SMTLIB standard when it comes to divide-by-zero.
// For divide-by-zero, we compute the result as: return "1" with the opposite
// sign than the numerator.
final int bitsize = ((BitvectorType) formulaCreator.getFormulaType(numerator)).getSize();
final Expr zero = makeBitvectorImpl(bitsize, 0);
final Expr one = makeBitvectorImpl(bitsize, 1);
// all bits equal "1"
final Expr maxValue = makeBitvectorImpl(bitsize, -1);
return exprManager.mkExpr(Kind.ITE, exprManager.mkExpr(Kind.EQUAL, denumerator, zero), exprManager.mkExpr(Kind.ITE, lessThan(numerator, zero, signed), one, maxValue), division);
}
use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.
the class CVC4BitvectorFormulaManager method modulo.
@Override
protected Expr modulo(Expr numerator, Expr denumerator, boolean signed) {
final Kind operator = signed ? Kind.BITVECTOR_SREM : Kind.BITVECTOR_UREM;
final Expr remainder = exprManager.mkExpr(operator, numerator, denumerator);
// CVC4 does not align with SMTLIB standard when it comes to modulo-by-zero.
// For modulo-by-zero, we compute the result as: "return the numerator".
final int bitsize = ((BitvectorType) formulaCreator.getFormulaType(numerator)).getSize();
final Expr zero = makeBitvectorImpl(bitsize, 0);
return exprManager.mkExpr(Kind.ITE, exprManager.mkExpr(Kind.EQUAL, denumerator, zero), numerator, remainder);
}
use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.
the class CVC4FormulaCreator method makeVariable.
@Override
public Expr makeVariable(Type type, String name) {
Expr exp = variablesCache.computeIfAbsent(name, n -> exprManager.mkVar(name, type));
Preconditions.checkArgument(type.equals(exp.getType()), "symbol name already in use for different type %s", exp.getType());
return exp;
}
use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.
the class CVC4FormulaCreator method declareUFImpl.
@Override
public Expr declareUFImpl(String pName, Type pReturnType, List<Type> pArgTypes) {
Expr exp = functionsCache.get(pName);
if (exp == null) {
vectorType args = new vectorType();
for (Type t : pArgTypes) {
args.add(t);
}
exp = exprManager.mkVar(pName, exprManager.mkFunctionType(args, pReturnType));
functionsCache.put(pName, exp);
}
return exp;
}
use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.
the class CVC4FormulaManager method dumpFormula.
@Override
public Appender dumpFormula(Expr f) {
assert getFormulaCreator().getFormulaType(f) == FormulaType.BooleanType : "Only BooleanFormulas may be dumped";
return new Appenders.AbstractAppender() {
@Override
public void appendTo(Appendable out) throws IOException {
// get all symbols
final Map<String, Expr> allVars = new LinkedHashMap<>();
creator.extractVariablesAndUFs(f, true, allVars::put);
// print all symbols
for (Map.Entry<String, Expr> entry : allVars.entrySet()) {
String name = entry.getKey();
Expr var = entry.getValue();
// escaping is stolen from SMTInterpol, lets hope this remains consistent
out.append("(declare-fun ").append(PrintTerm.quoteIdentifier(name)).append(" (");
// add function parameters
Iterable<Type> childrenTypes = Iterables.transform(var, Expr::getType);
out.append(Joiner.on(" ").join(childrenTypes));
// and return type
out.append(") ").append(var.getType().toString()).append(")\n");
}
// now add the final assert
out.append("(assert ");
// f.toStream() uses LET-expressions and is exactly what we want.
try (OutputStream stream = new OutputStream() {
@Override
public void write(int chr) throws IOException {
out.append((char) chr);
}
}) {
f.toStream(stream);
}
out.append(')');
}
};
}
Aggregations