MathGroup Archive 2002

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

Search the Archive

Re: Function as an argument of the function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34642] Re: [mg34638] Function as an argument of the function
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Fri, 31 May 2002 04:26:16 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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)?
>
>
>
>



  • Prev by Date: Efficiency question
  • Next by Date: RE: RE: two fonts in Plot
  • Previous by thread: Re: Function as an argument of the function
  • Next by thread: Extraction of positive values from list of both +/- values