Status: New Owner: ---- Labels: Type-Defect Priority-Medium New issue 1487 by Toon.Verstraelen: fcode: print sympy expressions as Fortran code http://code.google.com/p/sympy/issues/detail?id=1487
Hi, The patch is rather trivial for now. It just serves as a basic starting point for further extensions and testing with the codegen. I have a few questions related to ccode and fcode: * Should an exception be raised when ccode or fcode encounter a function that is not supported in the standard definitions of the C and Fortran language? (I'm pro raising an exception.) We can introduce an optional argument, user_functions={}, for fcode and ccode. This list contains the names user-defined functions that the printer should not complain about. A few examples: In [15]: ccode(integrate(sin(x)/x,x)) Out[15]: Integral(sin(x)/x, x) This should always raise an exception. Such a thing is never ever going to be compilable. In [22]: ccode(gamma(x)) Out[22]: gamma(x) This should also raise an error since the gamma function is not part of the C standard. We can provide a way around the issue: In [23]: ccode(gamma(x), user_functions={gamma: 'gsl_sf_gamma'}) Out[23]: gsl_sf_gamma(x) Is this acceptable? * What to do with sympy constants that are not part of the language? A typical example in Fortran is the constant pi. In a normal program, it has to be defined by the programmer in this style: REAL (KIND=dp), PARAMETER :: pi = 3.14159265358979323846264338_dp We can replace them by their numerical value in the printer, but this is a bit messy. How are we going to determine the precision to be used? We can probably think of more fancy solutions at the codegen level, but the printer on itself should also give an acceptable result. * ccode has an implementation for Piecewise functions that does not return a single expression, but multiple statements. This is not compatible with the assumptions made by the codegen. We can replace this by a conditional operator: http://en.wikipedia.org/wiki/Conditional_operator Any comments? Attachments: 0001-fcode-print-sympy-expressions-as-Fortran-code.patch.gz 1.6 KB -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-issues" group. To post to this group, send email to sympy-issues@googlegroups.com To unsubscribe from this group, send email to sympy-issues+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy-issues?hl=en -~----------~----~----~----~------~----~------~--~---