1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Aina Niemetz |
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 |
|
* Implementation of proof step and proof step buffer utilities. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "proof/proof_step_buffer.h" |
17 |
|
|
18 |
|
#include "proof/proof_checker.h" |
19 |
|
|
20 |
|
using namespace cvc5::kind; |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
|
24 |
3950 |
ProofStep::ProofStep() : d_rule(PfRule::UNKNOWN) {} |
25 |
3065829 |
ProofStep::ProofStep(PfRule r, |
26 |
|
const std::vector<Node>& children, |
27 |
3065829 |
const std::vector<Node>& args) |
28 |
3065829 |
: d_rule(r), d_children(children), d_args(args) |
29 |
|
{ |
30 |
3065829 |
} |
31 |
|
std::ostream& operator<<(std::ostream& out, ProofStep step) |
32 |
|
{ |
33 |
|
out << "(step " << step.d_rule; |
34 |
|
for (const Node& c : step.d_children) |
35 |
|
{ |
36 |
|
out << " " << c; |
37 |
|
} |
38 |
|
if (!step.d_args.empty()) |
39 |
|
{ |
40 |
|
out << " :args"; |
41 |
|
for (const Node& a : step.d_args) |
42 |
|
{ |
43 |
|
out << " " << a; |
44 |
|
} |
45 |
|
} |
46 |
|
out << ")"; |
47 |
|
return out; |
48 |
|
} |
49 |
|
|
50 |
16317 |
ProofStepBuffer::ProofStepBuffer(ProofChecker* pc) : d_checker(pc) {} |
51 |
|
|
52 |
126796 |
Node ProofStepBuffer::tryStep(PfRule id, |
53 |
|
const std::vector<Node>& children, |
54 |
|
const std::vector<Node>& args, |
55 |
|
Node expected) |
56 |
|
{ |
57 |
126796 |
if (d_checker == nullptr) |
58 |
|
{ |
59 |
|
Assert(false) << "ProofStepBuffer::ProofStepBuffer: no proof checker."; |
60 |
|
return Node::null(); |
61 |
|
} |
62 |
|
Node res = |
63 |
253592 |
d_checker->checkDebug(id, children, args, expected, "pf-step-buffer"); |
64 |
126796 |
if (!res.isNull()) |
65 |
|
{ |
66 |
|
// add proof step |
67 |
252952 |
d_steps.push_back( |
68 |
252952 |
std::pair<Node, ProofStep>(res, ProofStep(id, children, args))); |
69 |
|
} |
70 |
126796 |
return res; |
71 |
|
} |
72 |
|
|
73 |
2896937 |
void ProofStepBuffer::addStep(PfRule id, |
74 |
|
const std::vector<Node>& children, |
75 |
|
const std::vector<Node>& args, |
76 |
|
Node expected) |
77 |
|
{ |
78 |
5793874 |
d_steps.push_back( |
79 |
5793874 |
std::pair<Node, ProofStep>(expected, ProofStep(id, children, args))); |
80 |
2896937 |
} |
81 |
|
|
82 |
|
void ProofStepBuffer::addSteps(ProofStepBuffer& psb) |
83 |
|
{ |
84 |
|
const std::vector<std::pair<Node, ProofStep>>& steps = psb.getSteps(); |
85 |
|
for (const std::pair<Node, ProofStep>& step : steps) |
86 |
|
{ |
87 |
|
addStep(step.second.d_rule, |
88 |
|
step.second.d_children, |
89 |
|
step.second.d_args, |
90 |
|
step.first); |
91 |
|
} |
92 |
|
} |
93 |
|
|
94 |
616 |
void ProofStepBuffer::popStep() |
95 |
|
{ |
96 |
616 |
Assert(!d_steps.empty()); |
97 |
616 |
if (!d_steps.empty()) |
98 |
|
{ |
99 |
616 |
d_steps.pop_back(); |
100 |
|
} |
101 |
616 |
} |
102 |
|
|
103 |
|
size_t ProofStepBuffer::getNumSteps() const { return d_steps.size(); } |
104 |
|
|
105 |
121893 |
const std::vector<std::pair<Node, ProofStep>>& ProofStepBuffer::getSteps() const |
106 |
|
{ |
107 |
121893 |
return d_steps; |
108 |
|
} |
109 |
|
|
110 |
118412 |
void ProofStepBuffer::clear() { d_steps.clear(); } |
111 |
|
|
112 |
29340 |
} // namespace cvc5 |