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

• To: mathgroup at smc.vnet.net
• Subject: [mg89492] Re: [mg89457] Transform list of numbers into pure functions using replace rule
• From: "Szabolcs HorvÃt" <szhorvat at gmail.com>
• Date: Wed, 11 Jun 2008 03:15:40 -0400 (EDT)
• References: <200806100739.DAA09190@smc.vnet.net>

```On Tue, Jun 10, 2008 at 10:39, Mac <mwjdavidson 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.
>

Your syntax is incorrect (look up /; and ?), and Hold is completely unnecessary:

Probably you meant the following:

{1, 2, f[x]} /. x_?NumberQ -> (x &)

Also, f[x] looks like the value of a function, which may be a
function, but is more commonly a number ... did you mean f or f[x]
here?

```

• Prev by Date: Re: Many problems with 6.0, possibly java
• Next by Date: Re: Dynamic GUI problem II.
• Previous by thread: Transform list of numbers into pure functions using replace rule
• Next by thread: Re: Transform list of numbers into pure functions using replace rule