GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/cad/proof_generator.h Lines: 5 5 100.0 %
Date: 2021-08-16 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
588
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();
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
3
  void pruneChildren(F&& f)
80
  {
81
3
    d_current->pruneChildren(
82
6
        [&f](std::size_t i, const detail::TreeProofNode& tpn) { return f(i); });
83
3
  }
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
107
  /**
108
   * Constructs the (generalized) interval that is to be excluded from a
109
   * CACInterval. It should be called after the recursive call to construct the
110
   * generalized sample necessary for endScope().
111
   *
112
   * @param var The variable for which the interval is excluded
113
   * @param i The concrete interval that is excluded
114
   * @param a The current partial assignment
115
   * @param s The sample point that is refuted for var
116
   * @param vm A variable mapper between cvc5 and libpoly variables
117
   */
118
  std::vector<Node> constructCell(Node var,
119
                                  const CACInterval& i,
120
                                  const poly::Assignment& a,
121
                                  const poly::Value& s,
122
                                  VariableMapper& vm);
123
124
 private:
125
  /** The proof node manager used for the proofs */
126
  ProofNodeManager* d_pnm;
127
  /** The list of generated proofs */
128
  CDProofSet<LazyTreeProofGenerator> d_proofs;
129
  /** The current proof */
130
  LazyTreeProofGenerator* d_current;
131
132
  /** Constant false */
133
  Node d_false;
134
  /** Constant zero */
135
  Node d_zero;
136
};
137
138
/**
139
 * Prints the underlying LazyTreeProofGenerator. Please check the documentation
140
 * of std::ostream& operator<<(std::ostream&, const LazyTreeProofGenerator&)
141
 */
142
std::ostream& operator<<(std::ostream& os, const CADProofGenerator& proof);
143
144
}  // namespace cad
145
}  // namespace nl
146
}  // namespace arith
147
}  // namespace theory
148
}  // namespace cvc5
149
150
#endif
151
#endif