MathGroup Archive 2008

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

Search the Archive

Re: Transform list of numbers into pure functions using replace rule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89513] Re: Transform list of numbers into pure functions using replace rule
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 11 Jun 2008 03:20:00 -0400 (EDT)
  • References: <g2lb8t$964$1@smc.vnet.net> <g2lnoo$ihb$1@smc.vnet.net>


Hi,

you may try this:

{1,2,f[x],3&} //. {x1___,x2_?NumericQ,x3___}->{x1,x2&,x3}

Daniel



Mac wrote:

> On Jun 10, 9:42 am, Mac <mwjdavid... at googlemail.com> wrote:

>> Hello,

>>

>> I'm developed a program to invert satellite observations into

>> geophysical variables such as forest biomass. One of the input

>> parameters are the errors in the observation channels which can be

>> either constant or a function. To be consistent the program expects

>> all errors to be functions but they can also be constant functions

>> e.g. if the error is 4 then the input parameter is "4&".

>>

>> I've however hit a problem with the replacement rule that allows me to

>> transform all input errors into a function. The following works as

>> expected in that constants in the list are transformed into virtual

>> functions and functions in the list are left alone.

>>

>> In[40]:= If[NumberQ[#], ToExpression[ToString[#] <> "&"], #] & /@ {1,

>>   2, 3 &, f[x]}

>>

>> Out[40]= {1 &, 2 &, 3 &, f[x]}

>>

>> However, I cannot find a replacement rule to do the same job. Here is

>> one try:

>>

>> In[39]:= {1, 2, f[x]} /. x_ /; NumberQ -> Hold[x &]

>>

>> Out[39]= {1, 2, f[x]}

>>

>> Any help would be appreciated.

>>

>> Mac

> 

> Hello,

> 

> Many thanks for your very quick reply. Your solution doesn't quite

> work because I would also like to transform lists of this type (it was

> in the first example I gave):

> 

> In[3]:= {1, 2, f[x], 3 &} /. x_ /; NumberQ[x] -> (x &)

> 

> Out[3]= {1 &, 2 &, f[x], 3 & &}

> 

> The problem is the "3&&" which I would like to be "3&".

> 

> Any magic that you can propose ?

> 

> many thanks in any case

> 

> Mac

> 





-- 



Daniel Huber

Metrohm Ltd.

Oberdorfstr. 68

CH-9100 Herisau

Tel. +41 71 353 8585, Fax +41 71 353 8907

E-Mail:<mailto:dh at metrohm.com>

Internet:<http://www.metrohm.com>




  • Prev by Date: Re: Problem inputting data into a table that is larger than a window
  • Next by Date: Re: Transform list of numbers into pure functions using replace rule
  • Previous by thread: Re: Transform list of numbers into pure functions using replace rule
  • Next by thread: Re: Transform list of numbers into pure functions using replace rule