I want to calculate the Principal Value Integral of
$$ \int_a^\infty dx \frac{f(x)}{(x-b)^n}, $$
where $b$ is in the integration region. For the case $ n=1 $ I do know the trick
$$ \int_a^\infty dx\frac{f(x)}{x-b} = \int_a^\infty dx \frac{f(x)-f(b)}{x-b} + \int_a^\infty dx \frac{f(b)}{x-b}, $$ where after the trick the first part is numerically stable and the second part can be integrated analytically.
How can I extend this trick for higher $n$?
It might be difficult to come up with a solution for a general $f(x)$ and $n$ without implementing a QAWC adaptive integration for Cauchy principal values, using $$ I =\int_a^b dx \frac{f(x)}{x-c} = \lim_{\epsilon\rightarrow0}\bigg(\int_a^{c-\epsilon} dx \frac{f(x)}{x-c}+\int_{c+\epsilon}^{b} dx \frac{f(x)}{x-c} \bigg) $$
You can also experiment with the ‘cauchy’ weight for the quadrature. As an example consider the following for $f(x)=\cos(x)$. I used this example since I know the analytical solution.
In principle this should work for any $n$ but you have to tweak the numerical parameters.
plot