MathGroup Archive 2009

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

Search the Archive

Re: Determine if a parameter is a function

  • To: mathgroup at
  • Subject: [mg101838] Re: Determine if a parameter is a function
  • From: ADL <alberto.dilullo at>
  • Date: Sun, 19 Jul 2009 07:13:25 -0400 (EDT)
  • References: <h3kddu$g35$>

Actually, after some work, I found a solution which appears more
reliable (but who knows...):

FunctionQ[f_] := (functionQtest2[f] || functionQtest3[f]) &&

functionQtest1[f_Symbol] := (Length[StringPosition[ToString
functionQtest1[___] := True;
functionQtest2[f_] := (Head[f]===Function);
functionQtest3[f_] := (AtomQ[f] && (Head[f]===Symbol) && (!NumericQ
[f]) && (

The functionQtest1 test comes from a little heuristics about usage
Then, the following comes out:

In:= FunctionQ[Red]
Out= False

In:= FunctionQ[\[ScriptCapitalA]]
Out= False

In:= FunctionQ[Log]
Out= True

In:= FunctionQ[Algebraics]
Out= False

In:= FunctionQ[Log[Sin[#]] &]
Out= True

In:= systemFunctions = Select[ToExpression /@ Names["System`*"],
In:= systemFunctions // Length
Out= 1661


On Jul 15, 1:09 pm, Peter Breitfeld <ph... at> wrote:
> Suppose I have a function eg
> myfunc[f_,x_]:= <some definitions>
> f should be a pure function like (#^2&) or Function[{x},x^2] or a named
> function either self defined, like
> f[x_]:=x^2   or g[x_]=x^2
> or built-in like Sin, Log, ...
> How can I test if f is any of these, to be able to yield a message on
> wrong input?
> I found that the pure-functions have Head Function, but all the others
> have Head Symbol, so asking for the head is not sufficient.
> --
> _________________________________________________________________
> Peter Breitfeld, Bad Saulgau, Germany --

  • Prev by Date: Re: Different (real) solutions using Solve for same equation
  • Next by Date: Re: how to use to export a dxf file
  • Previous by thread: Re: Determine if a parameter is a function
  • Next by thread: Re: Determine if a parameter is a function