Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to iterate over 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

How to iterate over 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.

How to iterate over 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.