8597755c960f763f271ef42f6888f43ff9f20a62
1 /********************* */
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Morgan Deters, Francois Bobot
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing 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
22 #include "context/cdlist.h"
23 #include "context/cdo.h"
24 #include "expr/node.h"
29 class QuantifiersEngine
;
34 /** basic class defining an instantiation */
37 /* map from variable to ground terms */
38 std::vector
< Node
> d_vals
;
41 explicit InstMatch( TNode f
);
42 InstMatch( InstMatch
* m
);
44 /** fill all unfilled values with m */
45 bool add( InstMatch
& m
);
46 /** if compatible, fill all unfilled values with m and return true
47 return false otherwise */
48 bool merge( EqualityQuery
* q
, InstMatch
& m
);
49 /** debug print method */
50 void debugPrint( const char* c
);
53 /** make representative */
54 void makeRepresentative( QuantifiersEngine
* qe
);
60 inline void toStream(std::ostream
& out
) const {
61 out
<< "INST_MATCH( ";
63 for( unsigned i
=0; i
<d_vals
.size(); i
++ ){
64 if( !d_vals
[i
].isNull() ){
65 if( printed
){ out
<< ", "; }
66 out
<< i
<< " -> " << d_vals
[i
];
76 void getTerms( Node f
, std::vector
< Node
>& inst
);
78 void setValue( int i
, TNode n
);
79 bool set( QuantifiersEngine
* qe
, int i
, TNode n
);
80 };/* class InstMatch */
82 inline std::ostream
& operator<<(std::ostream
& out
, const InstMatch
& m
) {
87 /** trie for InstMatch objects */
92 std::vector
< int > d_order
;
93 };/* class InstMatchTrie ImtIndexOrder */
95 std::map
< Node
, InstMatchTrie
> d_data
;
97 void print( std::ostream
& out
, Node q
, std::vector
< TNode
>& terms
, bool& firstTime
, bool useActive
, std::vector
< Node
>& active
) const;
98 void getInstantiations( std::vector
< Node
>& insts
, Node q
, std::vector
< Node
>& terms
, QuantifiersEngine
* qe
, bool useActive
, std::vector
< Node
>& active
) const;
99 void getExplanationForInstLemmas( Node q
, std::vector
< Node
>& terms
, std::vector
< Node
>& lems
, std::map
< Node
, Node
>& quant
, std::map
< Node
, std::vector
< Node
> >& tvec
) const;
101 void setInstLemma( Node n
){
105 bool hasInstLemma() const { return !d_data
.empty(); }
106 Node
getInstLemma() const { return d_data
.begin()->first
; }
111 /** return true if m exists in this trie
112 modEq is if we check modulo equality
113 modInst is if we return true if m is an instance of a match that exists
115 bool existsInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false,
116 ImtIndexOrder
* imtio
= NULL
, int index
= 0 ) {
117 return !addInstMatch( qe
, f
, m
, modEq
, imtio
, true, index
);
119 bool existsInstMatch( QuantifiersEngine
* qe
, Node f
, std::vector
< Node
>& m
, bool modEq
= false,
120 ImtIndexOrder
* imtio
= NULL
, int index
= 0 ) {
121 return !addInstMatch( qe
, f
, m
, modEq
, imtio
, true, index
);
123 /** add match m for quantifier f, take into account equalities if modEq = true,
124 if imtio is non-null, this is the order to add to trie
125 return true if successful
127 bool addInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false,
128 ImtIndexOrder
* imtio
= NULL
, bool onlyExist
= false, int index
= 0 ){
129 return addInstMatch( qe
, f
, m
.d_vals
, modEq
, imtio
, onlyExist
, index
);
131 bool addInstMatch( QuantifiersEngine
* qe
, Node f
, std::vector
< Node
>& m
, bool modEq
= false,
132 ImtIndexOrder
* imtio
= NULL
, bool onlyExist
= false, int index
= 0 );
133 bool removeInstMatch( QuantifiersEngine
* qe
, Node f
, std::vector
< Node
>& m
, ImtIndexOrder
* imtio
= NULL
, int index
= 0 );
134 bool recordInstLemma( Node q
, std::vector
< Node
>& m
, Node lem
, ImtIndexOrder
* imtio
= NULL
, int index
= 0 );
135 void print( std::ostream
& out
, Node q
, bool& firstTime
, bool useActive
, std::vector
< Node
>& active
) const{
136 std::vector
< TNode
> terms
;
137 print( out
, q
, terms
, firstTime
, useActive
, active
);
139 void getInstantiations( std::vector
< Node
>& insts
, Node q
, QuantifiersEngine
* qe
, bool useActive
, std::vector
< Node
>& active
) {
140 std::vector
< Node
> terms
;
141 getInstantiations( insts
, q
, terms
, qe
, useActive
, active
);
143 void getExplanationForInstLemmas( Node q
, std::vector
< Node
>& lems
, std::map
< Node
, Node
>& quant
, std::map
< Node
, std::vector
< Node
> >& tvec
) const {
144 std::vector
< Node
> terms
;
145 getExplanationForInstLemmas( q
, terms
, lems
, quant
, tvec
);
147 void clear() { d_data
.clear(); }
148 };/* class InstMatchTrie */
150 /** trie for InstMatch objects */
151 class CDInstMatchTrie
{
154 std::map
< Node
, CDInstMatchTrie
* > d_data
;
156 context::CDO
< bool > d_valid
;
158 void print( std::ostream
& out
, Node q
, std::vector
< TNode
>& terms
, bool& firstTime
, bool useActive
, std::vector
< Node
>& active
) const;
159 void getInstantiations( std::vector
< Node
>& insts
, Node q
, std::vector
< Node
>& terms
, QuantifiersEngine
* qe
, bool useActive
, std::vector
< Node
>& active
) const;
160 void getExplanationForInstLemmas( Node q
, std::vector
< Node
>& terms
, std::vector
< Node
>& lems
, std::map
< Node
, Node
>& quant
, std::map
< Node
, std::vector
< Node
> >& tvec
) const;
162 void setInstLemma( Node n
){
166 bool hasInstLemma() const { return !d_data
.empty(); }
167 Node
getInstLemma() const { return d_data
.begin()->first
; }
169 CDInstMatchTrie( context::Context
* c
) : d_valid( c
, false ){}
172 /** return true if m exists in this trie
173 modEq is if we check modulo equality
174 modInst is if we return true if m is an instance of a match that exists
176 bool existsInstMatch( QuantifiersEngine
* qe
, Node q
, InstMatch
& m
, context::Context
* c
, bool modEq
= false,
178 return !addInstMatch( qe
, q
, m
, c
, modEq
, index
, true );
180 bool existsInstMatch( QuantifiersEngine
* qe
, Node q
, std::vector
< Node
>& m
, context::Context
* c
, bool modEq
= false,
182 return !addInstMatch( qe
, q
, m
, c
, modEq
, index
, true );
184 /** add match m for quantifier f, take into account equalities if modEq = true,
185 if imtio is non-null, this is the order to add to trie
186 return true if successful
188 bool addInstMatch( QuantifiersEngine
* qe
, Node q
, InstMatch
& m
, context::Context
* c
, bool modEq
= false,
189 int index
= 0, bool onlyExist
= false ) {
190 return addInstMatch( qe
, q
, m
.d_vals
, c
, modEq
, index
, onlyExist
);
192 bool addInstMatch( QuantifiersEngine
* qe
, Node q
, std::vector
< Node
>& m
, context::Context
* c
, bool modEq
= false,
193 int index
= 0, bool onlyExist
= false );
194 bool removeInstMatch( QuantifiersEngine
* qe
, Node q
, std::vector
< Node
>& m
, int index
= 0 );
195 bool recordInstLemma( Node q
, std::vector
< Node
>& m
, Node lem
, int index
= 0 );
196 void print( std::ostream
& out
, Node q
, bool& firstTime
, bool useActive
, std::vector
< Node
>& active
) const{
197 std::vector
< TNode
> terms
;
198 print( out
, q
, terms
, firstTime
, useActive
, active
);
200 void getInstantiations( std::vector
< Node
>& insts
, Node q
, QuantifiersEngine
* qe
, bool useActive
, std::vector
< Node
>& active
) {
201 std::vector
< Node
> terms
;
202 getInstantiations( insts
, q
, terms
, qe
, useActive
, active
);
204 void getExplanationForInstLemmas( Node q
, std::vector
< Node
>& lems
, std::map
< Node
, Node
>& quant
, std::map
< Node
, std::vector
< Node
> >& tvec
) const {
205 std::vector
< Node
> terms
;
206 getExplanationForInstLemmas( q
, terms
, lems
, quant
, tvec
);
208 };/* class CDInstMatchTrie */
211 class InstMatchTrieOrdered
{
213 InstMatchTrie::ImtIndexOrder
* d_imtio
;
216 InstMatchTrieOrdered( InstMatchTrie::ImtIndexOrder
* imtio
) : d_imtio( imtio
){}
217 ~InstMatchTrieOrdered(){}
219 InstMatchTrie::ImtIndexOrder
* getOrdering() { return d_imtio
; }
221 InstMatchTrie
* getTrie() { return &d_imt
; }
223 /** add match m, return true if successful */
224 bool addInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false, bool modInst
= false ){
225 return d_imt
.addInstMatch( qe
, f
, m
, modEq
, d_imtio
);
227 bool existsInstMatch( QuantifiersEngine
* qe
, Node f
, InstMatch
& m
, bool modEq
= false, bool modInst
= false ){
228 return d_imt
.existsInstMatch( qe
, f
, m
, modEq
, d_imtio
);
230 };/* class InstMatchTrieOrdered */
232 }/* CVC4::theory::inst namespace */
234 typedef CVC4::theory::inst::InstMatch InstMatch
;
236 }/* CVC4::theory namespace */
237 }/* CVC4 namespace */
239 #endif /* __CVC4__THEORY__QUANTIFIERS__INST_MATCH_H */