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
< TNode
, QcfNodeIndex
> d_children
;
35 void clear() { d_children
.clear(); }
36 void debugPrint( const char * c
, int t
);
37 Node
existsTerm( TNode n
, std::vector
< TNode
>& reps
, int index
= 0 );
38 Node
addTerm( TNode n
, std::vector
< TNode
>& reps
, int index
= 0 );
46 //current children information
48 //children of this object
49 //std::vector< int > d_children_order;
50 unsigned getNumChildren() { return d_children
.size(); }
51 //MatchGen * getChild( int i ) { return &d_children[d_children_order[i]]; }
52 MatchGen
* getChild( int i
) { return &d_children
[i
]; }
53 //current matching information
54 std::vector
< QcfNodeIndex
* > d_qn
;
55 std::vector
< std::map
< TNode
, QcfNodeIndex
>::iterator
> d_qni
;
56 bool doMatching( QuantConflictFind
* p
, QuantInfo
* qi
);
57 //for matching : each index is either a variable or a ground term
59 std::map
< int, int > d_qni_var_num
;
60 std::map
< int, TNode
> d_qni_gterm
;
61 std::map
< int, TNode
> d_qni_gterm_rep
;
62 std::map
< int, int > d_qni_bound
;
63 std::map
< int, TNode
> d_qni_bound_cons
;
64 std::map
< int, int > d_qni_bound_cons_var
;
65 std::map
< int, int >::iterator d_binding_it
;
67 //int getVarBindingVar();
68 std::map
< int, Node
> d_ground_eval
;
70 //type of the match generator
80 void debugPrintType( const char * c
, short typ
, bool isTrace
= false );
82 MatchGen() : d_type( typ_invalid
){}
83 MatchGen( QuantConflictFind
* p
, Node q
, Node n
, bool isTop
= false, bool isVar
= false );
86 std::vector
< MatchGen
> d_children
;
89 void reset_round( QuantConflictFind
* p
);
90 void reset( QuantConflictFind
* p
, bool tgt
, QuantInfo
* qi
);
91 bool getNextMatch( QuantConflictFind
* p
, QuantInfo
* qi
);
92 bool isValid() { return d_type
!=typ_invalid
; }
96 //info for quantifiers
99 QuantInfo() : d_mg( NULL
) {}
100 std::vector
< TNode
> d_vars
;
101 std::map
< TNode
, int > d_var_num
;
102 //std::map< EqRegistry *, bool > d_rel_eqr;
103 std::map
< int, std::vector
< Node
> > d_var_constraint
[2];
104 int getVarNum( TNode v
) { return d_var_num
.find( v
)!=d_var_num
.end() ? d_var_num
[v
] : -1; }
105 bool isVar( TNode v
) { return d_var_num
.find( v
)!=d_var_num
.end(); }
106 int getNumVars() { return (int)d_vars
.size(); }
107 TNode
getVar( int i
) { return d_vars
[i
]; }
110 std::map
< int, MatchGen
* > d_var_mg
;
111 void reset_round( QuantConflictFind
* p
);
113 //current constraints
114 std::map
< int, TNode
> d_match
;
115 std::map
< int, TNode
> d_match_term
;
116 std::map
< int, std::map
< TNode
, int > > d_curr_var_deq
;
117 int getCurrentRepVar( int v
);
118 TNode
getCurrentValue( TNode n
);
119 bool getCurrentCanBeEqual( QuantConflictFind
* p
, int v
, TNode n
, bool chDiseq
= false );
120 int addConstraint( QuantConflictFind
* p
, int v
, TNode n
, bool polarity
);
121 int addConstraint( QuantConflictFind
* p
, int v
, TNode n
, int vn
, bool polarity
, bool doRemove
);
122 bool setMatch( QuantConflictFind
* p
, int v
, TNode n
);
123 bool isMatchSpurious( QuantConflictFind
* p
);
124 bool completeMatch( QuantConflictFind
* p
, std::vector
< int >& assigned
);
125 void debugPrintMatch( const char * c
);
126 bool isConstrainedVar( int v
);
129 class QuantConflictFind
: public QuantifiersModule
131 friend class QcfNodeIndex
;
132 friend class MatchGen
;
133 friend class QuantInfo
;
134 typedef context::CDChunkList
<Node
> NodeList
;
135 typedef context::CDHashMap
<Node
, bool, NodeHashFunction
> NodeBoolMap
;
137 context::Context
* d_c
;
138 context::CDO
< bool > d_conflict
;
140 //void registerAssertion( Node n );
141 void registerNode( Node q
, Node n
, bool hasPol
, bool pol
);
142 void flatten( Node q
, Node n
);
144 std::map
< Node
, Node
> d_op_node
;
145 Node
getFunction( Node n
, int& index
, bool isQuant
= false );
147 std::map
< Node
, int > d_fid
;
148 Node
mkEqNode( Node a
, Node b
);
149 public: //for ground terms
153 Node
evaluateTerm( Node n
);
154 int evaluate( Node n
, bool pref
= false, bool hasPref
= false );
156 //currently asserted quantifiers
158 std::map
< Node
, QuantInfo
> d_qinfo
;
159 private: //for equivalence classes
160 eq::EqualityEngine
* getEqualityEngine();
161 bool areDisequal( Node n1
, Node n2
);
162 bool areEqual( Node n1
, Node n2
);
163 Node
getRepresentative( Node n
);
168 EqcInfo( context::Context* c ) : d_diseq( c ) {}
170 bool isDisequal( Node n ) { return d_diseq.find( n )!=d_diseq.end() && d_diseq[n]; }
171 void setDisequal( Node n, bool val = true ) { d_diseq[n] = val; }
172 //NodeBoolMap& getRelEqr( int index ) { return index==0 ? d_rel_eqr_e : d_rel_eqr_d; }
174 std::map< Node, EqcInfo * > d_eqc_info;
175 EqcInfo * getEqcInfo( Node n, bool doCreate = true );
177 // operator -> index(terms)
178 std::map
< TNode
, QcfNodeIndex
> d_uf_terms
;
179 // operator -> index(eqc -> terms)
180 std::map
< TNode
, QcfNodeIndex
> d_eqc_uf_terms
;
182 QcfNodeIndex
* getQcfNodeIndex( Node eqc
, Node f
);
183 QcfNodeIndex
* getQcfNodeIndex( Node f
);
185 std::map
< TypeNode
, std::vector
< TNode
> > d_eqcs
;
186 //mapping from UF terms to representatives of their arguments
187 std::map
< TNode
, std::vector
< TNode
> > d_arg_reps
;
189 void computeArgReps( TNode n
);
190 // is this term treated as UF application?
191 bool isHandledUfTerm( TNode n
);
202 bool isPropagationSet();
203 bool areMatchEqual( TNode n1
, TNode n2
);
204 bool areMatchDisequal( TNode n1
, TNode n2
);
206 QuantConflictFind( QuantifiersEngine
* qe
, context::Context
* c
);
208 /** register assertions */
209 //void registerAssertions( std::vector< Node >& assertions );
210 /** register quantifier */
211 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 void check( Theory::Effort level
);
225 bool needsCheck( Theory::Effort level
);
227 void computeRelevantEqr();
229 void debugPrint( const char * c
);
231 std::vector
< Node
> d_quants
;
232 std::map
< Node
, int > d_quant_id
;
233 void debugPrintQuant( const char * c
, Node q
);
234 void debugPrintQuantBody( const char * c
, Node q
, Node n
, bool doVarNum
= true );
236 /** statistics class */
239 IntStat d_inst_rounds
;
240 IntStat d_conflict_inst
;
245 Statistics d_statistics
;