0

This is my first time using GP/Pari and I am having trouble completing this question.

I am asked to print if the return of the function 'wq()' is an integer. Is there a function that can determine if the number passed in is an integer? If not how would I go about checking? I find the syntax somewhat difficult and can't find much information online about it.

I have included what I have so far, any help is appreciated.

wq(x) =
{
    [(x-1)! + 1]/x
}

test(r,s) =
{
    for (i=r, s, if(isinteger(wq(i)), print("integer"), print("not interger")));
}
  • A very related question was asked a couple of days earlier: [How to check if a number is an integer in Pari/GP?](http://stackoverflow.com/questions/36783151/) – Jeppe Stig Nielsen Apr 28 '16 at 21:45

2 Answers2

0

If I understand correctly you want to check if (x-1)! + 1 is a multiple of x. You can do that with the modulo operation:

test(r,s) =
{
    for (i=r, s, if(Mod((i - 1)! + 1, i) == 0, 
         print("integer"), 
         print("not integer")));
}
  • Thanks for your help! I am wondering how I would be able to do this using my wq() function I have defined. Part of the problem I'm trying to complete is also learning to use and call user defined functions. I tried calling the wq() within the mod but keep getting an error. – Michael Arciola Apr 25 '16 at 13:28
0

You can use:

wq(x) =
{
    ((x-1)! + 1)/x
}

test(r,s) =
{
    for (i=r, s, print(if(type(wq(i))=="t_INT", "integer", "not integer")))
}

I changed [] into () since [] gives a row vector (type t_VEC) which is not useful here.

Here is another way to write it:

wq(x) =
{
    Mod((x-1)! + 1, x)
}

test(r,s) =
{
    for (i=r, s, wq(i) && print1("not "); print("integer"))
}

The function print1 prints and "stays" on the same line. The 'and' operator && "short-circuits". The semicolon ; binds several expressions into one "sequence".

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