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-2013 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"
26 namespace quantifiers
{
30 class QuantConflictFind
;
34 std::map
< Node
, QcfNodeIndex
> d_children
;
35 void clear() { d_children
.clear(); }
36 //Node existsTerm( QuantConflictFind * qcf, Node n, int index = 0 );
37 //Node addTerm( QuantConflictFind * qcf, Node n, int index = 0 );
38 //bool addTermEq( QuantConflictFind * qcf, Node n1, Node n2, int index = 0 );
39 void debugPrint( const char * c
, int t
);
41 Node
existsTerm( Node n
, std::vector
< Node
>& reps
, int index
= 0 );
42 Node
addTerm( Node n
, std::vector
< Node
>& reps
, int index
= 0 );
43 bool addTermEq( Node n1
, Node n2
, std::vector
< Node
>& reps1
, std::vector
< Node
>& reps2
, int index
= 0 );
47 typedef context::CDChunkList
<Node
> NodeList
;
48 typedef context::CDHashMap
<Node
, bool, NodeHashFunction
> NodeBoolMap
;
50 EqRegistry( context::Context
* c
);
52 context::CDO
< bool > d_active
;
53 //NodeIndex describing pairs that meet the criteria of the EqRegistry
56 //qcf nodes that this helps to 1:satisfy -1:falsify 0:both a quantifier conflict node
57 //std::map< QcfNode *, int > d_qcf;
59 //bool hasEqc( Node n ) { return d_t_eqc.find( n )!=d_t_eqc.end() && d_t_eqc[n]; }
60 //void setEqc( Node n, bool val = true ) { d_t_eqc[n] = val; }
61 void clear() { d_qni
.clear(); }
62 void debugPrint( const char * c
, int t
);
68 QcfNode( context::Context* c );
70 std::map< int, QcfNode * > d_child;
72 EqRegistry * d_reg[2];
76 class QuantConflictFind
: public QuantifiersModule
78 friend class QcfNodeIndex
;
79 typedef context::CDChunkList
<Node
> NodeList
;
80 typedef context::CDHashMap
<Node
, bool, NodeHashFunction
> NodeBoolMap
;
82 context::Context
* d_c
;
83 context::CDO
< bool > d_conflict
;
85 //void registerAssertion( Node n );
86 void registerNode( Node q
, Node n
, bool hasPol
, bool pol
);
87 void flatten( Node q
, Node n
);
89 std::map
< TypeNode
, Node
> d_fv
;
90 Node
getFv( TypeNode tn
);
91 std::map
< Node
, Node
> d_op_node
;
92 int getFunctionId( Node f
);
93 bool isLessThan( Node a
, Node b
);
94 Node
getFunction( Node n
, bool isQuant
= false );
96 std::map
< Node
, int > d_fid
;
97 Node
mkEqNode( Node a
, Node b
);
98 private: //for ground terms
101 std::map
< Node
, std::map
< Node
, EqRegistry
* > > d_eqr
[2];
102 EqRegistry
* getEqRegistry( bool polarity
, Node lit
, bool doCreate
= true );
103 void getEqRegistryApps( Node lit
, std::vector
< Node
>& terms
);
104 int evaluate( Node n
);
105 public: //for quantifiers
109 //current children information
111 //children of this object
112 std::vector
< int > d_children_order
;
113 unsigned getNumChildren() { return d_children
.size(); }
114 MatchGen
* getChild( int i
) { return &d_children
[d_children_order
[i
]]; }
115 //current matching information
116 std::vector
< QcfNodeIndex
* > d_qn
;
117 std::vector
< std::map
< Node
, QcfNodeIndex
>::iterator
> d_qni
;
118 bool doMatching( QuantConflictFind
* p
, Node q
);
119 //for matching : each index is either a variable or a ground term
121 std::map
< int, int > d_qni_var_num
;
122 std::map
< int, Node
> d_qni_gterm
;
123 std::map
< int, Node
> d_qni_gterm_rep
;
124 std::map
< int, int > d_qni_bound
;
125 std::map
< int, Node
> d_qni_bound_cons
;
127 //type of the match generator
137 void debugPrintType( const char * c
, short typ
, bool isTrace
= false );
139 MatchGen() : d_type( typ_invalid
){}
140 MatchGen( QuantConflictFind
* p
, Node q
, Node n
, bool isTop
= false, bool isVar
= false );
143 std::vector
< MatchGen
> d_children
;
146 void reset_round( QuantConflictFind
* p
);
147 void reset( QuantConflictFind
* p
, bool tgt
, Node q
);
148 bool getNextMatch( QuantConflictFind
* p
, Node q
);
149 bool isValid() { return d_type
!=typ_invalid
; }
153 //currently asserted quantifiers
155 //info for quantifiers
158 QuantInfo() : d_mg( NULL
) {}
159 std::vector
< Node
> d_vars
;
160 std::map
< Node
, int > d_var_num
;
161 std::map
< EqRegistry
*, bool > d_rel_eqr
;
162 std::map
< int, std::vector
< Node
> > d_var_constraint
[2];
163 int getVarNum( Node v
) { return d_var_num
.find( v
)!=d_var_num
.end() ? d_var_num
[v
] : -1; }
164 bool isVar( Node v
) { return d_var_num
.find( v
)!=d_var_num
.end(); }
165 int getNumVars() { return (int)d_vars
.size(); }
166 Node
getVar( int i
) { return d_vars
[i
]; }
168 std::map
< int, MatchGen
* > d_var_mg
;
169 void reset_round( QuantConflictFind
* p
);
171 //current constraints
172 std::map
< int, Node
> d_match
;
173 std::map
< int, std::map
< Node
, int > > d_curr_var_deq
;
174 int getCurrentRepVar( int v
);
175 Node
getCurrentValue( Node n
);
176 bool getCurrentCanBeEqual( QuantConflictFind
* p
, int v
, Node n
);
177 int addConstraint( QuantConflictFind
* p
, int v
, Node n
, bool polarity
);
178 int addConstraint( QuantConflictFind
* p
, int v
, Node n
, int vn
, bool polarity
, bool doRemove
);
179 bool setMatch( QuantConflictFind
* p
, int v
, Node n
);
180 bool isMatchSpurious( QuantConflictFind
* p
);
181 bool completeMatch( QuantConflictFind
* p
, Node q
, std::vector
< int >& assigned
);
182 void debugPrintMatch( const char * c
);
184 std::map
< Node
, QuantInfo
> d_qinfo
;
185 private: //for equivalence classes
186 eq::EqualityEngine
* getEqualityEngine();
187 bool areDisequal( Node n1
, Node n2
);
188 bool areEqual( Node n1
, Node n2
);
189 Node
getRepresentative( Node n
);
190 Node
getTerm( Node n
);
194 EqcInfo( context::Context
* c
) : d_diseq( c
) {}
196 bool isDisequal( Node n
) { return d_diseq
.find( n
)!=d_diseq
.end() && d_diseq
[n
]; }
197 void setDisequal( Node n
, bool val
= true ) { d_diseq
[n
] = val
; }
198 //NodeBoolMap& getRelEqr( int index ) { return index==0 ? d_rel_eqr_e : d_rel_eqr_d; }
200 std::map
< Node
, EqcInfo
* > d_eqc_info
;
201 EqcInfo
* getEqcInfo( Node n
, bool doCreate
= true );
202 // operator -> index(terms)
203 std::map
< Node
, QcfNodeIndex
> d_uf_terms
;
204 // eqc x operator -> index(terms)
205 std::map
< Node
, std::map
< Node
, QcfNodeIndex
> > d_eqc_uf_terms
;
207 std::map
< TypeNode
, std::vector
< Node
> > d_eqcs
;
208 //mapping from UF terms to representatives of their arguments
209 std::map
< Node
, std::vector
< Node
> > d_arg_reps
;
211 void computeArgReps( Node n
);
213 QuantConflictFind( QuantifiersEngine
* qe
, context::Context
* c
);
215 /** register assertions */
216 //void registerAssertions( std::vector< Node >& assertions );
217 /** register quantifier */
218 void registerQuantifier( Node q
);
221 /** assert quantifier */
222 void assertNode( Node q
);
224 void newEqClass( Node n
);
226 void merge( Node a
, Node b
);
227 /** assert disequal */
228 void assertDisequal( Node a
, Node b
);
230 void check( Theory::Effort level
);
232 bool needsCheck( Theory::Effort level
);
234 void computeRelevantEqr();
236 void debugPrint( const char * c
);
238 std::vector
< Node
> d_quants
;
239 std::map
< Node
, int > d_quant_id
;
240 void debugPrintQuant( const char * c
, Node q
);
241 void debugPrintQuantBody( const char * c
, Node q
, Node n
, bool doVarNum
= true );
243 /** statistics class */
246 IntStat d_inst_rounds
;
247 IntStat d_conflict_inst
;
251 Statistics d_statistics
;