GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/preprocessing/passes/bv_gauss.h Lines: 1 1 100.0 %
Date: 2021-05-24 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Aina Niemetz, Mathias Preiner, Andres Noetzli
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
 * Gaussian Elimination preprocessing pass.
14
 *
15
 * Simplify a given equation system modulo a (prime) number via Gaussian
16
 * Elimination if possible.
17
 */
18
19
#include "cvc5_private.h"
20
21
#ifndef CVC5__PREPROCESSING__PASSES__BV_GAUSS_ELIM_H
22
#define CVC5__PREPROCESSING__PASSES__BV_GAUSS_ELIM_H
23
24
#include "expr/node.h"
25
#include "preprocessing/preprocessing_pass.h"
26
27
namespace cvc5 {
28
namespace preprocessing {
29
namespace passes {
30
31
18924
class BVGauss : public PreprocessingPass
32
{
33
 public:
34
  BVGauss(PreprocessingPassContext* preprocContext,
35
          const std::string& name = "bv-gauss");
36
37
 protected:
38
  /**
39
   * Apply Gaussian Elimination on (possibly multiple) set(s) of equations
40
   * modulo some (prime) number given as bit-vector equations.
41
   *
42
   * Note that these sets of equations do not have to be modulo some prime
43
   * but can be modulo any arbitrary number. However, GE is guaranteed to
44
   * succeed modulo a prime number, which is not necessarily the case if a
45
   * given set of equations is modulo a non-prime number.
46
   */
47
  PreprocessingPassResult applyInternal(
48
      AssertionPipeline* assertionsToPreprocess) override;
49
50
 private:
51
  /* Note: The following functionality is only exposed for unit testing in
52
   * pass_bv_gauss_white.h. */
53
54
  /**
55
   *  Represents the result of Gaussian Elimination where the solution
56
   *  of the given equation system is
57
   *
58
   *   INVALID ... i.e., NOT of the form c1*x1 + c2*x2 + ... % p = b,
59
   *               where ci, b and p are
60
   *                 - bit-vector constants
61
   *                 - extracts or zero extensions on bit-vector constants
62
   *                 - of arbitrary nesting level
63
   *               and p is co-prime to all bit-vector constants for which
64
   *               a multiplicative inverse has to be computed.
65
   *
66
   *   UNIQUE  ... determined for all unknowns, e.g., x = 4
67
   *
68
   *   PARTIAL ... e.g., x = 4 - 2z
69
   *
70
   *   NONE    ... no solution
71
   *
72
   *   Given a matrix A representing an equation system, the resulting
73
   *   matrix B after applying GE represents, e.g.:
74
   *
75
   *   B = 1 0 0 2 <-    UNIQUE
76
   *       0 1 0 3 <-
77
   *       0 0 1 1 <-
78
   *
79
   *   B = 1 0 2 4 <-    PARTIAL
80
   *       0 1 3 2 <-
81
   *       0 0 1 1
82
   *
83
   *   B = 1 0 0 1       NONE
84
   *       0 1 1 2
85
   *       0 0 0 2 <-
86
   */
87
  enum class Result
88
  {
89
    INVALID,
90
    UNIQUE,
91
    PARTIAL,
92
    NONE
93
  };
94
95
  static Result gaussElim(Integer prime,
96
                          std::vector<Integer>& rhs,
97
                          std::vector<std::vector<Integer>>& lhs);
98
99
  static Result gaussElimRewriteForUrem(const std::vector<Node>& equations,
100
                                        std::unordered_map<Node, Node>& res);
101
102
  static unsigned getMinBwExpr(Node expr);
103
};
104
105
}  // namespace passes
106
}  // namespace preprocessing
107
}  // namespace cvc5
108
109
#endif