Karim Belabas on Thu, 29 Jan 2004 01:17:30 +0100


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

Re: Bug?


* McLaughlin, James [2004-01-29 00:16]:
> I have a simple program which I use to work out the regular continued
> fraction expansion of rational functions (it may not be the most efficient
> but thats something else). Here is a really simple version that reproduces
> the problem I am having:

Not a bug, see below.

> allocatemem(356000000)
> {
> a=1; b=7; d=17;
> f=Pol(a*x^2+b*x+d,x);
> r=Pol((x+1)*(f+1),x);
> s=Pol(x*f,x);
> cf=[];
> while(s,
> c=5; m=0;
> t = r;
> while(c,
> dr = poldegree(t);
> ds = poldegree(s);
> cr = polcoeff(t,dr);
> cs = polcoeff(s,ds);
> e = dr - ds;
> m = Pol(m + (x^e)*cr/cs,x);
> t = Pol(t - s*(x^e)*cr/cs,x);
> c = floor((poldegree(t) +1)/(poldegree(s) +1));
> );
> cf = concat(cf,[m]);
> r = s;
> s = t;
> );
> x=3;
> der=cf;
> print(der);
> print(comp);
> print(eval(cf));
> kill(x);
> }
>  
> It does not seem to matter how big I make the stack with "allocatemem( )", I
> still get an error message:

poldegree(0) is -2147483647  ( conveniently close to -\infty ).  Raising an
object to that power is almost guaranteed to blow up the stack.

I would replace the line

  c = floor((poldegree(t) +1)/(poldegree(s) +1));

by

  if (!t || !(c = floor((poldegree(t) +1)/(poldegree(s) +1))), break);

You get the idea...

Cheers,

    Karim.
-- 
Karim Belabas                     Tel: (+33) (0)1 69 15 57 48
Dep. de Mathematiques, Bat. 425   Fax: (+33) (0)1 69 15 60 19
Universite Paris-Sud              http://www.math.u-psud.fr/~belabas/ 
F-91405 Orsay (France)            http://pari.math.u-bordeaux.fr/  [PARI/GP]