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.

179 lines
4.5 KiB

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