Bill Allombert on Sun, 05 Jul 2009 22:54:08 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Re: Some bugs?


On Sun, Jul 05, 2009 at 03:48:15PM +0100, Jason Moxham wrote:
>>>> [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>>>  ***   at top-level: ...Mod(1,10007)*(x^30+9557*x^29+7812*x^28+7090*x
>>>>  ***                                             ^--------------------
>>>>  *** _^s: degree overflow in pow_monome.
>>>
>>> This is very wrong: x^29 is absolutly safe. There are some corruption
>>> going on.
>
> I've put some printing in the code to try to see what is happening see  
> out.txt
>
>
> /* assume x != 0 */
> static GEN
> pow_monome(GEN x, long n)
> {
>  long i, d, dx = degpol(x);
>  GEN A, b, y;
>
>  printf("here %d %d %d %d\n",__LINE__,n,d,dx);

this should be %ld:
printf("here %d %ld %ld %ld\n",__LINE__,n,d,dx);
(also d is not yet initialised at this stage).

>
>  if (n < 0) { n = -n; y = cgetg(3, t_RFRAC); } else y = NULL;
>  printf("here %d %d %d %d\n",__LINE__,n,d,dx);
>  if (HIGHWORD(dx) || HIGHWORD(n))
>  {
>    LOCAL_HIREMAINDER;
>      printf("here %d %d %d %d\n",__LINE__,n,d,dx);
>    d = (long)mulll((ulong)dx, (ulong)n);
>      printf("here %d %d %d %d\n",__LINE__,n,d,dx);
>    if (hiremainder || (d &~ LGBITS)) d = LGBITS; /* overflow */
>      printf("here %d %d %d %d\n",__LINE__,n,d,dx);
>    d += 2;  printf("here %d %d %d %d\n",__LINE__,n,d,dx);
>  }
>  else
>    {d = dx*n + 2;  printf("here %d %d %d %d\n",__LINE__,n,d,dx);}
>
>      printf("here %d %d %d %d\n",__LINE__,n,d,dx);
>  if ((d + 1) & ~LGBITS) pari_err(talker,"degree overflow in pow_monome");
>    printf("here %d %d %d %d\n",__LINE__,n,d,dx);
>  A = cgetg(d+1, t_POL); A[1] = x[1];
>  for (i=2; i < d; i++) gel(A,i) = gen_0;
>  b = gpowgs(gel(x,dx+2), n); /* not memory clean if (n < 0) */
>  if (!y) y = A;
>  else {
>    GEN c = denom(b);
>    gel(y,1) = c; if (c != gen_1) b = gmul(b,c);
>    gel(y,2) = A;
>  }
>  gel(A,d) = b; return y;
> }
>
> [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
> here 537 30 14841240 1
> here 540 30 14841240 1
> here 552 30 32 1
> here 554 30 32 1
> here 556 30 32 1
> here 537 100925962 14841240 1
> here 540 100925962 14841240 1
> here 544 100925962 14841240 1
> here 546 100925962 100925962 1
> here 548 100925962 16777215 1
> here 549 100925962 16777217 1
> here 554 100925962 16777217 1
>  ***   at top-level: ...Mod(1,10007)*(x^30+9557*x^29+7812*x^28+7090*x
>  ***                                             ^--------------------
>  *** _^s: degree overflow in pow_monome.

pow_monome is called with n=100925962 instead of n=29. This confirms there
is some corruption going on.

Maybe you could extract a smaller test-case from the file 
src/test/in/ffisom ?

Cheers,
Bill.