# Keeping Integrate from making unnecessary assumptions

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.

-
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

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},
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


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]


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]


-
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