def _element_constructor_(self, x, check=True): """ Construct an element of ``self`` from ``x``. EXAMPLES:: sage: H = Hom(QuadraticField(-1, 'a'), QuadraticField(-1, 'b')) sage: phi = H([H.domain().gen()]); phi Ring morphism: From: Number Field in a with defining polynomial x^2 + 1 with a = 1*I To: Number Field in b with defining polynomial x^2 + 1 with b = 1*I Defn: a |--> b sage: H1 = End(QuadraticField(-1, 'a')) sage: H1.coerce(loads(dumps(H1[1]))) Ring endomorphism of Number Field in a with defining polynomial x^2 + 1 with a = 1*I Defn: a |--> -a TESTS: We can move morphisms between categories:: sage: f = H1.an_element() sage: g = End(H1.domain(), category=Rings())(f) sage: f == End(H1.domain(), category=NumberFields())(g) True Check that :trac:`28869` is fixed:: sage: K.<a> = CyclotomicField(8) sage: L.<b> = K.absolute_field() sage: H = L.Hom(K) sage: phi = L.structure()[0] sage: phi.parent() is H True sage: H(phi) Isomorphism given by variable name change map: From: Number Field in b with defining polynomial x^4 + 1 To: Cyclotomic Field of order 8 and degree 4 sage: R.<x> = L[] sage: (x^2 + b).change_ring(phi) x^2 + a """ if not isinstance(x, NumberFieldHomomorphism_im_gens): return self.element_class(self, x, check=check) from sage.categories.all import NumberFields, Rings if (x.parent() == self or (x.domain() == self.domain() and x.codomain() == self.codomain() and # This would be the better check, however it returns False currently: # self.homset_category().is_full_subcategory(x.category_for()) # So we check instead that this is a morphism anywhere between # Rings and NumberFields where the hom spaces do not change. NumberFields().is_subcategory(self.homset_category()) and self.homset_category().is_subcategory(Rings()) and NumberFields().is_subcategory(x.category_for()) and x.category_for().is_subcategory(Rings()))): return self.element_class(self, x.im_gens(), check=False)
def _normalize_number_field_data(self, R): r""" Helper method which returns the defining data of the number field ``R``. EXAMPLES:: sage: sys.path.append(os.getcwd()); from mac_lane import * # optional: standalone sage: R.<x> = QQ[] sage: K = R.quo(x^2 + 1) sage: pAdicValuation._normalize_number_field_data(K) (Rational Field, Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1, x^2 + 1) """ from sage.rings.polynomial.polynomial_quotient_ring import is_PolynomialQuotientRing from sage.rings.number_field.number_field import is_NumberField from sage.rings.fraction_field import is_FractionField if is_NumberField(R.fraction_field()): L = R.fraction_field() G = L.relative_polynomial() K = L.base_ring() elif is_PolynomialQuotientRing(R): from sage.categories.all import NumberFields if R.base_ring().fraction_field() not in NumberFields(): raise NotImplementedError("can not normalize quotients over %r"%(R.base_ring(),)) L = R.fraction_field() K = R.base_ring().fraction_field() G = R.modulus().change_ring(K) else: raise NotImplementedError("can not normalize %r"%(R,)) return K, L, G
def _coerce_impl(self, x): r""" Canonical coercion of ``x`` into this homset. The only things that coerce canonically into self are elements of self and of homsets equal to self. EXAMPLES:: sage: H1 = End(QuadraticField(-1, 'a')) sage: H1.coerce(loads(dumps(H1[1]))) # indirect doctest Ring endomorphism of Number Field in a with defining polynomial x^2 + 1 Defn: a |--> -a TESTS: We can move morphisms between categories:: sage: f = H1.an_element() sage: g = End(H1.domain(), category=Rings())(f) sage: f == End(H1.domain(), category=NumberFields())(g) True """ if not isinstance(x, NumberFieldHomomorphism_im_gens): raise TypeError if x.parent() is self: return x from sage.categories.all import NumberFields, Rings if (x.parent() == self or (x.domain() == self.domain() and x.codomain() == self.codomain() and # This would be the better check, however it returns False currently: # self.homset_category().is_full_subcategory(x.category_for()) # So we check instead that this is a morphism anywhere between # Rings and NumberFields where the hom spaces do not change. NumberFields().is_subcategory(self.homset_category()) and self.homset_category().is_subcategory(Rings()) and NumberFields().is_subcategory(x.category_for()) and x.category_for().is_subcategory(Rings()))): return NumberFieldHomomorphism_im_gens(self, x.im_gens(), check=False) raise TypeError
def __init__(self, R, S, category=None): """ TESTS: Check that :trac:`23647` is fixed:: sage: K.<a, b> = NumberField([x^2 - 2, x^2 - 3]) sage: e, u, v, w = End(K) sage: e.abs_hom().parent().category() Category of homsets of number fields sage: (v*v).abs_hom().parent().category() Category of homsets of number fields """ if category is None: from sage.categories.all import Fields, NumberFields if S in NumberFields(): category = NumberFields() elif S in Fields(): category = Fields() RingHomset_generic.__init__(self, R, S, category)