* Implementation of GiNaC's products of expressions. */
/*
- * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2002 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <iostream>
#include <vector>
#include <stdexcept>
#include "power.h"
#include "matrix.h"
#include "archive.h"
-#include "debugmsg.h"
#include "utils.h"
namespace GiNaC {
GINAC_IMPLEMENT_REGISTERED_CLASS(mul, expairseq)
//////////
-// default ctor, dctor, copy ctor assignment operator and helpers
+// default ctor, dtor, copy ctor, assignment operator and helpers
//////////
mul::mul()
{
- debugmsg("mul default ctor",LOGLEVEL_CONSTRUCT);
tinfo_key = TINFO_mul;
}
mul::mul(const ex & lh, const ex & rh)
{
- debugmsg("mul ctor from ex,ex",LOGLEVEL_CONSTRUCT);
tinfo_key = TINFO_mul;
overall_coeff = _ex1;
construct_from_2_ex(lh,rh);
mul::mul(const exvector & v)
{
- debugmsg("mul ctor from exvector",LOGLEVEL_CONSTRUCT);
tinfo_key = TINFO_mul;
overall_coeff = _ex1;
construct_from_exvector(v);
mul::mul(const epvector & v)
{
- debugmsg("mul ctor from epvector",LOGLEVEL_CONSTRUCT);
tinfo_key = TINFO_mul;
overall_coeff = _ex1;
construct_from_epvector(v);
mul::mul(const epvector & v, const ex & oc)
{
- debugmsg("mul ctor from epvector,ex",LOGLEVEL_CONSTRUCT);
tinfo_key = TINFO_mul;
overall_coeff = oc;
construct_from_epvector(v);
mul::mul(epvector * vp, const ex & oc)
{
- debugmsg("mul ctor from epvector *,ex",LOGLEVEL_CONSTRUCT);
tinfo_key = TINFO_mul;
GINAC_ASSERT(vp!=0);
overall_coeff = oc;
mul::mul(const ex & lh, const ex & mh, const ex & rh)
{
- debugmsg("mul ctor from ex,ex,ex",LOGLEVEL_CONSTRUCT);
tinfo_key = TINFO_mul;
exvector factors;
factors.reserve(3);
void mul::print(const print_context & c, unsigned level) const
{
- debugmsg("mul print", LOGLEVEL_PRINT);
-
if (is_a<print_tree>(c)) {
inherited::print(c, level);
while (it != itend) {
// If the first argument is a negative integer power, it gets printed as "1.0/<expr>"
- if (it == seq.begin() && ex_to<numeric>(it->coeff).is_integer() && it->coeff.compare(_num0) < 0) {
+ if (it == seq.begin() && ex_to<numeric>(it->coeff).is_integer() && it->coeff.info(info_flags::negative)) {
if (is_a<print_csrc_cl_N>(c))
c.s << "recip(";
else
}
// If the exponent is 1 or -1, it is left out
- if (it->coeff.compare(_ex1) == 0 || it->coeff.compare(_num_1) == 0)
+ if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1))
it->rest.print(c, precedence());
else {
// Outer parens around ex needed for broken gcc-2.95 parser:
// Separator is "/" for negative integer powers, "*" otherwise
++it;
if (it != itend) {
- if (ex_to<numeric>(it->coeff).is_integer() && it->coeff.compare(_num0) < 0)
+ if (ex_to<numeric>(it->coeff).is_integer() && it->coeff.info(info_flags::negative))
c.s << "/";
else
c.s << "*";
if (precedence() <= level)
c.s << ")";
+ } else if (is_a<print_python_repr>(c)) {
+ c.s << class_name() << '(';
+ op(0).print(c);
+ for (unsigned i=1; i<nops(); ++i) {
+ c.s << ',';
+ op(i).print(c);
+ }
+ c.s << ')';
} else {
if (precedence() <= level) {
* @param level cut-off in recursive evaluation */
ex mul::eval(int level) const
{
- debugmsg("mul eval",LOGLEVEL_MEMBER_FUNCTION);
-
epvector *evaled_seqp = evalchildren(level);
if (evaled_seqp) {
// do more evaluation later
exvector distrseq;
distrseq.reserve(n1*n2);
for (int i1=0; i1<n1; ++i1) {
- for (int i2=0; i2<n2; ++i2) {
- distrseq.push_back(add1.op(i1) * add2.op(i2));
- }
+ // cache the first operand (for efficiency):
+ const ex op1 = add1.op(i1);
+ for (int i2=0; i2<n2; ++i2)
+ distrseq.push_back(op1 * add2.op(i2));
}
last_expanded = (new add(distrseq))->
setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
* pointer, if sequence is unchanged. */
epvector * mul::expandchildren(unsigned options) const
{
- epvector::const_iterator last = seq.end();
+ const epvector::const_iterator last = seq.end();
epvector::const_iterator cit = seq.begin();
while (cit!=last) {
const ex & factor = recombine_pair_to_ex(*cit);