MathGroup Archive 2002

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

Search the Archive

RE: Re: Function as an argument of the function

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.


-----Original Message-----
From: Andrzej Kozlowski [mailto:andrzej at] 
To: mathgroup at
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], 

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:








g[p, x]

Andrzej Kozlowski
Toyama International University

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: RE: Re: Function as an argument of the function
  • Next by Date: Re: Efficiency question
  • Previous by thread: RE: Re: Function as an argument of the function
  • Next by thread: Re: Re: Function as an argument of the function