# Why this error?

f[x_] := Piecewise[{{1, -0.5 <= x <= 0.5}}, 0];
ProbabilityDistribution[
Integrate[f[a], {a, x - 0.5, x + 0.5}], {x, -2, 2}]


output: "Unable to prove that integration limits {-(1/2)+x,1/2+x} are real. \ Adding assumptions may help. !(*ButtonBox[\">>\", Appearance->{Automatic, None}, BaseStyle->\"Link\", ButtonData:>\"paclet:ref/Integrate\", ButtonNote->\"Integrate::pwrl\"])"

Assumptions is an option to Integrate. The message is telling you to add the assumption that x is real (by default, variables are usually treated as complex).

f[x_] := Piecewise[{{1, -1/2 <= x <= 1/2}}, 0];
ProbabilityDistribution[
Integrate[f[a], {a, x - 1/2, x + 1/2},
Assumptions -> x ∈ Reals], {x, -2, 2}]


For this simple example one could also use

ProbabilityDistribution[
Integrate[UnitBox[a], {a, x - 1/2, x + 1/2},
Assumptions -> x ∈ Reals], {x, -2, 2}]


or

TriangularDistribution[{-1, 1}]


(in case that helps).