1

I am creating a program in GP/Pari

foo()=
{
    coefficient = vector(2);
    coefficient[1] = 1;
    coefficient[2] = 2;

    UserNum = Vector(2);
    UserNum[1] = 1;
    UserNum[2] = 2;

    n=2;

    for( r=1,n,
    sum = coefficient[r]* UserNum[r]^r );



}

Why do i get a compilation error :

variable name not expected

It appears the error lies in the FOR LOOP but I cant tell whats wrong with my FOR LOOP , can someone help me thanks !!!

Piotr Semenov
  • 1,761
  • 16
  • 24
Computernerd
  • 7,378
  • 18
  • 66
  • 95

1 Answers1

2

The name sum is reserved for PARI/GP's built-in function. Just use another name. Your code can be improved as follows.

foo() = {
    coefficient = [1, 2];
    UserNum = [1, 2];

    for(r = 1, 2, var = coefficient[r] * UserNum[r]^r);
}
Piotr Semenov
  • 1,761
  • 16
  • 24