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
|
/********************* */
/*! \file proof_node_manager.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 manager
**/
#include "expr/proof_node_manager.h"
using namespace CVC4::kind;
namespace CVC4 {
ProofNodeManager::ProofNodeManager(ProofChecker* pc) : d_checker(pc) {}
std::shared_ptr<ProofNode> ProofNodeManager::mkNode(
PfRule id,
const std::vector<std::shared_ptr<ProofNode>>& children,
const std::vector<Node>& args,
Node expected)
{
Node res = checkInternal(id, children, args, expected);
if (res.isNull())
{
// if it was invalid, then we return the null node
return nullptr;
}
// otherwise construct the proof node and set its proven field
std::shared_ptr<ProofNode> pn =
std::make_shared<ProofNode>(id, children, args);
pn->d_proven = res;
return pn;
}
bool ProofNodeManager::updateNode(
ProofNode* pn,
PfRule id,
const std::vector<std::shared_ptr<ProofNode>>& children,
const std::vector<Node>& args)
{
// should have already computed what is proven
Assert(!pn->d_proven.isNull())
<< "ProofNodeManager::updateProofNode: invalid proof provided";
// We expect to prove the same thing as before
Node res = checkInternal(id, children, args, pn->d_proven);
if (res.isNull())
{
// if it was invalid, then we do not update
return false;
}
// we update its value
pn->setValue(id, children, args);
// proven field should already be the same as the result
Assert(res == pn->d_proven);
return true;
}
Node ProofNodeManager::checkInternal(
PfRule id,
const std::vector<std::shared_ptr<ProofNode>>& children,
const std::vector<Node>& args,
Node expected)
{
Node res;
if (d_checker)
{
// check with the checker, which takes expected as argument
res = d_checker->check(id, children, args, expected);
Assert(!res.isNull())
<< "ProofNodeManager::checkInternal: failed to check proof";
}
else
{
// otherwise we trust the expected value, if it exists
Assert(!expected.isNull()) << "ProofNodeManager::checkInternal: no checker "
"or expected value provided";
res = expected;
}
return res;
}
ProofChecker* ProofNodeManager::getChecker() const { return d_checker; }
} // namespace CVC4
|