RE: Re: Function as an argument of the function

*To*: mathgroup at smc.vnet.net*Subject*: [mg34698] RE: [mg34642] Re: [mg34638] Function as an argument of the function*From*: "DrBob" <majort at cox-internet.com>*Date*: Sat, 1 Jun 2002 04:29:06 -0400 (EDT)*Reply-to*: <drbob at bigfoot.com>*Sender*: owner-wri-mathgroup at wolfram.com

Functions don't exist in Mathematica quite the way they do in most languages. What we have instead are transformation rules. A rule that transforms Sin[Pi/2] into 1, for instance, might be an UpValue of Pi or it might be a DownValue, SubValue, or NValue of Sin. In fact it's none of these, so we can't know the relationship exists other than by evaluating Sin[Pi/2]. We can check those possibilities, and we can look for the NumericFunction attribute as Andrzej points out, but what Tomek really wanted to do... he CAN'T really do. Bobby -----Original Message----- From: Andrzej Kozlowski [mailto:andrzej at platon.c.u-tokyo.ac.jp] To: mathgroup at smc.vnet.net Subject: [mg34698] [mg34642] Re: [mg34638] Function as an argument of the function Strictly speaking your request does not make sense, since in Mathematica almost everything is a "function" in some sense or other. For example if f is a symbol you can always "apply" it to 2 to get f[2], and so on. However, I assume what yu mean is something in a very much narrower sense, meaning either a built-in numeric function like Sin, or a user defined function of the form f[x_]:= .... Well, something like this will do the trick, (with various obvious limitations): FunctionQ[f_] := Block[{x}, DownValues[f] != {} || MemberQ[Attributes[f], NumericFunction]] Now let's define a function: f[x_] := x^2 and something that needs an argument to be a function: g[f_?FunctionQ, a_] := f[a] We get: In[4]:= g[Sqrt,4] Out[4]= 2 In[5]:= g[Sin,x] Out[5]= Sin[x] In[6]:= g[f,x] Out[6]= x^2 In[7]:= g[p,x] Out[7]= g[p, x] Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ On Thursday, May 30, 2002, at 03:55 PM, Tomek wrote: > Hi. > I have to write a short function in Mathematica. But I have one > problem with it. One of arguments of my function have to be a > function of one variable. > How can I check if the argument of the function is a function of one > variable (I wish there's FunctionQ)? > > > >