MathGroup Archive 2006

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

Search the Archive

Re: Is it possible to "pre-evaluate" parts of pure function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70419] Re: Is it possible to "pre-evaluate" parts of pure function?
  • From: "Philipp" <piotr at bigpond.net.au>
  • Date: Mon, 16 Oct 2006 02:34:13 -0400 (EDT)
  • References: <egi22b$jd9$1@smc.vnet.net><egn94d$1d9$1@smc.vnet.net> <egse5o$crv$1@smc.vnet.net>

Roland,

Your method appears to be by far the most flexible/general one.

To extend it so that some symbols are evaluated at the definition time,
while others at the execution time is rather trivial as shown below.

Symbol c1 to be evaluated at the definition time, c2 at the execution
time:

In[1]:=  c1 = 5; c2 = 7;
         SetOptions[f, MultiplierFunction ->
           ReleaseHold[Apply[Function, {c1 # / HoldForm[c2]}]]]

Out[2]=  {MultiplierFunction -> ((5 #1) / c2 &)}

Philipp.

P.S. Jon McLoone's solution could also be extended for the same result,
i.e.,
In[1]:=  SetOptions[f, MultiplierFunction ->
           ReleaseHold[(Evaluate[c1 # / HoldForm[c2]] &)]]
Out[1]=  {MultiplierFunction -> ((5 #1) / c2 &)}

Roland Franzius wrote:

> Philpp schrieb:
> > Thanks a lot for all answers (including emails). I suppose the correct
> > solution
> >
> > SetOptions[f, MultiplierFunction -> (Evaluate[const #] &)]
> >
> > escaped me due to my lack of understanding of the pure function (body)&
> > syntax. As Jon McLoone points out, "the Evaluate needs to be on the
> > argument of Function not around the outside of it"
>
> An easy solution for problems of this kind is always
>
> f=Function@@{expression containing # and named symbols with values to be
> used at definition time}
>
> Using this definition the expression with Slot[] is evaluated first and
> becomes a function then using Apply. For functions with named arguments
> it works too.
>
> f=Function@@{{x,y},expression containing x,y }
>
> You only have to be cautious in order to avoid symbols you don't want to
> get evaluated at definition time.
> 
> -- 
> 
> Roland Franzius
> Roland Franzius


  • Prev by Date: Re: Is it possible to "pre-evaluate" parts of pure function?
  • Next by Date: Re: variable metric method automatic gradient yields Indeterminate
  • Previous by thread: Re: Is it possible to "pre-evaluate" parts of pure function?
  • Next by thread: IntervalComplement