Using Robert's suggestion of repr() got me pretty close. The biggest
remaining issue is that Sage writes a^x whereas C needs pow(a,x). For
simple cases, I was able to fix this with regular expression
substitution as follows:
import re
p = re.compile("([a-zA-Z0-9]+?)\\^([a-zA-Z0-9]+)")
o = open("mycode.c", "w")
o.write("E1 = "
o.write(p.subn("pow(\\1,\\2)", repr(E1))[0])
o.write(";\n")
Here E1 is the expression to be written out.
Unfortunately, my regular expression is too simple to handle cases
like (a+b)^2.
--Michael
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---