@@ -299,6 +299,12 @@ def create_key_and_extra_args_for_number_field_from_ideal(self, R, I, prime):
299299 sage: K.valuation(I)
300300 [ 2-adic valuation, v(x + 1) = 1/2 ]-adic valuation
301301
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+
302308 """
303309 K , L , G = self ._normalize_number_field_data (R )
304310
@@ -315,16 +321,29 @@ def create_key_and_extra_args_for_number_field_from_ideal(self, R, I, prime):
315321
316322 candidates = approximants [:]
317323
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+
318332 # Refine candidates until we can detect which valuation corresponds to the ideal I
319333 while True :
320- match = [i for (i , v ) in enumerate (candidates ) if all (v (g .polynomial ()) > 0 for g in I .gens ())]
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 )]
321337
322338 if len (match ) > 1 :
323339 raise ValueError ("%s does not single out a unique extension of %s to %s" % (prime , vK , L ))
324340 if len (match ) == 1 :
325341 return (R , approximants [match [0 ]]), {'approximants' : approximants }
326342
327- candidates = [v .mac_lane_step (G )[0 ] for v in candidates ]
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 ]
328347
329348 def _normalize_number_field_data (self , R ):
330349 r"""
0 commit comments