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

Public Member Functions

virtual void accept (Visitor &v) const
 
virtual void accept (EvalRealDoubleVisitorFinal &v) const
 
virtual hash_t __hash__ () const
 
virtual bool __eq__ (const Basic &o) const
 Test equality. More...
 
virtual int compare (const Basic &o) const
 
 Interval (const RCP< const Number > &start, const RCP< const Number > &end, const bool left_open=false, const bool right_open=false)
 
RCP< const Setopen () const
 
RCP< const Setclose () const
 
RCP< const SetLopen () const
 
RCP< const SetRopen () const
 
virtual RCP< const Setset_union (const RCP< const Set > &o) const
 
virtual RCP< const Setset_intersection (const RCP< const Set > &o) const
 
virtual RCP< const Setset_complement (const RCP< const Set > &o) const
 
virtual RCP< const Booleancontains (const RCP< const Basic > &a) const
 
virtual vec_basic get_args () const
 Returns the list of arguments. More...
 
const RCP< const Number > & get_start () const
 
const RCP< const Number > & get_end () const
 
const bool & get_left_open () const
 
const bool & get_right_open () const
 
- Public Member Functions inherited from SymEngine::Set
virtual vec_basic get_args () const =0
 Returns the list of arguments. More...
 
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. More...
 
 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. More...
 
bool __neq__ (const Basic &o) const
 true if this is not equal to o. More...
 
int __cmp__ (const Basic &o) const
 Comparison operator. More...
 
virtual int compare (const Basic &o) const =0
 
std::string __str__ () const
 
std::string dumps () const
 Returns a string of the instance serialized. More...
 
RCP< const Basicsubs (const map_basic_basic &subs_dict) const
 Substitutes 'subs_dict' into 'self'. More...
 
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 More...
 
virtual vec_basic get_args () const =0
 Returns the list of arguments. More...
 
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) More...
 
RCP< const Basicrcp_from_this () const
 Get RCP<const T> pointer to self (it will cast the pointer to const T) More...
 
RCP< const T2 > rcp_from_this_cast () const
 Get RCP<T2> pointer to self (it will cast the pointer to T2) More...
 
unsigned int use_count () const
 

Static Public Member Functions

static bool is_canonical (const RCP< const Number > &start, const RCP< const Number > &end, bool left_open, bool right_open)
 
- Static Public Member Functions inherited from SymEngine::Basic
static RCP< const Basicloads (const std::string &)
 Creates an instance of a serialized string. More...
 

Static Public Attributes

static const TypeID type_code_id = SYMENGINE_INTERVAL
 

Private Attributes

RCP< const Numberstart_
 
RCP< const Numberend_
 
bool left_open_
 
bool right_open_
 

Additional Inherited Members

- Data Fields inherited from SymEngine::Basic
TypeID type_code_
 

Detailed Description

Definition at line 145 of file sets.h.

Constructor & Destructor Documentation

◆ Interval()

SymEngine::Interval::Interval ( const RCP< const Number > &  start,
const RCP< const Number > &  end,
const bool  left_open = false,
const bool  right_open = false 
)

Definition at line 10 of file sets.cpp.

12 : start_(start), end_(end), left_open_(left_open), right_open_(right_open)
13{
14 SYMENGINE_ASSIGN_TYPEID()
15 SYMENGINE_ASSERT(
16 Interval::is_canonical(start_, end_, left_open_, right_open_));
17}

Member Function Documentation

◆ __eq__()

bool SymEngine::Interval::__eq__ ( const Basic o) const
virtual

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 43 of file sets.cpp.

44{
45 if (is_a<Interval>(o)) {
46 const Interval &s = down_cast<const Interval &>(o);
47 return ((this->left_open_ == s.left_open_)
48 and (this->right_open_ == s.right_open_)
49 and eq(*this->start_, *s.start_) and eq(*this->end_, *s.end_));
50 }
51 return false;
52}
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21

◆ __hash__()

hash_t SymEngine::Interval::__hash__ ( ) const
virtual

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 33 of file sets.cpp.

34{
35 hash_t seed = SYMENGINE_INTERVAL;
36 hash_combine<Basic>(seed, *start_);
37 hash_combine<Basic>(seed, *end_);
38 hash_combine<bool>(seed, left_open_);
39 hash_combine<bool>(seed, right_open_);
40 return seed;
41}

◆ accept() [1/2]

virtual void SymEngine::Interval::accept ( EvalRealDoubleVisitorFinal v) const
virtual

Implements SymEngine::Basic.

◆ accept() [2/2]

virtual void SymEngine::Interval::accept ( Visitor v) const
virtual

Implements SymEngine::Basic.

◆ close()

RCP< const Set > SymEngine::Interval::close ( ) const

Definition at line 92 of file sets.cpp.

93{
94 return interval(start_, end_, false, false);
95}
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:583

◆ compare()

int SymEngine::Interval::compare ( const Basic o) const
virtual

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 54 of file sets.cpp.

55{
56 // compares two interval based on their length
57 SYMENGINE_ASSERT(is_a<Interval>(s))
58 const Interval &o = down_cast<const Interval &>(s);
59 if (left_open_ and not o.left_open_) {
60 return -1;
61 } else if (not left_open_ and o.left_open_) {
62 return 1;
63 } else if (right_open_ and not o.right_open_) {
64 return 1;
65 } else if (not right_open_ and o.right_open_) {
66 return -1;
67 } else {
68 auto temp = start_->__cmp__(*(o.start_));
69 if (temp != 0) {
70 return temp;
71 } else {
72 return end_->__cmp__(*(o.end_));
73 }
74 }
75}

◆ contains()

RCP< const Boolean > SymEngine::Interval::contains ( const RCP< const Basic > &  a) const
virtual

Implements SymEngine::Set.

Definition at line 97 of file sets.cpp.

98{
99 if (not is_a_Number(*a)) {
100 if (is_a_Set(*a)) {
101 return boolean(false);
102 } else {
103 return make_rcp<Contains>(a, rcp_from_this_cast<const Set>());
104 }
105 }
106 if (eq(*start_, *a))
107 return boolean(not left_open_);
108 if (eq(*end_, *a))
109 return boolean(not right_open_);
110 if (eq(*min({end_, a}), *end_) or eq(*max({start_, a}), *start_))
111 return boolean(false);
112 return boolean(true);
113}
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 Basic > min(const vec_basic &arg)
Canonicalize Min:
Definition: functions.cpp:3659

◆ get_args()

vec_basic SymEngine::Interval::get_args ( ) const
virtual

Returns the list of arguments.

Implements SymEngine::Set.

Definition at line 267 of file sets.cpp.

268{
269 return {start_, end_, boolean(left_open_), boolean(right_open_)};
270}

◆ get_end()

const RCP< const Number > & SymEngine::Interval::get_end ( ) const
inline

Definition at line 180 of file sets.h.

181 {
182 return end_;
183 }

◆ get_left_open()

const bool & SymEngine::Interval::get_left_open ( ) const
inline

Definition at line 184 of file sets.h.

185 {
186 return this->left_open_;
187 }

◆ get_right_open()

const bool & SymEngine::Interval::get_right_open ( ) const
inline

Definition at line 188 of file sets.h.

189 {
190 return this->right_open_;
191 }

◆ get_start()

const RCP< const Number > & SymEngine::Interval::get_start ( ) const
inline

Definition at line 176 of file sets.h.

177 {
178 return start_;
179 }

◆ is_canonical()

bool SymEngine::Interval::is_canonical ( const RCP< const Number > &  start,
const RCP< const Number > &  end,
bool  left_open,
bool  right_open 
)
static

Definition at line 19 of file sets.cpp.

22{
23 if (is_a<Complex>(*s) or is_a<Complex>(*e))
24 throw NotImplementedError("Complex set not implemented");
25 if (eq(*e, *s)) {
26 return false;
27 } else if (eq(*min({s, e}), *e)) {
28 return false;
29 }
30 return true;
31}

◆ Lopen()

RCP< const Set > SymEngine::Interval::Lopen ( ) const

Definition at line 82 of file sets.cpp.

83{
84 return interval(start_, end_, true, false);
85}

◆ open()

RCP< const Set > SymEngine::Interval::open ( ) const

Definition at line 77 of file sets.cpp.

78{
79 return interval(start_, end_, true, true);
80}

◆ Ropen()

RCP< const Set > SymEngine::Interval::Ropen ( ) const

Definition at line 87 of file sets.cpp.

88{
89 return interval(start_, end_, false, true);
90}

◆ set_complement()

RCP< const Set > SymEngine::Interval::set_complement ( const RCP< const Set > &  o) const
virtual

Implements SymEngine::Set.

Definition at line 249 of file sets.cpp.

250{
251 if (is_a<Interval>(*o)) {
252 set_set cont;
253 const Interval &other = down_cast<const Interval &>(*o);
254 if (eq(*max({start_, other.start_}), *start_)) {
255 cont.insert(interval(other.get_start(), start_,
256 other.get_left_open(), not left_open_));
257 }
258 if (eq(*min({end_, other.end_}), *end_)) {
259 cont.insert(interval(end_, other.get_end(), not right_open_,
260 other.get_right_open()));
261 }
262 return SymEngine::set_union(cont);
263 }
264 return SymEngine::set_complement_helper(rcp_from_this_cast<const Set>(), o);
265}

◆ set_intersection()

RCP< const Set > SymEngine::Interval::set_intersection ( const RCP< const Set > &  o) const
virtual

Implements SymEngine::Set.

Definition at line 115 of file sets.cpp.

116{
117 if (is_a<Interval>(*o)) {
118 const Interval &other = down_cast<const Interval &>(*o);
119 RCP<const Number> start, end;
120 bool left_open, right_open;
121 RCP<const Basic> start_end, end_start;
122 start_end = min({this->start_, other.end_});
123 end_start = min({this->end_, other.start_});
124
125 if (eq(*this->start_, *start_end) and eq(*other.start_, *end_start)) {
126 RCP<const Basic> start_start, end_end;
127 start_start = min({this->start_, other.start_});
128 end_end = min({this->end_, other.end_});
129 if (neq(*this->start_, *other.start_)) {
130 if (eq(*this->start_, *start_start)) {
131 start = other.start_;
132 left_open = other.left_open_;
133 } else {
134 start = this->start_;
135 left_open = this->left_open_;
136 }
137 } else {
138 start = this->start_;
139 left_open = this->left_open_ or other.left_open_;
140 }
141
142 if (neq(*this->end_, *other.end_)) {
143 if (eq(*this->end_, *end_end)) {
144 end = this->end_;
145 right_open = this->right_open_;
146 } else {
147 end = other.end_;
148 right_open = other.right_open_;
149 }
150 } else {
151 end = this->end_;
152 right_open = this->right_open_ or other.right_open_;
153 }
154 return interval(start, end, left_open, right_open);
155 } else {
156 return emptyset();
157 }
158 }
159 if (is_a<Integers>(*o) or is_a<Naturals>(*o) or is_a<Naturals0>(*o)) {
160 if (is_a_Number(*start_) and is_a_Number(*end_)) {
161 auto first = SymEngine::ceiling(start_);
162 auto last = SymEngine::floor(end_);
163 if (is_a<Naturals>(*o)
164 and not down_cast<const Integer &>(*first).is_positive()) {
165 first = integer(1);
166 } else if (is_a<Naturals0>(*o)
167 and down_cast<const Integer &>(*first).is_negative()) {
168 first = integer(0);
169 }
170 if (eq(*first, *start_) and left_open_) {
171 first = add(first, integer(1));
172 }
173 if (eq(*last, *end_) and right_open_) {
174 last = add(last, integer(-1));
175 }
176 if (eq(*Lt(last, first), *boolTrue)) {
177 return emptyset();
178 }
179 set_basic container;
180 while (eq(*Ge(last, first), *boolTrue)) {
181 container.insert(first);
182 first = add(first, integer(1));
183 }
184 return finiteset(container);
185 } else {
186 return SymEngine::set_intersection(
187 {rcp_from_this_cast<const Set>(), o});
188 }
189 }
190 if (is_a<UniversalSet>(*o) or is_a<EmptySet>(*o) or is_a<FiniteSet>(*o)
191 or is_a<Union>(*o) or is_a<Rationals>(*o) or is_a<Reals>(*o)
192 or is_a<Complexes>(*o)) {
193 return (*o).set_intersection(rcp_from_this_cast<const Set>());
194 }
195 throw SymEngineException("Not implemented Intersection class");
196}
T end(T... args)
T insert(T... args)
RCP< const Boolean > Ge(const RCP< const Basic > &lhs, const RCP< const Basic > &rhs)
Convenience function returning LessThan object.
Definition: logic.cpp:744
RCP< const EmptySet > emptyset()
Definition: sets.h:562
RCP< const Set > finiteset(const set_basic &container)
Definition: sets.h:574
RCP< const Boolean > Lt(const RCP< const Basic > &lhs, const RCP< const Basic > &rhs)
Returns the canonicalized StrictLessThan object from the arguments.
Definition: logic.cpp:768
RCP< const Basic > ceiling(const RCP< const Basic > &arg)
Canonicalize Ceiling:
Definition: functions.cpp:705
RCP< const Basic > floor(const RCP< const Basic > &arg)
Canonicalize Floor:
Definition: functions.cpp:611
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
Definition: add.cpp:425
bool neq(const Basic &a, const Basic &b)
Checks inequality for a and b
Definition: basic-inl.h:29
std::enable_if< std::is_integral< T >::value, RCP< constInteger > >::type integer(T i)
Definition: integer.h:200

◆ set_union()

RCP< const Set > SymEngine::Interval::set_union ( const RCP< const Set > &  o) const
virtual

Implements SymEngine::Set.

Definition at line 206 of file sets.cpp.

207{
208 if (is_a<Interval>(*o)) {
209 const Interval &other = down_cast<const Interval &>(*o);
210 RCP<const Basic> start_start, end_end, m;
211 RCP<const Number> start, end;
212 bool left_open, right_open;
213 start_start = max({this->start_, other.start_});
214 end_end = min({this->end_, other.end_});
215 m = min({start_start, end_end});
216 if ((eq(*end_end, *start_start) and eq(*end_end, *m)
217 and ((eq(*end_end, *this->end_) and this->right_open_)
218 or (eq(*end_end, *other.end_) and other.right_open_)))
219 or (eq(*end_end, *m) and not eq(*end_end, *start_start))) {
220 return SymEngine::make_set_union(
221 {rcp_from_this_cast<const Set>(), o});
222 } else {
223 if (eq(*min({this->start_, other.start_}), *this->start_)) {
224 start = this->start_;
225 } else {
226 start = other.start_;
227 }
228 if (eq(*max({this->end_, other.end_}), *this->end_)) {
229 end = this->end_;
230 } else {
231 end = other.end_;
232 }
233 left_open = ((neq(*this->start_, *start) or this->left_open_)
234 and (neq(*other.start_, *start) or other.left_open_));
235 right_open = ((neq(*this->end_, *end) or this->right_open_)
236 and (neq(*other.end_, *end) or other.right_open_));
237 return interval(start, end, left_open, right_open);
238 }
239 }
240 if (is_a<UniversalSet>(*o) or is_a<EmptySet>(*o) or is_a<FiniteSet>(*o)
241 or is_a<Union>(*o) or is_a<Complexes>(*o) or is_a<Reals>(*o)
242 or is_a<Rationals>(*o) or is_a<Integers>(*o) or is_a<Naturals>(*o)
243 or is_a<Naturals0>(*o)) {
244 return (*o).set_union(rcp_from_this_cast<const Set>());
245 }
246 return SymEngine::make_set_union({rcp_from_this_cast<const Set>(), o});
247}

Field Documentation

◆ end_

RCP<const Number> SymEngine::Interval::end_
private

Definition at line 149 of file sets.h.

◆ left_open_

bool SymEngine::Interval::left_open_
private

Definition at line 150 of file sets.h.

◆ right_open_

bool SymEngine::Interval::right_open_
private

Definition at line 150 of file sets.h.

◆ start_

RCP<const Number> SymEngine::Interval::start_
private

Definition at line 148 of file sets.h.

◆ type_code_id

const TypeID SymEngine::Interval::type_code_id = SYMENGINE_INTERVAL
static

Type_code_id shared by all instances

Definition at line 153 of file sets.h.


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