After calling together
you can use fraction
to separate the numerator and denominator and then you can process the numerator with expand/collect
:
In [38]: A, B, p = symbols('A, B, p')
In [39]: A/(p+1)+B/(p+2)
Out[39]:
A B
───── + ─────
p + 1 p + 2
In [40]: e = A/(p+1)+B/(p+2)
In [41]: together(e)
Out[41]:
A?(p + 2) + B?(p + 1)
─────────────────────
(p + 1)?(p + 2)
In [42]: fraction(together(e))
Out[42]: (A?(p + 2) + B?(p + 1), (p + 1)?(p + 2))
In [43]: n, d = fraction(together(e))
In [44]: n = collect(expand(n), p)
In [45]: n/d
Out[45]:
2?A + B + p?(A + B)
───────────────────
(p + 1)?(p + 2)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…