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