+ def tosympy(self):
+ import sympy
+ constraints = []
+ for equality in self.equalities:
+ constraints.append(sympy.Eq(equality.tosympy(), 0))
+ for inequality in self.inequalities:
+ constraints.append(sympy.Ge(inequality.tosympy(), 0))
+ return sympy.And(*constraints)
+
+ def _symbolunion(self, *others):
+ symbols = set(self.symbols)
+ for other in others:
+ symbols.update(other.symbols)
+ return sorted(symbols)
+
+ def _toisl(self, symbols=None):
+ if symbols is None:
+ symbols = self.symbols
+ dimension = len(symbols)
+ space = libisl.isl_space_set_alloc(_main_ctx, 0, dimension)
+ bset = libisl.isl_basic_set_universe(libisl.isl_space_copy(space))
+ ls = libisl.isl_local_space_from_space(space)
+ for equality in self.equalities:
+ ceq = libisl.isl_equality_alloc(libisl.isl_local_space_copy(ls))
+ for symbol, coefficient in equality.coefficients():
+ val = str(coefficient).encode()
+ val = libisl.isl_val_read_from_str(_main_ctx, val)
+ dim = symbols.index(symbol)
+ ceq = libisl.isl_constraint_set_coefficient_val(ceq, libisl.isl_dim_set, dim, val)
+ if equality.constant != 0:
+ val = str(equality.constant).encode()
+ val = libisl.isl_val_read_from_str(_main_ctx, val)
+ ceq = libisl.isl_constraint_set_constant_val(ceq, val)
+ bset = libisl.isl_basic_set_add_constraint(bset, ceq)
+ for inequality in self.inequalities:
+ cin = libisl.isl_inequality_alloc(libisl.isl_local_space_copy(ls))
+ for symbol, coefficient in inequality.coefficients():
+ val = str(coefficient).encode()
+ val = libisl.isl_val_read_from_str(_main_ctx, val)
+ dim = symbols.index(symbol)
+ cin = libisl.isl_constraint_set_coefficient_val(cin, libisl.isl_dim_set, dim, val)
+ if inequality.constant != 0:
+ val = str(inequality.constant).encode()
+ val = libisl.isl_val_read_from_str(_main_ctx, val)
+ cin = libisl.isl_constraint_set_constant_val(cin, val)
+ bset = libisl.isl_basic_set_add_constraint(bset, cin)
+ bset = isl.BasicSet(bset)
+ return bset