# Probability Exercise. Find a joint distribution.

I have been working on some exercises for probability. There is a problem that I cannot even figure out where to start. So, here is the question.

• Let $$T$$ be drawn from a uniform distribution on the interval $$\left[0, \,\sqrt{\,{2}\,}\, - 1\right]$$.
• Accept $$T$$ with probability $$1/\left(1 + T^{2}\right)$$, otherwise start over.
• Let $$S = 2T/\left(1 + T^{2}\right)$$ and $$C = 1 - ST$$.
• Now with probability $$1/2$$ switch $$S$$ and $$C$$.
• Then with probability $$1/2$$ for each, independently, change the signs of $$S$$ and $$C$$.
• What is the joint distribution of $$S$$ and $$C$$ ?.

Okay, Let $$T \sim \mathcal U([0,\sqrt2-1])$$. Now, given that $$T=t$$ let $$X$$ be equal to $$t$$ with probability $$\frac{1}{1+t^2}$$. Otherwise, we select $$T$$ again. Firstly we'd like to find the distribution of $$X$$. Let $$F_X(s) = \mathbb P(X \leq s)$$. There are two trivial cases. If $$s < 0$$ then $$F_X(s) = 0$$ and if $$s > \sqrt2 -1$$ then $$F_X(s) = 1$$ no matter what.

So now the hard one, let $$s \in [0,\sqrt2-1]$$. For $$\{X \leq s\}$$ to happen, we must meet two conditions:

Obviously $$T \leq s$$ and while it happened, there also must be that $$T$$ was accepted.

$$F_X(s) = \mathbb P(\{T\leq s\}|\{T "accepted"\}) = \mathbb P(\{T "accepted" \} \cap \{T\leq s \})\cdot \frac{1}{\mathbb P(T "accepted")}$$.

So we have to compute probabilities of two events.

$$\mathbb P(T "accepted") = \mathbb E[\chi_{_{T "accepted"}} ] = \mathbb E [ \mathbb E[\chi_{_{T "accepted"}} | T]] = \mathbb E[\frac{1}{1+T^2}] = \frac{1}{\sqrt2-1}\int_0^{\sqrt2-1}\frac{1}{1+t^2}dt =$$

$$= \frac{\pi}{8(\sqrt2-1)}$$, because $$\arctan( \sqrt2-1) = \frac{\pi}{8}$$

$$\mathbb P(T \leq s \cap T "accepted" ) = \mathbb P(T"accepted" | T \leq s)\cdot \mathbb P(T\leq s) = \mathbb P(T"accepted" | T \leq s)\frac{s}{\sqrt2 -1 }$$

That is $$F_X(s) = \frac{8s}{\pi}\cdot \mathbb P(T"accepted" | T \leq s)$$, while the latter is equal to $$\frac{1}{s} \int_0^s \frac{1}{1+t^2}dt = \frac{\arctan(s)}{s}$$ (because we have to normalize it over $$[0,s]$$ (so that we get a factor $$\frac{1}{s}$$) and then integrate that "conditional" probability over whole interval of possible values of $$T$$( note, it isn't the whole $$[0,\sqrt2-1]$$ now, but only $$[0,s]$$))

Which gives us $$F_X(s) = \frac{8\arctan(s)}{\pi}$$, for $$s\in[0,\sqrt2-1]$$, so that $$g_X(s) = \frac{8}{\pi(1+s^2)}\chi_{[0,\sqrt2-1]}(s)$$ is the density.

Now we have to deal with $$S = \frac{2X}{1+X^2} = f(X)$$ and $$C = \frac{1-X^2}{1+X^2} = h(X)$$.

Since $$f,h$$ are smooth functions we can (and will) use the rule $$g_S(s) = g_X(f^{-1}(s))|\det(f^{-1}(s)|$$ (similarly for C)

Let's attack $$S$$: $$f([0,\sqrt2-1]) = [0,\frac{2\sqrt2-2}{2+2-2\sqrt2}] = [0,\frac{1}{\sqrt2}]$$

$$Y = \frac{2X}{1+X^2} \iff Y + YX^2 = 2X \iff YX^2 - 2X + Y = 0$$

$$\Delta = 4 - 4Y^2$$ so $$\sqrt\Delta = 2\sqrt{1-Y^2}$$, and we see that $$f^{-1}(y) = \frac{1\pm \sqrt{1-y^2}}{y}$$ (but the one with plus sign has to be rejected due to or domain of $$f^{-1}$$ (if we allow plus sign, then $$f^{-1}(\frac{1}{\sqrt{2}}) = \sqrt2 + 1$$, which isn't good)).

So $$f^{-1}(y) = \frac{1 - \sqrt{1-y^2}}{y}$$, and it's derivative $$\frac{\frac{2y^2}{2\sqrt{1-y^2}}-(1-\sqrt{1-y^2})}{y^2} = \frac{y^2 - \sqrt{1-y^2} + 1 - y^2}{y^2\sqrt{1-y^2}} = \frac{1-\sqrt{1-y^2}}{y^2\sqrt{1-y^2}}$$

So let's plug it:

$$g_S(s) = \frac{8}{\pi} \cdot \frac{1-\sqrt{1-y^2}}{y^2\sqrt{1-y^2}} \cdot \frac{y^2}{y^2 +2 - y^2 - 2\sqrt{1-y^2}} = \frac{4}{\pi\sqrt{1-y^2}}$$, and thankfully it integrates to $$1$$ over $$[0,\frac{1}{\sqrt2}]$$

Doing similarly with $$C$$ now: $$h([0,\sqrt2-1])=[\frac{1-(2+1-2\sqrt{2})}{1+(2+1-2\sqrt{2})},1] = [\frac{2\sqrt2-2}{4-2\sqrt2},1] = [\frac{1}{\sqrt2},1]$$

Hmm, that can help in the future that $$S$$ and $$C$$ have different values.

Okay, but let's go, finding $$h^{-1}$$:

$$Z = \frac{1-X^2}{1+X^2} \iff Z + ZX^2 = 1 - X^2 \iff X^2(1+Z) = 1 - Z \iff X^2 = \frac{1-Z}{1+Z}$$ And because we need positive value $$(X\ge 0 )$$ so $$X = \sqrt{\frac{1-Z}{1+Z}}$$ and $$h^{-1}(s) = \frac{\sqrt{1-s}}{\sqrt{1+s}}$$ and we can calculate it's derivative : $$\frac{-\sqrt{1+s}}{\sqrt{1-s}(1+s)^2}$$, now plugging everything into $$g_C$$ we have:

$$g_C(s) = \frac{8}{\pi}\cdot \frac{\sqrt{1+s}}{\sqrt{1-s}(1+s)^2} \cdot \frac{1+s}{1+s + 1 - s} = \frac{4}{\pi\sqrt{1-s^2}}$$ and again integrates to $$1$$ over$$[\frac{1}{\sqrt2},1]$$

NOTE: Those densities equal to that value for $$s \in [0,\frac{1}{\sqrt2}]$$ and $$s \in [\frac{1}{\sqrt2},1]$$ respectivelly, otherwise they are zero.

So we should take them into one spot, because they can be helpful:

$$g_S(x) = \frac{4}{\pi\sqrt{1-x^2}}\chi_{[0,\frac{1}{\sqrt2}]}(x)$$, and $$g_C(x) = \frac{4}{\pi\sqrt{1-x^2}}\chi_{[\frac{1}{\sqrt2},1]}(x)$$

So now we arrived at the moment when with probability $$\frac{1}{2}$$ we have to swap those variables. Instead we will create two new variables, call them $$W,U$$, and we describe them as follow: when $$C=c, S=s$$ then $$\mathbb P(W=s)=\mathbb P(W=c) = \frac{1}{2}$$ and $$U$$ is always that remaining value (that is: when $$W=s$$ then $$U=c$$ and when $$W=c$$ then $$U=s$$). Okay, so now we have to independently choose signs for $$W,U$$. Anyway, we need joint distribution of $$W$$ and $$U$$ that is the distribution of random vector $$V = (W,U)$$ .We are still conditioning on $$S=s, C=c$$ (let $$L=(S,C)$$):

$$\mathbb P(V=(\pm s,\pm c) | L=(s,c)) = \mathbb P(V=(\pm c,\pm s) | L=(s,c)) = \frac{1}{8}$$ (Hope you understand my shortcuts)

Now, when $$X=x$$ that mean : $$s=\frac{2x}{1+x^2}, c=\frac{1-x^2}{1+x^2}$$ while $$x$$ goes from $$0$$ to $$\sqrt2 -1$$, $$(s,c)$$ forms a curve located in $$[0,\frac{1}{\sqrt2}] \times [\frac{1}{\sqrt2},1]$$ starting at $$(0,1)$$ ending at $$(\frac{1}{\sqrt2},\frac{1}{\sqrt2})$$ while $$(c,s)$$ forms a curve in $$[\frac{1}{\sqrt2},1] \times[0,\frac{1}{\sqrt2}]$$ from $$(\frac{1}{\sqrt2},\frac{1}{\sqrt2})$$ to $$(1,0)$$.

Let (we'll need them later to write the distribution of $$V$$, exactly 8 "mirrored" parts)

$$\Gamma_{\pm1,\pm1,1} = \{ t \in \mathbb R^2: t=(\pm\frac{2x}{1+x^2},\pm\frac{1-x^2}{1+x^2}), x\in[0,\sqrt2-1]\}$$, $$\Gamma_{\pm1,\pm1,-1} = \{ t \in \mathbb R^2: t=(\pm\frac{1-x^2}{1+x^2},\pm\frac{2x}{1+x^2}), x\in[0,\sqrt2-1]\}$$

$$\Gamma = \bigcup (\Gamma_{\pm1,\pm1,1} \cup \Gamma_{\pm1,\pm1,-1})$$ ( glue all these eight pieces together)

Note: $$\Gamma$$ is just an unit circle! (Adding squared values of coordinates gives us $$1$$)

So, we should be able to "transform" those coordinates into $$\sin, \cos$$.

Note that, when $$X=\tan(\frac{\alpha}{2})$$, then $$V=(W,U)=(\sin(\alpha),\cos(\alpha))$$

And the density of $$X$$ tell us that the $$\frac{\alpha}{2}$$ is uniformly distributed on $$[0,\frac{\pi}{8}]$$ (taking this $$\arctan(\sqrt2 - 1)$$) So $$\alpha \sim \mathcal U([0,\frac{\pi}{4}])$$. But we have eight connected pieces curves $$\Gamma_{\pm1,\pm1,\pm1}$$, that behave as whole unit circle (those $$\sin,\cos$$ swaps with themselves and swaps signs).

That means, after letting $$S=\{ (x,y) \in \mathbb R^2 : x^2 + y^2 = 1 \}$$, the distribution of vector $$V$$ is $$\mu_{_V}$$, where for every borel set $$A \in \mathcal B(\mathbb R^2)$$, we have:

$$\mu_{_V}(A) = \frac{1}{8}\int_{A \cap S} \frac{4}{\pi} d\sigma_2(x,y) = \frac{1}{2\pi}\int_{A \cap S}d\sigma_2(x,y)$$

To clarify: That $$\frac{1}{8}$$ is due to our eight pieces with are really similar and mirrored (that is all those probabilities were $$\frac{1}{8}$$) and the $$\frac{4}{\pi}$$ is just the density function of $$\alpha$$ (note that there is indicator function, but in the limits (that $$\Gamma$$ ).)

After thinking a while, it wasn't that important to find densities of $$S,C$$, but I didn't see that vector $$V$$ "forms" a circle before having those calculated.

OK, let's go by steps.

First, for $$T$$, there is some rejection sampling happening. Noticing that and recalling the Cauchy distribution, we see that $$T$$ is drawn from a truncated Cauchy distribution -- i.e. $$T$$ has the distribution of a standard Cauchy random variable, conditioned on lying in the interval $$[0,\sqrt{2}-1]$$.

What that ends up meaning is that $$T$$ has density $$f_T$$ equal to 0 outside of $$[0,\sqrt{2}-1]$$ and otherwise equal to $f_T(x)=\frac{1}{Z} \frac{1}{1 + x^2}$ where $Z = \int_0^{\sqrt{2} - 1} \frac{1}{1 + x^2} \, dx = \frac{\pi}{8}$ thankfully -- someone has been nice with the constants. So $$f_T(x)=\frac{8}{\pi}\frac{1}{1+x^2}$$.

Now for $$S$$. What is this thing? If $$g(x)=2\frac{x}{1+x^2}$$ then $$S=g(T)$$. $$g$$ is a smooth invertible (in fact strictly increasing) function on the domain we care about (the values that $$T$$ can take, which are $$[0,\sqrt{2}-1]$$), so we can use a change of variables formula to compute the density $$f_S$$ of $$S$$ as follows.

First, since $$g(0)=0$$ and $$g(\sqrt{2}-1)=\sqrt{2}^{-1}$$ (again we have been blessed by someone here), we see that the probability that $$S$$ lies outside the interval $$[0,\sqrt{2}^{-1}]$$ is 0, so that $$f_S$$ is equal to 0 outside that interval, and inside of it we have$f_S(x)=f_T(g^{-1}(x)) g^{-1}{'}(x).$ On our region of interest, $$g^{-1}(x)=\frac{1-\sqrt{1-x^2}}{x}$$, which has derivative$g^{-1}{'}(x)=\frac{1}{x^2\sqrt{1-x^2}} - \frac{1}{x^2}.$ OK, so it's a bit of a pain, but $f_S(x)=\frac{8}{\pi}\frac{x^2}{(\sqrt{1-x^2}-x-1)^2}\bigg(\frac{1}{x^2\sqrt{1-x^2}} - \frac{1}{x^2}\bigg)=\frac{4}{\pi}\frac{1}{(x+1)\sqrt{1-x^2}},$ which isn't so bad in the end.

OK, so we have now the distribution of $$S$$. Let's find that of $$C$$, noticing that if $$h(x)=1-g(x)x$$, then $$C=h(T)$$. But wait -- simplifying $$h$$ we see that $$h(x)=\frac{1}{1+x^2}$$. (Who made this problem, and why? Haha.) On the interval we care about,$h^{-1}(x)=\frac{\sqrt{1-x}}{\sqrt{x}},$ with derivative $h^{-1}{'}(x)=-\frac{1}{2 x \sqrt{x}\sqrt{1-x}},$ so that$f_C(x)=f_T(h^{-1}(x)) h^{-1}{'}(x) = ...$ OK, I have to go offline for a while, but this might get you started...