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 : : * Utilities for computing letification of proofs. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__PROOF__PROOF_LETIFY_H 16 : : #define CVC5__PROOF__PROOF_LETIFY_H 17 : : 18 : : #include <iostream> 19 : : #include <map> 20 : : 21 : : #include "expr/node.h" 22 : : #include "proof/proof_node.h" 23 : : 24 : : namespace cvc5::internal { 25 : : namespace proof { 26 : : 27 : : /** 28 : : * A callback which asks whether a proof node should be traversed for 29 : : * proof letification. For example, this may make it so that SCOPE is not 30 : : * traversed. 31 : : */ 32 : : class ProofLetifyTraverseCallback 33 : : { 34 : : public: 35 : 1749 : virtual ~ProofLetifyTraverseCallback() {} 36 : : /** 37 : : * Should we traverse proof node pn for letification? If this returns false, 38 : : * then pn is being treated as a black box for letification. 39 : : */ 40 : : virtual bool shouldTraverse(const ProofNode* pn); 41 : : }; 42 : : 43 : : /** 44 : : * Utilities for letification. 45 : : */ 46 : : class ProofLetify 47 : : { 48 : : public: 49 : : /** 50 : : * Stores proofs in map that require letification, mapping them to a unique 51 : : * identifier. For each proof node in the domain of pletMap in the list 52 : : * pletList such that pletList[i] does not contain subproof pletList[j] for 53 : : * j>i. 54 : : * 55 : : * @param pn The proof node to letify 56 : : * @param pletList The list of proofs occurring in pn that should be letified 57 : : * @param pletMap Mapping from proofs in pletList to an identifier 58 : : * @param thresh The number of times a proof node has to occur to be added 59 : : * to pletList 60 : : * @param pltc A callback indicating whether to traverse a proof node during 61 : : * this call. 62 : : */ 63 : : static void computeProofLet(const ProofNode* pn, 64 : : std::vector<const ProofNode*>& pletList, 65 : : std::map<const ProofNode*, size_t>& pletMap, 66 : : size_t thresh = 2, 67 : : ProofLetifyTraverseCallback* pltc = nullptr); 68 : : 69 : : private: 70 : : /** 71 : : * Convert a map from proof nodes to # occurrences (pcount) to a list 72 : : * pletList / pletMap as described in the method above, where thresh 73 : : * is the minimum number of occurrences to be added to the list. 74 : : */ 75 : : static void convertProofCountToLet( 76 : : const std::vector<const ProofNode*>& visitList, 77 : : const std::map<const ProofNode*, size_t>& pcount, 78 : : std::vector<const ProofNode*>& pletList, 79 : : std::map<const ProofNode*, size_t>& pletMap, 80 : : size_t thresh = 2); 81 : : /** 82 : : * Compute the count of sub proof nodes in pn, store in pcount. Additionally, 83 : : * store each proof node in the domain of pcount in an order in visitList 84 : : * such that visitList[i] does not contain sub proof visitList[j] for j>i. 85 : : */ 86 : : static void computeProofCounts(const ProofNode* pn, 87 : : std::vector<const ProofNode*>& visitList, 88 : : std::map<const ProofNode*, size_t>& pcount, 89 : : ProofLetifyTraverseCallback* pltc); 90 : : }; 91 : : 92 : : } // namespace proof 93 : : } // namespace cvc5::internal 94 : : 95 : : #endif