The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

248 lines
5.6 KiB

2 months ago
  1. %module ModRationalFunction
  2. %{
  3. #include <carl/core/RationalFunction.h>
  4. #include <carl/core/MultivariatePolynomial.h>
  5. #include <carl/core/FactorizedPolynomial.h>
  6. typedef mpq_class Rational;
  7. typedef carl::Term<Rational> Term;
  8. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  9. typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial;
  10. typedef carl::RationalFunction<Polynomial> RationalFunction;
  11. typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction;
  12. typedef unsigned int uint;
  13. %}
  14. %include "std_string.i"
  15. //TODO: for 32 bit support this has to be changed..
  16. //%import <stddef> //for size_t maybe?
  17. typedef long unsigned int size_t; //this should be okay for 64 bits at least
  18. %import "rational.i"
  19. %import "variable.i"
  20. %import "monomial.i"
  21. %import "term.i"
  22. %import "polynomial.i"
  23. %import "factorizedpolynomial.i"
  24. typedef carl::Term<Rational> Term;
  25. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  26. typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial;
  27. typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction;
  28. %rename(RationalFunction) carl::RationalFunction<Polynomial>;
  29. %rename(FactorizedRationalFunction) carl::RationalFunction<FactorizedPolynomial>;
  30. namespace carl {
  31. class RationalFunction<Polynomial>
  32. {
  33. public:
  34. typedef typename Rational CoeffType;
  35. explicit RationalFunction(const Polynomial& nom, const Polynomial& denom):
  36. mPolynomialQuotient(nullptr),
  37. mNumberQuotient(),
  38. mIsSimplified(false)
  39. {
  40. }
  41. CoeffType evaluate(const std::map<Variable, CoeffType>& substitutions) const;
  42. inline Polynomial nominator() const;
  43. inline Polynomial denominator() const;
  44. %extend {
  45. std::string toString() {
  46. std::stringstream ss;
  47. ss << *$self;
  48. return ss.str();
  49. }
  50. Polynomial numerator() const {
  51. return $self->nominator();
  52. }
  53. std::vector<carl::Variable> gatherVariables() const {
  54. std::set<carl::Variable> asSet = $self->gatherVariables();
  55. return std::vector<carl::Variable>(asSet.begin(),asSet.end());
  56. }
  57. bool equals(const carl::RationalFunction<Polynomial>& other) {
  58. return *$self == other;
  59. }
  60. bool notEquals(const carl::RationalFunction<Polynomial>& other) {
  61. return *$self != other;
  62. }
  63. carl::RationalFunction<Polynomial> add(const Polynomial& rhs) {
  64. return *($self)+rhs;
  65. }
  66. carl::RationalFunction<Polynomial> add(const Term& rhs) {
  67. return *($self)+rhs;
  68. }
  69. carl::RationalFunction<Polynomial> add(const Monomial::Arg& rhs) {
  70. return *($self)+rhs;
  71. }
  72. carl::RationalFunction<Polynomial> add(carl::Variable::Arg rhs) {
  73. return *($self)+rhs;
  74. }
  75. carl::RationalFunction<Polynomial> add(Rational rhs) {
  76. return *($self)+rhs;
  77. }
  78. carl::RationalFunction<Polynomial> sub(const Polynomial& rhs) {
  79. return *($self)-rhs;
  80. }
  81. carl::RationalFunction<Polynomial> sub(const Term& rhs) {
  82. return *($self)-rhs;
  83. }
  84. carl::RationalFunction<Polynomial> sub(const Monomial::Arg& rhs) {
  85. return *($self)-rhs;
  86. }
  87. carl::RationalFunction<Polynomial> sub(carl::Variable::Arg rhs) {
  88. return *($self)-rhs;
  89. }
  90. carl::RationalFunction<Polynomial> sub(Rational rhs) {
  91. return *($self)-rhs;
  92. }
  93. carl::RationalFunction<Polynomial> mul(const Polynomial& rhs) {
  94. return *($self)*rhs;
  95. }
  96. carl::RationalFunction<Polynomial>mul(const Term& rhs) {
  97. return *($self)*rhs;
  98. }
  99. carl::RationalFunction<Polynomial> mul(const Monomial::Arg& rhs) {
  100. return *($self)*rhs;
  101. }
  102. carl::RationalFunction<Polynomial> mul(carl::Variable::Arg rhs) {
  103. return *($self)*rhs;
  104. }
  105. carl::RationalFunction<Polynomial> mul(Rational rhs) {
  106. return *($self)*rhs;
  107. }
  108. carl::RationalFunction<Polynomial> div(const Polynomial& rhs) {
  109. return *($self)/rhs;
  110. }
  111. carl::RationalFunction<Polynomial> div(const Term& rhs) {
  112. return *($self)/rhs;
  113. }
  114. carl::RationalFunction<Polynomial> div(const Monomial::Arg& rhs) {
  115. return *($self)/rhs;
  116. }
  117. carl::RationalFunction<Polynomial> div(carl::Variable::Arg rhs) {
  118. return *($self)/rhs;
  119. }
  120. carl::RationalFunction<Polynomial> div(Rational rhs) {
  121. return *($self)/rhs;
  122. }
  123. carl::RationalFunction<Polynomial> div(const RationalFunction& rhs) {
  124. return *($self)/rhs;
  125. }
  126. carl::RationalFunction<Polynomial> pow(uint exp) {
  127. return carl::pow(*($self),exp);
  128. }
  129. carl::RationalFunction<Polynomial> neg() {
  130. return *$self*Rational(-1);
  131. }
  132. }
  133. };
  134. class RationalFunction<FactorizedPolynomial> {
  135. public:
  136. typedef typename Rational CoeffType;
  137. explicit RationalFunction(const FactorizedPolynomial& nom, const FactorizedPolynomial& denom):
  138. mPolynomialQuotient(nullptr),
  139. mNumberQuotient(),
  140. mIsSimplified(false)
  141. {
  142. }
  143. CoeffType evaluate(const std::map<Variable, CoeffType>& substitutions) const;
  144. inline FactorizedPolynomial nominator() const;
  145. inline FactorizedPolynomial denominator() const;
  146. %extend {
  147. std::string toString() {
  148. std::stringstream ss;
  149. ss << *$self;
  150. return ss.str();
  151. }
  152. FactorizedPolynomial numerator() const {
  153. return $self->nominator();
  154. }
  155. std::vector<carl::Variable> gatherVariables() const {
  156. std::set<carl::Variable> asSet = $self->gatherVariables();
  157. return std::vector<carl::Variable>(asSet.begin(),asSet.end());
  158. }
  159. bool equals(const carl::RationalFunction<FactorizedPolynomial>& other) {
  160. return *$self == other;
  161. }
  162. }
  163. };
  164. }
  165. typedef carl::RationalFunction<Polynomial> RationalFunction;
  166. /*
  167. %template(RationalFunctionPoly) carl::RationalFunction<Polynomial>;
  168. %template(FactorizedRationalFunction) carl::RationalFunction<carl::FactorizedPolynomial<Polynomial>,false>; */