Sum of continuous random variables

18 views
Skip to first unread message

EKW

unread,
Oct 7, 2017, 8:46:34 PM10/7/17
to sympy
Consider:

```
>>> from sympy import *
>>> from sympy.stats import *
>>> t = Symbol('t')
>>> n = Uniform('n', 0, 1)
>>> print(density(n + n)(t))
Piecewise((1, (0 <= t/2) & (t/2 <= 1)), (0, True))/2
```

This is a uniform distribution from 0 to 2.

Am I misunderstanding what the sum of two random variables represents in sympy, or is this totally wrong? I would expect the result to be a triangular distribution.


Message has been deleted

Francesco Bonazzi

unread,
Oct 8, 2017, 1:16:27 AM10/8/17
to sympy


On Sunday, 8 October 2017 01:10:14 UTC-4, Francesco Bonazzi wrote:
This result is definitely wrong.

Sorry, ignore my previous answer, that result is correct. If you sum n + n, you are summing the same random value. To get the effect of summing two uniform distributions, just define a new uniform distribution:

In [8]: m = Uniform('m', 0, 1)

In [9]: density(n+m)
Out[9]:
     
⎛⎧                                 1       ⎛⎧                        
     
⎜⎪            0               for ─── < 1   ⎜⎪                        
     
⎜⎪                                z       ⎜⎪                        
z
- ⎜⎨                                       + ⎜⎨                        
     
⎜⎪  ╭─╮0, 2 2, 1       1               ⎜⎪  ╭─╮0, 2 2, 1        
     
⎜⎪z⋅│╶┐               ─⎟   otherwise   ⎜⎪z⋅│╶┐              
     
⎝⎩  ╰─╯2, 2      1, 0 z               ⎝⎩  ╰─╯2, 2      1, 0 p

                                                                     
1      
                 
0                                            for ─────── < 1
                                                                 
z - 1    
                                                                             

       
1           ╭─╮0, 2 2, 1               1                        
────────────────⎟ - │╶┐               ─────────────────⎟     otherwise  
olar_lift
(z - 1)⎠   ╰─╯2, 2      1, 0 polar_lift(z - 1)⎠                


The integral is unable to simplify the expression, but that's another issue.

Reply all
Reply to author
Forward
0 new messages