Karim Belabas on Thu, 14 Nov 2013 18:10:26 +0100


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

Re: factorpadic() for non-squarefree polynomials


* Jeroen Demeyer [2013-11-14 13:30]:
> The documentation for ??factorpadic states that the discriminant of
> the polynomial much have p-adic valuation less than r. While I
> understand where the condition comes from, does that mean that the
> following is undefined behaviour:
> 
> gp> factorpadic(t^2, 3, 5)
> %13 =
> [(1 + O(3^5))*t + O(3^5) 2]
> 
> Indeed, the following example should be equivalent but it's not:
> 
> gp> factorpadic(t^2 + 3^5, 3, 5)
> %14 =
> [(1 + O(3^5))*t^2 + O(3^5)*t + O(3^0) 1]
> 
> In any case, I think this important condition should be added to the
> short help ?factorpadic.

Sorry for the third message in a row. The following patch fixes the 
immediate bug in Z_to_Zp(). Now, we have

(18:02) gp >  factorpadic(t^2 + 3^5, 3, 5)
%1 = 
[(1 + O(3^5))*t^2 + O(3^5)*t + O(3^5) 1]

As to switching from absolute to relative accuracy, it would require further
checks. I'll leave the behaviour as it stands and fix the (unprecise
and misleading) documentation.

Cheers,

    K.B.

diff --git a/src/basemath/polarit1.c b/src/basemath/polarit1.c
index 2b451bf..2c7ac40 100644
--- a/src/basemath/polarit1.c
+++ b/src/basemath/polarit1.c
@@ -178,7 +178,8 @@ Z_to_Zp(GEN x, GEN p, GEN pr, long r)
   if (!sx) return zeropadic_shallow(p,r);
   v = Z_pvalrem(x,p,&x);
   if (v) {
-    r -= v; if (r <= 0) return zeropadic_shallow(p,r);
+    if (r <= v) return zeropadic_shallow(p,r);
+    r -= v;
     pr = powiu(p,r);
   }
   y = cgetg(5,t_PADIC);

--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux1.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux1.fr/  [PARI/GP]
`