]> www.ginac.de Git - ginac.git/commitdiff
Possbility for positive symbols/numbers.
authorChris Dams <Chris.Dams@mi.infn.it>
Thu, 25 May 2006 16:17:38 +0000 (16:17 +0000)
committerChris Dams <Chris.Dams@mi.infn.it>
Thu, 25 May 2006 16:17:38 +0000 (16:17 +0000)
ginac/constant.cpp
ginac/flags.h
ginac/inifcns.cpp
ginac/inifcns_trans.cpp
ginac/symbol.cpp
ginac/symbol.h

index cff955a9488bcb5b09298b4dc513a656a6dc1a3e..dd1c170b6c21ba425da8cbc2a82590ad525c1dd2 100644 (file)
@@ -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
index 8c4bdfb2ae16ae9a22084268d1e2c23f3539bb42..6cf3ea94dde8b34e88b477d6d075ec7d97e3525c 100644 (file)
@@ -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,
index c49fc7021aa5694c1862d8ff743ac9f7936b60e6..dad9d9e7702b1424300204de0acdc47c967f962b 100644 (file)
@@ -190,8 +190,14 @@ static ex abs_eval(const ex & arg)
 {
        if (is_exactly_a<numeric>(arg))
                return abs(ex_to<numeric>(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)
index 3f9c380b6dd51fe60708a275175f1831a63c1787..657cdfabb51275372934cd49ff96a813f606757d 100644 (file)
@@ -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));
 }
 
index 59dda652a133f3e71b0c0930696beb41139947d1..7e3b49d8bc7c0e59bcecf4c4034cfaaed1050a47 100644 (file)
@@ -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();
 }
index 9c7e526d6dca881b89c35a49e39fff2feb89c27b..90013144ccd5d7f88e28a280055b54c814c193df 100644 (file)
@@ -132,7 +132,10 @@ public:
 /** Specialization of is_exactly_a<realsymbol>(obj) for realsymbol objects. */
 template<> inline bool is_exactly_a<realsymbol>(const basic & obj)
 {
-       return (obj.tinfo() == &symbol::tinfo_static) && (static_cast<const symbol &>(obj).get_domain() == domain::real);
+       if (obj.tinfo() != &symbol::tinfo_static)
+               return false;
+       unsigned domain = static_cast<const symbol &>(obj).get_domain();
+       return domain==domain::real || domain==domain::positive;
 }
 
 // wrapper functions around member functions