1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Gereon Kremer |
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 |
|
* Proof checker utility. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__EXPR__PROOF_CHECKER_H |
19 |
|
#define CVC5__EXPR__PROOF_CHECKER_H |
20 |
|
|
21 |
|
#include <map> |
22 |
|
|
23 |
|
#include "expr/node.h" |
24 |
|
#include "expr/proof_rule.h" |
25 |
|
#include "util/statistics_stats.h" |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
|
29 |
|
class ProofChecker; |
30 |
|
class ProofNode; |
31 |
|
|
32 |
|
/** A virtual base class for checking a proof rule */ |
33 |
|
class ProofRuleChecker |
34 |
|
{ |
35 |
|
public: |
36 |
86100 |
ProofRuleChecker() {} |
37 |
86100 |
virtual ~ProofRuleChecker() {} |
38 |
|
/** |
39 |
|
* This checks a single step in a proof. |
40 |
|
* |
41 |
|
* Return the formula that is proven by a proof node with the given id, |
42 |
|
* premises and arguments, or null if such a proof node is not well-formed. |
43 |
|
* |
44 |
|
* Note that the input/output of this method expects to be terms in *Skolem |
45 |
|
* form*, which is passed to checkInternal below. Rule checkers may |
46 |
|
* convert premises to witness form when necessary. |
47 |
|
* |
48 |
|
* @param id The id of the proof node to check |
49 |
|
* @param children The premises of the proof node to check. These are nodes |
50 |
|
* corresponding to the conclusion (ProofNode::getResult) of the children |
51 |
|
* of the proof node we are checking in Skolem form. |
52 |
|
* @param args The arguments of the proof node to check |
53 |
|
* @return The conclusion of the proof node, in Skolem form, if successful or |
54 |
|
* null if such a proof node is malformed. |
55 |
|
*/ |
56 |
|
Node check(PfRule id, |
57 |
|
const std::vector<Node>& children, |
58 |
|
const std::vector<Node>& args); |
59 |
|
|
60 |
|
/** get an index from a node, return false if we fail */ |
61 |
|
static bool getUInt32(TNode n, uint32_t& i); |
62 |
|
/** get a Boolean from a node, return false if we fail */ |
63 |
|
static bool getBool(TNode n, bool& b); |
64 |
|
/** get a Kind from a node, return false if we fail */ |
65 |
|
static bool getKind(TNode n, Kind& k); |
66 |
|
/** Make a Kind into a node */ |
67 |
|
static Node mkKindNode(Kind k); |
68 |
|
|
69 |
|
/** Register all rules owned by this rule checker into pc. */ |
70 |
|
virtual void registerTo(ProofChecker* pc) {} |
71 |
|
|
72 |
|
protected: |
73 |
|
/** |
74 |
|
* This checks a single step in a proof. |
75 |
|
* |
76 |
|
* @param id The id of the proof node to check |
77 |
|
* @param children The premises of the proof node to check. These are nodes |
78 |
|
* corresponding to the conclusion (ProofNode::getResult) of the children |
79 |
|
* of the proof node we are checking. |
80 |
|
* @param args The arguments of the proof node to check |
81 |
|
* @return The conclusion of the proof node if successful or null if such a |
82 |
|
* proof node is malformed. |
83 |
|
*/ |
84 |
|
virtual Node checkInternal(PfRule id, |
85 |
|
const std::vector<Node>& children, |
86 |
|
const std::vector<Node>& args) = 0; |
87 |
|
}; |
88 |
|
|
89 |
|
/** Statistics class */ |
90 |
|
class ProofCheckerStatistics |
91 |
|
{ |
92 |
|
public: |
93 |
|
ProofCheckerStatistics(); |
94 |
|
/** Counts the number of checks for each kind of proof rule */ |
95 |
|
HistogramStat<PfRule> d_ruleChecks; |
96 |
|
/** Total number of rule checks */ |
97 |
|
IntStat d_totalRuleChecks; |
98 |
|
}; |
99 |
|
|
100 |
|
/** A class for checking proofs */ |
101 |
|
class ProofChecker |
102 |
|
{ |
103 |
|
public: |
104 |
3600 |
ProofChecker(uint32_t pclevel = 0) : d_pclevel(pclevel) {} |
105 |
3600 |
~ProofChecker() {} |
106 |
|
/** |
107 |
|
* Return the formula that is proven by proof node pn, or null if pn is not |
108 |
|
* well-formed. If expected is non-null, then we return null if pn does not |
109 |
|
* prove expected. |
110 |
|
* |
111 |
|
* @param pn The proof node to check |
112 |
|
* @param expected The (optional) formula that is the expected conclusion of |
113 |
|
* the proof node. |
114 |
|
* @return The conclusion of the proof node if successful or null if the |
115 |
|
* proof is malformed, or if no checker is available for id. |
116 |
|
*/ |
117 |
|
Node check(ProofNode* pn, Node expected = Node::null()); |
118 |
|
/** Same as above, with explicit arguments |
119 |
|
* |
120 |
|
* @param id The id of the proof node to check |
121 |
|
* @param children The children of the proof node to check |
122 |
|
* @param args The arguments of the proof node to check |
123 |
|
* @param expected The (optional) formula that is the expected conclusion of |
124 |
|
* the proof node. |
125 |
|
* @return The conclusion of the proof node if successful or null if the |
126 |
|
* proof is malformed, or if no checker is available for id. |
127 |
|
*/ |
128 |
|
Node check(PfRule id, |
129 |
|
const std::vector<std::shared_ptr<ProofNode>>& children, |
130 |
|
const std::vector<Node>& args, |
131 |
|
Node expected = Node::null()); |
132 |
|
/** |
133 |
|
* Same as above, without conclusions instead of proof node children. This |
134 |
|
* is used for debugging. In particular, this function does not throw an |
135 |
|
* assertion failure when a proof step is malformed and can be used without |
136 |
|
* constructing proof nodes. |
137 |
|
* |
138 |
|
* @param id The id of the proof node to check |
139 |
|
* @param children The conclusions of the children of the proof node to check |
140 |
|
* @param args The arguments of the proof node to check |
141 |
|
* @param expected The (optional) formula that is the expected conclusion of |
142 |
|
* the proof node. |
143 |
|
* @param traceTag The trace tag to print debug information to |
144 |
|
* @return The conclusion of the proof node if successful or null if the |
145 |
|
* proof is malformed, or if no checker is available for id. |
146 |
|
*/ |
147 |
|
Node checkDebug(PfRule id, |
148 |
|
const std::vector<Node>& cchildren, |
149 |
|
const std::vector<Node>& args, |
150 |
|
Node expected = Node::null(), |
151 |
|
const char* traceTag = ""); |
152 |
|
/** Indicate that psc is the checker for proof rule id */ |
153 |
|
void registerChecker(PfRule id, ProofRuleChecker* psc); |
154 |
|
/** |
155 |
|
* Indicate that id is a trusted rule with the given pedantic level, e.g.: |
156 |
|
* 0: (mandatory) always a failure to use the given id |
157 |
|
* 1: (major) failure on all (non-zero) pedantic levels |
158 |
|
* 10: (minor) failure only on pedantic levels >= 10. |
159 |
|
*/ |
160 |
|
void registerTrustedChecker(PfRule id, |
161 |
|
ProofRuleChecker* psc, |
162 |
|
uint32_t plevel = 10); |
163 |
|
/** get checker for */ |
164 |
|
ProofRuleChecker* getCheckerFor(PfRule id); |
165 |
|
|
166 |
|
/** |
167 |
|
* Get the pedantic level for id if it has been assigned a pedantic |
168 |
|
* level via registerTrustedChecker above, or zero otherwise. |
169 |
|
*/ |
170 |
|
uint32_t getPedanticLevel(PfRule id) const; |
171 |
|
|
172 |
|
/** |
173 |
|
* Is pedantic failure? If so, we return true and write a debug message on the |
174 |
|
* output stream out if enableOutput is true. |
175 |
|
*/ |
176 |
|
bool isPedanticFailure(PfRule id, |
177 |
|
std::ostream& out, |
178 |
|
bool enableOutput = true) const; |
179 |
|
|
180 |
|
private: |
181 |
|
/** statistics class */ |
182 |
|
ProofCheckerStatistics d_stats; |
183 |
|
/** Maps proof rules to their checker */ |
184 |
|
std::map<PfRule, ProofRuleChecker*> d_checker; |
185 |
|
/** Maps proof trusted rules to their pedantic level */ |
186 |
|
std::map<PfRule, uint32_t> d_plevel; |
187 |
|
/** The pedantic level of this checker */ |
188 |
|
uint32_t d_pclevel; |
189 |
|
/** |
190 |
|
* Check internal. This is used by check and checkDebug above. It writes |
191 |
|
* checking errors on out when enableOutput is true. We treat trusted checkers |
192 |
|
* (nullptr in the range of the map d_checker) as failures if |
193 |
|
* useTrustedChecker = false. |
194 |
|
*/ |
195 |
|
Node checkInternal(PfRule id, |
196 |
|
const std::vector<Node>& cchildren, |
197 |
|
const std::vector<Node>& args, |
198 |
|
Node expected, |
199 |
|
std::stringstream& out, |
200 |
|
bool useTrustedChecker, |
201 |
|
bool enableOutput); |
202 |
|
}; |
203 |
|
|
204 |
|
} // namespace cvc5 |
205 |
|
|
206 |
|
#endif /* CVC5__EXPR__PROOF_CHECKER_H */ |