X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fadd.cpp;h=6548366ee16f1facb3dab2c1751444730171f236;hp=b37ab79def6926ca36c3dc804f068580c10b7b09;hb=5fb83676210401cc08fae91831514bac44502209;hpb=701f2c9acbf58e84d2c8619f00d8b7718fb1eafd diff --git a/ginac/add.cpp b/ginac/add.cpp index b37ab79d..6548366e 100644 --- a/ginac/add.cpp +++ b/ginac/add.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's sums of expressions. */ /* - * GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2010 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 @@ -20,10 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include -#include - #include "add.h" #include "mul.h" #include "archive.h" @@ -33,6 +29,11 @@ #include "clifford.h" #include "ncmul.h" +#include +#include +#include +#include + namespace GiNaC { GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(add, expairseq, @@ -48,7 +49,6 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(add, expairseq, add::add() { - tinfo_key = &add::tinfo_static; } ////////// @@ -59,7 +59,6 @@ add::add() add::add(const ex & lh, const ex & rh) { - tinfo_key = &add::tinfo_static; overall_coeff = _ex0; construct_from_2_ex(lh,rh); GINAC_ASSERT(is_canonical()); @@ -67,7 +66,6 @@ add::add(const ex & lh, const ex & rh) add::add(const exvector & v) { - tinfo_key = &add::tinfo_static; overall_coeff = _ex0; construct_from_exvector(v); GINAC_ASSERT(is_canonical()); @@ -75,7 +73,6 @@ add::add(const exvector & v) add::add(const epvector & v) { - tinfo_key = &add::tinfo_static; overall_coeff = _ex0; construct_from_epvector(v); GINAC_ASSERT(is_canonical()); @@ -83,7 +80,6 @@ add::add(const epvector & v) add::add(const epvector & v, const ex & oc) { - tinfo_key = &add::tinfo_static; overall_coeff = oc; construct_from_epvector(v); GINAC_ASSERT(is_canonical()); @@ -91,7 +87,6 @@ add::add(const epvector & v, const ex & oc) add::add(std::auto_ptr vp, const ex & oc) { - tinfo_key = &add::tinfo_static; GINAC_ASSERT(vp.get()!=0); overall_coeff = oc; construct_from_epvector(*vp); @@ -102,7 +97,7 @@ add::add(std::auto_ptr vp, const ex & oc) // archiving ////////// -DEFAULT_ARCHIVING(add) +GINAC_BIND_UNARCHIVER(add); ////////// // functions overriding virtual functions from base classes @@ -172,37 +167,32 @@ void add::do_print_csrc(const print_csrc & c, unsigned level) const if (precedence() <= level) c.s << "("; - // Print arguments, separated by "+" + // Print arguments, separated by "+" or "-" epvector::const_iterator it = seq.begin(), itend = seq.end(); + char separator = ' '; while (it != itend) { - // If the coefficient is -1, it is replaced by a single minus sign - if (it->coeff.is_equal(_ex1)) { - it->rest.print(c, precedence()); - } else if (it->coeff.is_equal(_ex_1)) { - c.s << "-"; + // If the coefficient is negative, separator is "-" + if (it->coeff.is_equal(_ex_1) || + ex_to(it->coeff).numer().is_equal(*_num_1_p)) + separator = '-'; + c.s << separator; + if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1)) { it->rest.print(c, precedence()); - } else if (ex_to(it->coeff).numer().is_equal(*_num1_p)) { - it->rest.print(c, precedence()); - c.s << "/"; - ex_to(it->coeff).denom().print(c, precedence()); - } else if (ex_to(it->coeff).numer().is_equal(*_num_1_p)) { - c.s << "-"; + } else if (ex_to(it->coeff).numer().is_equal(*_num1_p) || + ex_to(it->coeff).numer().is_equal(*_num_1_p)) + { it->rest.print(c, precedence()); - c.s << "/"; + c.s << '/'; ex_to(it->coeff).denom().print(c, precedence()); } else { it->coeff.print(c, precedence()); - c.s << "*"; + c.s << '*'; it->rest.print(c, precedence()); } - // Separator is "+", except if the following expression would have a leading minus sign or the sign is sitting in parenthesis (as in a ctor) ++it; - if (it != itend - && (is_a(c) || !it->coeff.info(info_flags::real) // sign inside ctor arguments - || !(it->coeff.info(info_flags::negative) || (it->coeff.is_equal(*_num1_p) && is_exactly_a(it->rest) && it->rest.info(info_flags::negative))))) - c.s << "+"; + separator = '+'; } if (!overall_coeff.is_zero()) { @@ -234,6 +224,16 @@ bool add::info(unsigned inf) const case info_flags::integer_polynomial: case info_flags::cinteger_polynomial: case info_flags::rational_polynomial: + case info_flags::real: + case info_flags::rational: + case info_flags::integer: + case info_flags::crational: + case info_flags::cinteger: + case info_flags::positive: + case info_flags::nonnegative: + case info_flags::posint: + case info_flags::nonnegint: + case info_flags::even: case info_flags::crational_polynomial: case info_flags::rational_function: { epvector::const_iterator i = seq.begin(), end = seq.end(); @@ -242,6 +242,8 @@ bool add::info(unsigned inf) const return false; ++i; } + if (overall_coeff.is_zero() && (inf == info_flags::positive || inf == info_flags::posint)) + return true; return overall_coeff.info(inf); } case info_flags::algebraic: { @@ -502,10 +504,10 @@ unsigned add::return_type() const return seq.begin()->rest.return_type(); } -tinfo_t add::return_type_tinfo() const +return_type_t add::return_type_tinfo() const { if (seq.empty()) - return this; + return make_return_type_t(); else return seq.begin()->rest.return_type_tinfo(); }