Can't compile example from the tutorial
I'm trying to compile the example from https://www.ginac.de/tutorial/#Input_002foutput. My complete version of the example, with 'include' and 'using' statements, and with an added declaration of x and y in main(), is: ----- #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; static void my_print(const ex & e) { if (is_a<function>(e)) cout << ex_to<function>(e).get_name(); else cout << ex_to<basic>(e).class_name(); cout << "("; size_t n = e.nops(); if (n) for (size_t i=0; i<n; i++) { my_print(e.op(i)); if (i != n-1) cout << ","; } else cout << e; cout << ")"; } int main() { symbol x("x"), y("y"); my_print(pow(3, x) - 2 * sin(y / Pi)); cout << endl; return 0; } ----- I compile it with $ g++ --std=c++17 $(pkg-config --cflags ginac cln) custom_expression_output.cpp $(pkg-config --libs ginac cln) -o custom_expression_output which gives the following, with either g++ 11.4.0 or 12.3.0: ----- custom_expression_output.cpp: In function ‘void my_print(const GiNaC::ex&)’: custom_expression_output.cpp:16:9: error: parse error in template argument list 16 | if (is_a<function>(e)) | ^~~~~~~~~~~~~~ custom_expression_output.cpp:16:23: error: no matching function for call to ‘is_a<<expression error> >(const GiNaC::ex&)’ 16 | if (is_a<function>(e)) | ~~~~~~~~~~~~~~^~~ In file included from /home/warren/local/include/ginac/registrar.h:27, from /home/warren/local/include/ginac/basic.h:29, from /home/warren/local/include/ginac/ginac.h:28, from custom_expression_output.cpp:8: /home/warren/local/include/ginac/print.h:189:13: note: candidate: ‘template<class T> bool GiNaC::is_a(const GiNaC::print_context&)’ 189 | inline bool is_a(const print_context & obj) | ^~~~ /home/warren/local/include/ginac/print.h:189:13: note: template argument deduction/substitution failed: custom_expression_output.cpp:16:23: error: template argument 1 is invalid 16 | if (is_a<function>(e)) | ~~~~~~~~~~~~~~^~~ In file included from /home/warren/local/include/ginac/ginac.h:28, from custom_expression_output.cpp:8: /home/warren/local/include/ginac/basic.h:313:13: note: candidate: ‘template<class T> bool GiNaC::is_a(const GiNaC::basic&)’ 313 | inline bool is_a(const basic &obj) | ^~~~ /home/warren/local/include/ginac/basic.h:313:13: note: template argument deduction/substitution failed: custom_expression_output.cpp:16:23: error: template argument 1 is invalid 16 | if (is_a<function>(e)) | ~~~~~~~~~~~~~~^~~ In file included from /home/warren/local/include/ginac/ginac.h:30, from custom_expression_output.cpp:8: /home/warren/local/include/ginac/ex.h:955:13: note: candidate: ‘template<class T> bool GiNaC::is_a(const GiNaC::ex&)’ 955 | inline bool is_a(const ex &obj) | ^~~~ /home/warren/local/include/ginac/ex.h:955:13: note: template argument deduction/substitution failed: custom_expression_output.cpp:16:23: error: template argument 1 is invalid 16 | if (is_a<function>(e)) | ~~~~~~~~~~~~~~^~~ custom_expression_output.cpp:17:17: error: parse error in template argument list 17 | cout << ex_to<function>(e).get_name(); | ^~~~~~~~~~~~~~~ custom_expression_output.cpp:17:32: error: no matching function for call to ‘ex_to<<expression error> >(const GiNaC::ex&)’ 17 | cout << ex_to<function>(e).get_name(); | ~~~~~~~~~~~~~~~^~~ In file included from /home/warren/local/include/ginac/ginac.h:30, from custom_expression_output.cpp:8: /home/warren/local/include/ginac/ex.h:978:17: note: candidate: ‘template<class T> const T& GiNaC::ex_to(const GiNaC::ex&)’ 978 | inline const T &ex_to(const ex &e) | ^~~~~ /home/warren/local/include/ginac/ex.h:978:17: note: template argument deduction/substitution failed: custom_expression_output.cpp:17:32: error: template argument 1 is invalid 17 | cout << ex_to<function>(e).get_name(); | ~~~~~~~~~~~~~~~^~~ ----- If I change the first occurrence of "function" to "symbol" (just to see how it compiles), the expression is_a<symbol>(e) does not result in an error (but the compilation fails for other reasons). Any ideas of what is going on? Warren
On Wed, Jul 2, 2025 at 3:10 PM Warren Weckesser <warren.weckesser@gmail.com> wrote:
I'm trying to compile the example from https://www.ginac.de/tutorial/#Input_002foutput.
My complete version of the example, with 'include' and 'using' statements, and with an added declaration of x and y in main(), is: ...
I forgot to add that I'm using ginac 1.8.9 and cln 1.3.7, compiled from source tarballs. Warren
On Wed, Jul 2, 2025 at 3:10 PM Warren Weckesser <warren.weckesser@gmail.com> wrote:
I'm trying to compile the example from https://www.ginac.de/tutorial/#Input_002foutput.
My complete version of the example, with 'include' and 'using' statements, and with an added declaration of x and y in main(), is:
----- #include <iostream> #include <ginac/ginac.h>
using namespace std; using namespace GiNaC;
static void my_print(const ex & e) { if (is_a<function>(e)) cout << ex_to<function>(e).get_name(); else cout << ex_to<basic>(e).class_name(); cout << "("; size_t n = e.nops(); if (n) for (size_t i=0; i<n; i++) { my_print(e.op(i)); if (i != n-1) cout << ","; } else cout << e; cout << ")"; }
int main() { symbol x("x"), y("y"); my_print(pow(3, x) - 2 * sin(y / Pi)); cout << endl; return 0; } -----
I compile it with
$ g++ --std=c++17 $(pkg-config --cflags ginac cln) custom_expression_output.cpp $(pkg-config --libs ginac cln) -o custom_expression_output
which gives the following, with either g++ 11.4.0 or 12.3.0:
----- custom_expression_output.cpp: In function ‘void my_print(const GiNaC::ex&)’: custom_expression_output.cpp:16:9: error: parse error in template argument list 16 | if (is_a<function>(e)) | ^~~~~~~~~~~~~~ custom_expression_output.cpp:16:23: error: no matching function for call to ‘is_a<<expression error> >(const GiNaC::ex&)’ 16 | if (is_a<function>(e)) | ~~~~~~~~~~~~~~^~~ In file included from /home/warren/local/include/ginac/registrar.h:27, from /home/warren/local/include/ginac/basic.h:29, from /home/warren/local/include/ginac/ginac.h:28, from custom_expression_output.cpp:8: /home/warren/local/include/ginac/print.h:189:13: note: candidate: ‘template<class T> bool GiNaC::is_a(const GiNaC::print_context&)’ 189 | inline bool is_a(const print_context & obj) | ^~~~ /home/warren/local/include/ginac/print.h:189:13: note: template argument deduction/substitution failed: custom_expression_output.cpp:16:23: error: template argument 1 is invalid 16 | if (is_a<function>(e)) | ~~~~~~~~~~~~~~^~~ In file included from /home/warren/local/include/ginac/ginac.h:28, from custom_expression_output.cpp:8: /home/warren/local/include/ginac/basic.h:313:13: note: candidate: ‘template<class T> bool GiNaC::is_a(const GiNaC::basic&)’ 313 | inline bool is_a(const basic &obj) | ^~~~ /home/warren/local/include/ginac/basic.h:313:13: note: template argument deduction/substitution failed: custom_expression_output.cpp:16:23: error: template argument 1 is invalid 16 | if (is_a<function>(e)) | ~~~~~~~~~~~~~~^~~ In file included from /home/warren/local/include/ginac/ginac.h:30, from custom_expression_output.cpp:8: /home/warren/local/include/ginac/ex.h:955:13: note: candidate: ‘template<class T> bool GiNaC::is_a(const GiNaC::ex&)’ 955 | inline bool is_a(const ex &obj) | ^~~~ /home/warren/local/include/ginac/ex.h:955:13: note: template argument deduction/substitution failed: custom_expression_output.cpp:16:23: error: template argument 1 is invalid 16 | if (is_a<function>(e)) | ~~~~~~~~~~~~~~^~~ custom_expression_output.cpp:17:17: error: parse error in template argument list 17 | cout << ex_to<function>(e).get_name(); | ^~~~~~~~~~~~~~~ custom_expression_output.cpp:17:32: error: no matching function for call to ‘ex_to<<expression error> >(const GiNaC::ex&)’ 17 | cout << ex_to<function>(e).get_name(); | ~~~~~~~~~~~~~~~^~~ In file included from /home/warren/local/include/ginac/ginac.h:30, from custom_expression_output.cpp:8: /home/warren/local/include/ginac/ex.h:978:17: note: candidate: ‘template<class T> const T& GiNaC::ex_to(const GiNaC::ex&)’ 978 | inline const T &ex_to(const ex &e) | ^~~~~ /home/warren/local/include/ginac/ex.h:978:17: note: template argument deduction/substitution failed: custom_expression_output.cpp:17:32: error: template argument 1 is invalid 17 | cout << ex_to<function>(e).get_name(); | ~~~~~~~~~~~~~~~^~~ -----
The problem appears to have something to do with how the name 'function' is declared/namespaced. I can work around the problem by fully qualifying 'function' as 'GiNaC::function', e.g. ----- if (is_a<GiNaC::function>(e)) cout << ex_to<GiNaC::function>(e).get_name(); else cout << ex_to<basic>(e).class_name(); ----- Warren
Hello,
On Wed, 2 Jul 2025 15:55:56 -0400, Warren Weckesser <warren.weckesser@gmail.com> said: WW> On Wed, Jul 2, 2025 at 3:10 PM Warren Weckesser WW> <warren.weckesser@gmail.com<mailto:warren.weckesser@gmail.com>> WW> wrote: I'm trying to compile the example from WW> https://www.ginac.de/tutorial/#Input_002foutput.
The issue appears because "function" (or rather std:: function) is now a known class for modern C++ compilers. You need to add proper resolution by replacing <function> to <GiNaC::function> everywhere. I will submit a patch for this soon. Best wishes, Vladimir -- Vladimir V. Kisil http://v-v-kisil.scienceontheweb.net Book: Geometry of Mobius Maps https://doi.org/10.1142/p835 Soft: Geometry of cycles http://moebinv.sourceforge.net/ Jupyter notebooks: https://github.com/vvkisil?tab=repositories
participants (2)
-
Vladimir V. Kisil
-
Warren Weckesser