1 /********************* */
4 ** Original author: ajreynol
5 ** Major contributors: bobot
6 ** Minor contributors (to current version): mdeters
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009-2012 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 inst match class
15 #include "cvc4_private.h"
17 #ifndef __CVC4__THEORY__QUANTIFIERS__INST_MATCH_H
18 #define __CVC4__THEORY__QUANTIFIERS__INST_MATCH_H
20 #include "util/hash.h"
21 #include "context/cdo.h"
23 #include <ext/hash_set>
26 #include "context/cdlist.h"
27 #include "expr/node.h"
32 class QuantifiersEngine
;
37 /** basic class defining an instantiation */
39 /* map from variable to ground terms */
40 std::map
< Node
, Node
> d_map
;
43 InstMatch( InstMatch
* m
);
45 /** set the match of v to m */
46 bool setMatch( EqualityQuery
* q
, TNode v
, TNode m
);
47 /* This version tell if the variable has been set */
48 bool setMatch( EqualityQuery
* q
, TNode v
, TNode m
, bool & set
);
49 /** fill all unfilled values with m */
50 bool add( InstMatch
& m
);
51 /** if compatible, fill all unfilled values with m and return true
52 return false otherwise */
53 bool merge( EqualityQuery
* q
, InstMatch
& m
);
54 /** debug print method */
55 void debugPrint( const char* c
);
57 bool isComplete( Node f
) { return d_map
.size()==f
[0].getNumChildren(); }
59 void makeComplete( Node f
, QuantifiersEngine
* qe
);
60 /** make internal representative */
61 //void makeInternalRepresentative( QuantifiersEngine* qe );
62 /** make representative */
63 void makeRepresentative( QuantifiersEngine
* qe
);
65 Node
getValue( Node var
) const;
67 void clear(){ d_map
.clear(); }
69 bool empty(){ return d_map
.empty(); }
71 inline void toStream(std::ostream
& out
) const {
72 out
<< "INST_MATCH( ";
73 for( std::map
< Node
, Node
>::const_iterator it
= d_map
.begin(); it
!= d_map
.end(); ++it
){
74 if( it
!= d_map
.begin() ){ out
<< ", "; }
75 out
<< it
->first
<< " -> " << it
->second
;
86 template<class Iterator
>
87 void erase(Iterator begin
, Iterator end
){
88 for(Iterator i
= begin
; i
!= end
; ++i
){
92 void erase(Node node
){ d_map
.erase(node
); }
94 Node
get( TNode var
) { return d_map
[var
]; }
96 void set(TNode var
, TNode n
);
97 size_t size(){ return d_map
.size(); }
99 std::map
< Node
, Node
>::iterator
begin(){ return d_map
.begin(); };
100 std::map
< Node
, Node
>::iterator
end(){ return d_map
.end(); };
101 std::map
< Node
, Node
>::iterator
find(Node var
){ return d_map
.find(var
); };
102 /* Node used for matching the trigger only for mono-trigger (just for
103 efficiency because I need only that) */
105 };/* class InstMatch */
107 inline std::ostream
& operator<<(std::ostream
& out
, const InstMatch
& m
) {
112 /** trie for InstMatch objects */
113 class InstMatchTrie
{
115 class ImtIndexOrder
{
117 std::vector
< int > d_order
;
118 };/* class InstMatchTrie ImtIndexOrder */
120 /** add match m for quantifier f starting at index, take into account equalities q, return true if successful */
121 void addInstMatch2( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, int index
, ImtIndexOrder
* imtio
);
123 bool existsInstMatch2( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
, bool modInst
, int index
, ImtIndexOrder
* imtio
);
126 std::map
< Node
, InstMatchTrie
> d_data
;
131 /** return true if m exists in this trie
132 modEq is if we check modulo equality
133 modInst is if we return true if m is an instance of a match that exists
135 bool existsInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false,
136 bool modInst
= false, ImtIndexOrder
* imtio
= NULL
);
137 /** add match m for quantifier f, take into account equalities if modEq = true,
138 if imtio is non-null, this is the order to add to trie
139 return true if successful
141 bool addInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false,
142 bool modInst
= false, ImtIndexOrder
* imtio
= NULL
);
143 };/* class InstMatchTrie */
146 /** trie for InstMatch objects */
147 class CDInstMatchTrie
{
149 class ImtIndexOrder
{
151 std::vector
< int > d_order
;
152 };/* class InstMatchTrie ImtIndexOrder */
154 /** add match m for quantifier f starting at index, take into account equalities q, return true if successful */
155 void addInstMatch2( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, context::Context
* c
, int index
, ImtIndexOrder
* imtio
);
157 bool existsInstMatch2( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
, bool modInst
, int index
, ImtIndexOrder
* imtio
);
160 std::map
< Node
, CDInstMatchTrie
* > d_data
;
162 context::CDO
< bool > d_valid
;
164 CDInstMatchTrie( context::Context
* c
) : d_valid( c
, false ){}
167 /** return true if m exists in this trie
168 modEq is if we check modulo equality
169 modInst is if we return true if m is an instance of a match that exists
171 bool existsInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false,
172 bool modInst
= false, ImtIndexOrder
* imtio
= NULL
);
173 /** add match m for quantifier f, take into account equalities if modEq = true,
174 if imtio is non-null, this is the order to add to trie
175 return true if successful
177 bool addInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, context::Context
* c
, bool modEq
= false,
178 bool modInst
= false, ImtIndexOrder
* imtio
= NULL
);
179 };/* class CDInstMatchTrie */
181 class InstMatchTrieOrdered
{
183 InstMatchTrie::ImtIndexOrder
* d_imtio
;
186 InstMatchTrieOrdered( InstMatchTrie::ImtIndexOrder
* imtio
) : d_imtio( imtio
){}
187 ~InstMatchTrieOrdered(){}
189 InstMatchTrie::ImtIndexOrder
* getOrdering() { return d_imtio
; }
191 InstMatchTrie
* getTrie() { return &d_imt
; }
193 /** add match m, return true if successful */
194 bool addInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false, bool modInst
= false ){
195 return d_imt
.addInstMatch( qe
, f
, m
, modEq
, modInst
, d_imtio
);
197 bool existsInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false, bool modInst
= false ){
198 return d_imt
.existsInstMatch( qe
, f
, m
, modEq
, modInst
, d_imtio
);
200 };/* class InstMatchTrieOrdered */
202 }/* CVC4::theory::inst namespace */
204 typedef CVC4::theory::inst::InstMatch InstMatch
;
206 }/* CVC4::theory namespace */
207 }/* CVC4 namespace */
209 #endif /* __CVC4__THEORY__QUANTIFIERS__INST_MATCH_H */