1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Mathias Preiner, Morgan Deters |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 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. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Full model check class. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__QUANTIFIERS__FULL_MODEL_CHECK_H |
19 |
|
#define CVC5__THEORY__QUANTIFIERS__FULL_MODEL_CHECK_H |
20 |
|
|
21 |
|
#include "theory/quantifiers/fmf/first_order_model_fmc.h" |
22 |
|
#include "theory/quantifiers/fmf/model_builder.h" |
23 |
|
|
24 |
|
namespace cvc5 { |
25 |
|
namespace theory { |
26 |
|
namespace quantifiers { |
27 |
|
namespace fmcheck { |
28 |
|
|
29 |
|
|
30 |
|
class FirstOrderModelFmc; |
31 |
|
class FullModelChecker; |
32 |
|
|
33 |
1230222 |
class EntryTrie |
34 |
|
{ |
35 |
|
private: |
36 |
|
int d_complete; |
37 |
|
public: |
38 |
551530 |
EntryTrie() : d_complete(-1), d_data(-1){} |
39 |
|
std::map<Node,EntryTrie> d_child; |
40 |
|
int d_data; |
41 |
88184 |
void reset() { d_data = -1; d_child.clear(); d_complete = -1; } |
42 |
|
void addEntry( FirstOrderModelFmc * m, Node c, Node v, int data, int index = 0 ); |
43 |
|
bool hasGeneralization( FirstOrderModelFmc * m, Node c, int index = 0 ); |
44 |
|
int getGeneralizationIndex( FirstOrderModelFmc * m, std::vector<Node> & inst, int index = 0 ); |
45 |
|
void getEntries( FirstOrderModelFmc * m, Node c, std::vector<int> & compat, std::vector<int> & gen, int index = 0, bool is_gen = true ); |
46 |
|
};/* class EntryTrie */ |
47 |
|
|
48 |
|
|
49 |
416615 |
class Def |
50 |
|
{ |
51 |
|
public: |
52 |
|
EntryTrie d_et; |
53 |
|
//cond is APPLY_UF whose arguments are returned by FullModelChecker::getRepresentative |
54 |
|
std::vector< Node > d_cond; |
55 |
|
//value is returned by FullModelChecker::getRepresentative |
56 |
|
std::vector< Node > d_value; |
57 |
|
void basic_simplify( FirstOrderModelFmc * m ); |
58 |
|
private: |
59 |
|
enum { |
60 |
|
status_unk, |
61 |
|
status_redundant, |
62 |
|
status_non_redundant |
63 |
|
}; |
64 |
|
std::vector< int > d_status; |
65 |
|
bool d_has_simplified; |
66 |
|
public: |
67 |
111177 |
Def() : d_has_simplified(false){} |
68 |
13824 |
void reset() { |
69 |
13824 |
d_et.reset(); |
70 |
13824 |
d_cond.clear(); |
71 |
13824 |
d_value.clear(); |
72 |
13824 |
d_status.clear(); |
73 |
13824 |
d_has_simplified = false; |
74 |
13824 |
} |
75 |
|
bool addEntry( FirstOrderModelFmc * m, Node c, Node v); |
76 |
|
Node evaluate( FirstOrderModelFmc * m, std::vector<Node>& inst ); |
77 |
|
int getGeneralizationIndex( FirstOrderModelFmc * m, std::vector<Node>& inst ); |
78 |
|
void simplify( FullModelChecker * mc, FirstOrderModelFmc * m ); |
79 |
|
void debugPrint(const char * tr, Node op, FullModelChecker * m); |
80 |
|
};/* class Def */ |
81 |
|
|
82 |
|
|
83 |
2926 |
class FullModelChecker : public QModelBuilder |
84 |
|
{ |
85 |
|
protected: |
86 |
|
Node d_true; |
87 |
|
Node d_false; |
88 |
|
std::map<TypeNode, std::map< Node, int > > d_rep_ids; |
89 |
|
std::map<Node, Def > d_quant_models; |
90 |
|
/** |
91 |
|
* The predicate for the quantified formula. This is used to express |
92 |
|
* conditions under which the quantified formula is false in the model. |
93 |
|
* For example, for quantified formula (forall x:Int, y:U. P), this is |
94 |
|
* a predicate of type (Int x U) -> Bool. |
95 |
|
*/ |
96 |
|
std::map<Node, Node > d_quant_cond; |
97 |
|
/** A set of quantified formulas that cannot be handled by model-based |
98 |
|
* quantifier instantiation */ |
99 |
|
std::unordered_set<Node> d_unhandledQuant; |
100 |
|
std::map< TypeNode, Node > d_array_cond; |
101 |
|
std::map< Node, Node > d_array_term_cond; |
102 |
|
std::map< Node, std::vector< int > > d_star_insts; |
103 |
|
//--------------------for preinitialization |
104 |
|
/** preInitializeType |
105 |
|
* |
106 |
|
* This function ensures that the model fm is properly initialized with |
107 |
|
* respect to type tn. |
108 |
|
* |
109 |
|
* In particular, this class relies on the use of "model basis" terms, which |
110 |
|
* are distinguished terms that are used to specify default values for |
111 |
|
* uninterpreted functions. This method enforces that the model basis term |
112 |
|
* occurs in the model for each relevant type T, where a type T is relevant |
113 |
|
* if a bound variable is of type T, or an uninterpreted function has an |
114 |
|
* argument or a return value of type T. |
115 |
|
*/ |
116 |
|
void preInitializeType(TheoryModel* m, TypeNode tn); |
117 |
|
/** for each type, an equivalence class of that type from the model */ |
118 |
|
std::map<TypeNode, Node> d_preinitialized_eqc; |
119 |
|
/** map from types to whether we have called the method above */ |
120 |
|
std::map<TypeNode, bool> d_preinitialized_types; |
121 |
|
//--------------------end for preinitialization |
122 |
|
Node normalizeArgReps(FirstOrderModelFmc * fm, Node op, Node n); |
123 |
|
/** |
124 |
|
* Exhaustively instantiate quantified formula q based on condition c, which |
125 |
|
* indicate the domain to instantiate. |
126 |
|
*/ |
127 |
|
bool exhaustiveInstantiate(FirstOrderModelFmc* fm, Node q, Node c); |
128 |
|
|
129 |
|
private: |
130 |
|
void doCheck(FirstOrderModelFmc * fm, Node f, Def & d, Node n ); |
131 |
|
|
132 |
|
void doNegate( Def & dc ); |
133 |
|
void doVariableEquality( FirstOrderModelFmc * fm, Node f, Def & d, Node eq ); |
134 |
|
void doVariableRelation( FirstOrderModelFmc * fm, Node f, Def & d, Def & dc, Node v); |
135 |
|
void doUninterpretedCompose( FirstOrderModelFmc * fm, Node f, Def & d, Node n, std::vector< Def > & dc ); |
136 |
|
|
137 |
|
void doUninterpretedCompose( FirstOrderModelFmc * fm, Node f, Def & d, |
138 |
|
Def & df, std::vector< Def > & dc, int index, |
139 |
|
std::vector< Node > & cond, std::vector<Node> & val ); |
140 |
|
void doUninterpretedCompose2( FirstOrderModelFmc * fm, Node f, |
141 |
|
std::map< int, Node > & entries, int index, |
142 |
|
std::vector< Node > & cond, std::vector< Node > & val, |
143 |
|
EntryTrie & curr); |
144 |
|
|
145 |
|
void doInterpretedCompose( FirstOrderModelFmc * fm, Node f, Def & d, Node n, |
146 |
|
std::vector< Def > & dc, int index, |
147 |
|
std::vector< Node > & cond, std::vector<Node> & val ); |
148 |
|
int isCompat( FirstOrderModelFmc * fm, std::vector< Node > & cond, Node c ); |
149 |
|
bool doMeet( FirstOrderModelFmc * fm, std::vector< Node > & cond, Node c ); |
150 |
|
Node mkCond( std::vector< Node > & cond ); |
151 |
|
Node mkCondDefault( FirstOrderModelFmc * fm, Node f ); |
152 |
|
void mkCondDefaultVec( FirstOrderModelFmc * fm, Node f, std::vector< Node > & cond ); |
153 |
|
void mkCondVec( Node n, std::vector< Node > & cond ); |
154 |
|
Node evaluateInterpreted( Node n, std::vector< Node > & vals ); |
155 |
|
Node getSomeDomainElement( FirstOrderModelFmc * fm, TypeNode tn ); |
156 |
|
|
157 |
|
public: |
158 |
|
FullModelChecker(QuantifiersState& qs, |
159 |
|
QuantifiersInferenceManager& qim, |
160 |
|
QuantifiersRegistry& qr, |
161 |
|
TermRegistry& tr); |
162 |
|
/** finish init, which sets the model object */ |
163 |
|
void finishInit() override; |
164 |
|
void debugPrintCond(const char * tr, Node n, bool dispStar = false); |
165 |
|
void debugPrint(const char * tr, Node n, bool dispStar = false); |
166 |
|
|
167 |
|
int doExhaustiveInstantiation(FirstOrderModel* fm, |
168 |
|
Node f, |
169 |
|
int effort) override; |
170 |
|
|
171 |
|
Node getFunctionValue(FirstOrderModelFmc * fm, Node op, const char* argPrefix ); |
172 |
|
|
173 |
|
/** process build model */ |
174 |
|
bool preProcessBuildModel(TheoryModel* m) override; |
175 |
|
bool processBuildModel(TheoryModel* m) override; |
176 |
|
|
177 |
|
bool useSimpleModels(); |
178 |
|
private: |
179 |
|
/** |
180 |
|
* Register quantified formula. |
181 |
|
* This checks whether q can be handled by model-based instantiation and |
182 |
|
* initializes the necessary information if so. |
183 |
|
*/ |
184 |
|
void registerQuantifiedFormula(Node q); |
185 |
|
/** Is quantified formula q handled by model-based instantiation? */ |
186 |
|
bool isHandled(Node q) const; |
187 |
|
/** |
188 |
|
* The first order model. This is an extended form of the first order model |
189 |
|
* class that is specialized for this class. |
190 |
|
*/ |
191 |
|
std::unique_ptr<FirstOrderModelFmc> d_fm; |
192 |
|
};/* class FullModelChecker */ |
193 |
|
|
194 |
|
} // namespace fmcheck |
195 |
|
} // namespace quantifiers |
196 |
|
} // namespace theory |
197 |
|
} // namespace cvc5 |
198 |
|
|
199 |
|
#endif /* CVC5__THEORY__QUANTIFIERS__FULL_MODEL_CHECK_H */ |