GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/proof/trust_node.cpp Lines: 48 64 75.0 %
Date: 2021-09-16 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
312891
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g)
42
{
43
625782
  Node ckey = getConflictProven(conf);
44
  // if a generator is provided, should confirm that it can prove it
45
312891
  Assert(g == nullptr || g->hasProofFor(ckey));
46
625782
  return TrustNode(TrustNodeKind::CONFLICT, ckey, g);
47
}
48
49
2364897
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g)
50
{
51
4729794
  Node lkey = getLemmaProven(lem);
52
  // if a generator is provided, should confirm that it can prove it
53
2364897
  Assert(g == nullptr || g->hasProofFor(lkey));
54
4729794
  return TrustNode(TrustNodeKind::LEMMA, lkey, g);
55
}
56
57
644448
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g)
58
{
59
1288896
  Node pekey = getPropExpProven(lit, exp);
60
644448
  Assert(g == nullptr || g->hasProofFor(pekey));
61
1288896
  return TrustNode(TrustNodeKind::PROP_EXP, pekey, g);
62
}
63
64
2225308
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g)
65
{
66
4450616
  Node rkey = getRewriteProven(n, nr);
67
2225308
  Assert(g == nullptr || g->hasProofFor(rkey));
68
4450616
  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
4582134
TrustNode TrustNode::null()
78
{
79
4582134
  return TrustNode(TrustNodeKind::INVALID, Node::null());
80
}
81
82
10129678
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g)
83
10129678
    : d_tnk(tnk), d_proven(p), d_gen(g)
84
{
85
  // does not make sense to provide null node with generator
86
10129678
  Assert(!d_proven.isNull() || d_gen == nullptr);
87
10129678
}
88
89
3050944
TrustNodeKind TrustNode::getKind() const { return d_tnk; }
90
91
7765801
Node TrustNode::getNode() const
92
{
93
7765801
  switch (d_tnk)
94
  {
95
    // the node of lemma is the node itself
96
3155765
    case TrustNodeKind::LEMMA: return d_proven;
97
    // the node of the rewrite is the right hand side of EQUAL
98
2656956
    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
1953080
    default: return d_proven[0];
102
  }
103
}
104
105
4438742
Node TrustNode::getProven() const { return d_proven; }
106
107
1877276
ProofGenerator* TrustNode::getGenerator() const { return d_gen; }
108
109
7840204
bool TrustNode::isNull() const { return d_proven.isNull(); }
110
111
115580
std::shared_ptr<ProofNode> TrustNode::toProofNode() const
112
{
113
115580
  if (d_gen == nullptr)
114
  {
115
868
    return nullptr;
116
  }
117
114712
  return d_gen->getProofFor(d_proven);
118
}
119
120
329332
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); }
121
122
2620387
Node TrustNode::getLemmaProven(Node lem) { return lem; }
123
124
703040
Node TrustNode::getPropExpProven(TNode lit, Node exp)
125
{
126
703040
  return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit);
127
}
128
129
2225308
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); }
130
131
629102
void TrustNode::debugCheckClosed(const char* c,
132
                                 const char* ctx,
133
                                 bool reqNullGen)
134
{
135
629102
  pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen);
136
629102
}
137
138
61896
std::string TrustNode::identifyGenerator() const
139
{
140
61896
  if (d_gen == nullptr)
141
  {
142
444
    return "null";
143
  }
144
61452
  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
29577
}  // namespace cvc5