how to let ccode to print sympy.I as 1i, the c++ 14 style

65 views
Skip to first unread message

chaowen guo

unread,
May 12, 2016, 11:01:46 PM5/12/16
to sympy
Hi:

The output of sympy.ccode(1+sympy.I) is '1+I'

However, in c++14 mode, like g++ -std=c++14 source.cpp, the g++ compiler does not think I is the imaginary unit.

But in the http://en.cppreference.com/w/cpp/numeric/complex, I know that after
using namespace std::complex_literals;
I can use 1i to represent the imaginary unit.

So how to tell ccode not to convert sympy.I into I but 1i?

I just know that there just exists ccode to convert sympy expression into c code. But I can not find any cppcode to convert sympy expression into c++ code.

Jason Moore

unread,
May 13, 2016, 4:18:13 PM5/13/16
to sy...@googlegroups.com
You can subclass the CCodePrinter and change the method for sympy.I to print as you like. Examples are here: http://docs.sympy.org/latest/modules/printing.html

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/4177732d-3956-4f12-b2b9-7edc27e845a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Meurer

unread,
May 13, 2016, 4:20:29 PM5/13/16
to sy...@googlegroups.com
A cppcode would be useful to have for things like this (or just a flag
to ccode if the differences are minor).

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/CAP7f1AiF55f8Q2hm%2BK27E39-HS%3DGL5VKxqNUcJrzEhKE_fbHbQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages