Search in sources :

Example 16 with Expr

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);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr) BitvectorType(org.sosy_lab.java_smt.api.FormulaType.BitvectorType) Kind(edu.stanford.CVC4.Kind)

Example 17 with Expr

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);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr) BitvectorType(org.sosy_lab.java_smt.api.FormulaType.BitvectorType) Kind(edu.stanford.CVC4.Kind)

Example 18 with Expr

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;
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr)

Example 19 with Expr

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;
}
Also used : 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) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr) CVC4.vectorType(edu.stanford.CVC4.vectorType)

Example 20 with Expr

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(')');
        }
    };
}
Also used : Type(edu.stanford.CVC4.Type) FormulaType(org.sosy_lab.java_smt.api.FormulaType) Expr(edu.stanford.CVC4.Expr) OutputStream(java.io.OutputStream) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Expr (edu.stanford.CVC4.Expr)57 Test (org.junit.Test)55 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)49 SExpr (edu.stanford.CVC4.SExpr)42 Expr (com.microsoft.z3.Expr)32 Result (edu.stanford.CVC4.Result)32 Rational (edu.stanford.CVC4.Rational)28 Expr (com.google.api.expr.v1alpha1.Expr)23 BoolExpr (com.microsoft.z3.BoolExpr)22 ArrayType (edu.stanford.CVC4.ArrayType)12 BitVectorType (edu.stanford.CVC4.BitVectorType)12 Status (com.microsoft.z3.Status)11 Type (edu.stanford.CVC4.Type)11 HashMap (java.util.HashMap)11 Test (org.junit.jupiter.api.Test)11 ParsedExpr (com.google.api.expr.v1alpha1.ParsedExpr)10 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)9 ArithExpr (com.microsoft.z3.ArithExpr)8 BitVecExpr (com.microsoft.z3.BitVecExpr)8 Val (org.projectnessie.cel.common.types.ref.Val)7