Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build and tests with pari 2.17 #38749

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
19 changes: 13 additions & 6 deletions src/sage/arith/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2691,9 +2691,14 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds):

Any object which has a factor method can be factored like this::

sage: K.<i> = QuadraticField(-1) # needs sage.rings.number_field
sage: factor(122 - 454*i) # needs sage.rings.number_field
(-i) * (-i - 2)^3 * (i + 1)^3 * (-2*i + 3) * (i + 4)
sage: # needs sage.rings.number_field
sage: K.<i> = QuadraticField(-1)
sage: f = factor(122 - 454*i); f # random
(i) * (i - 1)^3 * (i + 2)^3 * (3*i + 2) * (i + 4)
sage: len(f)
4
sage: product(p[0]^p[1] for p in f) * f.unit()
-454*i + 122

To access the data in a factorization::

Expand Down Expand Up @@ -2775,8 +2780,10 @@ def radical(n, *args, **kwds):
...
ArithmeticError: radical of 0 is not defined
sage: K.<i> = QuadraticField(-1) # needs sage.rings.number_field
sage: radical(K(2)) # needs sage.rings.number_field
i + 1
sage: r = radical(K(2)); r # random, needs sage.rings.number_field
i - 1
sage: r.norm() # needs sage.rings.number_field
2

Tests with numpy and gmpy2 numbers::

Expand Down Expand Up @@ -3031,7 +3038,7 @@ def is_squarefree(n):
sage: is_squarefree(O(2))
False
sage: O(2).factor()
(-I) * (I + 1)^2
(...) * (...)^2

This method fails on domains which are not Unique Factorization Domains::

Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/quotient_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def gcd(self, other):
sage: R = ZZ.extension(x^2 + 1, names='i')
sage: i = R.1
sage: gcd(5, 3 + 4*i)
-i - 2
2*i - 1
sage: P.<t> = R[]
sage: gcd(t, i)
Traceback (most recent call last):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/dynamics/arithmetic_dynamics/berkovich_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,10 @@ def conjugate(self, M, adjugate=False, new_ideal=None):

sage: # needs sage.rings.number_field
sage: ideal = A.ideal(5).factor()[1][0]; ideal
Fractional ideal (2*a + 1)
Fractional ideal (-a + 2)
sage: g = f.conjugate(conj, new_ideal=ideal)
sage: g.domain().ideal()
Fractional ideal (2*a + 1)
Fractional ideal (-a + 2)
"""
if self.domain().is_padic_base():
return DynamicalSystem_Berkovich(self._system.conjugate(M, adjugate=adjugate))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ def primes_of_bad_reduction(self, check=True):
sage: P.<x,y> = ProjectiveSpace(K,1)
sage: f = DynamicalSystem_projective([1/3*x^2+1/a*y^2, y^2])
sage: f.primes_of_bad_reduction() # needs sage.rings.function_field
[Fractional ideal (a), Fractional ideal (3)]
[Fractional ideal (-a), Fractional ideal (3)]

This is an example where ``check=False`` returns extra primes::

Expand Down
15 changes: 7 additions & 8 deletions src/sage/libs/pari/convert_sage.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -573,17 +573,16 @@ cpdef list pari_prime_range(long c_start, long c_stop, bint py_ints=False):
sage: pari_prime_range(2, 19)
[2, 3, 5, 7, 11, 13, 17]
"""
cdef long p = 0
cdef byteptr pari_prime_ptr = diffptr
cdef ulong i = 1
res = []
while p < c_start:
NEXT_PRIME_VIADIFF(p, pari_prime_ptr)
while p < c_stop:
while pari_PRIMES[i] < c_start:
i+=1
while pari_PRIMES[i] < c_stop:
if py_ints:
res.append(p)
res.append(pari_PRIMES[i])
else:
z = <Integer>PY_NEW(Integer)
mpz_set_ui(z.value, p)
mpz_set_ui(z.value, pari_PRIMES[i])
res.append(z)
NEXT_PRIME_VIADIFF(p, pari_prime_ptr)
i+=1
return res
4 changes: 2 additions & 2 deletions src/sage/libs/pari/convert_sage_real_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cpdef Gen new_gen_from_real_mpfr_element(RealNumber self):

# We round up the precision to the nearest multiple of wordsize.
cdef int rounded_prec
rounded_prec = (self.prec() + wordsize - 1) & ~(wordsize - 1)
rounded_prec = nbits2prec(self.prec())

# Yes, assigning to self works fine, even in Cython.
if rounded_prec > prec:
Expand All @@ -48,7 +48,7 @@ cpdef Gen new_gen_from_real_mpfr_element(RealNumber self):
exponent = mpfr_get_z_exp(mantissa, self.value)

# Create a PARI REAL
pari_float = cgetr(2 + rounded_prec / wordsize)
pari_float = cgetr(rounded_prec)
pari_float[1] = evalexpo(exponent + rounded_prec - 1) + evalsigne(mpfr_sgn(self.value))
mpz_export(&pari_float[2], NULL, 1, wordsize // 8, 0, 0, mantissa)
mpz_clear(mantissa)
Expand Down
8 changes: 4 additions & 4 deletions src/sage/libs/pari/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@
sage: pari(-104).quadclassunit()
[6, [6], [Qfb(5, -4, 6)], 1]
sage: pari(109).quadclassunit()
[1, [], [], 5.56453508676047]
[1, [], [], 5.56453508676047, -1]
sage: pari(10001).quadclassunit() # random generators
[16, [16], [Qfb(10, 99, -5, 0.E-38)], 5.29834236561059]
sage: pari(10001).quadclassunit()[0]
Expand Down Expand Up @@ -1749,13 +1749,13 @@
sage: y = QQ['yy'].0; _ = pari(y) # pari has variable ordering rules
sage: x = QQ['zz'].0; nf = pari(x^2 + 2).nfinit()
sage: nf.nfroots(y^2 + 2)
[Mod(-zz, zz^2 + 2), Mod(zz, zz^2 + 2)]
[Mod(-zz, zz^2 + 2), Mod(zz, zz^2 + 2)]~
sage: nf = pari(x^3 + 2).nfinit()
sage: nf.nfroots(y^3 + 2)
[Mod(zz, zz^3 + 2)]
[Mod(zz, zz^3 + 2)]~
sage: nf = pari(x^4 + 2).nfinit()
sage: nf.nfroots(y^4 + 2)
[Mod(-zz, zz^4 + 2), Mod(zz, zz^4 + 2)]
[Mod(-zz, zz^4 + 2), Mod(zz, zz^4 + 2)]~
sage: nf = pari('x^2 + 1').nfinit()
sage: nf.nfrootsof1()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16584,7 +16584,7 @@ cdef class Matrix(Matrix1):
....: -2*a^2 + 4*a - 2, -2*a^2 + 1, 2*a, a^2 - 6, 3*a^2 - a ])
sage: r,s,p = m._echelon_form_PID()
sage: s[2]
(0, 0, -3*a^2 - 18*a + 34, -68*a^2 + 134*a - 53, -111*a^2 + 275*a - 90)
(0, 0, 3*a^2 + 18*a - 34, 68*a^2 - 134*a + 53, 111*a^2 - 275*a + 90)
sage: r * m == s and r.det() == 1
True

Expand Down
8 changes: 4 additions & 4 deletions src/sage/modular/cusps_nf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,9 @@ def NFCusps_ideal_reps_for_levelN(N, nlists=1):
sage: from sage.modular.cusps_nf import NFCusps_ideal_reps_for_levelN
sage: NFCusps_ideal_reps_for_levelN(N)
[(Fractional ideal (1),
Fractional ideal (67, a + 17),
Fractional ideal (127, a + 48),
Fractional ideal (157, a - 19))]
Fractional ideal (67, -4/7*a^3 + 13/7*a^2 + 39/7*a - 43),
Fractional ideal (127, -4/7*a^3 + 13/7*a^2 + 39/7*a - 42),
Fractional ideal (157, -4/7*a^3 + 13/7*a^2 + 39/7*a + 48))]
sage: L = NFCusps_ideal_reps_for_levelN(N, 5)
sage: all(len(L[i]) == k.class_number() for i in range(len(L)))
True
Expand Down Expand Up @@ -1244,7 +1244,7 @@ def units_mod_ideal(I):
sage: I = k.ideal(5, a + 1)
sage: units_mod_ideal(I)
[1,
-2*a^2 - 4*a + 1,
2*a^2 + 4*a - 1,
...]
::
Expand Down
8 changes: 4 additions & 4 deletions src/sage/modular/dirichlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2398,13 +2398,13 @@ class DirichletGroupFactory(UniqueFactory):
sage: parent(val)
Gaussian Integers generated by zeta4 in Cyclotomic Field of order 4 and degree 2
sage: r4_29_0 = r4.residue_field(K(29).factor()[0][0]); r4_29_0(val)
17
12
sage: r4_29_0(val) * GF(29)(3)
22
7
sage: r4_29_0(G.gens()[2].values_on_gens()[2]) * 3
22
7
sage: parent(r4_29_0(G.gens()[2].values_on_gens()[2]) * 3)
Residue field of Fractional ideal (-2*zeta4 + 5)
Residue field of Fractional ideal (-2*zeta4 - 5)

::

Expand Down
8 changes: 4 additions & 4 deletions src/sage/modular/modsym/p1list_nf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
sage: alpha = MSymbol(N, a + 2, 3*a^2)
sage: alpha.lift_to_sl2_Ok()
[-1, 4*a^2 - 13*a + 23, a + 2, 5*a^2 + 3*a - 3]
[-a - 1, 15*a^2 - 38*a + 86, a + 2, -a^2 + 9*a - 19]
sage: Ok = k.ring_of_integers()
sage: M = Matrix(Ok, 2, alpha.lift_to_sl2_Ok())
sage: det(M)
Expand Down Expand Up @@ -977,11 +977,11 @@ def apply_J_epsilon(self, i, e1, e2=1):
sage: N = k.ideal(5, a + 1)
sage: P = P1NFList(N)
sage: u = k.unit_group().gens_values(); u
[-1, -2*a^2 - 4*a + 1]
[-1, 2*a^2 + 4*a - 1]
sage: P.apply_J_epsilon(4, -1)
2
sage: P.apply_J_epsilon(4, u[0], u[1])
5
1
::
Expand Down Expand Up @@ -1122,7 +1122,7 @@ def lift_to_sl2_Ok(N, c, d):
sage: M = Matrix(Ok, 2, lift_to_sl2_Ok(N, 0, 7))
Traceback (most recent call last):
...
ValueError: <0> + <7> and the Fractional ideal (7, a) are not coprime.
ValueError: <0> + <7> and the Fractional ideal (7, -4/7*a^3 + 13/7*a^2 + 39/7*a - 19) are not coprime.
"""
k = N.number_field()
# check the input
Expand Down
8 changes: 4 additions & 4 deletions src/sage/quadratic_forms/binary_qf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ def solve_integer(self, n, *, algorithm='general', _flag=2):
sage: Q = BinaryQF([1, 0, 12345])
sage: n = 2^99 + 5273
sage: Q.solve_integer(n) # needs sage.libs.pari
(-67446480057659, 7139620553488)
(67446480057659, 7139620553488)
sage: Q.solve_integer(n, algorithm='cornacchia') # needs sage.libs.pari
(67446480057659, 7139620553488)
sage: timeit('Q.solve_integer(n)') # not tested
Expand All @@ -1661,7 +1661,7 @@ def solve_integer(self, n, *, algorithm='general', _flag=2):
sage: Qs
[x^2 + x*y + 6*y^2, 2*x^2 - x*y + 3*y^2, 2*x^2 + x*y + 3*y^2]
sage: [Q.solve_integer(3) for Q in Qs]
[None, (0, -1), (0, -1)]
[None, (0, 1), (0, 1)]
sage: [Q.solve_integer(5) for Q in Qs]
[None, None, None]
sage: [Q.solve_integer(6) for Q in Qs]
Expand Down Expand Up @@ -1741,11 +1741,11 @@ def solve_integer(self, n, *, algorithm='general', _flag=2):
sage: # needs sage.libs.pari
sage: Q = BinaryQF([1, 0, 5])
sage: Q.solve_integer(126, _flag=1)
[(11, -1), (-1, -5), (-1, 5), (-11, -1)]
[(-11, -1), (-1, -5), (-1, 5), (11, -1)]
sage: Q.solve_integer(126, _flag=2)
(11, -1)
sage: Q.solve_integer(126, _flag=3)
[(11, -1), (-1, -5), (-1, 5), (-11, -1), (-9, -3), (9, -3)]
[(-11, -1), (-9, -3), (-1, -5), (-1, 5), (9, -3), (11, -1)]
"""
if self.is_negative_definite(): # not supported by PARI
return (-self).solve_integer(-n)
Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/finite_rings/finite_field_prime_modn.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def _coerce_map_from_(self, S):
sage: RF13 = K.residue_field(pp)
sage: RF13.hom([GF(13)(1)])
Ring morphism:
From: Residue field of Fractional ideal (-w - 18)
To: Finite Field of size 13
Defn: 1 |--> 1
From: Residue field of Fractional ideal (w + 18)
To: Finite Field of size 13
Defn: 1 |--> 1
Check that :issue:`19573` is resolved::
Expand Down
41 changes: 19 additions & 22 deletions src/sage/rings/finite_rings/residue_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ monogenic (i.e., 2 is an essential discriminant divisor)::
sage: # needs sage.rings.number_field
sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8)
sage: F = K.factor(2); F
(Fractional ideal (-1/2*a^2 + 1/2*a - 1)) * (Fractional ideal (-a^2 + 2*a - 3))
* (Fractional ideal (3/2*a^2 - 5/2*a + 4))
(Fractional ideal (-1/2*a^2 + 1/2*a - 1)) * (Fractional ideal (a^2 - 2*a + 3)) * (Fractional ideal (-3/2*a^2 + 5/2*a - 4))
sage: F[0][0].residue_field()
Residue field of Fractional ideal (-1/2*a^2 + 1/2*a - 1)
sage: F[1][0].residue_field()
Residue field of Fractional ideal (-a^2 + 2*a - 3)
Residue field of Fractional ideal (a^2 - 2*a + 3)
sage: F[2][0].residue_field()
Residue field of Fractional ideal (3/2*a^2 - 5/2*a + 4)
Residue field of Fractional ideal (-3/2*a^2 + 5/2*a - 4)

We can also form residue fields from `\ZZ`::

Expand Down Expand Up @@ -126,10 +125,10 @@ First over a small non-prime field::
sage: I = ideal([ubar*X + Y]); I
Ideal (ubar*X + Y) of Multivariate Polynomial Ring in X, Y over
Residue field in ubar of Fractional ideal
(47, 517/55860*u^5 + 235/3724*u^4 + 9829/13965*u^3
+ 54106/13965*u^2 + 64517/27930*u + 755696/13965)
(47, 4841/93100*u^5 + 34451/139650*u^4 + 303697/69825*u^3
+ 297893/27930*u^2 + 1649764/23275*u + 2633506/69825)
sage: I.groebner_basis() # needs sage.libs.singular
[X + (-19*ubar^2 - 5*ubar - 17)*Y]
[X + (-15*ubar^2 + 3*ubar - 2)*Y]

And now over a large prime field::

Expand Down Expand Up @@ -496,9 +495,9 @@ class ResidueField_generic(Field):

sage: # needs sage.rings.number_field
sage: I = QQ[i].factor(2)[0][0]; I
Fractional ideal (I + 1)
Fractional ideal (-I - 1)
sage: k = I.residue_field(); k
Residue field of Fractional ideal (I + 1)
Residue field of Fractional ideal (-I - 1)
sage: type(k)
<class 'sage.rings.finite_rings.residue_field.ResidueFiniteField_prime_modn_with_category'>

Expand Down Expand Up @@ -1008,7 +1007,7 @@ cdef class ReductionMap(Map):
sage: cr
Partially defined reduction map:
From: Number Field in a with defining polynomial x^2 + 1
To: Residue field of Fractional ideal (a + 1)
To: Residue field of Fractional ideal (-a + 1)
sage: cr == r # not implemented
True
sage: r(2 + a) == cr(2 + a)
Expand Down Expand Up @@ -1039,7 +1038,7 @@ cdef class ReductionMap(Map):
sage: cr
Partially defined reduction map:
From: Number Field in a with defining polynomial x^2 + 1
To: Residue field of Fractional ideal (a + 1)
To: Residue field of Fractional ideal (-a + 1)
sage: cr == r # not implemented
True
sage: r(2 + a) == cr(2 + a)
Expand Down Expand Up @@ -1071,7 +1070,7 @@ cdef class ReductionMap(Map):
sage: r = F.reduction_map(); r
Partially defined reduction map:
From: Number Field in a with defining polynomial x^2 + 1
To: Residue field of Fractional ideal (a + 1)
To: Residue field of Fractional ideal (-a + 1)

We test that calling the function also works after copying::

Expand All @@ -1083,7 +1082,7 @@ cdef class ReductionMap(Map):
Traceback (most recent call last):
...
ZeroDivisionError: Cannot reduce field element 1/2*a
modulo Fractional ideal (a + 1): it has negative valuation
modulo Fractional ideal (-a + 1): it has negative valuation

sage: # needs sage.rings.finite_rings
sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
Expand All @@ -1105,11 +1104,11 @@ cdef class ReductionMap(Map):
sage: # needs sage.rings.number_field
sage: K.<i> = NumberField(x^2 + 1)
sage: P1, P2 = [g[0] for g in K.factor(5)]; P1, P2
(Fractional ideal (-i - 2), Fractional ideal (2*i + 1))
(Fractional ideal (2*i - 1), Fractional ideal (-2*i - 1))
sage: a = 1/(1+2*i)
sage: F1, F2 = [g.residue_field() for g in [P1,P2]]; F1, F2
(Residue field of Fractional ideal (-i - 2),
Residue field of Fractional ideal (2*i + 1))
(Residue field of Fractional ideal (2*i - 1),
Residue field of Fractional ideal (-2*i - 1))
sage: a.valuation(P1)
0
sage: F1(i/7)
Expand All @@ -1122,7 +1121,7 @@ cdef class ReductionMap(Map):
Traceback (most recent call last):
...
ZeroDivisionError: Cannot reduce field element -2/5*i + 1/5
modulo Fractional ideal (2*i + 1): it has negative valuation
modulo Fractional ideal (-2*i - 1): it has negative valuation
"""
# The reduction map is just x |--> F(to_vs(x) * (PB**(-1))) if
# either x is integral or the denominator of x is coprime to
Expand Down Expand Up @@ -1188,8 +1187,7 @@ cdef class ReductionMap(Map):
sage: f = k.convert_map_from(K)
sage: s = f.section(); s
Lifting map:
From: Residue field in abar of
Fractional ideal (-14*a^4 + 24*a^3 + 26*a^2 - 58*a + 15)
From: Residue field in abar of Fractional ideal (14*a^4 - 24*a^3 - 26*a^2 + 58*a - 15)
To: Number Field in a with defining polynomial x^5 - 5*x + 2
sage: s(k.gen())
a
Expand Down Expand Up @@ -1424,8 +1422,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism):
sage: f = k.coerce_map_from(K.ring_of_integers())
sage: s = f.section(); s
Lifting map:
From: Residue field in abar of
Fractional ideal (-14*a^4 + 24*a^3 + 26*a^2 - 58*a + 15)
From: Residue field in abar of Fractional ideal (14*a^4 - 24*a^3 - 26*a^2 + 58*a - 15)
To: Maximal Order generated by a in Number Field in a with defining polynomial x^5 - 5*x + 2
sage: s(k.gen())
a
Expand Down Expand Up @@ -1678,7 +1675,7 @@ cdef class LiftingMap(Section):
sage: F.<tmod> = K.factor(7)[0][0].residue_field()
sage: F.lift_map() #indirect doctest
Lifting map:
From: Residue field in tmod of Fractional ideal (theta_12^2 + 2)
From: Residue field in tmod of Fractional ideal (2*theta_12^3 + theta_12)
To: Maximal Order generated by theta_12 in Cyclotomic Field of order 12 and degree 4
"""
return "Lifting"
Expand Down
Loading
Loading