Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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[2], Zeta[3]} 

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?

share|improve this question
    
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. –  rasher Apr 10 at 9:40
    
zl = {1, 3, Pi, E, Sqrt[2], Zeta[3]}; 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 at 9:40
    
or If[Element[x , Integers] –  martin Apr 10 at 9:49
    
@martin Your hint wont work. I get the same results. –  K. L. Apr 10 at 10:18
    
@K.L. If you copy & paste entire first comment what do you get? –  martin Apr 10 at 10:20

1 Answer 1

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[2], Zeta[3], Zeta[-2]}

Mapping:

Column[f /@ test]

yields:

enter image description here

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

share|improve this answer
1  
Please consider Listable too :) –  Kuba Apr 10 at 9:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.