Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are some tools to wrap things up a bit. Note that "map_coefficients" might still do funny things with the codomain parent: for instance, in your case I think you end up with polynomials over the Algebraic Real Field rather than QQbar.

   sage: from sage.structure.coerce_maps import CallableConvertMap
   sage: H=CallableConvertMap(RR,QbarX,lambda self,f:QbarX(f.map_coefficients(hom)))

Making a homomorphism between the fields of fractions could be done similarly. I think the tools for this kind of stuff could be made more convenient and/or be documented in a more discoverable way.

There are some tools to wrap things up a bit. Note that "map_coefficients" might still do funny things with the codomain parent: for instance, in your case I think you end up with polynomials over the Algebraic Real Field rather than QQbar.

   sage: from sage.structure.coerce_maps import CallableConvertMap
   sage: H=CallableConvertMap(RR,QbarX,lambda self,f:QbarX(f.map_coefficients(hom)))

Making a homomorphism between the fields of fractions could be done similarly. I think the tools for this kind of stuff could be made more convenient and/or be documented in a more discoverable way.

In your particular case there might be a shortcut. It's not as general as good tools to naturally extend ring homomorphisms to modules and algebras over these bases. Given that your number field comes from QQbar, it should perhaps be constructed with an embedding into it as well. We can hack our way around that a little bit by registering the embedding ourselves (since this modifies the coercion graph at a node that might already have been used, it could lead to inconsistencies, so we have to take some extra steps to neutralize safety precautions. Furthermore, it modifies the behaviour of a possibly globally unique parent, so it's really a hack at this point. Embeddings should be supplied upon construction, not added later):

sage: nf, alpha, hom = QQbar(sqrt(2)).as_number_field_element()
sage: nf._unset_coercions_used()
sage: nf.register_embedding(hom)
sage: nfX.<x>=nf[]
sage: QbarX.<x>=QQbar[]
sage: 1/nfX.0 - QbarX.0
(-x^2 + 1)/x
sage: parent(1/nfX.0 - QbarX.0)
Fraction Field of Univariate Polynomial Ring in x over Algebraic Field
sage: QbarX.coerce_map_from(nfX)

Ring morphism:
  From: Univariate Polynomial Ring in x over Number Field in a with defining polynomial y^2 - 2
  To:   Univariate Polynomial Ring in x over Algebraic Field
  Defn: Induced from base ring by
        Composite map:
          From: Number Field in a with defining polynomial y^2 - 2
          To:   Algebraic Field
          Defn:   Ring morphism:
                  From: Number Field in a with defining polynomial y^2 - 2
                  To:   Algebraic Real Field
                  Defn: a |--> 1.414213562373095?
                then
                  Conversion map:
                  From: Algebraic Real Field
                  To:   Algebraic Field

Sage does have quite good tools available for discovering/constructing these kinds of induced maps, but unfortunately they are only available for registered coercion maps. It would be great if the same tools would also be usable with an explicitly given, non-standard set of homomorphisms for the construction of new maps.