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