3535
3636"""
3737#*****************************************************************************
38- # Copyright (C) 2013-2018 Julian Rüth <[email protected] > 38+ # Copyright (C) 2013-2020 Julian Rüth <[email protected] > 3939#
4040# Distributed under the terms of the GNU General Public License (GPL)
4141# as published by the Free Software Foundation; either version 2 of
@@ -285,6 +285,26 @@ def create_key_and_extra_args_for_number_field_from_ideal(self, R, I, prime):
285285 sage: GaussianIntegers().valuation(GaussianIntegers().ideal(2)) # indirect doctest
286286 2-adic valuation
287287
288+ TESTS:
289+
290+ Verify that :trac:`28976` has been resolved::
291+
292+ sage: R.<x> = QQ[]
293+ sage: K.<a> = NumberField(x^6 - 18*x^4 - 24*x^3 + 27*x^2 + 36*x - 6)
294+ sage: I = K.fractional_ideal((2, -7/44*a^5 + 19/44*a^4 + 87/44*a^3 - 87/44*a^2 - 5/2*a + 39/22))
295+ sage: I.norm()
296+ 2
297+ sage: I in K.primes_above(2)
298+ True
299+ sage: K.valuation(I)
300+ [ 2-adic valuation, v(x + 1) = 1/2 ]-adic valuation
301+
302+ ::
303+
304+ sage: K.<a, b> = NumberField([x^2 - 2, x^2 + x + 1])
305+ sage: K.valuation(2)
306+ 2-adic valuation
307+
288308 """
289309 K , L , G = self ._normalize_number_field_data (R )
290310
@@ -297,14 +317,33 @@ def create_key_and_extra_args_for_number_field_from_ideal(self, R, I, prime):
297317 if len (F ) != 1 :
298318 raise ValueError ("%r does not lie over a single prime of %r" % (I , K ))
299319 vK = K .valuation (F [0 ][0 ])
300- candidates = vK .mac_lane_approximants (G , require_incomparability = True )
320+ approximants = vK .mac_lane_approximants (G , require_incomparability = True )
301321
302- candidates_for_I = [c for c in candidates if all (c (g .polynomial ()) > 0 for g in I .gens ())]
303- assert (len (candidates_for_I ) > 0 ) # This should not be possible, unless I contains a unit
304- if len (candidates_for_I ) > 1 :
305- raise ValueError ("%s does not single out a unique extension of %s to %s" % (prime , vK , L ))
306- else :
307- return (R , candidates_for_I [0 ]), {'approximants' : candidates }
322+ candidates = approximants [:]
323+
324+ # The correct approximant has v(g) > 0 for all g in the ideal.
325+ # Unfortunately, the generators of I, even though defined over K have
326+ # their polynomial() defined over the rationals so we need to turn them
327+ # into polynomials over K[x] explicitly.
328+ from sage .rings .all import PolynomialRing
329+ gens = I .gens ()
330+ gens = [PolynomialRing (K , 'x' )(list (g .vector ())) for g in gens ]
331+
332+ # Refine candidates until we can detect which valuation corresponds to the ideal I
333+ while True :
334+ assert any (candidates ), "the defining polynomial of the extension factored but we still could not figure out which valuation corresponds to the given ideal"
335+
336+ match = [i for (i , v ) in enumerate (candidates ) if v and all (v (g ) > 0 for g in gens )]
337+
338+ if len (match ) > 1 :
339+ raise ValueError ("%s does not single out a unique extension of %s to %s" % (prime , vK , L ))
340+ if len (match ) == 1 :
341+ return (R , approximants [match [0 ]]), {'approximants' : approximants }
342+
343+ # We refine candidates which increases v(g) for all g in I;
344+ # however, we cannot augment the valuations which are already at
345+ # v(G) = +∞ which we ignore by setting them to None.
346+ candidates = [v .mac_lane_step (G )[0 ] if v and v .is_discrete_valuation () else None for v in candidates ]
308347
309348 def _normalize_number_field_data (self , R ):
310349 r"""
0 commit comments