Subtract a constant or another NormalDist instance. If *other* is a constant, translate by the constant mu, leaving sigma unchanged. If *other* is a NormalDist, subtract the means and add the variances. Mathematically, this works only if the two distributions are
(x1, x2)
| 1383 | return NormalDist(x1._mu + x2, x1._sigma) |
| 1384 | |
| 1385 | def __sub__(x1, x2): |
| 1386 | """Subtract a constant or another NormalDist instance. |
| 1387 | |
| 1388 | If *other* is a constant, translate by the constant mu, |
| 1389 | leaving sigma unchanged. |
| 1390 | |
| 1391 | If *other* is a NormalDist, subtract the means and add the variances. |
| 1392 | Mathematically, this works only if the two distributions are |
| 1393 | independent or if they are jointly normally distributed. |
| 1394 | """ |
| 1395 | if isinstance(x2, NormalDist): |
| 1396 | return NormalDist(x1._mu - x2._mu, hypot(x1._sigma, x2._sigma)) |
| 1397 | return NormalDist(x1._mu - x2, x1._sigma) |
| 1398 | |
| 1399 | def __mul__(x1, x2): |
| 1400 | """Multiply both mu and sigma by a constant. |