# Incorrect evaluation of a convolution

I want to evaluate a convolution for a stripe function and a Gaussian:

stripe[x_, d_] := If[EvenQ[Quotient[x, d]], 1, 0]
gaussian[x_, μ_, σ_] = 1/(Sqrt[2 π] σ) Exp[-((x - μ)^2/(2 σ^2))];
Plot[{stripe[τ, 1], gaussian[τ, 0, 0.5]}, {τ, -10, +10}]


Then, the convolution I want to evaluate is:

Convolve[UnitStep[τ + 5] stripe[τ, 1] UnitStep[5 - τ], gaussian[τ, 0, 0.5], τ, x]


the result was 0, although it should not be 0.

I also tried to evaluate it via Integrate:

Integrate[stripe[τ, 1] gaussian[x - τ, 0, 0.5], {τ, -5, +5}]


the result was 0 again.

I don't know why the results were zero. Does the complication of the stripe function cause this problem? How can I evaluate it correctly?

That does not explain why your solution does not work (I'm pretty sure it is because of your definition of stripe), but if you replace stripe with:

stripe[x_, d_] := HeavisidePi[Mod[x/(2 d), 1]]


you get:

conv[x_] = Convolve[UnitStep[tau + 5] stripe[tau, 1] UnitStep[5 - tau],
gaussian[tau, 0, 0.5], tau, x]

(* -0.5 (1. Erf[2.82843 - 1.41421 x] + 1. Erf[5.65685 - 1.41421 x] +
Erf[1.41421 (-5. + x)] + Erf[1.41421 (-3. + x)] +
Erf[1.41421 (-1. + x)] - 1. Erf[1.41421 x] +
Erf[1.41421 + 1.41421 x] - 1. Erf[2.82843 + 1.41421 x] +
Erf[4.24264 + 1.41421 x] - 1. Erf[5.65685 + 1.41421 x]) *)

Plot[conv[x], {x, -10, 10}]


With x and d not numeric:

If[EvenQ[Quotient[x, d]], 1, 0]
(* 0 *)


The essential difficulty is using programming constructs If and EvenQ to formulate a symbolic analysis problem.

• Since I used SetDelayed(:=) to define the stripe function, the right hand side must be evaluated for a specific x and d every time. In spite of this, why is it a problem? – Taiki Bessho Jan 4 '18 at 20:10
• @TaikiBessho No. If you want to define stripe only for numerical values, try stripe[x_?NumericQ, d_?NumericQ] := ... in what case, Convolve does not return 0 (it just does not evaluate). – anderstood Jan 4 '18 at 20:27
• I understood the root of this problem is that both Convolve and Integrate try to evaluate it not numerically but analytically where stripe[τ, 1] is zero identically because Quotient remains unevaluated, EvenQ gives False and If returns 0. Is this what you wanted to say? – Taiki Bessho Jan 5 '18 at 3:47
• @anderstood Why does the Convolve remain unevaluated if we define the stripe numerically? Doesn't the built-in function Convolve take numerical functions as arguments? – Taiki Bessho Jan 5 '18 at 4:13
• @TaikiBessho Convolve works purely symbolically, essentially by calling Integrate to solve the convolution integral. This won't work for functions that only return values for numerical input (i.e. stay unevaluated for symbolic input), because Integrate can't do anything meaningful with those intransparent functions. – Thies Heidecke Jan 5 '18 at 11:25