1 /********************* */
2 /*! \file theory_quantifiers.cpp
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Morgan Deters, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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 Implementation of the theory of quantifiers
14 ** Implementation of the theory of quantifiers.
17 #include "theory/quantifiers/theory_quantifiers.h"
19 #include "base/check.h"
20 #include "expr/kind.h"
21 #include "options/quantifiers_options.h"
22 #include "theory/quantifiers/ematching/instantiation_engine.h"
23 #include "theory/quantifiers/fmf/model_engine.h"
24 #include "theory/quantifiers/quantifiers_attributes.h"
25 #include "theory/quantifiers/quantifiers_rewriter.h"
26 #include "theory/quantifiers/term_database.h"
27 #include "theory/quantifiers/term_util.h"
28 #include "theory/quantifiers_engine.h"
29 #include "theory/valuation.h"
33 using namespace CVC4::kind
;
34 using namespace CVC4::context
;
35 using namespace CVC4::theory
;
36 using namespace CVC4::theory::quantifiers
;
38 TheoryQuantifiers::TheoryQuantifiers(Context
* c
, context::UserContext
* u
, OutputChannel
& out
, Valuation valuation
, const LogicInfo
& logicInfo
) :
39 Theory(THEORY_QUANTIFIERS
, c
, u
, out
, valuation
, logicInfo
)
41 out
.handleUserAttribute( "axiom", this );
42 out
.handleUserAttribute( "conjecture", this );
43 out
.handleUserAttribute( "fun-def", this );
44 out
.handleUserAttribute( "sygus", this );
45 out
.handleUserAttribute("quant-name", this);
46 out
.handleUserAttribute("sygus-synth-grammar", this);
47 out
.handleUserAttribute( "sygus-synth-fun-var-list", this );
48 out
.handleUserAttribute( "quant-inst-max-level", this );
49 out
.handleUserAttribute( "rr-priority", this );
50 out
.handleUserAttribute( "quant-elim", this );
51 out
.handleUserAttribute( "quant-elim-partial", this );
54 TheoryQuantifiers::~TheoryQuantifiers() {
57 void TheoryQuantifiers::finishInit()
59 // quantifiers are not evaluated in getModelValue
60 TheoryModel
* tm
= d_valuation
.getModel();
61 Assert(tm
!= nullptr);
62 tm
->setUnevaluatedKind(EXISTS
);
63 tm
->setUnevaluatedKind(FORALL
);
66 void TheoryQuantifiers::preRegisterTerm(TNode n
) {
67 if (n
.getKind() != FORALL
)
71 Debug("quantifiers-prereg") << "TheoryQuantifiers::preRegisterTerm() " << n
<< endl
;
72 // Preregister the quantified formula.
73 // This initializes the modules used for handling n in this user context.
74 getQuantifiersEngine()->preRegisterQuantifier(n
);
75 Debug("quantifiers-prereg")
76 << "TheoryQuantifiers::preRegisterTerm() done " << n
<< endl
;
80 void TheoryQuantifiers::presolve() {
81 Debug("quantifiers-presolve") << "TheoryQuantifiers::presolve()" << endl
;
82 if( getQuantifiersEngine() ){
83 getQuantifiersEngine()->presolve();
87 void TheoryQuantifiers::ppNotifyAssertions(
88 const std::vector
<Node
>& assertions
) {
89 Trace("quantifiers-presolve")
90 << "TheoryQuantifiers::ppNotifyAssertions" << std::endl
;
91 if (getQuantifiersEngine()) {
92 getQuantifiersEngine()->ppNotifyAssertions(assertions
);
96 bool TheoryQuantifiers::collectModelInfo(TheoryModel
* m
)
98 for(assertions_iterator i
= facts_begin(); i
!= facts_end(); ++i
) {
99 if ((*i
).d_assertion
.getKind() == kind::NOT
)
101 Debug("quantifiers::collectModelInfo")
102 << "got quant FALSE: " << (*i
).d_assertion
[0] << endl
;
103 if (!m
->assertPredicate((*i
).d_assertion
[0], false))
110 Debug("quantifiers::collectModelInfo") << "got quant TRUE : " << *i
<< endl
;
111 if (!m
->assertPredicate(*i
, true))
120 void TheoryQuantifiers::check(Effort e
) {
121 if (done() && !fullEffort(e
)) {
125 TimerStat::CodeTimer
checkTimer(d_checkTime
);
127 Trace("quantifiers-check") << "quantifiers::check(" << e
<< ")" << std::endl
;
129 Node assertion
= get();
130 Trace("quantifiers-assert") << "quantifiers::assert(): " << assertion
<< std::endl
;
131 switch(assertion
.getKind()) {
133 getQuantifiersEngine()->assertQuantifier(assertion
, true);
135 case kind::INST_CLOSURE
:
136 getQuantifiersEngine()->addTermToDatabase( assertion
[0], false, true );
137 if( !options::lteRestrictInstClosure() ){
138 getQuantifiersEngine()->getMasterEqualityEngine()->addTerm( assertion
[0] );
146 switch( assertion
[0].getKind()) {
148 getQuantifiersEngine()->assertQuantifier(assertion
[0], false);
153 case kind::INST_CLOSURE
:
154 default: Unhandled() << assertion
[0].getKind(); break;
158 default: Unhandled() << assertion
.getKind(); break;
161 // call the quantifiers engine to check
162 getQuantifiersEngine()->check( e
);
165 void TheoryQuantifiers::setUserAttribute(const std::string
& attr
, Node n
, std::vector
<Node
> node_values
, std::string str_value
){
166 QuantAttributes::setUserAttribute( attr
, n
, node_values
, str_value
);