Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds, Mathias Preiner, Aina Niemetz 4 : : * 5 : : * This file is part of the cvc5 project. 6 : : * 7 : : * Copyright (c) 2009-2025 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 : : * Class for applying the deep embedding for SyGuS 14 : : */ 15 : : 16 : : #include "cvc5_private.h" 17 : : 18 : : #ifndef CVC5__THEORY__QUANTIFIERS__EMBEDDING_CONVERTER_H 19 : : #define CVC5__THEORY__QUANTIFIERS__EMBEDDING_CONVERTER_H 20 : : 21 : : #include <map> 22 : : #include <vector> 23 : : 24 : : #include "expr/attribute.h" 25 : : #include "expr/node.h" 26 : : #include "smt/env_obj.h" 27 : : 28 : : namespace cvc5::internal { 29 : : namespace theory { 30 : : namespace quantifiers { 31 : : 32 : : class SynthConjecture; 33 : : class TermDbSygus; 34 : : 35 : : /** 36 : : * Utility for applying the deep embedding from Section 4 of Reynolds et al CAV 37 : : * 2015. 38 : : */ 39 : : class EmbeddingConverter : protected EnvObj 40 : : { 41 : : public: 42 : : EmbeddingConverter(Env& env, TermDbSygus* tds, SynthConjecture* p); 43 : 13036 : ~EmbeddingConverter() {} 44 : : /** process 45 : : * 46 : : * This converts node q based on its deep embedding 47 : : * (Section 4 of Reynolds et al CAV 2015). 48 : : * The syntactic restrictions are associated with 49 : : * the functions-to-synthesize using the attribute 50 : : * SygusSynthGrammarAttribute. 51 : : * The arguments templates and template_args 52 : : * indicate templates for the function to synthesize, 53 : : * in particular the solution for the i^th function 54 : : * to synthesis must be of the form 55 : : * templates[i]{ templates_arg[i] -> t } 56 : : * for some t if !templates[i].isNull(). 57 : : * 58 : : * This may return null if we are unable to construct a well founded 59 : : * grammar for a function-to-synthesize, which indicates that it is not 60 : : * possible to process this quantified formula with SyGuS. 61 : : */ 62 : : Node process(Node q, 63 : : const std::map<Node, Node>& templates, 64 : : const std::map<Node, Node>& templates_arg); 65 : : /** 66 : : * Same as above, but we have already determined that the set of first-order 67 : : * datatype variables that will quantify the deep embedding conjecture are 68 : : * the vector ebvl. 69 : : */ 70 : : Node process(Node q, 71 : : const std::map<Node, Node>& templates, 72 : : const std::map<Node, Node>& templates_arg, 73 : : const std::vector<Node>& ebvl); 74 : : 75 : : /** Is the syntax restricted? */ 76 : 971 : bool isSyntaxRestricted() { return d_is_syntax_restricted; } 77 : : /** 78 : : * Convert node n based on deep embedding, see Section 4 of Reynolds et al 79 : : * CAV 2015. 80 : : * 81 : : * This returns the result of converting n to its deep embedding based on 82 : : * the mapping from functions to datatype variables, stored in 83 : : * d_synth_fun_vars. This method should be called only after calling process 84 : : * above. 85 : : */ 86 : : Node convertToEmbedding(Node n); 87 : : /** 88 : : * Returns true iff there are syntax restrictions on the 89 : : * functions-to-synthesize of sygus conjecture q. 90 : : */ 91 : : static bool hasSyntaxRestrictions(Node q); 92 : : 93 : : private: 94 : : /** The sygus term database we are using */ 95 : : TermDbSygus* d_tds; 96 : : /** parent conjecture 97 : : * This contains global information about the synthesis conjecture. 98 : : */ 99 : : SynthConjecture* d_parent; 100 : : /** 101 : : * Maps each synthesis function to its corresponding (first-order) sygus 102 : : * datatype variable. This map is initialized by the process methods. 103 : : */ 104 : : std::map<Node, Node> d_synth_fun_vars; 105 : : /** is the syntax restricted? */ 106 : : bool d_is_syntax_restricted; 107 : : /** collect terms */ 108 : : void collectTerms(Node n, 109 : : std::map<TypeNode, std::unordered_set<Node>>& consts); 110 : : }; 111 : : 112 : : } // namespace quantifiers 113 : : } // namespace theory 114 : : } // namespace cvc5::internal 115 : : 116 : : #endif