0

I'm trying to write an if statement like this

 if(denominator([(i-1)! + 1] / i)-1,print(hi),print(ho))

i can be any integer, for example 10. When I set i to 10 it gives this error:

? [(x-1)! + 1] / x
  ***   this should be an integer: [(x-1)!+1]/x
                                    ^-----------

I really only need to check if [(x-1)! + 1] / x is an integer or not. The denominator thing is what I came up with, I also tried Mod but couldn't get that working either.

matthias_h
  • 11,356
  • 9
  • 22
  • 40

3 Answers3

3

It seems that you are confused with the names x and i. Please, see that expression below works properly:

i = 10;
print([(i-1)! + 1] / i);
gp > [362881/10]
Piotr Semenov
  • 1,761
  • 16
  • 24
0

I'm not sure what the error was but I ended up using a floor function for determining if it was an integer or not.

0

You could use:

print(if(((i-1)! + 1) % i, "hi", "ho"))

If i (in your question x) is not an integer, you get an error from the ! (factorial) operator (but see gamma as well).

Do not use [] here, it creates a vector.

The opreator % which I used, gives the remainder. For example 11 % 4 gives the integer 3. In comparison Mod(11, 4) is not an ordinary integer, it is a member of the ring Z/4Z (integers modulo 4). That is very useful in many cases.

I supposed you wanted to write out strings, so I used quotes ". If hi and ho are variables, omit the quotes of course.

Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181