Same problem again plus a few others.
Chris Dams
chrisd at sci.kun.nl
Wed Aug 28 01:18:15 CEST 2002
Hello,
Whoever reads this, have a look at my previous post. After this you are
probably convinced that it is a good idea to change the line
if (overall_coeff.info(info_flags::positive))
in add.cpp into
if (overall_coeff.info(info_flags::positive) ||
is_a<print_csrc_cl_N>(c))
After this have a look at the file mul.cpp. This contains the lines
if (is_a<print_csrc_cl_N>(c))
c.s << "recip(";
else
c.s << "1.0/";
Question: Who closes the opening parenthesis of after the recip? Answer:
I don't see anyone doing this. Furthermore it is not closed in my output.
Next, try the following program
#include <ginac/ginac.h>
#include <iostream>
using namespace std;
using namespace GiNaC;
int main()
{ symbol a("a"),b("b");
numeric half=numeric(1)/2;
(power(a,-half)*b).print(print_csrc(cout));
cout << endl;
return 0;
}
The result at my place is
b*pow(a,(1.000000e+00/2.000000e+00))
I would have expected a minus sign in the exponent.
A patch is attached to this mail that should fix these two problems in
mul.cpp. Also mul.cpp seems to be written before the info_flag negint
existed. The path also patches mul.cpp to use this flag.
Have a nice day,
Chris Dams
-------------- next part --------------
*** mul.cpp Wed Aug 28 00:50:17 2002
--- mul.cpp.patched Wed Aug 28 00:49:53 2002
***************
*** 141,165 ****
while (it != itend) {
// If the first argument is a negative integer power, it gets printed as "1.0/<expr>"
! if (it == seq.begin() && ex_to<numeric>(it->coeff).is_integer() && it->coeff.info(info_flags::negative)) {
! if (is_a<print_csrc_cl_N>(c))
c.s << "recip(";
! else
c.s << "1.0/";
}
// If the exponent is 1 or -1, it is left out
if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1))
it->rest.print(c, precedence());
! else {
// Outer parens around ex needed for broken gcc-2.95 parser:
! (ex(power(it->rest, abs(ex_to<numeric>(it->coeff))))).print(c, level);
! }
// Separator is "/" for negative integer powers, "*" otherwise
++it;
if (it != itend) {
! if (ex_to<numeric>(it->coeff).is_integer() && it->coeff.info(info_flags::negative))
c.s << "/";
else
c.s << "*";
--- 141,171 ----
while (it != itend) {
// If the first argument is a negative integer power, it gets printed as "1.0/<expr>"
! bool printfinalparenthesis=false;
! if (it == seq.begin() && it->coeff.info(info_flags::negint)) {
! if (is_a<print_csrc_cl_N>(c)) {
c.s << "recip(";
! printfinalparenthesis=true;
! } else
c.s << "1.0/";
}
// If the exponent is 1 or -1, it is left out
if (it->coeff.is_equal(_ex1) || it->coeff.is_equal(_ex_1))
it->rest.print(c, precedence());
! else if(it->coeff.info(info_flags::negint))
// Outer parens around ex needed for broken gcc-2.95 parser:
! (ex(power(it->rest, -ex_to<numeric>(it->coeff)))).print(c, level);
! else
! (ex(power(it->rest, ex_to<numeric>(it->coeff)))).print(c, level);
!
! if(printfinalparenthesis)
! c.s << ")";
// Separator is "/" for negative integer powers, "*" otherwise
++it;
if (it != itend) {
! if (it->coeff.info(info_flags::negint))
c.s << "/";
else
c.s << "*";
More information about the GiNaC-devel
mailing list