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