diff options
author | Andres Noetzli <andres.noetzli@gmail.com> | 2018-10-19 08:14:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-19 08:14:22 -0700 |
commit | c116c6c1ec757fe51f2b874e750ad8281baea103 (patch) | |
tree | cd5c1fc6deaff07d784705dae933a7abd01b546b /test | |
parent | 64dcc865f8aae4fd1591bfec9ee117b360e9f9b3 (diff) |
Add helper to detect length one string terms (#2654)
This commit introduces a helper function to detect string terms that
have exactly/at most length one. This is useful for a lot of rewrites
because strings of at most length one are guaranteed to not overlap
multiple components in a concatenation, which allows for more aggressive
rewriting.
This commit has been tested with --sygus-rr-synth-check for >1h on the
string term grammar.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/theory/theory_strings_rewriter_white.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/unit/theory/theory_strings_rewriter_white.h b/test/unit/theory/theory_strings_rewriter_white.h index c92597224..87817872b 100644 --- a/test/unit/theory/theory_strings_rewriter_white.h +++ b/test/unit/theory/theory_strings_rewriter_white.h @@ -80,6 +80,43 @@ class TheoryStringsRewriterWhite : public CxxTest::TestSuite TS_ASSERT_DIFFERS(res_t1, res_t2); } + void testCheckEntailLengthOne() + { + TypeNode intType = d_nm->integerType(); + TypeNode strType = d_nm->stringType(); + + Node a = d_nm->mkConst(::CVC4::String("A")); + Node abcd = d_nm->mkConst(::CVC4::String("ABCD")); + Node aaad = d_nm->mkConst(::CVC4::String("AAAD")); + Node b = d_nm->mkConst(::CVC4::String("B")); + Node x = d_nm->mkVar("x", strType); + Node y = d_nm->mkVar("y", strType); + Node negOne = d_nm->mkConst(Rational(-1)); + Node zero = d_nm->mkConst(Rational(0)); + Node one = d_nm->mkConst(Rational(1)); + Node two = d_nm->mkConst(Rational(2)); + Node three = d_nm->mkConst(Rational(3)); + Node i = d_nm->mkVar("i", intType); + + TS_ASSERT(TheoryStringsRewriter::checkEntailLengthOne(a)); + TS_ASSERT(TheoryStringsRewriter::checkEntailLengthOne(a, true)); + + Node substr = d_nm->mkNode(kind::STRING_SUBSTR, x, zero, one); + TS_ASSERT(TheoryStringsRewriter::checkEntailLengthOne(substr)); + TS_ASSERT(!TheoryStringsRewriter::checkEntailLengthOne(substr, true)); + + substr = d_nm->mkNode(kind::STRING_SUBSTR, + d_nm->mkNode(kind::STRING_CONCAT, a, x), + zero, + one); + TS_ASSERT(TheoryStringsRewriter::checkEntailLengthOne(substr)); + TS_ASSERT(TheoryStringsRewriter::checkEntailLengthOne(substr, true)); + + substr = d_nm->mkNode(kind::STRING_SUBSTR, x, zero, two); + TS_ASSERT(!TheoryStringsRewriter::checkEntailLengthOne(substr)); + TS_ASSERT(!TheoryStringsRewriter::checkEntailLengthOne(substr, true)); + } + void testCheckEntailArith() { TypeNode intType = d_nm->integerType(); |