# Conditional Convolution

I was hoping to incorporate an If function into a Convolve operation, as in

Convolve[
(-E^(-2 x) + E^-x) (7 - 3 If[-E^(-2 x) + E^-x >= 0, 1, 0]) +
(-E^(-2 x) + 2 E^-x) (2 - 2 If[-E^(-2 x) + 2 E^-x >= 0, 1, 0]) +
(E^(-2 x)/4 - 2 E^-x + 1/4 (7 - 6 x + 2 x^2)) *
(3 - 2 If[E^(-2 x)/4 - 2 E^-x + 1/4 (7 - 6 x + 2 x^2) >= 0, 1, 0]) +
(150 - 100 If[(2 E^(-2 x))/5 - E^-x/2 + 1/100 (10 Cos[x] + 30 Sin[x]) >=0, 1, 0]) *
((2 E^(-2 x))/5 - E^-x/2 + 1/100 (10 Cos[x] + 30 Sin[x]))[x],
Sqrt[1/2 Pi]*Exp[-x^2/2] - 1,
x, y
]


But at each time I run the programme computer does not respond. Can you tell me if the code is correct?

I see I will try Heaviside theta function.

I mean after executing the code I waited for about 5 hours without interrupting mathematica but it did not give me any input. There was still 'Running' on the window.

• If is not a mathematical function. Try something like HeavisideTheta instead. Also, what do you mean "the computer does not respond"? Do you mean that Mathematica crashes? (Also, please note how I formatted your post. Please don't use $\TeX$ markup in place of code blocks.) – Oleksandr R. Feb 17 '15 at 10:11
• Also, your function f (the first one inside Convolve) is not defined correctly. You have a trailing [x], but the head is not a function. – Oleksandr R. Feb 17 '15 at 10:19

Your computation (even after fixing the superfluous [x] and introducing HeavisideTheta) involves amounts of memory I'd call "extreme": After 20mins, it is well beyond 11 GB, and 20 mins later the kernel crashes (in a way, see below) due to all my 32 GB of RAM (and all of pagefile space) having been consumed.

Sidenote: In the given case, Mathematica's behavior is identical for If, HeavisideTheta and UnitStep.

You cannot hope to get a result on a typical PC nowadays.

This is the code I actually used (you may also use your If-version, or UnitStep, since it makes no difference in the outcome):

f = (-E^(-2 x) + E^-x) (7 -
3 HeavisideTheta[-E^(-2 x) + E^-x]) + (-E^(-2 x) + 2 E^-x) (2 -
2 HeavisideTheta[-E^(-2 x) + 2 E^-x]) + (E^(-2 x)/4 - 2 E^-x +
1/4 (7 - 6 x + 2 x^2))*(3 -
2 HeavisideTheta[
E^(-2 x)/4 - 2 E^-x + 1/4 (7 - 6 x + 2 x^2)]) + (150 -
100 HeavisideTheta[(2 E^(-2 x))/5 - E^-x/2 +
1/100 (10 Cos[x] + 30 Sin[x])])*((2 E^(-2 x))/5 - E^-x/2 +
1/100 (10 Cos[x] + 30 Sin[x]));

g = Sqrt[1/2 Pi]*Exp[-x^2/2] - 1;

{f, g} = FullSimplify /@ {f, g};

Convolve[f, g, x, y]


Interesting to note, though, that the kernel did not crash entirely, but just stopped its activities, obviously due to running out of available memory, but did not produce either

• a result or at least
• an error message

Odd.

Here is a simple example using UnitStep to create a conditional function

h = Exp[-x] UnitStep[x] + (1 - UnitStep[x]) Exp[-2 x];
f = Exp[-2 x];
Convolve[f, h, x, y]

-E^(-2 y) - E^(-2 y) y