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"
22 #include <ext/hash_set>
25 #include "context/cdlist.h"
26 #include "expr/node.h"
31 class QuantifiersEngine
;
36 /** basic class defining an instantiation */
38 /* map from variable to ground terms */
39 std::map
< Node
, Node
> d_map
;
42 InstMatch( InstMatch
* m
);
44 /** set the match of v to m */
45 bool setMatch( EqualityQuery
* q
, TNode v
, TNode m
);
46 /* This version tell if the variable has been set */
47 bool setMatch( EqualityQuery
* q
, TNode v
, TNode m
, bool & set
);
48 /** fill all unfilled values with m */
49 bool add( InstMatch
& m
);
50 /** if compatible, fill all unfilled values with m and return true
51 return false otherwise */
52 bool merge( EqualityQuery
* q
, InstMatch
& m
);
53 /** debug print method */
54 void debugPrint( const char* c
);
56 bool isComplete( Node f
) { return d_map
.size()==f
[0].getNumChildren(); }
58 void makeComplete( Node f
, QuantifiersEngine
* qe
);
59 /** make internal representative */
60 void makeInternalRepresentative( QuantifiersEngine
* qe
);
61 /** make representative */
62 void makeRepresentative( QuantifiersEngine
* qe
);
64 Node
getValue( Node var
) const;
66 void clear(){ d_map
.clear(); }
68 bool empty(){ return d_map
.empty(); }
70 inline void toStream(std::ostream
& out
) const {
71 out
<< "INST_MATCH( ";
72 for( std::map
< Node
, Node
>::const_iterator it
= d_map
.begin(); it
!= d_map
.end(); ++it
){
73 if( it
!= d_map
.begin() ){ out
<< ", "; }
74 out
<< it
->first
<< " -> " << it
->second
;
85 template<class Iterator
>
86 void erase(Iterator begin
, Iterator end
){
87 for(Iterator i
= begin
; i
!= end
; ++i
){
91 void erase(Node node
){ d_map
.erase(node
); }
93 Node
get( TNode var
) { return d_map
[var
]; }
95 void set(TNode var
, TNode n
){
96 //std::cout << "var.getType() " << var.getType() << "n.getType() " << n.getType() << std::endl ;
97 Assert( !var
.isNull() );
98 Assert( n
.isNull() ||// For a strange use in inst_match.cpp InstMatchGeneratorSimple::addInstantiations
99 //var.getType() == n.getType()
100 n
.getType().isSubtypeOf( var
.getType() ) );
103 size_t size(){ return d_map
.size(); }
105 std::map
< Node
, Node
>::iterator
begin(){ return d_map
.begin(); };
106 std::map
< Node
, Node
>::iterator
end(){ return d_map
.end(); };
107 std::map
< Node
, Node
>::iterator
find(Node var
){ return d_map
.find(var
); };
108 /* Node used for matching the trigger only for mono-trigger (just for
109 efficiency because I need only that) */
111 };/* class InstMatch */
113 inline std::ostream
& operator<<(std::ostream
& out
, const InstMatch
& m
) {
118 /** trie for InstMatch objects */
119 class InstMatchTrie
{
121 class ImtIndexOrder
{
123 std::vector
< int > d_order
;
124 };/* class InstMatchTrie ImtIndexOrder */
126 /** add match m for quantifier f starting at index, take into account equalities q, return true if successful */
127 void addInstMatch2( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, int index
, ImtIndexOrder
* imtio
);
129 bool existsInstMatch2( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
, bool modInst
, int index
, ImtIndexOrder
* imtio
);
132 std::map
< Node
, InstMatchTrie
> d_data
;
137 /** return true if m exists in this trie
138 modEq is if we check modulo equality
139 modInst is if we return true if m is an instance of a match that exists
141 bool existsInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false,
142 bool modInst
= false, ImtIndexOrder
* imtio
= NULL
);
143 /** add match m for quantifier f, take into account equalities if modEq = true,
144 if imtio is non-null, this is the order to add to trie
145 return true if successful
147 bool addInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false,
148 bool modInst
= false, ImtIndexOrder
* imtio
= NULL
);
149 };/* class InstMatchTrie */
151 class InstMatchTrieOrdered
{
153 InstMatchTrie::ImtIndexOrder
* d_imtio
;
156 InstMatchTrieOrdered( InstMatchTrie::ImtIndexOrder
* imtio
) : d_imtio( imtio
){}
157 ~InstMatchTrieOrdered(){}
159 InstMatchTrie::ImtIndexOrder
* getOrdering() { return d_imtio
; }
161 InstMatchTrie
* getTrie() { return &d_imt
; }
163 /** add match m, return true if successful */
164 bool addInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false, bool modInst
= false ){
165 return d_imt
.addInstMatch( qe
, f
, m
, modEq
, modInst
, d_imtio
);
167 bool existsInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false, bool modInst
= false ){
168 return d_imt
.existsInstMatch( qe
, f
, m
, modEq
, modInst
, d_imtio
);
170 };/* class InstMatchTrieOrdered */
172 }/* CVC4::theory::inst namespace */
174 typedef CVC4::theory::inst::InstMatch InstMatch
;
176 }/* CVC4::theory namespace */
177 }/* CVC4 namespace */
179 #endif /* __CVC4__THEORY__QUANTIFIERS__INST_MATCH_H */