Re: FunctionQ?

*To*: mathgroup at smc.vnet.net*Subject*: [mg113311] Re: FunctionQ?*From*: Pierre Albarede <pa.news at free.fr>*Date*: Sat, 23 Oct 2010 07:05:28 -0400 (EDT)*References*: <i9r7vd$hoo$1@smc.vnet.net>

On Oct 22, 7:37 am, Sam Takoy <sam.ta... at yahoo.com> wrote: > How does one tell whether a variable is a function? > More specifically, how does one tell whether a variable is a function of > two arguments? If an expression has the head Function, for example, Function[2#] or 2#&, then it is a function. But the converse is not true. A lot of functions do not have the head Function, for example, Head@Sin -> Symbol. Any symbol with no rules can be considered as a function of any number of argument, for example, ClearAll@f1; f1[x] is a valid expression. You can check if some expression is a function of 2 arguments by trying : Check[Sin[x, y], "not a function of 2", Sin::argx] -> Sin::argx: Sin called with 2 arguments; 1 argument is expected. >> not a function of 2 Check[Log[x, y], "not a function of 2", Sin::argx] -> Log[y]/Log[x] Log can also be a function of 1. > Finally, how does one tell whether a variable is a function of two > arguments that returns an array? I have already explained the first part of the question. Now, how to tell whether an expresion is an array ? I guess you mean array = matrix. You can check if Transpose works : Check[Transpose@Array[f1, {4, 5}];, "not a matrix"] Check[Transpose@{{x}, {x, y}};, "not a matrix"] Putting those ideas into general programs would require many programming skils but it may be a waste of time. It is not the philosophy of Mathematica to check types carefully, because Mathematica is interpreted and very tolerant with respect to types. A function will accomodate any type of argument, provided what you are doing with it makes sense. If not, you will see a flow of error messages.