1 /********************* */
2 /*! \file theory_strings.cpp
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Tianyi Liang, Morgan Deters
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
12 ** \brief Implementation of the theory of strings.
14 ** Implementation of the theory of strings.
17 #include "theory/strings/theory_strings.h"
21 #include "expr/kind.h"
22 #include "options/strings_options.h"
23 #include "smt/command.h"
24 #include "smt/logic_exception.h"
25 #include "smt/smt_statistics_registry.h"
26 #include "theory/ext_theory.h"
27 #include "theory/quantifiers/term_database.h"
28 #include "theory/rewriter.h"
29 #include "theory/strings/theory_strings_rewriter.h"
30 #include "theory/strings/type_enumerator.h"
31 #include "theory/theory_model.h"
32 #include "theory/valuation.h"
35 using namespace CVC4::context
;
36 using namespace CVC4::kind
;
42 std::ostream
& operator<<(std::ostream
& out
, Inference i
)
46 case INFER_SSPLIT_CST_PROP
: out
<< "S-Split(CST-P)-prop"; break;
47 case INFER_SSPLIT_VAR_PROP
: out
<< "S-Split(VAR)-prop"; break;
48 case INFER_LEN_SPLIT
: out
<< "Len-Split(Len)"; break;
49 case INFER_LEN_SPLIT_EMP
: out
<< "Len-Split(Emp)"; break;
50 case INFER_SSPLIT_CST_BINARY
: out
<< "S-Split(CST-P)-binary"; break;
51 case INFER_SSPLIT_CST
: out
<< "S-Split(CST-P)"; break;
52 case INFER_SSPLIT_VAR
: out
<< "S-Split(VAR)"; break;
53 case INFER_FLOOP
: out
<< "F-Loop"; break;
54 default: out
<< "?"; break;
59 std::ostream
& operator<<(std::ostream
& out
, InferStep s
)
63 case BREAK
: out
<< "break"; break;
64 case CHECK_INIT
: out
<< "check_init"; break;
65 case CHECK_CONST_EQC
: out
<< "check_const_eqc"; break;
66 case CHECK_EXTF_EVAL
: out
<< "check_extf_eval"; break;
67 case CHECK_CYCLES
: out
<< "check_cycles"; break;
68 case CHECK_FLAT_FORMS
: out
<< "check_flat_forms"; break;
69 case CHECK_NORMAL_FORMS_EQ
: out
<< "check_normal_forms_eq"; break;
70 case CHECK_NORMAL_FORMS_DEQ
: out
<< "check_normal_forms_deq"; break;
71 case CHECK_CODES
: out
<< "check_codes"; break;
72 case CHECK_LENGTH_EQC
: out
<< "check_length_eqc"; break;
73 case CHECK_EXTF_REDUCTION
: out
<< "check_extf_reduction"; break;
74 case CHECK_MEMBERSHIP
: out
<< "check_membership"; break;
75 case CHECK_CARDINALITY
: out
<< "check_cardinality"; break;
76 default: out
<< "?"; break;
81 Node
TheoryStrings::TermIndex::add( TNode n
, unsigned index
, TheoryStrings
* t
, Node er
, std::vector
< Node
>& c
) {
82 if( index
==n
.getNumChildren() ){
83 if( d_data
.isNull() ){
88 Assert( index
<n
.getNumChildren() );
89 TNode nir
= t
->getRepresentative( n
[index
] );
90 //if it is empty, and doing CONCAT, ignore
91 if( nir
==er
&& n
.getKind()==kind::STRING_CONCAT
){
92 return add( n
, index
+1, t
, er
, c
);
95 return d_children
[nir
].add( n
, index
+1, t
, er
, c
);
100 TheoryStrings::TheoryStrings(context::Context
* c
,
101 context::UserContext
* u
,
104 const LogicInfo
& logicInfo
)
105 : Theory(THEORY_STRINGS
, c
, u
, out
, valuation
, logicInfo
),
107 d_equalityEngine(d_notify
, c
, "theory::strings", true),
108 d_conflict(c
, false),
112 d_pregistered_terms_cache(u
),
113 d_registered_terms_cache(u
),
114 d_length_lemma_terms_cache(u
),
115 d_preproc(&d_sk_cache
, u
),
117 d_extf_infer_cache(c
),
118 d_extf_infer_cache_u(u
),
119 d_ee_disequalities(c
),
122 d_proxy_var_to_length(u
),
124 d_has_extf(c
, false),
125 d_has_str_code(false),
126 d_regexp_memberships(c
),
129 d_pos_memberships(c
),
130 d_neg_memberships(c
),
133 d_processed_memberships(c
),
137 d_cardinality_lits(u
),
138 d_curr_cardinality(c
, 0),
140 d_strategy_init(false)
143 getExtTheory()->addFunctionKind(kind::STRING_SUBSTR
);
144 getExtTheory()->addFunctionKind(kind::STRING_STRIDOF
);
145 getExtTheory()->addFunctionKind(kind::STRING_ITOS
);
146 getExtTheory()->addFunctionKind(kind::STRING_STOI
);
147 getExtTheory()->addFunctionKind(kind::STRING_STRREPL
);
148 getExtTheory()->addFunctionKind(kind::STRING_STRCTN
);
149 getExtTheory()->addFunctionKind(kind::STRING_IN_REGEXP
);
150 getExtTheory()->addFunctionKind(kind::STRING_LEQ
);
151 getExtTheory()->addFunctionKind(kind::STRING_CODE
);
153 // The kinds we are treating as function application in congruence
154 d_equalityEngine
.addFunctionKind(kind::STRING_LENGTH
);
155 d_equalityEngine
.addFunctionKind(kind::STRING_CONCAT
);
156 d_equalityEngine
.addFunctionKind(kind::STRING_IN_REGEXP
);
157 d_equalityEngine
.addFunctionKind(kind::STRING_CODE
);
158 if( options::stringLazyPreproc() ){
159 d_equalityEngine
.addFunctionKind(kind::STRING_STRCTN
);
160 d_equalityEngine
.addFunctionKind(kind::STRING_LEQ
);
161 d_equalityEngine
.addFunctionKind(kind::STRING_SUBSTR
);
162 d_equalityEngine
.addFunctionKind(kind::STRING_ITOS
);
163 d_equalityEngine
.addFunctionKind(kind::STRING_STOI
);
164 d_equalityEngine
.addFunctionKind(kind::STRING_STRIDOF
);
165 d_equalityEngine
.addFunctionKind(kind::STRING_STRREPL
);
168 d_zero
= NodeManager::currentNM()->mkConst( Rational( 0 ) );
169 d_one
= NodeManager::currentNM()->mkConst( Rational( 1 ) );
170 d_neg_one
= NodeManager::currentNM()->mkConst(Rational(-1));
171 d_emptyString
= NodeManager::currentNM()->mkConst( ::CVC4::String("") );
172 std::vector
< Node
> nvec
;
173 d_emptyRegexp
= NodeManager::currentNM()->mkNode( kind::REGEXP_EMPTY
, nvec
);
174 d_true
= NodeManager::currentNM()->mkConst( true );
175 d_false
= NodeManager::currentNM()->mkConst( false );
177 d_card_size
= TheoryStringsRewriter::getAlphabetCardinality();
180 TheoryStrings::~TheoryStrings() {
181 for( std::map
< Node
, EqcInfo
* >::iterator it
= d_eqc_info
.begin(); it
!= d_eqc_info
.end(); ++it
){
186 Node
TheoryStrings::getRepresentative( Node t
) {
187 if( d_equalityEngine
.hasTerm( t
) ){
188 return d_equalityEngine
.getRepresentative( t
);
194 bool TheoryStrings::hasTerm( Node a
){
195 return d_equalityEngine
.hasTerm( a
);
198 bool TheoryStrings::areEqual( Node a
, Node b
){
201 }else if( hasTerm( a
) && hasTerm( b
) ){
202 return d_equalityEngine
.areEqual( a
, b
);
208 bool TheoryStrings::areDisequal( Node a
, Node b
){
212 if( hasTerm( a
) && hasTerm( b
) ) {
213 Node ar
= d_equalityEngine
.getRepresentative( a
);
214 Node br
= d_equalityEngine
.getRepresentative( b
);
215 return ( ar
!=br
&& ar
.isConst() && br
.isConst() ) || d_equalityEngine
.areDisequal( ar
, br
, false );
217 Node ar
= getRepresentative( a
);
218 Node br
= getRepresentative( b
);
219 return ar
!=br
&& ar
.isConst() && br
.isConst();
224 bool TheoryStrings::areCareDisequal( TNode x
, TNode y
) {
225 Assert( d_equalityEngine
.hasTerm(x
) );
226 Assert( d_equalityEngine
.hasTerm(y
) );
227 if( d_equalityEngine
.isTriggerTerm(x
, THEORY_STRINGS
) && d_equalityEngine
.isTriggerTerm(y
, THEORY_STRINGS
) ){
228 TNode x_shared
= d_equalityEngine
.getTriggerTermRepresentative(x
, THEORY_STRINGS
);
229 TNode y_shared
= d_equalityEngine
.getTriggerTermRepresentative(y
, THEORY_STRINGS
);
230 EqualityStatus eqStatus
= d_valuation
.getEqualityStatus(x_shared
, y_shared
);
231 if( eqStatus
==EQUALITY_FALSE_AND_PROPAGATED
|| eqStatus
==EQUALITY_FALSE
|| eqStatus
==EQUALITY_FALSE_IN_MODEL
){
238 Node
TheoryStrings::getLengthExp( Node t
, std::vector
< Node
>& exp
, Node te
){
239 Assert( areEqual( t
, te
) );
240 Node lt
= mkLength( te
);
242 // use own length if it exists, leads to shorter explanation
245 EqcInfo
* ei
= getOrMakeEqcInfo( t
, false );
246 Node length_term
= ei
? ei
->d_length_term
: Node::null();
247 if( length_term
.isNull() ){
248 //typically shouldnt be necessary
251 Debug("strings") << "TheoryStrings::getLengthTerm " << t
<< " is " << length_term
<< std::endl
;
252 addToExplanation( length_term
, te
, exp
);
253 return Rewriter::rewrite( NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, length_term
) );
257 Node
TheoryStrings::getLength( Node t
, std::vector
< Node
>& exp
) {
258 return getLengthExp( t
, exp
, t
);
261 void TheoryStrings::setMasterEqualityEngine(eq::EqualityEngine
* eq
) {
262 d_equalityEngine
.setMasterEqualityEngine(eq
);
265 void TheoryStrings::addSharedTerm(TNode t
) {
266 Debug("strings") << "TheoryStrings::addSharedTerm(): "
267 << t
<< " " << t
.getType().isBoolean() << endl
;
268 d_equalityEngine
.addTriggerTerm(t
, THEORY_STRINGS
);
269 if (options::stringExp())
271 getExtTheory()->registerTermRec(t
);
273 Debug("strings") << "TheoryStrings::addSharedTerm() finished" << std::endl
;
276 EqualityStatus
TheoryStrings::getEqualityStatus(TNode a
, TNode b
) {
277 if( d_equalityEngine
.hasTerm(a
) && d_equalityEngine
.hasTerm(b
) ){
278 if (d_equalityEngine
.areEqual(a
, b
)) {
279 // The terms are implied to be equal
280 return EQUALITY_TRUE
;
282 if (d_equalityEngine
.areDisequal(a
, b
, false)) {
283 // The terms are implied to be dis-equal
284 return EQUALITY_FALSE
;
287 return EQUALITY_UNKNOWN
;
290 void TheoryStrings::propagate(Effort e
) {
291 // direct propagation now
294 bool TheoryStrings::propagate(TNode literal
) {
295 Debug("strings-propagate") << "TheoryStrings::propagate(" << literal
<< ")" << std::endl
;
296 // If already in conflict, no more propagation
298 Debug("strings-propagate") << "TheoryStrings::propagate(" << literal
<< "): already in conflict" << std::endl
;
302 bool ok
= d_out
->propagate(literal
);
310 void TheoryStrings::explain(TNode literal
, std::vector
<TNode
>& assumptions
) {
311 Debug("strings-explain") << "Explain " << literal
<< " " << d_conflict
<< std::endl
;
312 bool polarity
= literal
.getKind() != kind::NOT
;
313 TNode atom
= polarity
? literal
: literal
[0];
314 unsigned ps
= assumptions
.size();
315 std::vector
< TNode
> tassumptions
;
316 if (atom
.getKind() == kind::EQUAL
) {
317 if( atom
[0]!=atom
[1] ){
318 Assert( hasTerm( atom
[0] ) );
319 Assert( hasTerm( atom
[1] ) );
320 d_equalityEngine
.explainEquality(atom
[0], atom
[1], polarity
, tassumptions
);
323 d_equalityEngine
.explainPredicate(atom
, polarity
, tassumptions
);
325 for( unsigned i
=0; i
<tassumptions
.size(); i
++ ){
326 if( std::find( assumptions
.begin(), assumptions
.end(), tassumptions
[i
] )==assumptions
.end() ){
327 assumptions
.push_back( tassumptions
[i
] );
330 if (Debug
.isOn("strings-explain-debug"))
332 Debug("strings-explain-debug") << "Explanation for " << literal
<< " was "
334 for (unsigned i
= ps
; i
< assumptions
.size(); i
++)
336 Debug("strings-explain-debug") << " " << assumptions
[i
] << std::endl
;
341 Node
TheoryStrings::explain( TNode literal
){
342 Debug("strings-explain") << "explain called on " << literal
<< std::endl
;
343 std::vector
< TNode
> assumptions
;
344 explain( literal
, assumptions
);
345 if( assumptions
.empty() ){
347 }else if( assumptions
.size()==1 ){
348 return assumptions
[0];
350 return NodeManager::currentNM()->mkNode( kind::AND
, assumptions
);
354 bool TheoryStrings::getCurrentSubstitution( int effort
, std::vector
< Node
>& vars
,
355 std::vector
< Node
>& subs
, std::map
< Node
, std::vector
< Node
> >& exp
) {
356 Trace("strings-subs") << "getCurrentSubstitution, effort = " << effort
<< std::endl
;
357 for( unsigned i
=0; i
<vars
.size(); i
++ ){
359 Trace("strings-subs") << " get subs for " << n
<< "..." << std::endl
;
362 Node mv
= d_valuation
.getModel()->getRepresentative( n
);
363 Trace("strings-subs") << " model val : " << mv
<< std::endl
;
364 subs
.push_back( mv
);
366 Node nr
= getRepresentative( n
);
367 std::map
< Node
, Node
>::iterator itc
= d_eqc_to_const
.find( nr
);
368 if( itc
!=d_eqc_to_const
.end() ){
369 //constant equivalence classes
370 Trace("strings-subs") << " constant eqc : " << d_eqc_to_const_exp
[nr
] << " " << d_eqc_to_const_base
[nr
] << " " << nr
<< std::endl
;
371 subs
.push_back( itc
->second
);
372 if( !d_eqc_to_const_exp
[nr
].isNull() ){
373 exp
[n
].push_back( d_eqc_to_const_exp
[nr
] );
375 if( !d_eqc_to_const_base
[nr
].isNull() ){
376 addToExplanation( n
, d_eqc_to_const_base
[nr
], exp
[n
] );
378 }else if( effort
>=1 && effort
<3 && n
.getType().isString() ){
380 Node ns
= getNormalString( d_normal_forms_base
[nr
], exp
[n
] );
381 subs
.push_back( ns
);
382 Trace("strings-subs") << " normal eqc : " << ns
<< " " << d_normal_forms_base
[nr
] << " " << nr
<< std::endl
;
383 if( !d_normal_forms_base
[nr
].isNull() ) {
384 addToExplanation( n
, d_normal_forms_base
[nr
], exp
[n
] );
388 //Trace("strings-subs") << " representative : " << nr << std::endl;
389 //addToExplanation( n, nr, exp[n] );
390 //subs.push_back( nr );
398 int TheoryStrings::getReduction( int effort
, Node n
, Node
& nr
) {
399 //determine the effort level to process the extf at
400 // 0 - at assertion time, 1+ - after no other reduction is applicable
401 Assert( d_extf_info_tmp
.find( n
)!=d_extf_info_tmp
.end() );
402 if( d_extf_info_tmp
[n
].d_model_active
){
404 // polarity : 1 true, -1 false, 0 neither
406 if (n
.getType().isBoolean() && !d_extf_info_tmp
[n
].d_const
.isNull())
408 pol
= d_extf_info_tmp
[n
].d_const
.getConst
<bool>() ? 1 : -1;
410 if( n
.getKind()==kind::STRING_STRCTN
){
417 std::vector
< Node
> lexp
;
418 Node lenx
= getLength( x
, lexp
);
419 Node lens
= getLength( s
, lexp
);
420 if( areEqual( lenx
, lens
) ){
421 Trace("strings-extf-debug") << " resolve extf : " << n
<< " based on equal lengths disequality." << std::endl
;
422 //we can reduce to disequality when lengths are equal
423 if( !areDisequal( x
, s
) ){
424 lexp
.push_back( lenx
.eqNode(lens
) );
425 lexp
.push_back( n
.negate() );
426 Node xneqs
= x
.eqNode(s
).negate();
427 sendInference( lexp
, xneqs
, "NEG-CTN-EQL", true );
436 if( options::stringLazyPreproc() ){
437 if( n
.getKind()==kind::STRING_SUBSTR
){
439 }else if( n
.getKind()!=kind::STRING_IN_REGEXP
){
444 if( effort
==r_effort
){
445 Node c_n
= pol
==-1 ? n
.negate() : n
;
446 if( d_preproc_cache
.find( c_n
)==d_preproc_cache
.end() ){
447 d_preproc_cache
[ c_n
] = true;
448 Trace("strings-process-debug") << "Process reduction for " << n
<< ", pol = " << pol
<< std::endl
;
449 Kind k
= n
.getKind();
450 if (k
== kind::STRING_STRCTN
&& pol
== 1)
454 //positive contains reduces to a equality
455 Node sk1
= d_sk_cache
.mkSkolemCached(
456 x
, s
, SkolemCache::SK_ID_CTN_PRE
, "sc1");
457 Node sk2
= d_sk_cache
.mkSkolemCached(
458 x
, s
, SkolemCache::SK_ID_CTN_POST
, "sc2");
459 Node eq
= Rewriter::rewrite( x
.eqNode( mkConcat( sk1
, s
, sk2
) ) );
460 std::vector
< Node
> exp_vec
;
461 exp_vec
.push_back( n
);
462 sendInference( d_empty_vec
, exp_vec
, eq
, "POS-CTN", true );
463 //we've reduced this n
464 Trace("strings-extf-debug") << " resolve extf : " << n
<< " based on positive contain reduction." << std::endl
;
467 else if (k
!= kind::STRING_CODE
)
469 Assert(k
== STRING_SUBSTR
|| k
== STRING_STRCTN
|| k
== STRING_STRIDOF
472 || k
== STRING_STRREPL
474 std::vector
< Node
> new_nodes
;
475 Node res
= d_preproc
.simplify( n
, new_nodes
);
477 new_nodes
.push_back( NodeManager::currentNM()->mkNode( kind::EQUAL
, res
, n
) );
478 Node nnlem
= new_nodes
.size()==1 ? new_nodes
[0] : NodeManager::currentNM()->mkNode( kind::AND
, new_nodes
);
479 nnlem
= Rewriter::rewrite( nnlem
);
480 Trace("strings-red-lemma") << "Reduction_" << effort
<< " lemma : " << nnlem
<< std::endl
;
481 Trace("strings-red-lemma") << "...from " << n
<< std::endl
;
482 sendInference( d_empty_vec
, nnlem
, "Reduction", true );
483 //we've reduced this n
484 Trace("strings-extf-debug") << " resolve extf : " << n
<< " based on reduction." << std::endl
;
495 /////////////////////////////////////////////////////////////////////////////
497 /////////////////////////////////////////////////////////////////////////////
500 void TheoryStrings::presolve() {
501 Debug("strings-presolve") << "TheoryStrings::Presolving : get fmf options " << (options::stringFMF() ? "true" : "false") << std::endl
;
502 initializeStrategy();
504 // if strings fmf is enabled, register the strategy
505 if (options::stringFMF())
507 d_sslds
.reset(new StringSumLengthDecisionStrategy(
508 getSatContext(), getUserContext(), d_valuation
));
509 Trace("strings-dstrat-reg")
510 << "presolve: register decision strategy." << std::endl
;
511 std::vector
<Node
> inputVars
;
512 for (NodeSet::const_iterator itr
= d_input_vars
.begin();
513 itr
!= d_input_vars
.end();
516 inputVars
.push_back(*itr
);
518 d_sslds
->initialize(inputVars
);
519 getDecisionManager()->registerStrategy(
520 DecisionManager::STRAT_STRINGS_SUM_LENGTHS
, d_sslds
.get());
525 /////////////////////////////////////////////////////////////////////////////
527 /////////////////////////////////////////////////////////////////////////////
529 bool TheoryStrings::collectModelInfo(TheoryModel
* m
)
531 Trace("strings-model") << "TheoryStrings : Collect model info" << std::endl
;
532 Trace("strings-model") << "TheoryStrings : assertEqualityEngine." << std::endl
;
534 std::set
<Node
> termSet
;
536 // Compute terms appearing in assertions and shared terms
537 computeRelevantTerms(termSet
);
538 // assert the (relevant) portion of the equality engine to the model
539 if (!m
->assertEqualityEngine(&d_equalityEngine
, &termSet
))
544 std::unordered_set
<Node
, NodeHashFunction
> repSet
;
545 NodeManager
* nm
= NodeManager::currentNM();
547 // get the relevant string equivalence classes
548 for (const Node
& s
: termSet
)
550 if (s
.getType().isString())
552 Node r
= getRepresentative(s
);
556 std::vector
<Node
> nodes(repSet
.begin(), repSet
.end());
557 std::map
< Node
, Node
> processed
;
558 std::vector
< std::vector
< Node
> > col
;
559 std::vector
< Node
> lts
;
560 separateByLength( nodes
, col
, lts
);
561 //step 1 : get all values for known lengths
562 std::vector
< Node
> lts_values
;
563 std::map
<unsigned, Node
> values_used
;
564 std::vector
<Node
> len_splits
;
565 for( unsigned i
=0; i
<col
.size(); i
++ ) {
566 Trace("strings-model") << "Checking length for {";
567 for( unsigned j
=0; j
<col
[i
].size(); j
++ ) {
569 Trace("strings-model") << ", ";
571 Trace("strings-model") << col
[i
][j
];
573 Trace("strings-model") << " } (length is " << lts
[i
] << ")" << std::endl
;
575 if( lts
[i
].isConst() ) {
578 else if (!lts
[i
].isNull())
580 // get the model value for lts[i]
581 len_value
= d_valuation
.getModelValue(lts
[i
]);
583 if (len_value
.isNull())
585 lts_values
.push_back(Node::null());
589 Assert(len_value
.getConst
<Rational
>() <= Rational(String::maxSize()),
590 "Exceeded UINT32_MAX in string model");
592 len_value
.getConst
<Rational
>().getNumerator().toUnsignedInt();
593 std::map
<unsigned, Node
>::iterator itvu
= values_used
.find(lvalue
);
594 if (itvu
== values_used
.end())
596 values_used
[lvalue
] = lts
[i
];
600 len_splits
.push_back(lts
[i
].eqNode(itvu
->second
));
602 lts_values
.push_back(len_value
);
605 ////step 2 : assign arbitrary values for unknown lengths?
606 // confirmed by calculus invariant, see paper
607 Trace("strings-model") << "Assign to equivalence classes..." << std::endl
;
608 std::map
<Node
, Node
> pure_eq_assign
;
609 //step 3 : assign values to equivalence classes that are pure variables
610 for( unsigned i
=0; i
<col
.size(); i
++ ){
611 std::vector
< Node
> pure_eq
;
612 Trace("strings-model") << "The (" << col
[i
].size()
613 << ") equivalence classes ";
614 for (const Node
& eqc
: col
[i
])
616 Trace("strings-model") << eqc
<< " ";
617 //check if col[i][j] has only variables
620 Assert(d_normal_forms
.find(eqc
) != d_normal_forms
.end());
621 if (d_normal_forms
[eqc
].size() == 1)
623 // does it have a code and the length of these equivalence classes are
625 if (d_has_str_code
&& lts_values
[i
] == d_one
)
627 EqcInfo
* eip
= getOrMakeEqcInfo(eqc
, false);
628 if (eip
&& !eip
->d_code_term
.get().isNull())
630 // its value must be equal to its code
631 Node ct
= nm
->mkNode(kind::STRING_CODE
, eip
->d_code_term
.get());
632 Node ctv
= d_valuation
.getModelValue(ct
);
634 ctv
.getConst
<Rational
>().getNumerator().toUnsignedInt();
635 Trace("strings-model") << "(code: " << cvalue
<< ") ";
636 std::vector
<unsigned> vec
;
637 vec
.push_back(String::convertCodeToUnsignedInt(cvalue
));
638 Node mv
= nm
->mkConst(String(vec
));
639 pure_eq_assign
[eqc
] = mv
;
640 m
->getEqualityEngine()->addTerm(mv
);
643 pure_eq
.push_back(eqc
);
648 processed
[eqc
] = eqc
;
651 Trace("strings-model") << "have length " << lts_values
[i
] << std::endl
;
653 //assign a new length if necessary
654 if( !pure_eq
.empty() ){
655 if( lts_values
[i
].isNull() ){
656 // start with length two (other lengths have special precendence)
658 while( values_used
.find( lvalue
)!=values_used
.end() ){
661 Trace("strings-model") << "*** Decide to make length of " << lvalue
<< std::endl
;
662 lts_values
[i
] = nm
->mkConst(Rational(lvalue
));
663 values_used
[lvalue
] = Node::null();
665 Trace("strings-model") << "Need to assign values of length " << lts_values
[i
] << " to equivalence classes ";
666 for( unsigned j
=0; j
<pure_eq
.size(); j
++ ){
667 Trace("strings-model") << pure_eq
[j
] << " ";
669 Trace("strings-model") << std::endl
;
671 //use type enumerator
672 Assert(lts_values
[i
].getConst
<Rational
>() <= Rational(String::maxSize()),
673 "Exceeded UINT32_MAX in string model");
674 StringEnumeratorLength
sel(lts_values
[i
].getConst
<Rational
>().getNumerator().toUnsignedInt());
675 for (const Node
& eqc
: pure_eq
)
678 std::map
<Node
, Node
>::iterator itp
= pure_eq_assign
.find(eqc
);
679 if (itp
== pure_eq_assign
.end())
681 Assert( !sel
.isFinished() );
683 while (m
->hasTerm(c
))
686 if (sel
.isFinished())
688 // We are in a case where model construction is impossible due to
689 // an insufficient number of constants of a given length.
691 // Consider an integer equivalence class E whose value is assigned
692 // n in the model. Let { S_1, ..., S_m } be the set of string
693 // equivalence classes such that len( x ) is a member of E for
694 // some member x of each class S1, ...,Sm. Since our calculus is
695 // saturated with respect to cardinality inference (see Liang
696 // et al, Figure 6, CAV 2014), we have that m <= A^n, where A is
697 // the cardinality of our alphabet.
699 // Now, consider the case where there exists two integer
700 // equivalence classes E1 and E2 that are assigned n, and moreover
701 // we did not received notification from arithmetic that E1 = E2.
702 // This typically should never happen, but assume in the following
705 // Now, it may be the case that there are string equivalence
706 // classes { S_1, ..., S_m1 } whose lengths are in E1,
707 // and classes { S'_1, ..., S'_m2 } whose lengths are in E2, where
708 // m1 + m2 > A^n. In this case, we have insufficient strings to
709 // assign to { S_1, ..., S_m1, S'_1, ..., S'_m2 }. If this
710 // happens, we add a split on len( u1 ) = len( u2 ) for some
711 // len( u1 ) in E1, len( u2 ) in E2. We do this for each pair of
712 // integer equivalence classes that are assigned to the same value
714 AlwaysAssert(!len_splits
.empty());
715 for (const Node
& sl
: len_splits
)
717 Node spl
= nm
->mkNode(OR
, sl
, sl
.negate());
730 Trace("strings-model") << "*** Assigned constant " << c
<< " for "
733 if (!m
->assertEquality(eqc
, c
, true))
740 Trace("strings-model") << "String Model : Pure Assigned." << std::endl
;
741 //step 4 : assign constants to all other equivalence classes
742 for( unsigned i
=0; i
<nodes
.size(); i
++ ){
743 if( processed
.find( nodes
[i
] )==processed
.end() ){
744 Assert( d_normal_forms
.find( nodes
[i
] )!=d_normal_forms
.end() );
745 Trace("strings-model") << "Construct model for " << nodes
[i
] << " based on normal form ";
746 for( unsigned j
=0; j
<d_normal_forms
[nodes
[i
]].size(); j
++ ) {
747 if( j
>0 ) Trace("strings-model") << " ++ ";
748 Trace("strings-model") << d_normal_forms
[nodes
[i
]][j
];
749 Node r
= getRepresentative( d_normal_forms
[nodes
[i
]][j
] );
750 if( !r
.isConst() && processed
.find( r
)==processed
.end() ){
751 Trace("strings-model") << "(UNPROCESSED)";
754 Trace("strings-model") << std::endl
;
755 std::vector
< Node
> nc
;
756 for( unsigned j
=0; j
<d_normal_forms
[nodes
[i
]].size(); j
++ ) {
757 Node r
= getRepresentative( d_normal_forms
[nodes
[i
]][j
] );
758 Assert( r
.isConst() || processed
.find( r
)!=processed
.end() );
759 nc
.push_back(r
.isConst() ? r
: processed
[r
]);
761 Node cc
= mkConcat( nc
);
762 Assert( cc
.getKind()==kind::CONST_STRING
);
763 Trace("strings-model") << "*** Determined constant " << cc
<< " for " << nodes
[i
] << std::endl
;
764 processed
[nodes
[i
]] = cc
;
765 if (!m
->assertEquality(nodes
[i
], cc
, true))
771 //Trace("strings-model") << "String Model : Assigned." << std::endl;
772 Trace("strings-model") << "String Model : Finished." << std::endl
;
776 /////////////////////////////////////////////////////////////////////////////
778 /////////////////////////////////////////////////////////////////////////////
781 void TheoryStrings::preRegisterTerm(TNode n
) {
782 if( d_pregistered_terms_cache
.find(n
) == d_pregistered_terms_cache
.end() ) {
783 d_pregistered_terms_cache
.insert(n
);
784 Trace("strings-preregister")
785 << "TheoryString::preregister : " << n
<< std::endl
;
786 //check for logic exceptions
787 Kind k
= n
.getKind();
788 if( !options::stringExp() ){
789 if (k
== kind::STRING_STRIDOF
|| k
== kind::STRING_ITOS
790 || k
== kind::STRING_STOI
791 || k
== kind::STRING_STRREPL
792 || k
== kind::STRING_STRCTN
795 std::stringstream ss
;
796 ss
<< "Term of kind " << k
797 << " not supported in default mode, try --strings-exp";
798 throw LogicException(ss
.str());
804 d_equalityEngine
.addTriggerEquality(n
);
807 case kind::STRING_IN_REGEXP
: {
808 d_out
->requirePhase(n
, true);
809 d_equalityEngine
.addTriggerPredicate(n
);
810 d_equalityEngine
.addTerm(n
[0]);
811 d_equalityEngine
.addTerm(n
[1]);
816 TypeNode tn
= n
.getType();
817 if (tn
.isRegExp() && n
.isVar())
819 std::stringstream ss
;
820 ss
<< "Regular expression variables are not supported.";
821 throw LogicException(ss
.str());
823 if( tn
.isString() ) {
824 // all characters of constants should fall in the alphabet
827 std::vector
<unsigned> vec
= n
.getConst
<String
>().getVec();
828 for (unsigned u
: vec
)
830 if (u
>= d_card_size
)
832 std::stringstream ss
;
833 ss
<< "Characters in string \"" << n
834 << "\" are outside of the given alphabet.";
835 throw LogicException(ss
.str());
839 // if finite model finding is enabled,
840 // then we minimize the length of this term if it is a variable
841 // but not an internally generated Skolem, or a term that does
842 // not belong to this theory.
843 if (options::stringFMF()
844 && (n
.isVar() ? !d_sk_cache
.isSkolem(n
)
845 : kindToTheoryId(k
) != THEORY_STRINGS
))
847 d_input_vars
.insert(n
);
848 Trace("strings-dstrat-reg") << "input variable: " << n
<< std::endl
;
850 d_equalityEngine
.addTerm(n
);
851 } else if (tn
.isBoolean()) {
852 // Get triggered for both equal and dis-equal
853 d_equalityEngine
.addTriggerPredicate(n
);
855 // Function applications/predicates
856 d_equalityEngine
.addTerm(n
);
858 //concat terms do not contribute to theory combination? TODO: verify
859 if (n
.hasOperator() && kindToTheoryId(k
) == THEORY_STRINGS
860 && k
!= kind::STRING_CONCAT
)
862 d_functionsTerms
.push_back( n
);
869 Node
TheoryStrings::expandDefinition(LogicRequest
&logicRequest
, Node node
) {
870 Trace("strings-exp-def") << "TheoryStrings::expandDefinition : " << node
<< std::endl
;
874 void TheoryStrings::check(Effort e
) {
875 if (done() && e
<EFFORT_FULL
) {
879 TimerStat::CodeTimer
checkTimer(d_checkTime
);
884 if( !done() && !hasTerm( d_emptyString
) ) {
885 preRegisterTerm( d_emptyString
);
888 // Trace("strings-process") << "Theory of strings, check : " << e << std::endl;
889 Trace("strings-check") << "Theory of strings, check : " << e
<< std::endl
;
890 while ( !done() && !d_conflict
) {
891 // Get all the assertions
892 Assertion assertion
= get();
893 TNode fact
= assertion
.assertion
;
895 Trace("strings-assertion") << "get assertion: " << fact
<< endl
;
896 polarity
= fact
.getKind() != kind::NOT
;
897 atom
= polarity
? fact
: fact
[0];
899 //assert pending fact
900 assertPendingFact( atom
, polarity
, fact
);
904 Assert(d_strategy_init
);
905 std::map
<Effort
, std::pair
<unsigned, unsigned> >::iterator itsr
=
906 d_strat_steps
.find(e
);
907 if (!d_conflict
&& !d_valuation
.needCheck() && itsr
!= d_strat_steps
.end())
909 Trace("strings-check") << "Theory of strings " << e
<< " effort check "
911 if(Trace
.isOn("strings-eqc")) {
912 for( unsigned t
=0; t
<2; t
++ ) {
913 eq::EqClassesIterator eqcs2_i
= eq::EqClassesIterator( &d_equalityEngine
);
914 Trace("strings-eqc") << (t
==0 ? "STRINGS:" : "OTHER:") << std::endl
;
915 while( !eqcs2_i
.isFinished() ){
916 Node eqc
= (*eqcs2_i
);
917 bool print
= (t
==0 && eqc
.getType().isString() ) || (t
==1 && !eqc
.getType().isString() );
919 eq::EqClassIterator eqc2_i
= eq::EqClassIterator( eqc
, &d_equalityEngine
);
920 Trace("strings-eqc") << "Eqc( " << eqc
<< " ) : { ";
921 while( !eqc2_i
.isFinished() ) {
922 if( (*eqc2_i
)!=eqc
&& (*eqc2_i
).getKind()!=kind::EQUAL
){
923 Trace("strings-eqc") << (*eqc2_i
) << " ";
927 Trace("strings-eqc") << " } " << std::endl
;
928 EqcInfo
* ei
= getOrMakeEqcInfo( eqc
, false );
930 Trace("strings-eqc-debug") << "* Length term : " << ei
->d_length_term
.get() << std::endl
;
931 Trace("strings-eqc-debug") << "* Cardinality lemma k : " << ei
->d_cardinality_lem_k
.get() << std::endl
;
932 Trace("strings-eqc-debug") << "* Normalization length lemma : " << ei
->d_normalized_length
.get() << std::endl
;
937 Trace("strings-eqc") << std::endl
;
939 Trace("strings-eqc") << std::endl
;
941 unsigned sbegin
= itsr
->second
.first
;
942 unsigned send
= itsr
->second
.second
;
943 bool addedLemma
= false;
946 runStrategy(sbegin
, send
);
948 addedFact
= !d_pending
.empty();
949 addedLemma
= !d_lemma_cache
.empty();
952 // repeat if we did not add a lemma or conflict
953 }while( !d_conflict
&& !addedLemma
&& addedFact
);
955 Trace("strings-check") << "Theory of strings done full effort check " << addedLemma
<< " " << d_conflict
<< std::endl
;
957 Trace("strings-check") << "Theory of strings, done check : " << e
<< std::endl
;
958 Assert( d_pending
.empty() );
959 Assert( d_lemma_cache
.empty() );
962 bool TheoryStrings::needsCheckLastEffort() {
963 if( options::stringGuessModel() ){
964 return d_has_extf
.get();
970 void TheoryStrings::checkExtfReductions( int effort
) {
972 //std::vector< Node > nred;
973 //getExtTheory()->doReductions( effort, nred, false );
975 std::vector
< Node
> extf
= getExtTheory()->getActive();
976 Trace("strings-process") << " checking " << extf
.size() << " active extf"
978 for( unsigned i
=0; i
<extf
.size(); i
++ ){
980 Trace("strings-process") << " check " << n
<< ", active in model="
981 << d_extf_info_tmp
[n
].d_model_active
<< std::endl
;
983 int ret
= getReduction( effort
, n
, nr
);
984 Assert( nr
.isNull() );
986 getExtTheory()->markReduced( extf
[i
] );
995 TheoryStrings::EqcInfo::EqcInfo(context::Context
* c
)
998 d_cardinality_lem_k(c
),
999 d_normalized_length(c
)
1003 TheoryStrings::EqcInfo
* TheoryStrings::getOrMakeEqcInfo( Node eqc
, bool doMake
) {
1004 std::map
< Node
, EqcInfo
* >::iterator eqc_i
= d_eqc_info
.find( eqc
);
1005 if( eqc_i
==d_eqc_info
.end() ){
1007 EqcInfo
* ei
= new EqcInfo( getSatContext() );
1008 d_eqc_info
[eqc
] = ei
;
1014 return (*eqc_i
).second
;
1019 /** Conflict when merging two constants */
1020 void TheoryStrings::conflict(TNode a
, TNode b
){
1022 Debug("strings-conflict") << "Making conflict..." << std::endl
;
1025 conflictNode
= explain( a
.eqNode(b
) );
1026 Trace("strings-conflict") << "CONFLICT: Eq engine conflict : " << conflictNode
<< std::endl
;
1027 d_out
->conflict( conflictNode
);
1031 /** called when a new equivalance class is created */
1032 void TheoryStrings::eqNotifyNewClass(TNode t
){
1033 Kind k
= t
.getKind();
1034 if (k
== kind::STRING_LENGTH
|| k
== kind::STRING_CODE
)
1036 Trace("strings-debug") << "New length eqc : " << t
<< std::endl
;
1037 Node r
= d_equalityEngine
.getRepresentative(t
[0]);
1038 EqcInfo
* ei
= getOrMakeEqcInfo( r
, true );
1039 if (k
== kind::STRING_LENGTH
)
1041 ei
->d_length_term
= t
[0];
1045 ei
->d_code_term
= t
[0];
1047 //we care about the length of this string
1048 registerTerm( t
[0], 1 );
1050 //getExtTheory()->registerTerm( t );
1054 /** called when two equivalance classes will merge */
1055 void TheoryStrings::eqNotifyPreMerge(TNode t1
, TNode t2
){
1056 EqcInfo
* e2
= getOrMakeEqcInfo(t2
, false);
1058 EqcInfo
* e1
= getOrMakeEqcInfo( t1
);
1059 //add information from e2 to e1
1060 if( !e2
->d_length_term
.get().isNull() ){
1061 e1
->d_length_term
.set( e2
->d_length_term
);
1063 if (!e2
->d_code_term
.get().isNull())
1065 e1
->d_code_term
.set(e2
->d_code_term
);
1067 if( e2
->d_cardinality_lem_k
.get()>e1
->d_cardinality_lem_k
.get() ) {
1068 e1
->d_cardinality_lem_k
.set( e2
->d_cardinality_lem_k
);
1070 if( !e2
->d_normalized_length
.get().isNull() ){
1071 e1
->d_normalized_length
.set( e2
->d_normalized_length
);
1076 /** called when two equivalance classes have merged */
1077 void TheoryStrings::eqNotifyPostMerge(TNode t1
, TNode t2
) {
1081 /** called when two equivalance classes are disequal */
1082 void TheoryStrings::eqNotifyDisequal(TNode t1
, TNode t2
, TNode reason
) {
1083 if( t1
.getType().isString() ){
1084 //store disequalities between strings, may need to check if their lengths are equal/disequal
1085 d_ee_disequalities
.push_back( t1
.eqNode( t2
) );
1089 void TheoryStrings::addCarePairs( quantifiers::TermArgTrie
* t1
, quantifiers::TermArgTrie
* t2
, unsigned arity
, unsigned depth
) {
1092 Node f1
= t1
->getNodeData();
1093 Node f2
= t2
->getNodeData();
1094 if( !d_equalityEngine
.areEqual( f1
, f2
) ){
1095 Trace("strings-cg-debug") << "TheoryStrings::computeCareGraph(): checking function " << f1
<< " and " << f2
<< std::endl
;
1096 vector
< pair
<TNode
, TNode
> > currentPairs
;
1097 for (unsigned k
= 0; k
< f1
.getNumChildren(); ++ k
) {
1100 Assert( d_equalityEngine
.hasTerm(x
) );
1101 Assert( d_equalityEngine
.hasTerm(y
) );
1102 Assert( !d_equalityEngine
.areDisequal( x
, y
, false ) );
1103 Assert( !areCareDisequal( x
, y
) );
1104 if( !d_equalityEngine
.areEqual( x
, y
) ){
1105 if( d_equalityEngine
.isTriggerTerm(x
, THEORY_STRINGS
) && d_equalityEngine
.isTriggerTerm(y
, THEORY_STRINGS
) ){
1106 TNode x_shared
= d_equalityEngine
.getTriggerTermRepresentative(x
, THEORY_STRINGS
);
1107 TNode y_shared
= d_equalityEngine
.getTriggerTermRepresentative(y
, THEORY_STRINGS
);
1108 currentPairs
.push_back(make_pair(x_shared
, y_shared
));
1112 for (unsigned c
= 0; c
< currentPairs
.size(); ++ c
) {
1113 Trace("strings-cg-pair") << "TheoryStrings::computeCareGraph(): pair : " << currentPairs
[c
].first
<< " " << currentPairs
[c
].second
<< std::endl
;
1114 addCarePair(currentPairs
[c
].first
, currentPairs
[c
].second
);
1120 if( depth
<(arity
-1) ){
1121 //add care pairs internal to each child
1122 for( std::map
< TNode
, quantifiers::TermArgTrie
>::iterator it
= t1
->d_data
.begin(); it
!= t1
->d_data
.end(); ++it
){
1123 addCarePairs( &it
->second
, NULL
, arity
, depth
+1 );
1126 //add care pairs based on each pair of non-disequal arguments
1127 for( std::map
< TNode
, quantifiers::TermArgTrie
>::iterator it
= t1
->d_data
.begin(); it
!= t1
->d_data
.end(); ++it
){
1128 std::map
< TNode
, quantifiers::TermArgTrie
>::iterator it2
= it
;
1130 for( ; it2
!= t1
->d_data
.end(); ++it2
){
1131 if( !d_equalityEngine
.areDisequal(it
->first
, it2
->first
, false) ){
1132 if( !areCareDisequal(it
->first
, it2
->first
) ){
1133 addCarePairs( &it
->second
, &it2
->second
, arity
, depth
+1 );
1139 //add care pairs based on product of indices, non-disequal arguments
1140 for( std::map
< TNode
, quantifiers::TermArgTrie
>::iterator it
= t1
->d_data
.begin(); it
!= t1
->d_data
.end(); ++it
){
1141 for( std::map
< TNode
, quantifiers::TermArgTrie
>::iterator it2
= t2
->d_data
.begin(); it2
!= t2
->d_data
.end(); ++it2
){
1142 if( !d_equalityEngine
.areDisequal(it
->first
, it2
->first
, false) ){
1143 if( !areCareDisequal(it
->first
, it2
->first
) ){
1144 addCarePairs( &it
->second
, &it2
->second
, arity
, depth
+1 );
1153 void TheoryStrings::computeCareGraph(){
1154 //computing the care graph here is probably still necessary, due to operators that take non-string arguments TODO: verify
1155 Trace("strings-cg") << "TheoryStrings::computeCareGraph(): Build term indices..." << std::endl
;
1156 std::map
< Node
, quantifiers::TermArgTrie
> index
;
1157 std::map
< Node
, unsigned > arity
;
1158 unsigned functionTerms
= d_functionsTerms
.size();
1159 for (unsigned i
= 0; i
< functionTerms
; ++ i
) {
1160 TNode f1
= d_functionsTerms
[i
];
1161 Trace("strings-cg") << "...build for " << f1
<< std::endl
;
1162 Node op
= f1
.getOperator();
1163 std::vector
< TNode
> reps
;
1164 bool has_trigger_arg
= false;
1165 for( unsigned j
=0; j
<f1
.getNumChildren(); j
++ ){
1166 reps
.push_back( d_equalityEngine
.getRepresentative( f1
[j
] ) );
1167 if( d_equalityEngine
.isTriggerTerm( f1
[j
], THEORY_STRINGS
) ){
1168 has_trigger_arg
= true;
1171 if( has_trigger_arg
){
1172 index
[op
].addTerm( f1
, reps
);
1173 arity
[op
] = reps
.size();
1177 for( std::map
< Node
, quantifiers::TermArgTrie
>::iterator itii
= index
.begin(); itii
!= index
.end(); ++itii
){
1178 Trace("strings-cg") << "TheoryStrings::computeCareGraph(): Process index " << itii
->first
<< "..." << std::endl
;
1179 addCarePairs( &itii
->second
, NULL
, arity
[ itii
->first
], 0 );
1183 void TheoryStrings::assertPendingFact(Node atom
, bool polarity
, Node exp
) {
1184 Trace("strings-pending") << "Assert pending fact : " << atom
<< " " << polarity
<< " from " << exp
<< std::endl
;
1185 Assert(atom
.getKind() != kind::OR
, "Infer error: a split.");
1186 if( atom
.getKind()==kind::EQUAL
){
1187 Trace("strings-pending-debug") << " Register term" << std::endl
;
1188 for( unsigned j
=0; j
<2; j
++ ) {
1189 if( !d_equalityEngine
.hasTerm( atom
[j
] ) && atom
[j
].getType().isString() ) {
1190 registerTerm( atom
[j
], 0 );
1193 Trace("strings-pending-debug") << " Now assert equality" << std::endl
;
1194 d_equalityEngine
.assertEquality( atom
, polarity
, exp
);
1195 Trace("strings-pending-debug") << " Finished assert equality" << std::endl
;
1197 d_equalityEngine
.assertPredicate( atom
, polarity
, exp
);
1199 if( atom
.getKind()==kind::STRING_IN_REGEXP
){
1200 if( polarity
&& atom
[1].getKind()==kind::REGEXP_RANGE
){
1201 if( d_extf_infer_cache_u
.find( atom
)==d_extf_infer_cache_u
.end() ){
1202 d_extf_infer_cache_u
.insert( atom
);
1203 //length of first argument is one
1204 Node conc
= d_one
.eqNode( NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, atom
[0] ) );
1205 Node lem
= NodeManager::currentNM()->mkNode( kind::OR
, atom
.negate(), conc
);
1206 Trace("strings-lemma") << "Strings::Lemma RE-Range-Len : " << lem
<< std::endl
;
1207 d_out
->lemma( lem
);
1211 //register the atom here, since it may not create a new equivalence class
1212 //getExtTheory()->registerTerm( atom );
1214 Trace("strings-pending-debug") << " Now collect terms" << std::endl
;
1215 // Collect extended function terms in the atom. Notice that we must register
1216 // all extended functions occurring in assertions and shared terms. We
1217 // make a similar call to registerTermRec in addSharedTerm.
1218 getExtTheory()->registerTermRec( atom
);
1219 Trace("strings-pending-debug") << " Finished collect terms" << std::endl
;
1222 void TheoryStrings::doPendingFacts() {
1224 while( !d_conflict
&& i
<d_pending
.size() ) {
1225 Node fact
= d_pending
[i
];
1226 Node exp
= d_pending_exp
[ fact
];
1227 if(fact
.getKind() == kind::AND
) {
1228 for(size_t j
=0; j
<fact
.getNumChildren(); j
++) {
1229 bool polarity
= fact
[j
].getKind() != kind::NOT
;
1230 TNode atom
= polarity
? fact
[j
] : fact
[j
][0];
1231 assertPendingFact(atom
, polarity
, exp
);
1234 bool polarity
= fact
.getKind() != kind::NOT
;
1235 TNode atom
= polarity
? fact
: fact
[0];
1236 assertPendingFact(atom
, polarity
, exp
);
1241 d_pending_exp
.clear();
1244 void TheoryStrings::doPendingLemmas() {
1245 if( !d_conflict
&& !d_lemma_cache
.empty() ){
1246 for( unsigned i
=0; i
<d_lemma_cache
.size(); i
++ ){
1247 Trace("strings-pending") << "Process pending lemma : " << d_lemma_cache
[i
] << std::endl
;
1248 d_out
->lemma( d_lemma_cache
[i
] );
1250 for( std::map
< Node
, bool >::iterator it
= d_pending_req_phase
.begin(); it
!= d_pending_req_phase
.end(); ++it
){
1251 Trace("strings-pending") << "Require phase : " << it
->first
<< ", polarity = " << it
->second
<< std::endl
;
1252 d_out
->requirePhase( it
->first
, it
->second
);
1255 d_lemma_cache
.clear();
1256 d_pending_req_phase
.clear();
1259 bool TheoryStrings::hasProcessed() {
1260 return d_conflict
|| !d_lemma_cache
.empty() || !d_pending
.empty();
1263 void TheoryStrings::addToExplanation( Node a
, Node b
, std::vector
< Node
>& exp
) {
1265 Debug("strings-explain") << "Add to explanation : " << a
<< " == " << b
<< std::endl
;
1266 Assert( areEqual( a
, b
) );
1267 exp
.push_back( a
.eqNode( b
) );
1271 void TheoryStrings::addToExplanation( Node lit
, std::vector
< Node
>& exp
) {
1272 if( !lit
.isNull() ){
1273 exp
.push_back( lit
);
1277 void TheoryStrings::checkInit() {
1279 d_eqc_to_const
.clear();
1280 d_eqc_to_const_base
.clear();
1281 d_eqc_to_const_exp
.clear();
1282 d_eqc_to_len_term
.clear();
1283 d_term_index
.clear();
1284 d_strings_eqc
.clear();
1286 std::map
< Kind
, unsigned > ncongruent
;
1287 std::map
< Kind
, unsigned > congruent
;
1288 d_emptyString_r
= getRepresentative( d_emptyString
);
1289 eq::EqClassesIterator eqcs_i
= eq::EqClassesIterator( &d_equalityEngine
);
1290 while( !eqcs_i
.isFinished() ){
1291 Node eqc
= (*eqcs_i
);
1292 TypeNode tn
= eqc
.getType();
1293 if( !tn
.isRegExp() ){
1294 if( tn
.isString() ){
1295 d_strings_eqc
.push_back( eqc
);
1298 eq::EqClassIterator eqc_i
= eq::EqClassIterator( eqc
, &d_equalityEngine
);
1299 while( !eqc_i
.isFinished() ) {
1302 d_eqc_to_const
[eqc
] = n
;
1303 d_eqc_to_const_base
[eqc
] = n
;
1304 d_eqc_to_const_exp
[eqc
] = Node::null();
1305 }else if( tn
.isInteger() ){
1306 if( n
.getKind()==kind::STRING_LENGTH
){
1307 Node nr
= getRepresentative( n
[0] );
1308 d_eqc_to_len_term
[nr
] = n
[0];
1310 }else if( n
.getNumChildren()>0 ){
1311 Kind k
= n
.getKind();
1312 if( k
!=kind::EQUAL
){
1313 if( d_congruent
.find( n
)==d_congruent
.end() ){
1314 std::vector
< Node
> c
;
1315 Node nc
= d_term_index
[k
].add( n
, 0, this, d_emptyString_r
, c
);
1317 //check if we have inferred a new equality by removal of empty components
1318 if( n
.getKind()==kind::STRING_CONCAT
&& !areEqual( nc
, n
) ){
1319 std::vector
< Node
> exp
;
1320 unsigned count
[2] = { 0, 0 };
1321 while( count
[0]<nc
.getNumChildren() || count
[1]<n
.getNumChildren() ){
1322 //explain empty prefixes
1323 for( unsigned t
=0; t
<2; t
++ ){
1324 Node nn
= t
==0 ? nc
: n
;
1325 while( count
[t
]<nn
.getNumChildren() &&
1326 ( nn
[count
[t
]]==d_emptyString
|| areEqual( nn
[count
[t
]], d_emptyString
) ) ){
1327 if( nn
[count
[t
]]!=d_emptyString
){
1328 exp
.push_back( nn
[count
[t
]].eqNode( d_emptyString
) );
1333 //explain equal components
1334 if( count
[0]<nc
.getNumChildren() ){
1335 Assert( count
[1]<n
.getNumChildren() );
1336 if( nc
[count
[0]]!=n
[count
[1]] ){
1337 exp
.push_back( nc
[count
[0]].eqNode( n
[count
[1]] ) );
1343 //infer the equality
1344 sendInference( exp
, n
.eqNode( nc
), "I_Norm" );
1345 }else if( getExtTheory()->hasFunctionKind( n
.getKind() ) ){
1346 //mark as congruent : only process if neither has been reduced
1347 getExtTheory()->markCongruent( nc
, n
);
1349 //this node is congruent to another one, we can ignore it
1350 Trace("strings-process-debug") << " congruent term : " << n
<< std::endl
;
1351 d_congruent
.insert( n
);
1353 }else if( k
==kind::STRING_CONCAT
&& c
.size()==1 ){
1354 Trace("strings-process-debug") << " congruent term by singular : " << n
<< " " << c
[0] << std::endl
;
1356 if( !areEqual( c
[0], n
) ){
1357 std::vector
< Node
> exp
;
1358 //explain empty components
1359 bool foundNEmpty
= false;
1360 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ){
1361 if( areEqual( n
[i
], d_emptyString
) ){
1362 if( n
[i
]!=d_emptyString
){
1363 exp
.push_back( n
[i
].eqNode( d_emptyString
) );
1366 Assert( !foundNEmpty
);
1368 exp
.push_back( n
[i
].eqNode( c
[0] ) );
1373 AlwaysAssert( foundNEmpty
);
1374 //infer the equality
1375 sendInference( exp
, n
.eqNode( c
[0] ), "I_Norm_S" );
1377 d_congruent
.insert( n
);
1387 if( d_congruent
.find( n
)==d_congruent
.end() ){
1391 Trace("strings-process-debug") << " congruent variable : " << n
<< std::endl
;
1392 d_congruent
.insert( n
);
1401 if( Trace
.isOn("strings-process") ){
1402 for( std::map
< Kind
, TermIndex
>::iterator it
= d_term_index
.begin(); it
!= d_term_index
.end(); ++it
){
1403 Trace("strings-process") << " Terms[" << it
->first
<< "] = " << ncongruent
[it
->first
] << "/" << (congruent
[it
->first
]+ncongruent
[it
->first
]) << std::endl
;
1408 void TheoryStrings::checkConstantEquivalenceClasses()
1412 std::vector
<Node
> vecc
;
1416 Trace("strings-process-debug") << "Check constant equivalence classes..."
1418 prevSize
= d_eqc_to_const
.size();
1419 checkConstantEquivalenceClasses(&d_term_index
[kind::STRING_CONCAT
], vecc
);
1420 } while (!hasProcessed() && d_eqc_to_const
.size() > prevSize
);
1423 void TheoryStrings::checkConstantEquivalenceClasses( TermIndex
* ti
, std::vector
< Node
>& vecc
) {
1424 Node n
= ti
->d_data
;
1426 //construct the constant
1427 Node c
= mkConcat( vecc
);
1428 if( !areEqual( n
, c
) ){
1429 Trace("strings-debug") << "Constant eqc : " << c
<< " for " << n
<< std::endl
;
1430 Trace("strings-debug") << " ";
1431 for( unsigned i
=0; i
<vecc
.size(); i
++ ){
1432 Trace("strings-debug") << vecc
[i
] << " ";
1434 Trace("strings-debug") << std::endl
;
1436 unsigned countc
= 0;
1437 std::vector
< Node
> exp
;
1438 while( count
<n
.getNumChildren() ){
1439 while( count
<n
.getNumChildren() && areEqual( n
[count
], d_emptyString
) ){
1440 addToExplanation( n
[count
], d_emptyString
, exp
);
1443 if( count
<n
.getNumChildren() ){
1444 Trace("strings-debug") << "...explain " << n
[count
] << " " << vecc
[countc
] << std::endl
;
1445 if( !areEqual( n
[count
], vecc
[countc
] ) ){
1446 Node nrr
= getRepresentative( n
[count
] );
1447 Assert( !d_eqc_to_const_exp
[nrr
].isNull() );
1448 addToExplanation( n
[count
], d_eqc_to_const_base
[nrr
], exp
);
1449 exp
.push_back( d_eqc_to_const_exp
[nrr
] );
1451 addToExplanation( n
[count
], vecc
[countc
], exp
);
1457 //exp contains an explanation of n==c
1458 Assert( countc
==vecc
.size() );
1460 sendInference( exp
, n
.eqNode( c
), "I_CONST_MERGE" );
1462 }else if( !hasProcessed() ){
1463 Node nr
= getRepresentative( n
);
1464 std::map
< Node
, Node
>::iterator it
= d_eqc_to_const
.find( nr
);
1465 if( it
==d_eqc_to_const
.end() ){
1466 Trace("strings-debug") << "Set eqc const " << n
<< " to " << c
<< std::endl
;
1467 d_eqc_to_const
[nr
] = c
;
1468 d_eqc_to_const_base
[nr
] = n
;
1469 d_eqc_to_const_exp
[nr
] = mkAnd( exp
);
1470 }else if( c
!=it
->second
){
1472 Trace("strings-debug") << "Conflict, other constant was " << it
->second
<< ", this constant was " << c
<< std::endl
;
1473 if( d_eqc_to_const_exp
[nr
].isNull() ){
1474 // n==c ^ n == c' => false
1475 addToExplanation( n
, it
->second
, exp
);
1477 // n==c ^ n == d_eqc_to_const_base[nr] == c' => false
1478 exp
.push_back( d_eqc_to_const_exp
[nr
] );
1479 addToExplanation( n
, d_eqc_to_const_base
[nr
], exp
);
1481 sendInference( exp
, d_false
, "I_CONST_CONFLICT" );
1484 Trace("strings-debug") << "Duplicate constant." << std::endl
;
1489 for( std::map
< TNode
, TermIndex
>::iterator it
= ti
->d_children
.begin(); it
!= ti
->d_children
.end(); ++it
){
1490 std::map
< Node
, Node
>::iterator itc
= d_eqc_to_const
.find( it
->first
);
1491 if( itc
!=d_eqc_to_const
.end() ){
1492 vecc
.push_back( itc
->second
);
1493 checkConstantEquivalenceClasses( &it
->second
, vecc
);
1495 if( hasProcessed() ){
1502 void TheoryStrings::checkExtfEval( int effort
) {
1503 Trace("strings-extf-list") << "Active extended functions, effort=" << effort
<< " : " << std::endl
;
1504 d_extf_info_tmp
.clear();
1505 bool has_nreduce
= false;
1506 std::vector
< Node
> terms
= getExtTheory()->getActive();
1507 std::vector
< Node
> sterms
;
1508 std::vector
< std::vector
< Node
> > exp
;
1509 getExtTheory()->getSubstitutedTerms( effort
, terms
, sterms
, exp
);
1510 for( unsigned i
=0; i
<terms
.size(); i
++ ){
1512 Node sn
= sterms
[i
];
1513 //setup information about extf
1514 ExtfInfoTmp
& einfo
= d_extf_info_tmp
[n
];
1515 Node r
= getRepresentative(n
);
1516 std::map
<Node
, Node
>::iterator itcit
= d_eqc_to_const
.find(r
);
1517 if (itcit
!= d_eqc_to_const
.end())
1519 einfo
.d_const
= itcit
->second
;
1521 Trace("strings-extf-debug") << "Check extf " << n
<< " == " << sn
1522 << ", constant = " << einfo
.d_const
1523 << ", effort=" << effort
<< "..." << std::endl
;
1527 einfo
.d_exp
.insert(einfo
.d_exp
.end(), exp
[i
].begin(), exp
[i
].end());
1528 // inference is rewriting the substituted node
1529 Node nrc
= Rewriter::rewrite( sn
);
1530 Kind nrck
= nrc
.getKind();
1531 //if rewrites to a constant, then do the inference and mark as reduced
1532 if( nrc
.isConst() ){
1534 getExtTheory()->markReduced( n
);
1535 Trace("strings-extf-debug") << " resolvable by evaluation..." << std::endl
;
1536 std::vector
< Node
> exps
;
1537 // The following optimization gets the "symbolic definition" of
1538 // an extended term. The symbolic definition of a term t is a term
1539 // t' where constants are replaced by their corresponding proxy
1541 // For example, if lsym is a proxy variable for "", then
1542 // str.replace( lsym, lsym, lsym ) is the symbolic definition for
1543 // str.replace( "", "", "" ). It is generally better to use symbolic
1544 // definitions when doing cd-rewriting for the purpose of minimizing
1545 // clauses, e.g. we infer the unit equality:
1546 // str.replace( lsym, lsym, lsym ) == ""
1547 // instead of making this inference multiple times:
1548 // x = "" => str.replace( x, x, x ) == ""
1549 // y = "" => str.replace( y, y, y ) == ""
1550 Trace("strings-extf-debug") << " get symbolic definition..." << std::endl
;
1551 Node nrs
= getSymbolicDefinition( sn
, exps
);
1552 if( !nrs
.isNull() ){
1553 Trace("strings-extf-debug") << " rewrite " << nrs
<< "..." << std::endl
;
1554 Node nrsr
= Rewriter::rewrite(nrs
);
1555 // ensure the symbolic form is not rewritable
1558 // we cannot use the symbolic definition if it rewrites
1559 Trace("strings-extf-debug") << " symbolic definition is trivial..." << std::endl
;
1563 Trace("strings-extf-debug") << " could not infer symbolic definition." << std::endl
;
1566 if( !nrs
.isNull() ){
1567 Trace("strings-extf-debug") << " symbolic def : " << nrs
<< std::endl
;
1568 if( !areEqual( nrs
, nrc
) ){
1569 //infer symbolic unit
1570 if( n
.getType().isBoolean() ){
1571 conc
= nrc
==d_true
? nrs
: nrs
.negate();
1573 conc
= nrs
.eqNode( nrc
);
1575 einfo
.d_exp
.clear();
1578 if( !areEqual( n
, nrc
) ){
1579 if( n
.getType().isBoolean() ){
1580 if( areEqual( n
, nrc
==d_true
? d_false
: d_true
) ){
1581 einfo
.d_exp
.push_back(nrc
== d_true
? n
.negate() : n
);
1584 conc
= nrc
==d_true
? n
: n
.negate();
1587 conc
= n
.eqNode( nrc
);
1591 if( !conc
.isNull() ){
1592 Trace("strings-extf") << " resolve extf : " << sn
<< " -> " << nrc
<< std::endl
;
1594 einfo
.d_exp
, conc
, effort
== 0 ? "EXTF" : "EXTF-N", true);
1596 Trace("strings-extf-debug") << " conflict, return." << std::endl
;
1601 //check if it is already equal, if so, mark as reduced. Otherwise, do nothing.
1602 if( areEqual( n
, nrc
) ){
1603 Trace("strings-extf") << " resolved extf, since satisfied by model: " << n
<< std::endl
;
1604 einfo
.d_model_active
= false;
1607 //if it reduces to a conjunction, infer each and reduce
1609 else if ((nrck
== OR
&& einfo
.d_const
== d_false
)
1610 || (nrck
== AND
&& einfo
.d_const
== d_true
))
1613 getExtTheory()->markReduced( n
);
1614 einfo
.d_exp
.push_back(einfo
.d_const
== d_false
? n
.negate() : n
);
1615 Trace("strings-extf-debug") << " decomposable..." << std::endl
;
1616 Trace("strings-extf") << " resolve extf : " << sn
<< " -> " << nrc
1617 << ", const = " << einfo
.d_const
<< std::endl
;
1618 for (const Node
& nrcc
: nrc
)
1620 sendInference(einfo
.d_exp
,
1621 einfo
.d_const
== d_false
? nrcc
.negate() : nrcc
,
1622 effort
== 0 ? "EXTF_d" : "EXTF_d-N");
1628 to_reduce
= sterms
[i
];
1631 if( !to_reduce
.isNull() ){
1634 Trace("strings-extf") << " cannot rewrite extf : " << to_reduce
<< std::endl
;
1636 checkExtfInference(n
, to_reduce
, einfo
, effort
);
1637 if( Trace
.isOn("strings-extf-list") ){
1638 Trace("strings-extf-list") << " * " << to_reduce
;
1639 if (!einfo
.d_const
.isNull())
1641 Trace("strings-extf-list") << ", const = " << einfo
.d_const
;
1644 Trace("strings-extf-list") << ", from " << n
;
1646 Trace("strings-extf-list") << std::endl
;
1648 if (getExtTheory()->isActive(n
) && einfo
.d_model_active
)
1654 d_has_extf
= has_nreduce
;
1657 void TheoryStrings::checkExtfInference( Node n
, Node nr
, ExtfInfoTmp
& in
, int effort
){
1658 if (in
.d_const
.isNull())
1662 NodeManager
* nm
= NodeManager::currentNM();
1663 Trace("strings-extf-infer") << "checkExtfInference: " << n
<< " : " << nr
1664 << " == " << in
.d_const
<< std::endl
;
1666 // add original to explanation
1667 if (n
.getType().isBoolean())
1669 // if Boolean, it's easy
1670 in
.d_exp
.push_back(in
.d_const
.getConst
<bool>() ? n
: n
.negate());
1674 // otherwise, must explain via base node
1675 Node r
= getRepresentative(n
);
1677 // d_eqc_to_const_exp[r] => d_eqc_to_const_base[r] = in.d_const
1679 // n = d_eqc_to_const_base[r] ^ d_eqc_to_const_exp[r] => n = in.d_const
1680 Assert(d_eqc_to_const_base
.find(r
) != d_eqc_to_const_base
.end());
1681 addToExplanation(n
, d_eqc_to_const_base
[r
], in
.d_exp
);
1682 Assert(d_eqc_to_const_exp
.find(r
) != d_eqc_to_const_exp
.end());
1683 in
.d_exp
.insert(in
.d_exp
.end(),
1684 d_eqc_to_const_exp
[r
].begin(),
1685 d_eqc_to_const_exp
[r
].end());
1688 // d_extf_infer_cache stores whether we have made the inferences associated
1690 // this may need to be generalized if multiple inferences apply
1692 if (nr
.getKind() == STRING_STRCTN
)
1694 Assert(in
.d_const
.isConst());
1695 bool pol
= in
.d_const
.getConst
<bool>();
1696 if ((pol
&& nr
[1].getKind() == STRING_CONCAT
)
1697 || (!pol
&& nr
[0].getKind() == STRING_CONCAT
))
1699 // If str.contains( x, str.++( y1, ..., yn ) ),
1700 // we may infer str.contains( x, y1 ), ..., str.contains( x, yn )
1701 // The following recognizes two situations related to the above reasoning:
1702 // (1) If ~str.contains( x, yi ) holds for some i, we are in conflict,
1703 // (2) If str.contains( x, yj ) already holds for some j, then the term
1704 // str.contains( x, yj ) is irrelevant since it is satisfied by all models
1705 // for str.contains( x, str.++( y1, ..., yn ) ).
1707 // Notice that the dual of the above reasoning also holds, i.e.
1708 // If ~str.contains( str.++( x1, ..., xn ), y ),
1709 // we may infer ~str.contains( x1, y ), ..., ~str.contains( xn, y )
1710 // This is also handled here.
1711 if (d_extf_infer_cache
.find(nr
) == d_extf_infer_cache
.end())
1713 d_extf_infer_cache
.insert(nr
);
1715 int index
= pol
? 1 : 0;
1716 std::vector
<Node
> children
;
1717 children
.push_back(nr
[0]);
1718 children
.push_back(nr
[1]);
1719 for (const Node
& nrc
: nr
[index
])
1721 children
[index
] = nrc
;
1722 Node conc
= nm
->mkNode(STRING_STRCTN
, children
);
1723 conc
= Rewriter::rewrite(pol
? conc
: conc
.negate());
1724 // check if it already (does not) hold
1727 if (areEqual(conc
, d_false
))
1729 // we are in conflict
1730 sendInference(in
.d_exp
, conc
, "CTN_Decompose");
1732 else if (getExtTheory()->hasFunctionKind(conc
.getKind()))
1734 // can mark as reduced, since model for n implies model for conc
1735 getExtTheory()->markReduced(conc
);
1743 if (std::find(d_extf_info_tmp
[nr
[0]].d_ctn
[pol
].begin(),
1744 d_extf_info_tmp
[nr
[0]].d_ctn
[pol
].end(),
1746 == d_extf_info_tmp
[nr
[0]].d_ctn
[pol
].end())
1748 Trace("strings-extf-debug") << " store contains info : " << nr
[0]
1749 << " " << pol
<< " " << nr
[1] << std::endl
;
1750 // Store s (does not) contains t, since nr = (~)contains( s, t ) holds.
1751 d_extf_info_tmp
[nr
[0]].d_ctn
[pol
].push_back(nr
[1]);
1752 d_extf_info_tmp
[nr
[0]].d_ctn_from
[pol
].push_back(n
);
1753 // Do transistive closure on contains, e.g.
1754 // if contains( s, t ) and ~contains( s, r ), then ~contains( t, r ).
1756 // The following infers new (negative) contains based on the above
1757 // reasoning, provided that ~contains( t, r ) does not
1758 // already hold in the current context. We test this by checking that
1759 // contains( t, r ) is not already asserted false in the current
1760 // context. We also handle the case where contains( t, r ) is equivalent
1761 // to t = r, in which case we check that t != r does not already hold
1762 // in the current context.
1764 // Notice that form of the above inference is enough to find
1765 // conflicts purely due to contains predicates. For example, if we
1766 // have only positive occurrences of contains, then no conflicts due to
1767 // contains predicates are possible and this schema does nothing. For
1768 // example, note that contains( s, t ) and contains( t, r ) implies
1769 // contains( s, r ), which we could but choose not to infer. Instead,
1770 // we prefer being lazy: only if ~contains( s, r ) appears later do we
1771 // infer ~contains( t, r ), which suffices to show a conflict.
1773 for (unsigned i
= 0, size
= d_extf_info_tmp
[nr
[0]].d_ctn
[opol
].size();
1777 Node onr
= d_extf_info_tmp
[nr
[0]].d_ctn
[opol
][i
];
1779 nm
->mkNode(STRING_STRCTN
, pol
? nr
[1] : onr
, pol
? onr
: nr
[1]);
1780 conc
= Rewriter::rewrite(conc
);
1781 conc
= conc
.negate();
1782 bool do_infer
= false;
1783 bool pol
= conc
.getKind() != NOT
;
1784 Node lit
= pol
? conc
: conc
[0];
1785 if (lit
.getKind() == EQUAL
)
1787 do_infer
= pol
? !areEqual(lit
[0], lit
[1])
1788 : !areDisequal(lit
[0], lit
[1]);
1792 do_infer
= !areEqual(lit
, pol
? d_true
: d_false
);
1796 std::vector
<Node
> exp_c
;
1797 exp_c
.insert(exp_c
.end(), in
.d_exp
.begin(), in
.d_exp
.end());
1798 Node ofrom
= d_extf_info_tmp
[nr
[0]].d_ctn_from
[opol
][i
];
1799 Assert(d_extf_info_tmp
.find(ofrom
) != d_extf_info_tmp
.end());
1800 exp_c
.insert(exp_c
.end(),
1801 d_extf_info_tmp
[ofrom
].d_exp
.begin(),
1802 d_extf_info_tmp
[ofrom
].d_exp
.end());
1803 sendInference(exp_c
, conc
, "CTN_Trans");
1809 // If we already know that s (does not) contain t, then n is redundant.
1810 // For example, if str.contains( x, y ), str.contains( z, y ), and x=z
1811 // are asserted in the current context, then str.contains( z, y ) is
1812 // satisfied by all models of str.contains( x, y ) ^ x=z and thus can
1814 Trace("strings-extf-debug") << " redundant." << std::endl
;
1815 getExtTheory()->markReduced(n
);
1821 // If it's not a predicate, see if we can solve the equality n = c, where c
1822 // is the constant that extended term n is equal to.
1823 Node inferEq
= nr
.eqNode(in
.d_const
);
1824 Node inferEqr
= Rewriter::rewrite(inferEq
);
1825 Node inferEqrr
= inferEqr
;
1826 if (inferEqr
.getKind() == EQUAL
)
1828 // try to use the extended rewriter for equalities
1829 inferEqrr
= TheoryStringsRewriter::rewriteEqualityExt(inferEqr
);
1831 if (inferEqrr
!= inferEqr
)
1833 inferEqrr
= Rewriter::rewrite(inferEqrr
);
1834 Trace("strings-extf-infer") << "checkExtfInference: " << inferEq
1835 << " ...reduces to " << inferEqrr
<< std::endl
;
1836 sendInternalInference(in
.d_exp
, inferEqrr
, "EXTF_equality_rew");
1840 Node
TheoryStrings::getSymbolicDefinition( Node n
, std::vector
< Node
>& exp
) {
1841 if( n
.getNumChildren()==0 ){
1842 NodeNodeMap::const_iterator it
= d_proxy_var
.find( n
);
1843 if( it
==d_proxy_var
.end() ){
1844 return Node::null();
1846 Node eq
= n
.eqNode( (*it
).second
);
1847 eq
= Rewriter::rewrite( eq
);
1848 if( std::find( exp
.begin(), exp
.end(), eq
)==exp
.end() ){
1849 exp
.push_back( eq
);
1851 return (*it
).second
;
1854 std::vector
< Node
> children
;
1855 if (n
.getMetaKind() == kind::metakind::PARAMETERIZED
) {
1856 children
.push_back( n
.getOperator() );
1858 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ){
1859 if( n
.getKind()==kind::STRING_IN_REGEXP
&& i
==1 ){
1860 children
.push_back( n
[i
] );
1862 Node ns
= getSymbolicDefinition( n
[i
], exp
);
1864 return Node::null();
1866 children
.push_back( ns
);
1870 return NodeManager::currentNM()->mkNode( n
.getKind(), children
);
1874 Node
TheoryStrings::getConstantEqc( Node eqc
) {
1875 std::map
< Node
, Node
>::iterator it
= d_eqc_to_const
.find( eqc
);
1876 if( it
!=d_eqc_to_const
.end() ){
1879 return Node::null();
1883 void TheoryStrings::debugPrintFlatForms( const char * tc
){
1884 for( unsigned k
=0; k
<d_strings_eqc
.size(); k
++ ){
1885 Node eqc
= d_strings_eqc
[k
];
1886 if( d_eqc
[eqc
].size()>1 ){
1887 Trace( tc
) << "EQC [" << eqc
<< "]" << std::endl
;
1889 Trace( tc
) << "eqc [" << eqc
<< "]";
1891 std::map
< Node
, Node
>::iterator itc
= d_eqc_to_const
.find( eqc
);
1892 if( itc
!=d_eqc_to_const
.end() ){
1893 Trace( tc
) << " C: " << itc
->second
;
1894 if( d_eqc
[eqc
].size()>1 ){
1895 Trace( tc
) << std::endl
;
1898 if( d_eqc
[eqc
].size()>1 ){
1899 for( unsigned i
=0; i
<d_eqc
[eqc
].size(); i
++ ){
1900 Node n
= d_eqc
[eqc
][i
];
1902 for( unsigned j
=0; j
<d_flat_form
[n
].size(); j
++ ){
1903 Node fc
= d_flat_form
[n
][j
];
1904 itc
= d_eqc_to_const
.find( fc
);
1906 if( itc
!=d_eqc_to_const
.end() ){
1907 Trace( tc
) << itc
->second
;
1913 Trace( tc
) << ", from " << n
;
1915 Trace( tc
) << std::endl
;
1918 Trace( tc
) << std::endl
;
1921 Trace( tc
) << std::endl
;
1924 void TheoryStrings::debugPrintNormalForms( const char * tc
) {
1927 struct sortConstLength
{
1928 std::map
< Node
, unsigned > d_const_length
;
1929 bool operator() (Node i
, Node j
) {
1930 std::map
< Node
, unsigned >::iterator it_i
= d_const_length
.find( i
);
1931 std::map
< Node
, unsigned >::iterator it_j
= d_const_length
.find( j
);
1932 if( it_i
==d_const_length
.end() ){
1933 if( it_j
==d_const_length
.end() ){
1939 if( it_j
==d_const_length
.end() ){
1942 return it_i
->second
<it_j
->second
;
1948 void TheoryStrings::checkCycles()
1950 // first check for cycles, while building ordering of equivalence classes
1951 d_flat_form
.clear();
1952 d_flat_form_index
.clear();
1954 //rebuild strings eqc based on acyclic ordering
1955 std::vector
< Node
> eqc
;
1956 eqc
.insert( eqc
.end(), d_strings_eqc
.begin(), d_strings_eqc
.end() );
1957 d_strings_eqc
.clear();
1958 if( options::stringBinaryCsp() ){
1959 //sort: process smallest constants first (necessary if doing binary splits)
1960 sortConstLength scl
;
1961 for( unsigned i
=0; i
<eqc
.size(); i
++ ){
1962 std::map
< Node
, Node
>::iterator itc
= d_eqc_to_const
.find( eqc
[i
] );
1963 if( itc
!=d_eqc_to_const
.end() ){
1964 scl
.d_const_length
[eqc
[i
]] = itc
->second
.getConst
<String
>().size();
1967 std::sort( eqc
.begin(), eqc
.end(), scl
);
1969 for( unsigned i
=0; i
<eqc
.size(); i
++ ){
1970 std::vector
< Node
> curr
;
1971 std::vector
< Node
> exp
;
1972 checkCycles( eqc
[i
], curr
, exp
);
1973 if( hasProcessed() ){
1979 void TheoryStrings::checkFlatForms()
1981 // debug print flat forms
1982 if (Trace
.isOn("strings-ff"))
1984 Trace("strings-ff") << "Flat forms : " << std::endl
;
1985 debugPrintFlatForms("strings-ff");
1988 // inferences without recursively expanding flat forms
1990 //(1) approximate equality by containment, infer conflicts
1991 for (const Node
& eqc
: d_strings_eqc
)
1993 Node c
= getConstantEqc(eqc
);
1996 // if equivalence class is constant, all component constants in flat forms
1997 // must be contained in it, in order
1998 std::map
<Node
, std::vector
<Node
> >::iterator it
= d_eqc
.find(eqc
);
1999 if (it
!= d_eqc
.end())
2001 for (const Node
& n
: it
->second
)
2004 if (!TheoryStringsRewriter::canConstantContainList(
2005 c
, d_flat_form
[n
], firstc
, lastc
))
2007 Trace("strings-ff-debug") << "Flat form for " << n
2008 << " cannot be contained in constant "
2010 Trace("strings-ff-debug") << " indices = " << firstc
<< "/"
2011 << lastc
<< std::endl
;
2012 // conflict, explanation is n = base ^ base = c ^ relevant portion
2014 std::vector
<Node
> exp
;
2015 Assert(d_eqc_to_const_base
.find(eqc
) != d_eqc_to_const_base
.end());
2016 addToExplanation(n
, d_eqc_to_const_base
[eqc
], exp
);
2017 Assert(d_eqc_to_const_exp
.find(eqc
) != d_eqc_to_const_exp
.end());
2018 if (!d_eqc_to_const_exp
[eqc
].isNull())
2020 exp
.push_back(d_eqc_to_const_exp
[eqc
]);
2022 for (int e
= firstc
; e
<= lastc
; e
++)
2024 if (d_flat_form
[n
][e
].isConst())
2026 Assert(e
>= 0 && e
< (int)d_flat_form_index
[n
].size());
2027 Assert(d_flat_form_index
[n
][e
] >= 0
2028 && d_flat_form_index
[n
][e
] < (int)n
.getNumChildren());
2030 d_flat_form
[n
][e
], n
[d_flat_form_index
[n
][e
]], exp
);
2033 Node conc
= d_false
;
2034 sendInference(exp
, conc
, "F_NCTN");
2042 //(2) scan lists, unification to infer conflicts and equalities
2043 for (const Node
& eqc
: d_strings_eqc
)
2045 std::map
<Node
, std::vector
<Node
> >::iterator it
= d_eqc
.find(eqc
);
2046 if (it
== d_eqc
.end() || it
->second
.size() <= 1)
2050 // iterate over start index
2051 for (unsigned start
= 0; start
< it
->second
.size() - 1; start
++)
2053 for (unsigned r
= 0; r
< 2; r
++)
2055 bool isRev
= r
== 1;
2056 checkFlatForm(it
->second
, start
, isRev
);
2066 void TheoryStrings::checkFlatForm(std::vector
<Node
>& eqc
,
2071 std::vector
<Node
> inelig
;
2072 for (unsigned i
= 0; i
<= start
; i
++)
2074 inelig
.push_back(eqc
[start
]);
2076 Node a
= eqc
[start
];
2080 std::vector
<Node
> exp
;
2083 unsigned eqc_size
= eqc
.size();
2084 unsigned asize
= d_flat_form
[a
].size();
2087 for (unsigned i
= start
+ 1; i
< eqc_size
; i
++)
2090 if (std::find(inelig
.begin(), inelig
.end(), b
) == inelig
.end())
2092 unsigned bsize
= d_flat_form
[b
].size();
2096 std::vector
<Node
> conc_c
;
2097 for (unsigned j
= count
; j
< bsize
; j
++)
2100 b
[d_flat_form_index
[b
][j
]].eqNode(d_emptyString
));
2102 Assert(!conc_c
.empty());
2103 conc
= mkAnd(conc_c
);
2106 // swap, will enforce is empty past current
2112 inelig
.push_back(eqc
[i
]);
2118 Node curr
= d_flat_form
[a
][count
];
2119 Node curr_c
= getConstantEqc(curr
);
2120 Node ac
= a
[d_flat_form_index
[a
][count
]];
2121 std::vector
<Node
> lexp
;
2122 Node lcurr
= getLength(ac
, lexp
);
2123 for (unsigned i
= 1; i
< eqc_size
; i
++)
2126 if (std::find(inelig
.begin(), inelig
.end(), b
) == inelig
.end())
2128 if (count
== d_flat_form
[b
].size())
2130 inelig
.push_back(b
);
2132 std::vector
<Node
> conc_c
;
2133 for (unsigned j
= count
; j
< asize
; j
++)
2136 a
[d_flat_form_index
[a
][j
]].eqNode(d_emptyString
));
2138 Assert(!conc_c
.empty());
2139 conc
= mkAnd(conc_c
);
2147 Node cc
= d_flat_form
[b
][count
];
2150 Node bc
= b
[d_flat_form_index
[b
][count
]];
2151 inelig
.push_back(b
);
2152 Assert(!areEqual(curr
, cc
));
2153 Node cc_c
= getConstantEqc(cc
);
2154 if (!curr_c
.isNull() && !cc_c
.isNull())
2156 // check for constant conflict
2158 Node s
= TheoryStringsRewriter::splitConstant(
2159 cc_c
, curr_c
, index
, isRev
);
2162 addToExplanation(ac
, d_eqc_to_const_base
[curr
], exp
);
2163 addToExplanation(d_eqc_to_const_exp
[curr
], exp
);
2164 addToExplanation(bc
, d_eqc_to_const_base
[cc
], exp
);
2165 addToExplanation(d_eqc_to_const_exp
[cc
], exp
);
2171 else if ((d_flat_form
[a
].size() - 1) == count
2172 && (d_flat_form
[b
].size() - 1) == count
)
2174 conc
= ac
.eqNode(bc
);
2180 // if lengths are the same, apply LengthEq
2181 std::vector
<Node
> lexp2
;
2182 Node lcc
= getLength(bc
, lexp2
);
2183 if (areEqual(lcurr
, lcc
))
2185 Trace("strings-ff-debug") << "Infer " << ac
<< " == " << bc
2186 << " since " << lcurr
2187 << " == " << lcc
<< std::endl
;
2188 // exp_n.push_back( getLength( curr, true ).eqNode(
2189 // getLength( cc, true ) ) );
2190 Trace("strings-ff-debug") << "Explanation for " << lcurr
2192 for (unsigned j
= 0; j
< lexp
.size(); j
++)
2194 Trace("strings-ff-debug") << lexp
[j
] << std::endl
;
2196 Trace("strings-ff-debug") << "Explanation for " << lcc
2198 for (unsigned j
= 0; j
< lexp2
.size(); j
++)
2200 Trace("strings-ff-debug") << lexp2
[j
] << std::endl
;
2202 exp
.insert(exp
.end(), lexp
.begin(), lexp
.end());
2203 exp
.insert(exp
.end(), lexp2
.begin(), lexp2
.end());
2204 addToExplanation(lcurr
, lcc
, exp
);
2205 conc
= ac
.eqNode(bc
);
2217 Trace("strings-ff-debug")
2218 << "Found inference : " << conc
<< " based on equality " << a
2219 << " == " << b
<< ", " << isRev
<< " " << inf_type
<< std::endl
;
2220 addToExplanation(a
, b
, exp
);
2221 // explain why prefixes up to now were the same
2222 for (unsigned j
= 0; j
< count
; j
++)
2224 Trace("strings-ff-debug") << "Add at " << d_flat_form_index
[a
][j
] << " "
2225 << d_flat_form_index
[b
][j
] << std::endl
;
2227 a
[d_flat_form_index
[a
][j
]], b
[d_flat_form_index
[b
][j
]], exp
);
2229 // explain why other components up to now are empty
2230 for (unsigned t
= 0; t
< 2; t
++)
2232 Node c
= t
== 0 ? a
: b
;
2234 if (inf_type
== 3 || (t
== 1 && inf_type
== 2))
2236 // explain all the empty components for F_EndpointEq, all for
2237 // the short end for F_EndpointEmp
2238 jj
= isRev
? -1 : c
.getNumChildren();
2242 jj
= t
== 0 ? d_flat_form_index
[a
][count
]
2243 : d_flat_form_index
[b
][count
];
2245 int startj
= isRev
? jj
+ 1 : 0;
2246 int endj
= isRev
? c
.getNumChildren() : jj
;
2247 for (int j
= startj
; j
< endj
; j
++)
2249 if (areEqual(c
[j
], d_emptyString
))
2251 addToExplanation(c
[j
], d_emptyString
, exp
);
2255 // notice that F_EndpointEmp is not typically applied, since
2256 // strict prefix equality ( a.b = a ) where a,b non-empty
2257 // is conflicting by arithmetic len(a.b)=len(a)+len(b)!=len(a)
2264 : (inf_type
== 1 ? "F_Unify" : (inf_type
== 2 ? "F_EndpointEmp"
2265 : "F_EndpointEq")));
2273 } while (inelig
.size() < eqc
.size());
2275 for (const Node
& n
: eqc
)
2277 std::reverse(d_flat_form
[n
].begin(), d_flat_form
[n
].end());
2278 std::reverse(d_flat_form_index
[n
].begin(), d_flat_form_index
[n
].end());
2282 Node
TheoryStrings::checkCycles( Node eqc
, std::vector
< Node
>& curr
, std::vector
< Node
>& exp
){
2283 if( std::find( curr
.begin(), curr
.end(), eqc
)!=curr
.end() ){
2286 }else if( std::find( d_strings_eqc
.begin(), d_strings_eqc
.end(), eqc
)==d_strings_eqc
.end() ){
2287 curr
.push_back( eqc
);
2288 //look at all terms in this equivalence class
2289 eq::EqClassIterator eqc_i
= eq::EqClassIterator( eqc
, &d_equalityEngine
);
2290 while( !eqc_i
.isFinished() ) {
2292 if( d_congruent
.find( n
)==d_congruent
.end() ){
2293 if( n
.getKind() == kind::STRING_CONCAT
){
2294 Trace("strings-cycle") << eqc
<< " check term : " << n
<< " in " << eqc
<< std::endl
;
2295 if( eqc
!=d_emptyString_r
){
2296 d_eqc
[eqc
].push_back( n
);
2298 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ){
2299 Node nr
= getRepresentative( n
[i
] );
2300 if( eqc
==d_emptyString_r
){
2301 //for empty eqc, ensure all components are empty
2302 if( nr
!=d_emptyString_r
){
2303 std::vector
< Node
> exp
;
2304 exp
.push_back( n
.eqNode( d_emptyString
) );
2305 sendInference( exp
, n
[i
].eqNode( d_emptyString
), "I_CYCLE_E" );
2306 return Node::null();
2309 if( nr
!=d_emptyString_r
){
2310 d_flat_form
[n
].push_back( nr
);
2311 d_flat_form_index
[n
].push_back( i
);
2313 //for non-empty eqc, recurse and see if we find a loop
2314 Node ncy
= checkCycles( nr
, curr
, exp
);
2315 if( !ncy
.isNull() ){
2316 Trace("strings-cycle") << eqc
<< " cycle: " << ncy
<< " at " << n
<< "[" << i
<< "] : " << n
[i
] << std::endl
;
2317 addToExplanation( n
, eqc
, exp
);
2318 addToExplanation( nr
, n
[i
], exp
);
2320 //can infer all other components must be empty
2321 for( unsigned j
=0; j
<n
.getNumChildren(); j
++ ){
2322 //take first non-empty
2323 if( j
!=i
&& !areEqual( n
[j
], d_emptyString
) ){
2324 sendInference( exp
, n
[j
].eqNode( d_emptyString
), "I_CYCLE" );
2325 return Node::null();
2328 Trace("strings-error") << "Looping term should be congruent : " << n
<< " " << eqc
<< " " << ncy
<< std::endl
;
2329 //should find a non-empty component, otherwise would have been singular congruent (I_Norm_S)
2335 if( hasProcessed() ){
2336 return Node::null();
2346 //now we can add it to the list of equivalence classes
2347 d_strings_eqc
.push_back( eqc
);
2351 return Node::null();
2354 void TheoryStrings::checkNormalFormsEq()
2356 if( !options::stringEagerLen() ){
2357 for( unsigned i
=0; i
<d_strings_eqc
.size(); i
++ ) {
2358 Node eqc
= d_strings_eqc
[i
];
2359 eq::EqClassIterator eqc_i
= eq::EqClassIterator( eqc
, &d_equalityEngine
);
2360 while( !eqc_i
.isFinished() ) {
2362 if( d_congruent
.find( n
)==d_congruent
.end() ){
2363 registerTerm( n
, 2 );
2374 // calculate normal forms for each equivalence class, possibly adding
2376 d_normal_forms
.clear();
2377 d_normal_forms_exp
.clear();
2378 std::map
<Node
, Node
> nf_to_eqc
;
2379 std::map
<Node
, Node
> eqc_to_nf
;
2380 std::map
<Node
, Node
> eqc_to_exp
;
2381 for (const Node
& eqc
: d_strings_eqc
)
2383 Trace("strings-process-debug") << "- Verify normal forms are the same for "
2384 << eqc
<< std::endl
;
2385 normalizeEquivalenceClass(eqc
);
2386 Trace("strings-debug") << "Finished normalizing eqc..." << std::endl
;
2391 Node nf_term
= mkConcat(d_normal_forms
[eqc
]);
2392 std::map
<Node
, Node
>::iterator itn
= nf_to_eqc
.find(nf_term
);
2393 if (itn
!= nf_to_eqc
.end())
2395 // two equivalence classes have same normal form, merge
2396 std::vector
<Node
> nf_exp
;
2397 nf_exp
.push_back(mkAnd(d_normal_forms_exp
[eqc
]));
2398 nf_exp
.push_back(eqc_to_exp
[itn
->second
]);
2400 d_normal_forms_base
[eqc
].eqNode(d_normal_forms_base
[itn
->second
]);
2401 sendInference(nf_exp
, eq
, "Normal_Form");
2402 if( hasProcessed() ){
2408 nf_to_eqc
[nf_term
] = eqc
;
2409 eqc_to_nf
[eqc
] = nf_term
;
2410 eqc_to_exp
[eqc
] = mkAnd(d_normal_forms_exp
[eqc
]);
2412 Trace("strings-process-debug")
2413 << "Done verifying normal forms are the same for " << eqc
<< std::endl
;
2415 if (Trace
.isOn("strings-nf"))
2417 Trace("strings-nf") << "**** Normal forms are : " << std::endl
;
2418 for (std::map
<Node
, Node
>::iterator it
= eqc_to_exp
.begin();
2419 it
!= eqc_to_exp
.end();
2422 Trace("strings-nf") << " N[" << it
->first
<< "] (base "
2423 << d_normal_forms_base
[it
->first
]
2424 << ") = " << eqc_to_nf
[it
->first
] << std::endl
;
2425 Trace("strings-nf") << " exp: " << it
->second
<< std::endl
;
2427 Trace("strings-nf") << std::endl
;
2431 void TheoryStrings::checkCodes()
2433 // ensure that lemmas regarding str.code been added for each constant string
2437 NodeManager
* nm
= NodeManager::currentNM();
2438 // str.code applied to the code term for each equivalence class that has a
2439 // code term but is not a constant
2440 std::vector
<Node
> nconst_codes
;
2441 // str.code applied to the proxy variables for each equivalence classes that
2442 // are constants of size one
2443 std::vector
<Node
> const_codes
;
2444 for (const Node
& eqc
: d_strings_eqc
)
2446 if (d_normal_forms
[eqc
].size() == 1 && d_normal_forms
[eqc
][0].isConst())
2448 Node c
= d_normal_forms
[eqc
][0];
2449 Trace("strings-code-debug") << "Get proxy variable for " << c
2451 Node cc
= nm
->mkNode(kind::STRING_CODE
, c
);
2452 cc
= Rewriter::rewrite(cc
);
2453 Assert(cc
.isConst());
2454 NodeNodeMap::const_iterator it
= d_proxy_var
.find(c
);
2455 AlwaysAssert(it
!= d_proxy_var
.end());
2456 Node vc
= nm
->mkNode(kind::STRING_CODE
, (*it
).second
);
2457 if (!areEqual(cc
, vc
))
2459 sendInference(d_empty_vec
, cc
.eqNode(vc
), "Code_Proxy");
2461 const_codes
.push_back(vc
);
2465 EqcInfo
* ei
= getOrMakeEqcInfo(eqc
, false);
2466 if (ei
&& !ei
->d_code_term
.get().isNull())
2468 Node vc
= nm
->mkNode(kind::STRING_CODE
, ei
->d_code_term
.get());
2469 nconst_codes
.push_back(vc
);
2477 // now, ensure that str.code is injective
2478 std::vector
<Node
> cmps
;
2479 cmps
.insert(cmps
.end(), const_codes
.rbegin(), const_codes
.rend());
2480 cmps
.insert(cmps
.end(), nconst_codes
.rbegin(), nconst_codes
.rend());
2481 for (unsigned i
= 0, num_ncc
= nconst_codes
.size(); i
< num_ncc
; i
++)
2483 Node c1
= nconst_codes
[i
];
2485 for (const Node
& c2
: cmps
)
2487 Trace("strings-code-debug")
2488 << "Compare codes : " << c1
<< " " << c2
<< std::endl
;
2489 if (!areDisequal(c1
, c2
) && !areEqual(c1
, d_neg_one
))
2491 Node eq_no
= c1
.eqNode(d_neg_one
);
2492 Node deq
= c1
.eqNode(c2
).negate();
2493 Node eqn
= c1
[0].eqNode(c2
[0]);
2494 // str.code(x)==-1 V str.code(x)!=str.code(y) V x==y
2495 Node inj_lem
= nm
->mkNode(kind::OR
, eq_no
, deq
, eqn
);
2496 sendInference(d_empty_vec
, inj_lem
, "Code_Inj");
2503 //compute d_normal_forms_(base,exp,exp_depend)[eqc]
2504 void TheoryStrings::normalizeEquivalenceClass( Node eqc
) {
2505 Trace("strings-process-debug") << "Process equivalence class " << eqc
<< std::endl
;
2506 if( areEqual( eqc
, d_emptyString
) ) {
2507 #ifdef CVC4_ASSERTIONS
2508 for( unsigned j
=0; j
<d_eqc
[eqc
].size(); j
++ ){
2509 Node n
= d_eqc
[eqc
][j
];
2510 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ){
2511 Assert( areEqual( n
[i
], d_emptyString
) );
2516 Trace("strings-process-debug") << "Return process equivalence class " << eqc
<< " : empty." << std::endl
;
2517 d_normal_forms_base
[eqc
] = d_emptyString
;
2518 d_normal_forms
[eqc
].clear();
2519 d_normal_forms_exp
[eqc
].clear();
2521 Assert( d_normal_forms
.find(eqc
)==d_normal_forms
.end() );
2522 //phi => t = s1 * ... * sn
2523 // normal form for each non-variable term in this eqc (s1...sn)
2524 std::vector
< std::vector
< Node
> > normal_forms
;
2525 // explanation for each normal form (phi)
2526 std::vector
< std::vector
< Node
> > normal_forms_exp
;
2527 // dependency information
2528 std::vector
< std::map
< Node
, std::map
< bool, int > > > normal_forms_exp_depend
;
2529 // record terms for each normal form (t)
2530 std::vector
< Node
> normal_form_src
;
2532 getNormalForms(eqc
, normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
);
2533 if( hasProcessed() ){
2536 // process the normal forms
2537 processNEqc( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
);
2538 if( hasProcessed() ){
2541 //debugPrintNormalForms( "strings-solve", eqc, normal_forms, normal_form_src, normal_forms_exp, normal_forms_exp_depend );
2543 //construct the normal form
2544 Assert( !normal_forms
.empty() );
2547 std::vector
< Node
>::iterator itn
= std::find( normal_form_src
.begin(), normal_form_src
.end(), eqc
);
2548 if( itn
!=normal_form_src
.end() ){
2549 nf_index
= itn
- normal_form_src
.begin();
2550 Trace("strings-solve-debug2") << "take normal form " << nf_index
<< std::endl
;
2551 Assert( normal_form_src
[nf_index
]==eqc
);
2553 //just take the first normal form
2554 Trace("strings-solve-debug2") << "take the first normal form" << std::endl
;
2556 d_normal_forms
[eqc
].insert( d_normal_forms
[eqc
].end(), normal_forms
[nf_index
].begin(), normal_forms
[nf_index
].end() );
2557 d_normal_forms_exp
[eqc
].insert( d_normal_forms_exp
[eqc
].end(), normal_forms_exp
[nf_index
].begin(), normal_forms_exp
[nf_index
].end() );
2558 Trace("strings-solve-debug2") << "take normal form ... done" << std::endl
;
2559 d_normal_forms_base
[eqc
] = normal_form_src
[nf_index
];
2560 //track dependencies
2561 for( unsigned i
=0; i
<normal_forms_exp
[nf_index
].size(); i
++ ){
2562 Node exp
= normal_forms_exp
[nf_index
][i
];
2563 for( unsigned r
=0; r
<2; r
++ ){
2564 d_normal_forms_exp_depend
[eqc
][exp
][r
==0] = normal_forms_exp_depend
[nf_index
][exp
][r
==0];
2567 Trace("strings-process-debug") << "Return process equivalence class " << eqc
<< " : returned, size = " << d_normal_forms
[eqc
].size() << std::endl
;
2571 void trackNfExpDependency( std::vector
< Node
>& nf_exp_n
, std::map
< Node
, std::map
< bool, int > >& nf_exp_depend_n
, Node exp
, int new_val
, int new_rev_val
){
2572 if( std::find( nf_exp_n
.begin(), nf_exp_n
.end(), exp
)==nf_exp_n
.end() ){
2573 nf_exp_n
.push_back( exp
);
2575 for( unsigned k
=0; k
<2; k
++ ){
2576 int val
= k
==0 ? new_val
: new_rev_val
;
2577 std::map
< bool, int >::iterator itned
= nf_exp_depend_n
[exp
].find( k
==1 );
2578 if( itned
==nf_exp_depend_n
[exp
].end() ){
2579 Trace("strings-process-debug") << "Deps : set dependency on " << exp
<< " to " << val
<< " isRev=" << (k
==0) << std::endl
;
2580 nf_exp_depend_n
[exp
][k
==1] = val
;
2582 Trace("strings-process-debug") << "Deps : Multiple dependencies on " << exp
<< " : " << itned
->second
<< " " << val
<< " isRev=" << (k
==0) << std::endl
;
2583 //if we already have a dependency (in the case of non-linear string equalities), it is min/max
2584 bool cmp
= val
> itned
->second
;
2586 nf_exp_depend_n
[exp
][k
==1] = val
;
2592 void TheoryStrings::getNormalForms( Node
&eqc
, std::vector
< std::vector
< Node
> > &normal_forms
, std::vector
< Node
> &normal_form_src
,
2593 std::vector
< std::vector
< Node
> > &normal_forms_exp
, std::vector
< std::map
< Node
, std::map
< bool, int > > >& normal_forms_exp_depend
) {
2594 //constant for equivalence class
2595 Node eqc_non_c
= eqc
;
2596 Trace("strings-process-debug") << "Get normal forms " << eqc
<< std::endl
;
2597 eq::EqClassIterator eqc_i
= eq::EqClassIterator( eqc
, &d_equalityEngine
);
2598 while( !eqc_i
.isFinished() ){
2600 if( d_congruent
.find( n
)==d_congruent
.end() ){
2601 if( n
.getKind() == kind::CONST_STRING
|| n
.getKind() == kind::STRING_CONCAT
){
2602 Trace("strings-process-debug") << "Get Normal Form : Process term " << n
<< " in eqc " << eqc
<< std::endl
;
2603 std::vector
< Node
> nf_n
;
2604 std::vector
< Node
> nf_exp_n
;
2605 std::map
< Node
, std::map
< bool, int > > nf_exp_depend_n
;
2606 if( n
.getKind()==kind::CONST_STRING
){
2607 if( n
!=d_emptyString
) {
2608 nf_n
.push_back( n
);
2610 }else if( n
.getKind()==kind::STRING_CONCAT
){
2611 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ) {
2612 Node nr
= d_equalityEngine
.getRepresentative( n
[i
] );
2613 Trace("strings-process-debug") << "Normalizing subterm " << n
[i
] << " = " << nr
<< std::endl
;
2614 Assert( d_normal_forms
.find( nr
)!=d_normal_forms
.end() );
2615 unsigned orig_size
= nf_n
.size();
2616 unsigned add_size
= d_normal_forms
[nr
].size();
2617 //if not the empty string, add to current normal form
2618 if( !d_normal_forms
[nr
].empty() ){
2619 for( unsigned r
=0; r
<d_normal_forms
[nr
].size(); r
++ ) {
2620 if( Trace
.isOn("strings-error") ) {
2621 if( d_normal_forms
[nr
][r
].getKind()==kind::STRING_CONCAT
){
2622 Trace("strings-error") << "Strings::Error: From eqc = " << eqc
<< ", " << n
<< " index " << i
<< ", bad normal form : ";
2623 for( unsigned rr
=0; rr
<d_normal_forms
[nr
].size(); rr
++ ) {
2624 Trace("strings-error") << d_normal_forms
[nr
][rr
] << " ";
2626 Trace("strings-error") << std::endl
;
2629 Assert( d_normal_forms
[nr
][r
].getKind()!=kind::STRING_CONCAT
);
2631 nf_n
.insert( nf_n
.end(), d_normal_forms
[nr
].begin(), d_normal_forms
[nr
].end() );
2634 for( unsigned j
=0; j
<d_normal_forms_exp
[nr
].size(); j
++ ){
2635 Node exp
= d_normal_forms_exp
[nr
][j
];
2637 trackNfExpDependency( nf_exp_n
, nf_exp_depend_n
, exp
,
2638 orig_size
+ d_normal_forms_exp_depend
[nr
][exp
][false],
2639 orig_size
+ ( add_size
- d_normal_forms_exp_depend
[nr
][exp
][true] ) );
2641 if( d_normal_forms_base
[nr
]!=n
[i
] ){
2642 Assert( d_normal_forms_base
.find( nr
)!=d_normal_forms_base
.end() );
2643 Node eq
= n
[i
].eqNode( d_normal_forms_base
[nr
] );
2644 //track depends : entire current segment is dependent upon base equality
2645 trackNfExpDependency( nf_exp_n
, nf_exp_depend_n
, eq
, orig_size
, orig_size
+ add_size
);
2648 //convert forward indices to reverse indices
2649 int total_size
= nf_n
.size();
2650 for( std::map
< Node
, std::map
< bool, int > >::iterator it
= nf_exp_depend_n
.begin(); it
!= nf_exp_depend_n
.end(); ++it
){
2651 it
->second
[true] = total_size
- it
->second
[true];
2652 Assert( it
->second
[true]>=0 );
2655 //if not equal to self
2656 if( nf_n
.size()>1 || ( nf_n
.size()==1 && nf_n
[0].getKind()==kind::CONST_STRING
) ){
2657 if( nf_n
.size()>1 ) {
2658 for( unsigned i
=0; i
<nf_n
.size(); i
++ ){
2659 if( Trace
.isOn("strings-error") ){
2660 Trace("strings-error") << "Cycle for normal form ";
2661 printConcat(nf_n
,"strings-error");
2662 Trace("strings-error") << "..." << nf_n
[i
] << std::endl
;
2664 Assert( !areEqual( nf_n
[i
], n
) );
2667 normal_forms
.push_back(nf_n
);
2668 normal_form_src
.push_back(n
);
2669 normal_forms_exp
.push_back(nf_exp_n
);
2670 normal_forms_exp_depend
.push_back(nf_exp_depend_n
);
2672 //this was redundant: combination of self + empty string(s)
2673 Node nn
= nf_n
.size()==0 ? d_emptyString
: nf_n
[0];
2674 Assert( areEqual( nn
, eqc
) );
2683 if( normal_forms
.empty() ) {
2684 Trace("strings-solve-debug2") << "construct the normal form" << std::endl
;
2685 //do not choose a concat here use "eqc_non_c" (in this case they have non-trivial explanation why they normalize to self)
2686 std::vector
< Node
> eqc_non_c_nf
;
2687 getConcatVec( eqc_non_c
, eqc_non_c_nf
);
2688 normal_forms
.push_back( eqc_non_c_nf
);
2689 normal_form_src
.push_back( eqc_non_c
);
2690 normal_forms_exp
.push_back( std::vector
< Node
>() );
2691 normal_forms_exp_depend
.push_back( std::map
< Node
, std::map
< bool, int > >() );
2693 if(Trace
.isOn("strings-solve")) {
2694 Trace("strings-solve") << "--- Normal forms for equivalance class " << eqc
<< " : " << std::endl
;
2695 for( unsigned i
=0; i
<normal_forms
.size(); i
++ ) {
2696 Trace("strings-solve") << "#" << i
<< " (from " << normal_form_src
[i
] << ") : ";
2697 for( unsigned j
=0; j
<normal_forms
[i
].size(); j
++ ) {
2699 Trace("strings-solve") << ", ";
2701 Trace("strings-solve") << normal_forms
[i
][j
];
2703 Trace("strings-solve") << std::endl
;
2704 Trace("strings-solve") << " Explanation is : ";
2705 if(normal_forms_exp
[i
].size() == 0) {
2706 Trace("strings-solve") << "NONE";
2708 for( unsigned j
=0; j
<normal_forms_exp
[i
].size(); j
++ ) {
2710 Trace("strings-solve") << " AND ";
2712 Trace("strings-solve") << normal_forms_exp
[i
][j
];
2714 Trace("strings-solve") << std::endl
;
2715 Trace("strings-solve") << "WITH DEPENDENCIES : " << std::endl
;
2716 for( unsigned j
=0; j
<normal_forms_exp
[i
].size(); j
++ ) {
2717 Trace("strings-solve") << " " << normal_forms_exp
[i
][j
] << " -> ";
2718 Trace("strings-solve") << normal_forms_exp_depend
[i
][normal_forms_exp
[i
][j
]][false] << ",";
2719 Trace("strings-solve") << normal_forms_exp_depend
[i
][normal_forms_exp
[i
][j
]][true] << std::endl
;
2722 Trace("strings-solve") << std::endl
;
2726 Trace("strings-solve") << "--- Single normal form for equivalence class " << eqc
<< std::endl
;
2729 //if equivalence class is constant, approximate as containment, infer conflicts
2730 Node c
= getConstantEqc( eqc
);
2732 Trace("strings-solve") << "Eqc is constant " << c
<< std::endl
;
2733 for( unsigned i
=0; i
<normal_forms
.size(); i
++ ) {
2735 if( !TheoryStringsRewriter::canConstantContainList( c
, normal_forms
[i
], firstc
, lastc
) ){
2736 Node n
= normal_form_src
[i
];
2738 Trace("strings-solve") << "Normal form for " << n
<< " cannot be contained in constant " << c
<< std::endl
;
2739 //conflict, explanation is n = base ^ base = c ^ relevant porition of ( n = N[n] )
2740 std::vector
< Node
> exp
;
2741 Assert( d_eqc_to_const_base
.find( eqc
)!=d_eqc_to_const_base
.end() );
2742 addToExplanation( n
, d_eqc_to_const_base
[eqc
], exp
);
2743 Assert( d_eqc_to_const_exp
.find( eqc
)!=d_eqc_to_const_exp
.end() );
2744 if( !d_eqc_to_const_exp
[eqc
].isNull() ){
2745 exp
.push_back( d_eqc_to_const_exp
[eqc
] );
2747 //TODO: this can be minimized based on firstc/lastc, normal_forms_exp_depend
2748 exp
.insert( exp
.end(), normal_forms_exp
[i
].begin(), normal_forms_exp
[i
].end() );
2749 Node conc
= d_false
;
2750 sendInference( exp
, conc
, "N_NCTN" );
2757 void TheoryStrings::getExplanationVectorForPrefix( std::vector
< std::vector
< Node
> > &normal_forms_exp
, std::vector
< std::map
< Node
, std::map
< bool, int > > >& normal_forms_exp_depend
,
2758 unsigned i
, int index
, bool isRev
, std::vector
< Node
>& curr_exp
) {
2759 if( index
==-1 || !options::stringMinPrefixExplain() ){
2760 curr_exp
.insert(curr_exp
.end(), normal_forms_exp
[i
].begin(), normal_forms_exp
[i
].end() );
2762 for( unsigned k
=0; k
<normal_forms_exp
[i
].size(); k
++ ){
2763 Node exp
= normal_forms_exp
[i
][k
];
2764 int dep
= normal_forms_exp_depend
[i
][exp
][isRev
];
2766 curr_exp
.push_back( exp
);
2767 Trace("strings-explain-prefix-debug") << " include : " << exp
<< std::endl
;
2769 Trace("strings-explain-prefix-debug") << " exclude : " << exp
<< std::endl
;
2775 void TheoryStrings::getExplanationVectorForPrefixEq( std::vector
< std::vector
< Node
> > &normal_forms
, std::vector
< Node
> &normal_form_src
,
2776 std::vector
< std::vector
< Node
> > &normal_forms_exp
, std::vector
< std::map
< Node
, std::map
< bool, int > > >& normal_forms_exp_depend
,
2777 unsigned i
, unsigned j
, int index_i
, int index_j
, bool isRev
, std::vector
< Node
>& curr_exp
) {
2778 Trace("strings-explain-prefix") << "Get explanation for prefix " << index_i
<< ", " << index_j
<< " of normal forms " << i
<< " and " << j
<< ", reverse = " << isRev
<< std::endl
;
2779 for( unsigned r
=0; r
<2; r
++ ){
2780 getExplanationVectorForPrefix( normal_forms_exp
, normal_forms_exp_depend
, r
==0 ? i
: j
, r
==0 ? index_i
: index_j
, isRev
, curr_exp
);
2782 Trace("strings-explain-prefix") << "Included " << curr_exp
.size() << " / " << ( normal_forms_exp
[i
].size() + normal_forms_exp
[j
].size() ) << std::endl
;
2783 addToExplanation( normal_form_src
[i
], normal_form_src
[j
], curr_exp
);
2787 void TheoryStrings::processNEqc( std::vector
< std::vector
< Node
> > &normal_forms
, std::vector
< Node
> &normal_form_src
,
2788 std::vector
< std::vector
< Node
> > &normal_forms_exp
, std::vector
< std::map
< Node
, std::map
< bool, int > > >& normal_forms_exp_depend
){
2789 //the possible inferences
2790 std::vector
< InferInfo
> pinfer
;
2791 // loop over all pairs
2792 for(unsigned i
=0; i
<normal_forms
.size()-1; i
++) {
2793 //unify each normalform[j] with normal_forms[i]
2794 for(unsigned j
=i
+1; j
<normal_forms
.size(); j
++ ) {
2795 //ensure that normal_forms[i] and normal_forms[j] are the same modulo equality, add to pinfer if not
2796 Trace("strings-solve") << "Strings: Process normal form #" << i
<< " against #" << j
<< "..." << std::endl
;
2797 if( isNormalFormPair( normal_form_src
[i
], normal_form_src
[j
] ) ) {
2798 Trace("strings-solve") << "Strings: Already cached." << std::endl
;
2800 //process the reverse direction first (check for easy conflicts and inferences)
2801 unsigned rindex
= 0;
2802 processReverseNEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, rindex
, 0, pinfer
);
2803 if( hasProcessed() ){
2805 }else if( !pinfer
.empty() && pinfer
.back().d_id
==1 ){
2808 //AJR: for less aggressive endpoint inference
2812 processSimpleNEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, index
, false, rindex
, pinfer
);
2813 if( hasProcessed() ){
2815 }else if( !pinfer
.empty() && pinfer
.back().d_id
==1 ){
2825 // now, determine which of the possible inferences we want to add
2826 unsigned use_index
= 0;
2827 bool set_use_index
= false;
2828 Trace("strings-solve") << "Possible inferences (" << pinfer
.size()
2829 << ") : " << std::endl
;
2830 unsigned min_id
= 9;
2831 unsigned max_index
= 0;
2832 for (unsigned i
= 0, size
= pinfer
.size(); i
< size
; i
++)
2834 Trace("strings-solve") << "From " << pinfer
[i
].d_i
<< " / " << pinfer
[i
].d_j
2835 << " (rev=" << pinfer
[i
].d_rev
<< ") : ";
2836 Trace("strings-solve") << pinfer
[i
].d_conc
<< " by " << pinfer
[i
].d_id
2838 if (!set_use_index
|| pinfer
[i
].d_id
< min_id
2839 || (pinfer
[i
].d_id
== min_id
&& pinfer
[i
].d_index
> max_index
))
2841 min_id
= pinfer
[i
].d_id
;
2842 max_index
= pinfer
[i
].d_index
;
2844 set_use_index
= true;
2847 // send the inference
2848 if (!pinfer
[use_index
].d_nf_pair
[0].isNull())
2850 Assert(!pinfer
[use_index
].d_nf_pair
[1].isNull());
2851 addNormalFormPair(pinfer
[use_index
].d_nf_pair
[0],
2852 pinfer
[use_index
].d_nf_pair
[1]);
2854 std::stringstream ssi
;
2855 ssi
<< pinfer
[use_index
].d_id
;
2856 sendInference(pinfer
[use_index
].d_ant
,
2857 pinfer
[use_index
].d_antn
,
2858 pinfer
[use_index
].d_conc
,
2860 pinfer
[use_index
].sendAsLemma());
2861 // Register the new skolems from this inference. We register them here
2862 // (lazily), since the code above has now decided to use the inference
2863 // at use_index that involves them.
2864 for (const std::pair
<const LengthStatus
, std::vector
<Node
> >& sks
:
2865 pinfer
[use_index
].d_new_skolem
)
2867 for (const Node
& n
: sks
.second
)
2869 registerLength(n
, sks
.first
);
2874 bool TheoryStrings::InferInfo::sendAsLemma() {
2878 void TheoryStrings::processReverseNEq( std::vector
< std::vector
< Node
> > &normal_forms
, std::vector
< Node
> &normal_form_src
,
2879 std::vector
< std::vector
< Node
> > &normal_forms_exp
, std::vector
< std::map
< Node
, std::map
< bool, int > > >& normal_forms_exp_depend
,
2880 unsigned i
, unsigned j
, unsigned& index
, unsigned rproc
, std::vector
< InferInfo
>& pinfer
) {
2881 //reverse normal form of i, j
2882 std::reverse( normal_forms
[i
].begin(), normal_forms
[i
].end() );
2883 std::reverse( normal_forms
[j
].begin(), normal_forms
[j
].end() );
2885 processSimpleNEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, index
, true, rproc
, pinfer
);
2887 //reverse normal form of i, j
2888 std::reverse( normal_forms
[i
].begin(), normal_forms
[i
].end() );
2889 std::reverse( normal_forms
[j
].begin(), normal_forms
[j
].end() );
2892 //rproc is the # is the size of suffix that is identical
2893 void TheoryStrings::processSimpleNEq( std::vector
< std::vector
< Node
> > &normal_forms
, std::vector
< Node
> &normal_form_src
,
2894 std::vector
< std::vector
< Node
> > &normal_forms_exp
, std::vector
< std::map
< Node
, std::map
< bool, int > > >& normal_forms_exp_depend
,
2895 unsigned i
, unsigned j
, unsigned& index
, bool isRev
, unsigned rproc
, std::vector
< InferInfo
>& pinfer
) {
2896 Assert( rproc
<=normal_forms
[i
].size() && rproc
<=normal_forms
[j
].size() );
2900 //if we are at the end
2901 if( index
==(normal_forms
[i
].size()-rproc
) || index
==(normal_forms
[j
].size()-rproc
) ){
2902 if( index
==(normal_forms
[i
].size()-rproc
) && index
==(normal_forms
[j
].size()-rproc
) ){
2905 //the remainder must be empty
2906 unsigned k
= index
==(normal_forms
[i
].size()-rproc
) ? j
: i
;
2907 unsigned index_k
= index
;
2908 //Node eq_exp = mkAnd( curr_exp );
2909 std::vector
< Node
> curr_exp
;
2910 getExplanationVectorForPrefixEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, -1, -1, isRev
, curr_exp
);
2911 while( !d_conflict
&& index_k
<(normal_forms
[k
].size()-rproc
) ){
2912 //can infer that this string must be empty
2913 Node eq
= normal_forms
[k
][index_k
].eqNode( d_emptyString
);
2914 //Trace("strings-lemma") << "Strings: Infer " << eq << " from " << eq_exp << std::endl;
2915 Assert( !areEqual( d_emptyString
, normal_forms
[k
][index_k
] ) );
2916 sendInference( curr_exp
, eq
, "N_EndpointEmp" );
2921 Trace("strings-solve-debug") << "Process " << normal_forms
[i
][index
] << " ... " << normal_forms
[j
][index
] << std::endl
;
2922 if( normal_forms
[i
][index
]==normal_forms
[j
][index
] ){
2923 Trace("strings-solve-debug") << "Simple Case 1 : strings are equal" << std::endl
;
2927 Assert( !areEqual(normal_forms
[i
][index
], normal_forms
[j
][index
]) );
2928 std::vector
< Node
> temp_exp
;
2929 Node length_term_i
= getLength( normal_forms
[i
][index
], temp_exp
);
2930 Node length_term_j
= getLength( normal_forms
[j
][index
], temp_exp
);
2931 //check length(normal_forms[i][index]) == length(normal_forms[j][index])
2932 if( areEqual( length_term_i
, length_term_j
) ){
2933 Trace("strings-solve-debug") << "Simple Case 2 : string lengths are equal" << std::endl
;
2934 Node eq
= normal_forms
[i
][index
].eqNode( normal_forms
[j
][index
] );
2935 //eq = Rewriter::rewrite( eq );
2936 Node length_eq
= length_term_i
.eqNode( length_term_j
);
2937 //temp_exp.insert(temp_exp.end(), curr_exp.begin(), curr_exp.end() );
2938 getExplanationVectorForPrefixEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, index
, index
, isRev
, temp_exp
);
2939 temp_exp
.push_back(length_eq
);
2940 sendInference( temp_exp
, eq
, "N_Unify" );
2942 }else if( ( normal_forms
[i
][index
].getKind()!=kind::CONST_STRING
&& index
==normal_forms
[i
].size()-rproc
-1 ) ||
2943 ( normal_forms
[j
][index
].getKind()!=kind::CONST_STRING
&& index
==normal_forms
[j
].size()-rproc
-1 ) ){
2944 Trace("strings-solve-debug") << "Simple Case 3 : at endpoint" << std::endl
;
2945 std::vector
< Node
> antec
;
2946 //antec.insert(antec.end(), curr_exp.begin(), curr_exp.end() );
2947 getExplanationVectorForPrefixEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, -1, -1, isRev
, antec
);
2948 std::vector
< Node
> eqn
;
2949 for( unsigned r
=0; r
<2; r
++ ) {
2950 int index_k
= index
;
2951 int k
= r
==0 ? i
: j
;
2952 std::vector
< Node
> eqnc
;
2953 for( unsigned index_l
=index_k
; index_l
<(normal_forms
[k
].size()-rproc
); index_l
++ ) {
2955 eqnc
.insert(eqnc
.begin(), normal_forms
[k
][index_l
] );
2957 eqnc
.push_back( normal_forms
[k
][index_l
] );
2960 eqn
.push_back( mkConcat( eqnc
) );
2962 if( !areEqual( eqn
[0], eqn
[1] ) ){
2963 sendInference( antec
, eqn
[0].eqNode( eqn
[1] ), "N_EndpointEq", true );
2966 Assert( normal_forms
[i
].size()==normal_forms
[j
].size() );
2967 index
= normal_forms
[i
].size()-rproc
;
2969 }else if( normal_forms
[i
][index
].isConst() && normal_forms
[j
][index
].isConst() ){
2970 Node const_str
= normal_forms
[i
][index
];
2971 Node other_str
= normal_forms
[j
][index
];
2972 Trace("strings-solve-debug") << "Simple Case 3 : Const Split : " << const_str
<< " vs " << other_str
<< " at index " << index
<< ", isRev = " << isRev
<< std::endl
;
2973 unsigned len_short
= const_str
.getConst
<String
>().size() <= other_str
.getConst
<String
>().size() ? const_str
.getConst
<String
>().size() : other_str
.getConst
<String
>().size();
2974 bool isSameFix
= isRev
? const_str
.getConst
<String
>().rstrncmp(other_str
.getConst
<String
>(), len_short
): const_str
.getConst
<String
>().strncmp(other_str
.getConst
<String
>(), len_short
);
2976 //same prefix/suffix
2977 //k is the index of the string that is shorter
2978 int k
= const_str
.getConst
<String
>().size()<other_str
.getConst
<String
>().size() ? i
: j
;
2979 int l
= const_str
.getConst
<String
>().size()<other_str
.getConst
<String
>().size() ? j
: i
;
2980 //update the nf exp dependencies
2981 //notice this is not critical for soundness: not doing the below incrementing will only lead to overapproximating when antecedants are required in explanations
2982 for( std::map
< Node
, std::map
< bool, int > >::iterator itnd
= normal_forms_exp_depend
[l
].begin(); itnd
!= normal_forms_exp_depend
[l
].end(); ++itnd
){
2983 for( std::map
< bool, int >::iterator itnd2
= itnd
->second
.begin(); itnd2
!= itnd
->second
.end(); ++itnd2
){
2984 //see if this can be incremented: it can if it is not relevant to the current index
2985 Assert( itnd2
->second
>=0 && itnd2
->second
<=(int)normal_forms
[l
].size() );
2986 bool increment
= (itnd2
->first
==isRev
) ? itnd2
->second
>(int)index
: ( (int)normal_forms
[l
].size()-1-itnd2
->second
)<(int)index
;
2988 normal_forms_exp_depend
[l
][itnd
->first
][itnd2
->first
] = itnd2
->second
+ 1;
2993 int new_len
= normal_forms
[l
][index
].getConst
<String
>().size() - len_short
;
2994 Node remainderStr
= NodeManager::currentNM()->mkConst( normal_forms
[l
][index
].getConst
<String
>().substr(0, new_len
) );
2995 Trace("strings-solve-debug-test") << "Break normal form of " << normal_forms
[l
][index
] << " into " << normal_forms
[k
][index
] << ", " << remainderStr
<< std::endl
;
2996 normal_forms
[l
].insert( normal_forms
[l
].begin()+index
+ 1, remainderStr
);
2998 Node remainderStr
= NodeManager::currentNM()->mkConst(normal_forms
[l
][index
].getConst
<String
>().substr(len_short
));
2999 Trace("strings-solve-debug-test") << "Break normal form of " << normal_forms
[l
][index
] << " into " << normal_forms
[k
][index
] << ", " << remainderStr
<< std::endl
;
3000 normal_forms
[l
].insert( normal_forms
[l
].begin()+index
+ 1, remainderStr
);
3002 normal_forms
[l
][index
] = normal_forms
[k
][index
];
3007 std::vector
< Node
> antec
;
3008 getExplanationVectorForPrefixEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, index
, index
, isRev
, antec
);
3009 sendInference( antec
, d_false
, "N_Const", true );
3013 //construct the candidate inference "info"
3015 info
.d_index
= index
;
3020 bool info_valid
= false;
3021 Assert( index
<normal_forms
[i
].size()-rproc
&& index
<normal_forms
[j
].size()-rproc
);
3022 std::vector
< Node
> lexp
;
3023 Node length_term_i
= getLength( normal_forms
[i
][index
], lexp
);
3024 Node length_term_j
= getLength( normal_forms
[j
][index
], lexp
);
3025 //split on equality between string lengths (note that splitting on equality between strings is worse since it is harder to process)
3026 if( !areDisequal( length_term_i
, length_term_j
) && !areEqual( length_term_i
, length_term_j
) &&
3027 normal_forms
[i
][index
].getKind()!=kind::CONST_STRING
&& normal_forms
[j
][index
].getKind()!=kind::CONST_STRING
){ //AJR: remove the latter 2 conditions?
3028 Trace("strings-solve-debug") << "Non-simple Case 1 : string lengths neither equal nor disequal" << std::endl
;
3029 //try to make the lengths equal via splitting on demand
3030 Node length_eq
= NodeManager::currentNM()->mkNode( kind::EQUAL
, length_term_i
, length_term_j
);
3031 length_eq
= Rewriter::rewrite( length_eq
);
3033 info
.d_conc
= NodeManager::currentNM()->mkNode( kind::OR
, length_eq
, length_eq
.negate() );
3034 info
.d_pending_phase
[ length_eq
] = true;
3035 info
.d_id
= INFER_LEN_SPLIT
;
3038 Trace("strings-solve-debug") << "Non-simple Case 2 : must compare strings" << std::endl
;
3041 if( detectLoop( normal_forms
, i
, j
, index
, loop_in_i
, loop_in_j
, rproc
) ){
3042 if( !isRev
){ //FIXME
3043 getExplanationVectorForPrefixEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, -1, -1, isRev
, info
.d_ant
);
3045 if( processLoop( normal_forms
, normal_form_src
, i
, j
, loop_in_i
!=-1 ? i
: j
, loop_in_i
!=-1 ? j
: i
, loop_in_i
!=-1 ? loop_in_i
: loop_in_j
, index
, info
) ){
3050 //AJR: length entailment here?
3051 if( normal_forms
[i
][index
].getKind() == kind::CONST_STRING
|| normal_forms
[j
][index
].getKind() == kind::CONST_STRING
){
3052 unsigned const_k
= normal_forms
[i
][index
].getKind() == kind::CONST_STRING
? i
: j
;
3053 unsigned nconst_k
= normal_forms
[i
][index
].getKind() == kind::CONST_STRING
? j
: i
;
3054 Node other_str
= normal_forms
[nconst_k
][index
];
3055 Assert( other_str
.getKind()!=kind::CONST_STRING
, "Other string is not constant." );
3056 Assert( other_str
.getKind()!=kind::STRING_CONCAT
, "Other string is not CONCAT." );
3057 if( !d_equalityEngine
.areDisequal( other_str
, d_emptyString
, true ) ){
3058 Node eq
= other_str
.eqNode( d_emptyString
);
3060 info
.d_conc
= NodeManager::currentNM()->mkNode( kind::OR
, eq
, eq
.negate() );
3061 info
.d_id
= INFER_LEN_SPLIT_EMP
;
3064 if( !isRev
){ //FIXME
3065 Node xnz
= other_str
.eqNode( d_emptyString
).negate();
3066 unsigned index_nc_k
= index
+1;
3067 //Node next_const_str = TheoryStringsRewriter::collectConstantStringAt( normal_forms[nconst_k], index_nc_k, false );
3068 unsigned start_index_nc_k
= index
+1;
3069 Node next_const_str
= TheoryStringsRewriter::getNextConstantAt( normal_forms
[nconst_k
], start_index_nc_k
, index_nc_k
, false );
3070 if( !next_const_str
.isNull() ) {
3071 unsigned index_c_k
= index
;
3072 Node const_str
= TheoryStringsRewriter::collectConstantStringAt( normal_forms
[const_k
], index_c_k
, false );
3073 Assert( !const_str
.isNull() );
3074 CVC4::String stra
= const_str
.getConst
<String
>();
3075 CVC4::String strb
= next_const_str
.getConst
<String
>();
3076 //since non-empty, we start with charecter #1
3079 CVC4::String stra1
= stra
.prefix( stra
.size()-1 );
3080 p
= stra
.size() - stra1
.roverlap(strb
);
3081 Trace("strings-csp-debug") << "Compute roverlap : " << const_str
<< " " << next_const_str
<< std::endl
;
3082 size_t p2
= stra1
.rfind(strb
);
3083 p
= p2
==std::string::npos
? p
: ( p
>p2
+1? p2
+1 : p
);
3084 Trace("strings-csp-debug") << "overlap : " << stra1
<< " " << strb
<< " returned " << p
<< " " << p2
<< " " << (p2
==std::string::npos
) << std::endl
;
3086 CVC4::String stra1
= stra
.substr( 1 );
3087 p
= stra
.size() - stra1
.overlap(strb
);
3088 Trace("strings-csp-debug") << "Compute overlap : " << const_str
<< " " << next_const_str
<< std::endl
;
3089 size_t p2
= stra1
.find(strb
);
3090 p
= p2
==std::string::npos
? p
: ( p
>p2
+1? p2
+1 : p
);
3091 Trace("strings-csp-debug") << "overlap : " << stra1
<< " " << strb
<< " returned " << p
<< " " << p2
<< " " << (p2
==std::string::npos
) << std::endl
;
3094 if( start_index_nc_k
==index
+1 ){
3095 info
.d_ant
.push_back( xnz
);
3096 getExplanationVectorForPrefixEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
,
3097 const_k
, nconst_k
, index_c_k
, index_nc_k
, isRev
, info
.d_ant
);
3098 Node prea
= p
==stra
.size() ? const_str
: NodeManager::currentNM()->mkConst( isRev
? stra
.suffix( p
) : stra
.prefix( p
) );
3099 Node sk
= d_sk_cache
.mkSkolemCached(
3102 isRev
? SkolemCache::SK_ID_C_SPT_REV
3103 : SkolemCache::SK_ID_C_SPT
,
3105 Trace("strings-csp") << "Const Split: " << prea
<< " is removed from " << stra
<< " due to " << strb
<< ", p=" << p
<< std::endl
;
3107 info
.d_conc
= other_str
.eqNode( isRev
? mkConcat( sk
, prea
) : mkConcat(prea
, sk
) );
3108 info
.d_new_skolem
[LENGTH_SPLIT
].push_back(sk
);
3109 info
.d_id
= INFER_SSPLIT_CST_PROP
;
3112 /* FIXME for isRev, speculative
3113 else if( options::stringLenPropCsp() ){
3114 //propagate length constraint
3115 std::vector< Node > cc;
3116 for( unsigned i=index; i<start_index_nc_k; i++ ){
3117 cc.push_back( normal_forms[nconst_k][i] );
3119 Node lt = NodeManager::currentNM()->mkNode( kind::STRING_LENGTH, mkConcat( cc ) );
3120 conc = NodeManager::currentNM()->mkNode( kind::GEQ, lt, NodeManager::currentNM()->mkConst( Rational(p) ) );
3121 sendInference( ant, conc, "S-Split(CSP-P)-lprop", true );
3127 info
.d_ant
.push_back( xnz
);
3128 Node const_str
= normal_forms
[const_k
][index
];
3129 getExplanationVectorForPrefixEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, index
, index
, isRev
, info
.d_ant
);
3130 CVC4::String stra
= const_str
.getConst
<String
>();
3131 if( options::stringBinaryCsp() && stra
.size()>3 ){
3132 //split string in half
3133 Node c_firstHalf
= NodeManager::currentNM()->mkConst( isRev
? stra
.substr( stra
.size()/2 ) : stra
.substr(0, stra
.size()/2 ) );
3134 Node sk
= d_sk_cache
.mkSkolemCached(
3137 isRev
? SkolemCache::SK_ID_VC_BIN_SPT_REV
3138 : SkolemCache::SK_ID_VC_BIN_SPT
,
3140 Trace("strings-csp") << "Const Split: " << c_firstHalf
<< " is removed from " << const_str
<< " (binary) " << std::endl
;
3141 info
.d_conc
= NodeManager::currentNM()->mkNode( kind::OR
, other_str
.eqNode( isRev
? mkConcat( sk
, c_firstHalf
) : mkConcat( c_firstHalf
, sk
) ),
3142 NodeManager::currentNM()->mkNode( kind::AND
,
3143 sk
.eqNode( d_emptyString
).negate(),
3144 c_firstHalf
.eqNode( isRev
? mkConcat( sk
, other_str
) : mkConcat( other_str
, sk
) ) ) );
3145 info
.d_new_skolem
[LENGTH_SPLIT
].push_back(sk
);
3146 info
.d_id
= INFER_SSPLIT_CST_BINARY
;
3150 Node firstChar
= stra
.size() == 1 ? const_str
: NodeManager::currentNM()->mkConst( isRev
? stra
.suffix( 1 ) : stra
.prefix( 1 ) );
3151 Node sk
= d_sk_cache
.mkSkolemCached(
3154 isRev
? SkolemCache::SK_ID_VC_SPT_REV
3155 : SkolemCache::SK_ID_VC_SPT
,
3157 Trace("strings-csp") << "Const Split: " << firstChar
<< " is removed from " << const_str
<< " (serial) " << std::endl
;
3158 info
.d_conc
= other_str
.eqNode( isRev
? mkConcat( sk
, firstChar
) : mkConcat(firstChar
, sk
) );
3159 info
.d_new_skolem
[LENGTH_SPLIT
].push_back(sk
);
3160 info
.d_id
= INFER_SSPLIT_CST
;
3167 int lentTestSuccess
= -1;
3169 if( options::stringCheckEntailLen() ){
3171 for( unsigned e
=0; e
<2; e
++ ){
3172 Node t
= e
==0 ? normal_forms
[i
][index
] : normal_forms
[j
][index
];
3173 //do not infer constants are larger than variables
3174 if( t
.getKind()!=kind::CONST_STRING
){
3175 Node lt1
= e
==0 ? length_term_i
: length_term_j
;
3176 Node lt2
= e
==0 ? length_term_j
: length_term_i
;
3177 Node ent_lit
= Rewriter::rewrite( NodeManager::currentNM()->mkNode( kind::GT
, lt1
, lt2
) );
3178 std::pair
<bool, Node
> et
= d_valuation
.entailmentCheck( THEORY_OF_TYPE_BASED
, ent_lit
);
3180 Trace("strings-entail") << "Strings entailment : " << ent_lit
<< " is entailed in the current context." << std::endl
;
3181 Trace("strings-entail") << " explanation was : " << et
.second
<< std::endl
;
3182 lentTestSuccess
= e
;
3183 lentTestExp
= et
.second
;
3190 getExplanationVectorForPrefixEq( normal_forms
, normal_form_src
, normal_forms_exp
, normal_forms_exp_depend
, i
, j
, index
, index
, isRev
, info
.d_ant
);
3192 for(unsigned xory
=0; xory
<2; xory
++) {
3193 Node x
= xory
==0 ? normal_forms
[i
][index
] : normal_forms
[j
][index
];
3194 Node xgtz
= x
.eqNode( d_emptyString
).negate();
3195 if( d_equalityEngine
.areDisequal( x
, d_emptyString
, true ) ) {
3196 info
.d_ant
.push_back( xgtz
);
3198 info
.d_antn
.push_back( xgtz
);
3201 Node sk
= d_sk_cache
.mkSkolemCached(
3202 normal_forms
[i
][index
],
3203 normal_forms
[j
][index
],
3204 isRev
? SkolemCache::SK_ID_V_SPT_REV
3205 : SkolemCache::SK_ID_V_SPT
,
3207 // must add length requirement
3208 info
.d_new_skolem
[LENGTH_GEQ_ONE
].push_back(sk
);
3209 Node eq1
= normal_forms
[i
][index
].eqNode( isRev
? mkConcat(sk
, normal_forms
[j
][index
]) : mkConcat(normal_forms
[j
][index
], sk
) );
3210 Node eq2
= normal_forms
[j
][index
].eqNode( isRev
? mkConcat(sk
, normal_forms
[i
][index
]) : mkConcat(normal_forms
[i
][index
], sk
) );
3212 if( lentTestSuccess
!=-1 ){
3213 info
.d_antn
.push_back( lentTestExp
);
3214 info
.d_conc
= lentTestSuccess
==0 ? eq1
: eq2
;
3215 info
.d_id
= INFER_SSPLIT_VAR_PROP
;
3218 Node ldeq
= NodeManager::currentNM()->mkNode( kind::EQUAL
, length_term_i
, length_term_j
).negate();
3219 if( d_equalityEngine
.areDisequal( length_term_i
, length_term_j
, true ) ){
3220 info
.d_ant
.push_back( ldeq
);
3222 info
.d_antn
.push_back(ldeq
);
3225 info
.d_conc
= NodeManager::currentNM()->mkNode( kind::OR
, eq1
, eq2
);
3226 info
.d_id
= INFER_SSPLIT_VAR
;
3233 pinfer
.push_back( info
);
3242 bool TheoryStrings::detectLoop( std::vector
< std::vector
< Node
> > &normal_forms
, int i
, int j
, int index
, int &loop_in_i
, int &loop_in_j
, unsigned rproc
){
3243 int has_loop
[2] = { -1, -1 };
3244 if( options::stringLB() != 2 ) {
3245 for( unsigned r
=0; r
<2; r
++ ) {
3246 int n_index
= (r
==0 ? i
: j
);
3247 int other_n_index
= (r
==0 ? j
: i
);
3248 if( normal_forms
[other_n_index
][index
].getKind() != kind::CONST_STRING
) {
3249 for( unsigned lp
= index
+1; lp
<normal_forms
[n_index
].size()-rproc
; lp
++ ){
3250 if( normal_forms
[n_index
][lp
]==normal_forms
[other_n_index
][index
] ){
3258 if( has_loop
[0]!=-1 || has_loop
[1]!=-1 ) {
3259 loop_in_i
= has_loop
[0];
3260 loop_in_j
= has_loop
[1];
3263 Trace("strings-solve-debug") << "No loops detected." << std::endl
;
3269 bool TheoryStrings::processLoop( std::vector
< std::vector
< Node
> > &normal_forms
, std::vector
< Node
> &normal_form_src
,
3270 int i
, int j
, int loop_n_index
, int other_n_index
, int loop_index
, int index
, InferInfo
& info
){
3271 if( options::stringAbortLoop() ){
3272 std::stringstream ss
;
3273 ss
<< "Looping word equation encountered." << std::endl
;
3274 throw LogicException(ss
.str());
3276 if (!options::stringProcessLoop())
3278 d_out
->setIncomplete();
3281 NodeManager
* nm
= NodeManager::currentNM();
3283 Trace("strings-loop") << "Detected possible loop for "
3284 << normal_forms
[loop_n_index
][loop_index
] << std::endl
;
3285 Trace("strings-loop") << " ... (X)= " << normal_forms
[other_n_index
][index
]
3288 Trace("strings-loop") << " ... T(Y.Z)= ";
3289 std::vector
<Node
>& veci
= normal_forms
[loop_n_index
];
3290 std::vector
<Node
> vec_t(veci
.begin() + index
, veci
.begin() + loop_index
);
3291 Node t_yz
= mkConcat(vec_t
);
3292 Trace("strings-loop") << " (" << t_yz
<< ")" << std::endl
;
3293 Trace("strings-loop") << " ... S(Z.Y)= ";
3294 std::vector
<Node
>& vecoi
= normal_forms
[other_n_index
];
3295 std::vector
<Node
> vec_s(vecoi
.begin() + index
+ 1, vecoi
.end());
3296 Node s_zy
= mkConcat(vec_s
);
3297 Trace("strings-loop") << s_zy
<< std::endl
;
3298 Trace("strings-loop") << " ... R= ";
3299 std::vector
<Node
> vec_r(veci
.begin() + loop_index
+ 1, veci
.end());
3300 Node r
= mkConcat(vec_r
);
3301 Trace("strings-loop") << r
<< std::endl
;
3303 if (s_zy
.isConst() && r
.isConst() && r
!= d_emptyString
)
3307 if (s_zy
.getConst
<String
>().tailcmp(r
.getConst
<String
>(), c
))
3311 s_zy
= nm
->mkConst(s_zy
.getConst
<String
>().substr(0, c
));
3314 Trace("strings-loop") << "Strings::Loop: Refactor S(Z.Y)= " << s_zy
3315 << ", c=" << c
<< std::endl
;
3321 Trace("strings-loop") << "Strings::Loop: tails are different."
3323 sendInference(info
.d_ant
, conc
, "Loop Conflict", true);
3329 for (unsigned r
= 0; r
< 2; r
++)
3331 Node t
= r
== 0 ? normal_forms
[loop_n_index
][loop_index
] : t_yz
;
3332 split_eq
= t
.eqNode(d_emptyString
);
3333 Node split_eqr
= Rewriter::rewrite(split_eq
);
3334 // the equality could rewrite to false
3335 if (!split_eqr
.isConst())
3337 if (!areDisequal(t
, d_emptyString
))
3339 // try to make t equal to empty to avoid loop
3340 info
.d_conc
= nm
->mkNode(kind::OR
, split_eq
, split_eq
.negate());
3341 info
.d_id
= INFER_LEN_SPLIT_EMP
;
3346 info
.d_ant
.push_back(split_eq
.negate());
3351 Assert(!split_eqr
.getConst
<bool>());
3355 Node ant
= mkExplain(info
.d_ant
);
3357 info
.d_antn
.push_back(ant
);
3360 if (s_zy
== t_yz
&& r
== d_emptyString
&& s_zy
.isConst()
3361 && s_zy
.getConst
<String
>().isRepeated())
3363 Node rep_c
= nm
->mkConst(s_zy
.getConst
<String
>().substr(0, 1));
3364 Trace("strings-loop") << "Special case (X)="
3365 << normal_forms
[other_n_index
][index
] << " "
3367 Trace("strings-loop") << "... (C)=" << rep_c
<< " " << std::endl
;
3370 nm
->mkNode(kind::STRING_IN_REGEXP
,
3371 normal_forms
[other_n_index
][index
],
3372 nm
->mkNode(kind::REGEXP_STAR
,
3373 nm
->mkNode(kind::STRING_TO_REGEXP
, rep_c
)));
3376 else if (t_yz
.isConst())
3378 Trace("strings-loop") << "Strings::Loop: Const Normal Breaking."
3380 CVC4::String s
= t_yz
.getConst
<CVC4::String
>();
3381 unsigned size
= s
.size();
3382 std::vector
<Node
> vconc
;
3383 for (unsigned len
= 1; len
<= size
; len
++)
3385 Node y
= nm
->mkConst(s
.substr(0, len
));
3386 Node z
= nm
->mkConst(s
.substr(len
, size
- len
));
3389 if (r
!= d_emptyString
)
3391 std::vector
<Node
> v2(vec_r
);
3392 v2
.insert(v2
.begin(), y
);
3393 v2
.insert(v2
.begin(), z
);
3394 restr
= mkConcat(z
, y
);
3395 cc
= Rewriter::rewrite(s_zy
.eqNode(mkConcat(v2
)));
3399 cc
= Rewriter::rewrite(s_zy
.eqNode(mkConcat(z
, y
)));
3405 Node conc2
= nm
->mkNode(
3406 kind::STRING_IN_REGEXP
,
3407 normal_forms
[other_n_index
][index
],
3408 nm
->mkNode(kind::REGEXP_CONCAT
,
3409 nm
->mkNode(kind::STRING_TO_REGEXP
, y
),
3410 nm
->mkNode(kind::REGEXP_STAR
,
3411 nm
->mkNode(kind::STRING_TO_REGEXP
, restr
))));
3412 cc
= cc
== d_true
? conc2
: nm
->mkNode(kind::AND
, cc
, conc2
);
3413 d_regexp_ant
[conc2
] = ant
;
3414 vconc
.push_back(cc
);
3416 conc
= vconc
.size() == 0 ? Node::null() : vconc
.size() == 1
3418 : nm
->mkNode(kind::OR
, vconc
);
3422 Trace("strings-loop") << "Strings::Loop: Normal Loop Breaking."
3425 Node sk_w
= d_sk_cache
.mkSkolem("w_loop");
3426 Node sk_y
= d_sk_cache
.mkSkolem("y_loop");
3427 registerLength(sk_y
, LENGTH_GEQ_ONE
);
3428 Node sk_z
= d_sk_cache
.mkSkolem("z_loop");
3429 // t1 * ... * tn = y * z
3430 Node conc1
= t_yz
.eqNode(mkConcat(sk_y
, sk_z
));
3431 // s1 * ... * sk = z * y * r
3432 vec_r
.insert(vec_r
.begin(), sk_y
);
3433 vec_r
.insert(vec_r
.begin(), sk_z
);
3434 Node conc2
= s_zy
.eqNode(mkConcat(vec_r
));
3436 normal_forms
[other_n_index
][index
].eqNode(mkConcat(sk_y
, sk_w
));
3437 Node restr
= r
== d_emptyString
? s_zy
: mkConcat(sk_z
, sk_y
);
3439 nm
->mkNode(kind::STRING_IN_REGEXP
,
3441 nm
->mkNode(kind::REGEXP_STAR
,
3442 nm
->mkNode(kind::STRING_TO_REGEXP
, restr
)));
3444 std::vector
<Node
> vec_conc
;
3445 vec_conc
.push_back(conc1
);
3446 vec_conc
.push_back(conc2
);
3447 vec_conc
.push_back(conc3
);
3448 vec_conc
.push_back(str_in_re
);
3449 // vec_conc.push_back(sk_y.eqNode(d_emptyString).negate());//by mkskolems
3450 conc
= nm
->mkNode(kind::AND
, vec_conc
);
3453 // set its antecedant to ant, to say when it is relevant
3454 if (!str_in_re
.isNull())
3456 d_regexp_ant
[str_in_re
] = ant
;
3460 info
.d_id
= INFER_FLOOP
;
3461 info
.d_nf_pair
[0] = normal_form_src
[i
];
3462 info
.d_nf_pair
[1] = normal_form_src
[j
];
3466 //return true for lemma, false if we succeed
3467 void TheoryStrings::processDeq( Node ni
, Node nj
) {
3468 //Assert( areDisequal( ni, nj ) );
3469 if( d_normal_forms
[ni
].size()>1 || d_normal_forms
[nj
].size()>1 ){
3470 std::vector
< Node
> nfi
;
3471 nfi
.insert( nfi
.end(), d_normal_forms
[ni
].begin(), d_normal_forms
[ni
].end() );
3472 std::vector
< Node
> nfj
;
3473 nfj
.insert( nfj
.end(), d_normal_forms
[nj
].begin(), d_normal_forms
[nj
].end() );
3475 int revRet
= processReverseDeq( nfi
, nfj
, ni
, nj
);
3481 nfi
.insert( nfi
.end(), d_normal_forms
[ni
].begin(), d_normal_forms
[ni
].end() );
3483 nfj
.insert( nfj
.end(), d_normal_forms
[nj
].begin(), d_normal_forms
[nj
].end() );
3486 while( index
<nfi
.size() || index
<nfj
.size() ){
3487 int ret
= processSimpleDeq( nfi
, nfj
, ni
, nj
, index
, false );
3491 Assert( index
<nfi
.size() && index
<nfj
.size() );
3492 Node i
= nfi
[index
];
3493 Node j
= nfj
[index
];
3494 Trace("strings-solve-debug") << "...Processing(DEQ) " << i
<< " " << j
<< std::endl
;
3495 if( !areEqual( i
, j
) ){
3496 Assert( i
.getKind()!=kind::CONST_STRING
|| j
.getKind()!=kind::CONST_STRING
);
3497 std::vector
< Node
> lexp
;
3498 Node li
= getLength( i
, lexp
);
3499 Node lj
= getLength( j
, lexp
);
3500 if( areDisequal( li
, lj
) ){
3501 if( i
.getKind()==kind::CONST_STRING
|| j
.getKind()==kind::CONST_STRING
){
3503 Node const_k
= i
.getKind() == kind::CONST_STRING
? i
: j
;
3504 Node nconst_k
= i
.getKind() == kind::CONST_STRING
? j
: i
;
3505 Node lnck
= i
.getKind() == kind::CONST_STRING
? lj
: li
;
3506 if( !d_equalityEngine
.areDisequal( nconst_k
, d_emptyString
, true ) ){
3507 Node eq
= nconst_k
.eqNode( d_emptyString
);
3508 Node conc
= NodeManager::currentNM()->mkNode( kind::OR
, eq
, eq
.negate() );
3509 sendInference( d_empty_vec
, conc
, "D-DISL-Emp-Split" );
3512 //split on first character
3513 CVC4::String str
= const_k
.getConst
<String
>();
3514 Node firstChar
= str
.size() == 1 ? const_k
: NodeManager::currentNM()->mkConst( str
.prefix( 1 ) );
3515 if( areEqual( lnck
, d_one
) ){
3516 if( areDisequal( firstChar
, nconst_k
) ){
3518 }else if( !areEqual( firstChar
, nconst_k
) ){
3519 //splitting on demand : try to make them disequal
3521 firstChar
, nconst_k
, "S-Split(DEQL-Const)", false))
3527 Node sk
= d_sk_cache
.mkSkolemCached(
3528 nconst_k
, firstChar
, SkolemCache::SK_ID_DC_SPT
, "dc_spt");
3529 registerLength(sk
, LENGTH_ONE
);
3531 d_sk_cache
.mkSkolemCached(nconst_k
,
3533 SkolemCache::SK_ID_DC_SPT_REM
,
3535 Node eq1
= nconst_k
.eqNode( NodeManager::currentNM()->mkNode( kind::STRING_CONCAT
, sk
, skr
) );
3536 eq1
= Rewriter::rewrite( eq1
);
3537 Node eq2
= nconst_k
.eqNode( NodeManager::currentNM()->mkNode( kind::STRING_CONCAT
, firstChar
, skr
) );
3538 std::vector
< Node
> antec
;
3539 antec
.insert( antec
.end(), d_normal_forms_exp
[ni
].begin(), d_normal_forms_exp
[ni
].end() );
3540 antec
.insert( antec
.end(), d_normal_forms_exp
[nj
].begin(), d_normal_forms_exp
[nj
].end() );
3541 antec
.push_back( nconst_k
.eqNode( d_emptyString
).negate() );
3542 sendInference( antec
, NodeManager::currentNM()->mkNode( kind::OR
,
3543 NodeManager::currentNM()->mkNode( kind::AND
, eq1
, sk
.eqNode( firstChar
).negate() ), eq2
), "D-DISL-CSplit" );
3544 d_pending_req_phase
[ eq1
] = true;
3549 Trace("strings-solve") << "Non-Simple Case 1 : add lemma " << std::endl
;
3551 std::vector
< Node
> antec
;
3552 std::vector
< Node
> antec_new_lits
;
3553 antec
.insert( antec
.end(), d_normal_forms_exp
[ni
].begin(), d_normal_forms_exp
[ni
].end() );
3554 antec
.insert( antec
.end(), d_normal_forms_exp
[nj
].begin(), d_normal_forms_exp
[nj
].end() );
3556 if( areDisequal( ni
, nj
) ){
3557 antec
.push_back( ni
.eqNode( nj
).negate() );
3559 antec_new_lits
.push_back( ni
.eqNode( nj
).negate() );
3561 antec_new_lits
.push_back( li
.eqNode( lj
).negate() );
3562 std::vector
< Node
> conc
;
3563 Node sk1
= d_sk_cache
.mkSkolemCached(
3564 i
, j
, SkolemCache::SK_ID_DEQ_X
, "x_dsplit");
3565 Node sk2
= d_sk_cache
.mkSkolemCached(
3566 i
, j
, SkolemCache::SK_ID_DEQ_Y
, "y_dsplit");
3567 Node sk3
= d_sk_cache
.mkSkolemCached(
3568 i
, j
, SkolemCache::SK_ID_DEQ_Z
, "z_dsplit");
3569 registerLength(sk3
, LENGTH_GEQ_ONE
);
3570 //Node nemp = sk3.eqNode(d_emptyString).negate();
3571 //conc.push_back(nemp);
3572 Node lsk1
= mkLength( sk1
);
3573 conc
.push_back( lsk1
.eqNode( li
) );
3574 Node lsk2
= mkLength( sk2
);
3575 conc
.push_back( lsk2
.eqNode( lj
) );
3576 conc
.push_back( NodeManager::currentNM()->mkNode( kind::OR
, j
.eqNode( mkConcat( sk1
, sk3
) ), i
.eqNode( mkConcat( sk2
, sk3
) ) ) );
3577 sendInference( antec
, antec_new_lits
, NodeManager::currentNM()->mkNode( kind::AND
, conc
), "D-DISL-Split" );
3578 ++(d_statistics
.d_deq_splits
);
3581 }else if( areEqual( li
, lj
) ){
3582 Assert( !areDisequal( i
, j
) );
3583 //splitting on demand : try to make them disequal
3584 if (sendSplit(i
, j
, "S-Split(DEQL)", false))
3589 //splitting on demand : try to make lengths equal
3590 if (sendSplit(li
, lj
, "D-Split"))
3603 int TheoryStrings::processReverseDeq( std::vector
< Node
>& nfi
, std::vector
< Node
>& nfj
, Node ni
, Node nj
) {
3604 //reverse normal form of i, j
3605 std::reverse( nfi
.begin(), nfi
.end() );
3606 std::reverse( nfj
.begin(), nfj
.end() );
3609 int ret
= processSimpleDeq( nfi
, nfj
, ni
, nj
, index
, true );
3611 //reverse normal form of i, j
3612 std::reverse( nfi
.begin(), nfi
.end() );
3613 std::reverse( nfj
.begin(), nfj
.end() );
3618 int TheoryStrings::processSimpleDeq( std::vector
< Node
>& nfi
, std::vector
< Node
>& nfj
, Node ni
, Node nj
, unsigned& index
, bool isRev
){
3619 // See if one side is constant, if so, the disequality ni != nj is satisfied
3620 // since ni does not contain nj or vice versa.
3621 // This is only valid when isRev is false, since when isRev=true, the contents
3622 // of normal form vectors nfi and nfj are reversed.
3625 for (unsigned i
= 0; i
< 2; i
++)
3627 Node c
= getConstantEqc(i
== 0 ? ni
: nj
);
3631 if (!TheoryStringsRewriter::canConstantContainList(
3632 c
, i
== 0 ? nfj
: nfi
, findex
, lindex
))
3634 Trace("strings-solve-debug")
3635 << "Disequality: constant cannot contain list" << std::endl
;
3641 while( index
<nfi
.size() || index
<nfj
.size() ) {
3642 if( index
>=nfi
.size() || index
>=nfj
.size() ){
3643 Trace("strings-solve-debug") << "Disequality normalize empty" << std::endl
;
3644 std::vector
< Node
> ant
;
3645 //we have a conflict : because the lengths are equal, the remainder needs to be empty, which will lead to a conflict
3646 Node lni
= getLengthExp( ni
, ant
, d_normal_forms_base
[ni
] );
3647 Node lnj
= getLengthExp( nj
, ant
, d_normal_forms_base
[nj
] );
3648 ant
.push_back( lni
.eqNode( lnj
) );
3649 ant
.insert( ant
.end(), d_normal_forms_exp
[ni
].begin(), d_normal_forms_exp
[ni
].end() );
3650 ant
.insert( ant
.end(), d_normal_forms_exp
[nj
].begin(), d_normal_forms_exp
[nj
].end() );
3651 std::vector
< Node
> cc
;
3652 std::vector
< Node
>& nfk
= index
>=nfi
.size() ? nfj
: nfi
;
3653 for( unsigned index_k
=index
; index_k
<nfk
.size(); index_k
++ ){
3654 cc
.push_back( nfk
[index_k
].eqNode( d_emptyString
) );
3656 Node conc
= cc
.size()==1 ? cc
[0] : NodeManager::currentNM()->mkNode( kind::AND
, cc
);
3657 conc
= Rewriter::rewrite( conc
);
3658 sendInference( ant
, conc
, "Disequality Normalize Empty", true);
3661 Node i
= nfi
[index
];
3662 Node j
= nfj
[index
];
3663 Trace("strings-solve-debug") << "...Processing(QED) " << i
<< " " << j
<< std::endl
;
3664 if( !areEqual( i
, j
) ) {
3665 if( i
.getKind()==kind::CONST_STRING
&& j
.getKind()==kind::CONST_STRING
) {
3666 unsigned int len_short
= i
.getConst
<String
>().size() < j
.getConst
<String
>().size() ? i
.getConst
<String
>().size() : j
.getConst
<String
>().size();
3667 bool isSameFix
= isRev
? i
.getConst
<String
>().rstrncmp(j
.getConst
<String
>(), len_short
): i
.getConst
<String
>().strncmp(j
.getConst
<String
>(), len_short
);
3669 //same prefix/suffix
3670 //k is the index of the string that is shorter
3671 Node nk
= i
.getConst
<String
>().size() < j
.getConst
<String
>().size() ? i
: j
;
3672 Node nl
= i
.getConst
<String
>().size() < j
.getConst
<String
>().size() ? j
: i
;
3675 int new_len
= nl
.getConst
<String
>().size() - len_short
;
3676 remainderStr
= NodeManager::currentNM()->mkConst( nl
.getConst
<String
>().substr(0, new_len
) );
3677 Trace("strings-solve-debug-test") << "Rev. Break normal form of " << nl
<< " into " << nk
<< ", " << remainderStr
<< std::endl
;
3679 remainderStr
= NodeManager::currentNM()->mkConst( nl
.getConst
<String
>().substr( len_short
) );
3680 Trace("strings-solve-debug-test") << "Break normal form of " << nl
<< " into " << nk
<< ", " << remainderStr
<< std::endl
;
3682 if( i
.getConst
<String
>().size() < j
.getConst
<String
>().size() ) {
3683 nfj
.insert( nfj
.begin() + index
+ 1, remainderStr
);
3684 nfj
[index
] = nfi
[index
];
3686 nfi
.insert( nfi
.begin() + index
+ 1, remainderStr
);
3687 nfi
[index
] = nfj
[index
];
3693 std::vector
< Node
> lexp
;
3694 Node li
= getLength( i
, lexp
);
3695 Node lj
= getLength( j
, lexp
);
3696 if( areEqual( li
, lj
) && areDisequal( i
, j
) ){
3697 Trace("strings-solve") << "Simple Case 2 : found equal length disequal sub strings " << i
<< " " << j
<< std::endl
;
3698 //we are done: D-Remove
3711 void TheoryStrings::addNormalFormPair( Node n1
, Node n2
){
3712 if( !isNormalFormPair( n1
, n2
) ){
3714 NodeIntMap::const_iterator it
= d_nf_pairs
.find( n1
);
3715 if( it
!=d_nf_pairs
.end() ){
3716 index
= (*it
).second
;
3718 d_nf_pairs
[n1
] = index
+ 1;
3719 if( index
<(int)d_nf_pairs_data
[n1
].size() ){
3720 d_nf_pairs_data
[n1
][index
] = n2
;
3722 d_nf_pairs_data
[n1
].push_back( n2
);
3724 Assert( isNormalFormPair( n1
, n2
) );
3726 Trace("strings-nf-debug") << "Already a normal form pair " << n1
<< " " << n2
<< std::endl
;
3730 bool TheoryStrings::isNormalFormPair( Node n1
, Node n2
) {
3731 //TODO: modulo equality?
3732 return isNormalFormPair2( n1
, n2
) || isNormalFormPair2( n2
, n1
);
3735 bool TheoryStrings::isNormalFormPair2( Node n1
, Node n2
) {
3736 //Trace("strings-debug") << "is normal form pair. " << n1 << " " << n2 << std::endl;
3737 NodeIntMap::const_iterator it
= d_nf_pairs
.find( n1
);
3738 if( it
!=d_nf_pairs
.end() ){
3739 Assert( d_nf_pairs_data
.find( n1
)!=d_nf_pairs_data
.end() );
3740 for( int i
=0; i
<(*it
).second
; i
++ ){
3741 Assert( i
<(int)d_nf_pairs_data
[n1
].size() );
3742 if( d_nf_pairs_data
[n1
][i
]==n2
){
3750 void TheoryStrings::registerTerm( Node n
, int effort
) {
3751 TypeNode tn
= n
.getType();
3752 bool do_register
= true;
3755 if (options::stringEagerLen())
3757 do_register
= effort
== 0;
3761 do_register
= effort
> 0 || n
.getKind() != STRING_CONCAT
;
3768 if (d_registered_terms_cache
.find(n
) != d_registered_terms_cache
.end())
3772 d_registered_terms_cache
.insert(n
);
3773 NodeManager
* nm
= NodeManager::currentNM();
3774 Debug("strings-register") << "TheoryStrings::registerTerm() " << n
3775 << ", effort = " << effort
<< std::endl
;
3778 // register length information:
3779 // for variables, split on empty vs positive length
3780 // for concat/const/replace, introduce proxy var and state length relation
3782 if (n
.getKind() != STRING_CONCAT
&& n
.getKind() != CONST_STRING
)
3784 Node lsumb
= nm
->mkNode(STRING_LENGTH
, n
);
3785 lsum
= Rewriter::rewrite(lsumb
);
3786 // can register length term if it does not rewrite
3789 registerLength(n
, LENGTH_SPLIT
);
3793 Node sk
= d_sk_cache
.mkSkolemCached(n
, SkolemCache::SK_PURIFY
, "lsym");
3794 StringsProxyVarAttribute spva
;
3795 sk
.setAttribute(spva
, true);
3796 Node eq
= Rewriter::rewrite(sk
.eqNode(n
));
3797 Trace("strings-lemma") << "Strings::Lemma LENGTH Term : " << eq
3799 d_proxy_var
[n
] = sk
;
3800 Trace("strings-assert") << "(assert " << eq
<< ")" << std::endl
;
3802 Node skl
= nm
->mkNode(STRING_LENGTH
, sk
);
3803 if (n
.getKind() == STRING_CONCAT
)
3805 std::vector
<Node
> node_vec
;
3806 for (unsigned i
= 0; i
< n
.getNumChildren(); i
++)
3808 if (n
[i
].getAttribute(StringsProxyVarAttribute()))
3810 Assert(d_proxy_var_to_length
.find(n
[i
])
3811 != d_proxy_var_to_length
.end());
3812 node_vec
.push_back(d_proxy_var_to_length
[n
[i
]]);
3816 Node lni
= nm
->mkNode(STRING_LENGTH
, n
[i
]);
3817 node_vec
.push_back(lni
);
3820 lsum
= nm
->mkNode(PLUS
, node_vec
);
3821 lsum
= Rewriter::rewrite(lsum
);
3823 else if (n
.getKind() == CONST_STRING
)
3825 lsum
= nm
->mkConst(Rational(n
.getConst
<String
>().size()));
3827 Assert(!lsum
.isNull());
3828 d_proxy_var_to_length
[sk
] = lsum
;
3829 Node ceq
= Rewriter::rewrite(skl
.eqNode(lsum
));
3830 Trace("strings-lemma") << "Strings::Lemma LENGTH : " << ceq
<< std::endl
;
3831 Trace("strings-lemma-debug")
3832 << " prerewrite : " << skl
.eqNode(lsum
) << std::endl
;
3833 Trace("strings-assert") << "(assert " << ceq
<< ")" << std::endl
;
3836 else if (n
.getKind() == STRING_CODE
)
3838 d_has_str_code
= true;
3839 // ite( str.len(s)==1, 0 <= str.code(s) < num_codes, str.code(s)=-1 )
3840 Node code_len
= mkLength(n
[0]).eqNode(d_one
);
3841 Node code_eq_neg1
= n
.eqNode(d_neg_one
);
3842 Node code_range
= nm
->mkNode(
3844 nm
->mkNode(GEQ
, n
, d_zero
),
3845 nm
->mkNode(LT
, n
, nm
->mkConst(Rational(CVC4::String::num_codes()))));
3846 Node lem
= nm
->mkNode(ITE
, code_len
, code_range
, code_eq_neg1
);
3847 Trace("strings-lemma") << "Strings::Lemma CODE : " << lem
<< std::endl
;
3848 Trace("strings-assert") << "(assert " << lem
<< ")" << std::endl
;
3853 void TheoryStrings::sendInternalInference(std::vector
<Node
>& exp
,
3857 if (conc
.getKind() == AND
)
3859 for (const Node
& cc
: conc
)
3861 sendInternalInference(exp
, cc
, c
);
3865 bool pol
= conc
.getKind() != NOT
;
3866 Node lit
= pol
? conc
: conc
[0];
3867 if (lit
.getKind() == EQUAL
)
3869 for (unsigned i
= 0; i
< 2; i
++)
3871 if (!lit
[i
].isConst() && !hasTerm(lit
[i
]))
3873 // introduces a new non-constant term, do not infer
3877 // does it already hold?
3878 if (pol
? areEqual(lit
[0], lit
[1]) : areDisequal(lit
[0], lit
[1]))
3883 else if (lit
.isConst())
3885 if (lit
.getConst
<bool>())
3892 else if (!hasTerm(lit
))
3894 // introduces a new non-constant term, do not infer
3897 else if (areEqual(lit
, pol
? d_true
: d_false
))
3902 sendInference(exp
, conc
, c
);
3905 void TheoryStrings::sendInference( std::vector
< Node
>& exp
, std::vector
< Node
>& exp_n
, Node eq
, const char * c
, bool asLemma
) {
3906 eq
= eq
.isNull() ? d_false
: Rewriter::rewrite( eq
);
3908 if( Trace
.isOn("strings-infer-debug") ){
3909 Trace("strings-infer-debug") << "By " << c
<< ", infer : " << eq
<< " from: " << std::endl
;
3910 for( unsigned i
=0; i
<exp
.size(); i
++ ){
3911 Trace("strings-infer-debug") << " " << exp
[i
] << std::endl
;
3913 for( unsigned i
=0; i
<exp_n
.size(); i
++ ){
3914 Trace("strings-infer-debug") << " N:" << exp_n
[i
] << std::endl
;
3916 //Trace("strings-infer-debug") << "as lemma : " << asLemma << std::endl;
3918 //check if we should send a lemma or an inference
3919 if( asLemma
|| eq
==d_false
|| eq
.getKind()==kind::OR
|| !exp_n
.empty() || options::stringInferAsLemmas() ){
3921 if( options::stringRExplainLemmas() ){
3922 eq_exp
= mkExplain( exp
, exp_n
);
3925 eq_exp
= mkAnd( exp_n
);
3926 }else if( exp_n
.empty() ){
3927 eq_exp
= mkAnd( exp
);
3929 std::vector
< Node
> ev
;
3930 ev
.insert( ev
.end(), exp
.begin(), exp
.end() );
3931 ev
.insert( ev
.end(), exp_n
.begin(), exp_n
.end() );
3932 eq_exp
= NodeManager::currentNM()->mkNode( kind::AND
, ev
);
3935 // if we have unexplained literals, this lemma is not a conflict
3936 if (eq
== d_false
&& !exp_n
.empty())
3938 eq
= eq_exp
.negate();
3941 sendLemma( eq_exp
, eq
, c
);
3943 sendInfer( mkAnd( exp
), eq
, c
);
3948 void TheoryStrings::sendInference( std::vector
< Node
>& exp
, Node eq
, const char * c
, bool asLemma
) {
3949 std::vector
< Node
> exp_n
;
3950 sendInference( exp
, exp_n
, eq
, c
, asLemma
);
3953 void TheoryStrings::sendLemma( Node ant
, Node conc
, const char * c
) {
3954 if( conc
.isNull() || conc
== d_false
) {
3955 Trace("strings-conflict") << "Strings::Conflict : " << c
<< " : " << ant
<< std::endl
;
3956 Trace("strings-lemma") << "Strings::Conflict : " << c
<< " : " << ant
<< std::endl
;
3957 Trace("strings-assert") << "(assert (not " << ant
<< ")) ; conflict " << c
<< std::endl
;
3958 d_out
->conflict(ant
);
3962 if( ant
== d_true
) {
3965 lem
= NodeManager::currentNM()->mkNode( kind::IMPLIES
, ant
, conc
);
3967 Trace("strings-lemma") << "Strings::Lemma " << c
<< " : " << lem
<< std::endl
;
3968 Trace("strings-assert") << "(assert " << lem
<< ") ; lemma " << c
<< std::endl
;
3969 d_lemma_cache
.push_back( lem
);
3973 void TheoryStrings::sendInfer( Node eq_exp
, Node eq
, const char * c
) {
3974 if( options::stringInferSym() ){
3975 std::vector
< Node
> vars
;
3976 std::vector
< Node
> subs
;
3977 std::vector
< Node
> unproc
;
3978 inferSubstitutionProxyVars( eq_exp
, vars
, subs
, unproc
);
3979 if( unproc
.empty() ){
3980 Trace("strings-lemma-debug") << "Strings::Infer " << eq
<< " from " << eq_exp
<< " by " << c
<< std::endl
;
3981 Node eqs
= eq
.substitute( vars
.begin(), vars
.end(), subs
.begin(), subs
.end() );
3982 Trace("strings-lemma-debug") << "Strings::Infer Alternate : " << eqs
<< std::endl
;
3983 for( unsigned i
=0; i
<vars
.size(); i
++ ){
3984 Trace("strings-lemma-debug") << " " << vars
[i
] << " -> " << subs
[i
] << std::endl
;
3986 sendLemma( d_true
, eqs
, c
);
3989 for( unsigned i
=0; i
<unproc
.size(); i
++ ){
3990 Trace("strings-lemma-debug") << " non-trivial exp : " << unproc
[i
] << std::endl
;
3994 Trace("strings-lemma") << "Strings::Infer " << eq
<< " from " << eq_exp
<< " by " << c
<< std::endl
;
3995 Trace("strings-assert") << "(assert (=> " << eq_exp
<< " " << eq
<< ")) ; infer " << c
<< std::endl
;
3996 d_pending
.push_back( eq
);
3997 d_pending_exp
[eq
] = eq_exp
;
3998 d_infer
.push_back( eq
);
3999 d_infer_exp
.push_back( eq_exp
);
4002 bool TheoryStrings::sendSplit(Node a
, Node b
, const char* c
, bool preq
)
4004 Node eq
= a
.eqNode( b
);
4005 eq
= Rewriter::rewrite( eq
);
4008 Node neq
= NodeManager::currentNM()->mkNode(kind::NOT
, eq
);
4009 Node lemma_or
= NodeManager::currentNM()->mkNode(kind::OR
, eq
, neq
);
4010 Trace("strings-lemma") << "Strings::Lemma " << c
<< " SPLIT : " << lemma_or
4012 d_lemma_cache
.push_back(lemma_or
);
4013 d_pending_req_phase
[eq
] = preq
;
4014 ++(d_statistics
.d_splits
);
4020 void TheoryStrings::registerLength(Node n
, LengthStatus s
)
4022 if (d_length_lemma_terms_cache
.find(n
) != d_length_lemma_terms_cache
.end())
4026 d_length_lemma_terms_cache
.insert(n
);
4028 NodeManager
* nm
= NodeManager::currentNM();
4029 Node n_len
= nm
->mkNode(kind::STRING_LENGTH
, n
);
4031 if (s
== LENGTH_GEQ_ONE
)
4033 Node neq_empty
= n
.eqNode(d_emptyString
).negate();
4034 Node len_n_gt_z
= nm
->mkNode(GT
, n_len
, d_zero
);
4035 Node len_geq_one
= nm
->mkNode(AND
, neq_empty
, len_n_gt_z
);
4036 Trace("strings-lemma") << "Strings::Lemma SK-GEQ-ONE : " << len_geq_one
4038 Trace("strings-assert") << "(assert " << len_geq_one
<< ")" << std::endl
;
4039 d_out
->lemma(len_geq_one
);
4043 if (s
== LENGTH_ONE
)
4045 Node len_one
= n_len
.eqNode(d_one
);
4046 Trace("strings-lemma") << "Strings::Lemma SK-ONE : " << len_one
4048 Trace("strings-assert") << "(assert " << len_one
<< ")" << std::endl
;
4049 d_out
->lemma(len_one
);
4052 Assert(s
== LENGTH_SPLIT
);
4054 if( options::stringSplitEmp() || !options::stringLenGeqZ() ){
4055 Node n_len_eq_z
= n_len
.eqNode( d_zero
);
4056 Node n_len_eq_z_2
= n
.eqNode( d_emptyString
);
4057 Node case_empty
= nm
->mkNode(AND
, n_len_eq_z
, n_len_eq_z_2
);
4058 case_empty
= Rewriter::rewrite(case_empty
);
4059 Node case_nempty
= nm
->mkNode(GT
, n_len
, d_zero
);
4060 if (!case_empty
.isConst())
4062 Node lem
= nm
->mkNode(OR
, case_empty
, case_nempty
);
4064 Trace("strings-lemma") << "Strings::Lemma LENGTH >= 0 : " << lem
4066 // prefer trying the empty case first
4067 // notice that requirePhase must only be called on rewritten literals that
4068 // occur in the CNF stream.
4069 n_len_eq_z
= Rewriter::rewrite(n_len_eq_z
);
4070 Assert(!n_len_eq_z
.isConst());
4071 d_out
->requirePhase(n_len_eq_z
, true);
4072 n_len_eq_z_2
= Rewriter::rewrite(n_len_eq_z_2
);
4073 Assert(!n_len_eq_z_2
.isConst());
4074 d_out
->requirePhase(n_len_eq_z_2
, true);
4076 else if (!case_empty
.getConst
<bool>())
4078 // the rewriter knows that n is non-empty
4079 Trace("strings-lemma")
4080 << "Strings::Lemma LENGTH > 0 (non-empty): " << case_nempty
4082 d_out
->lemma(case_nempty
);
4086 // If n = "" ---> true or len( n ) = 0 ----> true, then we expect that
4087 // n ---> "". Since this method is only called on non-constants n, it must
4088 // be that n = "" ^ len( n ) = 0 does not rewrite to true.
4093 // additionally add len( x ) >= 0 ?
4094 if( options::stringLenGeqZ() ){
4095 Node n_len_geq
= nm
->mkNode(kind::GEQ
, n_len
, d_zero
);
4096 n_len_geq
= Rewriter::rewrite( n_len_geq
);
4097 d_out
->lemma( n_len_geq
);
4101 void TheoryStrings::inferSubstitutionProxyVars( Node n
, std::vector
< Node
>& vars
, std::vector
< Node
>& subs
, std::vector
< Node
>& unproc
) {
4102 if( n
.getKind()==kind::AND
){
4103 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ){
4104 inferSubstitutionProxyVars( n
[i
], vars
, subs
, unproc
);
4107 }else if( n
.getKind()==kind::EQUAL
){
4108 Node ns
= n
.substitute( vars
.begin(), vars
.end(), subs
.begin(), subs
.end() );
4109 ns
= Rewriter::rewrite( ns
);
4110 if( ns
.getKind()==kind::EQUAL
){
4113 for( unsigned i
=0; i
<2; i
++ ){
4115 if( ns
[i
].getAttribute(StringsProxyVarAttribute()) ){
4117 }else if( ns
[i
].isConst() ){
4118 NodeNodeMap::const_iterator it
= d_proxy_var
.find( ns
[i
] );
4119 if( it
!=d_proxy_var
.end() ){
4125 if( v
.getNumChildren()==0 ){
4129 //both sides involved in proxy var
4140 subs
.push_back( s
);
4141 vars
.push_back( v
);
4149 unproc
.push_back( n
);
4154 Node
TheoryStrings::mkConcat( Node n1
, Node n2
) {
4155 return Rewriter::rewrite( NodeManager::currentNM()->mkNode( kind::STRING_CONCAT
, n1
, n2
) );
4158 Node
TheoryStrings::mkConcat( Node n1
, Node n2
, Node n3
) {
4159 return Rewriter::rewrite( NodeManager::currentNM()->mkNode( kind::STRING_CONCAT
, n1
, n2
, n3
) );
4162 Node
TheoryStrings::mkConcat( const std::vector
< Node
>& c
) {
4163 return Rewriter::rewrite( c
.size()>1 ? NodeManager::currentNM()->mkNode( kind::STRING_CONCAT
, c
) : ( c
.size()==1 ? c
[0] : d_emptyString
) );
4166 Node
TheoryStrings::mkLength( Node t
) {
4167 return Rewriter::rewrite( NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, t
) );
4170 Node
TheoryStrings::mkExplain( std::vector
< Node
>& a
) {
4171 std::vector
< Node
> an
;
4172 return mkExplain( a
, an
);
4175 Node
TheoryStrings::mkExplain( std::vector
< Node
>& a
, std::vector
< Node
>& an
) {
4176 std::vector
< TNode
> antec_exp
;
4177 for( unsigned i
=0; i
<a
.size(); i
++ ) {
4178 if( std::find( a
.begin(), a
.begin() + i
, a
[i
] )==a
.begin() + i
) {
4180 Debug("strings-explain") << "Ask for explanation of " << a
[i
] << std::endl
;
4182 if(a
[i
].getKind() == kind::EQUAL
) {
4183 //Assert( hasTerm(a[i][0]) );
4184 //Assert( hasTerm(a[i][1]) );
4185 Assert( areEqual(a
[i
][0], a
[i
][1]) );
4186 if( a
[i
][0]==a
[i
][1] ){
4189 } else if( a
[i
].getKind()==kind::NOT
&& a
[i
][0].getKind()==kind::EQUAL
) {
4190 Assert( hasTerm(a
[i
][0][0]) );
4191 Assert( hasTerm(a
[i
][0][1]) );
4192 AlwaysAssert( d_equalityEngine
.areDisequal(a
[i
][0][0], a
[i
][0][1], true) );
4193 }else if( a
[i
].getKind() == kind::AND
){
4194 for( unsigned j
=0; j
<a
[i
].getNumChildren(); j
++ ){
4195 a
.push_back( a
[i
][j
] );
4200 unsigned ps
= antec_exp
.size();
4201 explain(a
[i
], antec_exp
);
4202 Debug("strings-explain") << "Done, explanation was : " << std::endl
;
4203 for( unsigned j
=ps
; j
<antec_exp
.size(); j
++ ) {
4204 Debug("strings-explain") << " " << antec_exp
[j
] << std::endl
;
4206 Debug("strings-explain") << std::endl
;
4210 for( unsigned i
=0; i
<an
.size(); i
++ ) {
4211 if( std::find( an
.begin(), an
.begin() + i
, an
[i
] )==an
.begin() + i
){
4212 Debug("strings-explain") << "Add to explanation (new literal) " << an
[i
] << std::endl
;
4213 antec_exp
.push_back(an
[i
]);
4217 if( antec_exp
.empty() ) {
4219 } else if( antec_exp
.size()==1 ) {
4222 ant
= NodeManager::currentNM()->mkNode( kind::AND
, antec_exp
);
4224 //ant = Rewriter::rewrite( ant );
4228 Node
TheoryStrings::mkAnd( std::vector
< Node
>& a
) {
4229 std::vector
< Node
> au
;
4230 for( unsigned i
=0; i
<a
.size(); i
++ ){
4231 if( std::find( au
.begin(), au
.end(), a
[i
] )==au
.end() ){
4232 au
.push_back( a
[i
] );
4237 } else if( au
.size() == 1 ) {
4240 return NodeManager::currentNM()->mkNode( kind::AND
, au
);
4244 void TheoryStrings::getConcatVec( Node n
, std::vector
< Node
>& c
) {
4245 if( n
.getKind()==kind::STRING_CONCAT
) {
4246 for( unsigned i
=0; i
<n
.getNumChildren(); i
++ ) {
4247 if( !areEqual( n
[i
], d_emptyString
) ) {
4248 c
.push_back( n
[i
] );
4256 void TheoryStrings::checkNormalFormsDeq()
4258 std::vector
< std::vector
< Node
> > cols
;
4259 std::vector
< Node
> lts
;
4260 std::map
< Node
, std::map
< Node
, bool > > processed
;
4262 //for each pair of disequal strings, must determine whether their lengths are equal or disequal
4263 for( NodeList::const_iterator id
= d_ee_disequalities
.begin(); id
!= d_ee_disequalities
.end(); ++id
) {
4266 for( unsigned i
=0; i
<2; i
++ ){
4267 n
[i
] = d_equalityEngine
.getRepresentative( eq
[i
] );
4269 if( processed
[n
[0]].find( n
[1] )==processed
[n
[0]].end() ){
4270 processed
[n
[0]][n
[1]] = true;
4272 for( unsigned i
=0; i
<2; i
++ ){
4273 EqcInfo
* ei
= getOrMakeEqcInfo( n
[i
], false );
4274 lt
[i
] = ei
? ei
->d_length_term
: Node::null();
4275 if( lt
[i
].isNull() ){
4278 lt
[i
] = NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, lt
[i
] );
4280 if( !areEqual( lt
[0], lt
[1] ) && !areDisequal( lt
[0], lt
[1] ) ){
4281 sendSplit( lt
[0], lt
[1], "DEQ-LENGTH-SP" );
4286 if( !hasProcessed() ){
4287 separateByLength( d_strings_eqc
, cols
, lts
);
4288 for( unsigned i
=0; i
<cols
.size(); i
++ ){
4289 if( cols
[i
].size()>1 && d_lemma_cache
.empty() ){
4290 Trace("strings-solve") << "- Verify disequalities are processed for " << cols
[i
][0] << ", normal form : ";
4291 printConcat( d_normal_forms
[cols
[i
][0]], "strings-solve" );
4292 Trace("strings-solve") << "... #eql = " << cols
[i
].size() << std::endl
;
4293 //must ensure that normal forms are disequal
4294 for( unsigned j
=0; j
<cols
[i
].size(); j
++ ){
4295 for( unsigned k
=(j
+1); k
<cols
[i
].size(); k
++ ){
4296 //for strings that are disequal, but have the same length
4297 if( areDisequal( cols
[i
][j
], cols
[i
][k
] ) ){
4298 Assert( !d_conflict
);
4299 Trace("strings-solve") << "- Compare " << cols
[i
][j
] << " ";
4300 printConcat( d_normal_forms
[cols
[i
][j
]], "strings-solve" );
4301 Trace("strings-solve") << " against " << cols
[i
][k
] << " ";
4302 printConcat( d_normal_forms
[cols
[i
][k
]], "strings-solve" );
4303 Trace("strings-solve") << "..." << std::endl
;
4304 processDeq( cols
[i
][j
], cols
[i
][k
] );
4305 if( hasProcessed() ){
4316 void TheoryStrings::checkLengthsEqc() {
4317 if( options::stringLenNorm() ){
4318 for( unsigned i
=0; i
<d_strings_eqc
.size(); i
++ ){
4319 //if( d_normal_forms[nodes[i]].size()>1 ) {
4320 Trace("strings-process-debug") << "Process length constraints for " << d_strings_eqc
[i
] << std::endl
;
4321 //check if there is a length term for this equivalence class
4322 EqcInfo
* ei
= getOrMakeEqcInfo( d_strings_eqc
[i
], false );
4323 Node lt
= ei
? ei
->d_length_term
: Node::null();
4324 if( !lt
.isNull() ) {
4325 Node llt
= NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, lt
);
4326 //now, check if length normalization has occurred
4327 if( ei
->d_normalized_length
.get().isNull() ) {
4328 Node nf
= mkConcat( d_normal_forms
[d_strings_eqc
[i
]] );
4329 if( Trace
.isOn("strings-process-debug") ){
4330 Trace("strings-process-debug") << " normal form is " << nf
<< " from base " << d_normal_forms_base
[d_strings_eqc
[i
]] << std::endl
;
4331 Trace("strings-process-debug") << " normal form exp is: " << std::endl
;
4332 for( unsigned j
=0; j
<d_normal_forms_exp
[d_strings_eqc
[i
]].size(); j
++ ){
4333 Trace("strings-process-debug") << " " << d_normal_forms_exp
[d_strings_eqc
[i
]][j
] << std::endl
;
4337 //if not, add the lemma
4338 std::vector
< Node
> ant
;
4339 ant
.insert( ant
.end(), d_normal_forms_exp
[d_strings_eqc
[i
]].begin(), d_normal_forms_exp
[d_strings_eqc
[i
]].end() );
4340 ant
.push_back( d_normal_forms_base
[d_strings_eqc
[i
]].eqNode( lt
) );
4341 Node lc
= NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, nf
);
4342 Node lcr
= Rewriter::rewrite( lc
);
4343 Trace("strings-process-debug") << "Rewrote length " << lc
<< " to " << lcr
<< std::endl
;
4344 Node eq
= llt
.eqNode( lcr
);
4346 ei
->d_normalized_length
.set( eq
);
4347 sendInference( ant
, eq
, "LEN-NORM", true );
4351 Trace("strings-process-debug") << "No length term for eqc " << d_strings_eqc
[i
] << " " << d_eqc_to_len_term
[d_strings_eqc
[i
]] << std::endl
;
4352 if( !options::stringEagerLen() ){
4353 Node c
= mkConcat( d_normal_forms
[d_strings_eqc
[i
]] );
4354 registerTerm( c
, 3 );
4357 NodeNodeMap::const_iterator it = d_proxy_var.find( c );
4358 if( it!=d_proxy_var.end() ){
4359 Node pv = (*it).second;
4360 Assert( d_proxy_var_to_length.find( pv )!=d_proxy_var_to_length.end() );
4361 Node pvl = d_proxy_var_to_length[pv];
4362 Node ceq = Rewriter::rewrite( mkLength( pv ).eqNode( pvl ) );
4363 sendInference( d_empty_vec, ceq, "LEN-NORM-I", true );
4370 // Trace("strings-process-debug") << "Do not process length constraints for " << nodes[i] << " " << d_normal_forms[nodes[i]].size() << std::endl;
4376 void TheoryStrings::checkCardinality() {
4377 //int cardinality = options::stringCharCardinality();
4378 //Trace("strings-solve-debug2") << "get cardinality: " << cardinality << endl;
4380 //AJR: this will create a partition of eqc, where each collection has length that are pairwise propagated to be equal.
4381 // we do not require disequalities between the lengths of each collection, since we split on disequalities between lengths of string terms that are disequal (DEQ-LENGTH-SP).
4382 // TODO: revisit this?
4383 std::vector
< std::vector
< Node
> > cols
;
4384 std::vector
< Node
> lts
;
4385 separateByLength( d_strings_eqc
, cols
, lts
);
4387 Trace("strings-card") << "Check cardinality...." << std::endl
;
4388 for( unsigned i
= 0; i
<cols
.size(); ++i
) {
4390 Trace("strings-card") << "Number of strings with length equal to " << lr
<< " is " << cols
[i
].size() << std::endl
;
4391 if( cols
[i
].size() > 1 ) {
4393 unsigned card_need
= 1;
4394 double curr
= (double)cols
[i
].size();
4395 while( curr
>d_card_size
){
4396 curr
= curr
/(double)d_card_size
;
4399 Trace("strings-card") << "Need length " << card_need
<< " for this number of strings (where alphabet size is " << d_card_size
<< ")." << std::endl
;
4400 //check if we need to split
4401 bool needsSplit
= true;
4403 // if constant, compare
4404 Node cmp
= NodeManager::currentNM()->mkNode( kind::GEQ
, lr
, NodeManager::currentNM()->mkConst( Rational( card_need
) ) );
4405 cmp
= Rewriter::rewrite( cmp
);
4406 needsSplit
= cmp
!=d_true
;
4408 // find the minimimum constant that we are unknown to be disequal from, or otherwise stop if we increment such that cardinality does not apply
4410 bool success
= true;
4411 while( r
<card_need
&& success
){
4412 Node rr
= NodeManager::currentNM()->mkConst
<Rational
>( Rational(r
) );
4413 if( areDisequal( rr
, lr
) ){
4420 Trace("strings-card") << "Symbolic length " << lr
<< " must be at least " << r
<< " due to constant disequalities." << std::endl
;
4422 needsSplit
= r
<card_need
;
4426 unsigned int int_k
= (unsigned int)card_need
;
4427 for( std::vector
< Node
>::iterator itr1
= cols
[i
].begin();
4428 itr1
!= cols
[i
].end(); ++itr1
) {
4429 for( std::vector
< Node
>::iterator itr2
= itr1
+ 1;
4430 itr2
!= cols
[i
].end(); ++itr2
) {
4431 if(!areDisequal( *itr1
, *itr2
)) {
4433 if (sendSplit(*itr1
, *itr2
, "CARD-SP"))
4440 EqcInfo
* ei
= getOrMakeEqcInfo( lr
, true );
4441 Trace("strings-card") << "Previous cardinality used for " << lr
<< " is " << ((int)ei
->d_cardinality_lem_k
.get()-1) << std::endl
;
4442 if( int_k
+1 > ei
->d_cardinality_lem_k
.get() ){
4443 Node k_node
= NodeManager::currentNM()->mkConst( ::CVC4::Rational( int_k
) );
4444 //add cardinality lemma
4445 Node dist
= NodeManager::currentNM()->mkNode( kind::DISTINCT
, cols
[i
] );
4446 std::vector
< Node
> vec_node
;
4447 vec_node
.push_back( dist
);
4448 for( std::vector
< Node
>::iterator itr1
= cols
[i
].begin();
4449 itr1
!= cols
[i
].end(); ++itr1
) {
4450 Node len
= NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, *itr1
);
4452 Node len_eq_lr
= len
.eqNode(lr
);
4453 vec_node
.push_back( len_eq_lr
);
4456 Node len
= NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, cols
[i
][0] );
4457 Node cons
= NodeManager::currentNM()->mkNode( kind::GEQ
, len
, k_node
);
4458 cons
= Rewriter::rewrite( cons
);
4459 ei
->d_cardinality_lem_k
.set( int_k
+1 );
4461 sendInference( d_empty_vec
, vec_node
, cons
, "CARDINALITY", true );
4468 Trace("strings-card") << "...end check cardinality" << std::endl
;
4471 void TheoryStrings::getEquivalenceClasses( std::vector
< Node
>& eqcs
) {
4472 eq::EqClassesIterator eqcs_i
= eq::EqClassesIterator( &d_equalityEngine
);
4473 while( !eqcs_i
.isFinished() ) {
4474 Node eqc
= (*eqcs_i
);
4475 //if eqc.getType is string
4476 if (eqc
.getType().isString()) {
4477 eqcs
.push_back( eqc
);
4483 void TheoryStrings::separateByLength(std::vector
< Node
>& n
,
4484 std::vector
< std::vector
< Node
> >& cols
,
4485 std::vector
< Node
>& lts
) {
4486 unsigned leqc_counter
= 0;
4487 std::map
< Node
, unsigned > eqc_to_leqc
;
4488 std::map
< unsigned, Node
> leqc_to_eqc
;
4489 std::map
< unsigned, std::vector
< Node
> > eqc_to_strings
;
4490 for( unsigned i
=0; i
<n
.size(); i
++ ) {
4492 Assert( d_equalityEngine
.getRepresentative(eqc
)==eqc
);
4493 EqcInfo
* ei
= getOrMakeEqcInfo( eqc
, false );
4494 Node lt
= ei
? ei
->d_length_term
: Node::null();
4496 lt
= NodeManager::currentNM()->mkNode( kind::STRING_LENGTH
, lt
);
4497 Node r
= d_equalityEngine
.getRepresentative( lt
);
4498 if( eqc_to_leqc
.find( r
)==eqc_to_leqc
.end() ){
4499 eqc_to_leqc
[r
] = leqc_counter
;
4500 leqc_to_eqc
[leqc_counter
] = r
;
4503 eqc_to_strings
[ eqc_to_leqc
[r
] ].push_back( eqc
);
4505 eqc_to_strings
[leqc_counter
].push_back( eqc
);
4509 for( std::map
< unsigned, std::vector
< Node
> >::iterator it
= eqc_to_strings
.begin(); it
!= eqc_to_strings
.end(); ++it
){
4510 cols
.push_back( std::vector
< Node
>() );
4511 cols
.back().insert( cols
.back().end(), it
->second
.begin(), it
->second
.end() );
4512 lts
.push_back( leqc_to_eqc
[it
->first
] );
4516 void TheoryStrings::printConcat( std::vector
< Node
>& n
, const char * c
) {
4517 for( unsigned i
=0; i
<n
.size(); i
++ ){
4518 if( i
>0 ) Trace(c
) << " ++ ";
4524 //// Finite Model Finding
4526 TheoryStrings::StringSumLengthDecisionStrategy::StringSumLengthDecisionStrategy(
4527 context::Context
* c
, context::UserContext
* u
, Valuation valuation
)
4528 : DecisionStrategyFmf(c
, valuation
), d_input_var_lsum(u
)
4532 bool TheoryStrings::StringSumLengthDecisionStrategy::isInitialized()
4534 return !d_input_var_lsum
.get().isNull();
4537 void TheoryStrings::StringSumLengthDecisionStrategy::initialize(
4538 const std::vector
<Node
>& vars
)
4540 if (d_input_var_lsum
.get().isNull() && !vars
.empty())
4542 NodeManager
* nm
= NodeManager::currentNM();
4543 std::vector
<Node
> sum
;
4544 for (const Node
& v
: vars
)
4546 sum
.push_back(nm
->mkNode(STRING_LENGTH
, v
));
4548 Node sumn
= sum
.size() == 1 ? sum
[0] : nm
->mkNode(PLUS
, sum
);
4549 d_input_var_lsum
.set(sumn
);
4553 Node
TheoryStrings::StringSumLengthDecisionStrategy::mkLiteral(unsigned i
)
4555 if (d_input_var_lsum
.get().isNull())
4557 return Node::null();
4559 NodeManager
* nm
= NodeManager::currentNM();
4560 Node lit
= nm
->mkNode(LEQ
, d_input_var_lsum
.get(), nm
->mkConst(Rational(i
)));
4561 Trace("strings-fmf") << "StringsFMF::mkLiteral: " << lit
<< std::endl
;
4564 std::string
TheoryStrings::StringSumLengthDecisionStrategy::identify() const
4566 return std::string("string_sum_len");
4569 Node
TheoryStrings::ppRewrite(TNode atom
) {
4570 Trace("strings-ppr") << "TheoryStrings::ppRewrite " << atom
<< std::endl
;
4572 if (options::regExpElim() && atom
.getKind() == STRING_IN_REGEXP
)
4574 // aggressive elimination of regular expression membership
4575 atomElim
= d_regexp_elim
.eliminate(atom
);
4576 if (!atomElim
.isNull())
4578 Trace("strings-ppr") << " rewrote " << atom
<< " -> " << atomElim
4579 << " via regular expression elimination."
4584 if( !options::stringLazyPreproc() ){
4585 //eager preprocess here
4586 std::vector
< Node
> new_nodes
;
4587 Node ret
= d_preproc
.processAssertion( atom
, new_nodes
);
4589 Trace("strings-ppr") << " rewrote " << atom
<< " -> " << ret
<< ", with " << new_nodes
.size() << " lemmas." << std::endl
;
4590 for( unsigned i
=0; i
<new_nodes
.size(); i
++ ){
4591 Trace("strings-ppr") << " lemma : " << new_nodes
[i
] << std::endl
;
4592 d_out
->lemma( new_nodes
[i
] );
4596 Assert( new_nodes
.empty() );
4603 TheoryStrings::Statistics::Statistics()
4604 : d_splits("theory::strings::NumOfSplitOnDemands", 0),
4605 d_eq_splits("theory::strings::NumOfEqSplits", 0),
4606 d_deq_splits("theory::strings::NumOfDiseqSplits", 0),
4607 d_loop_lemmas("theory::strings::NumOfLoops", 0)
4609 smtStatisticsRegistry()->registerStat(&d_splits
);
4610 smtStatisticsRegistry()->registerStat(&d_eq_splits
);
4611 smtStatisticsRegistry()->registerStat(&d_deq_splits
);
4612 smtStatisticsRegistry()->registerStat(&d_loop_lemmas
);
4615 TheoryStrings::Statistics::~Statistics(){
4616 smtStatisticsRegistry()->unregisterStat(&d_splits
);
4617 smtStatisticsRegistry()->unregisterStat(&d_eq_splits
);
4618 smtStatisticsRegistry()->unregisterStat(&d_deq_splits
);
4619 smtStatisticsRegistry()->unregisterStat(&d_loop_lemmas
);
4641 //// Regular Expressions
4644 unsigned TheoryStrings::getNumMemberships( Node n
, bool isPos
) {
4646 NodeIntMap::const_iterator it
= d_pos_memberships
.find( n
);
4647 if( it
!=d_pos_memberships
.end() ){
4648 return (*it
).second
;
4651 NodeIntMap::const_iterator it
= d_neg_memberships
.find( n
);
4652 if( it
!=d_neg_memberships
.end() ){
4653 return (*it
).second
;
4659 Node
TheoryStrings::getMembership( Node n
, bool isPos
, unsigned i
) {
4660 return isPos
? d_pos_memberships_data
[n
][i
] : d_neg_memberships_data
[n
][i
];
4663 Node
TheoryStrings::mkRegExpAntec(Node atom
, Node ant
) {
4664 if(d_regexp_ant
.find(atom
) == d_regexp_ant
.end()) {
4665 return NodeManager::currentNM()->mkNode(kind::AND
, ant
, atom
);
4667 Node n
= d_regexp_ant
[atom
];
4668 return NodeManager::currentNM()->mkNode(kind::AND
, ant
, n
);
4672 void TheoryStrings::checkMemberships() {
4673 //add the memberships
4674 std::vector
<Node
> mems
= getExtTheory()->getActive(kind::STRING_IN_REGEXP
);
4675 for (unsigned i
= 0; i
< mems
.size(); i
++) {
4677 Assert( d_extf_info_tmp
.find( n
)!=d_extf_info_tmp
.end() );
4678 if (!d_extf_info_tmp
[n
].d_const
.isNull())
4680 bool pol
= d_extf_info_tmp
[n
].d_const
.getConst
<bool>();
4681 Trace("strings-process-debug") << " add membership : " << n
<< ", pol = " << pol
<< std::endl
;
4682 addMembership( pol
? n
: n
.negate() );
4684 Trace("strings-process-debug") << " irrelevant (non-asserted) membership : " << n
<< std::endl
;
4688 bool addedLemma
= false;
4689 bool changed
= false;
4690 std::vector
< Node
> processed
;
4691 std::vector
< Node
> cprocessed
;
4693 Trace("regexp-debug") << "Checking Memberships ... " << std::endl
;
4694 //if(options::stringEIT()) {
4695 //TODO: Opt for normal forms
4696 for( NodeIntMap::const_iterator itr_xr
= d_pos_memberships
.begin(); itr_xr
!= d_pos_memberships
.end(); ++itr_xr
){
4697 bool spflag
= false;
4698 Node x
= (*itr_xr
).first
;
4699 Trace("regexp-debug") << "Checking Memberships for " << x
<< std::endl
;
4700 if(d_inter_index
.find(x
) == d_inter_index
.end()) {
4701 d_inter_index
[x
] = 0;
4703 int cur_inter_idx
= d_inter_index
[x
];
4704 unsigned n_pmem
= (*itr_xr
).second
;
4705 Assert( getNumMemberships( x
, true )==n_pmem
);
4706 if( cur_inter_idx
!= (int)n_pmem
) {
4708 d_inter_cache
[x
] = getMembership( x
, true, 0 );
4709 d_inter_index
[x
] = 1;
4710 Trace("regexp-debug") << "... only one choice " << std::endl
;
4711 } else if(n_pmem
> 1) {
4713 if(d_inter_cache
.find(x
) != d_inter_cache
.end()) {
4714 r
= d_inter_cache
[x
];
4717 r
= getMembership( x
, true, 0 );
4721 unsigned k_start
= cur_inter_idx
;
4722 Trace("regexp-debug") << "... staring from : " << cur_inter_idx
<< ", we have " << n_pmem
<< std::endl
;
4723 for(unsigned k
= k_start
; k
<n_pmem
; k
++) {
4724 Node r2
= getMembership( x
, true, k
);
4725 r
= d_regexp_opr
.intersect(r
, r2
, spflag
);
4728 } else if(r
== d_emptyRegexp
) {
4729 std::vector
< Node
> vec_nodes
;
4730 for( unsigned kk
=0; kk
<=k
; kk
++ ){
4731 Node rr
= getMembership( x
, true, kk
);
4732 Node n
= NodeManager::currentNM()->mkNode(kind::STRING_IN_REGEXP
, x
, rr
);
4733 vec_nodes
.push_back( n
);
4736 sendInference(vec_nodes
, conc
, "INTERSECT CONFLICT", true);
4745 if(!d_conflict
&& !spflag
) {
4746 d_inter_cache
[x
] = r
;
4747 d_inter_index
[x
] = (int)n_pmem
;
4754 Trace("regexp-debug") << "... No Intersect Conflict in Memberships, addedLemma: " << addedLemma
<< std::endl
;
4756 NodeManager
* nm
= NodeManager::currentNM();
4757 for( unsigned i
=0; i
<d_regexp_memberships
.size(); i
++ ) {
4758 //check regular expression membership
4759 Node assertion
= d_regexp_memberships
[i
];
4760 Trace("regexp-debug") << "Check : " << assertion
<< " " << (d_regexp_ucached
.find(assertion
) == d_regexp_ucached
.end()) << " " << (d_regexp_ccached
.find(assertion
) == d_regexp_ccached
.end()) << std::endl
;
4761 if( d_regexp_ucached
.find(assertion
) == d_regexp_ucached
.end()
4762 && d_regexp_ccached
.find(assertion
) == d_regexp_ccached
.end() ) {
4763 Trace("strings-regexp") << "We have regular expression assertion : " << assertion
<< std::endl
;
4764 Node atom
= assertion
.getKind()==kind::NOT
? assertion
[0] : assertion
;
4765 bool polarity
= assertion
.getKind()!=kind::NOT
;
4769 std::vector
< Node
> rnfexp
;
4773 x
= getNormalString(x
, rnfexp
);
4776 if (!d_regexp_opr
.checkConstRegExp(r
))
4778 r
= getNormalSymRegExp(r
, rnfexp
);
4781 Trace("strings-regexp-nf") << "Term " << atom
<< " is normalized to "
4782 << x
<< " IN " << r
<< std::endl
;
4786 Rewriter::rewrite(nm
->mkNode(kind::STRING_IN_REGEXP
, x
, r
));
4793 d_regexp_ccached
.insert(assertion
);
4796 else if (tmp
== d_false
)
4798 Node antec
= mkRegExpAntec(assertion
, mkExplain(rnfexp
));
4799 Node conc
= Node::null();
4800 sendLemma(antec
, conc
, "REGEXP NF Conflict");
4807 flag
= checkPDerivative(x
, r
, atom
, addedLemma
, rnfexp
);
4809 if(! options::stringExp()) {
4810 throw LogicException("Strings Incomplete (due to Negative Membership) by default, try --strings-exp option.");
4814 //check if the term is atomic
4815 Node xr
= getRepresentative( x
);
4816 //Trace("strings-regexp") << xr << " is rep of " << x << std::endl;
4817 //Assert( d_normal_forms.find( xr )!=d_normal_forms.end() );
4818 Trace("strings-regexp")
4819 << "Unroll/simplify membership of atomic term " << xr
4821 // if so, do simple unrolling
4822 std::vector
<Node
> nvec
;
4826 d_regexp_opr
.simplify(atom
, nvec
, polarity
);
4828 Node antec
= assertion
;
4829 if (d_regexp_ant
.find(assertion
) != d_regexp_ant
.end())
4831 antec
= d_regexp_ant
[assertion
];
4832 for (std::vector
<Node
>::const_iterator itr
= nvec
.begin();
4836 if (itr
->getKind() == kind::STRING_IN_REGEXP
)
4838 if (d_regexp_ant
.find(*itr
) == d_regexp_ant
.end())
4840 d_regexp_ant
[*itr
] = antec
;
4845 antec
= NodeManager::currentNM()->mkNode(
4846 kind::AND
, antec
, mkExplain(rnfexp
));
4847 Node conc
= nvec
.size() == 1
4849 : NodeManager::currentNM()->mkNode(kind::AND
, nvec
);
4850 conc
= Rewriter::rewrite(conc
);
4851 sendLemma(antec
, conc
, "REGEXP_Unfold");
4855 cprocessed
.push_back(assertion
);
4859 processed
.push_back(assertion
);
4861 // d_regexp_ucached[assertion] = true;
4871 for( unsigned i
=0; i
<processed
.size(); i
++ ) {
4872 Trace("strings-regexp") << "...add " << processed
[i
] << " to u-cache." << std::endl
;
4873 d_regexp_ucached
.insert(processed
[i
]);
4875 for( unsigned i
=0; i
<cprocessed
.size(); i
++ ) {
4876 Trace("strings-regexp") << "...add " << cprocessed
[i
] << " to c-cache." << std::endl
;
4877 d_regexp_ccached
.insert(cprocessed
[i
]);
4883 bool TheoryStrings::checkPDerivative( Node x
, Node r
, Node atom
, bool &addedLemma
, std::vector
< Node
> &nf_exp
) {
4885 Node antnf
= mkExplain(nf_exp
);
4887 if(areEqual(x
, d_emptyString
)) {
4889 switch(d_regexp_opr
.delta(r
, exp
)) {
4891 Node antec
= mkRegExpAntec(atom
, x
.eqNode(d_emptyString
));
4892 antec
= NodeManager::currentNM()->mkNode(kind::AND
, antec
, antnf
);
4893 sendLemma(antec
, exp
, "RegExp Delta");
4895 d_regexp_ccached
.insert(atom
);
4899 d_regexp_ccached
.insert(atom
);
4903 Node antec
= mkRegExpAntec(atom
, x
.eqNode(d_emptyString
));
4904 antec
= NodeManager::currentNM()->mkNode(kind::AND
, antec
, antnf
);
4905 Node conc
= Node::null();
4906 sendLemma(antec
, conc
, "RegExp Delta CONFLICT");
4908 d_regexp_ccached
.insert(atom
);
4916 /*Node xr = getRepresentative( x );
4918 Node n = NodeManager::currentNM()->mkNode(kind::STRING_IN_REGEXP, xr, r);
4919 Node nn = Rewriter::rewrite( n );
4921 d_regexp_ccached.insert(atom);
4923 } else if(nn == d_false) {
4924 Node antec = mkRegExpAntec(atom, x.eqNode(xr));
4925 Node conc = Node::null();
4926 sendLemma(antec, conc, "RegExp Delta CONFLICT");
4928 d_regexp_ccached.insert(atom);
4932 Node sREant
= mkRegExpAntec(atom
, d_true
);
4933 sREant
= NodeManager::currentNM()->mkNode(kind::AND
, sREant
, antnf
);
4934 if(deriveRegExp( x
, r
, sREant
)) {
4936 d_regexp_ccached
.insert(atom
);
4943 CVC4::String
TheoryStrings::getHeadConst( Node x
) {
4945 return x
.getConst
< String
>();
4946 } else if( x
.getKind() == kind::STRING_CONCAT
) {
4947 if( x
[0].isConst() ) {
4948 return x
[0].getConst
< String
>();
4950 return d_emptyString
.getConst
< String
>();
4953 return d_emptyString
.getConst
< String
>();
4957 bool TheoryStrings::deriveRegExp( Node x
, Node r
, Node ant
) {
4959 Assert(x
!= d_emptyString
);
4960 Trace("regexp-derive") << "TheoryStrings::deriveRegExp: x=" << x
<< ", r= " << r
<< std::endl
;
4962 // Node n = NodeManager::currentNM()->mkNode( kind::STRING_IN_REGEXP, x, r );
4963 // Node r = Rewriter::rewrite( n );
4965 // sendLemma(ant, r, "REGEXP REWRITE");
4969 CVC4::String s
= getHeadConst( x
);
4970 if( !s
.isEmptyString() && d_regexp_opr
.checkConstRegExp( r
) ) {
4971 Node conc
= Node::null();
4974 for(unsigned i
=0; i
<s
.size(); ++i
) {
4975 CVC4::String c
= s
.substr(i
, 1);
4977 int rt
= d_regexp_opr
.derivativeS(dc
, c
, dc2
);
4981 } else if(rt
== 2) {
4990 Assert(false, "Impossible: TheoryStrings::deriveRegExp: const string in const regular expression.");
4993 Assert( x
.getKind() == kind::STRING_CONCAT
);
4994 std::vector
< Node
> vec_nodes
;
4995 for(unsigned int i
=1; i
<x
.getNumChildren(); ++i
) {
4996 vec_nodes
.push_back( x
[i
] );
4998 Node left
= mkConcat( vec_nodes
);
4999 left
= Rewriter::rewrite( left
);
5000 conc
= NodeManager::currentNM()->mkNode( kind::STRING_IN_REGEXP
, left
, dc
);
5002 /*std::vector< Node > sdc;
5003 d_regexp_opr.simplify(conc, sdc, true);
5004 if(sdc.size() == 1) {
5007 conc = Rewriter::rewrite(NodeManager::currentNM()->mkNode(kind::AND, conc));
5011 sendLemma(ant
, conc
, "RegExp-Derive");
5018 void TheoryStrings::addMembership(Node assertion
) {
5019 bool polarity
= assertion
.getKind() != kind::NOT
;
5020 TNode atom
= polarity
? assertion
: assertion
[0];
5025 NodeIntMap::const_iterator it
= d_pos_memberships
.find( x
);
5026 if( it
!=d_nf_pairs
.end() ){
5027 index
= (*it
).second
;
5028 for( int k
=0; k
<index
; k
++ ){
5029 if( k
<(int)d_pos_memberships_data
[x
].size() ){
5030 if( d_pos_memberships_data
[x
][k
]==r
){
5038 d_pos_memberships
[x
] = index
+ 1;
5039 if( index
<(int)d_pos_memberships_data
[x
].size() ){
5040 d_pos_memberships_data
[x
][index
] = r
;
5042 d_pos_memberships_data
[x
].push_back( r
);
5044 } else if(!options::stringIgnNegMembership()) {
5045 /*if(options::stringEIT() && d_regexp_opr.checkConstRegExp(r)) {
5047 Node r2 = d_regexp_opr.complement(r, rt);
5048 Node a = NodeManager::currentNM()->mkNode(kind::STRING_IN_REGEXP, x, r2);
5051 NodeIntMap::const_iterator it
= d_neg_memberships
.find( x
);
5052 if( it
!=d_nf_pairs
.end() ){
5053 index
= (*it
).second
;
5054 for( int k
=0; k
<index
; k
++ ){
5055 if( k
<(int)d_neg_memberships_data
[x
].size() ){
5056 if( d_neg_memberships_data
[x
][k
]==r
){
5064 d_neg_memberships
[x
] = index
+ 1;
5065 if( index
<(int)d_neg_memberships_data
[x
].size() ){
5066 d_neg_memberships_data
[x
][index
] = r
;
5068 d_neg_memberships_data
[x
].push_back( r
);
5072 if(polarity
|| !options::stringIgnNegMembership()) {
5073 d_regexp_memberships
.push_back( assertion
);
5077 Node
TheoryStrings::getNormalString( Node x
, std::vector
< Node
>& nf_exp
){
5079 Node xr
= getRepresentative( x
);
5080 if( d_normal_forms
.find( xr
) != d_normal_forms
.end() ){
5081 Node ret
= mkConcat( d_normal_forms
[xr
] );
5082 nf_exp
.insert( nf_exp
.end(), d_normal_forms_exp
[xr
].begin(), d_normal_forms_exp
[xr
].end() );
5083 addToExplanation( x
, d_normal_forms_base
[xr
], nf_exp
);
5084 Trace("strings-debug") << "Term: " << x
<< " has a normal form " << ret
<< std::endl
;
5087 if(x
.getKind() == kind::STRING_CONCAT
) {
5088 std::vector
< Node
> vec_nodes
;
5089 for(unsigned i
=0; i
<x
.getNumChildren(); i
++) {
5090 Node nc
= getNormalString( x
[i
], nf_exp
);
5091 vec_nodes
.push_back( nc
);
5093 return mkConcat( vec_nodes
);
5100 Node
TheoryStrings::getNormalSymRegExp(Node r
, std::vector
<Node
> &nf_exp
) {
5102 switch( r
.getKind() ) {
5103 case kind::REGEXP_EMPTY
:
5104 case kind::REGEXP_SIGMA
:
5106 case kind::STRING_TO_REGEXP
: {
5107 if(!r
[0].isConst()) {
5108 Node tmp
= getNormalString( r
[0], nf_exp
);
5110 ret
= NodeManager::currentNM()->mkNode(kind::STRING_TO_REGEXP
, tmp
);
5115 case kind::REGEXP_CONCAT
:
5116 case kind::REGEXP_UNION
:
5117 case kind::REGEXP_INTER
:
5118 case kind::REGEXP_STAR
:
5120 std::vector
< Node
> vec_nodes
;
5121 for (const Node
& cr
: r
)
5123 vec_nodes
.push_back(getNormalSymRegExp(cr
, nf_exp
));
5125 ret
= Rewriter::rewrite(
5126 NodeManager::currentNM()->mkNode(r
.getKind(), vec_nodes
));
5129 //case kind::REGEXP_PLUS:
5130 //case kind::REGEXP_OPT:
5131 //case kind::REGEXP_RANGE:
5133 Trace("strings-error") << "Unsupported term: " << r
<< " in normalization SymRegExp." << std::endl
;
5135 //return Node::null();
5141 /** run the given inference step */
5142 void TheoryStrings::runInferStep(InferStep s
, int effort
)
5144 Trace("strings-process") << "Run " << s
;
5147 Trace("strings-process") << ", effort = " << effort
;
5149 Trace("strings-process") << "..." << std::endl
;
5152 case CHECK_INIT
: checkInit(); break;
5153 case CHECK_CONST_EQC
: checkConstantEquivalenceClasses(); break;
5154 case CHECK_EXTF_EVAL
: checkExtfEval(effort
); break;
5155 case CHECK_CYCLES
: checkCycles(); break;
5156 case CHECK_FLAT_FORMS
: checkFlatForms(); break;
5157 case CHECK_NORMAL_FORMS_EQ
: checkNormalFormsEq(); break;
5158 case CHECK_NORMAL_FORMS_DEQ
: checkNormalFormsDeq(); break;
5159 case CHECK_CODES
: checkCodes(); break;
5160 case CHECK_LENGTH_EQC
: checkLengthsEqc(); break;
5161 case CHECK_EXTF_REDUCTION
: checkExtfReductions(effort
); break;
5162 case CHECK_MEMBERSHIP
: checkMemberships(); break;
5163 case CHECK_CARDINALITY
: checkCardinality(); break;
5164 default: Unreachable(); break;
5166 Trace("strings-process") << "Done " << s
5167 << ", addedFact = " << !d_pending
.empty() << " "
5168 << !d_lemma_cache
.empty()
5169 << ", d_conflict = " << d_conflict
<< std::endl
;
5172 bool TheoryStrings::hasStrategyEffort(Effort e
) const
5174 return d_strat_steps
.find(e
) != d_strat_steps
.end();
5177 void TheoryStrings::addStrategyStep(InferStep s
, int effort
, bool addBreak
)
5179 // must run check init first
5180 Assert((s
== CHECK_INIT
)==d_infer_steps
.empty());
5181 // must use check cycles when using flat forms
5182 Assert(s
!= CHECK_FLAT_FORMS
5183 || std::find(d_infer_steps
.begin(), d_infer_steps
.end(), CHECK_CYCLES
)
5184 != d_infer_steps
.end());
5185 d_infer_steps
.push_back(s
);
5186 d_infer_step_effort
.push_back(effort
);
5189 d_infer_steps
.push_back(BREAK
);
5190 d_infer_step_effort
.push_back(0);
5194 void TheoryStrings::initializeStrategy()
5196 // initialize the strategy if not already done so
5197 if (!d_strategy_init
)
5199 std::map
<Effort
, unsigned> step_begin
;
5200 std::map
<Effort
, unsigned> step_end
;
5201 d_strategy_init
= true;
5202 // beginning indices
5203 step_begin
[EFFORT_FULL
] = 0;
5204 if (options::stringEager())
5206 step_begin
[EFFORT_STANDARD
] = 0;
5208 // add the inference steps
5209 addStrategyStep(CHECK_INIT
);
5210 addStrategyStep(CHECK_CONST_EQC
);
5211 addStrategyStep(CHECK_EXTF_EVAL
, 0);
5212 addStrategyStep(CHECK_CYCLES
);
5213 if (options::stringFlatForms())
5215 addStrategyStep(CHECK_FLAT_FORMS
);
5217 addStrategyStep(CHECK_EXTF_REDUCTION
, 1);
5218 if (options::stringEager())
5220 // do only the above inferences at standard effort, if applicable
5221 step_end
[EFFORT_STANDARD
] = d_infer_steps
.size() - 1;
5223 addStrategyStep(CHECK_NORMAL_FORMS_EQ
);
5224 addStrategyStep(CHECK_EXTF_EVAL
, 1);
5225 if (!options::stringEagerLen())
5227 addStrategyStep(CHECK_LENGTH_EQC
);
5229 addStrategyStep(CHECK_NORMAL_FORMS_DEQ
);
5230 addStrategyStep(CHECK_CODES
);
5231 if (options::stringEagerLen())
5233 addStrategyStep(CHECK_LENGTH_EQC
);
5235 if (options::stringExp() && !options::stringGuessModel())
5237 addStrategyStep(CHECK_EXTF_REDUCTION
, 2);
5239 addStrategyStep(CHECK_MEMBERSHIP
);
5240 addStrategyStep(CHECK_CARDINALITY
);
5241 step_end
[EFFORT_FULL
] = d_infer_steps
.size() - 1;
5242 if (options::stringExp() && options::stringGuessModel())
5244 step_begin
[EFFORT_LAST_CALL
] = d_infer_steps
.size();
5245 // these two steps are run in parallel
5246 addStrategyStep(CHECK_EXTF_REDUCTION
, 2, false);
5247 addStrategyStep(CHECK_EXTF_EVAL
, 3);
5248 step_end
[EFFORT_LAST_CALL
] = d_infer_steps
.size() - 1;
5250 // set the beginning/ending ranges
5251 for (const std::pair
<const Effort
, unsigned>& it_begin
: step_begin
)
5253 Effort e
= it_begin
.first
;
5254 std::map
<Effort
, unsigned>::iterator it_end
= step_end
.find(e
);
5255 Assert(it_end
!= step_end
.end());
5257 std::pair
<unsigned, unsigned>(it_begin
.second
, it_end
->second
);
5262 void TheoryStrings::runStrategy(unsigned sbegin
, unsigned send
)
5264 Trace("strings-process") << "----check, next round---" << std::endl
;
5265 for (unsigned i
= sbegin
; i
<= send
; i
++)
5267 InferStep curr
= d_infer_steps
[i
];
5277 runInferStep(curr
, d_infer_step_effort
[i
]);
5284 Trace("strings-process") << "----finished round---" << std::endl
;
5287 }/* CVC4::theory::strings namespace */
5288 }/* CVC4::theory namespace */
5289 }/* CVC4 namespace */