You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.7 KiB

2 months ago
  1. %module FactorizedPolynomialRational
  2. %{
  3. #include <carl/core/MultivariatePolynomial.h>
  4. #include <carl/core/FactorizedPolynomial.h>
  5. #include "gmp.h"
  6. #include "gmpxx.h"
  7. typedef mpq_class Rational;
  8. typedef carl::Term<Rational> Term;
  9. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  10. typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial;
  11. typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair;
  12. typedef unsigned int uint;
  13. typedef std::pair<carl::Variable,uint> VarIntPair;
  14. typedef FactorizedPolynomial::CACHE FactorizationCache;
  15. %}
  16. %include "std_string.i"
  17. %include "std_shared_ptr.i"
  18. %shared_ptr(carl::Cache<FactorizationPair>);
  19. %import "variable.i"
  20. %import "polynomial.i"
  21. typedef mpq_class Rational;
  22. typedef carl::Term<Rational> Term;
  23. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  24. typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial;
  25. typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair;
  26. typedef FactorizedPolynomial::CACHE FactorizationCache;
  27. namespace carl {
  28. %rename(FactorizationCache) Cache<FactorizationPair>;
  29. class Cache<FactorizationPair> {
  30. public:
  31. Cache( size_t _maxCacheSize = 10000, double _cacheReductionAmount = 0.2, double _decay = 0.98 );
  32. };
  33. template<typename P>
  34. class FactorizedPolynomial {
  35. public:
  36. typedef typename P::CoeffType CoeffType;
  37. typedef carl::Cache<carl::PolynomialFactorizationPair<P>> CACHE;
  38. explicit FactorizedPolynomial( const CoeffType& );
  39. explicit FactorizedPolynomial( const P& _polynomial, const std::shared_ptr<carl::FactorizedPolynomial::CACHE>&, bool = false );
  40. CoeffType constantPart() const;
  41. template<typename SubstitutionType = CoeffType>
  42. SubstitutionType evaluate(const std::map<carl::Variable, SubstitutionType>& substitutions) const;
  43. std::string toString( bool _infix = true, bool _friendlyVarNames = true ) const;
  44. %extend {
  45. std::vector<carl::Variable> gatherVariables() const {
  46. std::set<carl::Variable> asSet = $self->gatherVariables();
  47. return std::vector<carl::Variable>(asSet.begin(),asSet.end());
  48. }
  49. }
  50. %extend {
  51. carl::FactorizedPolynomial<P> add(const carl::FactorizedPolynomial<P>& rhs) {
  52. return *$self+rhs;
  53. }
  54. carl::FactorizedPolynomial<P> sub(const carl::FactorizedPolynomial<P>& rhs) {
  55. return *$self-rhs;
  56. }
  57. carl::FactorizedPolynomial<P> mul(const carl::FactorizedPolynomial<P>& rhs) {
  58. return *$self*rhs;
  59. }
  60. bool equals(const carl::FactorizedPolynomial<P>& rhs) {
  61. return *$self==rhs;
  62. }
  63. bool notEquals(const carl::FactorizedPolynomial<P>& rhs) {
  64. return *$self!=rhs;
  65. }
  66. }
  67. };
  68. %template(evaluate) carl::FactorizedPolynomial::evaluate<Rational>;
  69. }
  70. %template(FactorizedPolynomialRational) carl::FactorizedPolynomial<Polynomial>;