1 /********************* */
2 /*! \file quant_conflict_find.h
4 ** Original author: Andrew Reynolds
5 ** Major contributors: none
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief quantifiers conflict find class
15 #include "cvc4_private.h"
17 #ifndef QUANT_CONFLICT_FIND
18 #define QUANT_CONFLICT_FIND
20 #include "context/cdhashmap.h"
21 #include "context/cdchunk_list.h"
22 #include "theory/quantifiers_engine.h"
23 #include "theory/quantifiers/term_database.h"
27 namespace quantifiers
{
29 class QuantConflictFind
;
34 friend class QuantInfo
;
36 //current children information
38 //children of this object
39 std::vector
< int > d_children_order
;
40 unsigned getNumChildren() { return d_children
.size(); }
41 MatchGen
* getChild( int i
) { return &d_children
[d_children_order
[i
]]; }
42 //MatchGen * getChild( int i ) { return &d_children[i]; }
43 //current matching information
44 std::vector
< TermArgTrie
* > d_qn
;
45 std::vector
< std::map
< TNode
, TermArgTrie
>::iterator
> d_qni
;
46 bool doMatching( QuantConflictFind
* p
, QuantInfo
* qi
);
47 //for matching : each index is either a variable or a ground term
49 std::map
< int, int > d_qni_var_num
;
50 std::map
< int, TNode
> d_qni_gterm
;
51 std::map
< int, TNode
> d_qni_gterm_rep
;
52 std::map
< int, int > d_qni_bound
;
53 std::vector
< int > d_qni_bound_except
;
54 std::map
< int, TNode
> d_qni_bound_cons
;
55 std::map
< int, int > d_qni_bound_cons_var
;
56 std::map
< int, int >::iterator d_binding_it
;
57 //std::vector< int > d_independent;
60 //int getVarBindingVar();
61 std::map
< int, Node
> d_ground_eval
;
62 //determine variable order
63 void determineVariableOrder( QuantInfo
* qi
, std::vector
< int >& bvars
);
64 void collectBoundVar( QuantInfo
* qi
, Node n
, std::vector
< int >& cbvars
);
66 //type of the match generator
79 void debugPrintType( const char * c
, short typ
, bool isTrace
= false );
81 MatchGen() : d_type( typ_invalid
){}
82 MatchGen( QuantInfo
* qi
, Node n
, bool isVar
= false );
87 std::vector
< MatchGen
> d_children
;
90 void reset_round( QuantConflictFind
* p
);
91 void reset( QuantConflictFind
* p
, bool tgt
, QuantInfo
* qi
);
92 bool getNextMatch( QuantConflictFind
* p
, QuantInfo
* qi
);
93 bool getExplanation( QuantConflictFind
* p
, QuantInfo
* qi
, std::vector
< Node
>& exp
);
94 Node
getExplanationTerm( QuantConflictFind
* p
, QuantInfo
* qi
, Node t
, std::vector
< Node
>& exp
);
95 bool isValid() { return d_type
!=typ_invalid
; }
98 // is this term treated as UF application?
99 static bool isHandledBoolConnective( TNode n
);
100 static bool isHandledUfTerm( TNode n
);
101 static Node
getOperator( QuantConflictFind
* p
, Node n
);
102 //can this node be handled by the algorithm
103 static bool isHandled( TNode n
);
106 //info for quantifiers
109 void registerNode( Node n
, bool hasPol
, bool pol
, bool beneathQuant
= false );
110 void flatten( Node n
, bool beneathQuant
);
111 private: //for completing match
112 std::vector
< int > d_unassigned
;
113 std::vector
< TypeNode
> d_unassigned_tn
;
114 int d_unassigned_nvar
;
116 std::vector
< int > d_una_eqc_count
;
118 QuantInfo() : d_mg( NULL
) {}
119 ~QuantInfo() { delete d_mg
; }
120 std::vector
< TNode
> d_vars
;
121 std::map
< TNode
, int > d_var_num
;
122 std::vector
< int > d_tsym_vars
;
123 std::map
< TNode
, bool > d_inMatchConstraint
;
124 std::map
< int, std::vector
< Node
> > d_var_constraint
[2];
125 int getVarNum( TNode v
) { return d_var_num
.find( v
)!=d_var_num
.end() ? d_var_num
[v
] : -1; }
126 bool isVar( TNode v
) { return d_var_num
.find( v
)!=d_var_num
.end(); }
127 int getNumVars() { return (int)d_vars
.size(); }
128 TNode
getVar( int i
) { return d_vars
[i
]; }
132 std::map
< int, MatchGen
* > d_var_mg
;
133 void reset_round( QuantConflictFind
* p
);
136 void initialize( Node q
, Node qn
);
137 //current constraints
138 std::vector
< TNode
> d_match
;
139 std::vector
< TNode
> d_match_term
;
140 std::map
< int, std::map
< TNode
, int > > d_curr_var_deq
;
141 std::map
< Node
, bool > d_tconstraints
;
142 int getCurrentRepVar( int v
);
143 TNode
getCurrentValue( TNode n
);
144 TNode
getCurrentExpValue( TNode n
);
145 bool getCurrentCanBeEqual( QuantConflictFind
* p
, int v
, TNode n
, bool chDiseq
= false );
146 int addConstraint( QuantConflictFind
* p
, int v
, TNode n
, bool polarity
);
147 int addConstraint( QuantConflictFind
* p
, int v
, TNode n
, int vn
, bool polarity
, bool doRemove
);
148 bool setMatch( QuantConflictFind
* p
, int v
, TNode n
);
149 bool isMatchSpurious( QuantConflictFind
* p
);
150 bool isTConstraintSpurious( QuantConflictFind
* p
, std::vector
< Node
>& terms
);
151 bool entailmentTest( QuantConflictFind
* p
, Node lit
, bool chEnt
= true );
152 bool completeMatch( QuantConflictFind
* p
, std::vector
< int >& assigned
, bool doContinue
= false );
153 void revertMatch( std::vector
< int >& assigned
);
154 void debugPrintMatch( const char * c
);
155 bool isConstrainedVar( int v
);
157 void getMatch( std::vector
< Node
>& terms
);
160 class QuantConflictFind
: public QuantifiersModule
162 friend class MatchGen
;
163 friend class QuantInfo
;
164 typedef context::CDChunkList
<Node
> NodeList
;
165 typedef context::CDHashMap
<Node
, bool, NodeHashFunction
> NodeBoolMap
;
167 context::Context
* d_c
;
168 context::CDO
< bool > d_conflict
;
169 std::vector
< Node
> d_quant_order
;
170 std::map
< Kind
, Node
> d_zero
;
171 //for storing nodes created during t-constraint solving (prevents memory leaks)
172 std::vector
< Node
> d_tempCache
;
174 std::map
< Node
, Node
> d_op_node
;
176 std::map
< Node
, int > d_fid
;
177 Node
mkEqNode( Node a
, Node b
);
178 public: //for ground terms
181 TNode
getZero( Kind k
);
183 Node
evaluateTerm( Node n
);
184 int evaluate( Node n
, bool pref
= false, bool hasPref
= false );
186 //currently asserted quantifiers
188 std::map
< Node
, QuantInfo
> d_qinfo
;
189 private: //for equivalence classes
190 eq::EqualityEngine
* getEqualityEngine();
191 bool areDisequal( Node n1
, Node n2
);
192 bool areEqual( Node n1
, Node n2
);
193 Node
getRepresentative( Node n
);
194 TermDb
* getTermDatabase();
196 std::map
< TypeNode
, std::vector
< TNode
> > d_eqcs
;
197 std::map
< TypeNode
, Node
> d_model_basis
;
205 void setEffort( int e
) { d_effort
= e
; }
206 static short getMaxQcfEffort();
207 bool areMatchEqual( TNode n1
, TNode n2
);
208 bool areMatchDisequal( TNode n1
, TNode n2
);
210 QuantConflictFind( QuantifiersEngine
* qe
, context::Context
* c
);
211 /** register quantifier */
212 void registerQuantifier( Node q
);
214 /** assert quantifier */
215 void assertNode( Node q
);
217 void newEqClass( Node n
);
219 void merge( Node a
, Node b
);
220 /** assert disequal */
221 void assertDisequal( Node a
, Node b
);
223 bool needsCheck( Theory::Effort level
);
225 void reset_round( Theory::Effort level
);
227 void check( Theory::Effort level
, unsigned quant_e
);
229 bool d_needs_computeRelEqr
;
231 void computeRelevantEqr();
233 void debugPrint( const char * c
);
235 std::vector
< Node
> d_quants
;
236 std::map
< Node
, int > d_quant_id
;
237 void debugPrintQuant( const char * c
, Node q
);
238 void debugPrintQuantBody( const char * c
, Node q
, Node n
, bool doVarNum
= true );
240 /** statistics class */
243 IntStat d_inst_rounds
;
244 IntStat d_conflict_inst
;
246 IntStat d_entailment_checks
;
250 Statistics d_statistics
;
251 /** Identify this module */
252 std::string
identify() const { return "QcfEngine"; }