904{
905 if (is_a<FiniteSet>(*o)) {
906 const FiniteSet &other = down_cast<const FiniteSet &>(*o);
907 set_basic container;
909 other.container_.begin(), other.container_.end(),
911 RCPBasicKeyLess{});
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)) {
924 continue;
925 }
926 if (right)
927 if (
eq(*other.get_end(), *a)) {
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(
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_) {
961 }
962 }
963 if (container.empty()) {
965 } else {
966 return SymEngine::make_set_union(
968 }
969 }
970 if (is_a<Reals>(*o)) {
971 set_basic container;
972 for (const auto &elem : container_) {
974 || down_cast<const Number &>(*elem).is_complex()) {
976 }
977 }
978 if (container.empty()) {
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_) {
988 || down_cast<const Number &>(*elem).is_complex()) {
990 }
991 }
992 if (container.empty()) {
994 } else {
995 return SymEngine::make_set_union(
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)) {
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}
RCP< const Reals > reals()
RCP< const Rationals > rationals()
RCP< const Complexes > complexes()