From: Chris Dams Date: Thu, 25 May 2006 16:17:38 +0000 (+0000) Subject: Possbility for positive symbols/numbers. X-Git-Tag: release_1-4-0~87 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=f79727f9acf4f78ff71cbe324c333c234c211cb5;hp=aa378587448168767c40dcfc4c819d2893fc24a5 Possbility for positive symbols/numbers. --- diff --git a/ginac/constant.cpp b/ginac/constant.cpp index cff955a9..dd1c170b 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -142,7 +142,9 @@ bool constant::info(unsigned inf) const if (inf == info_flags::polynomial) return true; if (inf == info_flags::real) - return domain == domain::real; + return domain==domain::real || domain==domain::positive ; + if (inf==info_flags::positive || inf==info_flags::nonnegative) + return domain == domain::positive; else return inherited::info(inf); } @@ -164,21 +166,21 @@ bool constant::is_polynomial(const ex & var) const ex constant::conjugate() const { - if ( domain == domain::real ) + if ( domain==domain::real || domain==domain::positive ) return *this; return conjugate_function(*this).hold(); } ex constant::real_part() const { - if ( domain == domain::real ) + if ( domain==domain::real || domain==domain::positive ) return *this; return real_part_function(*this).hold(); } ex constant::imag_part() const { - if ( domain == domain::real ) + if ( domain==domain::real || domain==domain::positive ) return 0; return imag_part_function(*this).hold(); } @@ -244,13 +246,13 @@ unsigned constant::next_serial = 0; ////////// /** Pi. (3.14159...) Diverts straight into CLN for evalf(). */ -const constant Pi("Pi", PiEvalf, "\\pi", domain::real); +const constant Pi("Pi", PiEvalf, "\\pi", domain::positive); /** Euler's constant. (0.57721...) Sometimes called Euler-Mascheroni constant. * Diverts straight into CLN for evalf(). */ -const constant Euler("Euler", EulerEvalf, "\\gamma_E", domain::real); +const constant Euler("Euler", EulerEvalf, "\\gamma_E", domain::positive); /** Catalan's constant. (0.91597...) Diverts straight into CLN for evalf(). */ -const constant Catalan("Catalan", CatalanEvalf, "G", domain::real); +const constant Catalan("Catalan", CatalanEvalf, "G", domain::positive); } // namespace GiNaC diff --git a/ginac/flags.h b/ginac/flags.h index 8c4bdfb2..6cf3ea94 100644 --- a/ginac/flags.h +++ b/ginac/flags.h @@ -61,7 +61,8 @@ class domain { public: enum { complex, - real + real, + positive }; }; @@ -196,7 +197,7 @@ public: class info_flags { public: enum { - // answered by class numeric + // answered by class numeric and symbols/constants in particular domains numeric, real, rational, diff --git a/ginac/inifcns.cpp b/ginac/inifcns.cpp index c49fc702..dad9d9e7 100644 --- a/ginac/inifcns.cpp +++ b/ginac/inifcns.cpp @@ -190,8 +190,14 @@ static ex abs_eval(const ex & arg) { if (is_exactly_a(arg)) return abs(ex_to(arg)); - else - return abs(arg).hold(); + + if (arg.info(info_flags::nonnegative)) + return arg; + + if (is_ex_the_function(arg, abs)) + return arg; + + return abs(arg).hold(); } static void abs_print_latex(const ex & arg, const print_context & c) diff --git a/ginac/inifcns_trans.cpp b/ginac/inifcns_trans.cpp index 3f9c380b..657cdfab 100644 --- a/ginac/inifcns_trans.cpp +++ b/ginac/inifcns_trans.cpp @@ -246,11 +246,15 @@ static ex log_series(const ex &arg, static ex log_real_part(const ex & x) { + if (x.info(info_flags::nonnegative)) + return log(x).hold(); return log(abs(x)); } static ex log_imag_part(const ex & x) { + if (x.info(info_flags::nonnegative)) + return 0; return atan2(GiNaC::imag_part(x), GiNaC::real_part(x)); } diff --git a/ginac/symbol.cpp b/ginac/symbol.cpp index 59dda652..7e3b49d8 100644 --- a/ginac/symbol.cpp +++ b/ginac/symbol.cpp @@ -196,7 +196,9 @@ bool symbol::info(unsigned inf) const inf == info_flags::rational_function) return true; if (inf == info_flags::real) - return domain == domain::real; + return domain==domain::real || domain==domain::positive; + if (inf == info_flags::nonnegative) + return domain == domain::positive; else return inherited::info(inf); } @@ -228,14 +230,14 @@ ex symbol::conjugate() const ex symbol::real_part() const { - if (domain == domain::real) + if (domain==domain::real || domain==domain::positive) return *this; return real_part_function(*this).hold(); } ex symbol::imag_part() const { - if (domain == domain::real) + if (domain==domain::real || domain==domain::positive) return 0; return imag_part_function(*this).hold(); } diff --git a/ginac/symbol.h b/ginac/symbol.h index 9c7e526d..90013144 100644 --- a/ginac/symbol.h +++ b/ginac/symbol.h @@ -132,7 +132,10 @@ public: /** Specialization of is_exactly_a(obj) for realsymbol objects. */ template<> inline bool is_exactly_a(const basic & obj) { - return (obj.tinfo() == &symbol::tinfo_static) && (static_cast(obj).get_domain() == domain::real); + if (obj.tinfo() != &symbol::tinfo_static) + return false; + unsigned domain = static_cast(obj).get_domain(); + return domain==domain::real || domain==domain::positive; } // wrapper functions around member functions