GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/trust_node.cpp Lines: 48 62 77.4 %
Date: 2021-05-24 Branches: 70 202 34.7 %

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 "theory/trust_node.h"
17
18
#include "expr/proof_ensure_closed.h"
19
#include "expr/proof_generator.h"
20
21
namespace cvc5 {
22
namespace theory {
23
24
const char* toString(TrustNodeKind tnk)
25
{
26
  switch (tnk)
27
  {
28
    case TrustNodeKind::CONFLICT: return "CONFLICT";
29
    case TrustNodeKind::LEMMA: return "LEMMA";
30
    case TrustNodeKind::PROP_EXP: return "PROP_EXP";
31
    case TrustNodeKind::REWRITE: return "REWRITE";
32
    default: return "?";
33
  }
34
}
35
36
std::ostream& operator<<(std::ostream& out, TrustNodeKind tnk)
37
{
38
  out << toString(tnk);
39
  return out;
40
}
41
42
260614
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g)
43
{
44
521228
  Node ckey = getConflictProven(conf);
45
  // if a generator is provided, should confirm that it can prove it
46
260614
  Assert(g == nullptr || g->hasProofFor(ckey));
47
521228
  return TrustNode(TrustNodeKind::CONFLICT, ckey, g);
48
}
49
50
1353500
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g)
51
{
52
2707000
  Node lkey = getLemmaProven(lem);
53
  // if a generator is provided, should confirm that it can prove it
54
1353500
  Assert(g == nullptr || g->hasProofFor(lkey));
55
2707000
  return TrustNode(TrustNodeKind::LEMMA, lkey, g);
56
}
57
58
620772
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g)
59
{
60
1241544
  Node pekey = getPropExpProven(lit, exp);
61
620772
  Assert(g == nullptr || g->hasProofFor(pekey));
62
1241544
  return TrustNode(TrustNodeKind::PROP_EXP, pekey, g);
63
}
64
65
2013851
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g)
66
{
67
4027702
  Node rkey = getRewriteProven(n, nr);
68
2013851
  Assert(g == nullptr || g->hasProofFor(rkey));
69
4027702
  return TrustNode(TrustNodeKind::REWRITE, rkey, g);
70
}
71
72
4287858
TrustNode TrustNode::null()
73
{
74
4287858
  return TrustNode(TrustNodeKind::INVALID, Node::null());
75
}
76
77
8536595
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g)
78
8536595
    : d_tnk(tnk), d_proven(p), d_gen(g)
79
{
80
  // does not make sense to provide null node with generator
81
8536595
  Assert(!d_proven.isNull() || d_gen == nullptr);
82
8536595
}
83
84
2811018
TrustNodeKind TrustNode::getKind() const { return d_tnk; }
85
86
6281065
Node TrustNode::getNode() const
87
{
88
6281065
  switch (d_tnk)
89
  {
90
    // the node of lemma is the node itself
91
2027362
    case TrustNodeKind::LEMMA: return d_proven;
92
    // the node of the rewrite is the right hand side of EQUAL
93
2422149
    case TrustNodeKind::REWRITE: return d_proven[1];
94
    // the node of an explained propagation is the antecendant of an IMPLIES
95
    // the node of a conflict is underneath a NOT
96
1831554
    default: return d_proven[0];
97
  }
98
}
99
100
3714885
Node TrustNode::getProven() const { return d_proven; }
101
102
1764260
ProofGenerator* TrustNode::getGenerator() const { return d_gen; }
103
104
7336815
bool TrustNode::isNull() const { return d_proven.isNull(); }
105
106
106893
std::shared_ptr<ProofNode> TrustNode::toProofNode() const
107
{
108
106893
  if (d_gen == nullptr)
109
  {
110
1001
    return nullptr;
111
  }
112
105892
  return d_gen->getProofFor(d_proven);
113
}
114
115
276156
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); }
116
117
1563163
Node TrustNode::getLemmaProven(Node lem) { return lem; }
118
119
691172
Node TrustNode::getPropExpProven(TNode lit, Node exp)
120
{
121
691172
  return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit);
122
}
123
124
2013851
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); }
125
126
579255
void TrustNode::debugCheckClosed(const char* c,
127
                                 const char* ctx,
128
                                 bool reqNullGen)
129
{
130
579255
  pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen);
131
579255
}
132
133
64400
std::string TrustNode::identifyGenerator() const
134
{
135
64400
  if (d_gen == nullptr)
136
  {
137
1419
    return "null";
138
  }
139
62981
  return d_gen->identify();
140
}
141
142
std::ostream& operator<<(std::ostream& out, TrustNode n)
143
{
144
  out << "(" << n.getKind() << " " << n.getProven() << " "
145
      << n.identifyGenerator() << ")";
146
  return out;
147
}
148
149
}  // namespace theory
150
28191
}  // namespace cvc5