For Turing, you should be using the tilde operator (~) rather than assignment (=).

Your first example would be

p ~ Uniform(0,1)
p2 = 1-p

which will work in a Turing @model block. For your second example, you would have to draw the two variables separately and assign them before you add them:

have you looked @ Expectations.jl?
It allows you to compute expectations of transformations of random variables.

dist = Normal()
E = expectation(dist)
E(x -> x)
expectation(x->x^2, dist)
#
d = MixtureModel([Uniform(), Normal(), Gamma()]);
E = expectation(d);
E(x -> x) # 0.5000000000000016

I think it would be amazing if Distributions.jl supported transformations of random variables. Mathematica is the only software I know that does this well currently.

Those are two distinct problems. Samples generation is super easy (you just define a rand), but inference will be tricker: for monotone transformations you just transform the likelihood and correct with the Jacobian, while for sums that don’t result in a “known” distribution you have to do something else, eg latent variables.

This is one of those problems that are easy to state but require a moderate amount of work to solve, specific to the problem. You should focus on the actual question you are trying to solve and describe that here, so that we can give more specific help.

that may be the kind of problem that is intriguing enough to try to solve…

Just to have some guidance here, the place to start looking into is Distributions.jl? And look at the semantics provided by Mathematica as @Albert_Zevelev suggests?

Mathematica can handle transformations of a distribution when it can solve the problem symbolically.
In Julia things are usually done numerically, not symbolically.
Eg: Expectations.jl computes expectations numerically using quadrature.

For example consider a transformed Beta[4,3]. Mathematica can do all the following except it has no closed form for the entropy.

Now consider a transformed Beta[\alpha, \beta]:

I wrote a cheat-sheet which shows that Julia handles random variables much better than Matlab/R/STATA.
If we want Julia to deal w/ general transformations of random variables, we are probably gonna have to do this numerically. (but this means we an handle more transformations than Mathematica)

Very nice summary @Albert_Zevelev . Thanks.
Yes, I agree that things should be done numerically in Julia (unless there were
any heavy C.A. lifters around; don’t look at me )

You should look there! In some sense that is my research area. Assume you need to work with the conditional density (or posterior) p of X given X + Y which is not known in closed form. If you can find approximations X̃, Ỹ where you can compute the close form for the density p̃ of X̃ given X̃ + Ỹ, then you can use Monte Carlo methods to change samples from the conditional distribution of X̃ into the conditional distribution X that you are actually interested in. Almost used in all of my papers on arxiv: Moritz Schauer's articles on arXiv