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