Loading...
Searching...
No Matches
SymEngine::FiniteSet Class Reference
+ Inheritance diagram for SymEngine::FiniteSet:
+ Collaboration diagram for SymEngine::FiniteSet:

Public Member Functions

void accept (Visitor &v) const override
 
void accept (EvalRealDoubleVisitorFinal &v) const override
 
hash_t __hash__ () const override
 
bool __eq__ (const Basic &o) const override
 Test equality.
 
int compare (const Basic &o) const override
 
vec_basic get_args () const override
 Returns the list of arguments.
 
 FiniteSet (const set_basic &container)
 
RCP< const Setset_union (const RCP< const Set > &o) const override
 
RCP< const Setset_intersection (const RCP< const Set > &o) const override
 
RCP< const Setset_complement (const RCP< const Set > &o) const override
 
RCP< const Booleancontains (const RCP< const Basic > &a) const override
 
RCP< const Setcreate (const set_basic &container) const
 
const set_basicget_container () const
 
- Public Member Functions inherited from SymEngine::Set
vec_basic get_args () const override=0
 Returns the list of arguments.
 
virtual RCP< const Setset_intersection (const RCP< const Set > &o) const =0
 
virtual RCP< const Setset_union (const RCP< const Set > &o) const =0
 
virtual RCP< const Setset_complement (const RCP< const Set > &o) const =0
 
virtual RCP< const Booleancontains (const RCP< const Basic > &a) const =0
 
bool is_subset (const RCP< const Set > &o) const
 
bool is_proper_subset (const RCP< const Set > &o) const
 
bool is_superset (const RCP< const Set > &o) const
 
bool is_proper_superset (const RCP< const Set > &o) const
 
- Public Member Functions inherited from SymEngine::Basic
TypeID get_type_code () const
 
 Basic ()
 Constructor.
 
 Basic (const Basic &)=delete
 Delete the copy constructor and assignment.
 
Basicoperator= (const Basic &)=delete
 Assignment operator in continuation with above.
 
 Basic (Basic &&)=delete
 Delete the move constructor and assignment.
 
Basicoperator= (Basic &&)=delete
 Assignment operator in continuation with above.
 
virtual hash_t __hash__ () const =0
 
hash_t hash () const
 
virtual bool __eq__ (const Basic &o) const =0
 Test equality.
 
bool __neq__ (const Basic &o) const
 true if this is not equal to o.
 
int __cmp__ (const Basic &o) const
 Comparison operator.
 
virtual int compare (const Basic &o) const =0
 
std::string __str__ () const
 
std::string dumps () const
 Returns a string of the instance serialized.
 
RCP< const Basicsubs (const map_basic_basic &subs_dict) const
 Substitutes 'subs_dict' into 'self'.
 
RCP< const Basicxreplace (const map_basic_basic &subs_dict) const
 
virtual RCP< const Basicexpand_as_exp () const
 expands the special function in terms of exp function
 
virtual vec_basic get_args () const =0
 Returns the list of arguments.
 
virtual void accept (Visitor &v) const =0
 
virtual void accept (EvalRealDoubleVisitorFinal &v) const =0
 
RCP< const Basicdiff (const RCP< const Symbol > &x, bool cache=true) const
 
- Public Member Functions inherited from SymEngine::EnableRCPFromThis< Basic >
RCP< Basicrcp_from_this ()
 Get RCP<T> pointer to self (it will cast the pointer to T)
 
RCP< const Basicrcp_from_this () const
 Get RCP<const T> pointer to self (it will cast the pointer to const T)
 
RCP< const T2 > rcp_from_this_cast () const
 Get RCP<T2> pointer to self (it will cast the pointer to T2)
 
unsigned int use_count () const
 

Static Public Member Functions

static bool is_canonical (const set_basic &container)
 
- Static Public Member Functions inherited from SymEngine::Basic
static RCP< const Basicloads (const std::string &)
 Creates an instance of a serialized string.
 

Static Public Attributes

static const TypeID type_code_id = SYMENGINE_FINITESET
 

Private Attributes

set_basic container_
 

Additional Inherited Members

- Data Fields inherited from SymEngine::Basic
TypeID type_code_
 

Detailed Description

Definition at line 115 of file sets.h.

Constructor & Destructor Documentation

◆ FiniteSet()

SymEngine::FiniteSet::FiniteSet ( const set_basic container)

Definition at line 850 of file sets.cpp.

850 : container_(container)
851{
852 SYMENGINE_ASSIGN_TYPEID()
853 SYMENGINE_ASSERT(FiniteSet::is_canonical(container_));
854}

Member Function Documentation

◆ __eq__()

bool SymEngine::FiniteSet::__eq__ ( const Basic o) const
overridevirtual

Test equality.

A virtual function for testing the equality of two Basic objects

Deprecated:
Use eq(const Basic &a, const Basic &b) non-member method
Parameters
oa constant reference to object to test against
Returns
True if this is equal to o

Implements SymEngine::Basic.

Definition at line 869 of file sets.cpp.

870{
871 if (is_a<FiniteSet>(o)) {
872 const FiniteSet &other = down_cast<const FiniteSet &>(o);
873 return unified_eq(container_, other.container_);
874 }
875 return false;
876}

◆ __hash__()

hash_t SymEngine::FiniteSet::__hash__ ( ) const
overridevirtual

Calculates the hash of the given SymEngine class. Use Basic.hash() which gives a cached version of the hash.

Returns
64-bit integer value for the hash

Implements SymEngine::Basic.

Definition at line 861 of file sets.cpp.

862{
863 hash_t seed = SYMENGINE_FINITESET;
864 for (const auto &a : container_)
865 hash_combine<Basic>(seed, *a);
866 return seed;
867}

◆ accept() [1/2]

void SymEngine::FiniteSet::accept ( EvalRealDoubleVisitorFinal v) const
overridevirtual

Implements SymEngine::Basic.

◆ accept() [2/2]

void SymEngine::FiniteSet::accept ( Visitor v) const
overridevirtual

Implements SymEngine::Basic.

◆ compare()

int SymEngine::FiniteSet::compare ( const Basic o) const
overridevirtual

Returns -1, 0, 1 for this < o, this == o, this > o. This method is used when you want to sort things like x+y+z into canonical order. This function assumes that o is the same type as this. Use __cmp__ if you want general comparison.

Implements SymEngine::Basic.

Definition at line 878 of file sets.cpp.

879{
880 // compares two FiniteSet based on their length
881 SYMENGINE_ASSERT(is_a<FiniteSet>(o))
882 const FiniteSet &other = down_cast<const FiniteSet &>(o);
883 return unified_compare(container_, other.container_);
884}
int unified_compare(const T &a, const T &b)
Definition: dict.h:205

◆ contains()

RCP< const Boolean > SymEngine::FiniteSet::contains ( const RCP< const Basic > &  a) const
overridevirtual

Implements SymEngine::Set.

Definition at line 886 of file sets.cpp.

887{
888 set_basic rest;
889 for (const auto &elem : container_) {
890 auto cont = Eq(elem, a);
891 if (eq(*cont, *boolTrue))
892 return boolTrue;
893 if (not eq(*cont, *boolFalse))
894 rest.insert(elem);
895 }
896 if (rest.empty()) {
897 return boolFalse;
898 } else {
899 return make_rcp<Contains>(a, finiteset(rest));
900 }
901}
RCP< const Set > finiteset(const set_basic &container)
Definition: sets.h:602
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21
RCP< const Boolean > Eq(const RCP< const Basic > &lhs)
Returns the canonicalized Equality object from a single argument.
Definition: logic.cpp:653

◆ create()

RCP< const Set > SymEngine::FiniteSet::create ( const set_basic container) const

Definition at line 1182 of file sets.cpp.

1183{
1184 return finiteset(container);
1185}

◆ get_args()

vec_basic SymEngine::FiniteSet::get_args ( ) const
inlineoverridevirtual

Returns the list of arguments.

Implements SymEngine::Set.

Definition at line 125 of file sets.h.

126 {
127 return vec_basic(container_.begin(), container_.end());
128 }
T begin(T... args)
T end(T... args)

◆ get_container()

const set_basic & SymEngine::FiniteSet::get_container ( ) const
inline

Definition at line 139 of file sets.h.

140 {
141 return this->container_;
142 }

◆ is_canonical()

bool SymEngine::FiniteSet::is_canonical ( const set_basic container)
static

Definition at line 856 of file sets.cpp.

857{
858 return container.size() != 0;
859}

◆ set_complement()

RCP< const Set > SymEngine::FiniteSet::set_complement ( const RCP< const Set > &  o) const
overridevirtual

Implements SymEngine::Set.

Definition at line 1126 of file sets.cpp.

1127{
1128 if (is_a<FiniteSet>(*o)) {
1129 const FiniteSet &other = down_cast<const FiniteSet &>(*o);
1130 set_basic container;
1131 std::set_difference(other.container_.begin(), other.container_.end(),
1132 container_.begin(), container_.end(),
1133 std::inserter(container, container.begin()),
1134 RCPBasicKeyLess{});
1135 return finiteset(container);
1136 }
1137
1138 if (is_a<Interval>(*o)) {
1139 set_set intervals;
1140 auto &other = down_cast<const Interval &>(*o);
1141 RCP<const Number> last = other.get_start();
1142 RCP<const Number> a_num;
1143 set_basic rest;
1144 bool left_open = other.get_left_open(),
1145 right_open = other.get_right_open();
1146 for (auto it = container_.begin(); it != container_.end(); it++) {
1147 if (eq(*max({*it, other.get_start()}), *other.get_start())) {
1148 if (eq(**it, *other.get_start()))
1149 left_open = true;
1150 continue;
1151 }
1152 if (eq(*max({*it, other.get_end()}), **it)) {
1153 if (eq(**it, *other.get_end()))
1154 right_open = true;
1155 break;
1156 }
1157 if (is_a_Number(**it)) {
1158 a_num = rcp_static_cast<const Number>(*it);
1159 intervals.insert(interval(last, a_num, left_open, true));
1160 last = a_num;
1161 left_open = true;
1162 } else {
1163 rest.insert(*it);
1164 }
1165 }
1166
1167 if (eq(*max({last, other.get_end()}), *other.get_end())) {
1168 intervals.insert(
1169 interval(last, other.get_end(), left_open, right_open));
1170 }
1171 if (rest.empty()) {
1172 return SymEngine::make_set_union(intervals);
1173 } else {
1174 return make_rcp<const Complement>(
1175 SymEngine::make_set_union(intervals), finiteset(rest));
1176 }
1177 }
1178
1179 return SymEngine::set_complement_helper(rcp_from_this_cast<const Set>(), o);
1180}
T inserter(T... args)
bool is_a_Number(const Basic &b)
Definition: number.h:130
RCP< const Basic > max(const vec_basic &arg)
Canonicalize Max:
Definition: functions.cpp:3555
RCP< const Set > interval(const RCP< const Number > &start, const RCP< const Number > &end, const bool left_open=false, const bool right_open=false)
Definition: sets.h:611
T set_difference(T... args)

◆ set_intersection()

RCP< const Set > SymEngine::FiniteSet::set_intersection ( const RCP< const Set > &  o) const
overridevirtual

Implements SymEngine::Set.

Definition at line 1031 of file sets.cpp.

1032{
1033 if (is_a<FiniteSet>(*o)) {
1034 return SymEngine::set_intersection(
1035 {rcp_from_this_cast<const Set>(), o});
1036 }
1037 if (is_a<Interval>(*o)) {
1038 set_basic container;
1039 for (const auto &a : container_) {
1040 auto contain = o->contains(a);
1041 if (eq(*contain, *boolTrue))
1042 container.insert(a);
1043 if (is_a<Contains>(*contain))
1044 return make_set_intersection(
1045 {rcp_from_this_cast<const Set>(), o});
1046 }
1047 return finiteset(container);
1048 }
1049 if (is_a<Complexes>(*o) or is_a<Reals>(*o) or is_a<Rationals>(*o)) {
1050 set_basic kept;
1051 set_basic others;
1052 for (const auto &elem : container_) {
1053 if (is_a_Number(*elem)) {
1054 if (!down_cast<const Number &>(*elem).is_complex()) {
1055 if (!is_a<Rationals>(*o)
1056 or down_cast<const Number &>(*elem).is_exact()) {
1057 kept.insert(elem);
1058 }
1059 } else {
1060 if (is_a<Complexes>(*o)) {
1061 kept.insert(elem);
1062 }
1063 }
1064 } else {
1065 others.insert(elem);
1066 }
1067 }
1068 if (kept.empty()) {
1069 if (others.empty()) {
1070 return emptyset();
1071 } else {
1072 return SymEngine::make_set_intersection({o, finiteset(others)});
1073 }
1074 } else {
1075 if (others.empty()) {
1076 return finiteset(kept);
1077 } else {
1078 others.insert(kept.begin(), kept.end());
1079 return SymEngine::make_set_intersection({o, finiteset(others)});
1080 }
1081 }
1082 }
1083 if (is_a<Integers>(*o) or is_a<Naturals>(*o) or is_a<Naturals0>(*o)) {
1084 set_basic kept_integers;
1085 set_basic others;
1086 for (const auto &elem : container_) {
1087 if (is_a_Number(*elem)) {
1088 if (is_a<Integers>(*o) and is_a<Integer>(*elem)) {
1089 kept_integers.insert(elem);
1090 } else if (is_a<Naturals>(*o) and is_a<Integer>(*elem)
1091 and down_cast<const Integer &>(*elem)
1092 .is_positive()) {
1093 kept_integers.insert(elem);
1094 } else if (is_a<Naturals0>(*o) and is_a<Integer>(*elem)
1095 and (not down_cast<const Integer &>(*elem)
1096 .is_negative())) {
1097 kept_integers.insert(elem);
1098 }
1099 } else {
1100 others.insert(elem);
1101 }
1102 }
1103 if (kept_integers.empty()) {
1104 if (others.empty()) {
1105 return emptyset();
1106 } else {
1107 return SymEngine::make_set_intersection(
1108 {integers(), finiteset(others)});
1109 }
1110 } else {
1111 if (others.empty()) {
1112 return finiteset(kept_integers);
1113 } else {
1114 others.insert(kept_integers.begin(), kept_integers.end());
1115 return SymEngine::make_set_intersection(
1116 {integers(), finiteset(others)});
1117 }
1118 }
1119 }
1120 if (is_a<UniversalSet>(*o) or is_a<EmptySet>(*o) or is_a<Union>(*o)) {
1121 return (*o).set_intersection(rcp_from_this_cast<const Set>());
1122 }
1123 return make_set_intersection({rcp_from_this_cast<const Set>(), o});
1124}
T insert(T... args)
RCP< const EmptySet > emptyset()
Definition: sets.h:590
RCP< const Integers > integers()
Definition: sets.h:572

◆ set_union()

RCP< const Set > SymEngine::FiniteSet::set_union ( const RCP< const Set > &  o) const
overridevirtual

Implements SymEngine::Set.

Definition at line 903 of file sets.cpp.

904{
905 if (is_a<FiniteSet>(*o)) {
906 const FiniteSet &other = down_cast<const FiniteSet &>(*o);
907 set_basic container;
908 std::set_union(container_.begin(), container_.end(),
909 other.container_.begin(), other.container_.end(),
910 std::inserter(container, container.begin()),
911 RCPBasicKeyLess{});
912 return finiteset(container);
913 }
914 if (is_a<Interval>(*o)) {
915 set_basic container;
916 const Interval &other = down_cast<const Interval &>(*o);
917 bool left = other.get_left_open(), right = other.get_right_open();
918 for (const auto &a : container_) {
919 auto contain = o->contains(a);
920 if (eq(*contain, *boolFalse)) {
921 if (left)
922 if (eq(*other.get_start(), *a)) {
923 left = false;
924 continue;
925 }
926 if (right)
927 if (eq(*other.get_end(), *a)) {
928 right = false;
929 continue;
930 }
931 container.insert(a);
932 } else if (is_a<Contains>(*contain)) {
933 container.insert(a);
934 }
935 }
936 if (not container.empty()) {
937 if (left == other.get_left_open()
938 and right == other.get_right_open()) {
939 return SymEngine::make_set_union({finiteset(container), o});
940 } else {
941 return SymEngine::make_set_union(
942 set_set({finiteset(container),
943 interval(other.get_start(), other.get_end(), left,
944 right)}));
945 }
946 } else {
947 if (left == other.get_left_open()
948 and right == other.get_right_open()) {
949 return o;
950 } else {
951 return interval(other.get_start(), other.get_end(), left,
952 right);
953 }
954 }
955 }
956 if (is_a<Complexes>(*o)) {
957 set_basic container;
958 for (const auto &elem : container_) {
959 if (!is_a_Number(*elem)) {
960 container.insert(elem);
961 }
962 }
963 if (container.empty()) {
964 return complexes();
965 } else {
966 return SymEngine::make_set_union(
967 {complexes(), finiteset(container)});
968 }
969 }
970 if (is_a<Reals>(*o)) {
971 set_basic container;
972 for (const auto &elem : container_) {
973 if (!is_a_Number(*elem)
974 || down_cast<const Number &>(*elem).is_complex()) {
975 container.insert(elem);
976 }
977 }
978 if (container.empty()) {
979 return reals();
980 } else {
981 return SymEngine::make_set_union({reals(), finiteset(container)});
982 }
983 }
984 if (is_a<Rationals>(*o)) {
985 set_basic container;
986 for (const auto &elem : container_) {
987 if (!is_a_Number(*elem)
988 || down_cast<const Number &>(*elem).is_complex()) {
989 container.insert(elem);
990 }
991 }
992 if (container.empty()) {
993 return rationals();
994 } else {
995 return SymEngine::make_set_union(
996 {rationals(), finiteset(container)});
997 }
998 }
999 if (is_a<Integers>(*o) or is_a<Naturals>(*o) or is_a<Naturals0>(*o)) {
1000 set_basic container;
1001 for (const auto &elem : container_) {
1002 if (is_a<Integers>(*o)) {
1003 if (not is_a<Integer>(*elem)) {
1004 container.insert(elem);
1005 }
1006 } else if (is_a<Naturals>(*o)) {
1007 if (not(is_a<Integer>(*elem)
1008 and down_cast<const Integer &>(*elem).is_positive())) {
1009 container.insert(elem);
1010 }
1011 } else {
1012 if (not(is_a<Integer>(*elem)
1013 and not down_cast<const Integer &>(*elem)
1014 .is_negative())) {
1015 container.insert(elem);
1016 }
1017 }
1018 }
1019 if (container.empty()) {
1020 return o;
1021 } else {
1022 return SymEngine::make_set_union({o, finiteset(container)});
1023 }
1024 }
1025 if (is_a<UniversalSet>(*o) or is_a<EmptySet>(*o) or is_a<Union>(*o)) {
1026 return (*o).set_union(rcp_from_this_cast<const Set>());
1027 }
1028 return SymEngine::make_set_union({rcp_from_this_cast<const Set>(), o});
1029}
T left(T... args)
RCP< const Reals > reals()
Definition: sets.h:560
RCP< const Rationals > rationals()
Definition: sets.h:566
RCP< const Complexes > complexes()
Definition: sets.h:554
T set_union(T... args)

Field Documentation

◆ container_

set_basic SymEngine::FiniteSet::container_
private

Definition at line 118 of file sets.h.

◆ type_code_id

const TypeID SymEngine::FiniteSet::type_code_id = SYMENGINE_FINITESET
static

Type_code_id shared by all instances

Definition at line 121 of file sets.h.


The documentation for this class was generated from the following files: