]> www.ginac.de Git - ginac.git/blobdiff - ginac/power.cpp
Add mul::info() and add::info() support for numeric info_flags.
[ginac.git] / ginac / power.cpp
index a4a33c576ca415e0a3baa7e6b089fd8dae22b81f..7ae0f04d69e4de2760d8eab81c3e17de90b989b0 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's symbolic exponentiation (basis^exponent). */
 
 /*
- *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2009 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
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <vector>
-#include <iostream>
-#include <stdexcept>
-#include <limits>
-
 #include "power.h"
 #include "expairseq.h"
 #include "add.h"
 #include "relational.h"
 #include "compiler.h"
 
+#include <iostream>
+#include <limits>
+#include <stdexcept>
+#include <vector>
+
 namespace GiNaC {
 
 GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(power, basic,
@@ -59,7 +59,7 @@ typedef std::vector<int> intvector;
 // default constructor
 //////////
 
-power::power() : inherited(&power::tinfo_static) { }
+power::power() { }
 
 //////////
 // other constructors
@@ -71,8 +71,9 @@ power::power() : inherited(&power::tinfo_static) { }
 // archiving
 //////////
 
-power::power(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst)
+void power::read_archive(const archive_node &n, lst &sym_lst)
 {
+       inherited::read_archive(n, sym_lst);
        n.find_ex("basis", basis, sym_lst);
        n.find_ex("exponent", exponent, sym_lst);
 }
@@ -84,8 +85,6 @@ void power::archive(archive_node &n) const
        n.add_ex("exponent", exponent);
 }
 
-DEFAULT_UNARCHIVE(power)
-
 //////////
 // functions overriding virtual functions from base classes
 //////////
@@ -241,6 +240,8 @@ bool power::info(unsigned inf) const
                               basis.info(inf);
                case info_flags::expanded:
                        return (flags & status_flags::expanded);
+               case info_flags::positive:
+                       return basis.info(info_flags::positive) && exponent.info(info_flags::real);
                case info_flags::has_indices: {
                        if (flags & status_flags::has_indices)
                                return true;
@@ -377,17 +378,13 @@ ex power::eval(int level) const
        const ex & ebasis    = level==1 ? basis    : basis.eval(level-1);
        const ex & eexponent = level==1 ? exponent : exponent.eval(level-1);
        
-       bool basis_is_numerical = false;
-       bool exponent_is_numerical = false;
-       const numeric *num_basis;
-       const numeric *num_exponent;
+       const numeric *num_basis = NULL;
+       const numeric *num_exponent = NULL;
        
        if (is_exactly_a<numeric>(ebasis)) {
-               basis_is_numerical = true;
                num_basis = &ex_to<numeric>(ebasis);
        }
        if (is_exactly_a<numeric>(eexponent)) {
-               exponent_is_numerical = true;
                num_exponent = &ex_to<numeric>(eexponent);
        }
        
@@ -404,7 +401,7 @@ ex power::eval(int level) const
                return ebasis;
 
        // ^(0,c1) -> 0 or exception  (depending on real value of c1)
-       if (ebasis.is_zero() && exponent_is_numerical) {
+       if ( ebasis.is_zero() && num_exponent ) {
                if ((num_exponent->real()).is_zero())
                        throw (std::domain_error("power::eval(): pow(0,I) is undefined"));
                else if ((num_exponent->real()).is_negative())
@@ -425,11 +422,11 @@ ex power::eval(int level) const
        if (is_exactly_a<power>(ebasis) && ebasis.op(0).info(info_flags::positive) && ebasis.op(1).info(info_flags::real))
                return power(ebasis.op(0), ebasis.op(1) * eexponent);
 
-       if (exponent_is_numerical) {
+       if ( num_exponent ) {
 
                // ^(c1,c2) -> c1^c2  (c1, c2 numeric(),
                // except if c1,c2 are rational, but c1^c2 is not)
-               if (basis_is_numerical) {
+               if ( num_basis ) {
                        const bool basis_is_crational = num_basis->is_crational();
                        const bool exponent_is_crational = num_exponent->is_crational();
                        if (!basis_is_crational || !exponent_is_crational) {
@@ -769,7 +766,7 @@ unsigned power::return_type() const
        return basis.return_type();
 }
 
-tinfo_t power::return_type_tinfo() const
+return_type_t power::return_type_tinfo() const
 {
        return basis.return_type_tinfo();
 }
@@ -1061,4 +1058,6 @@ ex power::expand_mul(const mul & m, const numeric & n, unsigned options, bool fr
        return result;
 }
 
+GINAC_BIND_UNARCHIVER(power);
+
 } // namespace GiNaC