How to integrate $\int \frac{\cos^m x}{\cos nx} \,\mathrm{d}x$ How to integrate $$\int \frac{\cos^m x}{\cos nx} \,\mathrm{d}x$$
Motivation: $\int \cos mx \sec nx \,\mathrm{d}x $ and $ \int \cos mx\sec^n x\,\mathrm{d}x $ and  $\int \cos^m x \cos nx \,\mathrm{d}x $ and $\int \cos mx \cos nx \,\mathrm{d}x$ are all integrals with closed forms (including summations) I've solved myself or read elsewhere.
Plugging various $m,n$ into wolfram shows the antiderivative always has a combination of trig functions and $\tanh^{-1}$. Nothing I've tried has worked or even simplified it.
 A: HINT
Let $y=\cos(x),$ then
$$\frac{\cos^m x}{\cos nx} = \frac{(\cos x)^m}{T_n(\cos x)} = f(\cos x),$$
where $T_n(y)$ are the Chebyshev's polynomials of the first kind.
If $m\ge n$ it is necessary to single out an integer part of the ratio of polynomials.
Let 
$$g_{n-1}(y) = y^m\bmod T_n(y),\quad h(y) = f(y) - g_{n-1}(y),$$
then 
$$f(y) = r(y) + h(y),$$
where 
$$r(y) = \frac{g_{n-1}(y)}{T_n(y)},$$
$h(y)$ are polynomial of $y$ or zero, and $g_{n-1}(y)$ is polynomial of order $(n-1)$ or less.
Then,
$$T_n(y) = 2^n\prod_{k=1}^n (y-y_{n,k}),$$
where
$$y_{n,k} = \cos\left|\frac{2k-1}{2n}\right|.$$
So
$$r(y) = \frac {g_{n-1}(y)}{2^n \prod_{k=1}^n (y-y_{n,k})} = \sum_\limits{k=1}^n \frac{a_k}{y-y_{n,k}},$$
and
$$a_k = \lim_{y\to y_{n,k}}r(y)(y-y_{n,k}).$$
In this way,
$$\int\frac{\cos^m(x)}{\cos nx}\,dx = \sum_{k=1}^n a_k\int\frac{dx}{\cos x - y_{n,k}} + \int h(\cos x)\,dx,$$
where $h(y)$ is the polynomial, and the integrals under the sum can be calculated using the universal trig substitution.
A: The integral evaluates to the elementary close-form below
\begin{align}
\int \frac{\cos^m x}{\cos nx} \,{d}x
=\frac1{2n}\sum_{k=1}^n (-1)^{n+m+k} \cos^m a_k \ 
\ln\frac{1+\cos(x-a_k)}{1+\cos(x+a_k)}\tag1
\end{align}
with $a_k= \frac{(2k-1)\pi}{2n}$. To derive, note that the denominator factorizes as
$$\cos nx = {2^{n-1}}\prod_{k=1}^n 
(\cos x +\cos a_k)
$$
which, for $m<n$, allows the partial decomposition of the integrand below
\begin{align}
\frac{\cos^m x}{\cos nx} \,{d}x
=& \ \frac1n \sum_{k=1}^n \frac{(-1)^{n+m+k} \cos^m a_k \sin a_k}{\cos x +\cos a_k}
\end{align}
Integrate the above summation piecewise to obtain the close-form (1).
A: Let's note first of all, that the integrand function
$f(x)=\cos ^{\,m} x/\cos nx$ is periodic with period $2\pi$ for $n$  integer,
and that it has simple poles in $x_{\,p}  =  (2k+1)/(2n) \pi $ (for $n \neq 0$), of which
only those at  $(2k+1)/2 \pi $ are cancelled if $1 \leqslant m$.
That means that at the non-vanishing poles the integral will presents log-order spikes.
In the complex field $f(z)$ is a meromorphic function, so its series expansion will converge in every circle not including the poles.
Moreover $\cos{z}$ is an even function and so is $f(z)$.
Let's take $m$ and $n$ to be integers, which simplifies the handling of complex exponentiation ($\exp(z)^m = \exp(mz)$ ).
Since $\cos(nx)=\cos(-nz)$, $n$ can be taken  to have non-negative values.
That premised, let's rewrite the integrand as
$$
\eqalign{
  & {{\cos ^{\,m} z} \over {\cos n\,z}}\quad \left| \matrix{
  \,{\rm integers}\,m,n \hfill \cr 
  \;z  \in \mathbf{C}\; \hfill \cr}  \right.\quad  = {{\cos ^{\,m} \left( { \pm z} \right)} \over {\cos \left( { \pm n\,z} \right)}} =   \cr 
  &  = {{\left( {e^{\,i\,z}  + e^{\, - \,i\,z} } \right)^{\,m} } \over {2^{\,m - 1} \left( {e^{\,i\,n\,z}  + e^{\, - \,i\,n\,z} } \right)}} = {{\left( {1 + e^{\,i\,2\,\,z} } \right)^{\,m} } \over {2^{\,m - 1} e^{\,\,i\,\left( {m - n} \right)\,z} \left( {1 + e^{\,\,i\,2n\,z} } \right)}} =   \cr 
  &  = {{e^{\,\,i\,\left( {n - m} \right)\,z} \left( {1 + e^{\,i\,2\,\,z} } \right)^{\,m} } \over {2^{\,m - 1} \left( {1 + e^{\,\,i\,2n\,z} } \right)}} =   \cr 
  & {\rm (with}\,{\rm the}\,{\rm premised}\,{\rm conditions}\,{\rm for}\,{\rm convergence)} =   \cr 
  &  = {{e^{\,\,i\,\left( {n - m} \right)\,z} } \over {2^{\,m - 1} \left( {1 + e^{\,\,i\,2n\,z} } \right)}}\sum\limits_{0\, \le \,k\,\left( { \le \,m} \right)} {\left( \matrix{
  m \cr 
  k \cr}  \right)e^{\,i\,2\,k\,z} }  =   \cr 
  &  = {{e^{\,\,i\,\left( {n - m} \right)\,z} } \over {2^{\,m - 1} }}\sum\limits_{0\, \le \,j\,} {\left( { - 1} \right)^j e^{\,i\,2\,j\,n\,z} \sum\limits_{0\, \le \,k\,\left( { \le \,m} \right)} {\left( \matrix{
  m \cr 
  k \cr}  \right)e^{\,i\,2\,k\,z} } }  \cr} 
$$
Therefore:
$$ \bbox[lightyellow] {  
\eqalign{
  & \int {{{\cos ^{\,m} z} \over {\cos n\,z}}dz} \quad \left| \matrix{
  \,{\rm integers}\,m,n \hfill \cr 
  \;z \in \mathbf{C}\;\backslash \left\{ {{{\left( {2k + 1} \right)} \over {2n}}\pi ,0} \right\} \hfill \cr}  \right.\quad  =   \cr 
  &  = {{e^{\,\,i\,\left( {n - m} \right)\,z} } \over {i\,2^{\,m - 1} }}\sum\limits_{0\, \le \,k\,\left( { \le \,m} \right)} {\left( \matrix{
  m \cr 
  k \cr}  \right)e^{\,i\,2\,k\,z} \sum\limits_{0\, \le \,j\,} {{{\left( { - 1} \right)^j } \over {\left( {2k + 2j\,n + n - m} \right)}}e^{\,i\,2\,j\,n\,z} } }  =   \cr 
  &  = {{e^{\,\,i\,\left( {n - m} \right)\,z} } \over {i\,2^{\,m - 1} }}\sum\limits_{0\, \le \,k\,\left( { \le \,m} \right)} {\left( \matrix{
  m \cr 
  k \cr}  \right){{e^{\,i\,2\,k\,z} } \over {\left( {2k + n - m} \right)}}{}_2F_{\,1} \left( {1,{{2k + n - m} \over {2\,n}};\;{{2k + n - m} \over {2\,n}} + 1;\; - e^{\,i\,2\,n\,z} } \right)}  \cr} 
}$$
where the replacement of the sum in $j$ with the Gaussian hypergeometric function
comes from the fact that the ratio of two consecutive summands gives:
$$
{{{{\left( { - 1} \right)^{\left( {j + 1} \right)} } \over {\left( {2k + 2\left( {j + 1} \right)\,n + n - m} \right)}}e^{\,i\,2\,\left( {j + 1} \right)\,n\,z} } \over {{{\left( { - 1} \right)^j } \over {\left( {2k + 2j\,n + n - m} \right)}}e^{\,i\,2\,j\,n\,z} }} = {{j + \left( {{{2k + n - m} \over {2\,n}}} \right)} \over {j + \left( {{{2k + n - m} \over {2\,n}} + 1} \right)}}\left( { - e^{\,i\,2\,n\,z} } \right)
$$
