On Mar 12, 2009, at 12:32 AM, Simon King wrote: > Dear Supporters, > > the following works: > sage: R=PolynomialRing(QQ,['a','x1','y1']) > sage: S=PolynomialRing(QQ,['x1','y1','z']) > sage: R('x1+a')+S('x1+z') > a + 2*x1 + z > > The following does not work: > sage: R=PolynomialRing(QQ,['a','x','y1']) > sage: S=PolynomialRing(QQ,['x1','y1','z']) > sage: R('x+a')+S('x1+z') > Traceback (most recent call last): > TypeError: unsupported operand parent(s) for '+': 'Multivariate > Polynomial Ring in a, x, y1 over Rational Field' and 'Multivariate > Polynomial Ring in x1, y1, z over Rational Field' > > Why? > > In both cases, the polynomial rings have some variable names in > common, some not. In the first case, we have a successful coercion to > a common parent: > sage: R=PolynomialRing(QQ,['a','x1','y1']) > sage: S=PolynomialRing(QQ,['x1','y1','z']) > sage: (R('x1+a')*S('x1+z')).parent() > Multivariate Polynomial Ring in a, x1, y1, z over Rational Field > > So, why is the corresponding operation not done in the second example?
Because the ordering of variables is ambiguous. Should it be QQ [a,x,x1,y1,z] or QQ[a,x1,x,y1,z]? sage: QQ['x,y'] == QQ['y,x'] False > Second (related) question: If R and S are polynomial rings over the > same base ring, how can I form the polynomial ring (over the same base > ring) whose variables are the union of the variables of R and of S? Is > this an easy (speed wise) operation? Relatively easy. sage: R = QQ['a,b,c,d'] sage: S = QQ['x,y,z'] sage: all_vars = list(set(R.variable_names() + S.variable_names())) sage: PolynomialRing(R.base_ring(), all_vars) Multivariate Polynomial Ring in a, c, b, d, y, x, z over Rational Field - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---