Is it possible to get fortran code for an expression?
Hello, is it possible to get the fortran code for expressions in SageMath?
Here's what I mean:
sage: var('a b x y')
( a, b, x, y )
sage: eq = x^a + 3/2*y^b
sage: get_fortran(eq)
x**a + 3.0/2.0*y**b
Right now the best I can do as a workaround is:
sage: eq.__str__().replace('^', '**')
x**a + 3/2*y**b
but the numbers appear as integers, which makes the division be performed as integer division in Fortran, which forces me to manually change that. Is there a function I can use to get what I want?
Cheers
Sage doesn't use Fortran for very many things - notably R and perhaps some other numerical routines. So there isn't a "canonical" Fortran version of most things. You may also be interested in f2py but of course this would be the opposite.
But really the question is, what do you want this for? Fortran doesn't really have "symbolic variables" and probably would be very inefficient for a lot of the things you want to do; if you ask a more specific question about what you need it for, perhaps there is something more targeted we can offer Fortran-wise.