How can I get the expected results of 2 from this integral?

Assuming[{U, k} \[Element] Reals && k > 0, (
    2 (U Exp[\[ImaginaryJ] k x])^2, {x, -\[Infinity], \[Infinity]}] //
  Integrate[(U Exp[\[ImaginaryJ] k x])^2, {x, -\[Infinity], \
\[Infinity]}] // HoldForm) // FullSimplify]
  • $\begingroup$ The integral $\int_{-\infty }^{\infty } e^{2 i k x} \, dx$ diverges and Matematica reports it. In view of it I find the question meaningless. $\endgroup$
    – user64494
    Jan 8, 2022 at 5:35
  • $\begingroup$ As the integral diverges, you have Infinity/Infinity what is not defined. The best you can do is to take the definite integral from -a to a and take the limit a->Infinity. $\endgroup$ Jan 8, 2022 at 10:15
  • $\begingroup$ @DanielHuber: Its Cauchy pprincipal value does not exists as Limit[Integrate[(Exp[\[ImaginaryJ] k x])^2, {x, -a, a}, Assumptions -> a > 0], a -> Infinity] produces and the same with the denominator. $\endgroup$
    – user64494
    Jan 8, 2022 at 17:10
  • 2
    $\begingroup$ @user64494, I interpreted the question differently: Why do the integrals not cancel no matter what the integrand is? In any case, due to HoldForm the integral does not evaluate at all. The issue then is, how to pull 2 from within Integrate in the numerator, and then how to convince Mathematica to cancel the two identical expressions. Experienced users of this site know what to do, but it is not surprising that those less experienced do not. By the way, it took me a few minutes to realize that HoldForm needed to be replaced by Unevaluated. $\endgroup$
    – bbgodfrey
    Jan 8, 2022 at 18:30
  • $\begingroup$ @bbgodfrey Thank you, your comment and answer are very helpful. $\endgroup$ Jan 10, 2022 at 4:01

1 Answer 1


A transformation function must be defined to extract the leading number from within Integrate. Also, HoldForm should be replaced by Unevaluated.

tf[e_] := e /. Integrate[Times[n_?NumericQ, z1__], z2_] :> n Integrate [z1, z2]

Assuming[{U, k} ∈ Reals && k > 0, (
    (Integrate[2 (U Exp[ k x])^2, {x, -∞, ∞}] // Unevaluated)/
    (Integrate[(U Exp[ k x])^2, {x, -∞, ∞}] // Unevaluated)) // 
    FullSimplify[#, TransformationFunctions -> {Automatic, tf}] &]
(* 2 *)
  • 1
    $\begingroup$ TransformationFunctions seems to be a very useful function that I do not know previously. Thank you for the answer. $\endgroup$ Jan 10, 2022 at 4:08
  • 1
    $\begingroup$ @bakerryd123, Check out the ComplexityFunction option too. Best wishes. $\endgroup$
    – bbgodfrey
    Jan 10, 2022 at 5:26
  • $\begingroup$ Nice suggestion, thanks! $\endgroup$ Jan 10, 2022 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.