GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/trust_substitutions.h Lines: 1 1 100.0 %
Date: 2021-05-22 Branches: 0 2 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Gereon Kremer
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
 * Trust substitutions.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__TRUST_SUBSTITUTIONS_H
19
#define CVC5__THEORY__TRUST_SUBSTITUTIONS_H
20
21
#include "context/cdhashmap.h"
22
#include "context/cdlist.h"
23
#include "context/context.h"
24
#include "expr/lazy_proof.h"
25
#include "expr/proof_node_manager.h"
26
#include "expr/proof_set.h"
27
#include "expr/term_conversion_proof_generator.h"
28
#include "theory/eager_proof_generator.h"
29
#include "theory/substitutions.h"
30
#include "theory/theory_proof_step_buffer.h"
31
#include "theory/trust_node.h"
32
33
namespace cvc5 {
34
namespace theory {
35
36
/**
37
 * A layer on top of SubstitutionMap that tracks proofs.
38
 */
39
38938
class TrustSubstitutionMap : public ProofGenerator
40
{
41
  using NodeUIntMap = context::CDHashMap<Node, size_t>;
42
43
 public:
44
  TrustSubstitutionMap(context::Context* c,
45
                       ProofNodeManager* pnm = nullptr,
46
                       std::string name = "TrustSubstitutionMap",
47
                       PfRule trustId = PfRule::PREPROCESS_LEMMA,
48
                       MethodId ids = MethodId::SB_DEFAULT);
49
  /** Set proof node manager */
50
  void setProofNodeManager(ProofNodeManager* pnm);
51
  /** Gets a reference to the underlying substitution map */
52
  SubstitutionMap& get();
53
  /**
54
   * Add substitution x -> t, where pg can provide a closed proof of (= x t)
55
   * in the remainder of this user context.
56
   */
57
  void addSubstitution(TNode x, TNode t, ProofGenerator* pg = nullptr);
58
  /**
59
   * Add substitution x -> t from a single proof step with rule id, no children
60
   * and arguments args.
61
   */
62
  void addSubstitution(TNode x,
63
                       TNode t,
64
                       PfRule id,
65
                       const std::vector<Node>& children,
66
                       const std::vector<Node>& args);
67
  /**
68
   * Add substitution x -> t, which was derived from the proven field of
69
   * trust node tn. In other words, (= x t) is the solved form of
70
   * tn.getProven(). This method is a helper function for methods (e.g.
71
   * ppAssert) that put literals into solved form. It should be the case
72
   * that (= x t) and tn.getProven() can be shown equivalent by rewriting.
73
   *
74
   * This ensures that we add a substitution with a proof
75
   * based on transforming the tn.getProven() to (= x t) if tn has a
76
   * non-null proof generator; otherwise if tn has no proof generator
77
   * we simply add the substitution.
78
   *
79
   * @return The proof generator that can prove (= x t).
80
   */
81
  ProofGenerator* addSubstitutionSolved(TNode x, TNode t, TrustNode tn);
82
  /**
83
   * Add substitutions from trust substitution map t. This adds all
84
   * substitutions from the map t and carries over its information about proofs.
85
   */
86
  void addSubstitutions(TrustSubstitutionMap& t);
87
  /**
88
   * Apply substitutions in this class to node n. Returns a trust node
89
   * proving n = n*sigma, where the proof generator is provided by this class
90
   * (when proofs are enabled).
91
   */
92
  TrustNode applyTrusted(Node n, bool doRewrite = true);
93
  /** Same as above, without proofs */
94
  Node apply(Node n, bool doRewrite = true);
95
96
  /** Get the proof for formula f */
97
  std::shared_ptr<ProofNode> getProofFor(Node f) override;
98
  /** Identify */
99
  std::string identify() const override;
100
101
 private:
102
  /** Are proofs enabled? */
103
  bool isProofEnabled() const;
104
  /**
105
   * Get the substitution up to index
106
   */
107
  Node getSubstitution(size_t index);
108
  /** The context used here */
109
  context::Context* d_ctx;
110
  /** The substitution map */
111
  SubstitutionMap d_subs;
112
  /** A context-dependent list of trust nodes */
113
  context::CDList<TrustNode> d_tsubs;
114
  /** Theory proof step buffer */
115
  std::unique_ptr<TheoryProofStepBuffer> d_tspb;
116
  /** A lazy proof for substitution steps */
117
  std::unique_ptr<LazyCDProof> d_subsPg;
118
  /** A lazy proof for apply steps */
119
  std::unique_ptr<LazyCDProof> d_applyPg;
120
  /**
121
   * A context-dependent list of LazyCDProof, allocated for internal steps.
122
   */
123
  std::unique_ptr<CDProofSet<LazyCDProof>> d_helperPf;
124
  /** Name for debugging */
125
  std::string d_name;
126
  /**
127
   * The placeholder trusted PfRule identifier for calls to addSubstitution
128
   * that are not given proof generators.
129
   */
130
  PfRule d_trustId;
131
  /** The method id for which form of substitution to apply */
132
  MethodId d_ids;
133
  /**
134
   * Map from solved equalities to the size of d_tsubs at the time they
135
   * were concluded. Notice this is required so that we can reconstruct
136
   * proofs for substitutions after they have become invalidated by later
137
   * calls to addSubstitution. For example, if we call:
138
   *   addSubstitution x -> y
139
   *   addSubstitution z -> w
140
   *   apply f(x), returns f(y)
141
   *   addSubstitution y -> w
142
   * We map (= (f x) (f y)) to index 2, since we only should apply the first
143
   * two substitutions but not the third when asked to prove this equality.
144
   */
145
  NodeUIntMap d_eqtIndex;
146
};
147
148
}  // namespace theory
149
}  // namespace cvc5
150
151
#endif /* CVC5__THEORY__TRUST_SUBSTITUTIONS_H */