diff options
author | yoni206 <yoni206@users.noreply.github.com> | 2020-09-15 21:31:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-15 23:31:10 -0500 |
commit | e61c6ecf2e8c569d9f1b5f27ec1309371cc45cff (patch) | |
tree | 339ec96158b78b7e998a6c4edd16a4127a7fe8aa /src/preprocessing | |
parent | 85a3056bed70e226d9e17a1f5785d957628f9e26 (diff) |
bv2int: support models in tests (#5068)
Previous changes in this preprocessing pass have already enabled model generation when using it.
However, the satisfiable tests still had --no-check-models.
The changes in this PR:
All --no-check-models from current tests for the preprocessing pass are removed.
Refactoring of the relevant part of the code.
Solves CVC4/cvc4-projects#128.
Remark: disabling white-spaces when reviewing this PR is recommended.
Diffstat (limited to 'src/preprocessing')
-rw-r--r-- | src/preprocessing/passes/bv_to_int.cpp | 70 | ||||
-rw-r--r-- | src/preprocessing/passes/bv_to_int.h | 5 |
2 files changed, 40 insertions, 35 deletions
diff --git a/src/preprocessing/passes/bv_to_int.cpp b/src/preprocessing/passes/bv_to_int.cpp index e40b828b5..13ad086e8 100644 --- a/src/preprocessing/passes/bv_to_int.cpp +++ b/src/preprocessing/passes/bv_to_int.cpp @@ -687,11 +687,7 @@ Node BVToInt::translateNoChildren(Node original) uint64_t bvsize = original.getType().getBitVectorSize(); translation = newVar; d_rangeAssertions.insert(mkRangeConstraint(newVar, bvsize)); - std::vector<Expr> args; - Node intToBVOp = d_nm->mkConst<IntToBitVector>(IntToBitVector(bvsize)); - Node newNode = d_nm->mkNode(intToBVOp, newVar); - smt::currentSmtEngine()->defineFunction( - original.toExpr(), args, newNode.toExpr(), true); + defineBVUFAsIntUF(original, newVar); } else if (original.getType().isFunction()) { @@ -756,41 +752,49 @@ Node BVToInt::translateFunctionSymbol(Node bvUF) void BVToInt::defineBVUFAsIntUF(Node bvUF, Node intUF) { - // This function should only be called after translating - // the function symbol to a new function symbol - // with the right domain and range. - - // get domain and range of the original function - TypeNode tn = bvUF.getType(); - vector<TypeNode> bvDomain = tn.getArgTypes(); - TypeNode bvRange = tn.getRangeType(); - + // The resulting term + Node result; + // The type of the resulting term + TypeNode resultType; // symbolic arguments of original function vector<Expr> args; - // children of the new symbolic application - vector<Node> achildren; - achildren.push_back(intUF); - int i = 0; - for (TypeNode d : bvDomain) - { - // Each bit-vector argument is casted to a natural number - // Other arguments are left intact. - Node fresh_bound_var = d_nm->mkBoundVar(d); - args.push_back(fresh_bound_var.toExpr()); - Node castedArg = args[i]; - if (d.isBitVector()) + if (!bvUF.getType().isFunction()) { + // bvUF is a variable. + // in this case, the result is just the original term + // (it will be casted later if needed) + result = intUF; + resultType = bvUF.getType(); + } else { + // bvUF is a function with arguments + // The arguments need to be casted as well. + TypeNode tn = bvUF.getType(); + resultType = tn.getRangeType(); + vector<TypeNode> bvDomain = tn.getArgTypes(); + // children of the new symbolic application + vector<Node> achildren; + achildren.push_back(intUF); + int i = 0; + for (const TypeNode& d : bvDomain) { - castedArg = castToType(castedArg, d_nm->integerType()); + // Each bit-vector argument is casted to a natural number + // Other arguments are left intact. + Node fresh_bound_var = d_nm->mkBoundVar(d); + args.push_back(fresh_bound_var.toExpr()); + Node castedArg = args[i]; + if (d.isBitVector()) + { + castedArg = castToType(castedArg, d_nm->integerType()); + } + achildren.push_back(castedArg); + i++; } - achildren.push_back(castedArg); - i++; + result = d_nm->mkNode(kind::APPLY_UF, achildren); } - Node intApplication = d_nm->mkNode(kind::APPLY_UF, achildren); - // If the range is BV, the application needs to be casted back. - intApplication = castToType(intApplication, bvRange); + // If the result is BV, it needs to be casted back. + result = castToType(result, resultType); // add the function definition to the smt engine. smt::currentSmtEngine()->defineFunction( - bvUF.toExpr(), args, intApplication.toExpr(), true); + bvUF.toExpr(), args, result.toExpr(), true); } bool BVToInt::childrenTypesChanged(Node n) diff --git a/src/preprocessing/passes/bv_to_int.h b/src/preprocessing/passes/bv_to_int.h index db2d08b7d..b84726878 100644 --- a/src/preprocessing/passes/bv_to_int.h +++ b/src/preprocessing/passes/bv_to_int.h @@ -289,11 +289,12 @@ class BVToInt : public PreprocessingPass * When a UF f is translated to a UF g, * we add a define-fun command to the smt-engine * to relate between f and g. + * We do the same when f and g are just variables. * This is useful, for example, when asking * for a model-value of a term that includes the * original UF f. - * @param bvUF the original function - * @param intUF the translated function + * @param bvUF the original function or variable + * @param intUF the translated function or variable */ void defineBVUFAsIntUF(Node bvUF, Node intUF); |