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