Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to evaluate the integral $\int_{-\infty}^\infty \mathrm{d}x \, \exp\left(- a x^2 - x^4\right)$ for any real value of $a$. Mathematica 8.0.4 gives the following result:

Integrate[Exp[- a x^2  - x^4], {x, -∞, ∞}, Assumptions -> {a ∈ Reals}]
ConditionalExpression[1/2 Sqrt[a] E^(a^2/8) BesselK[1/4, a^2/8], a >= 0]

Can I keep Mathematica from restricting its answer to non-negative values of $a$, especially since it can do the integral also for negative values:

Integrate[Exp[- a x^2  - x^4], {x, -∞, ∞}, Assumptions -> {a < 0}]
(Sqrt[-a] E^(a^2/8) π (BesselI[-(1/4), a^2/8] + BesselI[1/4, a^2/8]))/(2 Sqrt[2])

I can construct the solution for all real $a$ from these two restricted solutions using Piecewise, but I'd rather not do that.

share|improve this question
1  
Not a real solution, but if you know that conditions aren't needed, you could cheat by adding the option GenerateConditions -> False to Integrate. Then Assumptions -> {a ∈ Reals} is sufficient. –  Jens Jun 20 '13 at 22:56
    
That's good to know. Unfortunately, in this case, the condition is needed, as otherwise Mathematica returns only the solution for a>0. I don't mind (not that it would matter if I did!) that there are two separate expressions for the value of the integral for a>0 and for a<0, I just wish that Mathematica could automatically give the combined piecewise result, rather than arbitrarily choosing only the a>0 solution. –  user8153 Jun 20 '13 at 23:11
    
Even more troublesome is the situation where the solution is actually valid for all a on the real line, but mma still returns ConditionalExpression[sol, a > 0] –  wolfies Jun 21 '13 at 4:11
    
If you accept to be pragmatic, maybe define int[a_] = UnitStep[a] Integrate[Exp[-a x^2 - x^4], {x, -Infinity, Infinity}, Assumptions -> {a >= 0}] + UnitStep[-a] Integrate[Exp[-a x^2 - x^4], {x, -Infinity, Infinity}, Assumptions -> {a < 0}] ? –  b.gatessucks Jun 21 '13 at 17:14
add comment

1 Answer 1

up vote 4 down vote accepted

There's a system option, ConditionalAnswerFormat, which controls how conditional results are output. First here's a function to evaluate an expression with a temporarily different setting for ConditionalAnswerFormat:

SetAttributes[withCAF, HoldFirst];
withCAF[expr_, caf_] :=
 Module[{originalCAF, result},
  originalCAF = SystemOptions[ConditionalAnswerFormat];
  SetSystemOptions[ConditionalAnswerFormat -> caf];
  result = expr;
  SetSystemOptions[originalCAF];
  result]

If you use If as the setting, Mathematica will output conditional results in an If statement (I think this is what used to happen before version 8):

Integrate[Exp[-a x^2 - x^4], {x, -\[Infinity], \[Infinity]}, 
 Assumptions -> {a \[Element] Reals}] ~withCAF~ If

enter image description here

As pointed out in the question, Mathematica can actually do the unevaluated integral. You can just copy and paste it into an input cell and get a result:

Integrate[E^(-x^2 (a + x^2)), {x, -\[Infinity], \[Infinity]}, 
 Assumptions -> a \[Element] Reals && a < 0]

enter image description here

Of course the integral didn't get evaluated inside the If statement because If has the HoldRest attribute. So what if we use a setting for ConditionalAnswerFormat which evaluates the results before feeding them to If, and then applies a PiecewiseExpand. This can be done easily with a Composition:

Integrate[Exp[-a x^2 - x^4], {x, -\[Infinity], \[Infinity]}, 
 Assumptions -> {a \[Element] Reals}] ~withCAF~ Composition[PiecewiseExpand, If]

enter image description here

share|improve this answer
    
The value of the integral should be 1/2 Gamma[1/4] at zero, but I don't think your final result gives that. I think it's indeterminate at zero. –  m_goldberg Jun 22 '13 at 12:04
    
@m_goldberg That's also an issue with the original ConditionalExpression result. You can use Limit to get the correct result at a=0. –  Simon Woods Jun 22 '13 at 13:04
    
I did use Limit; that's how I know what the value of zero should be. –  m_goldberg Jun 22 '13 at 13:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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