1 /******************************************************************************
2 * Top contributors (to current version):
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 * Arithmetic equality solver
16 #include "theory/arith/equality_solver.h"
18 #include "theory/arith/inference_manager.h"
20 using namespace cvc5::kind
;
26 EqualitySolver::EqualitySolver(ArithState
& astate
, InferenceManager
& aim
)
31 d_propLits(astate
.getSatContext())
35 bool EqualitySolver::needsEqualityEngine(EeSetupInfo
& esi
)
37 esi
.d_notify
= &d_notify
;
38 esi
.d_name
= "arith::ee";
42 void EqualitySolver::finishInit()
44 d_ee
= d_astate
.getEqualityEngine();
45 // add the function kinds
46 d_ee
->addFunctionKind(kind::NONLINEAR_MULT
);
47 d_ee
->addFunctionKind(kind::EXPONENTIAL
);
48 d_ee
->addFunctionKind(kind::SINE
);
49 d_ee
->addFunctionKind(kind::IAND
);
50 d_ee
->addFunctionKind(kind::POW2
);
53 bool EqualitySolver::preNotifyFact(
54 TNode atom
, bool pol
, TNode fact
, bool isPrereg
, bool isInternal
)
56 if (atom
.getKind() != EQUAL
)
58 // finished processing, since not beneficial to add non-equality facts
61 Trace("arith-eq-solver") << "EqualitySolver::preNotifyFact: " << fact
67 TrustNode
EqualitySolver::explain(TNode lit
)
69 Trace("arith-eq-solver-debug") << "explain " << lit
<< "?" << std::endl
;
70 // check if we propagated it?
71 if (d_propLits
.find(lit
) == d_propLits
.end())
73 Trace("arith-eq-solver-debug") << "...did not propagate" << std::endl
;
74 return TrustNode::null();
76 Trace("arith-eq-solver-debug")
77 << "...explain via inference manager" << std::endl
;
78 // if we did, explain with the arithmetic inference manager
79 return d_aim
.explainLit(lit
);
81 bool EqualitySolver::propagateLit(Node lit
)
83 // if we've already propagated, ignore
84 if (d_aim
.hasPropagated(lit
))
88 // notice this is only used when ee-mode=distributed
89 // remember that this was a literal we propagated
90 Trace("arith-eq-solver-debug") << "propagate lit " << lit
<< std::endl
;
91 d_propLits
.insert(lit
);
92 return d_aim
.propagateLit(lit
);
94 void EqualitySolver::conflictEqConstantMerge(TNode a
, TNode b
)
96 d_aim
.conflictEqConstantMerge(a
, b
);
99 bool EqualitySolver::EqualitySolverNotify::eqNotifyTriggerPredicate(
100 TNode predicate
, bool value
)
102 Trace("arith-eq-solver") << "...propagate (predicate) " << predicate
<< " -> "
103 << value
<< std::endl
;
106 return d_es
.propagateLit(predicate
);
108 return d_es
.propagateLit(predicate
.notNode());
111 bool EqualitySolver::EqualitySolverNotify::eqNotifyTriggerTermEquality(
112 TheoryId tag
, TNode t1
, TNode t2
, bool value
)
114 Trace("arith-eq-solver") << "...propagate (term eq) " << t1
.eqNode(t2
)
115 << " -> " << value
<< std::endl
;
118 return d_es
.propagateLit(t1
.eqNode(t2
));
120 return d_es
.propagateLit(t1
.eqNode(t2
).notNode());
123 void EqualitySolver::EqualitySolverNotify::eqNotifyConstantTermMerge(TNode t1
,
126 Trace("arith-eq-solver") << "...conflict merge " << t1
<< " " << t2
128 d_es
.conflictEqConstantMerge(t1
, t2
);
132 } // namespace theory