if (divide_in_z(p, g, ca ? *ca : dummy, var) && divide_in_z(q, g, cb ? *cb : dummy, var)) {
g *= gc;
ex lc = g.lcoeff(*x);
- if (is_ex_exactly_of_type(lc, numeric) && lc.compare(_ex0()) < 0)
+ if (is_ex_exactly_of_type(lc, numeric) && ex_to_numeric(lc).is_negative())
return -g;
else
return g;
ex gcd(const ex &a, const ex &b, ex *ca, ex *cb, bool check_args)
{
+//clog << "gcd(" << a << "," << b << ")\n";
+
// Partially factored cases (to avoid expanding large expressions)
if (is_ex_exactly_of_type(a, mul)) {
if (is_ex_exactly_of_type(b, mul) && b.nops() > a.nops())
// as defined by get_first_symbol() is made positive)
const symbol *x;
if (get_first_symbol(den, x)) {
- if (den.unit(*x).compare(_ex0()) < 0) {
+ GINAC_ASSERT(is_ex_exactly_of_type(den.unit(*x),numeric));
+ if (ex_to_numeric(den.unit(*x)).is_negative()) {
num *= _ex_1();
den *= _ex_1();
}
}
// Return result as list
+//clog << " returns num = " << num << ", den = " << den << ", pre_factor = " << pre_factor << endl;
return (new lst(num * pre_factor.numer(), den * pre_factor.denom()))->setflag(status_flags::dynallocated);
}
// split it into numerator and denominator
GINAC_ASSERT(ex_to_numeric(ex_to_add(n.op(0)).overall_coeff).is_rational());
numeric overall = ex_to_numeric(ex_to_add(n.op(0)).overall_coeff);
- o.push_back((new lst(overall.numer(), overall.denom()))->setflag(status_flags::dynallocated));
+ o.push_back((new lst(overall.numer(), overall.denom() * n.op(1)))->setflag(status_flags::dynallocated));
} else
o.push_back(n);
it++;
// Determine common denominator
ex den = _ex1();
exvector::const_iterator ait = o.begin(), aitend = o.end();
+//clog << "add::normal uses the following summands:\n";
while (ait != aitend) {
+//clog << " num = " << ait->op(0) << ", den = " << ait->op(1) << endl;
den = lcm(ait->op(1), den, false);
ait++;
}
+//clog << " common denominator = " << den << endl;
// Add fractions
if (den.is_equal(_ex1())) {
// should not happen
throw(std::runtime_error("invalid expression in add::normal, division failed"));
}
- num_seq.push_back(ait->op(0) * q);
+ num_seq.push_back((ait->op(0) * q).expand());
}
ex num = (new add(num_seq))->setflag(status_flags::dynallocated);