# Determining whether or not an expression is an integer

I'd like to define a function that controls if a certain number is an integer, rational, algebraic and so far. First, I tried generating a list of those numbers:

ZL = {1, 3, Pi, E, Sqrt, Zeta}


I then created my functions like so:

TestI[x_] := If[x ∈ Integers, x "is Integer", x "is no Integer"]


It works so far.

I now tried to define a For-function like this:

For[i = 1, i <= Length[ZL], i++, Print[TestZ[Part[ZL, i]]]]


However, when I evaluate the above expression, the output is like

is integer
3 is integer
...
is no integer E


How can I achieve an output that says:

1 is Integer
3 is Integer
...
\e is no Integer


and so on?

• TestI[x_] := If[x \[Element] Integers, ToString[x] <> " is Integer", ToString[x] <> " is no Integer"] Also, BAD idea to use uppercase for your symbol initials - might clash with built-in symbols. – ciao Apr 10 '14 at 9:40
• zl = {1, 3, Pi, E, Sqrt, Zeta}; testi[x_] := If[IntegerQ[x], x "is Integer", x "is not Integer"]; For[i = 1, i <= Length[zl], i++, Print[testi[Part[zl, i]]]] – martin Apr 10 '14 at 9:40
• or If[Element[x , Integers] – martin Apr 10 '14 at 9:49
• @martin Your hint wont work. I get the same results. – K. L. Apr 10 '14 at 10:18
• @K.L. If you copy & paste entire first comment what do you get? – martin Apr 10 '14 at 10:20

You could achieve without If, e.g.:

f[x_Integer] := StringForm[" is an integer", x];
f[x_] := StringForm[" is not an integer", x];


Test:

test = {1, 3, Pi, E, Sqrt, Zeta, Zeta[-2]}


Mapping:

Column[f /@ test]


yields: Please note IntegerQ is True, however IntegerQ[3.] is False

• Please consider Listable too :) – Kuba Apr 10 '14 at 9:53