GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/operator_elim.h Lines: 1 1 100.0 %
Date: 2021-08-01 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Martin Brain, 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
 * Operator elimination for arithmetic.
14
 */
15
16
#pragma once
17
18
#include <map>
19
20
#include "expr/node.h"
21
#include "expr/skolem_manager.h"
22
#include "proof/eager_proof_generator.h"
23
#include "theory/logic_info.h"
24
#include "theory/skolem_lemma.h"
25
26
namespace cvc5 {
27
28
class TConvProofGenerator;
29
30
namespace theory {
31
namespace arith {
32
33
class OperatorElim : public EagerProofGenerator
34
{
35
 public:
36
  OperatorElim(ProofNodeManager* pnm, const LogicInfo& info);
37
9838
  ~OperatorElim() {}
38
  /** Eliminate operators in this term.
39
   *
40
   * Eliminate operators in term n. If n has top symbol that is not a core
41
   * one (including division, int division, mod, to_int, is_int, syntactic sugar
42
   * transcendental functions), then we replace it by a form that eliminates
43
   * that operator. This may involve the introduction of witness terms.
44
   *
45
   * @param n The node to eliminate
46
   * @param lems The lemmas that we wish to add concerning n. It is the
47
   * responsbility of the caller to process these lemmas.
48
   * @param partialOnly Whether we only want to eliminate partial operators.
49
   * @return the trust node of kind REWRITE encapsulating the eliminated form
50
   * of n and a proof generator for proving this equivalence.
51
   */
52
  TrustNode eliminate(Node n,
53
                      std::vector<SkolemLemma>& lems,
54
                      bool partialOnly = false);
55
  /**
56
   * Get axiom for term n. This returns the axiom that this class uses to
57
   * eliminate the term n, which is determined by its top-most symbol.
58
   */
59
  static Node getAxiomFor(Node n);
60
61
 private:
62
  /** Logic info of the owner of this class */
63
  const LogicInfo& d_info;
64
  /**
65
   * Function symbols used to implement:
66
   * (1) Uninterpreted division-by-zero semantics.  Needed to deal with partial
67
   * division function ("/"),
68
   * (2) Uninterpreted int-division-by-zero semantics.  Needed to deal with
69
   * partial function "div",
70
   * (3) Uninterpreted mod-zero semantics.  Needed to deal with partial
71
   * function "mod".
72
   *
73
   * If the option arithNoPartialFun() is enabled, then the range of this map
74
   * stores Skolem constants instead of Skolem functions, meaning that the
75
   * function-ness of e.g. division by zero is ignored.
76
   *
77
   * Note that this cache is used only for performance reasons. Conceptually,
78
   * these skolem functions actually live in SkolemManager.
79
   */
80
  std::map<SkolemFunId, Node> d_arithSkolem;
81
  /**
82
   * Eliminate operators in term n. If n has top symbol that is not a core
83
   * one (including division, int division, mod, to_int, is_int, syntactic sugar
84
   * transcendental functions), then we replace it by a form that eliminates
85
   * that operator. This may involve the introduction of witness terms.
86
   *
87
   * One exception to the above rule is that we may leave certain applications
88
   * like (/ 4 1) unchanged, since replacing this by 4 changes its type from
89
   * real to int. This is important for some subtyping issues during
90
   * expandDefinition. Moreover, applications like this can be eliminated
91
   * trivially later by rewriting.
92
   *
93
   * This method is called both during expandDefinition and during ppRewrite.
94
   *
95
   * @param n The node to eliminate operators from.
96
   * @return The (single step) eliminated form of n.
97
   */
98
  Node eliminateOperators(Node n,
99
                          std::vector<SkolemLemma>& lems,
100
                          TConvProofGenerator* tg,
101
                          bool partialOnly);
102
  /** get arithmetic skolem
103
   *
104
   * Returns the Skolem in the above map for the given id, creating it if it
105
   * does not already exist.
106
   */
107
  Node getArithSkolem(SkolemFunId asi);
108
  /**
109
   * Make the witness term, which creates a witness term based on the skolem
110
   * manager with this class as a proof generator.
111
   */
112
  Node mkWitnessTerm(Node v,
113
                     Node pred,
114
                     const std::string& prefix,
115
                     const std::string& comment,
116
                     std::vector<SkolemLemma>& lems);
117
  /** get arithmetic skolem application
118
   *
119
   * By default, this returns the term f( n ), where f is the Skolem function
120
   * for the identifier asi.
121
   *
122
   * If the option arithNoPartialFun is enabled, this returns f, where f is
123
   * the Skolem constant for the identifier asi.
124
   */
125
  Node getArithSkolemApp(Node n, SkolemFunId asi);
126
127
  /**
128
   * Called when a non-linear term n is given to this class. Throw an exception
129
   * if the logic is linear.
130
   */
131
  void checkNonLinearLogic(Node term);
132
};
133
134
}  // namespace arith
135
}  // namespace theory
136
}  // namespace cvc5