Ask Your Question

# Revision history [back]

Just to chime in here on this long abandoned question, the code generation module that DSM mentions is now included in Sage. Here's a short example:

sage: x, y = var('x, y')
sage: f = x**2 + sin(y)/sqrt(5*x+9*y)
sage: fs = f._sympy_() # convert to a sympy symbolic expression
sage: [(c_name, c_code), (h_name, c_header)] = codegen(("f", fs), "C", "test")
sage: print c_code
/******************************************************************************
*                      Code generated with sympy 0.7.1                       *
*                                                                            *
*              See http://www.sympy.org/ for more information.               *
*                                                                            *
*                       This file is part of 'project'                       *
******************************************************************************/
#include "test.h"
#include <math.h>

double f(double x, double y) {

return pow(x, 2) + sin(y)/sqrt(5*x + 9*y);

}