Rewriting an expression in terms of a different variable

asked 2022-07-12 13:12:05 +0200

Hi there! I'm a beginner in SageMath and I have a question on a topic that's been boggling me for some time now.

I was wondering how one could rewrite an expression in terms of a different variable, where the twist is that some variable is "deleted".

For an example, how can I tell SageMath that I want to rewrite the expression

[a^2 + b] (this expression has 2 variables, namely "a" and "b")

into an expression in terms of 2 variables "t" and "b", where "t = a+b". In this case, we "delete" "a".

If we were to compute this ourselves, then a^2 + 2ab + b^2 = t^2 implies a^2 = t^2 - b^2 - 2ab = t^2 - b^2 - 2(t-b)b, thus

[a^2 + b = (t^2 - b^2 - 2(t-b)b) + b = t^2 - b^2 - 2(t-b)b + b]

which is completely in terms of "t" and "b", noticing that "a" is now not a part of the expression.

I have a long expression like this right now with degree <= 4 and it would very helpful if someone could provide the answer.

Thank you in advance.

edit retag flag offensive close merge delete

Comments

Try (a^2 + b).subs({a:t-b}) or (a^2 + b).subs({a:t-b}).expand() if you want the expression in expanded form.

Max Alekseyev gravatar imageMax Alekseyev ( 2022-07-13 19:49:38 +0200 )edit