From 42eac5f0061c65139c8e548c6cb228fa0be12bc2 Mon Sep 17 00:00:00 2001 From: Andrew Reynolds Date: Tue, 7 Jun 2022 16:25:10 -0500 Subject: [PATCH] Allow mixed int/real equalities in non-strict parsing mode (#8865) --- src/parser/smt2/smt2.cpp | 45 ++++++++++++------- test/regress/cli/CMakeLists.txt | 1 + .../parser/non-strict-real-vs-int.smt2 | 8 ++++ 3 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 test/regress/cli/regress0/parser/non-strict-real-vs-int.smt2 diff --git a/src/parser/smt2/smt2.cpp b/src/parser/smt2/smt2.cpp index cbf699f6b..122f7dbba 100644 --- a/src/parser/smt2/smt2.cpp +++ b/src/parser/smt2/smt2.cpp @@ -1149,17 +1149,39 @@ cvc5::Term Smt2::applyParseOp(ParseOp& p, std::vector& args) } else if (isBuiltinOperator) { - if (!isHoEnabled() && (kind == cvc5::EQUAL || kind == cvc5::DISTINCT)) + if (kind == cvc5::EQUAL || kind == cvc5::DISTINCT) { + bool isReal = false; // need hol if these operators are applied over function args - for (std::vector::iterator i = args.begin(); i != args.end(); - ++i) + for (const Term& i : args) { - if ((*i).getSort().isFunction()) + Sort s = i.getSort(); + if (!isHoEnabled()) { - parseError( - "Cannot apply equality to functions unless logic is prefixed by " - "HO_."); + if (s.isFunction()) + { + parseError( + "Cannot apply equality to functions unless logic is prefixed " + "by HO_."); + } + } + if (s.isReal()) + { + isReal = true; + } + } + // If strict mode is not enabled, we are permissive for Int and Real + // subtyping. Note that other arithmetic operators and relations are + // already permissive, e.g. <=, +. + if (isReal && !strictModeEnabled()) + { + for (Term& i : args) + { + Sort s = i.getSort(); + if (s.isInteger()) + { + i = d_solver->mkTerm(cvc5::TO_REAL, {i}); + } } } } @@ -1197,14 +1219,7 @@ cvc5::Term Smt2::applyParseOp(ParseOp& p, std::vector& args) << std::endl; return ret; } - if (kind == cvc5::SET_SINGLETON && args.size() == 1) - { - cvc5::Term ret = d_solver->mkTerm(cvc5::SET_SINGLETON, {args[0]}); - Trace("parser") << "applyParseOp: return set.singleton " << ret - << std::endl; - return ret; - } - else if (kind == cvc5::CARDINALITY_CONSTRAINT) + if (kind == cvc5::CARDINALITY_CONSTRAINT) { if (args.size() != 2) { diff --git a/test/regress/cli/CMakeLists.txt b/test/regress/cli/CMakeLists.txt index 763270a6f..4a11a6f2f 100644 --- a/test/regress/cli/CMakeLists.txt +++ b/test/regress/cli/CMakeLists.txt @@ -915,6 +915,7 @@ set(regress_0_tests regress0/parser/linear_arithmetic_err3.smt2 regress0/parser/named-attr-error.smt2 regress0/parser/named-attr.smt2 + regress0/parser/non-strict-real-vs-int.smt2 regress0/parser/proj-issue370-push-pop-global.smt2 regress0/parser/quoted-define-fun.smt2 regress0/parser/real-numerals.smt2 diff --git a/test/regress/cli/regress0/parser/non-strict-real-vs-int.smt2 b/test/regress/cli/regress0/parser/non-strict-real-vs-int.smt2 new file mode 100644 index 000000000..84122e8d0 --- /dev/null +++ b/test/regress/cli/regress0/parser/non-strict-real-vs-int.smt2 @@ -0,0 +1,8 @@ +; COMMAND-LINE: --no-strict-parsing +; EXPECT: sat +(set-logic ALL) +(set-info :status sat) +(declare-fun x () Real) +(assert (= x 10)) +(assert (<= (+ x 1) 20)) +(check-sat) -- 2.30.2