# Ticket #9054: trac_9054_maps_refactor.patch

File trac_9054_maps_refactor.patch, 14.6 KB (added by saraedum, 10 years ago)

refactored maps class hieararchy

• ## sage/rings/function_field/function_field.py

```exporting patch:
# HG changeset patch
# User Julian Rueth <julian.rueth@gmail.com>
Trac 9054: refactored maps class hierarchy

diff --git a/sage/rings/function_field/function_field.py b/sage/rings/function_field/function_field.py
index f894165..093dbd6 100644```
 a class FunctionField(Field): return True return False def hom(self, im_gens, base_morphism=None): """ Create a homomorphism from self to another function field. INPUT: - ``im_gens`` -- a list of images of the generators of self and of successive base rings. - ``base_morphism`` -- (default: None) a homomorphism of the base ring, after the im_gens are used.  Thus if im_gens has length 2, then base_morphism should be a morphism from self.base_ring().base_ring(). EXAMPLES:: We create a rational function field, and a quadratic extension of it:: sage: R. = FunctionField(QQ); S. = R[] sage: L. = R.extension(y^2 - x^3 - 1) We make the field automorphism that sends y to -y:: sage: f = L.hom(-y); f Morphism of function fields defined by y |--> -y Evaluation works:: sage: f(y*x - 1/x) -x*y - 1/x We try to define an invalid morphism:: sage: f = L.hom(y+1); f Traceback (most recent call last): ... ValueError: invalid morphism We make a morphism of the base rational function field:: sage: phi = R.hom(x+1); phi Morphism of function fields defined by x |--> x + 1 sage: phi(x^3 - 3) x^3 + 3*x^2 + 3*x - 2 sage: (x+1)^3-3 x^3 + 3*x^2 + 3*x - 2 We make a morphism by specifying where the generators and the base generators go:: sage: L.hom([-y, x]) Morphism of function fields defined by y |--> -y,  x |--> x The usage of the keyword base_morphism is not implemented yet:: sage: L.hom([-y, x-1], base_morphism=phi) Traceback (most recent call last): ... NotImplementedError: Function field homorphisms with optional argument base_morphism are not implemented yet. Please specify the images of the generators of the base fields manually. We make another extension of a rational function field:: sage: R2. = FunctionField(QQ); S2. = R2[] sage: L2. = R2.extension((4*w)^2 - (t+1)^3 - 1) We define a morphism, by giving the images of generators:: sage: f = L.hom([4*w, t+1]); f Morphism of function fields defined by y |--> 4*w,  x |--> t + 1 Evaluation works, as expected:: sage: f(y+x) 4*w + t + 1 sage: f(x*y + x/(x^2+1)) (4*t + 4)*w + (t + 1)/(t^2 + 2*t + 2) We make another extension of a rational function field:: sage: R3. = FunctionField(QQ); S3. = R3[] sage: L3. = R3.extension(yy^2 - xx^3 - 1) This is the function field L with the generators exchanged. We define a morphism to L:: sage: g = L3.hom([x,y]); g Morphism of function fields defined by xx |--> x, yy |--> y """ if base_morphism is not None: raise NotImplementedError, "Function field homorphisms with optional argument base_morphism are not implemented yet. Please specify the images of the generators of the base fields manually." if not isinstance(im_gens, (list,tuple)): im_gens = [im_gens] if len(im_gens) == 0: raise ValueError, "no images specified" if len(im_gens) > 1: base_morphism = self.base_field().hom(im_gens[1:], base_morphism) # the codomain of this morphism is the field containing all the im_gens codomain = im_gens[0].parent(); if base_morphism is not None: if base_morphism.codomain().has_coerce_map_from(codomain): codomain = base_morphism.codomain(); return maps.FunctionFieldMorphism(self.Hom(codomain), im_gens[0], base_morphism) class FunctionField_polymod(FunctionField): """ A function field defined by a univariate polynomial, as an class FunctionField_polymod(FunctionField): return self.order(d*self.gen(), check=False) def hom(self, im_gens, base_morphism=None): """ Create a homomorphism from self to another function field. INPUT: - ``im_gens`` -- a list of images of the generators of self and of successive base rings. - ``base_morphism`` -- (default: None) a homomorphism of the base ring, after the im_gens are used.  Thus if im_gens has length 2, then base_morphism should be a morphism from self.base_ring().base_ring(). EXAMPLES: We create a rational function field, and a quadratic extension of it:: sage: K. = FunctionField(QQ); R. = K[] sage: L. = K.extension(y^2 - x^3 - 1) We make the field automorphism that sends y to -y:: sage: f = L.hom(-y); f Morphism of function fields defined by y |--> -y Evaluation works:: sage: f(y*x - 1/x) -x*y - 1/x We try to define an invalid morphism:: sage: f = L.hom(y+1) Traceback (most recent call last): ... ValueError: invalid morphism We make a morphism of the base rational function field:: sage: phi = K.hom(x+1); phi Morphism of function fields defined by x |--> x + 1 sage: phi(x^3 - 3) x^3 + 3*x^2 + 3*x - 2 sage: (x+1)^3-3 x^3 + 3*x^2 + 3*x - 2 We make a morphism by specifying where the generators and the base generators go:: sage: L.hom([-y, x]) Morphism of function fields defined by y |--> -y,  x |--> x The usage of the keyword base_morphism is not implemented yet:: sage: L.hom([-y, x-1], base_morphism=phi) Traceback (most recent call last): ... NotImplementedError: Function field homorphisms with optional argument base_morphism are not implemented yet. Please specify the images of the generators of the base fields manually. We make another extension of a rational function field:: sage: K2. = FunctionField(QQ); R2. = K2[] sage: L2. = K2.extension((4*w)^2 - (t+1)^3 - 1) We define a morphism, by giving the images of generators:: sage: f = L.hom([4*w, t+1]); f Morphism of function fields defined by y |--> 4*w,  x |--> t + 1 Evaluation works, as expected:: sage: f(y+x) 4*w + t + 1 sage: f(x*y + x/(x^2+1)) (4*t + 4)*w + (t + 1)/(t^2 + 2*t + 2) We make another extension of a rational function field:: sage: K3. = FunctionField(QQ); R3. = K3[] sage: L3. = K3.extension(yy^2 - xx^3 - 1) This is the function field L with the generators exchanged. We define a morphism to L:: sage: g = L3.hom([x,y]); g Morphism of function fields defined by xx |--> x, yy |--> y """ if base_morphism is not None: raise NotImplementedError, "Function field homorphisms with optional argument base_morphism are not implemented yet. Please specify the images of the generators of the base fields manually." if not isinstance(im_gens, (list,tuple)): im_gens = [im_gens] if len(im_gens) == 0: raise ValueError, "no images specified" if len(im_gens) > 1: base_morphism = self.base_field().hom(im_gens[1:], base_morphism) # the codomain of this morphism is the field containing all the im_gens codomain = im_gens[0].parent(); if base_morphism is not None: if base_morphism.codomain().has_coerce_map_from(codomain): codomain = base_morphism.codomain(); from maps import FunctionFieldMorphism_polymod return FunctionFieldMorphism_polymod(self.Hom(codomain), im_gens[0], base_morphism) class RationalFunctionField(FunctionField): """ A rational function field K(t) in one variable, over an arbitrary
• ## sage/rings/function_field/maps.py

```diff --git a/sage/rings/function_field/maps.py b/sage/rings/function_field/maps.py