# How can I assign first evaluate an Integrate command and then assign the integrated expression to a function?

I am trying to evaluate this integral?

$$\int_0^1\int_0^1 \frac{\mathrm dt\mathrm ds}{(c^2 + 2se + as^2 - 2tf - 2tsd + bt^2)^2}$$

I tried to do using the definite integral, but these two didn't converge:

Integrate[
1/(c^2 + 2*s*e + a*s^2 - 2*t*f - 2*s*t*d + b*t^2)^2, {s, 0, 1}, {t,
0, 1}, Assumptions -> Element[a, Reals],
Assumptions -> Element[e, Reals], Assumptions -> Element[d, Reals],
Assumptions -> Element[b, Reals], Assumptions -> Element[f, Reals]]


and

Integrate[Integrate[
1/(c^2 + 2*s*e + a*s^2 - 2*t*f - 2*s*t*d + b*t^2)^2, {s, 0, 1},
Assumptions -> Element[a | e | d | f | b, Reals]], {t, 0, 1},
Assumptions -> Element[a | e | d | f | b, Reals]]


But if I do:

Integrate[
Integrate[1/(c^2 + 2*s*e + a*s^2 - 2*t*f - 2*s*t*d + b*t^2)^2, s,
Assumptions -> Element[a | e | d | f | b, Reals]], t,
Assumptions -> Element[a | e | d | f | b, Reals]]


surprisingly, it works very fast and this is the result:

(((-b (e + a s) + d (f + d s)) ArcTan[(f + d s - b t)/
Sqrt[-(f + d s)^2 + b (c^2 + 2 e s + a s^2)]])/Sqrt[-(f + d s)^2 +
b (c^2 + 2 e s + a s^2)] + ((d e - a f + a b t - d^2 t) ArcTan[(
e + a s - d t)/
Sqrt[-(e - d t)^2 + a (c^2 - 2 f t + b t^2)]])/Sqrt[-(e - d t)^2 +
a (c^2 - 2 f t + b t^2)])/(2 (c^2 d^2 + e (b e - 2 d f) +
a (-b c^2 + f^2)))


Now, how can I assign the indefinite integral expression into a function and evaluate it at 0 and 1 using Mathematica?

F[s_, t_] :=
Integrate[
Integrate[1/(c^2 + 2*s*e + a*s^2 - 2*t*f - 2*s*t*d + b*t^2)^2, s,
Assumptions -> Element[a | e | d | f | b, Reals]], t,
Assumptions -> Element[a | e | d | f | b, Reals]] // FullSimplify


Doesn't actually evaluate the integral upon declaration. How can I feed Integrate into a function.

• Multiple Assumptions options are not going to work. I'm not really giving high hopes on improving calculation time, but I'd suggest writing this as Integrate[1/(c^2 + 2*s*e + a*s^2 - 2*t*f - 2*s*t*d + b*t^2)^2, {s, 0, 1}, {t, 0, 1}, Assumptions -> Element[a | b | d | e | f, Reals]]. (You could also group them as Element[a, Reals] && Element[b, Reals] && ....) Did you possibly forget to include c in the assumptions? Sep 18, 2018 at 15:18
• @kirma doesn't finish without the assumptions either.
– 0x90
Sep 18, 2018 at 15:22
• What does "doesn't finish" mean? Not all integrals, especially complicated symbolic ones, can be calculated in an instant (if at all).
– ktm
Sep 18, 2018 at 15:23
• I would guess complete assumptions could actually speed up the operation. Your variant of listing multiple Assumptions options is going to cause Integrate pick only one of them. Sep 18, 2018 at 15:27
• Try your integral in Rubi. Perhaps that can solve it.
– ktm
Sep 18, 2018 at 15:28

I use Rule-based Integration aka: Rubi from here:

<<Rubi (*Load package*)

s1 = Int[1/(c^2 + 2*s*e + a*s^2 - 2*t*f - 2*s*t*d + b*t^2)^2, t]
s2 = Limit[s1, t -> 1] - Limit[s1, t -> 0] // Simplify
(*I assumed the original function is continuous*)

s3= Int[s2, s]

s4 = Limit[s3, s -> 1, Assumptions -> {e > 0, c > 0, a > 0, f > 0, d > 0, b > 0}] - Limit[s3, s -> 0,
Assumptions -> {e > 0, c > 0, a > 0, f > 0, d > 0, b > 0}]
(*I assumed the original function is continuous. *)

(*Warning!!! See restrictions about parameters ? *)

s5 = s4[[1]] // Simplify
(* Solution *)


Formula for:

$e > 0, c > 0, a > 0, f > 0, d > 0, b > 0$

and

$-1<\frac{(b e-d f) \Im\left(\frac{1}{\sqrt{a b c^2-c^2 d^2-b e^2+2 d e f-a f^2}}\right)}{\sqrt{b}}<1\land b c^2>f^2\land (d+f)^2<b \left(a+c^2+2 e\right)$

SOL[a_, c_, e_, f_, d_, b_] := (1/(2 (a b c^2 - c^2 d^2 - b e^2 + 2 d e f -
a f^2)))(((d e - a f) ArcTan[e/Sqrt[a c^2 - e^2]])/Sqrt[
a c^2 - e^2] + ((-d e + a f) ArcTan[(a + e)/Sqrt[a c^2 - e^2]])/
Sqrt[a c^2 -
e^2] + ((d (-d + e) + a (b - f)) ArcTan[(d - e)/
Sqrt[-(d - e)^2 + a (b + c^2 - 2 f)]])/
Sqrt[-(d - e)^2 +
a (b + c^2 - 2 f)] + ((d (d - e) + a (-b + f)) ArcTan[(-a + d - e)/
Sqrt[-(d - e)^2 + a (b + c^2 - 2 f)]])/
Sqrt[-(d - e)^2 +
a (b + c^2 - 2 f)] + ((-b e + d f) ArcTan[(b - f)/Sqrt[
b c^2 - f^2]])/Sqrt[
b c^2 - f^2] + ((-b e + d f) ArcTan[f/Sqrt[b c^2 - f^2]])/Sqrt[
b c^2 - f^2] + ((a b - d^2 + b e -
d f) (ArcTan[(b - d - f)/Sqrt[b (a + c^2 + 2 e) - (d + f)^2]] +
ArcTan[(d + f)/Sqrt[b (a + c^2 + 2 e) - (d + f)^2]]))/Sqrt[
a b + b (c^2 + 2 e) - (d + f)^2]);


At first we must check restrictions:

-1 < ((b e - d f) Im[1/Sqrt[a b c^2 - c^2 d^2 - b e^2 + 2 d e f - a f^2]])/Sqrt[b] < 1 &&
b c^2 > f^2 && (d + f)^2 < b (a + c^2 + 2 e) /. {a -> 1, c -> 2, e -> 1, f -> 2, d -> 1, b -> 2}
(*True *)(*OK*)


If false then forumla gives complex number (Wrong answer!).

then:

 F[a_, c_, e_, f_, d_, b_] := NIntegrate[1/(c^2 + 2*s*e + a*s^2 - 2*t*f - 2*s*t*d + b*t^2)^2, {t, 0, 1}, {s, 0, 1}]
F[1, 2, 1, 2, 1, 2]
(* 0.105123 *)

SOL[1, 2, 1, 2, 1, 2] // N
(* 0.105123 *)


Works as should it.

For some values use Limit,because formula gives Power::infy: Infinite expression 1/0 encountered

At first check restrictions about parameters:

 1 < ((b e - d f) Im[1/Sqrt[a b c^2 - c^2 d^2 - b e^2 + 2 d e f - a f^2]])/Sqrt[b] <
1 && b c^2 > f^2 && (d + f)^2 < b (a + c^2 + 2 e) /. {a -> 1, e -> 1, f ->
1, d -> 1, b -> 2}

(*-1 < Im[1/Sqrt[-1 + c^2]]/Sqrt[2] < 1 && 2 c^2 > 1 && 4 < 2 (3 + c^2)*)

Limit[Im[1/Sqrt[-1 + c^2]]/Sqrt[2], c -> 1, Direction -> -1]
(* 0 *)
-1 < 0 < 1 && 2 c^2 > 1 && 4 < 2 (3 + c^2) /. c -> 1
(*True*)

F[1, 1, 1, 1, 1, 2]
(* 0.803374 *)
SOL[1, 1, 1, 1, 1, 2](* errors *)

Limit[SOL[1, c, 1, 1, 1, 2], c -> 1] // N
(* 0.803374 *)


Bonus Extra:

With a small changes:

s4 = Limit[s3, s -> 1, Assumptions -> {e ∈ Reals, c ∈ Reals, a ∈ Reals, f ∈ Reals, d ∈ Reals, b ∈ Reals}]-
Limit[s3, s -> 0, Assumptions -> {e ∈ Reals, c ∈ Reals, a ∈ Reals, f ∈ Reals,
d ∈ Reals,b ∈ Reals}]//Simplify
(* solution *)

SOL2[a_, c_, e_, f_, d_, b_] := (1/(
2 (a b c^2 - c^2 d^2 - b e^2 + 2 d e f -
a f^2)))(((d e - a f) ArcTan[e/Sqrt[a c^2 - e^2]])/Sqrt[
a c^2 - e^2] + ((-d e + a f) ArcTan[(a + e)/Sqrt[a c^2 - e^2]])/
Sqrt[a c^2 -
e^2] + ((d (-d + e) + a (b - f)) ArcTan[(d - e)/
Sqrt[-(d - e)^2 + a (b + c^2 - 2 f)]])/
Sqrt[-(d - e)^2 +
a (b + c^2 - 2 f)] + ((d (d - e) + a (-b + f)) ArcTan[(-a + d -
e)/Sqrt[-(d - e)^2 + a (b + c^2 - 2 f)]])/
Sqrt[-(d - e)^2 +
a (b + c^2 - 2 f)] + ((-b e +
d f) (ArcTan[(b - f)/Sqrt[b c^2 - f^2]] +
ArcTan[f/Sqrt[b c^2 - f^2]]))/Sqrt[
b c^2 - f^2] + ((a b - d^2 + b e -
d f) (ArcTan[(b - d - f)/Sqrt[
a b + b (c^2 + 2 e) - (d + f)^2]] +
ArcTan[(d + f)/Sqrt[a b + b (c^2 + 2 e) - (d + f)^2]]))/Sqrt[
a b + b (c^2 + 2 e) - (d + f)^2]);


$$\int _0^1\int _0^1\frac{1}{\left(c^2+2 s e+a s^2-2 t f-2 s t d+b t^2\right)^2}dtds=\\\frac{\frac{(d e-a f) \tan ^{-1}\left(\frac{e}{\sqrt{a c^2-e^2}}\right)}{\sqrt{a c^2-e^2}}+\frac{(-d e+a f) \tan ^{-1}\left(\frac{a+e}{\sqrt{a c^2-e^2}}\right)}{\sqrt{a c^2-e^2}}+\frac{(d (-d+e)+a (b-f)) \tan ^{-1}\left(\frac{d-e}{\sqrt{-(d-e)^2+a \left(b+c^2-2 f\right)}}\right)}{\sqrt{-(d-e)^2+a \left(b+c^2-2 f\right)}}+\frac{(d (d-e)+a (-b+f)) \tan ^{-1}\left(\frac{-a+d-e}{\sqrt{-(d-e)^2+a \left(b+c^2-2 f\right)}}\right)}{\sqrt{-(d-e)^2+a \left(b+c^2-2 f\right)}}+\frac{(-b e+d f) \left(\tan ^{-1}\left(\frac{b-f}{\sqrt{b c^2-f^2}}\right)+\tan ^{-1}\left(\frac{f}{\sqrt{b c^2-f^2}}\right)\right)}{\sqrt{b c^2-f^2}}+\frac{\left(a b-d^2+b e-d f\right) \left(\tan ^{-1}\left(\frac{b-d-f}{\sqrt{a b+b \left(c^2+2 e\right)-(d+f)^2}}\right)+\tan ^{-1}\left(\frac{d+f}{\sqrt{a b+b \left(c^2+2 e\right)-(d+f)^2}}\right)\right)}{\sqrt{a b+b \left(c^2+2 e\right)-(d+f)^2}}}{2 \left(a b c^2-c^2 d^2-b e^2+2 d e f-a f^2\right)}$$

Formula for:

$\{e\in \mathbb{R},c\in \mathbb{R},a\in \mathbb{R},f\in \mathbb{R},d\in \mathbb{R},b\in \mathbb{R}\}$

with restrictions:

$b c^2-f^2>0\land (d+f)^2<b \left(a+c^2+2 e\right)$

Reduce[b c^2 > f^2 && (d + f)^2 < b (a + c^2 + 2 e)]
`

$$(d|e|f)\in \mathbb{R}\land \left(\left(c<0\land b>\frac{f^2}{c^2}\land a>\frac{-b c^2-2 b e+d^2+2 d f+f^2}{b}\right)\lor \left(c>0\land b>\frac{f^2}{c^2}\land a>\frac{-b c^2-2 b e+d^2+2 d f+f^2}{b}\right)\right)$$