]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
Happy new year!
[ginac.git] / ginac / mul.cpp
index 298715b33fd2eabfd28ea9390229fb3f5b90b39d..3d33c78a129eeaeaaf9074bc291e76624e403da8 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's products of expressions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2007 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2008 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
@@ -469,8 +469,8 @@ ex mul::eval(int level) const
 
                        // XXX: What is the best way to check if the polynomial is a primitive? 
                        numeric c = i->rest.integer_content();
-                       const numeric& lead_coeff =
-                               ex_to<numeric>(ex_to<add>(i->rest).seq.begin()->coeff).div_dyn(c);
+                       const numeric lead_coeff =
+                               ex_to<numeric>(ex_to<add>(i->rest).seq.begin()->coeff).div(c);
                        const bool canonicalizable = lead_coeff.is_integer();
 
                        // XXX: The main variable is chosen in a random way, so this code 
@@ -994,15 +994,23 @@ bool mul::can_be_further_expanded(const ex & e)
 ex mul::expand(unsigned options) const
 {
        {
-       // trivial case: expanding the monomial (~ 30% of all calls)
+       // trivial case: expanding the monomial (~ 30% of all calls)
                epvector::const_iterator i = seq.begin(), seq_end = seq.end();
                while ((i != seq.end()) &&  is_a<symbol>(i->rest) && i->coeff.info(info_flags::integer))
                        ++i;
-               if (i == seq_end)
-                       return (new mul(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
+               if (i == seq_end) {
+                       setflag(status_flags::expanded);
+                       return *this;
+               }
        }
 
-       const bool skip_idx_rename = ! info(info_flags::has_indices);
+       // do not rename indices if the object has no indices at all
+       if ((!(options & expand_options::expand_rename_idx)) && 
+                       this->info(info_flags::has_indices))
+               options |= expand_options::expand_rename_idx;
+
+       const bool skip_idx_rename = !(options & expand_options::expand_rename_idx);
+
        // First, expand the children
        std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
        const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);