# How to iterate over symbolic coefficients

I am a relative newbie to Sage but not to algebraic manipulation in general.

I have a family of expressions with non-linear coefficients which I am not sure how best to represent. In the end it has to be an (infinite) ring of polynomials representing a Volterra space, but I have the same terms inside non-linear functions (which I need to evaluate to a known value) and as the polynomial variables.

Here is an example, where simple symbolic manipulation doesn't work:

```
f_m = a*x^b
ex = expand(f_m.subs({b : b_m + (b_s-b_m)^3})).derivative(b_m).full_simplify()
ex.subs({b_m + (b_s-b_m)^3 : b_m }).show()
```

Producing:

```
-(3*a*b_m^2 - 6*a*b_m*b_s + 3*a*b_s^2 - a)*x^(-b_m^3 + 3*b_m^2*b_s - 3*b_m*b_s^2 + b_s^3 + b_m)*log(x)
```

When what I want is:

```
-(3*a*b_m^2 - 6*a*b_m*b_s + 3*a*b_s^2 - a)*x^(-b_m)*log(x)
```

How can I iterate over non-linear elements (exponent and the arguments to any non-monomial terms) carrying out direct substitutions, while leaving monomials alone. I want the result to remain as a polynomial ring on b_s

Clarification: The intent is to use the code for a generic non-linear construct. It's intended to handle any general non-linear expression in L2, but these are manipulated to belong to a class of Volterra polynomials with non-linear coefficients. like the log(x) and x^bm on the above example. Those are the coefficients of the monomials.

Idealy whatever process I follow should be able to identify the non-monomial coefficients in the expression and remove the monomial terms from them by doing the substitution b_s = b_m. Basically:

```
x.subs(b_s = b_m) for x not a monomial term in expression.
```

Which would make the resulting expression strictly a polynomial ring on b_s with non-linear coefficients on x and b_m.

Are you using the "symbolic ring" or the more specific polynomial rings? It's unclear from your code, though the use of

`full_simplify`

indicates you are just using`var()`

to create new variables - making a polynomial ring in`b_s`

might help, I'm not sure.I don't have experience with either, but it's obvious to me that a polynomial ring is what I want and a symbolic ring might provide me with the proper iteration tools. When I tried the polynomial ring of polynomial coefficients I kept getting errors due to the same variable being used on the exponents and the monomials. I have no idea about the symbolic ring or how to use it, but given that this is just a minor step in a long process doing things by hand is not an option.

Are

`b_m`

and`b_s`

supposed to remain unknown, or will they be given actual integer values ?@tmontell They are supposed to remain unknown until I can coerce the final output of a long set of operations into a numeric framework.