5 #ifndef SYMENGINE_SETS_H
6 #define SYMENGINE_SETS_H
10 #include <symengine/symengine_casts.h>
17 inline bool is_a_Boolean(
const Basic &b);
18 RCP<const BooleanAtom> boolean(
bool b);
29 virtual RCP<const Set> set_intersection(
const RCP<const Set> &o)
const = 0;
30 virtual RCP<const Set> set_union(
const RCP<const Set> &o)
const = 0;
31 virtual RCP<const Set> set_complement(
const RCP<const Set> &o)
const = 0;
32 virtual RCP<const Boolean> contains(
const RCP<const Basic> &a)
const = 0;
33 bool is_subset(
const RCP<const Set> &o)
const
35 return eq(*this->set_intersection(o), *
this);
37 bool is_proper_subset(
const RCP<const Set> &o)
const
39 return not
eq(*
this, *o) and this->is_subset(o);
41 bool is_superset(
const RCP<const Set> &o)
const
43 return o->is_subset(rcp_from_this_cast<const Set>());
45 bool is_proper_superset(
const RCP<const Set> &o)
const
47 return not
eq(*
this, *o) and this->is_superset(o);
54 EmptySet(){SYMENGINE_ASSIGN_TYPEID()}
61 const static RCP<const EmptySet> &getInstance();
70 template <
typename T_,
typename... Args>
71 friend inline RCP<T_> make_rcp(Args &&...args);
73 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
74 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
75 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
76 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override
78 return boolean(
false);
87 SYMENGINE_ASSIGN_TYPEID()
94 const static RCP<const UniversalSet> &getInstance();
103 template <
typename T_,
typename... Args>
104 friend inline RCP<T_> make_rcp(Args &&...args);
106 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
107 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
108 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
109 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override
111 return boolean(
true);
131 static bool is_canonical(
const set_basic &container);
133 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
134 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
135 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
136 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
137 RCP<const Set> create(
const set_basic &container)
const;
139 inline const set_basic &get_container()
const
141 return this->container_;
148 RCP<const Number> start_;
149 RCP<const Number> end_;
150 bool left_open_, right_open_;
158 Interval(
const RCP<const Number> &start,
const RCP<const Number> &end,
159 const bool left_open =
false,
const bool right_open =
false);
161 RCP<const Set> open()
const;
162 RCP<const Set> close()
const;
163 RCP<const Set> Lopen()
const;
164 RCP<const Set> Ropen()
const;
166 static bool is_canonical(
const RCP<const Number> &start,
167 const RCP<const Number> &end,
bool left_open,
170 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
171 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
172 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
173 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
176 inline const RCP<const Number> &get_start()
const
180 inline const RCP<const Number> &get_end()
const
184 inline const bool &get_left_open()
const
186 return this->left_open_;
188 inline const bool &get_right_open()
const
190 return this->right_open_;
199 SYMENGINE_ASSIGN_TYPEID()
204 void operator=(
Complexes const &) =
delete;
205 const static RCP<const Complexes> &getInstance();
214 template <
typename T_,
typename... Args>
215 friend inline RCP<T_> make_rcp(Args &&...args);
217 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
218 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
219 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
220 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
228 SYMENGINE_ASSIGN_TYPEID()
233 void operator=(
Reals const &) =
delete;
234 const static RCP<const Reals> &getInstance();
243 template <
typename T_,
typename... Args>
244 friend inline RCP<T_> make_rcp(Args &&...args);
246 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
247 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
248 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
249 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
257 SYMENGINE_ASSIGN_TYPEID()
262 void operator=(
Rationals const &) =
delete;
263 const static RCP<const Rationals> &getInstance();
272 template <
typename T_,
typename... Args>
273 friend inline RCP<T_> make_rcp(Args &&...args);
275 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
276 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
277 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
278 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
286 SYMENGINE_ASSIGN_TYPEID()
291 void operator=(
Integers const &) =
delete;
292 const static RCP<const Integers> &getInstance();
301 template <
typename T_,
typename... Args>
302 friend inline RCP<T_> make_rcp(Args &&...args);
304 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
305 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
306 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
307 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
315 SYMENGINE_ASSIGN_TYPEID()
320 void operator=(
Naturals const &) =
delete;
321 const static RCP<const Naturals> &getInstance();
330 template <
typename T_,
typename... Args>
331 friend inline RCP<T_> make_rcp(Args &&...args);
333 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
334 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
335 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
336 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
344 SYMENGINE_ASSIGN_TYPEID()
349 void operator=(
Naturals0 const &) =
delete;
350 const static RCP<const Naturals0> &getInstance();
359 template <
typename T_,
typename... Args>
360 friend inline RCP<T_> make_rcp(Args &&...args);
362 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
363 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
364 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
365 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
380 static bool is_canonical(
const set_set &in);
382 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
383 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
384 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
385 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
387 inline const set_set &get_container()
const
389 return this->container_;
392 RCP<const Set> create(
const set_set &in)
const;
407 static bool is_canonical(
const set_set &in);
409 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
410 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
411 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
412 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
414 inline const set_set &get_container()
const
416 return this->container_;
419 RCP<const Set> create(
const set_set &in)
const;
426 RCP<const Set> universe_;
427 RCP<const Set> container_;
436 return {universe_, container_};
438 Complement(
const RCP<const Set> &universe,
const RCP<const Set> &container);
440 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
441 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
442 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
443 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
445 inline const RCP<const Set> &get_universe()
const
447 return this->universe_;
449 inline const RCP<const Set> &get_container()
const
451 return this->container_;
458 RCP<const Basic> sym;
459 RCP<const Boolean> condition_;
468 return {sym, condition_};
471 const RCP<const Boolean> &condition);
472 static bool is_canonical(
const RCP<const Basic> &sym,
473 const RCP<const Boolean> &condition);
474 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
475 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
476 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
477 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
478 inline const RCP<const Basic> &get_symbol()
const
482 inline const RCP<const Boolean> &get_condition()
const
484 return this->condition_;
492 RCP<const Basic> sym_;
493 RCP<const Basic> expr_;
494 RCP<const Set> base_;
503 return {sym_, expr_, base_};
505 ImageSet(
const RCP<const Basic> &sym,
const RCP<const Basic> &expr,
506 const RCP<const Set> &base);
508 static bool is_canonical(
const RCP<const Basic> &sym,
509 const RCP<const Basic> &expr,
510 const RCP<const Set> &base);
511 RCP<const Set> set_intersection(
const RCP<const Set> &o)
const override;
512 RCP<const Set> set_union(
const RCP<const Set> &o)
const override;
513 RCP<const Set> set_complement(
const RCP<const Set> &o)
const override;
514 RCP<const Boolean> contains(
const RCP<const Basic> &a)
const override;
516 inline const RCP<const Basic> &get_symbol()
const
520 inline const RCP<const Basic> &get_expr()
const
524 inline const RCP<const Set> &get_baseset()
const
529 RCP<const Set> create(
const RCP<const Basic> &sym,
530 const RCP<const Basic> &expr,
531 const RCP<const Set> &base)
const;
534 inline bool is_a_Set(
const Basic &b)
536 return (b.get_type_code() == SYMENGINE_EMPTYSET
537 || b.get_type_code() == SYMENGINE_UNIVERSALSET
538 || b.get_type_code() == SYMENGINE_FINITESET
539 || b.get_type_code() == SYMENGINE_COMPLEMENT
540 || b.get_type_code() == SYMENGINE_CONDITIONSET
541 || b.get_type_code() == SYMENGINE_INTERVAL
542 || b.get_type_code() == SYMENGINE_COMPLEXES
543 || b.get_type_code() == SYMENGINE_REALS
544 || b.get_type_code() == SYMENGINE_RATIONALS
545 || b.get_type_code() == SYMENGINE_INTEGERS
546 || b.get_type_code() == SYMENGINE_NATURALS
547 || b.get_type_code() == SYMENGINE_NATURALS0
548 || b.get_type_code() == SYMENGINE_UNION
549 || b.get_type_code() == SYMENGINE_INTERSECTION
550 || b.get_type_code() == SYMENGINE_IMAGESET);
556 return Complexes::getInstance();
562 return Reals::getInstance();
568 return Rationals::getInstance();
574 return Integers::getInstance();
580 return Naturals::getInstance();
586 return Naturals0::getInstance();
592 return EmptySet::getInstance();
598 return UniversalSet::getInstance();
604 if (FiniteSet::is_canonical(container)) {
605 return make_rcp<const FiniteSet>(container);
611 inline RCP<const Set>
interval(
const RCP<const Number> &start,
612 const RCP<const Number> &end,
613 const bool left_open =
false,
614 const bool right_open =
false)
616 if (Interval::is_canonical(start, end, left_open, right_open))
617 return make_rcp<const Interval>(start, end, left_open, right_open);
618 if (
eq(*start, *end) and not(left_open or right_open))
624 inline RCP<const Set> imageset(
const RCP<const Basic> &sym,
625 const RCP<const Basic> &expr,
626 const RCP<const Set> &base)
628 if (not is_a_sub<Symbol>(*sym))
629 throw SymEngineException(
"first arg is expected to be a symbol");
636 if (is_a_Set(*expr)) {
637 for (
const auto &s :
static_cast<const Set &
>(*expr).get_args()) {
639 or is_a_Boolean(*s))) {
640 return make_rcp<const ImageSet>(sym, expr, base);
646 if (is_a<FiniteSet>(*base)) {
650 down_cast<const FiniteSet &>(*base).get_container()) {
652 temp.
insert(expr->subs(d));
658 if (is_a<ImageSet>(*base)) {
659 const ImageSet &imbase = down_cast<const ImageSet &>(*base);
661 d[sym] = imbase.get_expr();
662 return imageset(imbase.get_symbol(),
expand(expr->subs(d)),
663 imbase.get_baseset());
666 return make_rcp<const ImageSet>(sym, expr, base);
670 RCP<const Set>
set_union(
const set_set &in);
675 RCP<const Set> set_complement_helper(
const RCP<const Set> &container,
676 const RCP<const Set> &universe);
679 RCP<const Set> set_complement(
const RCP<const Set> &universe,
680 const RCP<const Set> &container);
683 RCP<const Set>
conditionset(
const RCP<const Basic> &sym,
684 const RCP<const Boolean> &condition);
686 RCP<const Basic> sup(
const Set &s);
687 RCP<const Basic> inf(
const Set &s);
688 RCP<const Set> boundary(
const Set &s);
689 RCP<const Set> interior(
const Set &s);
690 RCP<const Set> closure(
const Set &s);
#define IMPLEMENT_TYPEID(SYMENGINE_ID)
Inline members and functions.
The lowest unit of symbolic representation.
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
hash_t __hash__() const override
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
hash_t __hash__() const override
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
hash_t __hash__() const override
vec_basic get_args() const override
Returns the list of arguments.
vec_basic get_args() const override
Returns the list of arguments.
hash_t __hash__() const override
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
bool __eq__(const Basic &o) const override
Test equality.
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
hash_t __hash__() const override
bool __eq__(const Basic &o) const override
Test equality.
hash_t __hash__() const override
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
hash_t __hash__() const override
int compare(const Basic &o) const override
vec_basic get_args() const override
Returns the list of arguments.
bool __eq__(const Basic &o) const override
Test equality.
bool __eq__(const Basic &o) const override
Test equality.
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
hash_t __hash__() const override
bool __eq__(const Basic &o) const override
Test equality.
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
hash_t __hash__() const override
hash_t __hash__() const override
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
hash_t __hash__() const override
bool __eq__(const Basic &o) const override
Test equality.
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
hash_t __hash__() const override
vec_basic get_args() const override
Returns the list of arguments.
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Test equality.
hash_t __hash__() const override
vec_basic get_args() const override=0
Returns the list of arguments.
hash_t __hash__() const override
int compare(const Basic &o) const override
vec_basic get_args() const override
Returns the list of arguments.
bool __eq__(const Basic &o) const override
Test equality.
vec_basic get_args() const override
Returns the list of arguments.
bool __eq__(const Basic &o) const override
Test equality.
int compare(const Basic &o) const override
hash_t __hash__() const override
Main namespace for SymEngine package.
bool is_a_Number(const Basic &b)
RCP< const Set > interval(const RCP< const Number > &start, const RCP< const Number > &end, const bool left_open=false, const bool right_open=false)
RCP< const Complexes > complexes()
RCP< const Reals > reals()
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
RCP< const Naturals > naturals()
RCP< const EmptySet > emptyset()
RCP< const Integers > integers()
RCP< const UniversalSet > universalset()
RCP< const Set > conditionset(const RCP< const Basic > &sym, const RCP< const Boolean > &condition)
RCP< const Set > finiteset(const set_basic &container)
RCP< const Basic > expand(const RCP< const Basic > &self, bool deep=true)
Expands self
RCP< const Naturals0 > naturals0()
RCP< const Rationals > rationals()
T set_intersection(T... args)