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.

185 lines
4.6 KiB

2 months ago
  1. SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
  2. SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
  3. %module FormulaPolynomialT
  4. %{
  5. #include <carl/formula/Formula.h>
  6. #include <carl/formula/Constraint.h>
  7. #include <carl/core/SimpleConstraint.h>
  8. #include "gmpxx.h"
  9. #include <carl/core/RationalFunction.h>
  10. #include <carl/core/Relation.h>
  11. typedef mpq_class Rational;
  12. typedef carl::Monomial::Arg Monomial;
  13. typedef carl::Term<Rational> Term;
  14. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  15. typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial;
  16. typedef carl::RationalFunction<Polynomial> RationalFunction;
  17. typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction;
  18. typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair;
  19. typedef carl::Formula<Polynomial> FormulaPolynomial;
  20. typedef std::vector<FormulaPolynomial> FormulaVector;
  21. %}
  22. %import "constraint.i"
  23. %include "std_string.i"
  24. %import "variable.i"
  25. %import "polynomial.i"
  26. %import "rationalfunction.i"
  27. %import "factorizedpolynomial.i"
  28. %include "std_vector.i"
  29. %include "std_map.i"
  30. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  31. typedef std::vector<FormulaPolynomial> FormulaVector;
  32. %template(FormulaVector) std::vector<carl::Formula<carl::MultivariatePolynomial<Rational>>>;
  33. typedef carl::Formula<Polynomial> FormulaPolynomial;
  34. typedef mpq_class Rational;
  35. typedef carl::Monomial::Arg Monomial;
  36. typedef carl::Term<Rational> Term;
  37. typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial;
  38. typedef carl::RationalFunction<Polynomial> RationalFunction;
  39. typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction;
  40. typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair;
  41. namespace carl {
  42. enum FormulaType {
  43. // Generic
  44. ITE, EXISTS, FORALL,
  45. // Core Theory
  46. TRUE, FALSE,
  47. BOOL,
  48. NOT, IMPLIES, AND, OR, XOR,
  49. IFF,
  50. // Arithmetic Theory
  51. CONSTRAINT,
  52. // Bitvector Theory
  53. BITVECTOR,
  54. // Uninterpreted Theory
  55. UEQ
  56. };
  57. template<typename Pol> class Formula {
  58. public:
  59. explicit Formula( carl::Variable::Arg _booleanVar ):
  60. Formula( carl::FormulaPool<Pol>::getInstance().create( _booleanVar ) )
  61. {}
  62. explicit Formula( const carl::Constraint<Pol>& _constraint ):
  63. Formula( carl::FormulaPool<Pol>::getInstance().create( _constraint ) )
  64. {}
  65. explicit Formula( carl::FormulaType _type, const Formula& _subformula ):
  66. Formula(carl::FormulaPool<Pol>::getInstance().create(_type, std::move(Formula(_subformula))))
  67. {}
  68. explicit Formula( carl::FormulaType _type, const std::vector<Formula<Pol>>& _subasts ):
  69. Formula( carl::FormulaPool<Pol>::getInstance().create( _type, _subasts ) )
  70. {}
  71. //Apparently satisfiedBy no longer exists
  72. //unsigned satisfiedBy( const carl::EvaluationMap<typename Pol::NumberType>& _assignment ) const;
  73. std::string toString( bool _withActivity = false, unsigned _resolveUnequal = 0, const std::string _init = "", bool _oneline = true, bool _infix = false, bool _friendlyNames = true, bool _withVariableDefinition = false ) const;
  74. size_t size() const;
  75. carl::FormulaType getType() const;
  76. //TODO: maybe find fix for the weird underscore names
  77. %extend {
  78. carl::Formula<Pol> not_() {
  79. return carl::Formula<Pol>(carl::FormulaType::NOT, carl::Formula<Pol>(*$self));
  80. }
  81. carl::Formula<Pol> and_(const carl::Constraint<Pol>& rhs) {
  82. return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs));
  83. }
  84. carl::Formula<Pol> and_(const carl::Formula<Pol>& rhs) {
  85. return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), rhs);
  86. }
  87. carl::Formula<Pol> or_(const carl::Constraint<Pol>& rhs) {
  88. return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs));
  89. }
  90. carl::Formula<Pol> or_(const carl::Formula<Pol>& rhs) {
  91. return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), rhs);
  92. }
  93. carl::Formula<Pol> xor_(const carl::Constraint<Pol>& rhs) {
  94. return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs));
  95. }
  96. carl::Formula<Pol> xor_(const carl::Formula<Pol>& rhs) {
  97. return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), rhs);
  98. }
  99. //instead of iterator
  100. carl::Formula<Pol> getItem(int i) {
  101. return $self->subformulas().at(i);
  102. }
  103. bool equals(const carl::Formula<Pol>& rhs) {
  104. return *$self == rhs;
  105. }
  106. }
  107. };
  108. }
  109. %template(FormulaPolynomial) carl::Formula<Polynomial>;