GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/proof/trust_node.cpp Lines: 48 64 75.0 %
Date: 2021-09-15 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
312895
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g)
42
{
43
625790
  Node ckey = getConflictProven(conf);
44
  // if a generator is provided, should confirm that it can prove it
45
312895
  Assert(g == nullptr || g->hasProofFor(ckey));
46
625790
  return TrustNode(TrustNodeKind::CONFLICT, ckey, g);
47
}
48
49
2364903
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g)
50
{
51
4729806
  Node lkey = getLemmaProven(lem);
52
  // if a generator is provided, should confirm that it can prove it
53
2364903
  Assert(g == nullptr || g->hasProofFor(lkey));
54
4729806
  return TrustNode(TrustNodeKind::LEMMA, lkey, g);
55
}
56
57
644653
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g)
58
{
59
1289306
  Node pekey = getPropExpProven(lit, exp);
60
644653
  Assert(g == nullptr || g->hasProofFor(pekey));
61
1289306
  return TrustNode(TrustNodeKind::PROP_EXP, pekey, g);
62
}
63
64
2225320
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g)
65
{
66
4450640
  Node rkey = getRewriteProven(n, nr);
67
2225320
  Assert(g == nullptr || g->hasProofFor(rkey));
68
4450640
  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
4582192
TrustNode TrustNode::null()
78
{
79
4582192
  return TrustNode(TrustNodeKind::INVALID, Node::null());
80
}
81
82
10129963
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g)
83
10129963
    : d_tnk(tnk), d_proven(p), d_gen(g)
84
{
85
  // does not make sense to provide null node with generator
86
10129963
  Assert(!d_proven.isNull() || d_gen == nullptr);
87
10129963
}
88
89
3051158
TrustNodeKind TrustNode::getKind() const { return d_tnk; }
90
91
7766295
Node TrustNode::getNode() const
92
{
93
7766295
  switch (d_tnk)
94
  {
95
    // the node of lemma is the node itself
96
3155773
    case TrustNodeKind::LEMMA: return d_proven;
97
    // the node of the rewrite is the right hand side of EQUAL
98
2656972
    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
1953550
    default: return d_proven[0];
102
  }
103
}
104
105
4438972
Node TrustNode::getProven() const { return d_proven; }
106
107
1877370
ProofGenerator* TrustNode::getGenerator() const { return d_gen; }
108
109
7840280
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
329337
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); }
121
122
2620393
Node TrustNode::getLemmaProven(Node lem) { return lem; }
123
124
703314
Node TrustNode::getPropExpProven(TNode lit, Node exp)
125
{
126
703314
  return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit);
127
}
128
129
2225320
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); }
130
131
629183
void TrustNode::debugCheckClosed(const char* c,
132
                                 const char* ctx,
133
                                 bool reqNullGen)
134
{
135
629183
  pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen);
136
629183
}
137
138
61900
std::string TrustNode::identifyGenerator() const
139
{
140
61900
  if (d_gen == nullptr)
141
  {
142
444
    return "null";
143
  }
144
61456
  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