MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FullSimplify in functions

  • To: mathgroup at
  • Subject: [mg82601] Re: FullSimplify in functions
  • From: Szabolcs Horvát <szhorvat at>
  • Date: Fri, 26 Oct 2007 05:14:41 -0400 (EDT)
  • References: <ffpq3s$lbu$>

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[1]:= f[x_] = Simplify[Sin[x]^2 + 2 Cos[x]^2]
Out[1]= 1/2 (3 + Cos[2 x])

In[2]:= ?f
f[x_]=1/2 (3+Cos[2 x])

In[3]:= g[x_] := Simplify[Sin[x]^2 + 2 Cos[x]^2]

In[4]:= ?g
g[x_]:=Simplify[Sin[x]^2+2 Cos[x]^2]

Is this what you meant?


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.

  • Prev by Date: Re: Selecting Rows Where All Columns Satisfy a Condition
  • Next by Date: Re: eigenvectors is taking lot of time
  • Previous by thread: Re: FullSimplify in functions
  • Next by thread: Re: FullSimplify in functions