2

It's not easy to see whether an expression can act as a "good" function.

A good function refers to an operater that transforms symbolic entities like 1+x^2 or numeric entities like 1+Sqrt[2] into a new one.

(Remember that we only discuss the function,but not the function of function here.)

For example, Composition[#1^2&,InverseFunction[1/#1&]] is a good function, but Composition[1[3],2[2]] isn't.

So how to determine whether an expression can act as a "good" function in general cases?

WateSoyan
  • 1,854
  • 13
  • 19

1 Answers1

4

In short: there's no reliable way, so don't bother. Leave it to the users of your function to pass correct arguments to it which are actually functions. I think there was a question about this before, but I can't find it.


Why is this not possible? There are many, many very different types of expressions in Mathematica that can act as functions, and each new version adds more. They don't have a common attribute that identifies them as functions. The only two ways to test would be:

Examples of expressions that can act as functions:

  • DownValues: f[x_]:=x^2
  • SubValues: a[_][_][x_]:=x^2
  • Composition
  • Function
  • InterpolatingFunction, BooleanFunction, CompiledFunction, Associations, etc.
  • Operator forms such as Map[f], Apply[f], etc.
  • probably many more that I can't think of right now
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263