Skip to content

Commit b5656c7

Browse files
Joel Allredromainbrenguier
Joel Allred
authored andcommitted
Fix add_axioms_for_index_of
Add constraints to rule out '!contains' being true when the string has been found.
1 parent 60e8334 commit b5656c7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/solvers/refinement/string_constraint_generator_indexof.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ exprt string_constraint_generatort::add_axioms_for_index_of_string(
9696
// a2 : !contains => offset=-1
9797
// a3 : forall 0<=witness<|substring|.
9898
// contains => str[witness+offset]=substring[witness]
99+
// a4 : forall n:[0,offset[.
100+
// contains => (exists m:[0,|substring|[. str[n+m]!=substring[m]])
101+
// a5: forall n:[0,|str|-|substring|[.
102+
// !contains => (exists m:[0,|substring|[. str[n+m]!=substring[m])
99103

100104
implies_exprt a1(
101105
contains,
@@ -118,6 +122,26 @@ exprt string_constraint_generatort::add_axioms_for_index_of_string(
118122
equal_exprt(str[plus_exprt(qvar, offset)], substring[qvar]));
119123
axioms.push_back(a3);
120124

125+
string_not_contains_constraintt a4(
126+
from_integer(0, index_type),
127+
offset,
128+
contains,
129+
from_integer(0, index_type),
130+
substring.length(),
131+
str,
132+
substring);
133+
axioms.push_back(a4);
134+
135+
string_not_contains_constraintt a5(
136+
from_integer(0, index_type),
137+
minus_exprt(str.length(), substring.length()),
138+
not_exprt(contains),
139+
from_integer(0, index_type),
140+
substring.length(),
141+
str,
142+
substring);
143+
axioms.push_back(a5);
144+
121145
return offset;
122146
}
123147

0 commit comments

Comments
 (0)