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-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 : : * 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 : 14314 : ~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 : : Node process(Node q, 59 : : const std::map<Node, Node>& templates, 60 : : const std::map<Node, Node>& templates_arg); 61 : : /** 62 : : * Same as above, but we have already determined that the set of first-order 63 : : * datatype variables that will quantify the deep embedding conjecture are 64 : : * the vector ebvl. 65 : : */ 66 : : Node process(Node q, 67 : : const std::map<Node, Node>& templates, 68 : : const std::map<Node, Node>& templates_arg, 69 : : const std::vector<Node>& ebvl); 70 : : 71 : : /** Is the syntax restricted? */ 72 : 1163 : bool isSyntaxRestricted() { return d_is_syntax_restricted; } 73 : : /** 74 : : * Convert node n based on deep embedding, see Section 4 of Reynolds et al 75 : : * CAV 2015. 76 : : * 77 : : * This returns the result of converting n to its deep embedding based on 78 : : * the mapping from functions to datatype variables, stored in 79 : : * d_synth_fun_vars. This method should be called only after calling process 80 : : * above. 81 : : */ 82 : : Node convertToEmbedding(Node n); 83 : : /** 84 : : * Returns true iff there are syntax restrictions on the 85 : : * functions-to-synthesize of sygus conjecture q. 86 : : */ 87 : : static bool hasSyntaxRestrictions(Node q); 88 : : 89 : : private: 90 : : /** The sygus term database we are using */ 91 : : TermDbSygus* d_tds; 92 : : /** parent conjecture 93 : : * This contains global information about the synthesis conjecture. 94 : : */ 95 : : SynthConjecture* d_parent; 96 : : /** 97 : : * Maps each synthesis function to its corresponding (first-order) sygus 98 : : * datatype variable. This map is initialized by the process methods. 99 : : */ 100 : : std::map<Node, Node> d_synth_fun_vars; 101 : : /** is the syntax restricted? */ 102 : : bool d_is_syntax_restricted; 103 : : /** collect terms */ 104 : : void collectTerms(Node n, 105 : : std::map<TypeNode, std::unordered_set<Node>>& consts); 106 : : }; 107 : : 108 : : } // namespace quantifiers 109 : : } // namespace theory 110 : : } // namespace cvc5::internal 111 : : 112 : : #endif