Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Implements utilities for coverings projection operators. 11 : : */ 12 : : 13 : : #include "theory/arith/nl/coverings/projections.h" 14 : : 15 : : #ifdef CVC5_POLY_IMP 16 : : 17 : : #include "base/check.h" 18 : : 19 : : namespace cvc5::internal { 20 : : namespace theory { 21 : : namespace arith { 22 : : namespace nl { 23 : : namespace coverings { 24 : : 25 : : using namespace poly; 26 : : 27 : 70221 : void PolyVector::add(const poly::Polynomial& poly, bool assertMain) 28 : : { 29 [ + + ]: 158575 : for (const auto& p : poly::square_free_factors(poly)) 30 : : { 31 [ + + ]: 88354 : if (poly::is_constant(p)) continue; 32 [ + + ]: 81865 : if (assertMain) 33 : : { 34 [ - + ][ - + ]: 2695 : Assert(main_variable(poly) == main_variable(p)); [ - - ] 35 : : } 36 : 81865 : std::vector<poly::Polynomial>::emplace_back(p); 37 : 70221 : } 38 : 70221 : } 39 : : 40 : 14579 : void PolyVector::reduce() 41 : : { 42 : 14579 : std::sort(begin(), end()); 43 : 14579 : erase(std::unique(begin(), end()), end()); 44 : 14579 : } 45 : : 46 : 2102 : void PolyVector::makeFinestSquareFreeBasis() 47 : : { 48 [ + + ]: 11806 : for (std::size_t i = 0, n = size(); i < n; ++i) 49 : : { 50 [ + + ]: 30630 : for (std::size_t j = i + 1; j < n; ++j) 51 : : { 52 : 20926 : Polynomial g = gcd((*this)[i], (*this)[j]); 53 [ + + ]: 20926 : if (!is_constant(g)) 54 : : { 55 : 42 : (*this)[i] = div((*this)[i], g); 56 : 42 : (*this)[j] = div((*this)[j], g); 57 : 42 : add(g); 58 : : } 59 : 20926 : } 60 : : } 61 : 2102 : auto it = std::remove_if( 62 : 9746 : begin(), end(), [](const Polynomial& p) { return is_constant(p); }); 63 : 2102 : erase(it, end()); 64 : 2102 : reduce(); 65 : 2102 : } 66 : 14745 : void PolyVector::pushDownPolys(PolyVector& down, poly::Variable var) 67 : : { 68 : : auto it = 69 : 14745 : std::remove_if(begin(), end(), [&down, &var](const poly::Polynomial& p) { 70 [ + + ]: 38725 : if (main_variable(p) == var) return false; 71 : 23548 : down.add(p); 72 : 23548 : return true; 73 : : }); 74 : 14745 : erase(it, end()); 75 : 14745 : } 76 : : 77 : 1 : PolyVector projectionMcCallum(const std::vector<Polynomial>& polys) 78 : : { 79 : 1 : PolyVector res; 80 : : 81 [ + + ]: 3 : for (const auto& p : polys) 82 : : { 83 [ + + ]: 4 : for (const auto& coeff : coefficients(p)) 84 : : { 85 : 2 : res.add(coeff); 86 : 2 : } 87 : 2 : res.add(discriminant(p)); 88 : : } 89 [ + + ]: 3 : for (std::size_t i = 0, n = polys.size(); i < n; ++i) 90 : : { 91 [ + + ]: 3 : for (std::size_t j = i + 1; j < n; ++j) 92 : : { 93 : 1 : res.add(resultant(polys[i], polys[j])); 94 : : } 95 : : } 96 : : 97 : 1 : res.reduce(); 98 : 1 : return res; 99 : 0 : } 100 : : 101 : : } // namespace coverings 102 : : } // namespace nl 103 : : } // namespace arith 104 : : } // namespace theory 105 : : } // namespace cvc5::internal 106 : : 107 : : #endif