I would like Mathematica to pull constants outside of an integral: e.g., $\int_0^t f[t] g[s] dt \to g[s] \int_0^t f[t] dt$ This has previously been discussed at
replacement rule to pull independent expression outside of Integrate
but the solution does not seem to work for me. My code starts as follows:
ϕ[t_, n_, λ_] = -a[t, n] (λ^2 + I λ);
The next line I write in LaTeX because the mathematica code would not be readable
$ \text{$\Phi $op}[\text{n$\_$},\text{s$\_$},\text{t$\_$},\text{x$\_$},\lambda \_,\text{f$\_$}]\text{:=}\text{FullSimplify}\left[\frac{\phi [s,n,\lambda ]D\left[f \,\text{Exp}\left[i \lambda x +\int_s^t \phi [u,0,\lambda ] \, du\right],\{\lambda ,n\}\right]}{\text{Exp}\left[i \lambda x + \int_s^t \phi [u,0,\lambda ] \, du\right]}\right] $
If I type
Φop[1, s, t, x, λ, 1]
and shift + Enter then Mathematica returns
$ (1-i \lambda ) \lambda a[s,1] \left(x-i \int_s^t -(i+2 \lambda ) a[u,0] \, du\right) $
which is correct, but I want to pull out everything in the integral that does not depend on the variable of integration. So I try
Φop[1, s, t, x, λ, 1] /.
Integrate[q_*r_, {v_, l_, h_}] /; FreeQ[r, v] :> r*Integrate[q, {v, l, h}]
which returns
$ (1-i \lambda ) \lambda a[s,1] \left(x-i (-i-2 \lambda ) \int_s^t a[u,0] \, du\right) $
Okay, good. This is what I want.
But, now is where I have difficulties. I need to compute
Integrate[Φop[1, s, t, x, λ, 1], {s, 0, t}]
But, I want to get pull everying out of the iterated integral that does not depend on the vaiables of integration, so I try
Integrate[Φop[1, s, t, x, λ, 1] (...) , {s, 0, t}] (...)
where "(...)" I put
/. Integrate[q_*r_, {v_, l_, h_}] /; FreeQ[r, v] :> r*Integrate[q, {v, l, h}]
and Mathematica returns
$ (1-i \lambda ) \lambda \int_0^t a[s,1] \left(x-i (-i-2 \lambda ) \int_s^t a[u,0] \, du\right) \, ds $
I cannot figure out how to get Mathematica to pull the factors $i (-i-2 \lambda )$ and $x$ outside of the outer integral.