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-2020 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 "expr/proof_node_manager.h"
22 #include "options/quantifiers_options.h"
23 #include "theory/quantifiers/ematching/instantiation_engine.h"
24 #include "theory/quantifiers/fmf/model_engine.h"
25 #include "theory/quantifiers/quantifiers_attributes.h"
26 #include "theory/quantifiers/quantifiers_rewriter.h"
27 #include "theory/quantifiers/term_database.h"
28 #include "theory/quantifiers/term_util.h"
29 #include "theory/quantifiers_engine.h"
30 #include "theory/valuation.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
,
40 context::UserContext
* u
,
43 const LogicInfo
& logicInfo
,
44 ProofNodeManager
* pnm
)
45 : Theory(THEORY_QUANTIFIERS
, c
, u
, out
, valuation
, logicInfo
, pnm
)
47 out
.handleUserAttribute( "fun-def", this );
48 out
.handleUserAttribute( "sygus", this );
49 out
.handleUserAttribute("quant-name", this);
50 out
.handleUserAttribute("sygus-synth-grammar", this);
51 out
.handleUserAttribute( "sygus-synth-fun-var-list", this );
52 out
.handleUserAttribute( "quant-inst-max-level", this );
53 out
.handleUserAttribute( "quant-elim", this );
54 out
.handleUserAttribute( "quant-elim-partial", this );
56 ProofChecker
* pc
= pnm
!= nullptr ? pnm
->getChecker() : nullptr;
59 // add the proof rules
60 d_qChecker
.registerTo(pc
);
64 TheoryQuantifiers::~TheoryQuantifiers() {
67 void TheoryQuantifiers::finishInit()
69 // quantifiers are not evaluated in getModelValue
70 TheoryModel
* tm
= d_valuation
.getModel();
71 Assert(tm
!= nullptr);
72 tm
->setUnevaluatedKind(EXISTS
);
73 tm
->setUnevaluatedKind(FORALL
);
74 // witness is used in several instantiation strategies
75 tm
->setUnevaluatedKind(WITNESS
);
78 void TheoryQuantifiers::preRegisterTerm(TNode n
) {
79 if (n
.getKind() != FORALL
)
83 Debug("quantifiers-prereg") << "TheoryQuantifiers::preRegisterTerm() " << n
<< endl
;
84 // Preregister the quantified formula.
85 // This initializes the modules used for handling n in this user context.
86 getQuantifiersEngine()->preRegisterQuantifier(n
);
87 Debug("quantifiers-prereg")
88 << "TheoryQuantifiers::preRegisterTerm() done " << n
<< endl
;
92 void TheoryQuantifiers::presolve() {
93 Debug("quantifiers-presolve") << "TheoryQuantifiers::presolve()" << endl
;
94 if( getQuantifiersEngine() ){
95 getQuantifiersEngine()->presolve();
99 void TheoryQuantifiers::ppNotifyAssertions(
100 const std::vector
<Node
>& assertions
) {
101 Trace("quantifiers-presolve")
102 << "TheoryQuantifiers::ppNotifyAssertions" << std::endl
;
103 if (getQuantifiersEngine()) {
104 getQuantifiersEngine()->ppNotifyAssertions(assertions
);
108 bool TheoryQuantifiers::collectModelInfo(TheoryModel
* m
)
110 for(assertions_iterator i
= facts_begin(); i
!= facts_end(); ++i
) {
111 if ((*i
).d_assertion
.getKind() == kind::NOT
)
113 Debug("quantifiers::collectModelInfo")
114 << "got quant FALSE: " << (*i
).d_assertion
[0] << endl
;
115 if (!m
->assertPredicate((*i
).d_assertion
[0], false))
122 Debug("quantifiers::collectModelInfo") << "got quant TRUE : " << *i
<< endl
;
123 if (!m
->assertPredicate(*i
, true))
132 void TheoryQuantifiers::check(Effort e
) {
133 if (done() && !fullEffort(e
)) {
137 TimerStat::CodeTimer
checkTimer(d_checkTime
);
139 Trace("quantifiers-check") << "quantifiers::check(" << e
<< ")" << std::endl
;
141 Node assertion
= get();
142 Trace("quantifiers-assert") << "quantifiers::assert(): " << assertion
<< std::endl
;
143 switch(assertion
.getKind()) {
145 getQuantifiersEngine()->assertQuantifier(assertion
, true);
147 case kind::INST_CLOSURE
:
148 getQuantifiersEngine()->addTermToDatabase( assertion
[0], false, true );
149 if( !options::lteRestrictInstClosure() ){
150 getQuantifiersEngine()->getMasterEqualityEngine()->addTerm( assertion
[0] );
158 switch( assertion
[0].getKind()) {
160 getQuantifiersEngine()->assertQuantifier(assertion
[0], false);
165 case kind::INST_CLOSURE
:
166 default: Unhandled() << assertion
[0].getKind(); break;
170 default: Unhandled() << assertion
.getKind(); break;
173 // call the quantifiers engine to check
174 getQuantifiersEngine()->check( e
);
177 void TheoryQuantifiers::setUserAttribute(const std::string
& attr
, Node n
, std::vector
<Node
> node_values
, std::string str_value
){
178 QuantAttributes::setUserAttribute( attr
, n
, node_values
, str_value
);