blob: b5e3910491b031a248055d0b9ad58b617bd9ccb7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/********************* */
/*! \file proof_node.cpp
** \verbatim
** Top contributors (to current version):
** Andrew Reynolds
** This file is part of the CVC4 project.
** Copyright (c) 2009-2019 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**
** \brief Implementation of proof node utility
**/
#include "expr/proof_node.h"
namespace CVC4 {
ProofNode::ProofNode(PfRule id,
const std::vector<std::shared_ptr<ProofNode>>& children,
const std::vector<Node>& args)
{
setValue(id, children, args);
}
PfRule ProofNode::getRule() const { return d_rule; }
const std::vector<std::shared_ptr<ProofNode>>& ProofNode::getChildren() const
{
return d_children;
}
const std::vector<Node>& ProofNode::getArguments() const { return d_args; }
Node ProofNode::getResult() const { return d_proven; }
void ProofNode::getFreeAssumptions(std::vector<Node>& assump) const
{
// visited set false after preorder traversal, true after postorder traversal
std::unordered_map<const ProofNode*, bool> visited;
std::unordered_map<const ProofNode*, bool>::iterator it;
std::vector<const ProofNode*> visit;
// the current set of formulas bound by SCOPE
std::unordered_set<Node, NodeHashFunction> currentScope;
const ProofNode* cur;
visit.push_back(this);
do
{
cur = visit.back();
visit.pop_back();
it = visited.find(cur);
if (it == visited.end())
{
visited[cur] = true;
PfRule id = cur->getRule();
if (id == PfRule::ASSUME)
{
Assert(cur->d_args.size() == 1);
Node f = cur->d_args[0];
if (currentScope.find(f) == currentScope.end())
{
assump.push_back(f);
}
}
else
{
if (id == PfRule::SCOPE)
{
// mark that its arguments are bound in the current scope
for (const Node& a : cur->d_args)
{
// should not have assumption shadowing
Assert(currentScope.find(a) != currentScope.end());
currentScope.insert(a);
}
// will need to unbind the variables below
visited[cur] = false;
}
for (const std::shared_ptr<ProofNode>& cp : cur->d_children)
{
visit.push_back(cp.get());
}
}
}
else if (!it->second)
{
Assert(cur->getRule() == PfRule::SCOPE);
// unbind its assumptions
for (const Node& a : cur->d_args)
{
currentScope.erase(a);
}
}
} while (!visit.empty());
}
bool ProofNode::isClosed() const
{
std::vector<Node> assumps;
getFreeAssumptions(assumps);
return assumps.empty();
}
void ProofNode::setValue(
PfRule id,
const std::vector<std::shared_ptr<ProofNode>>& children,
const std::vector<Node>& args)
{
d_rule = id;
d_children = children;
d_args = args;
}
void ProofNode::printDebug(std::ostream& os) const
{
os << "(" << d_rule;
for (const std::shared_ptr<ProofNode>& c : d_children)
{
os << " ";
c->printDebug(os);
}
if (!d_args.empty())
{
os << " :args " << d_args;
}
os << ")";
}
} // namespace CVC4
|