1 | initial version |
You should really give explicit example with Sage code, so that we really understand what do you want to achieve. Let me take my own example:
sage: equ0 = cos(x) == 3*x^2 + log(x) + 42*sin(x)
sage: equ0
cos(x) == 3*x^2 + log(x) + 42*sin(x)
You can first extract the right-hand-side of the equation as follows:
sage: equ0.rhs()
3*x^2 + log(x) + 42*sin(x)
Then, you can check that it is an addition:
sage: equ0.rhs().operator()
<function add_vararg at 0x7f5a30600050>
For which you can get the operands:
sage: equ0.rhs().operands()
[3*x^2, log(x), 42*sin(x)]
You can extract the first two terms of this list:
sage: equ0.rhs().operands()[:2]
[3*x^2, log(x)]
You can them add them together:
sage: sum(equ0.rhs().operands()[:2])
3*x^2 + log(x)
WARNING the order of the operands is not necessrilly the one you entered:
sage: equ0 = cos(x) == log(x) + 3*x^2 + 42*sin(x)
sage: equ0
cos(x) == 3*x^2 + log(x) + 42*sin(x)