1 /******************************************************************************
2 * Top contributors (to current version):
3 * Andrew Reynolds, Gereon Kremer, Aina Niemetz
5 * This file is part of the cvc5 project.
7 * Copyright (c) 2009-2021 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.
11 * ****************************************************************************
13 * Implementation of the inference manager for the theory of sets.
16 #include "theory/sets/inference_manager.h"
18 #include "options/sets_options.h"
19 #include "theory/rewriter.h"
22 using namespace cvc5::kind
;
28 InferenceManager::InferenceManager(Env
& env
, Theory
& t
, SolverState
& s
)
29 : InferenceManagerBuffered(env
, t
, s
, "theory::sets::"), d_state(s
)
31 d_true
= NodeManager::currentNM()->mkConst(true);
32 d_false
= NodeManager::currentNM()->mkConst(false);
35 bool InferenceManager::assertFactRec(Node fact
, InferenceId id
, Node exp
, int inferType
)
37 // should we send this fact out as a lemma?
38 if ((options().sets
.setsInferAsLemmas
&& inferType
!= -1) || inferType
== 1)
40 if (d_state
.isEntailed(fact
, true))
47 lem
= NodeManager::currentNM()->mkNode(IMPLIES
, exp
, fact
);
49 addPendingLemma(lem
, id
);
52 Trace("sets-fact") << "Assert fact rec : " << fact
<< ", exp = " << exp
56 // either trivial or a conflict
59 Trace("sets-lemma") << "Conflict : " << exp
<< std::endl
;
65 else if (fact
.getKind() == AND
66 || (fact
.getKind() == NOT
&& fact
[0].getKind() == OR
))
69 Node f
= fact
.getKind() == NOT
? fact
[0] : fact
;
70 for (unsigned i
= 0; i
< f
.getNumChildren(); i
++)
72 Node factc
= fact
.getKind() == NOT
? f
[i
].negate() : f
[i
];
73 bool tret
= assertFactRec(factc
, id
, exp
, inferType
);
75 if (d_state
.isInConflict())
82 bool polarity
= fact
.getKind() != NOT
;
83 TNode atom
= polarity
? fact
: fact
[0];
84 if (d_state
.isEntailed(atom
, polarity
))
88 // things we can assert to equality engine
89 if (atom
.getKind() == MEMBER
90 || (atom
.getKind() == EQUAL
&& atom
[0].getType().isSet()))
92 // send to equality engine
93 if (assertSetsFact(atom
, polarity
, id
, exp
))
95 // return true if this wasn't redundant
101 // must send as lemma
105 lem
= NodeManager::currentNM()->mkNode(IMPLIES
, exp
, fact
);
107 addPendingLemma(lem
, id
);
113 bool InferenceManager::assertSetsFact(Node atom
,
118 Node conc
= polarity
? atom
: atom
.notNode();
119 return assertInternalFact(
120 atom
, polarity
, id
, PfRule::THEORY_INFERENCE
, {exp
}, {conc
});
123 void InferenceManager::assertInference(Node fact
,
128 if (assertFactRec(fact
, id
, exp
, inferType
))
130 Trace("sets-lemma") << "Sets::Lemma : " << fact
<< " from " << exp
<< " by "
132 Trace("sets-assertion") << "(assert (=> " << exp
<< " " << fact
133 << ")) ; by " << id
<< std::endl
;
137 void InferenceManager::assertInference(Node fact
,
139 std::vector
<Node
>& exp
,
142 Node exp_n
= exp
.empty() ? d_true
145 : NodeManager::currentNM()->mkNode(AND
, exp
));
146 assertInference(fact
, id
, exp_n
, inferType
);
149 void InferenceManager::assertInference(std::vector
<Node
>& conc
,
156 Node fact
= conc
.size() == 1 ? conc
[0]
157 : NodeManager::currentNM()->mkNode(AND
, conc
);
158 assertInference(fact
, id
, exp
, inferType
);
161 void InferenceManager::assertInference(std::vector
<Node
>& conc
,
163 std::vector
<Node
>& exp
,
166 Node exp_n
= exp
.empty() ? d_true
169 : NodeManager::currentNM()->mkNode(AND
, exp
));
170 assertInference(conc
, id
, exp_n
, inferType
);
173 void InferenceManager::split(Node n
, InferenceId id
, int reqPol
)
176 Node lem
= NodeManager::currentNM()->mkNode(OR
, n
, n
.negate());
179 Trace("sets-lemma") << "Sets::Lemma split : " << lem
<< std::endl
;
182 Trace("sets-lemma") << "Sets::Require phase " << n
<< " " << (reqPol
> 0)
184 requirePhase(n
, reqPol
> 0);
189 } // namespace theory