Skip to content

Commit 9b140d2

Browse files
committed
Add core theory "implies" operation
1 parent 3599b1d commit 9b140d2

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/solvers/smt2_incremental/smt_core_theory.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ void smt_core_theoryt::nott::validate(const smt_termt &operand)
2222
const smt_function_application_termt::factoryt<smt_core_theoryt::nott>
2323
smt_core_theoryt::make_not{};
2424

25+
const char *smt_core_theoryt::impliest::identifier()
26+
{
27+
return "=>";
28+
}
29+
30+
smt_sortt
31+
smt_core_theoryt::impliest::return_sort(const smt_termt &, const smt_termt &)
32+
{
33+
return smt_bool_sortt{};
34+
}
35+
36+
void smt_core_theoryt::impliest::validate(
37+
const smt_termt &lhs,
38+
const smt_termt &rhs)
39+
{
40+
INVARIANT(
41+
lhs.get_sort() == smt_bool_sortt{},
42+
"Left hand side of \"=>\" must have bool sort.");
43+
INVARIANT(
44+
rhs.get_sort() == smt_bool_sortt{},
45+
"Right hand side of \"=>\" must have bool sort.");
46+
}
47+
48+
const smt_function_application_termt::factoryt<smt_core_theoryt::impliest>
49+
smt_core_theoryt::implies{};
50+
2551
const char *smt_core_theoryt::equalt::identifier()
2652
{
2753
return "=";

src/solvers/smt2_incremental/smt_core_theory.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ class smt_core_theoryt
1616
};
1717
static const smt_function_application_termt::factoryt<nott> make_not;
1818

19+
struct impliest final
20+
{
21+
static const char *identifier();
22+
static smt_sortt return_sort(const smt_termt &lhs, const smt_termt &rhs);
23+
static void validate(const smt_termt &lhs, const smt_termt &rhs);
24+
};
25+
static const smt_function_application_termt::factoryt<impliest> implies;
26+
1927
struct equalt final
2028
{
2129
static const char *identifier();

unit/solvers/smt2_incremental/smt_core_theory.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ TEST_CASE("SMT core theory \"not\".", "[core][smt2_incremental]")
2222
CHECK_THROWS(smt_core_theoryt::make_not(smt_bit_vector_constant_termt{0, 1}));
2323
}
2424

25+
TEST_CASE("SMT core theory implies.", "[core][smt2_incremental]")
26+
{
27+
const smt_bool_literal_termt true_term{true};
28+
const smt_bool_literal_termt false_term{false};
29+
const auto implies = smt_core_theoryt::implies(true_term, false_term);
30+
CHECK(implies.get_sort() == smt_bool_sortt{});
31+
CHECK(
32+
implies.function_identifier() ==
33+
smt_identifier_termt{"=>", smt_bool_sortt{}});
34+
REQUIRE(implies.arguments().size() == 2);
35+
CHECK(implies.arguments()[0].get() == true_term);
36+
CHECK(implies.arguments()[1].get() == false_term);
37+
cbmc_invariants_should_throwt invariants_throw;
38+
const smt_bit_vector_constant_termt two{2, 8};
39+
CHECK_THROWS(smt_core_theoryt::implies(two, false_term));
40+
CHECK_THROWS(smt_core_theoryt::implies(true_term, two));
41+
}
42+
2543
TEST_CASE("SMT core theory \"=\".", "[core][smt2_incremental]")
2644
{
2745
SECTION("Bool sorted term comparison")

0 commit comments

Comments
 (0)