GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/proof/trust_node.cpp Lines: 48 64 75.0 %
Date: 2021-09-29 Branches: 70 204 34.3 %

Line Exec Source
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
 * Implementation of the trust node utility.
14
 */
15
16
#include "proof/trust_node.h"
17
18
#include "proof/proof_ensure_closed.h"
19
#include "proof/proof_generator.h"
20
21
namespace cvc5 {
22
23
const char* toString(TrustNodeKind tnk)
24
{
25
  switch (tnk)
26
  {
27
    case TrustNodeKind::CONFLICT: return "CONFLICT";
28
    case TrustNodeKind::LEMMA: return "LEMMA";
29
    case TrustNodeKind::PROP_EXP: return "PROP_EXP";
30
    case TrustNodeKind::REWRITE: return "REWRITE";
31
    default: return "?";
32
  }
33
}
34
35
std::ostream& operator<<(std::ostream& out, TrustNodeKind tnk)
36
{
37
  out << toString(tnk);
38
  return out;
39
}
40
41
197349
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g)
42
{
43
394698
  Node ckey = getConflictProven(conf);
44
  // if a generator is provided, should confirm that it can prove it
45
197349
  Assert(g == nullptr || g->hasProofFor(ckey));
46
394698
  return TrustNode(TrustNodeKind::CONFLICT, ckey, g);
47
}
48
49
886059
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g)
50
{
51
1772118
  Node lkey = getLemmaProven(lem);
52
  // if a generator is provided, should confirm that it can prove it
53
886059
  Assert(g == nullptr || g->hasProofFor(lkey));
54
1772118
  return TrustNode(TrustNodeKind::LEMMA, lkey, g);
55
}
56
57
355138
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g)
58
{
59
710276
  Node pekey = getPropExpProven(lit, exp);
60
355138
  Assert(g == nullptr || g->hasProofFor(pekey));
61
710276
  return TrustNode(TrustNodeKind::PROP_EXP, pekey, g);
62
}
63
64
667333
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g)
65
{
66
1334666
  Node rkey = getRewriteProven(n, nr);
67
667333
  Assert(g == nullptr || g->hasProofFor(rkey));
68
1334666
  return TrustNode(TrustNodeKind::REWRITE, rkey, g);
69
}
70
71
TrustNode TrustNode::mkReplaceGenTrustNode(const TrustNode& orig,
72
                                           ProofGenerator* g)
73
{
74
  return TrustNode(orig.getKind(), orig.getProven(), g);
75
}
76
77
2471819
TrustNode TrustNode::null()
78
{
79
2471819
  return TrustNode(TrustNodeKind::INVALID, Node::null());
80
}
81
82
4577698
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g)
83
4577698
    : d_tnk(tnk), d_proven(p), d_gen(g)
84
{
85
  // does not make sense to provide null node with generator
86
4577698
  Assert(!d_proven.isNull() || d_gen == nullptr);
87
4577698
}
88
89
1056620
TrustNodeKind TrustNode::getKind() const { return d_tnk; }
90
91
3457332
Node TrustNode::getNode() const
92
{
93
3457332
  switch (d_tnk)
94
  {
95
    // the node of lemma is the node itself
96
1441107
    case TrustNodeKind::LEMMA: return d_proven;
97
    // the node of the rewrite is the right hand side of EQUAL
98
915454
    case TrustNodeKind::REWRITE: return d_proven[1];
99
    // the node of an explained propagation is the antecendant of an IMPLIES
100
    // the node of a conflict is underneath a NOT
101
1100771
    default: return d_proven[0];
102
  }
103
}
104
105
1325536
Node TrustNode::getProven() const { return d_proven; }
106
107
580084
ProofGenerator* TrustNode::getGenerator() const { return d_gen; }
108
109
4746598
bool TrustNode::isNull() const { return d_proven.isNull(); }
110
111
1251
std::shared_ptr<ProofNode> TrustNode::toProofNode() const
112
{
113
1251
  if (d_gen == nullptr)
114
  {
115
3
    return nullptr;
116
  }
117
1248
  return d_gen->getProofFor(d_proven);
118
}
119
120
197702
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); }
121
122
912179
Node TrustNode::getLemmaProven(Node lem) { return lem; }
123
124
358585
Node TrustNode::getPropExpProven(TNode lit, Node exp)
125
{
126
358585
  return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit);
127
}
128
129
667333
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); }
130
131
243718
void TrustNode::debugCheckClosed(const char* c,
132
                                 const char* ctx,
133
                                 bool reqNullGen)
134
{
135
243718
  pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen);
136
243718
}
137
138
1300
std::string TrustNode::identifyGenerator() const
139
{
140
1300
  if (d_gen == nullptr)
141
  {
142
4
    return "null";
143
  }
144
1296
  return d_gen->identify();
145
}
146
147
std::ostream& operator<<(std::ostream& out, TrustNode n)
148
{
149
  out << "(" << n.getKind() << " " << n.getProven() << " "
150
      << n.identifyGenerator() << ")";
151
  return out;
152
}
153
154
22746
}  // namespace cvc5