1 /** @file relational.cpp
3 * Implementation of relations between expressions */
10 // default constructor, destructor, copy constructor assignment operator and helpers
15 relational::relational() : basic(TINFO_RELATIONAL)
17 debugmsg("relational default constructor",LOGLEVEL_CONSTRUCT);
20 relational::~relational()
22 debugmsg("relational destructor",LOGLEVEL_DESTRUCT);
26 relational::relational(relational const & other)
28 debugmsg("relational copy constructor",LOGLEVEL_CONSTRUCT);
32 relational const & relational::operator=(relational const & other)
34 debugmsg("relational operator=",LOGLEVEL_ASSIGNMENT);
44 void relational::copy(relational const & other)
52 void relational::destroy(bool call_parent)
54 if (call_parent) basic::destroy(call_parent);
63 relational::relational(ex const & lhs, ex const & rhs, operators oper) : basic(TINFO_RELATIONAL)
65 debugmsg("relational constructor ex,ex,operator",LOGLEVEL_CONSTRUCT);
72 // functions overriding virtual functions from bases classes
77 basic * relational::duplicate() const
79 debugmsg("relational duplicate",LOGLEVEL_DUPLICATE);
80 return new relational(*this);
83 bool relational::info(unsigned inf) const
86 case info_flags::relation:
88 case info_flags::relation_equal:
90 case info_flags::relation_not_equal:
92 case info_flags::relation_less:
94 case info_flags::relation_less_or_equal:
95 return o==less_or_equal;
96 case info_flags::relation_greater:
98 case info_flags::relation_greater_or_equal:
99 return o==greater_or_equal;
104 int relational::nops() const
109 ex & relational::let_op(int const i)
114 return i==0 ? lh : rh;
117 ex relational::eval(int level) const
122 if (level == -max_recursion_level) {
123 throw(std::runtime_error("max recursion level reached"));
125 return (new relational(lh.eval(level-1),rh.eval(level-1),o))->
126 setflag(status_flags::dynallocated |
127 status_flags::evaluated );
130 ex relational::evalf(int level) const
135 if (level == -max_recursion_level) {
136 throw(std::runtime_error("max recursion level reached"));
138 return (new relational(lh.eval(level-1),rh.eval(level-1),o))->
139 setflag(status_flags::dynallocated);
142 ex relational::simplify_ncmul(exvector const & v) const
144 return lh.simplify_ncmul(v);
149 int relational::compare_same_type(basic const & other) const
151 ASSERT(is_exactly_of_type(other, relational));
152 relational const & oth=static_cast<relational const &>(const_cast<basic &>(other));
157 cmpval=lh.compare(oth.lh);
159 return rh.compare(oth.rh);
171 unsigned relational::return_type(void) const
173 ASSERT(lh.return_type()==rh.return_type());
174 return lh.return_type();
177 unsigned relational::return_type_tinfo(void) const
179 ASSERT(lh.return_type_tinfo()==rh.return_type_tinfo());
180 return lh.return_type_tinfo();
184 // new virtual functions which can be overridden by derived classes
190 // non-virtual functions in this class
195 relational::operator bool() const
197 // please note that (a<b) == false does not imply (a>=b) == true
198 // a false result means the comparison is either false or undecidable
199 // (except for !=, where true means unequal or undecidable)
201 if (!is_ex_exactly_of_type(df,numeric)) {
202 return o==not_equal ? true : false; // cannot decide on non-numerical results
204 int cmpval=ex_to_numeric(df).compare(numZERO());
221 case greater_or_equal:
225 throw(std::logic_error("invalid relational operator"));
231 // static member variables
236 unsigned relational::precedence=20;
242 const relational some_relational;
243 type_info const & typeid_relational=typeid(some_relational);