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 : : * Oracle engine for SMTO 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__QUANTIFIERS__ORACLE_ENGINE_H 16 : : #define CVC5__THEORY__QUANTIFIERS__ORACLE_ENGINE_H 17 : : 18 : : #include "theory/decision_strategy.h" 19 : : #include "theory/quantifiers/oracle_checker.h" 20 : : #include "theory/quantifiers/quant_module.h" 21 : : 22 : : namespace cvc5::internal { 23 : : namespace theory { 24 : : namespace quantifiers { 25 : : 26 : : /** 27 : : * Oracle engine 28 : : * 29 : : * This class manages the list of declared oracle functions and asserted 30 : : * oracle interfaces. 31 : : * 32 : : * For SMT modulo oracles (SMTO) queries, this class is responsible for 33 : : * invoking oracles, as specified by oracle interface quantifiers (see 34 : : * OracleInterfaceAttribute), until all oracle functions have consistent 35 : : * definitions with respect to the current model. 36 : : * 37 : : * In detail, an oracle function f has a consistent definition with respect to 38 : : * the current model M if all invocations f(t) in assertions are such that 39 : : * we have invoked its associated oracle on t^M and that invocation returned 40 : : * the value f(t)^M. This module is complete for oracle interface quantifiers 41 : : * if their associated oracle function has a consistent definition. 42 : : * 43 : : * For details, see Polgreen et al VMCAI 2022. 44 : : */ 45 : : class OracleEngine : public QuantifiersModule 46 : : { 47 : : public: 48 : : OracleEngine(Env& env, 49 : : QuantifiersState& qs, 50 : : QuantifiersInferenceManager& qim, 51 : : QuantifiersRegistry& qr, 52 : : TermRegistry& tr); 53 : 1060 : ~OracleEngine() {} 54 : : /** Presolve */ 55 : : void presolve() override; 56 : : /** Needs check. */ 57 : : bool needsCheck(Theory::Effort e) override; 58 : : /** Needs model. */ 59 : : QEffort needsModel(Theory::Effort e) override; 60 : : /** Reset round. */ 61 : : void reset_round(Theory::Effort e) override; 62 : : /** Register quantified formula q */ 63 : : void registerQuantifier(Node q) override; 64 : : /** Check. 65 : : * Adds instantiations for all currently asserted 66 : : * quantified formulas via calls to process(...) 67 : : */ 68 : : void check(Theory::Effort e, QEffort quant_e) override; 69 : : /** 70 : : * Check was complete for quantified formula q, return true if we can say 71 : : * "sat" provided that q is currently asserted. 72 : : */ 73 : : bool checkCompleteFor(Node q) override; 74 : : /** check ownership */ 75 : : void checkOwnership(Node q) override; 76 : : /** Identify. */ 77 : : std::string identify() const override; 78 : : 79 : : /** Declare oracle fun */ 80 : : void declareOracleFun(Node f); 81 : : /** Get the list of all declared oracle functions */ 82 : : std::vector<Node> getOracleFuns() const; 83 : : 84 : : /** Make an oracle interface quantifier */ 85 : : static Node mkOracleInterface(const std::vector<Node>& inputs, 86 : : const std::vector<Node>& outputs, 87 : : Node assume, 88 : : Node constraint, 89 : : Node oracleNode); 90 : : /** 91 : : * Get oracle interface, returns true if q is an oracle interface quantifier 92 : : * (constructed by the above method). Obtains the arguments for which q is 93 : : * constructed. 94 : : */ 95 : : bool getOracleInterface(Node q, 96 : : std::vector<Node>& inputs, 97 : : std::vector<Node>& outputs, 98 : : Node& assume, 99 : : Node& constraint, 100 : : Node& oracleNode) const; 101 : : 102 : : private: 103 : : /** The oracle functions (user-context dependent) */ 104 : : context::CDList<Node> d_oracleFuns; 105 : : /** Pointer to the oracle checker */ 106 : : OracleChecker* d_ochecker; 107 : : /** 108 : : * In a given instantiation round, did consistency checks pass for all 109 : : * oracle interface quantified formulas? 110 : : */ 111 : : bool d_consistencyCheckPassed; 112 : : /** 113 : : * A decision strategy that prefers equating arguments of oracles to 114 : : * values that we have already evaluated the oracle on. For example, if 115 : : * we have an application (f a) of oracle function f, then if a=5 in one 116 : : * model, we may generate the lemma (=> (= a 5) (= (f a) 10)), where 10 is 117 : : * result of calling f on 5. This decision strategy will henceforth decide 118 : : * (= a 5) -> true. This ensures that we don't invoke f for evaluating (f a) 119 : : * again until we are sure that (= a 5) cannot be made true. 120 : : */ 121 : : DecisionStrategyVector d_dstrat; 122 : : }; 123 : : 124 : : } // namespace quantifiers 125 : : } // namespace theory 126 : : } // namespace cvc5::internal 127 : : 128 : : #endif