Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 | _CompiledFunction] = True;
FunctionQ[f_Symbol] := Or[
  DownValues[f] =!= {}, 
  MemberQ[ Attributes[f], NumericFunction ]]
FunctionQ[_] = False;
like image 629
Phil Avatar asked Apr 16 '11 12:04

Phil


People also ask

What is the head of an expression in Mathematica?

The object f in an expression f[x,y,…] is known as the head of the expression. You can extract it using Head[expr].

How do you write a command in Mathematica?

Writing a Mathematica command"x cube"and "x square" are typed using the carat (^ ) . The product "9 x" does not need a multiplication symbol. The two possible forms for writing a product are "9 x" (employing a space as above) and "9*x" (employing an asterisk).


1 Answers

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.

like image 171
WReach Avatar answered Sep 27 '22 20:09

WReach