# Pull Constants outside of integrals

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.

• Could you give good Mathematica code for a perhaps simpler example? – David Park Aug 5 '13 at 23:42

## 1 Answer

OK, here is an example that is close to yours. Again I am going to use the Presentations Application, which I sell, because it has the ability to manipulate separable integrals before evaluation.

step0 = Integrate[\[Lambda]1 a[s,
1] (x + Integrate[\[Lambda]2 a[u, 0], {u, s, t}]), {s, 0,
t}] //. Integrate[q_*r_, {v_, l_, h_}] /; FreeQ[r, v] :>
r*Integrate[q, {v, l, h}]


The repeated use of the rule does not completely breakout the integral. Here are the steps using Presentations. The integrate command is like Integrate but does not evaluate.

<< Presentations

step1 = integrate[\[Lambda]1 a[s,
1] (x + integrate[\[Lambda]2 a[u, 0], {u, s, t}]), {s, 0, t}]
step2 = step1 // OperateIntegrand[Expand]
step3 = step2 // BreakoutIntegral // OperateIntegrand[Expand]
step4 = step3 // BreakoutIntegral    That completely breaks out the integral as you wished. Now, just for fun, let's substitute some explicit values for the a functions and evaluate. UseIntegrate[] invokes the regular Mathematica Integrate command (one could also use a specialized table of integrals). Assumption can be placed in the UseIntegrate[assumptions] statement so you don't have to put them in at the beginning and destroy the formatting of Integrate.

step5 = step4 /. {a[s, 1] -> s^2, a[u, 0] -> u}
step6 = step5 // UseIntegrate[] // UseIntegrate[]
`  