GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/fp/theory_fp.h Lines: 6 7 85.7 %
Date: 2021-05-22 Branches: 0 2 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Martin Brain, Aina Niemetz
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
 * Theory of floating-point arithmetic.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__FP__THEORY_FP_H
19
#define CVC5__THEORY__FP__THEORY_FP_H
20
21
#include <string>
22
#include <utility>
23
24
#include "context/cdhashset.h"
25
#include "context/cdo.h"
26
#include "theory/fp/theory_fp_rewriter.h"
27
#include "theory/theory.h"
28
#include "theory/theory_inference_manager.h"
29
#include "theory/theory_state.h"
30
#include "theory/uf/equality_engine.h"
31
32
namespace cvc5 {
33
namespace theory {
34
namespace fp {
35
36
class FpConverter;
37
38
18920
class TheoryFp : public Theory
39
{
40
 public:
41
  /** Constructs a new instance of TheoryFp w.r.t. the provided contexts. */
42
  TheoryFp(context::Context* c,
43
           context::UserContext* u,
44
           OutputChannel& out,
45
           Valuation valuation,
46
           const LogicInfo& logicInfo,
47
           ProofNodeManager* pnm = nullptr);
48
49
  //--------------------------------- initialization
50
  /** Get the official theory rewriter of this theory. */
51
  TheoryRewriter* getTheoryRewriter() override;
52
  /** get the proof checker of this theory */
53
  ProofRuleChecker* getProofChecker() override;
54
  /**
55
   * Returns true if we need an equality engine. If so, we initialize the
56
   * information regarding how it should be setup. For details, see the
57
   * documentation in Theory::needsEqualityEngine.
58
   */
59
  bool needsEqualityEngine(EeSetupInfo& esi) override;
60
  /** Finish initialization. */
61
  void finishInit() override;
62
  //--------------------------------- end initialization
63
64
  void preRegisterTerm(TNode node) override;
65
  TrustNode ppRewrite(TNode node, std::vector<SkolemLemma>& lems) override;
66
67
  //--------------------------------- standard check
68
  /** Do we need a check call at last call effort? */
69
  bool needsCheckLastEffort() override;
70
  /** Post-check, called after the fact queue of the theory is processed. */
71
  void postCheck(Effort level) override;
72
  /** Pre-notify fact, return true if processed. */
73
  bool preNotifyFact(TNode atom,
74
                     bool pol,
75
                     TNode fact,
76
                     bool isPrereg,
77
                     bool isInternal) override;
78
  //--------------------------------- end standard check
79
80
  Node getModelValue(TNode var) override;
81
  bool collectModelInfo(TheoryModel* m,
82
                        const std::set<Node>& relevantTerms) override;
83
  /**
84
   * Collect model values in m based on the relevant terms given by
85
   * relevantTerms.
86
   */
87
  bool collectModelValues(TheoryModel* m,
88
                          const std::set<Node>& relevantTerms) override;
89
90
  std::string identify() const override { return "THEORY_FP"; }
91
92
  TrustNode explain(TNode n) override;
93
94
 protected:
95
  using ConversionAbstractionMap = context::CDHashMap<TypeNode, Node>;
96
  using AbstractionMap = context::CDHashMap<Node, Node>;
97
98
  /** Equality engine. */
99
9460
  class NotifyClass : public eq::EqualityEngineNotify {
100
   protected:
101
    TheoryFp& d_theorySolver;
102
103
   public:
104
9460
    NotifyClass(TheoryFp& solver) : d_theorySolver(solver) {}
105
    bool eqNotifyTriggerPredicate(TNode predicate, bool value) override;
106
    bool eqNotifyTriggerTermEquality(TheoryId tag,
107
                                     TNode t1,
108
                                     TNode t2,
109
                                     bool value) override;
110
    void eqNotifyConstantTermMerge(TNode t1, TNode t2) override;
111
2648
    void eqNotifyNewClass(TNode t) override {}
112
1295
    void eqNotifyMerge(TNode t1, TNode t2) override {}
113
477
    void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override {}
114
  };
115
  friend NotifyClass;
116
117
  NotifyClass d_notification;
118
119
  /** General utility. */
120
  void registerTerm(TNode node);
121
  bool isRegistered(TNode node);
122
123
  context::CDHashSet<Node> d_registeredTerms;
124
125
  /** The word-blaster. Translates FP -> BV. */
126
  std::unique_ptr<FpConverter> d_conv;
127
128
  bool d_expansionRequested;
129
130
  void convertAndEquateTerm(TNode node);
131
132
  /** Interaction with the rest of the solver **/
133
  void handleLemma(Node node, InferenceId id);
134
  /**
135
   * Called when literal node is inferred by the equality engine. This
136
   * propagates node on the output channel.
137
   */
138
  bool propagateLit(TNode node);
139
  /**
140
   * Called when two constants t1 and t2 merge in the equality engine. This
141
   * sends a conflict on the output channel.
142
   */
143
  void conflictEqConstantMerge(TNode t1, TNode t2);
144
145
  bool refineAbstraction(TheoryModel* m, TNode abstract, TNode concrete);
146
147
  Node abstractRealToFloat(Node);
148
  Node abstractFloatToReal(Node);
149
150
 private:
151
152
  ConversionAbstractionMap d_realToFloatMap;
153
  ConversionAbstractionMap d_floatToRealMap;
154
  AbstractionMap d_abstractionMap;  // abstract -> original
155
156
  /** The theory rewriter for this theory. */
157
  TheoryFpRewriter d_rewriter;
158
  /** A (default) theory state object */
159
  TheoryState d_state;
160
  /** A (default) inference manager */
161
  TheoryInferenceManager d_im;
162
}; /* class TheoryFp */
163
164
}  // namespace fp
165
}  // namespace theory
166
}  // namespace cvc5
167
168
#endif /* CVC5__THEORY__FP__THEORY_FP_H */