Fix strings rewriter for strip constant endpoint reverse direction (#1424)
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>
Mon, 4 Dec 2017 20:18:16 +0000 (14:18 -0600)
committerGitHub <noreply@github.com>
Mon, 4 Dec 2017 20:18:16 +0000 (14:18 -0600)
src/theory/strings/theory_strings_rewriter.cpp
test/regress/regress0/strings/Makefile.am
test/regress/regress0/strings/strip-endpt-sound.smt2 [new file with mode: 0644]

index aab4196ccb51edfd3d757b4795aaa4c2cda82fad..5cb58729ee4c7c430c1ad05b6e1196b7c41c7f9b 100644 (file)
@@ -2401,7 +2401,7 @@ bool TheoryStringsRewriter::stripConstantEndpoints(std::vector<Node>& n1,
         if (n2[index1].isConst())
         {
           CVC4::String t = n2[index1].getConst<String>();
-          std::size_t ret = s.find(t);
+          std::size_t ret = r == 0 ? s.find(t) : s.rfind(t);
           if (ret == std::string::npos)
           {
             if (n1.size() == 1)
@@ -2423,9 +2423,12 @@ bool TheoryStringsRewriter::stripConstantEndpoints(std::vector<Node>& n1,
           else
           {
             Assert(ret < s.size());
-            // can strip off up to the find position
-            // e.g. str.contains( str.++( "abc", x ), str.++( "b", y ) ) -->
-            // str.contains( str.++( "bc", x ), str.++( "b", y ) )
+            // can strip off up to the find position, e.g.
+            // str.contains( str.++( "abc", x ), str.++( "b", y ) ) -->
+            // str.contains( str.++( "bc", x ), str.++( "b", y ) ),
+            // and
+            // str.contains( str.++( x, "abbd" ), str.++( y, "b" ) ) -->
+            // str.contains( str.++( x, "abb" ), str.++( y, "b" ) )
             overlap = s.size() - ret;
           }
         }
index 99fd2b6307bec4ee192afb8de14cd43622af8dac..18b07b91d9999838a8c658a55b2ad2e23f8d342e 100644 (file)
@@ -94,7 +94,8 @@ TESTS = \
   rewrites-v2.smt2 \
   substr-rewrites.smt2 \
   norn-ab.smt2 \
-  type002.smt2
+  type002.smt2 \
+  strip-endpt-sound.smt2
 
 FAILING_TESTS =
 
diff --git a/test/regress/regress0/strings/strip-endpt-sound.smt2 b/test/regress/regress0/strings/strip-endpt-sound.smt2
new file mode 100644 (file)
index 0000000..0c1dd12
--- /dev/null
@@ -0,0 +1,29 @@
+; COMMAND-LINE: --strings-exp
+; EXPECT: sat
+(set-logic QF_S)
+(declare-fun x () String)
+(declare-fun y () String)
+
+(assert (str.contains "c(ab)" (str.++ x ")")))
+(assert (str.contains "c(ab)" (str.++ "c(" y)))
+
+(declare-fun z () String)
+(declare-fun w () String)
+
+(assert (str.contains "c(ab))" (str.++ z "))")))
+(assert (str.contains z "b"))
+
+(assert (str.contains "c(ab))" (str.++ w "b)")))
+(assert (str.contains w "a"))
+
+
+(declare-fun p () String)
+(declare-fun q () String)
+
+(assert (str.contains "c(aab))" (str.++ "a" p)))
+(assert (str.contains p "a"))
+
+(assert (str.contains "c(abb))" (str.++ q "b")))
+(assert (str.contains q "b"))
+
+(check-sat)