GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/trust_node.cpp Lines: 48 62 77.4 %
Date: 2021-05-22 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
263941
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g)
43
{
44
527882
  Node ckey = getConflictProven(conf);
45
  // if a generator is provided, should confirm that it can prove it
46
263941
  Assert(g == nullptr || g->hasProofFor(ckey));
47
527882
  return TrustNode(TrustNodeKind::CONFLICT, ckey, g);
48
}
49
50
1356117
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g)
51
{
52
2712234
  Node lkey = getLemmaProven(lem);
53
  // if a generator is provided, should confirm that it can prove it
54
1356117
  Assert(g == nullptr || g->hasProofFor(lkey));
55
2712234
  return TrustNode(TrustNodeKind::LEMMA, lkey, g);
56
}
57
58
632115
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g)
59
{
60
1264230
  Node pekey = getPropExpProven(lit, exp);
61
632115
  Assert(g == nullptr || g->hasProofFor(pekey));
62
1264230
  return TrustNode(TrustNodeKind::PROP_EXP, pekey, g);
63
}
64
65
2019511
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g)
66
{
67
4039022
  Node rkey = getRewriteProven(n, nr);
68
2019511
  Assert(g == nullptr || g->hasProofFor(rkey));
69
4039022
  return TrustNode(TrustNodeKind::REWRITE, rkey, g);
70
}
71
72
4296213
TrustNode TrustNode::null()
73
{
74
4296213
  return TrustNode(TrustNodeKind::INVALID, Node::null());
75
}
76
77
8567897
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g)
78
8567897
    : d_tnk(tnk), d_proven(p), d_gen(g)
79
{
80
  // does not make sense to provide null node with generator
81
8567897
  Assert(!d_proven.isNull() || d_gen == nullptr);
82
8567897
}
83
84
2821555
TrustNodeKind TrustNode::getKind() const { return d_tnk; }
85
86
6323939
Node TrustNode::getNode() const
87
{
88
6323939
  switch (d_tnk)
89
  {
90
    // the node of lemma is the node itself
91
2034080
    case TrustNodeKind::LEMMA: return d_proven;
92
    // the node of the rewrite is the right hand side of EQUAL
93
2429499
    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
1860360
    default: return d_proven[0];
97
  }
98
}
99
100
3724335
Node TrustNode::getProven() const { return d_proven; }
101
102
1769114
ProofGenerator* TrustNode::getGenerator() const { return d_gen; }
103
104
7358298
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
279483
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); }
116
117
1565780
Node TrustNode::getLemmaProven(Node lem) { return lem; }
118
119
702515
Node TrustNode::getPropExpProven(TNode lit, Node exp)
120
{
121
702515
  return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit);
122
}
123
124
2019511
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); }
125
126
582732
void TrustNode::debugCheckClosed(const char* c,
127
                                 const char* ctx,
128
                                 bool reqNullGen)
129
{
130
582732
  pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen);
131
582732
}
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
28194
}  // namespace cvc5