Karim BELABAS on Tue, 8 Dec 1998 17:13:25 +0100 (MET) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: bug with complex coefficient polynomials |
[Igor:] > ? factor(x^2-I) > *** segmentation fault: bug in GP (please report). This one was hard to correct... I had introduced two different bugs when trying 1) to improve factornf (use modular gcd), but the input is not always suitable. 2) to avoid the following annoyance: (17:09) gp > factor(x^2+I) %1 = [x^2 + I 1] (17:09) gp > factor(y^2+I) *** polynomial variable must be of higher priority than number field variable in factornf. [Also 3): the internal data was inconsistent but used to work due to a kernel "feature" ] It should work better now (and with t_QUADs also). Karim. P.S: I will try to put together 2.0.13.alpha before the end of the week. *** src/basemath/polarit2.c.orig Fri Nov 13 13:26:00 1998 --- src/basemath/polarit2.c Tue Dec 8 16:59:28 1998 *************** *** 633,642 **** { long t[LT]; /* code pour 0,1,2,3,61,62,63,67,7,81,82,83,86,87,91,93,97 */ long tx = typ(x),lx,i,j,s,pa=BIGINT; ! static long pcx[] = { evaltyp(t_POL)|m_evallg(5), ! evalsigne(1)|evalvarn(0)|m_evallgef(5), ! 0, 0, 0 }; /* x^2 + 1 */ ! GEN p=NULL,pol=NULL,p1,p2; if (is_scalar_t(tx)) { --- 633,639 ---- { long t[LT]; /* code pour 0,1,2,3,61,62,63,67,7,81,82,83,86,87,91,93,97 */ long tx = typ(x),lx,i,j,s,pa=BIGINT; ! GEN pcx=NULL, p=NULL,pol=NULL,p1,p2; if (is_scalar_t(tx)) { *************** *** 644,650 **** x = scalarpol(x,0); } for (i=2; i<LT; i++) t[i]=0; /* t[0..1] unused */ ! lx = lgef(x); pcx[2]=pcx[4]=un; pcx[3]=zero; for (i=2; i<lx; i++) { p1=(GEN)x[i]; --- 641,647 ---- x = scalarpol(x,0); } for (i=2; i<LT; i++) t[i]=0; /* t[0..1] unused */ ! lx = lgef(x); for (i=2; i<lx; i++) { p1=(GEN)x[i]; *************** *** 659,664 **** --- 656,667 ---- assign_or_fail((GEN)p1[1],p); t[3]=1; break; case t_COMPLEX: + if (!pcx) + { + pcx = cgetg(5,t_POL); /* x^2 + 1 */ + pcx[1] = evalsigne(1)|evalvarn(0)|m_evallgef(5), + pcx[2]=pcx[4]=un; pcx[3]=zero; + } for (j=1; j<=2; j++) { p2 = (GEN)p1[j]; *************** *** 869,900 **** case t_PADIC: return factorpadic4(x,p,pa); default: ! av=avma; x = dummycopy(x); lx=lgef(x); v = varn(pol); ! for(i=2; i<lx; i++) ! { ! p1=(GEN)x[i]; ! switch(typ(p1)) ! { ! case t_QUAD: p1++; ! case t_COMPLEX: ! p2 = cgetg(3, t_POLMOD); x[i] = (long) p2; ! p2[1] = (long)pol; ! p2[2] = (long)poldeg1(v, (GEN)p1[1],(GEN)p1[2]); ! } ! } ! tetpil=avma; ! switch(typ2(tx)) ! { ! case t_INT: p1 = polfnf(x,pol); break; ! case t_INTMOD: p1 = factmod9(x,p,pol); break; default: err(impl,"factor of general polynomial"); ! } switch (typ1(tx)) { ! case t_POLMOD: return gerepile(av,tetpil,p1); case t_COMPLEX: p5 = gi; break; case t_QUAD: p5=cgetg(4,t_QUAD); p5[1]=(long)pol; p5[2]=zero; p5[3]=un; default: err(impl,"factor of general polynomial"); } p2=(GEN)p1[1]; --- 872,911 ---- case t_PADIC: return factorpadic4(x,p,pa); default: ! { ! long killv; ! av=avma; x = dummycopy(x); lx=lgef(x); ! pol = dummycopy(pol); ! v = manage_var(4,NULL); ! for(i=2; i<lx; i++) ! { ! p1=(GEN)x[i]; ! switch(typ(p1)) ! { ! case t_QUAD: p1++; ! case t_COMPLEX: ! p2 = cgetg(3, t_POLMOD); x[i] = (long) p2; ! p2[1] = (long)pol; ! p2[2] = (long)poldeg1(v, (GEN)p1[1],(GEN)p1[2]); ! } ! } ! killv = (avma != (long)pol); ! if (killv) setvarn(pol, fetch_var()); ! switch (typ2(tx)) ! { ! case t_INT: p1 = polfnf(x,pol); break; ! case t_INTMOD: p1 = factmod9(x,p,pol); default: err(impl,"factor of general polynomial"); ! } switch (typ1(tx)) { ! case t_POLMOD: ! if (killv) delete_var(); ! return gerepileupto(av,p1); case t_COMPLEX: p5 = gi; break; case t_QUAD: p5=cgetg(4,t_QUAD); p5[1]=(long)pol; p5[2]=zero; p5[3]=un; + break; default: err(impl,"factor of general polynomial"); } p2=(GEN)p1[1]; *************** *** 904,915 **** for(j=2; j<lgef(p3); j++) { p4=(GEN)p3[j]; ! if(typ(p4)==t_POLMOD) p3[j]=lsubst((GEN)p4[2],varn(pol),p5); } } tetpil=avma; y=cgetg(3,t_MAT); y[1]=lcopy(p2);y[2]=lcopy((GEN)p1[2]); return gerepile(av,tetpil,y); } case t_RFRACN: --- 915,928 ---- for(j=2; j<lgef(p3); j++) { p4=(GEN)p3[j]; ! if(typ(p4)==t_POLMOD) p3[j]=lsubst((GEN)p4[2],v,p5); } } + if (killv) delete_var(); tetpil=avma; y=cgetg(3,t_MAT); y[1]=lcopy(p2);y[2]=lcopy((GEN)p1[2]); return gerepile(av,tetpil,y); + } } case t_RFRACN: *************** *** 2253,2259 **** vt=varn(t); v=varn(a); if (vt<v) err(talker,"polynomial variable must be of higher priority than number field variable\nin factornf"); ! u = gdiv(a,modulargcd(a,derivpol(a))); unt = gmodulsg(1,t); u = gmul(unt,u); g=lift(u); k = -2; do --- 2264,2270 ---- vt=varn(t); v=varn(a); if (vt<v) err(talker,"polynomial variable must be of higher priority than number field variable\nin factornf"); ! u = gdiv(a,ggcd(a,derivpol(a))); unt = gmodulsg(1,t); u = gmul(unt,u); g=lift(u); k = -2; do *** src/language/anal.c.orig Wed Dec 2 16:21:54 1998 --- src/language/anal.c Tue Dec 8 14:55:05 1998 *************** *** 1660,1665 **** --- 1660,1666 ---- { case 2: return nvar=0; case 3: return nvar; + case 4: return max_avail; } /* user wants to delete one of his/her/its variables */ -- Karim Belabas email: Karim.Belabas@math.u-psud.fr Dep. de Mathematiques, Bat. 425 Universite Paris-Sud Tel: (00 33) 1 69 15 57 48 F-91405 Orsay (France) Fax: (00 33) 1 69 15 60 19 -- PARI/GP Home Page: http://pari.home.ml.org