Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds, Yoni Zohar 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 : : * Utility for detecting quantifier macro definitions. 14 : : */ 15 : : 16 : : #include "cvc5_private.h" 17 : : 18 : : #ifndef CVC5__THEORY__QUANTIFIERS__QUANTIFIERS_MACROS_H 19 : : #define CVC5__THEORY__QUANTIFIERS__QUANTIFIERS_MACROS_H 20 : : 21 : : #include <map> 22 : : #include <vector> 23 : : 24 : : #include "expr/node.h" 25 : : #include "smt/env_obj.h" 26 : : 27 : : namespace cvc5::internal { 28 : : namespace theory { 29 : : namespace quantifiers { 30 : : 31 : : class QuantifiersRegistry; 32 : : 33 : : /** 34 : : * A utility for inferring macros from quantified formulas. This can be seen as 35 : : * a method for putting quantified formulas in solved form, e.g. 36 : : * forall x. P(x) ---> P = (lambda x. true) 37 : : */ 38 : : class QuantifiersMacros : protected EnvObj 39 : : { 40 : : public: 41 : : QuantifiersMacros(Env& env, QuantifiersRegistry& qr); 42 : 90 : ~QuantifiersMacros() {} 43 : : /** 44 : : * Called on quantified formulas lit of the form 45 : : * forall x1 ... xn. n = ndef 46 : : * where n is of the form U(x1...xn). Returns an equality of the form 47 : : * U = lambda x1 ... xn. ndef 48 : : * if this is a legal macro definition for U, and the null node otherwise. 49 : : * 50 : : * @param lit The body of the quantified formula 51 : : * @param reqGround Whether we require the macro definition to be ground, 52 : : * i.e. does not contain quantified formulas as subterms. 53 : : * @return If a macro can be inferred, an equality of the form 54 : : * (op = lambda x1 ... xn. def)), or the null node otherwise. 55 : : */ 56 : : Node solve(Node lit, bool reqGround = false); 57 : : 58 : : private: 59 : : /** 60 : : * Return true n is an APPLY_UF with pairwise unique BOUND_VARIABLE as 61 : : * children. 62 : : */ 63 : : bool isBoundVarApplyUf(Node n); 64 : : /** 65 : : * Returns true if n contains op, or if n contains a quantified formula 66 : : * as a subterm and reqGround is true. 67 : : */ 68 : : bool containsBadOp(Node n, Node op, bool reqGround); 69 : : /** 70 : : * Return true if n preserves trigger variables in quantified formula q, that 71 : : * is, triggers can be inferred containing all variables in q in term n. 72 : : */ 73 : : bool preservesTriggerVariables(Node q, Node n); 74 : : /** 75 : : * From n, get a list of possible subterms of n that could be the head of a 76 : : * macro definition. 77 : : */ 78 : : void getMacroCandidates(Node n, 79 : : std::vector<Node>& candidates, 80 : : std::map<Node, bool>& visited); 81 : : /** 82 : : * Solve n in literal lit, return n' such that n = n' is equivalent to lit 83 : : * if possible, or null otherwise. 84 : : */ 85 : : Node solveInEquality(Node n, Node lit); 86 : : /** 87 : : * Called when we have inferred a quantified formula is of the form 88 : : * forall x1 ... xn. n = ndef 89 : : * where n is of the form U(x1...xn). 90 : : */ 91 : : Node solveEq(Node n, Node ndef); 92 : : /** 93 : : * Returns the macro fdef, which originated from lit. This method is for 94 : : * debugging. 95 : : */ 96 : : Node returnMacro(Node fdef, Node lit) const; 97 : : /** Reference to the quantifiers registry */ 98 : : QuantifiersRegistry& d_qreg; 99 : : }; 100 : : 101 : : } // namespace quantifiers 102 : : } // namespace theory 103 : : } // namespace cvc5::internal 104 : : 105 : : #endif /*CVC5__THEORY__QUANTIFIERS__QUANTIFIER_MACROS_H */