GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/cad/proof_generator.h Lines: 5 5 100.0 %
Date: 2021-11-07 Branches: 1 2 50.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   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
 * Implements the proof generator for CAD.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__ARITH__NL__CAD__PROOF_GENERATOR_H
19
#define CVC5__THEORY__ARITH__NL__CAD__PROOF_GENERATOR_H
20
21
#ifdef CVC5_POLY_IMP
22
23
#include <poly/polyxx.h>
24
25
#include <vector>
26
27
#include "expr/node.h"
28
#include "proof/lazy_tree_proof_generator.h"
29
#include "proof/proof_set.h"
30
#include "theory/arith/nl/cad/cdcac_utils.h"
31
32
namespace cvc5 {
33
34
class ProofGenerator;
35
36
namespace theory {
37
namespace arith {
38
namespace nl {
39
40
struct VariableMapper;
41
42
namespace cad {
43
44
/**
45
 * This class manages the proof creation during a run of the CAD solver.
46
 *
47
 * Though it implements the ProofGenerator interface getProofFor(Node), it only
48
 * gives a proof for a single node.
49
 *
50
 * It uses a LazyTreeProofGenerator internally to manage the tree-based proof
51
 * construction.
52
 */
53
4681
class CADProofGenerator
54
{
55
 public:
56
  friend std::ostream& operator<<(std::ostream& os,
57
                                  const CADProofGenerator& proof);
58
  CADProofGenerator(context::Context* ctx, ProofNodeManager* pnm);
59
60
  /** Start a new proof in this proof generator */
61
  void startNewProof();
62
  /** Start a new recursive call */
63
  void startRecursive();
64
  /** Finish the current recursive call */
65
  void endRecursive(size_t intervalId);
66
  /** Start a new scope, corresponding to a guess in CDCAC */
67
  void startScope();
68
  /** Finish a scope and add the (generalized) sample that was refuted */
69
  void endScope(const std::vector<Node>& args);
70
  /** Return the current proof generator */
71
  ProofGenerator* getProofGenerator() const;
72
73
  /**
74
   * Calls LazyTreeProofGenerator::pruneChildren(f), but decorates the
75
   * predicate such that f only accepts the index.
76
   * @param f A Callable bool(std::size_t)
77
   */
78
  template <typename F>
79
141
  void pruneChildren(F&& f)
80
  {
81
141
    d_current->pruneChildren(
82
1231
        [&f](const detail::TreeProofNode& tpn) { return f(tpn.d_objectId); });
83
141
  }
84
85
  /**
86
   * Add a direct interval conflict as generated in getUnsatIntervals().
87
   * Its meaning is:
88
   *   over the partial assignment a, var is not in interval because p~sc~0
89
   *   and the origin of this is constraint.
90
   *
91
   * @param var The variable for which the interval is excluded
92
   * @param vm A variable mapper between cvc5 and libpoly variables
93
   * @param p The polynomial of the constraint
94
   * @param a The current partial assignment
95
   * @param sc The sign condition of the constraint
96
   * @param interval The concrete interval that is excluded
97
   * @param constraint The assumption that yields p and sc
98
   */
99
  void addDirect(Node var,
100
                 VariableMapper& vm,
101
                 const poly::Polynomial& p,
102
                 const poly::Assignment& a,
103
                 poly::SignCondition& sc,
104
                 const poly::Interval& interval,
105
                 Node constraint,
106
                 size_t intervalId);
107
108
  /**
109
   * Constructs the (generalized) interval that is to be excluded from a
110
   * CACInterval. It should be called after the recursive call to construct the
111
   * generalized sample necessary for endScope().
112
   *
113
   * @param var The variable for which the interval is excluded
114
   * @param i The concrete interval that is excluded
115
   * @param a The current partial assignment
116
   * @param s The sample point that is refuted for var
117
   * @param vm A variable mapper between cvc5 and libpoly variables
118
   */
119
  std::vector<Node> constructCell(Node var,
120
                                  const CACInterval& i,
121
                                  const poly::Assignment& a,
122
                                  const poly::Value& s,
123
                                  VariableMapper& vm);
124
125
 private:
126
  /** The proof node manager used for the proofs */
127
  ProofNodeManager* d_pnm;
128
  /** The list of generated proofs */
129
  CDProofSet<LazyTreeProofGenerator> d_proofs;
130
  /** The current proof */
131
  LazyTreeProofGenerator* d_current;
132
133
  /** Constant false */
134
  Node d_false;
135
  /** Constant zero */
136
  Node d_zero;
137
};
138
139
/**
140
 * Prints the underlying LazyTreeProofGenerator. Please check the documentation
141
 * of std::ostream& operator<<(std::ostream&, const LazyTreeProofGenerator&)
142
 */
143
std::ostream& operator<<(std::ostream& os, const CADProofGenerator& proof);
144
145
}  // namespace cad
146
}  // namespace nl
147
}  // namespace arith
148
}  // namespace theory
149
}  // namespace cvc5
150
151
#endif
152
#endif