       Re: Forcing Argument Evaluation

• To: mathgroup at smc.vnet.net
• Subject: [mg49871] Re: [mg49848] Forcing Argument Evaluation
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Thu, 5 Aug 2004 09:20:31 -0400 (EDT)
• References: <200408041446.KAA20125@smc.vnet.net> <ABF3EBB6-E69F-11D8-A60A-000A95B4967A@mimuw.edu.pl>
• Sender: owner-wri-mathgroup at wolfram.com

```Although it is not needed in your case for a fuller implementation you
also need to add rules involving Power:

Unprotect[Times,Plus,Power];

(a_?NumericQ*f_.)[x_]:=a f[x];
(f_+g_)[x_]:=f[x]+g[x];
(f_*g_)[x_]:=f[x]*g[x];
(f_^n_?NumericQ)[x_]:=f[x]^n

Protect[Times,Plus,Power];

Andrzej

On 5 Aug 2004, at 07:24, Andrzej Kozlowski wrote:

>
> On 4 Aug 2004, at 16:46, Scott Guthery wrote:
>>
>> f[x_] := x^2;
>> a = {f,f/2};
>>
>> a[]
>> 4
>>
>> a[][
>> f/2
>>
>> I know I'm missing something fundamental.
>>
>> Cheers, Scott
>>
>>
>
> It's the same problem again, which I already once explained. The
> algebra of functions is not implemented in Mathematica so although f
> is a function f/2 is not a function. So you can't expect f/2 to
> have return anything. If you really want implement the algebra of
> fucntions you could do something like this:
>
>
>
>
> Unprotect[Times,Plus];
>
> (a_?NumericQ * f_)[x_]:=a f[x]
> (f_+g_)[x_]:=f[x]+g[x]
> (f_*g_)[x_]:=f[x]*g[x]
>
> Protect[Times,Plus]
>
> Now
>
> f[x_]:=x^2;
> a={f,f/2};
>
>
> a[]
> 2
>
>
>
> Andrzej Kozlowski
> Chiba, Japan
> http://www.mimuw.edu.pl/~akoz/
>

```

• Prev by Date: Re: ReadListBinary question
• Next by Date: Re: populate a list with random numbers from normal distribution?
• Previous by thread: Re: Forcing Argument Evaluation
• Next by thread: Re: Forcing Argument Evaluation