开发者

Is there a function head in mathematica that can be used to define an input type?

I am defining a function that takes as input a function and I want to specify it in the input type i.e. Operat[_?FunctionQ]:=... But there is no functionQ as of yet in mathematica. How do I get aroud this except not specifying any type at all.

Any ideas?

Oh! This: Test if an expression is a Function? may be the answer i am looking for. I am reading further

Is the solution proposed there robust?, i.e.:

FunctionQ[_Function | _InterpolatingFunction | _Compil开发者_StackOverflowedFunction] = True;
FunctionQ[f_Symbol] := Or[
  DownValues[f] =!= {}, 
  MemberQ[ Attributes[f], NumericFunction ]]
FunctionQ[_] = False;


The exhibited definition has great utility. The question is: what exactly constitutes a function in Mathematica? Pure functions and the like are easily to classify as functions, but what about definitions that involve pattern-matching? Consider:

h[g[x_]] ^:= x + 1

Is h to be considered a function? If so, it will be hard to identify as it will entail examining the up-values of every symbol in the system to make that determination. Is g a function? It has an up-value, but g[x] is an inert expression.

What about head composition:

f[x_][y_][z_] := x + y + z

Is f a function? How about f[1] or f[1][2]?

And then there are the various capabilities like JLink and NETLink:

Needs["JLink`"]
obj = JavaNew["java.util.Date"]
obj@toString[]

Is obj@toString a function?

I hate to bring up these problems without offering solutions -- but I want to emphasize that the question as to what constitutes a function in the Mathematica context is a tricky one. It is tricky from both the theoretical and practical standpoints.

I think that the answer to whether the exhibited function test is complete really depends upon the types of expressions that you will be feeding it in your specific application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜