Let U, V both be independent uniform random variables from [0, 1]. I am interested in the function F(x, y) = Pr[2/3 U - 2/3 <= x, 2/3 V - 2/3 <= y] and its derivative. I wrote the following Sage code to calculate it, but it's taking very long (more than 10 minutes and no output yet). Is there a way to speed the code? from sage.all import * var('u v x y') ineq1 = heaviside(x + QQ(2)/3 - QQ(2)/3 * u) ineq2 = heaviside(y + QQ(2)/3 - QQ(2)/3 * v ) indicator = ineq1 * ineq2 cdf = integrate(integrate(indicator, v, 0, 1), u, 0, 1) diff(cdf, x) If I change to say another transformation like Pr[2/3 U + 1/3 V - 2/3 <= x, 1/3 U + 2/3 V - 2/3 <= y], it outputs the result in less than a second: from sage.all import * var('u v x y') ineq1 = heaviside(x + QQ(2)/3 - QQ(2)/3 * u - QQ(1)/3 * v) ineq2 = heaviside(y + QQ(2)/3 - QQ(1)/3 * u - QQ(2)/3 * v ) indicator = ineq1 * ineq2 cdf = integrate(integrate(indicator, v, 0, 1), u, 0, 1) diff(cdf, x) Continue reading...