[GiNaC-devel] [PATCH 3/3] power::to_polinomial: improve handling of
negative powers
Alexei Sheplyakov
varg at theor.jinr.ru
Fri Oct 6 13:40:48 CEST 2006
Now
collect_common_factors((x*y*a+x*y*b)^(-3) + (x*z + x*y)^(-2))
will evaluate to
x^(-2)*(x^(-1)*(a+b)^(-3)*y^(-3)+(z+y)^(-2))
which is actually what I expect.
---
ginac/normal.cpp | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/ginac/normal.cpp b/ginac/normal.cpp
index fc89710..b2a4e8c 100644
--- a/ginac/normal.cpp
+++ b/ginac/normal.cpp
@@ -2455,7 +2455,16 @@ ex power::to_polynomial(exmap & repl) co
if (exponent.info(info_flags::posint))
return power(basis.to_rational(repl), exponent);
else if (exponent.info(info_flags::negint))
- return power(replace_with_symbol(power(basis, _ex_1), repl), -exponent);
+ {
+ ex basis_pref = collect_common_factors(basis);
+ if (is_exactly_a<mul>(basis_pref) || is_exactly_a<power>(basis_pref)) {
+ // (A*B)^n will be automagically transformed to A^n*B^n
+ ex t = power(basis_pref, exponent);
+ return t.to_polynomial(repl);
+ }
+ else
+ return power(replace_with_symbol(power(basis, _ex_1), repl), -exponent);
+ }
else
return replace_with_symbol(*this, repl);
}
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-devel/attachments/20061006/7e2a696c/attachment.pgp
More information about the GiNaC-devel
mailing list