\[ \int \cot ^3(c+d x) (a+i a \tan (c+d x))^4 (A+B \tan (c+d x)) \, dx \]
Optimal antiderivative \[ -8 a^{4} \left (i A +B \right ) x -\frac {a^{4} \left (-4 i B +A \right ) \ln \left (\cos \left (d x +c \right )\right )}{d}-\frac {a^{4} \left (-4 i B +7 A \right ) \ln \left (\sin \left (d x +c \right )\right )}{d}-\frac {a A \left (\cot ^{2}\left (d x +c \right )\right ) \left (a +i a \tan \left (d x +c \right )\right )^{3}}{2 d}-\frac {\left (5 i A +2 B \right ) \cot \left (d x +c \right ) \left (a^{2}+i a^{2} \tan \left (d x +c \right )\right )^{2}}{2 d}-\frac {3 A \left (a^{4}+i a^{4} \tan \left (d x +c \right )\right )}{d} \]
command
integrate(cot(d*x+c)**3*(a+I*a*tan(d*x+c))**4*(A+B*tan(d*x+c)),x)
Sympy 1.10.1 under Python 3.10.4 output
\[ - \frac {a^{4} \left (A - 4 i B\right ) \log {\left (e^{2 i d x} + \frac {\left (4 A a^{4} - 4 i B a^{4} - a^{4} \left (A - 4 i B\right )\right ) e^{- 2 i c}}{3 A a^{4}} \right )}}{d} - \frac {a^{4} \cdot \left (7 A - 4 i B\right ) \log {\left (e^{2 i d x} + \frac {\left (4 A a^{4} - 4 i B a^{4} - a^{4} \cdot \left (7 A - 4 i B\right )\right ) e^{- 2 i c}}{3 A a^{4}} \right )}}{d} + \frac {10 A a^{4} e^{4 i c} e^{4 i d x} - 8 A a^{4} + 4 i B a^{4} + \left (2 A a^{4} e^{2 i c} - 4 i B a^{4} e^{2 i c}\right ) e^{2 i d x}}{d e^{6 i c} e^{6 i d x} - d e^{4 i c} e^{4 i d x} - d e^{2 i c} e^{2 i d x} + d} \]
Sympy 1.8 under Python 3.8.8 output
\[ \text {Exception raised: NotInvertible} \]________________________________________________________________________________________