# What is a good way to check what kind of a function a function is?

i want a module or function or switch or If (whatever works), what asks if a function is an e function or a polynomial(a hole number one or fractorial), a exponential function, a logarithm function and so on. How can i do this? And where can i find all the build-in-questions for this? I only found PolynomialQ so far. But i am not able to put it in a Switch. Maybe It's better with If? Thanks. The Iam Switch is just here to look good. I wanted to create functionQ like this. The Iam Switch is from the book "Programming with Mathematica" by Paul Wellin.

fuu[x_] := 2 x - 5 x^3
PolynomialQ[fuu[x], x]
True

Iam[expr_] := Switch[expr,
_Integer, "I am an integer",
_Rational, "I am rational",
_Real, "I am real",
_Complex, "I am complex",
_, "I am not a number"]

functionQ[f_] := Switch[f,
_PolynomialQ[f, x], "I am polynomial",
_, "mystical"]
Plus

Iam[fuu[x]]
I am not a number

functionQ[fuu[x]]
mystical

• What would a function like Sqrt[x] be? If x is 2 then Sqrt[x] is an irrational number, if x is 4 then Sqrt[x] is an integer. – Ymareth Jun 2 '15 at 9:06
• And what is the reason for wanting this check? – Ymareth Jun 2 '15 at 9:07
• i am working on an module which shall perfom a curve sketching with an arbitrary function. I want to check first what kind of function i have. I don't know if i will need it. But it would be nice to at least give a message that states what kind of function i have, if it is a special function. - sorry for the factorial english :D – baloo Jun 2 '15 at 9:11
• maybe it is useless.. – baloo Jun 2 '15 at 9:17
• I think you may find this question relevant to your problem. – m_goldberg Jun 2 '15 at 11:56

PolynomialQ isn't the head of your function, so your pattern won't match it in your switch statement. Instead, you can can use a conditional pattern with the /; operator like so:

functionQ[f_] := Switch[f,
_/;PolynomialQ[f, x], "I am polynomial",
_, "mystical"
]

functionQ[fuu[x]]

(* "I am polynomial" *)


You can use this operator in the form pattern/;condition, which only attempts to match pattern if condition evaluates to True.