1 /********************* */
2 /*! \file theory_quantifiers.cpp
4 ** Original author: ajreynol
5 ** Major contributors: none
6 ** Minor contributors (to current version): bobot, 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 Implementation of the theory of quantifiers
14 ** Implementation of the theory of quantifiers.
18 #include "theory/quantifiers/theory_quantifiers.h"
19 #include "theory/valuation.h"
20 #include "theory/quantifiers_engine.h"
21 #include "theory/quantifiers/instantiation_engine.h"
22 #include "theory/quantifiers/model_engine.h"
23 #include "expr/kind.h"
24 #include "util/cvc4_assert.h"
25 #include "theory/quantifiers/options.h"
26 #include "theory/quantifiers/term_database.h"
27 #include "theory/quantifiers/quantifiers_attributes.h"
31 using namespace CVC4::kind
;
32 using namespace CVC4::context
;
33 using namespace CVC4::theory
;
34 using namespace CVC4::theory::quantifiers
;
36 TheoryQuantifiers::TheoryQuantifiers(Context
* c
, context::UserContext
* u
, OutputChannel
& out
, Valuation valuation
, const LogicInfo
& logicInfo
, QuantifiersEngine
* qe
) :
37 Theory(THEORY_QUANTIFIERS
, c
, u
, out
, valuation
, logicInfo
, qe
),
39 d_masterEqualityEngine(0)
41 d_numInstantiations
= 0;
43 out
.handleUserAttribute( "axiom", this );
44 out
.handleUserAttribute( "conjecture", this );
47 TheoryQuantifiers::~TheoryQuantifiers() {
50 void TheoryQuantifiers::setMasterEqualityEngine(eq::EqualityEngine
* eq
) {
51 d_masterEqualityEngine
= eq
;
54 void TheoryQuantifiers::addSharedTerm(TNode t
) {
55 Debug("quantifiers-other") << "TheoryQuantifiers::addSharedTerm(): "
60 void TheoryQuantifiers::notifyEq(TNode lhs
, TNode rhs
) {
61 Debug("quantifiers-other") << "TheoryQuantifiers::notifyEq(): "
62 << lhs
<< " = " << rhs
<< endl
;
66 void TheoryQuantifiers::preRegisterTerm(TNode n
) {
67 Debug("quantifiers-prereg") << "TheoryQuantifiers::preRegisterTerm() " << n
<< endl
;
68 if( n
.getKind()==FORALL
&& !n
.hasAttribute(InstConstantAttribute()) ){
69 getQuantifiersEngine()->registerQuantifier( n
);
74 void TheoryQuantifiers::presolve() {
75 Debug("quantifiers-presolve") << "TheoryQuantifiers::presolve()" << endl
;
78 Node
TheoryQuantifiers::getValue(TNode n
) {
79 //NodeManager* nodeManager = NodeManager::currentNM();
84 if( d_valuation
.hasSatValue( n
, value
) ){
85 return NodeManager::currentNM()->mkConst(value
);
87 return NodeManager::currentNM()->mkConst(false); //FIX_THIS?
91 Unhandled(n
.getKind());
95 void TheoryQuantifiers::collectModelInfo( TheoryModel
* m
, bool fullModel
){
99 void TheoryQuantifiers::check(Effort e
) {
100 CodeTimer
codeTimer(d_theoryTime
);
102 Debug("quantifiers-check") << "quantifiers::check(" << e
<< ")" << std::endl
;
104 Node assertion
= get();
105 Debug("quantifiers-assert") << "quantifiers::assert(): " << assertion
<< std::endl
;
106 switch(assertion
.getKind()) {
108 assertUniversal( assertion
);
112 switch( assertion
[0].getKind()) {
114 assertExistential( assertion
);
117 Unhandled(assertion
[0].getKind());
123 Unhandled(assertion
.getKind());
127 // call the quantifiers engine to check
128 getQuantifiersEngine()->check( e
);
131 void TheoryQuantifiers::propagate(Effort level
){
132 //CodeTimer codeTimer(d_theoryTime);
133 //getQuantifiersEngine()->propagate( level );
136 Node
TheoryQuantifiers::getNextDecisionRequest(){
137 return getQuantifiersEngine()->getNextDecisionRequest();
140 void TheoryQuantifiers::assertUniversal( Node n
){
141 Assert( n
.getKind()==FORALL
);
142 if( !n
.hasAttribute(InstConstantAttribute()) ){
143 getQuantifiersEngine()->registerQuantifier( n
);
144 getQuantifiersEngine()->assertNode( n
);
148 void TheoryQuantifiers::assertExistential( Node n
){
149 Assert( n
.getKind()== NOT
&& n
[0].getKind()==FORALL
);
150 if( !n
[0].hasAttribute(InstConstantAttribute()) ){
151 if( d_skolemized
.find( n
)==d_skolemized
.end() ){
152 Node body
= getQuantifiersEngine()->getTermDatabase()->getSkolemizedBody( n
[0] );
153 NodeBuilder
<> nb(kind::OR
);
154 nb
<< n
[0] << body
.notNode();
156 Debug("quantifiers-sk") << "Skolemize lemma : " << lem
<< std::endl
;
158 d_skolemized
[n
] = true;
163 bool TheoryQuantifiers::flipDecision(){
164 //Debug("quantifiers-flip") << "No instantiation given, flip decision, level = " << d_valuation.getDecisionLevel() << std::endl;
165 //for( int i=1; i<=(int)d_valuation.getDecisionLevel(); i++ ){
166 // Debug("quantifiers-flip") << " " << d_valuation.getDecision( i ) << std::endl;
168 //if( d_valuation.getDecisionLevel()>0 ){
169 // double r = double(rand())/double(RAND_MAX);
170 // unsigned decisionLevel = (unsigned)(r*d_valuation.getDecisionLevel());
171 // d_out->flipDecision( decisionLevel );
177 if( !d_out
->flipDecision() ){
183 bool TheoryQuantifiers::restart(){
184 static const int restartLimit
= 0;
185 if( d_numRestarts
==restartLimit
){
186 Debug("quantifiers-flip") << "No more restarts." << std::endl
;
190 Debug("quantifiers-flip") << "Do restart." << std::endl
;
195 void TheoryQuantifiers::setUserAttribute( const std::string
& attr
, Node n
){
196 QuantifiersAttributes::setUserAttribute( attr
, n
);