]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
include <algorithm> for use of std::min().
[ginac.git] / ginac / mul.cpp
index 64660a288a211695a0e91f07f0f2e92b055fe706..052e7f7f9251c6a3fb640389b364f040265c497f 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's products of expressions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2015 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
@@ -344,7 +344,7 @@ bool mul::info(unsigned inf) const
                                else
                                        return false;
                        }
-                       return (overall_coeff.info(info_flags::negative)? pos : !pos);
+                       return (overall_coeff.info(info_flags::negative)? !pos : pos);
                }
                case info_flags::posint:
                case info_flags::negint: {
@@ -406,7 +406,7 @@ bool mul::is_polynomial(const ex & var) const
 {
        for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i) {
                if (!i->rest.is_polynomial(var) ||
-                   (i->rest.has(var) && !i->coeff.info(info_flags::integer))) {
+                   (i->rest.has(var) && !i->coeff.info(info_flags::nonnegint))) {
                        return false;
                }
        }
@@ -497,7 +497,7 @@ ex mul::coeff(const ex & s, int n) const
 ex mul::eval(int level) const
 {
        std::auto_ptr<epvector> evaled_seqp = evalchildren(level);
-       if (evaled_seqp.get()) {
+       if (unlikely(evaled_seqp.get() != 0)) {
                // do more evaluation later
                return (new mul(evaled_seqp, overall_coeff))->
                           setflag(status_flags::dynallocated);
@@ -764,7 +764,7 @@ bool tryfactsubs(const ex & origfactor, const ex & patternfactor, int & nummatch
        return true;
 }
 
-/** Checks wheter e matches to the pattern pat and the (possibly to be updated)
+/** Checks whether e matches to the pattern pat and the (possibly to be updated)
   * list of replacements repls. This matching is in the sense of algebraic
   * substitutions. Matching starts with pat.op(factor) of the pattern because
   * the factors before this one have already been matched. The (possibly
@@ -805,7 +805,7 @@ bool algebraic_match_mul_with_mul(const mul &e, const ex &pat, exmap& repls,
 
 bool mul::has(const ex & pattern, unsigned options) const
 {
-       if(!(options&has_options::algebraic))
+       if(!(options & has_options::algebraic))
                return basic::has(pattern,options);
        if(is_a<mul>(pattern)) {
                exmap repls;
@@ -1089,10 +1089,9 @@ void mul::combine_overall_coeff(const ex & c1, const ex & c2)
 bool mul::can_make_flat(const expair & p) const
 {
        GINAC_ASSERT(is_exactly_a<numeric>(p.coeff));
-       // this assertion will probably fail somewhere
-       // it would require a more careful make_flat, obeying the power laws
-       // probably should return true only if p.coeff is integer
-       return ex_to<numeric>(p.coeff).is_equal(*_num1_p);
+
+       // (x*y)^c == x^c*y^c  if c ∈ ℤ
+       return p.coeff.info(info_flags::integer);
 }
 
 bool mul::can_be_further_expanded(const ex & e)
@@ -1293,7 +1292,7 @@ ex mul::expand(unsigned options) const
 
 /** Member-wise expand the expairs representing this sequence.  This must be
  *  overridden from expairseq::expandchildren() and done iteratively in order
- *  to allow for early cancallations and thus safe memory.
+ *  to allow for early cancellations and thus safe memory.
  *
  *  @see mul::expand()
  *  @return pointer to epvector containing expanded representation or zero