GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/fp/theory_fp.h Lines: 6 7 85.7 %
Date: 2021-09-16 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 FpWordBlaster;
37
38
19878
class TheoryFp : public Theory
39
{
40
 public:
41
  /** Constructs a new instance of TheoryFp w.r.t. the provided contexts. */
42
  TheoryFp(Env& env, OutputChannel& out, Valuation valuation);
43
44
  //--------------------------------- initialization
45
  /** Get the official theory rewriter of this theory. */
46
  TheoryRewriter* getTheoryRewriter() override;
47
  /** get the proof checker of this theory */
48
  ProofRuleChecker* getProofChecker() override;
49
  /**
50
   * Returns true if we need an equality engine. If so, we initialize the
51
   * information regarding how it should be setup. For details, see the
52
   * documentation in Theory::needsEqualityEngine.
53
   */
54
  bool needsEqualityEngine(EeSetupInfo& esi) override;
55
  /** Finish initialization. */
56
  void finishInit() override;
57
  //--------------------------------- end initialization
58
59
  void preRegisterTerm(TNode node) override;
60
  TrustNode ppRewrite(TNode node, std::vector<SkolemLemma>& lems) override;
61
62
  //--------------------------------- standard check
63
  /** Do we need a check call at last call effort? */
64
  bool needsCheckLastEffort() override;
65
  /** Post-check, called after the fact queue of the theory is processed. */
66
  void postCheck(Effort level) override;
67
  /** Pre-notify fact, return true if processed. */
68
  bool preNotifyFact(TNode atom,
69
                     bool pol,
70
                     TNode fact,
71
                     bool isPrereg,
72
                     bool isInternal) override;
73
  //--------------------------------- end standard check
74
75
  Node getModelValue(TNode var) override;
76
  bool collectModelInfo(TheoryModel* m,
77
                        const std::set<Node>& relevantTerms) override;
78
  /**
79
   * Collect model values in m based on the relevant terms given by
80
   * relevantTerms.
81
   */
82
  bool collectModelValues(TheoryModel* m,
83
                          const std::set<Node>& relevantTerms) override;
84
85
  std::string identify() const override { return "THEORY_FP"; }
86
87
  TrustNode explain(TNode n) override;
88
89
 protected:
90
  using ConversionAbstractionMap = context::CDHashMap<TypeNode, Node>;
91
  using AbstractionMap = context::CDHashMap<Node, Node>;
92
93
  /** Equality engine. */
94
9939
  class NotifyClass : public eq::EqualityEngineNotify {
95
   protected:
96
    TheoryFp& d_theorySolver;
97
98
   public:
99
9942
    NotifyClass(TheoryFp& solver) : d_theorySolver(solver) {}
100
    bool eqNotifyTriggerPredicate(TNode predicate, bool value) override;
101
    bool eqNotifyTriggerTermEquality(TheoryId tag,
102
                                     TNode t1,
103
                                     TNode t2,
104
                                     bool value) override;
105
    void eqNotifyConstantTermMerge(TNode t1, TNode t2) override;
106
7046
    void eqNotifyNewClass(TNode t) override {}
107
5678
    void eqNotifyMerge(TNode t1, TNode t2) override {}
108
4519
    void eqNotifyDisequal(TNode t1, TNode t2, TNode reason) override {}
109
  };
110
  friend NotifyClass;
111
112
  void notifySharedTerm(TNode n) override;
113
114
  NotifyClass d_notification;
115
116
  /** General utility. */
117
  void registerTerm(TNode node);
118
  bool isRegistered(TNode node);
119
120
  context::CDHashSet<Node> d_registeredTerms;
121
122
  /** The word-blaster. Translates FP -> BV. */
123
  std::unique_ptr<FpWordBlaster> d_wordBlaster;
124
125
  bool d_expansionRequested;
126
127
  void wordBlastAndEquateTerm(TNode node);
128
129
  /** Interaction with the rest of the solver **/
130
  void handleLemma(Node node, InferenceId id);
131
  /**
132
   * Called when literal node is inferred by the equality engine. This
133
   * propagates node on the output channel.
134
   */
135
  bool propagateLit(TNode node);
136
  /**
137
   * Called when two constants t1 and t2 merge in the equality engine. This
138
   * sends a conflict on the output channel.
139
   */
140
  void conflictEqConstantMerge(TNode t1, TNode t2);
141
142
  bool refineAbstraction(TheoryModel* m, TNode abstract, TNode concrete);
143
144
  Node abstractRealToFloat(Node);
145
  Node abstractFloatToReal(Node);
146
147
 private:
148
  ConversionAbstractionMap d_realToFloatMap;
149
  ConversionAbstractionMap d_floatToRealMap;
150
  AbstractionMap d_abstractionMap;  // abstract -> original
151
152
  /** The theory rewriter for this theory. */
153
  TheoryFpRewriter d_rewriter;
154
  /** A (default) theory state object. */
155
  TheoryState d_state;
156
  /** A (default) inference manager. */
157
  TheoryInferenceManager d_im;
158
  /** Cache of word-blasted facts. */
159
  context::CDHashSet<Node> d_wbFactsCache;
160
161
  /** True constant. */
162
  Node d_true;
163
};
164
165
}  // namespace fp
166
}  // namespace theory
167
}  // namespace cvc5
168
169
#endif /* CVC5__THEORY__FP__THEORY_FP_H */