       Re: FunctionQ?

• To: mathgroup at smc.vnet.net
• Subject: [mg113329] Re: FunctionQ?
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Sat, 23 Oct 2010 07:08:53 -0400 (EDT)

```On 10/22/10 at 1:35 AM, sam.takoy at yahoo.com (Sam Takoy) wrote:

>How does one tell whether a variable is a function? More
>specifically, how does one tell whether a variable is a function of
>two arguments? Finally, how does one tell whether a variable is a
>function of two arguments that returns an array?

A function will have down values but a variable will not. For example:

In:= f[x_] := 2 x
g[x_] = 4 x;
DownValues /@ {f, g}

Out= {{HoldPattern[f(x_)]:>2 x},{HoldPattern[g(x_)]:>4 x}}

In:= y = 9;
DownValues[y]

Out= {}

Further, you can use the down values of a function to answer
your other questions. For example:

In:= k[x_, y_] := x y
Length[Cases[DownValues[k], _k, \[Infinity]][]]

Out= 2

In:= m[x_] := {x}
Head@DownValues[m][[1, 2]]

Out= List

But there is a difficulty with your other questions. For
example, I can do:

In:= m[x_, y] := x y

In:= DownValues[m]

Out= {HoldPattern[m(x_)]:>{x},HoldPattern[m(x_,9)]:>x y}

Now, m can take either 1 or 2 arguments and returns either a
single value or an array depending on arguments. What I've done
above with DownValues to get the number of arguments and return
values only works for simply defined functions.

```

• Prev by Date: Re: Replacement in a held function
• Next by Date: Re: Fitting the solution of a differential equation to a data set
• Previous by thread: Re: FunctionQ?
• Next by thread: Re: FunctionQ?