Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The pdf of a half normal distribution is: $\frac{\sqrt{2}}{\sigma\sqrt{\pi}}\exp\left(-\frac{x^2}{2\sigma^2}\right)$, $x>0$


This doesn't make sense, the integral should be equal to one, right?

Mathematica code used to compute this:

Integrate[(Sqrt[2/Pi]/s)*Exp[-(x^2)/(2*s^2)], {x, 0, Infinity}, Assumptions -> Re[s^2] > 0]

What am I doing wrong?

share|improve this question

migrated from Apr 14 '14 at 5:35

This question came from our site for people studying math at any level and professionals in related fields.

And it is equal to $1$. – André Nicolas Apr 14 '14 at 3:33
See the Mathematica code I added to the question. – user142972 Apr 14 '14 at 3:48
Luckily not my problem, I can't afford Mathematica. Conceivably a bug. More likely an input typo. – André Nicolas Apr 14 '14 at 4:22

Using Assuming[Element[s, Reals] && s > 0 tells Mathematica that Re[s^2]>1 and also s itself is real to allow it to simplify final result to 1.

Mathematica did not simplify $\sqrt{\frac{1}{s^2}}$ to $\frac{1}{s}$ since it did not know if $s$ was real or not and if it was real, if it is positive or not. That is why you did not get the result 1 expected.

Assuming[Element[s, Reals] && s > 0, Integrate[(Sqrt[2/Pi]/s)*Exp[-(x^2)/(2*s^2)], 
     {x, 0, Infinity}]]

 (* 1*)
share|improve this answer
thanks this is the right answer, but for this OP, it might be helpful to provide a bit more textual explanation. – Verbeia Apr 14 '14 at 6:19

Here are some variants:

td = TruncatedDistribution[{0, Infinity}, NormalDistribution[0, s]];
Assuming[Element[s, Reals] && s > 0, 
Integrate[Sqrt[2/Pi] Exp[-x^2/(2 s^2)]/s, {x, 0, Infinity}]]
Integrate[Sqrt[2/Pi] Exp[-x^2/(2 s^2)]/s, {x, 0, Infinity}, 
 Assumptions -> {Element[s, Reals], s > 0}]
Integrate[PDF[td, x], {x, 0, Infinity}, 
 Assumptions -> {Element[s, Reals], s > 0}]
 PDF[HalfNormalDistribution[Sqrt[2/Pi]/s], x], {x, 0, Infinity}, 
 Assumptions -> {Element[s, Reals], s > 0}]

Note all the integrals yield 1. As @Nasser has observed the assumptions need to be declared.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.