## PiecewiseExpand and conditional results from Integrate

### PiecewiseExpand and conditional results from Integrate

The following are based on a recent thread.
I found it good to collect the results.
(Version 5.2 is used)
-------------------------------------------------------------

When Integrate returns conditional results (that is If[...]
structures)
it does not mean necessary that for the other values of the
parameter(s)
there is divergence or no closed form solution.
Below there is a nice example

In:=
Integrate[E^(-x^2 - x*y)/Sqrt[x], {x, 0, Infinity}]

Out=
If[Re[y] < 0, (E^(y^2/8)*Pi*Sqrt[-y]*(BesselI[-(1/4), y^2/8] +
BesselI[1/4, y^2/8]))/(2*Sqrt),
Integrate[1/(E^(x*(x + y))*Sqrt[x]), {x, 0, Infinity}, Assumptions -

At first someone might think that for Re[y]>0 there is no convergence
or closed form solution. However it is just that the integrator found
a result
which is valid for Re[y]<0. Nothing more, nothing less.
Specifying assumptions shows the situation

In:=
(Integrate[E^(-x^2 - x*y)/Sqrt[x], {x, 0, Infinity}, Assumptions ->
#1[Re[y], 0]] & ) /@ {Greater, Less}

Out=
{(1/2)*E^(y^2/8)*Sqrt[y]*BesselK[1/4, y^2/8], (E^(y^2/8)*Pi*Sqrt[-
y]*(BesselI[-(1/4), y^2/8] + BesselI[1/4, y^2/8]))/
(2*Sqrt)}

A nice application of PiecewiseExpand is given below

In:=
Integrate[E^(-x^2 - x*y)/Sqrt[x], {x, 0, Infinity}]
PiecewiseExpand[%]

Out=
If[Re[y] < 0, (E^(y^2/8)*Pi*Sqrt[-y]*(BesselI[-(1/4), y^2/8] +
BesselI[1/4, y^2/8]))/(2*Sqrt),
Integrate[1/(E^(x*(x + y))*Sqrt[x]), {x, 0, Infinity}, Assumptions -
Out=
Piecewise[{{(E^(y^2/8)*Pi*Sqrt[-y]*(BesselI[-(1/4), y^2/8] +
BesselI[1/4, y^2/8]))/(2*Sqrt), Re[y] <= 0}},
(1/2)*E^(y^2/8)*Sqrt[y]*BesselK[1/4, y^2/8]]

As another example consider

In:=
Integrate[(1 + k*Sin[a]^2)^(1/2), {a, 0, 2*Pi}, Assumptions -> k
Reals]
PiecewiseExpand[%]

Out=
If[k >= -1, 4*EllipticE[-k], Integrate[Sqrt[1 + k*Sin[a]^2], {a, 0,
2*Pi}, Assumptions -> k < -1]]
Out=
4*EllipticE[-k]

which shows that although the If structure would indicate that there
is closed form
solution valid only for k>=-1, application of PiecewiseExpand shows
that the closed
form result is valid for all real k.

Dimitris

Hi all,

I have the following query:

The two and clauses in the subquery need to be conditional.(if possible)
Only included in the select if @current_hazards = True Or @areas IS NOT NULL

If @current_hazards = False AND @areas IS NULL then both add statements are
to be ignored???

If this is possible i would appreciate any insight on how to achieve this...

Cheers,

SELECT
oce_rep_areas.oce_rep_area_id, oce_rep_areas.name
FROM
oce_rep_areas
WHERE
oce_rep_areas.oce_rep_area_id IN (
SELECT
parent
FROM
oce_rep_areas
INNER JOIN
oce_rep_items
ON
oce_rep_areas.oce_rep_area_id = oce_rep_items.oce_rep_area_id
WHERE
oce_rep_items.oce_report_id = @oceid
AND ///to bo conditional : ie add only if @hazards = True
oce_rep_items.current_hazard = True
AND //to be conditional : ie only include when @areas is not null
oce_rep_areas.oce_rep_area_id IN(@areas))