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