\[ \int (d \sec (e+f x))^{2 n} (a+i a \tan (e+f x))^{3-n} \, dx \]
Optimal antiderivative \[ \frac {4 \,\mathrm {I} a^{2} \left (d \sec \! \left (f x +e \right )\right )^{2 n} \left (a +\mathrm {I} a \tan \! \left (f x +e \right )\right )^{1-n}}{f \left (n^{2}+3 n +2\right )}+\frac {\mathrm {I} a \left (d \sec \! \left (f x +e \right )\right )^{2 n} \left (a +\mathrm {I} a \tan \! \left (f x +e \right )\right )^{2-n}}{f \left (2+n \right )}+\frac {8 \,\mathrm {I} a^{3} \left (d \sec \! \left (f x +e \right )\right )^{2 n} \left (a +\mathrm {I} a \tan \! \left (f x +e \right )\right )^{-n}}{f n \left (n^{2}+3 n +2\right )} \]
command
integrate((d*sec(f*x+e))^(2*n)*(a+I*a*tan(f*x+e))^(3-n),x, algorithm="maxima")
Maxima 5.46 SBCL 2.0.1.debian via sagemath 9.6 output
\[ \text {Exception raised: RuntimeError} \]
Maxima 5.44 via sagemath 9.3 output
\[ \frac {2^{n + 3} a^{3} d^{2 \, n} \cos \left (n \arctan \left (\sin \left (2 \, f x + 2 \, e\right ), \cos \left (2 \, f x + 2 \, e\right ) + 1\right )\right ) - i \cdot 2^{n + 3} a^{3} d^{2 \, n} \sin \left (n \arctan \left (\sin \left (2 \, f x + 2 \, e\right ), \cos \left (2 \, f x + 2 \, e\right ) + 1\right )\right ) + 8 \, {\left (a^{3} d^{2 \, n} n + 2 \, a^{3} d^{2 \, n}\right )} 2^{n} \cos \left (-2 \, f x + n \arctan \left (\sin \left (2 \, f x + 2 \, e\right ), \cos \left (2 \, f x + 2 \, e\right ) + 1\right ) - 2 \, e\right ) + 4 \, {\left (a^{3} d^{2 \, n} n^{2} + 3 \, a^{3} d^{2 \, n} n + 2 \, a^{3} d^{2 \, n}\right )} 2^{n} \cos \left (-4 \, f x + n \arctan \left (\sin \left (2 \, f x + 2 \, e\right ), \cos \left (2 \, f x + 2 \, e\right ) + 1\right ) - 4 \, e\right ) - {\left (8 i \, a^{3} d^{2 \, n} n + 16 i \, a^{3} d^{2 \, n}\right )} 2^{n} \sin \left (-2 \, f x + n \arctan \left (\sin \left (2 \, f x + 2 \, e\right ), \cos \left (2 \, f x + 2 \, e\right ) + 1\right ) - 2 \, e\right ) - {\left (4 i \, a^{3} d^{2 \, n} n^{2} + 12 i \, a^{3} d^{2 \, n} n + 8 i \, a^{3} d^{2 \, n}\right )} 2^{n} \sin \left (-4 \, f x + n \arctan \left (\sin \left (2 \, f x + 2 \, e\right ), \cos \left (2 \, f x + 2 \, e\right ) + 1\right ) - 4 \, e\right )}{{\left ({\left (-i \, a^{n} n^{3} - 3 i \, a^{n} n^{2} - 2 i \, a^{n} n\right )} {\left (\cos \left (2 \, f x + 2 \, e\right )^{2} + \sin \left (2 \, f x + 2 \, e\right )^{2} + 2 \, \cos \left (2 \, f x + 2 \, e\right ) + 1\right )}^{\frac {1}{2} \, n} \cos \left (4 \, f x + 4 \, e\right ) + {\left (a^{n} n^{3} + 3 \, a^{n} n^{2} + 2 \, a^{n} n\right )} {\left (\cos \left (2 \, f x + 2 \, e\right )^{2} + \sin \left (2 \, f x + 2 \, e\right )^{2} + 2 \, \cos \left (2 \, f x + 2 \, e\right ) + 1\right )}^{\frac {1}{2} \, n} \sin \left (4 \, f x + 4 \, e\right ) + {\left (-i \, a^{n} n^{3} - 3 i \, a^{n} n^{2} - 2 i \, a^{n} n + {\left (-2 i \, a^{n} n^{3} - 6 i \, a^{n} n^{2} - 4 i \, a^{n} n\right )} \cos \left (2 \, f x + 2 \, e\right ) + 2 \, {\left (a^{n} n^{3} + 3 \, a^{n} n^{2} + 2 \, a^{n} n\right )} \sin \left (2 \, f x + 2 \, e\right )\right )} {\left (\cos \left (2 \, f x + 2 \, e\right )^{2} + \sin \left (2 \, f x + 2 \, e\right )^{2} + 2 \, \cos \left (2 \, f x + 2 \, e\right ) + 1\right )}^{\frac {1}{2} \, n}\right )} f} \]