GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/arith/nl/cad/projections.cpp Lines: 28 42 66.7 %
Date: 2021-05-22 Branches: 31 94 33.0 %

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
1337
void PolyVector::add(const poly::Polynomial& poly, bool assertMain)
31
{
32
3010
  for (const auto& p : poly::square_free_factors(poly))
33
  {
34
1673
    if (poly::is_constant(p)) continue;
35
1414
    if (assertMain)
36
    {
37
40
      Assert(main_variable(poly) == main_variable(p));
38
    }
39
1414
    std::vector<poly::Polynomial>::emplace_back(p);
40
  }
41
1337
}
42
43
224
void PolyVector::reduce()
44
{
45
224
  std::sort(begin(), end());
46
224
  erase(std::unique(begin(), end()), end());
47
224
}
48
49
28
void PolyVector::makeFinestSquareFreeBasis()
50
{
51
66
  for (std::size_t i = 0, n = size(); i < n; ++i)
52
  {
53
50
    for (std::size_t j = i + 1; j < n; ++j)
54
    {
55
24
      Polynomial g = gcd((*this)[i], (*this)[j]);
56
12
      if (!is_constant(g))
57
      {
58
        (*this)[i] = div((*this)[i], g);
59
        (*this)[j] = div((*this)[j], g);
60
        add(g);
61
      }
62
    }
63
  }
64
  auto it = std::remove_if(
65
66
      begin(), end(), [](const Polynomial& p) { return is_constant(p); });
66
28
  erase(it, end());
67
28
  reduce();
68
28
}
69
1045
void PolyVector::pushDownPolys(PolyVector& down, poly::Variable var)
70
{
71
  auto it =
72
1324
      std::remove_if(begin(), end(), [&down, &var](const poly::Polynomial& p) {
73
1194
        if (main_variable(p) == var) return false;
74
130
        down.add(p);
75
130
        return true;
76
1045
      });
77
1045
  erase(it, end());
78
1045
}
79
80
PolyVector projection_mccallum(const std::vector<Polynomial>& polys)
81
{
82
  PolyVector res;
83
84
  for (const auto& p : polys)
85
  {
86
    for (const auto& coeff : coefficients(p))
87
    {
88
      res.add(coeff);
89
    }
90
    res.add(discriminant(p));
91
  }
92
  for (std::size_t i = 0, n = polys.size(); i < n; ++i)
93
  {
94
    for (std::size_t j = i + 1; j < n; ++j)
95
    {
96
      res.add(resultant(polys[i], polys[j]));
97
    }
98
  }
99
100
  res.reduce();
101
  return res;
102
}
103
104
}  // namespace cad
105
}  // namespace nl
106
}  // namespace arith
107
}  // namespace theory
108
}  // namespace cvc5
109
110
#endif