1 /********************* */
2 /*! \file theory_quantifiers.cpp
4 ** Original author: ajreynol
5 ** Major contributors: none
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
14 ** \brief Implementation of the theory of quantifiers
16 ** Implementation of the theory of quantifiers.
20 #include "theory/quantifiers/theory_quantifiers.h"
21 #include "theory/valuation.h"
22 #include "theory/quantifiers_engine.h"
23 #include "theory/quantifiers/instantiation_engine.h"
24 #include "theory/quantifiers/model_engine.h"
25 #include "expr/kind.h"
26 #include "util/Assert.h"
27 #include "theory/quantifiers/theory_quantifiers_instantiator.h"
28 #include "theory/quantifiers/options.h"
29 #include "theory/quantifiers/term_database.h"
30 #include "theory/quantifiers/quantifiers_attributes.h"
34 using namespace CVC4::kind
;
35 using namespace CVC4::context
;
36 using namespace CVC4::theory
;
37 using namespace CVC4::theory::quantifiers
;
39 TheoryQuantifiers::TheoryQuantifiers(Context
* c
, context::UserContext
* u
, OutputChannel
& out
, Valuation valuation
, const LogicInfo
& logicInfo
, QuantifiersEngine
* qe
) :
40 Theory(THEORY_QUANTIFIERS
, c
, u
, out
, valuation
, logicInfo
, qe
),
42 d_numInstantiations
= 0;
44 out
.handleUserAttribute( "axiom", this );
45 out
.handleUserAttribute( "conjecture", this );
49 TheoryQuantifiers::~TheoryQuantifiers() {
52 void TheoryQuantifiers::addSharedTerm(TNode t
) {
53 Debug("quantifiers-other") << "TheoryQuantifiers::addSharedTerm(): "
58 void TheoryQuantifiers::notifyEq(TNode lhs
, TNode rhs
) {
59 Debug("quantifiers-other") << "TheoryQuantifiers::notifyEq(): "
60 << lhs
<< " = " << rhs
<< endl
;
64 void TheoryQuantifiers::preRegisterTerm(TNode n
) {
65 Debug("quantifiers-prereg") << "TheoryQuantifiers::preRegisterTerm() " << n
<< endl
;
66 if( n
.getKind()==FORALL
&& !n
.hasAttribute(InstConstantAttribute()) ){
67 getQuantifiersEngine()->registerQuantifier( n
);
72 void TheoryQuantifiers::presolve() {
73 Debug("quantifiers-presolve") << "TheoryQuantifiers::presolve()" << endl
;
76 Node
TheoryQuantifiers::getValue(TNode n
) {
77 //NodeManager* nodeManager = NodeManager::currentNM();
82 if( d_valuation
.hasSatValue( n
, value
) ){
83 return NodeManager::currentNM()->mkConst(value
);
85 return NodeManager::currentNM()->mkConst(false); //FIX_THIS?
89 Unhandled(n
.getKind());
93 void TheoryQuantifiers::collectModelInfo( TheoryModel
* m
, bool fullModel
){
97 void TheoryQuantifiers::check(Effort e
) {
98 CodeTimer
codeTimer(d_theoryTime
);
100 Debug("quantifiers-check") << "quantifiers::check(" << e
<< ")" << std::endl
;
102 Node assertion
= get();
103 Debug("quantifiers-assert") << "quantifiers::assert(): " << assertion
<< std::endl
;
104 switch(assertion
.getKind()) {
106 assertUniversal( assertion
);
110 switch( assertion
[0].getKind()) {
112 assertExistential( assertion
);
115 Unhandled(assertion
[0].getKind());
121 Unhandled(assertion
.getKind());
125 // call the quantifiers engine to check
126 getQuantifiersEngine()->check( e
);
129 void TheoryQuantifiers::propagate(Effort level
){
130 //CodeTimer codeTimer(d_theoryTime);
131 //getQuantifiersEngine()->propagate( level );
134 Node
TheoryQuantifiers::getNextDecisionRequest(){
135 return getQuantifiersEngine()->getNextDecisionRequest();
138 void TheoryQuantifiers::assertUniversal( Node n
){
139 Assert( n
.getKind()==FORALL
);
140 if( !n
.hasAttribute(InstConstantAttribute()) ){
141 getQuantifiersEngine()->registerQuantifier( n
);
142 getQuantifiersEngine()->assertNode( n
);
146 void TheoryQuantifiers::assertExistential( Node n
){
147 Assert( n
.getKind()== NOT
&& n
[0].getKind()==FORALL
);
148 if( !n
[0].hasAttribute(InstConstantAttribute()) ){
149 if( d_skolemized
.find( n
)==d_skolemized
.end() ){
150 Node body
= getQuantifiersEngine()->getTermDatabase()->getSkolemizedBody( n
[0] );
151 NodeBuilder
<> nb(kind::OR
);
152 nb
<< n
[0] << body
.notNode();
154 Debug("quantifiers-sk") << "Skolemize lemma : " << lem
<< std::endl
;
156 d_skolemized
[n
] = true;
161 bool TheoryQuantifiers::flipDecision(){
162 //Debug("quantifiers-flip") << "No instantiation given, flip decision, level = " << d_valuation.getDecisionLevel() << std::endl;
163 //for( int i=1; i<=(int)d_valuation.getDecisionLevel(); i++ ){
164 // Debug("quantifiers-flip") << " " << d_valuation.getDecision( i ) << std::endl;
166 //if( d_valuation.getDecisionLevel()>0 ){
167 // double r = double(rand())/double(RAND_MAX);
168 // unsigned decisionLevel = (unsigned)(r*d_valuation.getDecisionLevel());
169 // d_out->flipDecision( decisionLevel );
175 if( !d_out
->flipDecision() ){
181 bool TheoryQuantifiers::restart(){
182 static const int restartLimit
= 0;
183 if( d_numRestarts
==restartLimit
){
184 Debug("quantifiers-flip") << "No more restarts." << std::endl
;
188 Debug("quantifiers-flip") << "Do restart." << std::endl
;
193 void TheoryQuantifiers::setUserAttribute( std::string
& attr
, Node n
){
194 QuantifiersAttributes::setUserAttribute( attr
, n
);