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 : : * Theory of bit-vectors. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__BV__THEORY_BV_H 16 : : #define CVC5__THEORY__BV__THEORY_BV_H 17 : : 18 : : #include "theory/bv/bv_pp_assert.h" 19 : : #include "theory/bv/proof_checker.h" 20 : : #include "theory/bv/theory_bv_rewriter.h" 21 : : #include "theory/theory.h" 22 : : #include "theory/theory_eq_notify.h" 23 : : #include "theory/theory_state.h" 24 : : 25 : : namespace cvc5::internal { 26 : : 27 : : class ProofRuleChecker; 28 : : 29 : : namespace theory { 30 : : namespace bv { 31 : : 32 : : class BVSolver; 33 : : 34 : : class TheoryBV : public Theory 35 : : { 36 : : public: 37 : : TheoryBV(Env& env, 38 : : OutputChannel& out, 39 : : Valuation valuation, 40 : : std::string name = ""); 41 : : 42 : : ~TheoryBV(); 43 : : 44 : : /** get the official theory rewriter of this theory */ 45 : : TheoryRewriter* getTheoryRewriter() override; 46 : : /** get the proof checker of this theory */ 47 : : ProofRuleChecker* getProofChecker() override; 48 : : 49 : : /** 50 : : * Returns true if we need an equality engine. If so, we initialize the 51 : : * information regarding how it should be setup. For details, see the 52 : : * documentation in Theory::needsEqualityEngine. 53 : : */ 54 : : bool needsEqualityEngine(EeSetupInfo& esi) override; 55 : : 56 : : void finishInit() override; 57 : : 58 : : void preRegisterTerm(TNode n) override; 59 : : 60 : : bool preCheck(Effort e) override; 61 : : 62 : : void postCheck(Effort e) override; 63 : : 64 : : bool preNotifyFact(TNode atom, 65 : : bool pol, 66 : : TNode fact, 67 : : bool isPrereg, 68 : : bool isInternal) override; 69 : : 70 : : void notifyFact(TNode atom, bool pol, TNode fact, bool isInternal) override; 71 : : 72 : : bool needsCheckLastEffort() override; 73 : : 74 : : void propagate(Effort e) override; 75 : : 76 : : TrustNode explain(TNode n) override; 77 : : 78 : : void computeRelevantTerms(std::set<Node>& termSet) override; 79 : : 80 : : /** Collect model values in m based on the relevant terms given by termSet */ 81 : : bool collectModelValues(TheoryModel* m, 82 : : const std::set<Node>& termSet) override; 83 : : 84 : 0 : std::string identify() const override { return std::string("TheoryBV"); } 85 : : 86 : : bool ppAssert(TrustNode in, TrustSubstitutionMap& outSubstitutions) override; 87 : : 88 : : TrustNode ppRewrite(TNode t, std::vector<SkolemLemma>& lems) override; 89 : : 90 : : TrustNode ppStaticRewrite(TNode atom) override; 91 : : 92 : : void ppStaticLearn(TNode in, std::vector<TrustNode>& learned) override; 93 : : 94 : : void presolve() override; 95 : : 96 : : EqualityStatus getEqualityStatus(TNode a, TNode b) override; 97 : : 98 : : /** 99 : : * Get the model value of given `node`. 100 : : * 101 : : * Recursively evaluates `node` from its leaves using the model of the 102 : : * internal bit-vector solver (leaves that have not been bit-blasted are 103 : : * value-initialized to 0). 104 : : * 105 : : * @param node The Node to evaluate under the current model. 106 : : * @return A node representing the value of the given node. 107 : : */ 108 : : Node getValue(TNode node); 109 : : 110 : : /** 111 : : * Mark the model value cache used by getValue() as stale. Must be called 112 : : * whenever the underlying model may have changed (e.g. between solve calls of 113 : : * the abstraction refinement loop). 114 : : */ 115 : 257 : void invalidateModelCache() { d_invalidateModelCache = true; } 116 : : 117 : : private: 118 : : void notifySharedTerm(TNode t) override; 119 : : 120 : : /** Internal BV solver. */ 121 : : std::unique_ptr<BVSolver> d_internal; 122 : : 123 : : /** The preprocess assertion utility */ 124 : : BvPpAssert d_ppAssert; 125 : : 126 : : /** The theory rewriter for this theory. */ 127 : : TheoryBVRewriter d_rewriter; 128 : : 129 : : /** A (default) theory state object */ 130 : : TheoryState d_state; 131 : : 132 : : /** A (default) theory inference manager. */ 133 : : TheoryInferenceManager d_im; 134 : : 135 : : /** The notify class for equality engine. */ 136 : : TheoryEqNotifyClass d_notify; 137 : : 138 : : /** Flag indicating whether `d_modelCache` should be invalidated. */ 139 : : context::CDO<bool> d_invalidateModelCache; 140 : : 141 : : bool d_inPostCheck; 142 : : 143 : : /** 144 : : * Cache for getValue() calls. 145 : : * 146 : : * Is cleared at the beginning of a getValue() call if the 147 : : * `d_invalidateModelCache` flag is set to true. 148 : : */ 149 : : std::unordered_map<Node, Node> d_modelCache; 150 : : 151 : : /** TheoryBV statistics. */ 152 : : struct Statistics 153 : : { 154 : : Statistics(StatisticsRegistry& reg, const std::string& name); 155 : : IntStat d_solveSubstitutions; 156 : : } d_stats; 157 : : 158 : : /** Proof rule checker */ 159 : : BVProofRuleChecker d_checker; 160 : : }; /* class TheoryBV */ 161 : : 162 : : } // namespace bv 163 : : } // namespace theory 164 : : } // namespace cvc5::internal 165 : : 166 : : #endif /* CVC5__THEORY__BV__THEORY_BV_H */