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 : : * Print benchmark utility. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__SMT__PRINT_BENCHMARK_H 16 : : #define CVC5__SMT__PRINT_BENCHMARK_H 17 : : 18 : : #include <iosfwd> 19 : : #include <vector> 20 : : 21 : : #include "expr/node.h" 22 : : 23 : : namespace cvc5::internal { 24 : : 25 : : class Printer; 26 : : class NodeConverter; 27 : : 28 : : namespace smt { 29 : : 30 : : /** 31 : : * A utility for printing a benchmark. This utility requires no bookkeeping 32 : : * about which commands have been executed. It reconstructs the set of 33 : : * commands that would have been required for generating a benchmark based on 34 : : * a list of nodes. 35 : : */ 36 : : class PrintBenchmark 37 : : { 38 : : public: 39 : : /** 40 : : * Constructor. 41 : : * @param nm The associated node manager. 42 : : * @param p The associated printer. 43 : : * @param sorted True if declarations should be sorted wrt node id. 44 : : * @param c The associated node converter. 45 : : */ 46 : 1807 : PrintBenchmark(NodeManager* nm, 47 : : const Printer* p, 48 : : bool sorted = true, 49 : : NodeConverter* c = nullptr) 50 : 1807 : : d_nm(nm), d_printer(p), d_sorted(sorted), d_converter(c) 51 : : { 52 : 1807 : } 53 : : /** 54 : : * Print the declarations and definitions from a set of definitions and terms. 55 : : * 56 : : * @param outDecl The output stream to print the declarations on 57 : : * @param outDef The output stream to print the definitions on. 58 : : * @param def The definitions to print. 59 : : * @param term The terms to print declarations and definitions from. 60 : : */ 61 : : void printDeclarationsFrom(std::ostream& outDecl, 62 : : std::ostream& outDef, 63 : : const std::vector<Node>& defs, 64 : : const std::vector<Node>& terms); 65 : : /** 66 : : * Print assertions. This prints a parsable set of commands on the output 67 : : * stream out that defines (recursive) functions in defs, and asserts 68 : : * assertions. It does not print a set-logic or check-sat command. 69 : : * 70 : : * Each node in defs is either of the form: 71 : : * (1) (= s t), where s is a (non-recursively) defined function, where 72 : : * the term t may be a lambda if s has non-zero arity. 73 : : * (2) (forall V (= (s V) t)), where s is a recursively defined function. 74 : : */ 75 : : void printAssertions(std::ostream& out, 76 : : const std::vector<Node>& defs, 77 : : const std::vector<Node>& assertions); 78 : : /** 79 : : * Print assertions, without special handling of defined functions. 80 : : */ 81 : : void printAssertions(std::ostream& out, const std::vector<Node>& assertions); 82 : : 83 : : /** 84 : : * Print benchmark, which prints a parsable benchmark on the output stream 85 : : * out. It relies on the printAssertions method above, as well as printing 86 : : * the logic based on given string and a final check-sat command. 87 : : * 88 : : * For the best printing, defs should be given in the order in which 89 : : * the symbols were declared. If this is not the case, then we may e.g. 90 : : * group blocks of definitions that were not grouped in the input. 91 : : */ 92 : : void printBenchmark(std::ostream& out, 93 : : const std::string& logic, 94 : : const std::vector<Node>& defs, 95 : : const std::vector<Node>& assertions); 96 : : 97 : : /** 98 : : * Mark that the given symbol should not be printed in benchmark outputs. 99 : : */ 100 : : static void markNoPrint(Node& sym); 101 : : 102 : : private: 103 : : /** 104 : : * print declared symbols in funs but not processed; updates processed to 105 : : * include what was printed 106 : : */ 107 : : void printDeclaredFuns(std::ostream& out, 108 : : const std::vector<Node>& funs, 109 : : std::unordered_set<Node>& processed); 110 : : /** 111 : : * Get the connected types. This traverses subfield types of datatypes and 112 : : * adds to connectedTypes everything that is necessary for printing tn. 113 : : * 114 : : * @param tn The type to traverse 115 : : * @param connectedTypes The types that tn depends on 116 : : * @param process The types we have already processed. We update this set 117 : : * with those added to connectedTypes. 118 : : */ 119 : : void getConnectedSubfieldTypes(TypeNode tn, 120 : : std::vector<TypeNode>& connectedTypes, 121 : : std::unordered_set<TypeNode>& processed); 122 : : /** 123 : : * Get connected definitions for symbol v. 124 : : * 125 : : * @param recDefs The recursive function definitions that v depends on 126 : : * @param ordinaryDefs The non-recursive definitions that v depends on 127 : : * @param syms The declared symbols that v depends on 128 : : * @param defMap Map from symbols to their definitions 129 : : * @param processedDefs The (recursive or non-recursive) definitions we have 130 : : * processed already. We update this with symbols we add to recDefs and 131 : : * ordinaryDefs. 132 : : * @param visited The set of terms we have already visited when searching for 133 : : * free symbols. This set is updated for the bodies of definitions processed 134 : : * in this call. 135 : : */ 136 : : void getConnectedDefinitions( 137 : : Node v, 138 : : std::vector<Node>& recDefs, 139 : : std::vector<Node>& ordinaryDefs, 140 : : std::unordered_set<Node>& syms, 141 : : const std::unordered_map<Node, std::pair<bool, Node>>& defMap, 142 : : std::unordered_set<Node>& processedDefs, 143 : : std::unordered_set<TNode>& visited); 144 : : /** 145 : : * Decompose definition assertion a. 146 : : * 147 : : * @param a The definition assertion 148 : : * @param isRecDef Updated to true if a is a recursive function definition (a 149 : : * quantified formula) 150 : : * @param sym Updated to the symbol that a defines 151 : : * @param body Update to the term that defines sym 152 : : * @return true if the definition was successfully inferred 153 : : */ 154 : : bool decomposeDefinition(Node a, bool& isRecDef, Node& sym, Node& body); 155 : : /** Pointer to the node manager */ 156 : : NodeManager* d_nm; 157 : : /** 158 : : * Pointer to the printer we are using, which is responsible for printing 159 : : * individual commands. 160 : : */ 161 : : const Printer* d_printer; 162 : : /* True if declarations should be sorted wrt node id. */ 163 : : bool d_sorted; 164 : : /** (Optional) node converter */ 165 : : NodeConverter* d_converter; 166 : : }; 167 : : 168 : : } // namespace smt 169 : : } // namespace cvc5::internal 170 : : 171 : : #endif /* CVC5__SMT__PRINT_BENCHMARK_H */