Re: FullSimplify in functions
- To: mathgroup at smc.vnet.net
- Subject: [mg82601] Re: FullSimplify in functions
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Fri, 26 Oct 2007 05:14:41 -0400 (EDT)
- References: <firstname.lastname@example.org>
Michael Mandelberg wrote: > What is the best/proper way to incorporate FullSimplify[ ] into a > function definition in such a way that the FullSimplify[ ] executes > only once instead of each time the function is called, i.e. it is > "compiled", though I'm not sure this is the same thing as the > Mathematica Compile[ ] function. > OK, I think I misunderstood what you meant. If the expression FullSimplify will be applied to does not depend on the argument of the function, then simply use Set instead of SetDelayed. In:= f[x_] = Simplify[Sin[x]^2 + 2 Cos[x]^2] Out= 1/2 (3 + Cos[2 x]) In:= ?f Global`f f[x_]=1/2 (3+Cos[2 x]) In:= g[x_] := Simplify[Sin[x]^2 + 2 Cos[x]^2] In:= ?g Global`g g[x_]:=Simplify[Sin[x]^2+2 Cos[x]^2] Is this what you meant? Szabolcs P.S. Still, compilation is something *completely* different from evaluating an expression before assigning it to something. Read the doc page tutorial/CompilingMathematicaExpressions to understand it.