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

```* 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:
>
> %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

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

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)
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);
}