       Re: Controlled evaluation of functions

• To: mathgroup at smc.vnet.net
• Subject: [mg56806] Re: [mg56763] Controlled evaluation of functions
• From: "David Park" <djmp at earthlink.net>
• Date: Fri, 6 May 2005 03:00:40 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Brett,

The reason Sin doesn't further evaluate is that you have exact expressions
and Mathematica knows no further rules for it. But make i in your Table an
approximate number and Sin will evaluate and behave just like your k.

So if you don't want k to evaluate, don't give it a definition! Or rather,
make it a rule and then use the rule when you want evaluation. And in
general, if you want controlled evaluation use rules instead of definitions.

krule = k -> (#^2 &);
f[i_, x_] := k[i x]

g[x_] = Table[f[i, x], {i, 3}]
{k[x], k[2 x], k[3 x]}

{3, 0, 1}.g[y]
% /. krule
3 k[y] + k[3 y]
12*y^2

David Park

From: Brett Patterson [mailto:muckle.moose at gmail.com]
To: mathgroup at smc.vnet.net

Consider the following behaviour:

In:= f[i_, x_] := Sin[i x]

In:= g[x_] = Table[f[i, x], {i, 3}]

Out= {Sin[x], Sin[2 x], Sin[3 x]}

In:= {3, 0, 1} . g[y]

Out= 3 Sin[y] + Sin[3 y]

This is what I want to do, but using my own function instead of Sin.
However, this is the result:

In:= k[x_] := x^2           (* This is my alternative to Sin *)

In:= f[i_, x_] := k[i x]

In:= g[x_] = Table[f[i, x], {i, 3}]

Out= {x^2, 4 x^2, 9 x^2}    (* I want {k[x], k[2 x], k[3 x]} *)

In:= {3, 0, 1} . g[y]

Out= 12 y^2                 (* I want 3 k[y] + k[3 y] *)

How can I get the function k to behave like Sin, so that it is not
evaluated?

Note that in my real application, k is a lot more complex and has
conditions on its arguments, etc.

Thanks!

Brett Patterson

```

• Prev by Date: Re: ZTarnsform[Sin[4 n],n,z] OK, but ZTransform[Sin[5 n],n,z,] hangs?
• Next by Date: Re: Bug in Integrate in Version 5.1?
• Previous by thread: Re: Controlled evaluation of functions
• Next by thread: InitializationCell -> Toggle shortcut key