# How to group or factor out exponential terms of an integral result

I would like to group the following integral result according to e^(r1^2+r2^2)+e^(r1^2-r2^2)+e^(r1-r2)^2. I've tried Collect, Factor, FactorTerms, doThat, Simplify...etc. but no luck.

Here is the integral

    Integrate[
E^(-((ρ1^2 + ρ2^2)/(4*σ^2)))*
E^(-((ρ2 - ρ1)^2/(2*δij^2)))*
E^((I*k)/(2*B)*(A*(ρ1^2 - ρ2^2) -
2*(r1*ρ1 - r2*ρ2) +
D*(r1^2 - r2^2))), {ρ1, -Infinity,
Infinity}, {ρ2, -Infinity, Infinity},
GenerateConditions -> False]


and the expected/simplified result is given in the below image. Also, I couldnt group the exponentials according to e^(r1^2+r2^2)+e^(r1^2-r2^2)+e^(r1-r2)^2 if the expr is written by hand like in the following:

    expr = Exp[(I*k*A)/(2*B)*(r1^2 - r2^2) - k^2/(4*p^2*B^2)*r1^2 +
1/(4*p^2)*(a*r1 - b*r2)^2]


the expected/simplified result is:

somehow they do it (dont worry about the constants out of the exponentials). Any idea? Thanks in advance.

Clear["Global*"]
expr = Integrate[
E^(-((ρ1^2 + ρ2^2)/(4*σ^2)))*
E^(-((ρ2 - ρ1)^2/(2*δij^2)))*
E^((I*k)/(2*B)*(A*(ρ1^2 - ρ2^2) -
2*(r1*ρ1 - r2*ρ2) +
D*(r1^2 - r2^2))), {ρ1, -Infinity,
Infinity}, {ρ2, -Infinity, Infinity},
GenerateConditions -> False]


To collect as desired:

expr /. Exp[a_] :> Exp[ Collect[a, {r1 - r2, r1 + r2}]] /.
Exp[Plus[a_, b_, c_]] :> Times[E[a], E[b], E[c]]


• Thank you @Nasser for the edit.
– Syed
Commented Sep 13, 2022 at 10:06
• Thank you @Syed, it works for the integral result. But, now, I couldnt group the exponentials for the hand written form like the one in the edited post. Can you help me once again? Commented Sep 13, 2022 at 11:23
• Your problem is clearly stated as far as the separation of exponential functions is concerned. Beyond that it is not easy (or at least I can't readily think of an obvious transformation). If you want someone to help you further, please load definitions of Aij, Bij, Iij, Qij, Rij. I also note that I and D` are reserved words in Mathematica.
– Syed
Commented Sep 13, 2022 at 11:39
• Everything is a constant except for r1,r2, I removed the constants from the image. I is the complex unit, I edited D to A, because I didnt know that D is reserved (thanks @Syed by the way). So, what I am trying to do is trying to get to the second line of the image from the first line by using mathematica. Commented Sep 13, 2022 at 12:07
• After @Syed pointed out the i imaginary, I noticed that I have to take it under i paranthesis. So I will delete the question and renew it. Commented Sep 15, 2022 at 5:36