From kreckel at thep.physik.uni-mainz.de Sat Dec 8 14:55:16 2001 From: kreckel at thep.physik.uni-mainz.de (Richard B. Kreckel) Date: Sat, 8 Dec 2001 14:55:16 +0100 (CET) Subject: invalid expression in content|unit|...() In-Reply-To: <20011122193302.A12756@student.physik.uni-mainz.de> Message-ID: Hi, On Thu, 22 Nov 2001, Christian Bauer wrote: > On Thu, Nov 22, 2001 at 08:10:56PM +0200, Pearu Peterson wrote: > > Ok then, but how about the following solution: remove constant > > class altogether and put its current initnumber/efun stuff into symbol > > class. > > This is what I had in mind. > > > simplify_indexed(p.i^2*q.j^2-p.n^2*q.j^2)-0 erroneously returned > > p.i^2*q.j^2-q.i^2*p.j^2 instead of 0 > > Interesting. Maybe this is one of those checks that were never guaranteed > to always work... :-) Indeed. It is sensitive to the serial number of the symbols involved. I have attached a testsuite for this particular problem. Am wondering what "never guaranteed to always work" was supposed to mean... Cheers -richy. -- Richard B. Kreckel -------------- next part -------------- A non-text attachment was scrubbed... Name: indextest.cc Type: text/x-c++src Size: 1456 bytes Desc: indextest.cc URL: From fujio at ccm.cl.nec.co.jp Thu Dec 13 09:57:39 2001 From: fujio at ccm.cl.nec.co.jp (Hidehiro FUJIO) Date: Thu, 13 Dec 2001 17:57:39 +0900 Subject: How to use sqrt for input expression? Message-ID: <005601c183b4$387db940$c026380a@csl.cl.nec.co.jp> Dear GiNaC developers, I'm using GiNaC for making numerical simulation tools. My problem with GiNaC is how to handle 'sqrt' function in expression input. The simplest example is, ======================================= #include using namespace GiNaC; #include int main() { symbol x("x"); ex e("sqrt(x)",lst(x)); cout << e < Message-ID: Hello, On Thu, 13 Dec 2001, Hidehiro FUJIO wrote: > I'm using GiNaC for making numerical simulation tools. > > My problem with GiNaC is how to handle 'sqrt' function in > expression input. The simplest example is, > > ======================================= > #include > > using namespace GiNaC; > #include > int main() > { > symbol x("x"); > ex e("sqrt(x)",lst(x)); > cout << e < } > ======================================= > > When it runs, it makes core dump. Rather it throws an (uncaught) exception telling you that there is no function 'sqrt' included in the parser. > When I use 'sin' instead of 'sqrt', the result is what > I expected with GiNaC library. > > Is it a bug or normal? If normal, how to input expression > that contains 'sqrt' function? Till this is fixed, just use "x^(1/2)" instead of "sqrt(x)" when constructing an ex from a string. Regards -richy. -- Richard B. Kreckel From cbauer at student.physik.uni-mainz.de Mon Dec 17 21:00:58 2001 From: cbauer at student.physik.uni-mainz.de (Christian Bauer) Date: Mon, 17 Dec 2001 21:00:58 +0100 Subject: Bug?: (a^b).unit(a) -> SIGSEGV In-Reply-To: References: Message-ID: <20011217210058.A31171@student.physik.uni-mainz.de> Hi! On Sun, Nov 25, 2001 at 02:21:44PM +0200, Pearu Peterson wrote: > Notice that (a^b).unit(a) leads to Segmentation fault. [...] > Any ideas? My guess is that it enters an infinite recursion in unit() because lcoeff(a^b,a) = a^b, and unit() expects the coefficient to not contain the specified variable any more. Technically, unit() is being called with illegal arguments as it expects a polynomial and doesn't do any checking for speed reasons. Maybe power::degree() should throw an exception if it has a non-integer exponent instead of returning 0? I'm not sure whether this will break anything... Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/ From pearu at cens.ioc.ee Tue Dec 18 18:48:42 2001 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 18 Dec 2001 19:48:42 +0200 (EET) Subject: Adding python support to GiNaC Message-ID: Hi! I have been working on the python interface to GiNaC. It is quite usable already and I have tested it in many problems. However, it would be great if some python specific changes that I had to do in GiNaC, could be added to GiNaC. These changes include mostly printing expressions. Earlier I used hooks from GiNaC archive features to get desired output for python, but it was _very_ slow compared to the native GiNaC print hooks. So, please find a patch attached that adds two new print_context classes, print_python and print_python_repr, with the corresponding additions to print methods of the basic classes. The patch includes also the following change in the idx::print method for print_latex context: `a.b' becomes `a_{b}' if b is covariant, `a^{b}', otherwise (you can ignore it if you don't like it). This patch is against GiNaC-1.0.1. I can make it also against the latest GiNaC in CVS. Let me know if needed. Thanks, Pearu -------------- next part -------------- diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/add.cpp GiNaC-1.0.1-print_python/ginac/add.cpp --- GiNaC/ginac/add.cpp Thu Nov 22 19:15:03 2001 +++ GiNaC-1.0.1-print_python/ginac/add.cpp Fri Nov 23 16:28:09 2001 @@ -155,7 +155,16 @@ if (precedence() <= level) c.s << ")"; - + } else if (is_a(c)) { + c.s << class_name() << '('; + unsigned end = nops(); + if (end) + op(0).print(c); + for (unsigned i=1; i(c)) c.s << TeX_name; - else + else if (is_a(c)) { + c.s << class_name() << "('" << name << "'"; + if (TeX_name != "\\mbox{" + name + "}") + c.s << ",TeX_name='" << TeX_name << "'"; + c.s << ')'; + } else c.s << name; } diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/container.pl GiNaC-1.0.1-print_python/ginac/container.pl --- GiNaC/ginac/container.pl Fri Oct 26 17:08:24 2001 +++ GiNaC-1.0.1-print_python/ginac/container.pl Fri Nov 23 17:41:39 2001 @@ -430,7 +430,11 @@ ++i; } c.s << std::string(level + delta_indent,' ') << "=====" << std::endl; - + } else if (is_a(c)) { + printseq(c, '[', ',', ']', precedence(), precedence()+1); + } else if (is_a(c)) { + c.s << class_name (); + printseq(c, '(', ',', ')', precedence(), precedence()+1); } else { // always print brackets around seq, ignore upper_precedence printseq(c, '${open_bracket}', ',', '${close_bracket}', precedence(), precedence()+1); diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/exprseq.cpp GiNaC-1.0.1-print_python/ginac/exprseq.cpp --- GiNaC/ginac/exprseq.cpp Tue Nov 20 11:00:11 2001 +++ GiNaC-1.0.1-print_python/ginac/exprseq.cpp Fri Nov 23 18:11:55 2001 @@ -345,7 +345,11 @@ ++i; } c.s << std::string(level + delta_indent,' ') << "=====" << std::endl; - + } else if (is_a(c)) { + printseq(c, '[', ',', ']', precedence(), precedence()+1); + } else if (is_a(c)) { + c.s << class_name (); + printseq(c, '(', ',', ')', precedence(), precedence()+1); } else { // always print brackets around seq, ignore upper_precedence printseq(c, '(', ',', ')', precedence(), precedence()+1); diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/idx.cpp GiNaC-1.0.1-print_python/ginac/idx.cpp --- GiNaC/ginac/idx.cpp Sat Oct 27 18:18:57 2001 +++ GiNaC-1.0.1-print_python/ginac/idx.cpp Fri Nov 23 17:36:39 2001 @@ -156,7 +156,9 @@ } else { - if (!is_of_type(c, print_latex)) + if (is_a(c)) + c.s << "_{"; + else c.s << "."; bool need_parens = !(is_ex_exactly_of_type(value, numeric) || is_ex_of_type(value, symbol)); if (need_parens) @@ -164,6 +166,8 @@ value.print(c); if (need_parens) c.s << ")"; + if (is_a(c)) + c.s << "}"; } } @@ -180,8 +184,13 @@ dim.print(c, level + delta_indent); } else { - - if (!is_of_type(c, print_latex)) { + if (is_a(c)) { + if (covariant) + c.s << "_{"; + else + c.s << "^{"; + } + else { if (covariant) c.s << "."; else @@ -193,6 +202,8 @@ value.print(c); if (need_parens) c.s << ")"; + if (is_a(c)) + c.s << "}"; } } @@ -212,7 +223,12 @@ } else { bool is_tex = is_of_type(c, print_latex); - if (!is_tex) { + if (is_tex) { + if (covariant) + c.s << "_{"; + else + c.s << "^{"; + } else { if (covariant) c.s << "."; else @@ -231,6 +247,8 @@ if (need_parens) c.s << ")"; if (is_tex && dotted) + c.s << "}"; + if (is_tex) c.s << "}"; } } diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/lst.cpp GiNaC-1.0.1-print_python/ginac/lst.cpp --- GiNaC/ginac/lst.cpp Tue Nov 20 11:00:11 2001 +++ GiNaC-1.0.1-print_python/ginac/lst.cpp Fri Nov 23 18:11:55 2001 @@ -345,7 +345,11 @@ ++i; } c.s << std::string(level + delta_indent,' ') << "=====" << std::endl; - + } else if (is_a(c)) { + printseq(c, '[', ',', ']', precedence(), precedence()+1); + } else if (is_a(c)) { + c.s << class_name (); + printseq(c, '(', ',', ')', precedence(), precedence()+1); } else { // always print brackets around seq, ignore upper_precedence printseq(c, '{', ',', '}', precedence(), precedence()+1); diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/matrix.cpp GiNaC-1.0.1-print_python/ginac/matrix.cpp --- GiNaC/ginac/matrix.cpp Sat Oct 27 18:18:57 2001 +++ GiNaC-1.0.1-print_python/ginac/matrix.cpp Fri Nov 23 17:44:47 2001 @@ -147,6 +147,9 @@ } else { + if (is_a(c)) + c.s << class_name() << '('; + c.s << "["; for (unsigned y=0; y(c)) + c.s << ')'; } } diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/mul.cpp GiNaC-1.0.1-print_python/ginac/mul.cpp --- GiNaC/ginac/mul.cpp Thu Nov 22 19:15:04 2001 +++ GiNaC-1.0.1-print_python/ginac/mul.cpp Fri Nov 23 16:28:32 2001 @@ -168,7 +168,16 @@ if (precedence() <= level) c.s << ")"; - + } else if (is_a(c)) { + c.s << class_name() << '('; + unsigned end = nops(); + if (end) + op(0).print(c); + for (unsigned i=1; i(c)) { + } else if (is_a(c) || is_a(c)) { - c.s << "ncmul("; + c.s << class_name() << "("; exvector::const_iterator it = seq.begin(), itend = seq.end()-1; while (it != itend) { it->print(c, precedence()); diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/numeric.cpp GiNaC-1.0.1-print_python/ginac/numeric.cpp --- GiNaC/ginac/numeric.cpp Tue Nov 6 17:55:29 2001 +++ GiNaC-1.0.1-print_python/ginac/numeric.cpp Fri Nov 23 17:46:43 2001 @@ -389,6 +389,8 @@ const std::string mul_sym = is_a(c) ? " " : "*"; const cln::cl_R r = cln::realpart(cln::the(value)); const cln::cl_R i = cln::imagpart(cln::the(value)); + if (is_a(c)) + c.s << class_name() << "('"; if (cln::zerop(i)) { // case 1, real: x or -x if ((precedence() <= level) && (!this->is_nonneg_integer())) { @@ -446,6 +448,8 @@ c.s << par_close; } } + if (is_a(c)) + c.s << "')"; } } diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/power.cpp GiNaC-1.0.1-print_python/ginac/power.cpp --- GiNaC/ginac/power.cpp Fri Oct 26 17:08:24 2001 +++ GiNaC-1.0.1-print_python/ginac/power.cpp Fri Nov 23 21:30:11 2001 @@ -159,6 +159,14 @@ c.s << ')'; } + } else if (is_a(c)) { + + c.s << class_name() << '('; + basis.print(c); + c.s << ','; + exponent.print(c); + c.s << ')'; + } else { if (exponent.is_equal(_ex1_2)) { @@ -179,7 +187,10 @@ c.s << "("; } basis.print(c, precedence()); - c.s << '^'; + if (is_a(c)) + c.s << "**"; + else + c.s << '^'; if (is_a(c)) c.s << '{'; exponent.print(c, precedence()); diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/print.cpp GiNaC-1.0.1-print_python/ginac/print.cpp --- GiNaC/ginac/print.cpp Sat Oct 27 18:18:57 2001 +++ GiNaC-1.0.1-print_python/ginac/print.cpp Fri Nov 23 14:01:57 2001 @@ -36,6 +36,16 @@ print_latex::print_latex(std::ostream & os) : print_context(os) {} +print_python::print_python() + : print_context(std::cout) {} +print_python::print_python(std::ostream & os) + : print_context(os) {} + +print_python_repr::print_python_repr() + : print_context(std::cout) {} +print_python_repr::print_python_repr(std::ostream & os) + : print_context(os) {} + print_tree::print_tree(unsigned d) : print_context(std::cout), delta_indent(d) {} print_tree::print_tree(std::ostream & os, unsigned d) diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/print.h GiNaC-1.0.1-print_python/ginac/print.h --- GiNaC/ginac/print.h Sat Oct 27 18:18:57 2001 +++ GiNaC-1.0.1-print_python/ginac/print.h Sat Nov 24 10:35:57 2001 @@ -49,6 +49,22 @@ print_latex(std::ostream &); }; +/** Context for python pretty-print output. */ +class print_python : public print_context +{ +public: + print_python(); + print_python(std::ostream &); +}; + +/** Context for python-parsable output. */ +class print_python_repr : public print_context +{ +public: + print_python_repr(); + print_python_repr(std::ostream &); +}; + /** Context for tree-like output for debugging. */ class print_tree : public print_context { diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/pseries.cpp GiNaC-1.0.1-print_python/ginac/pseries.cpp --- GiNaC/ginac/pseries.cpp Sat Oct 27 18:18:57 2001 +++ GiNaC-1.0.1-print_python/ginac/pseries.cpp Tue Nov 27 11:40:46 2001 @@ -133,7 +133,23 @@ } var.print(c, level + delta_indent); point.print(c, level + delta_indent); - + } else if (is_a(c)) { + c.s << class_name() << "(relational("; + var.print(c); + c.s << ','; + point.print(c); + c.s << "),["; + unsigned num = seq.size(); + for (unsigned i=0; icoeff.compare(_ex1)) { - c.s << '^'; + if (is_a(c)) + c.s << "**"; + else + c.s << '^'; if (i->coeff.info(info_flags::negative)) { c.s << par_open; i->coeff.print(c); diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/relational.cpp GiNaC-1.0.1-print_python/ginac/relational.cpp --- GiNaC/ginac/relational.cpp Thu Nov 22 19:15:15 2001 +++ GiNaC-1.0.1-print_python/ginac/relational.cpp Fri Nov 23 20:36:26 2001 @@ -95,9 +95,17 @@ } else { - if (precedence() <= level) - c.s << "("; - lh.print(c, precedence()); + if (is_a(c)) { + c.s << class_name() << '('; + lh.print(c); + c.s << ','; + rh.print(c); + c.s << ",'"; + } else { + if (precedence() <= level) + c.s << "("; + lh.print(c, precedence()); + } switch (o) { case equal: c.s << "=="; @@ -120,9 +128,13 @@ default: c.s << "(INVALID RELATIONAL OPERATOR)"; } - rh.print(c, precedence()); - if (precedence() <= level) - c.s << ")"; + if (is_a(c)) + c.s << "')"; + else { + rh.print(c, precedence()); + if (precedence() <= level) + c.s << ")"; + } } } diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/symbol.cpp GiNaC-1.0.1-print_python/ginac/symbol.cpp --- GiNaC/ginac/symbol.cpp Fri Oct 26 17:08:25 2001 +++ GiNaC-1.0.1-print_python/ginac/symbol.cpp Fri Nov 23 18:00:58 2001 @@ -153,7 +153,12 @@ } else if (is_a(c)) c.s << TeX_name; - else + else if (is_a(c)) { + c.s << class_name() << "('" << name; + if (TeX_name != default_TeX_name()) + c.s << "','" << TeX_name; + c.s << "')"; + } else c.s << name; } diff -Nau -x CVS -x .libs -x .deps -x *.o -x *.lo -x *.la -x *~ -x Makefile GiNaC/ginac/wildcard.cpp GiNaC-1.0.1-print_python/ginac/wildcard.cpp --- GiNaC/ginac/wildcard.cpp Sat Oct 27 18:18:57 2001 +++ GiNaC-1.0.1-print_python/ginac/wildcard.cpp Fri Nov 23 18:07:48 2001 @@ -95,6 +95,8 @@ c.s << std::string(level, ' ') << class_name() << " (" << label << ")" << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec << std::endl; + } else if (is_a(c)) { + c.s << class_name() << '(' << label << ')'; } else c.s << "$" << label; } From kreckel at thep.physik.uni-mainz.de Wed Dec 19 17:17:52 2001 From: kreckel at thep.physik.uni-mainz.de (Richard B. Kreckel) Date: Wed, 19 Dec 2001 17:17:52 +0100 (CET) Subject: Adding python support to GiNaC In-Reply-To: Message-ID: Hi there, On Tue, 18 Dec 2001, Pearu Peterson wrote: > I have been working on the python interface to GiNaC. It is quite usable > already and I have tested it in many problems. However, it would be great > if some python specific changes that I had to do in GiNaC, could be added > to GiNaC. These changes include mostly printing expressions. Earlier I > used hooks from GiNaC archive features to get desired output for python, > but it was _very_ slow compared to the native GiNaC print hooks. > > So, please find a patch attached that adds two new print_context classes, > print_python and print_python_repr, with the corresponding additions to > print methods of the basic classes. > The patch includes also the following change in the idx::print method for > print_latex context: `a.b' becomes `a_{b}' if b is covariant, `a^{b}', > otherwise (you can ignore it if you don't like it). > > This patch is against GiNaC-1.0.1. I can make it also against the > latest GiNaC in CVS. Let me know if needed. I am about to check in your patch. Just one curious question: why the unsigned variable in > unsigned end = nops(); > if (end) > op(0).print(c); > for (unsigned i=1; i c.s << ','; > op(i).print(c); > } in classes mul and add? Did > op(0).print(c); > for (unsigned i=1; i c.s << ','; > op(i).print(c); > } not work? In this case you would have gotten an unevaluated expairseq, which'ld be strange... Also, I am removing the implementation of relational::is_equal_same_type you sent us for 1.0.1 because having relational::compare_same_type is enough by virtue of basic::compare_same_type. Well, theoretically. In practice, removing it brought me rather close to the gates of Heisenbug-madness. See the new lines in inifcns_trans.cpp for a scary moment. May GCC-2.95 soon fade into oblivion! :-( Regards -richy. -- Richard B. Kreckel From pearu at cens.ioc.ee Wed Dec 19 18:28:03 2001 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Wed, 19 Dec 2001 19:28:03 +0200 (EET) Subject: Adding python support to GiNaC In-Reply-To: Message-ID: On Wed, 19 Dec 2001, Richard B. Kreckel wrote: > I am about to check in your patch. Just one curious question: why the > unsigned variable in > > > unsigned end = nops(); > > if (end) > > op(0).print(c); > > for (unsigned i=1; i > c.s << ','; > > op(i).print(c); > > } > > in classes mul and add? Did > > > op(0).print(c); > > for (unsigned i=1; i > c.s << ','; > > op(i).print(c); > > } > > not work? In this case you would have gotten an unevaluated expairseq, > which'ld be strange... Indeed, it works. Silly me .. > Also, I am removing the implementation of relational::is_equal_same_type > you sent us for 1.0.1 because having relational::compare_same_type is > enough by virtue of basic::compare_same_type. I've checked out 1.0.2. All pyGiNaC tests pass fine. Thanks, Pearu From kreckel at thep.physik.uni-mainz.de Wed Dec 19 20:21:31 2001 From: kreckel at thep.physik.uni-mainz.de (Richard B. Kreckel) Date: Wed, 19 Dec 2001 20:21:31 +0100 (CET) Subject: After lifting the "no-bugs" ordinance... Message-ID: ...a couple of bugs were indeed discovered and fixed wich leeds us to the release of GiNaC-1.0.2, available at the usual places. It does not break compatibility with prior 1.0.n-versions. Enjoy -richy. -- Richard B. Kreckel From pearu at cens.ioc.ee Thu Dec 20 11:48:55 2001 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Thu, 20 Dec 2001 12:48:55 +0200 (EET) Subject: decomp_rational(pow(x,-2),x) fails with MemoryError Message-ID: Hi! Note that the following program fails to compute decomp_rational(pow(x,-2),x) #include #include using namespace std; using namespace GiNaC; int main() { symbol x("x"); cout << "r="<1 in x**-n. I am using latest GiNaC from CVS on woody debian. Regards, Pearu From cbauer at student.physik.uni-mainz.de Thu Dec 20 12:25:19 2001 From: cbauer at student.physik.uni-mainz.de (Christian Bauer) Date: Thu, 20 Dec 2001 12:25:19 +0100 Subject: decomp_rational(pow(x,-2),x) fails with MemoryError In-Reply-To: References: Message-ID: <20011220122518.A31058@student.physik.uni-mainz.de> Hi! On Thu, Dec 20, 2001 at 12:48:55PM +0200, Pearu Peterson wrote: > Note that the following program fails to compute > decomp_rational(pow(x,-2),x) Fixed in CVS. Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/ From kreckel at thep.physik.uni-mainz.de Fri Dec 21 19:50:20 2001 From: kreckel at thep.physik.uni-mainz.de (Richard B. Kreckel) Date: Fri, 21 Dec 2001 19:50:20 +0100 (CET) Subject: Just finished compiling version 1.0.2? Message-ID: Well, here comes the next load to keep your machine busy. Version 1.0.3 contains two bugfixes without compromising binary compatiblilty: * Fixed a bug where quo() would call vector::reserve() with a negative argument (reported by Pearu Peterson). * Fixed several bugs in code generation (reported by Do Hoang Son). We apologize for the inconvenience... -richy. -- Richard B. Kreckel