MathGroup Archive 2008

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

Search the Archive

Re: Combining pure functions to produce a new pure

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89818] Re: Combining pure functions to produce a new pure
  • From: sashap <pavlyk at gmail.com>
  • Date: Sat, 21 Jun 2008 05:31:51 -0400 (EDT)
  • References: <g3fvuf$kt5$1@smc.vnet.net>

On Jun 20, 5:14 am, Bob Hanlon <hanl... at cox.net> wrote:
> Try
>
> h[f1_Function, f2_Function] :=
>   Function[x, {f1[x], f2[x]}];

Or, equivalently, and not using global symbols:

In[20]:= h[f1_Function, f2_Function] :=
  Function[Evaluate[{f1[#], f2[#]}]];

In[23]:= h[Function[x, Sin[x]], Cos[#] &]

Out[23]= {Sin[#1], Cos[#1]} &

Oleksandr Pavlyk

>
> Bob Hanlon
>
> ---- Mac <mwjdavid... at googlemail.com> wrote:
> > I have a function where one of the arguments is supposed to be a list
> > of pure functions. Tyhis is useful for an algorithm that can run using
> > multiple input functions. Based on a previous post some time ago
>
> >http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_...
> > /thread/b1faadec497c657d/5cc40d169d8992b4?lnk=gst&q=pure+function+#=
5cc4=
> > 0d169d8992b4
>
> > a method was proposed to address this. If I apply this method to list
> > arguments I get the following code and results:
>
> > In[60]:= h[f1_, f2_] :=
> >  Function[x,
> >   Evaluate[{f1[x], f2[x]} /.
> >     HoldPattern[Function[a_, b_]] -> Function[a, b][x]]]
>
> > Combine two simple pure functions - works as expected
>
> > In[58]:= h[# + 1 &, # + 2 &]
> > %[1]
>
> > Out[58]= Function[x$, {1 + x$, 2 + x$}]
>
> > Out[59]= {2, 3}
>
> > Combine two custom functions and I get the internal details of one
> > function and with the second one evaluated properly
>
> > In[66]:= h[forwardmodel["letoan", #] &, forwardmodel["saatchiphv", #]
> > &]
> > %[100]
>
> > Out[66]= Function[x$, {If[-10. - 32./biomass$491^0.434294 <= -15,
> >    10 Log[10, 10^(\[Gamma]1$491/10) Sin[27 =B0]],
> >    10 Log[10, 10^(\[Gamma]2$491/10) Sin[27 =B0]]],
> >   If[x$ > 2, -35.01 + 4.296 Log[x$], -35.01 + 4.296 Log[2]]}]
>
> > Out[67]= {If[-10. - 32./biomass$491^0.434294 <= -15,
> >   10 Log[10, 10^(\[Gamma]1$491/10) Sin[27 =B0]],
> >   10 Log[10, 10^(\[Gamma]2$491/10) Sin[27 =B0]]], -15.2262}
>
> > I can see that this effect is due to the evaluations of the function
>
> >  forwardmodel["letoan", #] &
>
> > so that the output no longer depends on the pure function variable $x.
> > Note that separately these functions work as expected. Here some
> > predicted radar backscatter coefficients.
>
> > In[69]:= forwardmodel["letoan", #] &[100]
> > forwardmodel["saatchiphv", #] &[100]
>
> > Out[69]= -17.6312
>
> > Out[70]= -15.2262
>
> > Can annybody suggest a general solution ?
>
> > Many thanks
>
> > Mac



  • Prev by Date: Re: WorldPlot and excel data
  • Next by Date: Re: Problems with FindRoot and recursive functions
  • Previous by thread: Re: Problem with Mesh for MatrixPlot
  • Next by thread: Re: Combining pure functions to produce a new pure