DEFAULT_ARCHIVING(add)
//////////
-// functions overriding virtual functions from bases classes
+// functions overriding virtual functions from base classes
//////////
// public
// If the coefficient is -1, it is replaced by a single minus sign
if (it->coeff.compare(_num1()) == 0) {
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
} else if (it->coeff.compare(_num_1()) == 0) {
c.s << "-";
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
} else if (ex_to<numeric>(it->coeff).numer().compare(_num1()) == 0) {
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
c.s << "/";
ex_to<numeric>(it->coeff).denom().print(c, precedence());
} else if (ex_to<numeric>(it->coeff).numer().compare(_num_1()) == 0) {
c.s << "-";
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
c.s << "/";
ex_to<numeric>(it->coeff).denom().print(c, precedence());
} else {
- it->coeff.bp->print(c, precedence());
+ it->coeff.print(c, precedence());
c.s << "*";
- it->rest.bp->print(c, precedence());
+ it->rest.print(c, precedence());
}
// Separator is "+", except if the following expression would have a leading minus sign
if (!overall_coeff.is_zero()) {
if (overall_coeff.info(info_flags::positive))
c.s << '+';
- overall_coeff.bp->print(c, precedence());
+ overall_coeff.print(c, precedence());
}
if (precedence() <= level)
return (new add(coeffseq, n==0 ? overall_coeff : _ex0()))->setflag(status_flags::dynallocated);
}
+/** Perform automatic term rewriting rules in this class. In the following
+ * x stands for a symbolic variables of type ex and c stands for such
+ * an expression that contain a plain number.
+ * - +(;c) -> c
+ * - +(x;1) -> x
+ *
+ * @param level cut-off in recursive evaluation */
ex add::eval(int level) const
{
- // simplifications: +(;c) -> c
- // +(x;1) -> x
-
debugmsg("add eval",LOGLEVEL_MEMBER_FUNCTION);
epvector *evaled_seqp = evalchildren(level);
}
int seq_size = seq.size();
- if (seq_size==0) {
+ if (seq_size == 0) {
// +(;c) -> c
return overall_coeff;
- } else if ((seq_size==1) && overall_coeff.is_zero()) {
+ } else if (seq_size == 1 && overall_coeff.is_zero()) {
// +(x;0) -> x
return recombine_pair_to_ex(*(seq.begin()));
+ } else if (!overall_coeff.is_zero() && seq[0].rest.return_type() != return_types::commutative) {
+ throw (std::logic_error("add::eval(): sum of non-commutative objects has non-zero numeric term"));
}
return this->hold();
}
ex add::expand(unsigned options) const
{
- if (options == 0 && (flags & status_flags::expanded))
- return *this;
-
epvector *vp = expandchildren(options);
if (vp == NULL) {
// the terms have not changed, so it is safe to declare this expanded