problem with powers.

Chris Dams chrisd at sci.kun.nl
Mon Dec 15 15:25:21 CET 2003


Hello,

Expanding an expression by calling the .expand() method is obsoleted by
the now preferred method of the so-called "repeated reciprocal". You want
to expand a*(a+b)? Here is how this is done nowadays.

ex test = a*(a+b)
ex expanded_test = 1/(1/test)

Then again, maybe this was not the idea. A patch that is supposed to
remove this feature from GiNaC is attached.

Have a nice day,
Chris
-------------- next part --------------
Index: power.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/power.cpp,v
retrieving revision 1.89
diff -r1.89 power.cpp
659c669
< 		return expand_mul(ex_to<mul>(expanded_basis), num_exponent);
---
> 		return expand_mul(ex_to<mul>(expanded_basis), num_exponent, true);
716c726
< 				term.push_back(expand_mul(ex_to<mul>(b),numeric(k[l])));
---
> 				term.push_back(expand_mul(ex_to<mul>(b),numeric(k[l]),true));
730c740
< 			term.push_back(expand_mul(ex_to<mul>(b),numeric(n-k_cum[m-2])));
---
> 			term.push_back(expand_mul(ex_to<mul>(b),numeric(n-k_cum[m-2]),true));
790c800
< 				sum.push_back(expair(expand_mul(ex_to<mul>(r),_num2),
---
> 				sum.push_back(expair(expand_mul(ex_to<mul>(r),_num2,true),
798c808
< 				sum.push_back(a.combine_ex_with_coeff_to_pair(expand_mul(ex_to<mul>(r),_num2),
---
> 				sum.push_back(a.combine_ex_with_coeff_to_pair(expand_mul(ex_to<mul>(r),_num2,true),
833c843
< ex power::expand_mul(const mul & m, const numeric & n) const
---
> ex power::expand_mul(const mul & m, const numeric & n, bool from_expand) const
853c863
< 			if (is_exactly_a<add>(cit->rest) && new_coeff.is_pos_integer()) {
---
> 			if (from_expand && is_exactly_a<add>(cit->rest) && new_coeff.is_pos_integer()) {
866c876
< 	else
---
> 	if (from_expand)
867a878
> 	return result;
Index: power.h
===================================================================
RCS file: /home/cvs/GiNaC/ginac/power.h,v
retrieving revision 1.47
diff -r1.47 power.h
60a61
> 	ex conjugate() const;
89c90
< 	ex expand_mul(const mul & m, const numeric & n) const;
---
> 	ex expand_mul(const mul & m, const numeric & n, bool from_expand = false) const;


More information about the GiNaC-devel mailing list