Bill Allombert on Wed, 04 May 2022 13:42:10 +0200


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

Re: slow factor


On Wed, May 04, 2022 at 07:20:59PM +0800, Zhao Li wrote:
> We have run it for about an hour but it still does not stop. It seems it got into an infinite loop. 
> 
> We are using the version 2.13.4。 
> The complete script is 
> 
> ==========================
> default(parisize, 1200000000);
> 
> fact(P) =
> {
>  my(x=variable(P),y=variable(Vec(P)));
>  my(d=poldegree(P,y));
>  my(C=content(P),FC=factor(C));
>  for(i=1,oo,
>    my(R=substpol(factor(subst(P/C,ieta,(x+i)^d)),(x+i)^d,ieta));
>    R= matconcat([FC,R]~);
>    my(F=factorback(R)*C);
>    if(pollead(P)*F==pollead(F)*P,
>      return(R)));
> }
> 
> 
> P = -400000*ieta + 3600000*ep*ieta + 4*ep*ieta^2 - 11300000*ep^2*ieta - 20*ep^2*ieta^2 + 15000000*ep^3*ieta + 33*ep^3*ieta^2 - 7200000*ep^4*ieta - 18*ep^4*ieta^2;

OK I found the problem. This is due to variable priority, in my GP
session ep has higher priority than ieta but it is the opposite in your.

My script mistakenly assumed the secondary variable to be always ieta and never ep.

Change the line 
    my(R=substpol(factor(subst(P/C,ieta,(x+i)^d)),(x+i)^d,ieta));
to
    my(R=substpol(factor(subst(P/C,y,(x+i)^d)),(x+i)^d,y));

and it should work.

On the other hand, you can save you some potential confusion by forcing
a variable order when you start gp:
do
ep;ieta;
before using ieta to ensure ep always have higher priority.

Cheers,
Bill.