summaryrefslogtreecommitdiff
path: root/src/theory/arith/arith_ite_utils.h
blob: ba7a2347944900afb8965904b8cb16e68bc80b45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/******************************************************************************
 * Top contributors (to current version):
 *   Tim King, Mathias Preiner, Aina Niemetz
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * [[ Add one-line brief description here ]]
 *
 * [[ Add lengthier description here ]]
 * \todo document this file
 */

// Pass 1: label the ite as (constant) or (+ constant variable)

#include "cvc5_private.h"

#ifndef CVC5__THEORY__ARITH__ARITH_ITE_UTILS_H
#define CVC5__THEORY__ARITH__ARITH_ITE_UTILS_H

#include <unordered_map>

#include "context/cdinsert_hashmap.h"
#include "context/cdo.h"
#include "expr/node.h"
#include "util/integer.h"

namespace cvc5 {
namespace preprocessing {
namespace util {
class ContainsTermITEVisitor;
}
}  // namespace preprocessing

namespace theory {

class SubstitutionMap;

namespace arith {

class ArithIteUtils {
  preprocessing::util::ContainsTermITEVisitor& d_contains;
  SubstitutionMap& d_subs;

  typedef std::unordered_map<Node, Node> NodeMap;
  // cache for reduce vars
  NodeMap d_reduceVar; // if reduceVars[n].isNull(), treat reduceVars[n] == n

  // reduceVars[n] = d_constants[n] + d_varParts[n]
  NodeMap d_constants; // d_constants[n] is a constant ite tree
  NodeMap d_varParts; // d_varParts[n] is a polynomial


  NodeMap d_reduceGcd;
  typedef std::unordered_map<Node, Integer> NodeIntegerMap;
  NodeIntegerMap d_gcds;

  Integer d_one;

  context::CDO<unsigned> d_subcount;
  typedef context::CDInsertHashMap<Node, Node> CDNodeMap;
  CDNodeMap d_skolems;

  typedef std::map<Node, std::set<Node> > ImpMap;
  ImpMap d_implies;

  std::vector<Node> d_orBinEqs;

public:
 ArithIteUtils(preprocessing::util::ContainsTermITEVisitor& contains,
               context::Context* userContext,
               SubstitutionMap& subs);
 ~ArithIteUtils();

 //(ite ?v_2 ?v_1 (ite ?v_3 (- ?v_1 128) (- ?v_1 256)))

 /** removes common sums variables sums from term ites. */
 Node reduceVariablesInItes(Node n);

 Node reduceConstantIteByGCD(Node n);

 void clear();

 Node applySubstitutions(TNode f);
 unsigned getSubCount() const;

 void learnSubstitutions(const std::vector<Node>& assertions);

private:
  /* applies this to all children of n and constructs the result */
  Node applyReduceVariablesInItes(Node n);

  const Integer& gcdIte(Node n);
  Node reduceIteConstantIteByGCD_rec(Node n, const Rational& q);
  Node reduceIteConstantIteByGCD(Node n);

  void addSubstitution(TNode f, TNode t);
  Node selectForCmp(Node n) const;

  void collectAssertions(TNode assertion);
  void addImplications(Node x, Node y);
  Node findIteCnd(TNode tb, TNode fb) const;
  bool solveBinOr(TNode binor);

}; /* class ArithIteUtils */

}  // namespace arith
}  // namespace theory
}  // namespace cvc5

#endif /* CVC5__THEORY__ARITH__ARITH_ITE_UTILS_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback