summaryrefslogtreecommitdiff
path: root/src/preprocessing/passes/unconstrained_simplifier.h
blob: 914d450b08274969761fdc822b096e0cf8326212 (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
/******************************************************************************
 * Top contributors (to current version):
 *   Clark Barrett, Andres Noetzli, Andrew Reynolds
 *
 * 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.
 * ****************************************************************************
 *
 * Simplifications based on unconstrained variables
 *
 * This module implements a preprocessing phase which replaces certain
 * "unconstrained" expressions by variables.  Based on Roberto
 * Bruttomesso's PhD thesis.
 */

#include "cvc4_private.h"

#ifndef CVC5__PREPROCESSING_PASSES_UNCONSTRAINED_SIMPLIFIER_H
#define CVC5__PREPROCESSING_PASSES_UNCONSTRAINED_SIMPLIFIER_H

#include <unordered_map>
#include <unordered_set>

#include "expr/node.h"
#include "preprocessing/preprocessing_pass.h"
#include "theory/substitutions.h"
#include "util/statistics_registry.h"

namespace cvc5 {
namespace context {
class Context;
}
namespace preprocessing {
namespace passes {

class UnconstrainedSimplifier : public PreprocessingPass
{
 public:
  UnconstrainedSimplifier(PreprocessingPassContext* preprocContext);
  ~UnconstrainedSimplifier() override;

  PreprocessingPassResult applyInternal(
      AssertionPipeline* assertionsToPreprocess) override;

 private:
  /** number of expressions eliminated due to unconstrained simplification */
  IntStat d_numUnconstrainedElim;

  using TNodeCountMap = std::unordered_map<TNode, unsigned, TNodeHashFunction>;
  using TNodeMap = std::unordered_map<TNode, TNode, TNodeHashFunction>;
  using TNodeSet = std::unordered_set<TNode, TNodeHashFunction>;

  TNodeCountMap d_visited;
  TNodeMap d_visitedOnce;
  TNodeSet d_unconstrained;

  context::Context* d_context;
  theory::SubstitutionMap d_substitutions;

  /**
   * Visit all subterms in assertion. This method throws a LogicException if
   * there is a subterm that is unhandled by this preprocessing pass (e.g. a
   * quantified formula).
   */
  void visitAll(TNode assertion);
  Node newUnconstrainedVar(TypeNode t, TNode var);
  void processUnconstrained();
};

}  // namespace passes
}  // namespace preprocessing
}  // namespace cvc5

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