On Thursday, October 1, 2015 at 8:15:39 AM UTC-7, len...@ackermans.info 
wrote:
>
> In my code I often encounter elements of polynomial rings of polynomial 
> rings. Since some functions only work on multivariate polynomial rings I 
> need to create a homomorphism, but I'm unable to do this. What is the 
> recommended way?
>

This is actually one of the things where sage's coercion framework is 
pretty advanced. You do have to make sure that the names of the variables 
agree, tough. Sage uses those names to figure out how to coerce. To define 
the homomorphism:

sage: A=QQ['x']
sage: B=A['y']
sage: C=QQ['x','y']
sage: B.hom([C.1])
Ring morphism:
  From: Univariate Polynomial Ring in y over Univariate Polynomial Ring in 
x over Rational Field
  To:   Multivariate Polynomial Ring in x, y over Rational Field
  Defn: y |--> y

The homomorphism is described by "send the generator of B (over A) to the 
second generator of C, and figure out yourself how to coerce A into C". It 
can do the latter because both A and C are generated over a common subring 
(QQ) and the generator of A has a name that is equal to the name of a 
generator of C: an obvious target.

Indeed, these rules allow sage to even coerce B into C: you can just mix 
them in expressions:

sage: A.0+B.0+C.0
2*x + y

It chooses the multivariate ring as the common parent:

sage: parent(A.0+B.0+C.0) is C
True

You can also obtain the coercion map sage uses itself and use it as the 
homomorphism you asked for at the top:

sage: C.coerce_map_from(B)
Conversion map:
  From: Univariate Polynomial Ring in y over Univariate Polynomial Ring in 
x over Rational Field
  To:   Multivariate Polynomial Ring in x, y over Rational Field

 

> Further questions:
> Why is there no standard coercion between nested polynomial rings and 
> multivariate polynomial rings?
>

There is such a coercion 

Should we change functions on polynomials like factor() to work in the case 
> of nested polynomial rings, by using a coercion to multivariate polynomial 
> rings?
>

In individual cases: possibly. In general: no. There could be merit in 
"nested" arithmetic.  
 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to