1 /********************* */
2 /*! \file first_order_model.h
4 ** Original author: Andrew Reynolds
5 ** Major contributors: Morgan Deters
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 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 Model extended classes
15 #include "cvc4_private.h"
17 #ifndef __CVC4__FIRST_ORDER_MODEL_H
18 #define __CVC4__FIRST_ORDER_MODEL_H
20 #include "theory/theory_model.h"
21 #include "theory/uf/theory_uf_model.h"
22 #include "expr/attribute.h"
27 class QuantifiersEngine
;
29 namespace quantifiers
{
33 class FirstOrderModelIG
;
36 class FirstOrderModelFmc
;
37 }/* CVC4::theory::quantifiers::fmcheck namespace */
39 class FirstOrderModelQInt
;
40 class FirstOrderModelAbs
;
42 struct IsStarAttributeId
{};
43 typedef expr::Attribute
<IsStarAttributeId
, bool> IsStarAttribute
;
45 class FirstOrderModel
: public TheoryModel
49 QuantifiersEngine
* d_qe
;
50 /** list of quantifiers asserted in the current context */
51 context::CDList
<Node
> d_forall_asserts
;
52 /** list of quantifiers that have been marked to reduce */
53 std::map
< Node
, bool > d_forall_to_reduce
;
55 context::CDO
< bool > d_isModelSet
;
56 /** get variable id */
57 std::map
< Node
, std::map
< Node
, int > > d_quant_var_id
;
58 /** get current model value */
59 virtual Node
getCurrentUfModelValue( Node n
, std::vector
< Node
> & args
, bool partial
) = 0;
60 public: //for Theory Quantifiers:
61 /** assert quantifier */
62 void assertQuantifier( Node n
, bool reduced
= false );
63 /** get number of asserted quantifiers */
64 int getNumAssertedQuantifiers() { return (int)d_forall_asserts
.size(); }
65 /** get asserted quantifier */
66 Node
getAssertedQuantifier( int i
) { return d_forall_asserts
[i
]; }
67 /** get number to reduce quantifiers */
68 unsigned getNumToReduceQuantifiers() { return d_forall_to_reduce
.size(); }
69 /** initialize model for term */
70 void initializeModelForTerm( Node n
, std::map
< Node
, bool >& visited
);
71 virtual void processInitializeModelForTerm( Node n
) = 0;
72 virtual void processInitializeQuantifier( Node q
) {}
74 FirstOrderModel(QuantifiersEngine
* qe
, context::Context
* c
, std::string name
);
75 virtual ~FirstOrderModel() throw() {}
76 virtual FirstOrderModelIG
* asFirstOrderModelIG() { return NULL
; }
77 virtual fmcheck::FirstOrderModelFmc
* asFirstOrderModelFmc() { return NULL
; }
78 virtual FirstOrderModelQInt
* asFirstOrderModelQInt() { return NULL
; }
79 virtual FirstOrderModelAbs
* asFirstOrderModelAbs() { return NULL
; }
80 // initialize the model
82 virtual void processInitialize( bool ispre
) = 0;
84 void markModelSet() { d_isModelSet
= true; }
86 bool isModelSet() { return d_isModelSet
; }
87 /** get current model value */
88 Node
getCurrentModelValue( Node n
, bool partial
= false );
89 /** get variable id */
90 int getVariableId(TNode q
, TNode n
) {
91 return d_quant_var_id
.find( q
)!=d_quant_var_id
.end() ? d_quant_var_id
[q
][n
] : -1;
93 /** get some domain element */
94 Node
getSomeDomainElement(TypeNode tn
);
95 /** do we need to do any work? */
98 void markQuantifierReduced( Node q
);
100 //list of inactive quantified formulas
101 std::map
< TNode
, bool > d_quant_active
;
105 /** set quantified formula active/inactive
106 * a quantified formula may be set inactive if for instance:
107 * - it is entailed by other quantified formulas
109 void setQuantifierActive( TNode q
, bool active
);
110 /** is quantified formula active */
111 bool isQuantifierActive( TNode q
);
112 };/* class FirstOrderModel */
115 class FirstOrderModelIG
: public FirstOrderModel
117 public: //for Theory UF:
118 //models for each UF operator
119 std::map
< Node
, uf::UfModelTree
> d_uf_model_tree
;
121 std::map
< Node
, uf::UfModelTreeGenerator
> d_uf_model_gen
;
123 //map from terms to the models used to calculate their value
124 std::map
< Node
, bool > d_eval_uf_use_default
;
125 std::map
< Node
, uf::UfModelTree
> d_eval_uf_model
;
126 void makeEvalUfModel( Node n
);
127 //index ordering to use for each term
128 std::map
< Node
, std::vector
< int > > d_eval_term_index_order
;
129 void makeEvalUfIndexOrder( Node n
);
130 /** get current model value */
131 Node
getCurrentUfModelValue( Node n
, std::vector
< Node
> & args
, bool partial
);
132 //the following functions are for evaluating quantifier bodies
134 FirstOrderModelIG(QuantifiersEngine
* qe
, context::Context
* c
, std::string name
);
135 ~FirstOrderModelIG() throw() {}
136 FirstOrderModelIG
* asFirstOrderModelIG() { return this; }
137 // initialize the model
138 void processInitialize( bool ispre
);
139 //for initialize model
140 void processInitializeModelForTerm( Node n
);
141 /** reset evaluation */
142 void resetEvaluate();
143 /** evaluate functions */
144 int evaluate( Node n
, int& depIndex
, RepSetIterator
* ri
);
145 Node
evaluateTerm( Node n
, int& depIndex
, RepSetIterator
* ri
);
151 int d_eval_lits_unknown
;
153 //default evaluate term function
154 Node
evaluateTermDefault( Node n
, int& depIndex
, std::vector
< int >& childDepIndex
, RepSetIterator
* ri
);
155 //temporary storing which literals have failed
156 void clearEvalFailed( int index
);
157 std::map
< Node
, bool > d_eval_failed
;
158 std::map
< int, std::vector
< Node
> > d_eval_failed_lits
;
159 };/* class FirstOrderModelIG */
166 class FirstOrderModelFmc
: public FirstOrderModel
168 friend class FullModelChecker
;
171 std::map
<Node
, Def
* > d_models
;
172 std::map
<TypeNode
, Node
> d_type_star
;
174 Node
getUsedRepresentative(Node n
, bool strict
= false);
175 /** get current model value */
176 Node
getCurrentUfModelValue( Node n
, std::vector
< Node
> & args
, bool partial
);
177 void processInitializeModelForTerm(Node n
);
179 FirstOrderModelFmc(QuantifiersEngine
* qe
, context::Context
* c
, std::string name
);
180 virtual ~FirstOrderModelFmc() throw();
181 FirstOrderModelFmc
* asFirstOrderModelFmc() { return this; }
182 // initialize the model
183 void processInitialize( bool ispre
);
184 Node
getFunctionValue(Node op
, const char* argPrefix
);
187 Node
getStar(TypeNode tn
);
188 Node
getStarElement(TypeNode tn
);
189 bool isModelBasisTerm(Node n
);
190 Node
getModelBasisTerm(TypeNode tn
);
191 bool isInterval(Node n
);
192 Node
getInterval( Node lb
, Node ub
);
193 bool isInRange( Node v
, Node i
);
194 };/* class FirstOrderModelFmc */
196 }/* CVC4::theory::quantifiers::fmcheck namespace */
200 class FirstOrderModelAbs
: public FirstOrderModel
203 std::map
< Node
, AbsDef
* > d_models
;
204 std::map
< Node
, bool > d_models_valid
;
205 std::map
< TNode
, unsigned > d_rep_id
;
206 std::map
< TypeNode
, unsigned > d_domain
;
207 std::map
< Node
, std::vector
< int > > d_var_order
;
208 std::map
< Node
, std::map
< int, int > > d_var_index
;
210 /** get current model value */
211 Node
getCurrentUfModelValue( Node n
, std::vector
< Node
> & args
, bool partial
);
212 void processInitializeModelForTerm(Node n
);
213 void processInitializeQuantifier( Node q
);
214 void collectEqVars( TNode q
, TNode n
, std::map
< int, bool >& eq_vars
);
216 FirstOrderModelAbs(QuantifiersEngine
* qe
, context::Context
* c
, std::string name
);
217 ~FirstOrderModelAbs() throw() {}
218 FirstOrderModelAbs
* asFirstOrderModelAbs() { return this; }
219 void processInitialize( bool ispre
);
220 unsigned getRepresentativeId( TNode n
);
221 TNode
getUsedRepresentative( TNode n
);
222 bool isValidType( TypeNode tn
) { return d_domain
.find( tn
)!=d_domain
.end(); }
223 Node
getFunctionValue(Node op
, const char* argPrefix
);
224 Node
getVariable( Node q
, unsigned i
);
227 }/* CVC4::theory::quantifiers namespace */
228 }/* CVC4::theory namespace */
229 }/* CVC4 namespace */
231 #endif /* __CVC4__FIRST_ORDER_MODEL_H */