1 /********************* */
2 /*! \file theory_sets.cpp
4 ** Top contributors (to current version):
5 ** Andrew Reynolds, Kshitij Bansal, Andres Noetzli
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 Sets theory.
17 #include "theory/sets/theory_sets.h"
19 #include "options/sets_options.h"
20 #include "theory/sets/theory_sets_private.h"
21 #include "theory/sets/theory_sets_rewriter.h"
22 #include "theory/theory_model.h"
24 using namespace CVC4::kind
;
30 TheorySets::TheorySets(context::Context
* c
,
31 context::UserContext
* u
,
34 const LogicInfo
& logicInfo
,
35 ProofNodeManager
* pnm
)
36 : Theory(THEORY_SETS
, c
, u
, out
, valuation
, logicInfo
, pnm
),
37 d_internal(new TheorySetsPrivate(*this, c
, u
))
39 // Do not move me to the header.
40 // The constructor + destructor are not in the header as d_internal is a
41 // unique_ptr<TheorySetsPrivate> and TheorySetsPrivate is an opaque type in
42 // the header (Pimpl). See https://herbsutter.com/gotw/_100/ .
45 TheorySets::~TheorySets()
47 // Do not move me to the header. See explanation in the constructor.
50 TheoryRewriter
* TheorySets::getTheoryRewriter()
52 return d_internal
->getTheoryRewriter();
55 void TheorySets::finishInit()
57 TheoryModel
* tm
= d_valuation
.getModel();
58 Assert(tm
!= nullptr);
59 tm
->setUnevaluatedKind(COMPREHENSION
);
60 // choice is used to eliminate witness
61 tm
->setUnevaluatedKind(WITNESS
);
64 void TheorySets::addSharedTerm(TNode n
) {
65 d_internal
->addSharedTerm(n
);
68 void TheorySets::check(Effort e
) {
69 if (done() && e
< Theory::EFFORT_FULL
) {
72 TimerStat::CodeTimer
checkTimer(d_checkTime
);
76 bool TheorySets::collectModelInfo(TheoryModel
* m
)
78 return d_internal
->collectModelInfo(m
);
81 void TheorySets::computeCareGraph() {
82 d_internal
->computeCareGraph();
85 TrustNode
TheorySets::explain(TNode node
)
87 Node exp
= d_internal
->explain(node
);
88 return TrustNode::mkTrustPropExp(node
, exp
, nullptr);
91 EqualityStatus
TheorySets::getEqualityStatus(TNode a
, TNode b
) {
92 return d_internal
->getEqualityStatus(a
, b
);
95 Node
TheorySets::getModelValue(TNode node
) {
99 void TheorySets::preRegisterTerm(TNode node
) {
100 d_internal
->preRegisterTerm(node
);
103 TrustNode
TheorySets::expandDefinition(Node n
)
105 Kind nk
= n
.getKind();
106 if (nk
== UNIVERSE_SET
|| nk
== COMPLEMENT
|| nk
== JOIN_IMAGE
107 || nk
== COMPREHENSION
)
109 if (!options::setsExt())
111 std::stringstream ss
;
112 ss
<< "Extended set operators are not supported in default mode, try "
114 throw LogicException(ss
.str());
117 if (nk
== COMPREHENSION
)
119 // set comprehension is an implicit quantifier, require it in the logic
120 if (!getLogicInfo().isQuantified())
122 std::stringstream ss
;
123 ss
<< "Set comprehensions require quantifiers in the background logic.";
124 throw LogicException(ss
.str());
127 return d_internal
->expandDefinition(n
);
130 Theory::PPAssertStatus
TheorySets::ppAssert(TNode in
, SubstitutionMap
& outSubstitutions
) {
131 Debug("sets-proc") << "ppAssert : " << in
<< std::endl
;
132 Theory::PPAssertStatus status
= Theory::PP_ASSERT_STATUS_UNSOLVED
;
134 // this is based off of Theory::ppAssert
135 if (in
.getKind() == kind::EQUAL
)
137 if (in
[0].isVar() && isLegalElimination(in
[0], in
[1]))
139 // We cannot solve for sets if setsExt is enabled, since universe set
140 // may appear when this option is enabled, and solving for such a set
141 // impacts the semantics of universe set, see
142 // regress0/sets/pre-proc-univ.smt2
143 if (!in
[0].getType().isSet() || !options::setsExt())
145 outSubstitutions
.addSubstitution(in
[0], in
[1]);
146 status
= Theory::PP_ASSERT_STATUS_SOLVED
;
149 else if (in
[1].isVar() && isLegalElimination(in
[1], in
[0]))
151 if (!in
[0].getType().isSet() || !options::setsExt())
153 outSubstitutions
.addSubstitution(in
[1], in
[0]);
154 status
= Theory::PP_ASSERT_STATUS_SOLVED
;
157 else if (in
[0].isConst() && in
[1].isConst())
161 status
= Theory::PP_ASSERT_STATUS_CONFLICT
;
168 void TheorySets::presolve() {
169 d_internal
->presolve();
172 void TheorySets::propagate(Effort e
) {
173 d_internal
->propagate(e
);
176 void TheorySets::setMasterEqualityEngine(eq::EqualityEngine
* eq
) {
177 d_internal
->setMasterEqualityEngine(eq
);
180 bool TheorySets::isEntailed( Node n
, bool pol
) {
181 return d_internal
->isEntailed( n
, pol
);
184 }/* CVC4::theory::sets namespace */
185 }/* CVC4::theory namespace */
186 }/* CVC4 namespace */