X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Frelational.cpp;h=324b2a5d72a82d4809a22f85a9c1f4e5dbd9ce23;hp=05fe56e8b0103b8348ad6d7d418c8a17b11d0d7d;hb=982f603551fad1a9d1242b5523334e4d5831fb9e;hpb=b66548802c56b34d6b212a0196d622937841ca61 diff --git a/ginac/relational.cpp b/ginac/relational.cpp index 05fe56e8..324b2a5d 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -3,7 +3,7 @@ * Implementation of relations between expressions */ /* - * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -33,14 +33,14 @@ namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(relational, basic, print_func(&relational::do_print). - print_func(&basic::do_print_tree). + print_func(&relational::do_print_tree). print_func(&relational::do_print_python_repr)) ////////// // default constructor ////////// -relational::relational() : basic(TINFO_relational) {} +relational::relational() : basic(&relational::tinfo_static) {} ////////// // other constructors @@ -48,7 +48,7 @@ relational::relational() : basic(TINFO_relational) {} // public -relational::relational(const ex & lhs, const ex & rhs, operators oper) : basic(TINFO_relational), lh(lhs), rh(rhs), o(oper) {} +relational::relational(const ex & lhs, const ex & rhs, operators oper) : basic(&relational::tinfo_static), lh(lhs), rh(rhs), o(oper) {} ////////// // archiving @@ -164,7 +164,14 @@ ex relational::op(size_t i) const ex relational::map(map_function & f) const { - return (new relational(f(lh), f(rh), o))->setflag(status_flags::dynallocated); + const ex &mapped_lh = f(lh); + const ex &mapped_rh = f(rh); + + if (!are_ex_trivially_equal(lh, mapped_lh) + || !are_ex_trivially_equal(rh, mapped_rh)) + return (new relational(mapped_lh, mapped_rh, o))->setflag(status_flags::dynallocated); + else + return *this; } ex relational::eval(int level) const @@ -243,7 +250,7 @@ unsigned relational::return_type() const return lh.return_type(); } -unsigned relational::return_type_tinfo() const +tinfo_t relational::return_type_tinfo() const { GINAC_ASSERT(lh.return_type_tinfo()==rh.return_type_tinfo()); return lh.return_type_tinfo(); @@ -251,7 +258,7 @@ unsigned relational::return_type_tinfo() const unsigned relational::calchash() const { - unsigned v = golden_ratio_hash(tinfo()); + unsigned v = golden_ratio_hash((p_int)tinfo()); unsigned lhash = lh.gethash(); unsigned rhash = rh.gethash(); @@ -331,13 +338,13 @@ relational::operator relational::safe_bool() const case not_equal: return make_safe_bool(!ex_to(df).is_zero()); case less: - return make_safe_bool(ex_to(df)<_num0); + return make_safe_bool(ex_to(df)<(*_num0_p)); case less_or_equal: - return make_safe_bool(ex_to(df)<=_num0); + return make_safe_bool(ex_to(df)<=(*_num0_p)); case greater: - return make_safe_bool(ex_to(df)>_num0); + return make_safe_bool(ex_to(df)>(*_num0_p)); case greater_or_equal: - return make_safe_bool(ex_to(df)>=_num0); + return make_safe_bool(ex_to(df)>=(*_num0_p)); default: throw(std::logic_error("invalid relational operator")); }