GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/cad/projections.cpp Lines: 42 42 100.0 %
Date: 2021-09-15 Branches: 52 94 55.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   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
 * Implements utilities for CAD projection operators.
14
 */
15
16
#include "theory/arith/nl/cad/projections.h"
17
18
#ifdef CVC5_POLY_IMP
19
20
#include "base/check.h"
21
22
namespace cvc5 {
23
namespace theory {
24
namespace arith {
25
namespace nl {
26
namespace cad {
27
28
using namespace poly;
29
30
2410
void PolyVector::add(const poly::Polynomial& poly, bool assertMain)
31
{
32
5231
  for (const auto& p : poly::square_free_factors(poly))
33
  {
34
2821
    if (poly::is_constant(p)) continue;
35
2463
    if (assertMain)
36
    {
37
122
      Assert(main_variable(poly) == main_variable(p));
38
    }
39
2463
    std::vector<poly::Polynomial>::emplace_back(p);
40
  }
41
2410
}
42
43
690
void PolyVector::reduce()
44
{
45
690
  std::sort(begin(), end());
46
690
  erase(std::unique(begin(), end()), end());
47
690
}
48
49
98
void PolyVector::makeFinestSquareFreeBasis()
50
{
51
244
  for (std::size_t i = 0, n = size(); i < n; ++i)
52
  {
53
198
    for (std::size_t j = i + 1; j < n; ++j)
54
    {
55
104
      Polynomial g = gcd((*this)[i], (*this)[j]);
56
52
      if (!is_constant(g))
57
      {
58
4
        (*this)[i] = div((*this)[i], g);
59
4
        (*this)[j] = div((*this)[j], g);
60
4
        add(g);
61
      }
62
    }
63
  }
64
  auto it = std::remove_if(
65
248
      begin(), end(), [](const Polynomial& p) { return is_constant(p); });
66
98
  erase(it, end());
67
98
  reduce();
68
98
}
69
1636
void PolyVector::pushDownPolys(PolyVector& down, poly::Variable var)
70
{
71
  auto it =
72
2131
      std::remove_if(begin(), end(), [&down, &var](const poly::Polynomial& p) {
73
1901
        if (main_variable(p) == var) return false;
74
230
        down.add(p);
75
230
        return true;
76
1636
      });
77
1636
  erase(it, end());
78
1636
}
79
80
2
PolyVector projectionMcCallum(const std::vector<Polynomial>& polys)
81
{
82
2
  PolyVector res;
83
84
6
  for (const auto& p : polys)
85
  {
86
8
    for (const auto& coeff : coefficients(p))
87
    {
88
4
      res.add(coeff);
89
    }
90
4
    res.add(discriminant(p));
91
  }
92
6
  for (std::size_t i = 0, n = polys.size(); i < n; ++i)
93
  {
94
6
    for (std::size_t j = i + 1; j < n; ++j)
95
    {
96
2
      res.add(resultant(polys[i], polys[j]));
97
    }
98
  }
99
100
2
  res.reduce();
101
2
  return res;
102
}
103
104
}  // namespace cad
105
}  // namespace nl
106
}  // namespace arith
107
}  // namespace theory
108
}  // namespace cvc5
109
110
#endif