// other ctors
//////////
-power::power(const ex & lh, const ex & rh) : inherited(TINFO_power), basis(lh), exponent(rh)
-{
- debugmsg("power ctor from ex,ex",LOGLEVEL_CONSTRUCT);
-}
-
-/** Ctor from an ex and a bare numeric. This is somewhat more efficient than
- * the normal ctor from two ex whenever it can be used. */
-power::power(const ex & lh, const numeric & rh) : inherited(TINFO_power), basis(lh), exponent(rh)
-{
- debugmsg("power ctor from ex,numeric",LOGLEVEL_CONSTRUCT);
-}
+// all inlined
//////////
// archiving
DEFAULT_UNARCHIVE(power)
//////////
-// functions overriding virtual functions from bases classes
+// functions overriding virtual functions from base classes
//////////
// public
ex power::evalm(void) const
{
- ex ebasis = basis.evalm();
- ex eexponent = exponent.evalm();
+ const ex ebasis = basis.evalm();
+ const ex eexponent = exponent.evalm();
if (is_ex_of_type(ebasis,matrix)) {
if (is_ex_of_type(eexponent,numeric)) {
return (new matrix(ex_to<matrix>(ebasis).pow(eexponent)))->setflag(status_flags::dynallocated);
ex power::expand(unsigned options) const
{
- if (flags & status_flags::expanded)
+ if (options == 0 && (flags & status_flags::expanded))
return *this;
ex expanded_basis = basis.expand(options);
epvector::const_iterator cit = a.seq.begin();
while (cit!=last) {
distrseq.push_back(power(expanded_basis, a.recombine_pair_to_ex(*cit)));
- cit++;
+ ++cit;
}
// Make sure that e.g. (x+y)^(2+a) expands the (x+y)^2 factor
if (are_ex_trivially_equal(basis,expanded_basis) && are_ex_trivially_equal(exponent,expanded_exponent)) {
return this->hold();
} else {
- return (new power(expanded_basis,expanded_exponent))->setflag(status_flags::dynallocated | status_flags::expanded);
+ return (new power(expanded_basis,expanded_exponent))->setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
}
}
if (are_ex_trivially_equal(basis,expanded_basis) && are_ex_trivially_equal(exponent,expanded_exponent))
return this->hold();
else
- return (new power(expanded_basis,expanded_exponent))->setflag(status_flags::dynallocated | status_flags::expanded);
+ return (new power(expanded_basis,expanded_exponent))->setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0));
}
//////////
upper_limit[l] = n;
}
- while (1) {
+ while (true) {
exvector term;
term.reserve(m+1);
for (l=0; l<m-1; l++) {
term.push_back(f);
- /*
- cout << "begin term" << endl;
- for (int i=0; i<m-1; i++) {
- cout << "k[" << i << "]=" << k[i] << endl;
- cout << "k_cum[" << i << "]=" << k_cum[i] << endl;
- cout << "upper_limit[" << i << "]=" << upper_limit[i] << endl;
- }
- for_each(term.begin(), term.end(), ostream_iterator<ex>(cout, "\n"));
- cout << "end term" << endl;
- */
-
- // TODO: optimize this
+ // TODO: Can we optimize this? Alex seemed to think so...
sum.push_back((new mul(term))->setflag(status_flags::dynallocated));
// increment k[]
l = m-2;
- while ((l>=0)&&((++k[l])>upper_limit[l])) {
+ while ((l>=0) && ((++k[l])>upper_limit[l])) {
k[l] = 0;
- l--;
+ --l;
}
if (l<0) break;
upper_limit[i] = n-k_cum[i-1];
}
return (new add(sum))->setflag(status_flags::dynallocated |
- status_flags::expanded );
+ status_flags::expanded );
}
// power(+(x,...,z;c),2)=power(+(x,...,z;0),2)+2*c*+(x,...,z;0)+c*c
// first part: ignore overall_coeff and expand other terms
for (epvector::const_iterator cit0=a.seq.begin(); cit0!=last; ++cit0) {
- const ex & r = (*cit0).rest;
- const ex & c = (*cit0).coeff;
+ const ex & r = cit0->rest;
+ const ex & c = cit0->coeff;
GINAC_ASSERT(!is_ex_exactly_of_type(r,add));
GINAC_ASSERT(!is_ex_exactly_of_type(r,power) ||
}
for (epvector::const_iterator cit1=cit0+1; cit1!=last; ++cit1) {
- const ex & r1 = (*cit1).rest;
- const ex & c1 = (*cit1).coeff;
+ const ex & r1 = cit1->rest;
+ const ex & c1 = cit1->coeff;
sum.push_back(a.combine_ex_with_coeff_to_pair((new mul(r,r1))->setflag(status_flags::dynallocated),
_num2().mul(ex_to<numeric>(c)).mul_dyn(ex_to<numeric>(c1))));
}
// second part: add terms coming from overall_factor (if != 0)
if (!a.overall_coeff.is_zero()) {
- for (epvector::const_iterator cit=a.seq.begin(); cit!=a.seq.end(); ++cit) {
- sum.push_back(a.combine_pair_with_coeff_to_pair(*cit,ex_to<numeric>(a.overall_coeff).mul_dyn(_num2())));
+ epvector::const_iterator i = a.seq.begin(), end = a.seq.end();
+ while (i != end) {
+ sum.push_back(a.combine_pair_with_coeff_to_pair(*i, ex_to<numeric>(a.overall_coeff).mul_dyn(_num2())));
+ ++i;
}
sum.push_back(expair(ex_to<numeric>(a.overall_coeff).power_dyn(_num2()),_ex1()));
}
return (new mul(distrseq,ex_to<numeric>(m.overall_coeff).power_dyn(n)))->setflag(status_flags::dynallocated);
}
-/*
-ex power::expand_noncommutative(const ex & basis, const numeric & exponent,
- unsigned options) const
-{
- ex rest_power = ex(power(basis,exponent.add(_num_1()))).
- expand(options | expand_options::internal_do_not_expand_power_operands);
-
- return ex(mul(rest_power,basis),0).
- expand(options | expand_options::internal_do_not_expand_mul_operands);
-}
-*/
-
// helper function
ex sqrt(const ex & a)