exporting a list of functions for use in a C function
- To: mathgroup at smc.vnet.net
- Subject: [mg44346] exporting a list of functions for use in a C function
- From: Nathan Moore <nmoore at physics.umn.edu>
- Date: Wed, 5 Nov 2003 10:02:11 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
I've composed a large list of functions in Mathematica that I'd like to
have a c function evaluate. To my knowledge c and C++ reject the
convention x^2 and prefer either x*x or pow(x,2). The functions are
integer powers of a single variable. I'm using the command,
Export["function_list.txt", Table[gflist[p], {p, 2, 5}], "CSV"]
where "gflist[n]" generates the said set of functions for the case "n".
The output file then looks like:
[winesap:~] nmoore% cat function_list.txt
1/(8*d*l^3*Pi)
1/(8*l^3*Pi),-(-3 + d)/(16*d*l^3*Pi)
(8 - 3*d)/(64*l^3*Pi),(-4 + d)^2/(64*d*l^3*Pi)
-(-5 + d^2)/(64*l^3*Pi),(-5 + 30*d - 15*d^2 +
2*d^3)/(192*d*l^3*Pi),-(-5 + d)^3/(384*d*l^3*Pi)
I don't mind pasting in the "case" statement required by c, but I don't
have the free two days required to re-express all the carats (^). How
can I have Mathematica express x^15 as x*x*x*x*x*x*x*x*x*x*x*x*x*x*x
(the highest power of the polynomial is "n", I'd like to export the set
of functions n=2 to n=30 or so - far too much typing for me)
NT Moore
University of Minnesota Physics