GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/proof/trust_node.cpp Lines: 48 64 75.0 %
Date: 2021-09-07 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
302887
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g)
42
{
43
605774
  Node ckey = getConflictProven(conf);
44
  // if a generator is provided, should confirm that it can prove it
45
302887
  Assert(g == nullptr || g->hasProofFor(ckey));
46
605774
  return TrustNode(TrustNodeKind::CONFLICT, ckey, g);
47
}
48
49
2316499
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g)
50
{
51
4632998
  Node lkey = getLemmaProven(lem);
52
  // if a generator is provided, should confirm that it can prove it
53
2316499
  Assert(g == nullptr || g->hasProofFor(lkey));
54
4632998
  return TrustNode(TrustNodeKind::LEMMA, lkey, g);
55
}
56
57
611101
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g)
58
{
59
1222202
  Node pekey = getPropExpProven(lit, exp);
60
611101
  Assert(g == nullptr || g->hasProofFor(pekey));
61
1222202
  return TrustNode(TrustNodeKind::PROP_EXP, pekey, g);
62
}
63
64
2086511
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g)
65
{
66
4173022
  Node rkey = getRewriteProven(n, nr);
67
2086511
  Assert(g == nullptr || g->hasProofFor(rkey));
68
4173022
  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
4574361
TrustNode TrustNode::null()
78
{
79
4574361
  return TrustNode(TrustNodeKind::INVALID, Node::null());
80
}
81
82
9891359
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g)
83
9891359
    : d_tnk(tnk), d_proven(p), d_gen(g)
84
{
85
  // does not make sense to provide null node with generator
86
9891359
  Assert(!d_proven.isNull() || d_gen == nullptr);
87
9891359
}
88
89
2896955
TrustNodeKind TrustNode::getKind() const { return d_tnk; }
90
91
7488977
Node TrustNode::getNode() const
92
{
93
7488977
  switch (d_tnk)
94
  {
95
    // the node of lemma is the node itself
96
3101162
    case TrustNodeKind::LEMMA: return d_proven;
97
    // the node of the rewrite is the right hand side of EQUAL
98
2518022
    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
1869793
    default: return d_proven[0];
102
  }
103
}
104
105
4290821
Node TrustNode::getProven() const { return d_proven; }
106
107
1823555
ProofGenerator* TrustNode::getGenerator() const { return d_gen; }
108
109
7830247
bool TrustNode::isNull() const { return d_proven.isNull(); }
110
111
114248
std::shared_ptr<ProofNode> TrustNode::toProofNode() const
112
{
113
114248
  if (d_gen == nullptr)
114
  {
115
865
    return nullptr;
116
  }
117
113383
  return d_gen->getProofFor(d_proven);
118
}
119
120
319300
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); }
121
122
2571947
Node TrustNode::getLemmaProven(Node lem) { return lem; }
123
124
669740
Node TrustNode::getPropExpProven(TNode lit, Node exp)
125
{
126
669740
  return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit);
127
}
128
129
2086511
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); }
130
131
618057
void TrustNode::debugCheckClosed(const char* c,
132
                                 const char* ctx,
133
                                 bool reqNullGen)
134
{
135
618057
  pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen);
136
618057
}
137
138
61921
std::string TrustNode::identifyGenerator() const
139
{
140
61921
  if (d_gen == nullptr)
141
  {
142
441
    return "null";
143
  }
144
61480
  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
29502
}  // namespace cvc5