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 floating-point arithmetic. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__FP__THEORY_FP_H 16 : : #define CVC5__THEORY__FP__THEORY_FP_H 17 : : 18 : : #include <string> 19 : : #include <utility> 20 : : 21 : : #include "context/cdhashset.h" 22 : : #include "context/cdo.h" 23 : : #include "theory/fp/theory_fp_rewriter.h" 24 : : #include "theory/theory.h" 25 : : #include "theory/theory_eq_notify.h" 26 : : #include "theory/theory_inference_manager.h" 27 : : #include "theory/theory_state.h" 28 : : #include "theory/uf/equality_engine.h" 29 : : 30 : : namespace cvc5::internal { 31 : : namespace theory { 32 : : namespace fp { 33 : : 34 : : class FpWordBlaster; 35 : : 36 : : class TheoryFp : public Theory 37 : : { 38 : : public: 39 : : /** Constructs a new instance of TheoryFp w.r.t. the provided contexts. */ 40 : : TheoryFp(Env& env, OutputChannel& out, Valuation valuation); 41 : : 42 : : //--------------------------------- initialization 43 : : /** Get the official theory rewriter of this theory. */ 44 : : TheoryRewriter* getTheoryRewriter() override; 45 : : /** get the proof checker of this theory */ 46 : : ProofRuleChecker* getProofChecker() override; 47 : : /** 48 : : * Returns true if we need an equality engine. If so, we initialize the 49 : : * information regarding how it should be setup. For details, see the 50 : : * documentation in Theory::needsEqualityEngine. 51 : : */ 52 : : bool needsEqualityEngine(EeSetupInfo& esi) override; 53 : : /** Finish initialization. */ 54 : : void finishInit() override; 55 : : //--------------------------------- end initialization 56 : : 57 : : void preRegisterTerm(TNode node) override; 58 : : TrustNode ppRewrite(TNode node, std::vector<SkolemLemma>& lems) override; 59 : : 60 : : //--------------------------------- standard check 61 : : /** Do we need a check call at last call effort? */ 62 : : bool needsCheckLastEffort() override; 63 : : /** Post-check, called after the fact queue of the theory is processed. */ 64 : : void postCheck(Effort level) override; 65 : : /** Pre-notify fact, return true if processed. */ 66 : : bool preNotifyFact(TNode atom, 67 : : bool pol, 68 : : TNode fact, 69 : : bool isPrereg, 70 : : bool isInternal) override; 71 : : //--------------------------------- end standard check 72 : : 73 : : bool collectModelInfo(TheoryModel* m, 74 : : const std::set<Node>& relevantTerms) override; 75 : : bool collectModelValues(TheoryModel* m, 76 : : const std::set<Node>& termSet) override; 77 : : 78 : 0 : std::string identify() const override { return "THEORY_FP"; } 79 : : 80 : : TrustNode explain(TNode n) override; 81 : : 82 : : Node getCandidateModelValue(TNode node) override; 83 : : 84 : : EqualityStatus getEqualityStatus(TNode a, TNode b) override; 85 : : 86 : : private: 87 : : using ConversionAbstractionMap = context::CDHashMap<TypeNode, Node>; 88 : : using AbstractionMap = context::CDHashMap<Node, Node>; 89 : : 90 : : void notifySharedTerm(TNode n) override; 91 : : 92 : : /** General utility. */ 93 : : void registerTerm(TNode node); 94 : : bool isRegistered(TNode node); 95 : : 96 : : /** The word-blaster. Translates FP -> BV. */ 97 : : std::unique_ptr<FpWordBlaster> d_wordBlaster; 98 : : 99 : : void wordBlastAndEquateTerm(TNode node); 100 : : 101 : : /** Interaction with the rest of the solver **/ 102 : : void handleLemma(Node node, InferenceId id); 103 : : /** 104 : : * Called when literal node is inferred by the equality engine. This 105 : : * propagates node on the output channel. 106 : : */ 107 : : bool propagateLit(TNode node); 108 : : /** 109 : : * Called when two constants t1 and t2 merge in the equality engine. This 110 : : * sends a conflict on the output channel. 111 : : */ 112 : : void conflictEqConstantMerge(TNode t1, TNode t2); 113 : : 114 : : bool refineAbstraction(TheoryModel* m, TNode abstract, TNode concrete); 115 : : 116 : : /** The terms registered via registerTerm(). */ 117 : : context::CDHashSet<Node> d_registeredTerms; 118 : : 119 : : /** Map abstraction skolem to abstracted FP_TO_REAL/FP_FROM_REAL node. */ 120 : : AbstractionMap d_abstractionMap; // abstract -> original 121 : : 122 : : /** The theory rewriter for this theory. */ 123 : : TheoryFpRewriter d_rewriter; 124 : : /** A (default) theory state object. */ 125 : : TheoryState d_state; 126 : : /** A (default) inference manager. */ 127 : : TheoryInferenceManager d_im; 128 : : /** The notify class for equality engine. */ 129 : : TheoryEqNotifyClass d_notify; 130 : : 131 : : /** Cache of word-blasted facts. */ 132 : : context::CDHashSet<Node> d_wbFactsCache; 133 : : 134 : : /** Flag indicating whether `d_modelCache` should be invalidated. */ 135 : : context::CDO<bool> d_invalidateModelCache; 136 : : 137 : : /** 138 : : * Cache for getValue() calls. 139 : : * 140 : : * Is cleared at the beginning of a getValue() call if the 141 : : * `d_invalidateModelCache` flag is set to true. 142 : : */ 143 : : std::unordered_map<Node, Node> d_modelCache; 144 : : 145 : : /** True constant. */ 146 : : Node d_true; 147 : : }; 148 : : 149 : : } // namespace fp 150 : : } // namespace theory 151 : : } // namespace cvc5::internal 152 : : 153 : : #endif /* CVC5__THEORY__FP__THEORY_FP_H */