@@ -45,24 +45,21 @@ exprt string_constraint_generatort::add_axioms_for_set_length(
45
45
46
46
// We add axioms:
47
47
// a1 : |res|=k
48
- // a2 : forall i<|res|. i < |s1| ==> res[i] = s1[i]
49
- // a3 : forall i<|res|. i >= |s1| ==> res[i] = 0
48
+ // a2 : forall i< min( |s1|, k) . res[i] = s1[i]
49
+ // a3 : forall |s1| <= i < |res|. res[i] = 0
50
50
51
51
lemmas.push_back (res.axiom_for_has_length (k));
52
52
53
- symbol_exprt idx = fresh_univ_index (" QA_index_set_length" , index_type);
54
- string_constraintt a2 (
55
- idx,
56
- res.length (),
57
- s1.axiom_for_length_gt (idx),
58
- equal_exprt (s1[idx], res[idx]));
53
+ const symbol_exprt idx = fresh_univ_index (" QA_index_set_length" , index_type);
54
+ const string_constraintt a2 (
55
+ idx, minimum (s1.length (), k), equal_exprt (s1[idx], res[idx]));
59
56
constraints.push_back (a2);
60
57
61
58
symbol_exprt idx2 = fresh_univ_index (" QA_index_set_length2" , index_type);
62
59
string_constraintt a3 (
63
60
idx2,
61
+ s1.length (),
64
62
res.length (),
65
- s1.axiom_for_length_le (idx2),
66
63
equal_exprt (res[idx2], constant_char (0 , char_type)));
67
64
constraints.push_back (a3);
68
65
@@ -395,8 +392,8 @@ exprt string_constraint_generatort::add_axioms_for_to_upper_case(
395
392
// / These axioms are:
396
393
// / 1. \f$ |{\tt res}| = |{\tt str}|\f$
397
394
// / 2. \f$ {\tt res}[{\tt pos}]={\tt char}\f$
398
- // / 3. \f$ \forall i< |{\tt res}|.\ i \ne {\tt pos}
399
- // / \Rightarrow {\tt res}[i] = {\tt str}[i]\f$
395
+ // / 3. \f$ \forall i < min( |{\tt res}|, pos). {\tt res}[i] = {\tt str}[i]\f$
396
+ // / 4. \f$ \forall pos+1 <= i < |{\tt res}|.\ {\tt res}[i] = {\tt str}[i]\f$
400
397
// / \param f: function application with arguments integer `|res|`, character
401
398
// / pointer `&res[0]`, refined_string `str`, integer `pos`,
402
399
// / and character `char`
@@ -413,14 +410,22 @@ exprt string_constraint_generatort::add_axioms_for_char_set(
413
410
const exprt &character = f.arguments ()[4 ];
414
411
415
412
const binary_relation_exprt out_of_bounds (position, ID_ge, str.length ());
416
- lemmas.push_back (equal_exprt (res.length (), str.length ()));
417
- lemmas.push_back (equal_exprt (res[position], character));
413
+ const equal_exprt a1 (res.length (), str.length ());
414
+ lemmas.push_back (a1);
415
+ const equal_exprt a2 (res[position], character);
416
+ lemmas.push_back (a2);
417
+
418
418
const symbol_exprt q = fresh_univ_index (" QA_char_set" , position.type ());
419
- equal_exprt a3_body (res[q], str[q]);
420
- notequal_exprt a3_guard (q, position);
421
- constraints.push_back (
422
- string_constraintt (
423
- q, from_integer (0 , q.type ()), res.length (), a3_guard, a3_body));
419
+ const equal_exprt a3_body (res[q], str[q]);
420
+ const string_constraintt a3 (q, minimum (res.length (), position), a3_body);
421
+ constraints.push_back (a3);
422
+
423
+ const symbol_exprt q2 = fresh_univ_index (" QA_char_set2" , position.type ());
424
+ const plus_exprt lower_bound (position, from_integer (1 , position.type ()));
425
+ const equal_exprt a4_body (res[q2], str[q2]);
426
+ const string_constraintt a4 (q2, lower_bound, res.length (), a4_body);
427
+ constraints.push_back (a4);
428
+
424
429
return if_exprt (
425
430
out_of_bounds, from_integer (1 , f.type ()), from_integer (0 , f.type ()));
426
431
}
0 commit comments