GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/trust_node.cpp Lines: 48 62 77.4 %
Date: 2021-05-21 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
245120
TrustNode TrustNode::mkTrustConflict(Node conf, ProofGenerator* g)
43
{
44
490240
  Node ckey = getConflictProven(conf);
45
  // if a generator is provided, should confirm that it can prove it
46
245120
  Assert(g == nullptr || g->hasProofFor(ckey));
47
490240
  return TrustNode(TrustNodeKind::CONFLICT, ckey, g);
48
}
49
50
1333572
TrustNode TrustNode::mkTrustLemma(Node lem, ProofGenerator* g)
51
{
52
2667144
  Node lkey = getLemmaProven(lem);
53
  // if a generator is provided, should confirm that it can prove it
54
1333572
  Assert(g == nullptr || g->hasProofFor(lkey));
55
2667144
  return TrustNode(TrustNodeKind::LEMMA, lkey, g);
56
}
57
58
594875
TrustNode TrustNode::mkTrustPropExp(TNode lit, Node exp, ProofGenerator* g)
59
{
60
1189750
  Node pekey = getPropExpProven(lit, exp);
61
594875
  Assert(g == nullptr || g->hasProofFor(pekey));
62
1189750
  return TrustNode(TrustNodeKind::PROP_EXP, pekey, g);
63
}
64
65
1976712
TrustNode TrustNode::mkTrustRewrite(TNode n, Node nr, ProofGenerator* g)
66
{
67
3953424
  Node rkey = getRewriteProven(n, nr);
68
1976712
  Assert(g == nullptr || g->hasProofFor(rkey));
69
3953424
  return TrustNode(TrustNodeKind::REWRITE, rkey, g);
70
}
71
72
4170817
TrustNode TrustNode::null()
73
{
74
4170817
  return TrustNode(TrustNodeKind::INVALID, Node::null());
75
}
76
77
8321096
TrustNode::TrustNode(TrustNodeKind tnk, Node p, ProofGenerator* g)
78
8321096
    : d_tnk(tnk), d_proven(p), d_gen(g)
79
{
80
  // does not make sense to provide null node with generator
81
8321096
  Assert(!d_proven.isNull() || d_gen == nullptr);
82
8321096
}
83
84
2737199
TrustNodeKind TrustNode::getKind() const { return d_tnk; }
85
86
6116463
Node TrustNode::getNode() const
87
{
88
6116463
  switch (d_tnk)
89
  {
90
    // the node of lemma is the node itself
91
1990404
    case TrustNodeKind::LEMMA: return d_proven;
92
    // the node of the rewrite is the right hand side of EQUAL
93
2376965
    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
1749094
    default: return d_proven[0];
97
  }
98
}
99
100
3630140
Node TrustNode::getProven() const { return d_proven; }
101
102
1714644
ProofGenerator* TrustNode::getGenerator() const { return d_gen; }
103
104
7170029
bool TrustNode::isNull() const { return d_proven.isNull(); }
105
106
103370
std::shared_ptr<ProofNode> TrustNode::toProofNode() const
107
{
108
103370
  if (d_gen == nullptr)
109
  {
110
747
    return nullptr;
111
  }
112
102623
  return d_gen->getProofFor(d_proven);
113
}
114
115
260708
Node TrustNode::getConflictProven(Node conf) { return conf.notNode(); }
116
117
1543502
Node TrustNode::getLemmaProven(Node lem) { return lem; }
118
119
665444
Node TrustNode::getPropExpProven(TNode lit, Node exp)
120
{
121
665444
  return NodeManager::currentNM()->mkNode(kind::IMPLIES, exp, lit);
122
}
123
124
1976712
Node TrustNode::getRewriteProven(TNode n, Node nr) { return n.eqNode(nr); }
125
126
553237
void TrustNode::debugCheckClosed(const char* c,
127
                                 const char* ctx,
128
                                 bool reqNullGen)
129
{
130
553237
  pfgEnsureClosed(d_proven, d_gen, c, ctx, reqNullGen);
131
553237
}
132
133
64598
std::string TrustNode::identifyGenerator() const
134
{
135
64598
  if (d_gen == nullptr)
136
  {
137
1419
    return "null";
138
  }
139
63179
  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
27735
}  // namespace cvc5