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;
The object f in an expression f[x,y,…] is known as the head of the expression. You can extract it using Head[expr].
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With