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 : : * CoCoA utilities 11 : : */ 12 : : 13 : : #ifdef CVC5_USE_COCOA 14 : : 15 : : #include "cvc5_private.h" 16 : : 17 : : #ifndef CVC5__THEORY__FF__COCOA_UTIL_H 18 : : #define CVC5__THEORY__FF__COCOA_UTIL_H 19 : : 20 : : // external includes 21 : : #include <CoCoA/BigInt.H> 22 : : #include <CoCoA/ring.H> 23 : : 24 : : // std includes 25 : : #include <optional> 26 : : #include <sstream> 27 : : #include <vector> 28 : : 29 : : // internal includes 30 : : #include "theory/ff/util.h" 31 : : #include "util/finite_field_value.h" 32 : : #include "util/integer.h" 33 : : #include "util/resource_manager.h" 34 : : 35 : : namespace cvc5::internal { 36 : : namespace theory { 37 : : namespace ff { 38 : : 39 : : /** Type definitions. */ 40 : : 41 : : /** A polynomial. (note: C++/Cocoa doesn't distinguish this from Scalar) */ 42 : : using Poly = CoCoA::RingElem; 43 : : /** A coefficient. (note: C++/Cocoa doesn't distinguish this from Poly) */ 44 : : using Scalar = CoCoA::RingElem; 45 : : /** A list of polynomials. */ 46 : : using Polys = std::vector<Poly>; 47 : : /** A partial input (point/vector with optional entries) to a polynomial */ 48 : : using PartialPoint = std::vector<std::optional<Scalar>>; 49 : : /** An input (point/vector) to a polynomial */ 50 : : using Point = std::vector<Scalar>; 51 : : 52 : : /** 53 : : * partial evaluation of polynomials 54 : : * 55 : : * returns an empty std::optional when some variable in `poly` does not have a 56 : : * value in `values` 57 : : */ 58 : : std::optional<Scalar> cocoaEval(Poly poly, const PartialPoint& values); 59 : : 60 : : /** total evaluation of polynomials */ 61 : : Scalar cocoaEval(Poly poly, const Point& values); 62 : : 63 : : /** convert cocoa integer mod p to a FiniteFieldValue. */ 64 : : FiniteFieldValue cocoaFfToFfVal(const Scalar& elem, const FfSize& size); 65 : : 66 : : /** convert an Integer to CoCoA::BitInt. */ 67 : : CoCoA::BigInt intToCocoa(const Integer& i); 68 : : 69 : : /** get the string representation of a type that implements operator<<. */ 70 : : template <typename T> 71 : 306796 : std::string extractStr(const T& t) 72 : : { 73 : 306796 : std::ostringstream o; 74 : 306796 : o << t; 75 : 613592 : return o.str(); 76 : 306796 : } 77 : : 78 : : /** 79 : : * Compute a GB, with timeout given by `rm`. 80 : : * Throws an FfTimeoutException if the timeout is exceeded. 81 : : */ 82 : : const std::vector<Poly>& GBasisTimeout(const CoCoA::ideal& ideal, 83 : : const ResourceManager* rm); 84 : : 85 : : } // namespace ff 86 : : } // namespace theory 87 : : } // namespace cvc5::internal 88 : : 89 : : #endif /* CVC5__THEORY__FF__COCOA_UTIL_H */ 90 : : 91 : : #endif /* CVC5_USE_COCOA */