1 | initial version |

The problem is that, fundamentally, a symbolic expression is a tree whose leaf nodes are variables, whereas a polynomial is a list of (power, coefficients) pairs; the fact that the notations "^", "+" and "*" are homonyms is (almost) an historical accident.

There is no built-in way for Sage to construct the list you wish to build from your tree. However, it can be done using the (accidental) common representation... as a character string. The following horror works :

```
sage: Lv = ("x", "y")
sage: Li = ("u", "v")
sage: var(Lv)
(x, y)
sage: R1=PolynomialRing(GF(101), Li)
sage: P = x^2 - x*y + y^3
sage: S = repr(P)
sage: for r in zip(Lv, Li) : S = S.replace(r[0], r[1])
sage: Q = R1(S)
sage: Q
v^3 + u^2 - u*v
sage: Q.parent()
Multivariate Polynomial Ring in u, v over Finite Field of size 101
```

but keep in mind that this is a pure typographical manipulation, with no intrinsic mathematical meaning at the level of the symbols used. (Tois has of course a mathematical meaning in terms of manipulation of strings..., but this is irrelevant to your problem).

HTH,

2 | No.2 Revision |

The problem is that, fundamentally, a symbolic expression is a tree whose leaf nodes are variables, whereas a polynomial is a list of (power, coefficients) pairs; the fact that the notations "^", "+" and "*" are homonyms is (almost) an historical accident.

There is no built-in way for Sage to construct the list you wish to build from your tree. However, it can be done using the (accidental) common representation... as a character string. The following horror works :

```
sage: Lv = ("x", "y")
sage: Li = ("u", "v")
sage: var(Lv)
(x, y)
sage: R1=PolynomialRing(GF(101), Li)
sage: P = x^2 - x*y + y^3
sage: S = repr(P)
sage: for r in zip(Lv, Li) : S = S.replace(r[0], r[1])
sage: Q = R1(S)
sage: Q
v^3 + u^2 - u*v
sage: Q.parent()
Multivariate Polynomial Ring in u, v over Finite Field of size 101
```

but keep in mind that this is a pure typographical manipulation, with no intrinsic mathematical meaning at the level of the symbols used. ~~(Tois ~~(This has of course a mathematical meaning in terms of manipulation of strings..., but this is irrelevant to your problem).

HTH,

3 | No.3 Revision |

The problem is that, fundamentally, a symbolic expression is a tree whose leaf nodes are variables, whereas a polynomial is a list of ~~(power, coefficients) ~~(list of (indeterminate, power,) coefficient) pairs; the fact that the notations "^", "+" and "*" are homonyms is (almost) an historical accident.

There is no built-in way for Sage to construct the list you wish to build from your tree. However, it can be done using the (accidental) common representation... as a character string. The following horror works :

```
sage: Lv = ("x", "y")
sage: Li = ("u", "v")
sage: var(Lv)
(x, y)
sage: R1=PolynomialRing(GF(101), Li)
sage: P = x^2 - x*y + y^3
sage: S = repr(P)
sage: for r in zip(Lv, Li) : S = S.replace(r[0], r[1])
sage: Q = R1(S)
sage: Q
v^3 + u^2 - u*v
sage: Q.parent()
Multivariate Polynomial Ring in u, v over Finite Field of size 101
```

but keep in mind that this is a pure typographical manipulation, with no intrinsic mathematical meaning at the level of the symbols used. (This has of course a mathematical meaning in terms of manipulation of strings..., but this is irrelevant to your problem).

HTH,

**EDIT :** PS : note that you can obtain directly a relevant polynomial by :

```
sage: Q2 = P.polynomial(base_ring=GF(101))
sage: Q2
y^3 + x^2 - x*y
sage: Q2.parent()
Multivariate Polynomial Ring in x, y over Finite Field of size 101
```

but the notations are becoming extremely confusing, since :

```
sage: x.parent()
Symbolic Ring
```

As far as I know, Sage has no built-in way to substitute an indeterminate for another in a multivariate polynomial, so working (temporarily) in `PolynomialRing(GF(101), ["x", "y", "u", "v"])`

is a dead end.

Of course, if you don't have to denote the individual indeterminates and work on them at the individual level, you can get away with working only with polynomials :

```
sage: P
y^3 + x^2 - x*y
sage: T1 = P.polynomial(base_ring=GF(101))
sage: T2 = (x^3-y^2).polynomial(base_ring=GF(101))
sage: T1+T2
x^3 + y^3 + x^2 - x*y - y^2
sage: (T1+T2).parent()
Multivariate Polynomial Ring in x, y over Finite Field of size 101
```

Again, you might confuse your readers with such pranks.

4 | No.4 Revision |

The problem is that, fundamentally, a symbolic expression is a tree whose leaf nodes are variables, whereas a polynomial is a ~~list of (list ~~*list* of (monomial, coefficient) pairs the monomials being themselves lists of (indeterminate, ~~power,) coefficient) ~~power) pairs; the fact that the notations "^", "+" and "*" are homonyms is (almost) an historical ~~accident.~~accident. A symbolic expression may have an analytic meaning, a polynomial is strictly algebraic.

```
sage: Lv = ("x", "y")
sage: Li = ("u", "v")
sage: var(Lv)
(x, y)
sage: R1=PolynomialRing(GF(101), Li)
sage: P = x^2 - x*y + y^3
sage: S = repr(P)
sage: for r in zip(Lv, Li) : S = S.replace(r[0], r[1])
sage: Q = R1(S)
sage: Q
v^3 + u^2 - u*v
sage: Q.parent()
Multivariate Polynomial Ring in u, v over Finite Field of size 101
```

but keep in mind that this is a pure typographical manipulation, with no intrinsic mathematical meaning at the level of the symbols used. (This has of course a mathematical meaning in terms of manipulation of strings..., but this is irrelevant to your problem).

HTH,

**EDIT :** PS : note that you can obtain directly a relevant polynomial by :

```
sage: Q2 = P.polynomial(base_ring=GF(101))
sage: Q2
y^3 + x^2 - x*y
sage: Q2.parent()
Multivariate Polynomial Ring in x, y over Finite Field of size 101
```

but the notations are becoming extremely confusing, since :

```
sage: x.parent()
Symbolic Ring
```

As far as I know, Sage has no built-in way to substitute an indeterminate for another in a multivariate polynomial, so working (temporarily) in `PolynomialRing(GF(101), ["x", "y", "u", "v"])`

is a dead end.

Of course, if you don't have to denote the individual indeterminates and work on them at the individual level, you can get away with working only with polynomials :

```
sage: P
y^3 + x^2 - x*y
sage: T1 = P.polynomial(base_ring=GF(101))
sage: T2 = (x^3-y^2).polynomial(base_ring=GF(101))
sage: T1+T2
x^3 + y^3 + x^2 - x*y - y^2
sage: (T1+T2).parent()
Multivariate Polynomial Ring in x, y over Finite Field of size 101
```

Again, you might confuse your readers with such pranks.

**EDIT :** clarified the definition of a polynomial.

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.