DEFAULT_ARCHIVING(add)
//////////
-// functions overriding virtual functions from bases classes
+// functions overriding virtual functions from base classes
//////////
// public
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