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.

155 lines
3.1 KiB

2 months ago
  1. %module TermRationalT
  2. %{
  3. #include <carl/core/Term.h>
  4. #include <carl/core/MultivariatePolynomial.h>
  5. #include <carl/core/RationalFunction.h>
  6. #include "gmp.h"
  7. #include "gmpxx.h"
  8. typedef mpq_class Rational;
  9. typedef carl::Term<Rational> Term;
  10. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  11. typedef carl::RationalFunction<Polynomial> RationalFunction;
  12. %}
  13. %include "std_string.i"
  14. %import "monomial.i"
  15. %import "rational.i"
  16. %import "polynomial.i"
  17. %import "rationalfunction.i"
  18. typedef mpq_class Rational;
  19. typedef carl::Term<Rational> Term;
  20. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  21. typedef carl::RationalFunction<Polynomial> RationalFunction;
  22. namespace carl {
  23. template<typename Coefficient>
  24. class Term {
  25. public:
  26. Term(const Coefficient& c, const carl::Monomial::Arg& m);
  27. Coefficient& coeff();
  28. inline const Monomial::Arg& monomial() const;
  29. //template<typename C = Coefficient, DisableIf<is_interval<C>> = dummy>
  30. //std::string toString(bool infix=true, bool friendlyVarNames=true) const;
  31. carl::Term<Coefficient> pow(uint exp) const;
  32. %extend {
  33. std::string toString() const {
  34. return $self->toString();
  35. }
  36. Polynomial add(const carl::Term<Coefficient>& rhs) {
  37. return *($self)+rhs;
  38. }
  39. Polynomial add(const Polynomial& rhs) {
  40. return *($self)+rhs;
  41. }
  42. Polynomial add(const Monomial::Arg& rhs) {
  43. return *($self)+rhs;
  44. }
  45. Polynomial add(carl::Variable::Arg rhs) {
  46. return *($self)+rhs;
  47. }
  48. Polynomial add(const Coefficient& rhs) {
  49. return *($self)+rhs;
  50. }
  51. Polynomial sub(const carl::Term<Coefficient>& rhs) {
  52. return *($self)-rhs;
  53. }
  54. Polynomial sub(const Polynomial& rhs) {
  55. return *($self)-rhs;
  56. }
  57. Polynomial sub(const Monomial::Arg& rhs) {
  58. return *($self)-rhs;
  59. }
  60. Polynomial sub(carl::Variable::Arg rhs) {
  61. return *($self)-rhs;
  62. }
  63. Polynomial sub(const Coefficient& rhs) {
  64. return *($self)-rhs;
  65. }
  66. carl::Term<Coefficient> mul(const carl::Term<Coefficient>& rhs) {
  67. return *($self)*rhs;
  68. }
  69. Polynomial mul(const Polynomial& rhs) {
  70. return *($self)*rhs;
  71. }
  72. carl::Term<Coefficient> mul(const Monomial::Arg& rhs) {
  73. return *($self)*rhs;
  74. }
  75. carl::Term<Coefficient> mul(carl::Variable::Arg rhs) {
  76. return *($self)*rhs;
  77. }
  78. carl::Term<Coefficient> mul(const Coefficient& rhs) {
  79. return *($self)*rhs;
  80. }
  81. RationalFunction div(const RationalFunction& rhs) {
  82. return RationalFunction(Polynomial(*($self))) / rhs;
  83. }
  84. RationalFunction div(const Polynomial& rhs) {
  85. return RationalFunction(Polynomial(*($self))) / rhs;
  86. }
  87. RationalFunction div(const carl::Term<Coefficient>& rhs) {
  88. return RationalFunction(Polynomial(*($self))) / rhs;
  89. }
  90. RationalFunction div(const Monomial::Arg& rhs) {
  91. return RationalFunction(Polynomial(*($self))) / rhs;
  92. }
  93. RationalFunction div(carl::Variable::Arg rhs) {
  94. return RationalFunction(Polynomial(*($self))) / rhs;
  95. }
  96. carl::Term<Coefficient> div(const Rational& rhs) {
  97. return *$self / rhs;
  98. }
  99. carl::Term<Coefficient> neg() {
  100. return *$self*Coefficient(-1);
  101. }
  102. }
  103. };
  104. }
  105. %template(TermRational) carl::Term<Rational>;