Path: blob/master/sage/rings/function_field/function_field_ideal.py
4038 views
r"""1Ideals in Function Fields23AUTHORS:45- William Stein (2010): initial version67- Maarten Derickx (2011-09-14): fixed ideal_with_gens_over_base()89EXAMPLES:1011Ideals in the maximal order of a rational function field::1213sage: K.<x> = FunctionField(QQ)14sage: O = K.maximal_order()15sage: I = O.ideal(x^3+1); I16Ideal (x^3 + 1) of Maximal order in Rational function field in x over Rational Field17sage: I^218Ideal (x^6 + 2*x^3 + 1) of Maximal order in Rational function field in x over Rational Field19sage: ~I20Ideal (1/(x^3 + 1)) of Maximal order in Rational function field in x over Rational Field21sage: ~I * I22Ideal (1) of Maximal order in Rational function field in x over Rational Field2324Ideals in the equation order of an extension of a rational function field::2526sage: K.<x> = FunctionField(QQ); R.<y> = K[]27sage: L.<y> = K.extension(y^2-x^3-1)28sage: O = L.equation_order()29sage: I = O.ideal(y); I30Ideal (x^3 + 1, -y) of Order in Function field in y defined by y^2 - x^3 - 131sage: I^232Ideal (x^3 + 1, (-x^3 - 1)*y) of Order in Function field in y defined by y^2 - x^3 - 133sage: ~I34Ideal (-1, (1/(x^3 + 1))*y) of Order in Function field in y defined by y^2 - x^3 - 135sage: ~I * I36Ideal (1, y) of Order in Function field in y defined by y^2 - x^3 - 137sage: I.intersection(~I)38Ideal (x^3 + 1, -y) of Order in Function field in y defined by y^2 - x^3 - 139"""40#*****************************************************************************41# Copyright (C) 2010 William Stein <[email protected]>42# Copyright (C) 2011 Maarten Derickx <[email protected]>43#44# Distributed under the terms of the GNU General Public License (GPL)45# as published by the Free Software Foundation; either version 2 of46# the License, or (at your option) any later version.47# http://www.gnu.org/licenses/48#*****************************************************************************4950from sage.rings.ideal import Ideal_generic5152class FunctionFieldIdeal(Ideal_generic):53"""54A fractional ideal of a function field.5556EXAMPLES::5758sage: K.<x> = FunctionField(GF(7))59sage: O = K.maximal_order()60sage: I = O.ideal(x^3+1)61sage: isinstance(I, sage.rings.function_field.function_field_ideal.FunctionFieldIdeal)62True63"""64pass6566class FunctionFieldIdeal_module(FunctionFieldIdeal):67"""68A fractional ideal specified by a finitely generated module over69the integers of the base field.7071EXAMPLES:7273An ideal in an extension of a rational function field::7475sage: K.<x> = FunctionField(QQ); R.<y> = K[]76sage: L.<y> = K.extension(y^2 - x^3 - 1)77sage: O = L.equation_order()78sage: I = O.ideal(y)79sage: I80Ideal (x^3 + 1, -y) of Order in Function field in y defined by y^2 - x^3 - 181sage: I^282Ideal (x^3 + 1, (-x^3 - 1)*y) of Order in Function field in y defined by y^2 - x^3 - 183"""84def __init__(self, ring, module):85"""86INPUT:8788- ``ring`` -- an order in a function field89- ``module`` -- a module9091EXAMPLES::9293sage: K.<x> = FunctionField(QQ); R.<y> = K[]94sage: L.<y> = K.extension(y^2 - x^3 - 1)95sage: O = L.equation_order()96sage: I = O.ideal(y)97sage: type(I)98<class 'sage.rings.function_field.function_field_ideal.FunctionFieldIdeal_module'>99"""100self._ring = ring101self._module = module102self._structure = ring.fraction_field().vector_space()103V, from_V, to_V = self._structure104gens = tuple([from_V(a) for a in module.basis()])105Ideal_generic.__init__(self, ring, gens, coerce=False)106107def __contains__(self, x):108"""109Return True if x is in this ideal.110111EXAMPLES::112113sage: K.<x> = FunctionField(GF(7)); R.<y> = K[]114sage: L.<y> = K.extension(y^2 - x^3 - 1)115sage: O = L.equation_order()116sage: I = O.ideal_with_gens_over_base([1, y]); I117Ideal (1, y) of Order in Function field in y defined by y^2 + 6*x^3 + 6118sage: y in I119True120sage: y/x in I121False122sage: y^2 - 2 in I123True124"""125return self._structure[2](x) in self._module126127def module(self):128"""129Return module over the maximal order of the base field that130underlies self.131132The formation of this module is compatible with the vector133space corresponding to the function field.134135OUTPUT:136137- a module over the maximal order of the base field of self138139EXAMPLES::140141sage: K.<x> = FunctionField(GF(7))142sage: O = K.maximal_order(); O143Maximal order in Rational function field in x over Finite Field of size 7144sage: K.polynomial_ring()145Univariate Polynomial Ring in x over Rational function field in x over Finite Field of size 7146sage: I = O.ideal_with_gens_over_base([x^2 + 1, x*(x^2+1)])147sage: I.gens()148(x^2 + 1,)149sage: I.module()150Free module of degree 1 and rank 1 over Maximal order in Rational function field in x over Finite Field of size 7151User basis matrix:152[x^2 + 1]153sage: V, from_V, to_V = K.vector_space(); V154Vector space of dimension 1 over Rational function field in x over Finite Field of size 7155sage: I.module().is_submodule(V)156True157"""158return self._module159160def __add__(self, other):161"""162Add self and ``other``.163164EXAMPLES::165166sage: K.<x> = FunctionField(GF(7)); R.<y> = K[]167sage: L.<y> = K.extension(y^2 - x^3 - 1)168sage: O = L.equation_order()169sage: I = O.ideal(y); J = O.ideal(y+1)170sage: Z = I + J; Z171Ideal (y + 1, 6*y) of Order in Function field in y defined by y^2 + 6*x^3 + 6172sage: 1 in Z173True174sage: O.ideal(y^2) + O.ideal(y^3) == O.ideal(y^2,y^3)175True176"""177if not isinstance(other, FunctionFieldIdeal_module):178other = self.ring().ideal(other)179return FunctionFieldIdeal_module(self.ring(), self.module() + other.module())180181def intersection(self, other):182"""183Return the intersection of the ideals self and ``other``.184185EXAMPLES::186187sage: K.<x> = FunctionField(GF(7)); R.<y> = K[]188sage: L.<y> = K.extension(y^2 - x^3 - 1)189sage: O = L.equation_order()190sage: I = O.ideal(y^3); J = O.ideal(y^2)191sage: Z = I.intersection(J); Z192Ideal (x^6 + 2*x^3 + 1, (6*x^3 + 6)*y) of Order in Function field in y defined by y^2 + 6*x^3 + 6193sage: y^2 in Z194False195sage: y^3 in Z196True197"""198if not isinstance(other, FunctionFieldIdeal_module):199other = self.ring().ideal(other)200if self.ring() != other.ring():201raise ValueError, "rings must be the same"202return FunctionFieldIdeal_module(self.ring(), self.module().intersection(other.module()))203204def __cmp__(self, other):205"""206Compare self and ``other``.207208EXAMPLES::209210sage: K.<x> = FunctionField(GF(7)); R.<y> = K[]211sage: L.<y> = K.extension(y^2 - x^3 - 1)212sage: O = L.equation_order()213sage: I = O.ideal(y*(y+1)); J = O.ideal((y^2-2)*(y+1))214sage: I+J == J+I # indirect test215True216sage: I == J217False218sage: I < J219True220sage: J < I221False222"""223if not isinstance(other, FunctionFieldIdeal_module):224other = self.ring().ideal(other)225if self.ring() != other.ring():226raise ValueError, "rings must be the same"227return cmp(self.module(), other.module())228229def __invert__(self):230"""231Return the inverse of this fractional ideal.232233EXAMPLES::234235sage: K.<x> = FunctionField(GF(7)); R.<y> = K[]236sage: L.<y> = K.extension(y^2 - x^3 - 1)237sage: O = L.equation_order()238sage: I = O.ideal(y)239sage: ~I240Ideal (6, (1/(x^3 + 1))*y) of Order in Function field in y defined by y^2 + 6*x^3 + 6241sage: I^(-1)242Ideal (6, (1/(x^3 + 1))*y) of Order in Function field in y defined by y^2 + 6*x^3 + 6243sage: ~I * I244Ideal (1, y) of Order in Function field in y defined by y^2 + 6*x^3 + 6245"""246if len(self.gens()) == 0:247raise ZeroDivisionError248249# NOTE: If I = (g0, ..., gn), then {x : x*I is in R}250# is the intersection over i of {x : x*gi is in R}251# Thus (I + J)^(-1) = I^(-1) intersect J^(-1).252253G = self.gens()254R = self.ring()255inv = R.ideal(~G[0])256for g in G[1:]:257inv = inv.intersection(R.ideal(~g))258return inv259260def ideal_with_gens(R, gens):261"""262Return fractional ideal in the order ``R`` with generators ``gens``263over ``R``.264265EXAMPLES::266267sage: K.<x> = FunctionField(QQ); R.<y> = K[]268sage: L.<y> = K.extension(y^2 - x^3 - 1)269sage: O = L.equation_order()270sage: sage.rings.function_field.function_field_ideal.ideal_with_gens(O, [y])271Ideal (x^3 + 1, -y) of Order in Function field in y defined by y^2 - x^3 - 1272"""273K = R.fraction_field()274return ideal_with_gens_over_base(R, [b*K(g) for b in R.basis() for g in gens])275276def ideal_with_gens_over_base(R, gens):277"""278Return fractional ideal in the order ``R`` with generators ``gens``279over the maximal order of the base field.280281EXAMPLES::282283sage: K.<x> = FunctionField(QQ); R.<y> = K[]284sage: L.<y> = K.extension(y^2 - x^3 - 1)285sage: O = L.equation_order()286sage: sage.rings.function_field.function_field_ideal.ideal_with_gens_over_base(O, [x^3+1,-y])287Ideal (x^3 + 1, -y) of Order in Function field in y defined by y^2 - x^3 - 1288289TESTS::290291sage: K.<x> = FunctionField(QQ)292sage: O = K.maximal_order()293sage: I = O*x294sage: ~I295Ideal (1/x) of Maximal order in Rational function field in x over Rational Field296sage: ~I == O.ideal(1/x)297True298sage: O.ideal([x,1/x])299Ideal (1/x) of Maximal order in Rational function field in x over Rational Field300sage: O.ideal([1/x,1/(x+1)])301Ideal (1/(x^2 + x)) of Maximal order in Rational function field in x over Rational Field302"""303K = R.fraction_field()304V, from_V, to_V = K.vector_space()305306# We handle the case of a rational function field separately,307# since this is the base case and is used, e.g,. internally308# by the linear algebra Hermite form code.309import function_field_order310if isinstance(R, function_field_order.FunctionFieldOrder_rational):311from sage.modules import free_module_element312gens = free_module_element.vector(x.element() for x in gens)313d = gens.denominator()314gens *= d315v = R._ring.ideal(gens.list()).gens_reduced()316assert len(v) == 1317basis = [to_V(v[0]/d)]318M = V.span_of_basis(basis, check=False, already_echelonized=True, base_ring=R)319else:320# General case321S = V.base_field().maximal_order()322M = V.span([to_V(b) for b in gens], base_ring=S)323324return FunctionFieldIdeal_module(R, M)325326327