Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Arithmetic equality solver 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__ARITH__EQUALITY_SOLVER_H 16 : : #define CVC5__THEORY__ARITH__EQUALITY_SOLVER_H 17 : : 18 : : #include "context/cdhashset.h" 19 : : #include "expr/node.h" 20 : : #include "proof/trust_node.h" 21 : : #include "smt/env_obj.h" 22 : : #include "theory/ee_setup_info.h" 23 : : #include "theory/theory_state.h" 24 : : #include "theory/uf/equality_engine.h" 25 : : 26 : : namespace cvc5::internal { 27 : : namespace theory { 28 : : namespace arith { 29 : : 30 : : class InferenceManager; 31 : : 32 : : namespace linear { 33 : : class ArithCongruenceManager; 34 : : } 35 : : 36 : : /** 37 : : * The arithmetic equality solver. This class manages arithmetic equalities 38 : : * in the default way via an equality engine, or defers to the congruence 39 : : * manager of linear arithmetic if setCongruenceManager is called on a 40 : : * non-null congruence manager. 41 : : * 42 : : * Since arithmetic has multiple ways of propagating literals, it tracks 43 : : * the literals that it propagates and only explains the literals that 44 : : * originated from this class. 45 : : */ 46 : : class EqualitySolver : protected EnvObj 47 : : { 48 : : using NodeSet = context::CDHashSet<Node>; 49 : : 50 : : public: 51 : : EqualitySolver(Env& env, TheoryState& astate, InferenceManager& aim); 52 : 101406 : ~EqualitySolver() {} 53 : : //--------------------------------- initialization 54 : : /** 55 : : * Returns true if we need an equality engine, see 56 : : * Theory::needsEqualityEngine. 57 : : */ 58 : : bool needsEqualityEngine(EeSetupInfo& esi); 59 : : /** 60 : : * Finish initialize 61 : : */ 62 : : void finishInit(); 63 : : //--------------------------------- end initialization 64 : : /** 65 : : * Pre-notify fact, return true if we are finished processing, false if 66 : : * we wish to assert the fact to the equality engine of this class. 67 : : */ 68 : : bool preNotifyFact( 69 : : TNode atom, bool pol, TNode fact, bool isPrereg, bool isInternal); 70 : : /** 71 : : * Return an explanation for the literal lit (which was previously propagated 72 : : * by this solver). 73 : : */ 74 : : TrustNode explain(TNode lit); 75 : : 76 : : /** Set the congruence manager, which will be notified of propagations */ 77 : : void setCongruenceManager(linear::ArithCongruenceManager* acm); 78 : : 79 : : private: 80 : : /** Notification class from the equality engine */ 81 : : class EqualitySolverNotify : public eq::EqualityEngineNotify 82 : : { 83 : : public: 84 : 51048 : EqualitySolverNotify(EqualitySolver& es) : d_es(es) {} 85 : : 86 : : bool eqNotifyTriggerPredicate(TNode predicate, bool value) override; 87 : : 88 : : bool eqNotifyTriggerTermEquality(TheoryId tag, 89 : : TNode t1, 90 : : TNode t2, 91 : : bool value) override; 92 : : 93 : : void eqNotifyConstantTermMerge(TNode t1, TNode t2) override; 94 : 2590653 : void eqNotifyNewClass(CVC5_UNUSED TNode t) override {} 95 : 3202131 : void eqNotifyMerge(CVC5_UNUSED TNode t1, CVC5_UNUSED TNode t2) override {} 96 : 694283 : void eqNotifyDisequal(CVC5_UNUSED TNode t1, 97 : : CVC5_UNUSED TNode t2, 98 : : CVC5_UNUSED TNode reason) override 99 : : { 100 : 694283 : } 101 : : 102 : : private: 103 : : /** reference to parent */ 104 : : EqualitySolver& d_es; 105 : : }; 106 : : /** Propagate literal */ 107 : : bool propagateLit(Node lit); 108 : : /** Conflict when two constants merge */ 109 : : void conflictEqConstantMerge(TNode a, TNode b); 110 : : /** reference to the state */ 111 : : TheoryState& d_astate; 112 : : /** reference to parent */ 113 : : InferenceManager& d_aim; 114 : : /** Equality solver notify */ 115 : : EqualitySolverNotify d_notify; 116 : : /** Pointer to the equality engine */ 117 : : eq::EqualityEngine* d_ee; 118 : : /** The literals we have propagated */ 119 : : NodeSet d_propLits; 120 : : /** Pointer to the congruence manager, for notifications of propagations */ 121 : : linear::ArithCongruenceManager* d_acm; 122 : : }; 123 : : 124 : : } // namespace arith 125 : : } // namespace theory 126 : : } // namespace cvc5::internal 127 : : 128 : : #endif