Building a function of a random variable dynamically in python
Question: I have some random variables using `scipy.stats` as follows:

    
    
    import scipy.stats as st
    x1 = st.uniform()
    x2 = st.uniform()
    

Now I would like make another random variable based on previous random
variables and make some calculations like `var` for the new random variable.
Assume that I want the new random variable to be something like `max(2, x1) +
x2`. How can I define this dynamically?


Answer: Not directly, I think. However, this approach might be of use to you.

Assume to begin with that you know either the pdf or the cdf of the function
of the random variables of interest. Then you can use rv_continuous in
scipy.stats to calculate the variance and other moments of that function using
the recipe offered at [SO
doc](http://stackoverflow.com/documentation/scipy/6873/rv-continuous-for-
distribution-with-parameters#t=201610161945055670237). (Incidentally, someone
doesn't like it for some reason. If you think of improvements, please
comment.)

Obviously the 'fun' begins here. Usually you would attempt to define the cdf.
For any given value of the random variable this is the probability that an
expression such as the one you gave is not more than the given value. Thus
determining the cdf reduces to solving a (an infinite) collection of
inequalities in two variables. Of course there is often a strong pattern that
greatly reduces the complexity and difficulty of performing this task.

