Sunday, January 7, 2018

A Note on Conditional Expectations


This post is about a very small problem on conditional expectations but which got me thinking for a couple of days. Eventually I realized how I never really fully understood them.

The problems is this: Let $X, Y$ be two random variables uniformly distributed between $0$ and $1$. Find $\mathbb{E}(X\vert X+Y \leq 1)$.

I was discussing with a friend and he even tried to write the Bayes formula for exceptions. Only when I started thinking about this I realized, how may people, including me, don't see the absurdity of trying to find Expectation of events and Probability of variables.

For example, $\mathbb{E}(X+Y \leq 1)$ doesn't make any sense at all. Neither does $\mathbb{P}(X)$. Both of them completely nonsensical. For the first one to make sense, it would be more appropriate to talk about $\mathbb{E}(I_{X+Y \leq 1})$ where $I$ is an indicator random variable. Similarly, $\mathbb{P}(0.25\leq X \leq 0.5)$ is valid expression.

Let $X$ be a variable and $Z$ be an event, something like $X+Y\leq1$ or $X \geq Y$. Let $I_Z$ be the indicator random variable of the event $Z$. Now, conditioning on $Z$,

$\begin{align}\mathbb{E}(X\cdot I_z)&=\mathbb{P}(Z)\mathbb{E}(X\cdot I_z\vert Z)+\mathbb{P}(Z^c)\mathbb{E}(X\cdot I_z \vert Z^c)\\
&=\mathbb{P}(Z)\mathbb{E}(X\cdot 1\vert Z)+\mathbb{P}(Z^c)\mathbb{E}(X\cdot 0\vert Z^c)\\
&=\mathbb{P}(Z)\mathbb{E}(X\vert Z)\\
\end{align}$

On the other hand, conditioning on $X$,

$\begin{align}\mathbb{E}(X\cdot I_z)&=\mathbb{E}(\mathbb{E}(X\cdot I_z \vert X))\\
&=\mathbb{E}(X\cdot \mathbb{E}(I_z\vert X))\\
&=\mathbb{E}(X\cdot \mathbb{P}(Z\vert X))
\end{align}$

Equating the two, we finally get,

$\mathbb{E}(X\vert Z)=\displaystyle\frac{\mathbb{E}(X\cdot \mathbb{P}(Z\vert X))}{\mathbb{P}(Z)}$

Now this makes the problem tractable, as all the terms makes perfect sense provided we understand that $X$ is a variable and $Z$ is an event (which could even be something like $X=3$ in the discrete case).

An alternate way of deriving the same result will be like the following. Assume $X$ is a continuous random variable. The reasoning will be very similar if $X$ is discrete.

$\begin{align}
\mathbb{E}(X\vert Z)&=\int x f_{X\vert Z}(x)\,dx\\
&=\int x \text{ }\frac{\mathbb{P}(Z\vert X)f_{X}(x)}{\mathbb{P}(Z)}\,dx=\displaystyle\frac{1}{\mathbb{P}(Z)}\int x\text{ } \mathbb{P}(Z\vert X)f_{X}(x)\,dx\\
&=\displaystyle\frac{\mathbb{E}(X\cdot \mathbb{P}(Z\vert X))}{\mathbb{P}(Z)}
\end{align}$

However, the first way includes a lot of tiny beautiful details like the conditioning on a random variable, law of total expectation, and most importantly it gives a chance to understand that,

$\mathbb{E}(X\cdot I_z\vert I_z=1)\ne\mathbb{E}(X)$ in general. Rather when the dependence between $X$ and $Z$ is not clear or not given, it is always better to state the relation as,

$\mathbb{E}(X\cdot I_z\vert I_z=1)=\mathbb{E}(X\vert Z)$

That's what I wanted to convey in this post because I had a very difficult time on how to solve that conditional expectation. Hope you enjoyed this.


Until then
Yours Aye,
Me

Thursday, January 4, 2018

Visualizing Conformal Mapping with Mathematica


Hi everyone, My first post in 2018..

Well, this post does not have any mathematics. Rather, this post is about, as the title says, visualizing conformal mapping. I recently came across an amazing Youtube Channel, 3Blue1Brown. If you haven't seen it, you should definitely check it out.

Most of the videos are pretty amazing. If you think Mathematics is beautiful with just equations, then visualizing Math is possibly the only thing better than Math itself (in my humble opinion).

Especially the video Visualizing the Riemann Zeta function is outstanding, simply the best video I've seen on Youtube, I think. Ever since I saw that, I wanted to create those animations. A simple Google search led me the fact that Grant Sanderson, creator of the Channel, uses his own Python module manim to create these animations.

I'm just a beginner in Python and using a specialized module is far from my relationship with Python. So I turned to the next best thing at my disposal, Mathematica. It took me about four evenings to get everything right to get an Animation and save it as GIF using Mathematica. But now after seeing those animations, I feel like it's really worth it.

So here's one of my first animations. The Inverse of a complex number.



Pretty neat, don't you think?

Now for the Zeta function itself. Mathematica takes about 5 mins to create the following animation.



Look at that.. So beautiful...

Moreover, looking at the two mappings we can get to see how the Zeta function has a simple pole at 1. Both graphs look almost the same at the final stage except that the Zeta function is translated by a unit distance along the real axis.

I also created one with a darker background but it doesn't look all that nice. The different colors are not by choice. In fact I'm not sure how to make all the curves along the real axis look the same color. Hope you would let me know in case you are aware of that.

Now for the code.

Clear["Global`*"];
f[z_] := Zeta[z];
Lim = 5;
DiscreteXValues =
 Join[Range[-Lim, -2], Table[j/10, {j, -15, 15}],
  Range[2, Lim]]; ContinuousYValues = {-Lim, Lim};
DiscreteYValues =
 Join[Range[-Lim, -2], Table[j/10, {j, -15, 15}],
  Range[2, Lim]]; ContinuousXValues = {-Lim, Lim};
RangeofthePlot = {{-Lim, Lim}, {-Lim, Lim}};
slides = Table[
    Show[ParametricPlot[
      Evaluate[
       Table[{XVaries (1 - t) + t Re[f[XVaries + I k]],
         k (1 - t) + t Im[f[XVaries + I k]]}, {k,
         DiscreteYValues}]], {XVaries, First[ContinuousXValues],
       Last[ContinuousXValues]}],
     ParametricPlot[
      Evaluate[
       Table[{k (1 - t) + t Re[f[k + I YVaries]],
         YVaries (1 - t) + t Im[f[k + I YVaries]]}, {k,
         DiscreteXValues}]], {YVaries, First[ContinuousYValues],
       Last[ContinuousYValues]}], PlotRange -> RangeofthePlot,
     AxesOrigin -> {0, 0}, GridLines -> Automatic], {t, 0, 1,
     1/40}]; // AbsoluteTiming
ListAnimate[slides, AnimationDirection -> ForwardBackward,
 AnimationRunning -> True, AnimationRate -> 8]
(*Export["ZetaFunction.gif",slides,ConversionRules\[Rule]{\
"ControlAppearance"\[Rule]None,"DisplayDurations"\[Rule]1/5}]*)
Export["ZetaFunction.gif",
 Flatten[{slides,
   Table[slides[[i]], {i, Length[slides] - 1, 2, -1}]}],
 "ControlAppearance" -> None, "DisplayDurations" -> 1/8]

After several iterations, I ended up with the above. It has options to control how many grid lines you want in each direction, and for each of them how long you wanna plot in the perpendicular direction. Play with DiscreteXValues, DiscreteYValues, ContinuousXValues and ContinuousYValues.

And before I finish, while we are on the 3Blue1Brown, his video on Pi hiding in prime irregularities, inspired me to find the following two 'non-obvious' results.

$\displaystyle \frac{\sqrt{2}\pi}{5}=\left\vert \frac{1}{1} + \frac{i}{2}- \frac{i}{3} - \frac{1}{4} + \frac{1}{5} + \frac{i}{6} - \frac{i}{7} - \frac{1}{8} + \cdots\right\vert$

$\displaystyle \frac{\pi}{\sqrt{10}}=\left\vert \frac{1}{1} + \frac{i}{3}- \frac{i}{7} - \frac{1}{9} + \frac{1}{11} + \frac{i}{13} - \frac{i}{17} - \frac{1}{19} + \cdots\right\vert$

Hope you enjoyed them.



Until then,
Yours Aye
Me.

Saturday, December 30, 2017

A little math on Badminton


If you had read my first few posts, you would've known that am an amateur Badminton player. Now I don't find either the time or the energy to play the game, but it's a game that I've always enjoyed playing. This post is about combining my interest on Badminton and my passion for math.

Most of the important details of the post are borrowed from Score probabilities for serve and rally competitions. The paper was too good in analyzing a given serve-rally competition, be it tennis or Badminton or the likes, the paper did not stick to any one particular game and finish it off in style which is exactly what we plan to do here for Badminton.

Let's just list the rules to make sure we are all on the same page.

  • A rally cannot end in a draw
  • The winner of the current rally wins a point and serves next irrespective of who served the current rally
  • The first player to reach 21 points wins the game unless the score was ever tied at 20 apiece
  • If the score ever reached 20-20, then the first player to lead by two point or the reach 30 points wins the game

Let me stick to the notations used in the paper quoted above and call the two players $A$ and $B$. WLOG, we always consider $A$ to serve first. The game will be analyzed from $A$'s perspective and hence let $p_a$ denote the probability that $A$ wins the rally when $A$ serves and $p_b$ denote the probability that $A$ wins the rally when $B$ serves.

Then $q_x=1-p_x,\text{ }x=a,b$ be the corresponding winning probabilities for $B$.

Given these probabilities, we intend to find the probability of $A$ winning the game. But before we begin, assuming both the players are equally skilled, do you think that $A$ has an advantage because he is serving first?

Let $\mathbb{P}(X),\text{ } X=A,B$ denote the probability that $X$ wins the game and $\mathbb{P}(X_{i,j}),\text{ } X=A,B$ denote the probability that game is at a stage where $A$ has $i$ points, $B$ has $j$ points and $X$ has won the last point.

The paper doesn't go on to complete by taking into account the end conditions of the game. To do that, we extend it to cover the end cases as well.

$\mathbb{P}(A_{i,j})=
\begin{cases}
0,& i \leq 0\\
p_a^i, &i\leq21,j=0\\
\displaystyle p_a^iq_b^j\sum_{r=1}^i\binom{i}{r}\binom{j-1}{r-1}\left(\frac{q_a p_b}{p_a q_b}\right)^r,&i < 21, j<21\text{ (or) }i=21,j<20\\
p_a\text{ }\mathbb{P}(A_{i-1,j})+p_b\text{ }\mathbb{P}(B_{i-1,j}),&0\leq i - j \leq 2, \text{ }i\leq30,j<30
\end{cases}$

$\mathbb{P}(B_{i,j})=
\begin{cases}
0,& j \leq 0\\
q_a q_b^{j-1}, &j\leq21,i=0\\
q_a q_b^{j-1}p_a^i\left[1+\displaystyle\sum_{s=1}^{j-1}\sum_{r=1}^i\binom{i}{r}\binom{s-1}{r-1}\left(\frac{q_a p_b}{p_a q_b}\right)^r\right],&j < 21, i<21\text{ (or) }j=21,i<20\\
q_a\text{ }\mathbb{P}(A_{i,j-1})+q_b\text{ }\mathbb{P}(B_{i,j-1}),&0\leq j-i \leq 2, \text{ }j\leq30,i<30
\end{cases}$

Anything that doesn't fall in these categories is $0$.

Now,

$\mathbb{P}(A)=\displaystyle\sum_{r=0}^{19} \mathbb{P}(A_{21,r})+\sum_{r=22}^{30} \mathbb{P}(A_{r,r-2})+\mathbb{P}(A_{30,29})$ and $\mathbb{P}(B)=1-\mathbb{P}(A)$

Playing with this code, we now answer the question that I asked above. According to the model, when both the players are equally skilled (both while serving and defending), it makes no difference as to who serves first. This seemed a counter-intuitive to me because assuming everything else equal, I thought the first player has the initiative.

Let's look at the question of serve-advantage with the following graphic.



The probability of $A$ winning the game is plotted in the Y-axes. The orange curve is when both players are equally adept at winning the rallies when they serve. That 'adept-ness' is in the X-axis. The upper blue curve is when $A$ has a 'slight' serve-advantage over $B$ and vice verse for the lower green curve. (The 'slight' is 1% here)

The green curve clearly shows the second player can 'pull-down' $A$'s chances of winning the game by developing a serve-advantage though at professional levels this diminishes fast.

Yet another interesting graphic is the one where the first player has the same probability of winning a rally irrespective of who served.


Again the Y-axis shows the probability of $A$ winning the game and the X-axis, his probability of winning the rally (irrespective of the serve). The graph pretty much says that once a player reached about 2/3rd chance of winning the rally, there is pretty much nothing more he has (or need) to do.

Hope you enjoyed this. Wish you all a very Happy New Year!!



Yours Aye,
Me

Wednesday, December 20, 2017

An Iterated Sum


 I recently saw a very nice problem. It's a problem on Continuous distribution but I recognized it's one of those problems where the reasoning can be applied exactly to the discrete case too. So here it is.

Consider the following sum.

$T(n)=\displaystyle\sum_{j_1=1}^n\sum_{j_2=1}^{n-j_1}\sum_{j_3=1}^{n-j_2}\cdots\sum_{j_k=1}^{n-j_{k-1}}1$

One interpretation of the above sum can be as follows: The sum counts the number of $k$-tuples of positive integers such that each integer in the tuple is less than or equal $n$ and the sum of any two consecutive elements in the tuple in less than or equal to $n$ as well.

To find this sum, let's modify the notation a bit. Let

$T_k(m)=\displaystyle\sum_{j_1=1}^{n-m}\sum_{j_2=1}^{n-j_1}\sum_{j_3=1}^{n-j_2}\cdots\sum_{j_k=1}^{n-j_{k-1}}1$

So we are solving for $T_k(0)$ given $n$. Now we take advantage of the iterative structure of the sum to write it as,

$T_k(m)=\displaystyle\sum_{j=1}^{n-m}T_{k-1}(j)$

with $T_0(m)=1$. This may be a little confusing but a moment of thought clears it up easily. Now this renders itself to the idea of generating functions. We define,

$f(z,m)=\displaystyle\sum_{j=0}^\infty T_j(m)z^j$

Let's do some algebraic manipulations in the above sum.

$\begin{align}
f(z,m)&=1+z\sum_{j=1}^\infty T_j(m)z^{j-1}\\
&=1+z\sum_{j=1}^\infty z^{j-1} \sum_{i=1}^{n-m}T_{j-1}(i)\\
&=1+z\sum_{i=1}^{n-m}  \sum_{j=1}^\infty T_{j-1}(i)z^{j-1}\\
&=1+z\sum_{i=1}^{n-m} f(z,i)\\
\end{align}$

We can infer that

$(1):$    $f(z,h+1)-f(z,h)=-z f(z,n-h)$

$(2):$    $f(z,h+2)-2f(z,h+1)+f(z,h)=-z (f(z,n-h-1)-f(z,n-h))$

$(3):$    $f(z,n)=1$

$(4):$    Using $h=0$ in $(1)$, we have $f(z,1)-f(z,0)=-z$      (using $(3)$)

Using $h=n-m-1$ in $(1)$, we have $f(z,n-m)-f(z,n-m-1)=-z f(z,m+1)$. Substituting this in $(2)$, we finally arrive at,

$f(z,m+2)-2f(z,m+1)+f(z,m)=-z^2f(z,m+1)$

This is a simple difference equation of the second order. The characteristic equation of this is,

$x^2+(z^2-2)x+1=0$ with roots $z_{+,-}=\displaystyle\frac{1}{2}(2-z^2\pm z\sqrt{z^2-4})$

Therefore, $f(z,m)=c_1 z_+^m+c_2 z_-^m$. Note that our point of interest $f(z,0)=c_1+c_2$

We use $(3)$ and $(4)$ to solve for these constants. Finally,

$T_k(0)=[z^k]f(z,0)=[z^k]\displaystyle\frac{z_+^n-z_+^{-n}+\sqrt{z^2-4}}{\frac{z}{2}(z_+^n-z_+^{-n})+\frac{\sqrt{z^2-4}}{2}(z_+^n+z_+^{-n})}$

Honestly, the entire idea so far has been adapted to the discrete case from the original source. Moreover, the given expression looks complicated. It seems we can simplify this and somehow get rid of the radical terms but I was not able to.

But I did all these because, first of all, it was fun and second, I was able to notice something very nice which would be my original contribution to this post.

Let $f_j(z)=z+\displaystyle\frac{1}{f_{j-1}(-z)}$ with $f_0(z)=1$. Then $T_k(0)=[z^k]f_n(z)$. That is,

$\displaystyle\sum_{j_1=1}^n\sum_{j_2=1}^{n-j_1}\sum_{j_3=1}^{n-j_2}\cdots\sum_{j_k=1}^{n-j_{k-1}}1=[z^k] \text{  }[z;-z,z,-z,\cdots,(-1)^{n-1}z,1]$

in continued fraction notation. Note that there are $n$ $z$'s on the RHS and the sign alternates with every iterate.

I really liked how an iterated sums occur on one side, a continued fraction on the other and levels on both sides $k$ and $n$ in a twisted way. Not only does this make the sum compact (also freeing it of any radicals), it also makes it easier to program. I used this idea to make a Python program for different $k$.

Yeah, my original idea was very small compared to the length of the post but it was great learning experience for me going through a problem in both continuous and discrete cases side-by-side, understanding how each steps transpires in both of them. Hope you enjoyed this.


Until then
Yours Aye
Me.

Tuesday, October 24, 2017

A (very) short note on the MTZ constraints of Vehicle Routing Problem


This post will be about the Vehicle Routing Problem (VRP), a combinatorial optimization and integer programming problem which generalizes the famous Travelling Salesman Problem (TSP). To be even more specific, I'm making this post to discuss MTZ constraints, a set of  sub-tour elimination constraints, in the Vehicle flow formulation of the VRP.

I tried to understand the ones given in the Wiki article but they are definitely wrong (as of this writing). Very many sources can be found on the internet but I was not able to understand any of them clearly. Turns out, those are not very hard to understand and I was able to make my own formulation. It goes like the following.

$u_i-u_j+Cx_{ij}\leq C-d_j$      $\forall i,j \in V \setminus \{0\}, i\ne j$      $s.t.$ $0<d_i \leq C$
$d_i\leq u_i \leq C$     $\forall i \in V \setminus \{0\}$

where $C$ is the capacity of the vehicle, $d_i$ is the demand of the $i$th city, and $x_{ij}$ is a binary variable that defines whether a tour happens from the $i$th city to the $j$th city or not (To avoid confusion, I've used the notations used in the Wiki article).

It is easy to see why this works. First, if there exists a sub-tour involving $k$ cities, then we can add the inequalities corresponding to those edges. The $u$ variables cancel each other and we will left with,

$0\leq -d_{i_1}-d_{i_2}-d_{i_3}-\cdots-d_{i_k}$

which is not possible because of the strictly positive constraint placed on the $d$ variables, thus proving every feasible tour of this formulation has exactly one sub-tour starting and ending at the 'origin' city.

To prove the existence of $u$ variables for all feasible solutions, first let's consider the case where not trip takes place from the $i$th city to the $j$th city. That is, $x_{ij}=0$. Then, the constraint corresponding to $x_{ij}$ becomes,

$0\leq (C-u_i)+(u_j-d_j)$

Both the bracketed terms are positive because of the constraints place on the $u$'s and thus the constraint becomes non-binding. On the other hand, let's consider the most interesting case of $x_{ij}=1$.

Now the $u$'s can be given a very nice interpretation. A particular $u_i$ can be interpreted as the cumulative demand delivered so far in tour upto (and including) city $i$. With this, we can see that easily see that the inequality becomes,

$-d_j+C\leq C-d_j$

which is trivially true. Hope you enjoyed this.


Until then,
Yours Aye,
Me

Friday, September 22, 2017

Proof for the Expected Value Problem III


Let $ABC$ be a triangle with $AB=c$, $BC=a$, and $CA=b$. Let $D$, $E$ and $F$ denote the feet of the altitudes from $A$, $B$ and $C$ receptively such that $AD=h_a$, $BE=h_b$ and $CF=h_c$.

First off, we define some notations. Let $L$ be the length of the line drawn by selecting a random point $P$ in a triangle $ABC$ and let $X$ be the point where the random line intersects the triangle.

Let $\mathbb{E}_{\triangle ABC}(L|S_k)$ be the expected length of the line drawn as described in setup $S_k$ in the triangle $ABC$.

Setup 1 Select a random point in triangle $ABC$ and draw a line (towards $BC$) parallel to the altitude $AD$.

WLOG, we can chose the vertex $B$ to be the origin with the $x$-axis aligned with the side $BC$. Then we have,

$\displaystyle\mathbb{E}_{\triangle ABC}(L|S_1)=\frac{1}{\triangle ABC}\iint\limits_{(x,y)\in\triangle ABC}|PX|\,dy\,dx=\frac{1}{\triangle ABC}\iint\limits_{(x,y)\in\triangle ABC}y\,dy\,dx=\frac{h_a}{3}$

The last equality follows by recognizing the integral as the $y$-coordinate of the centroid of the triangle $ABC$.

Setup 2 Given a point $M$ between $B$ and $D$, select a random point in triangle $ABC$ and draw a line (towards $BC$) parallel to $AM$ until it meets the triangle. Let $t$ be the angle between $AM$ and $AD$ (measured clockwise from $AD$).

Using the same co-ordinate system as above, this time we have,

$
\begin{align}
\displaystyle\mathbb{E}_{\triangle ABC}(L|S_2,M)&=\frac{1}{\triangle ABC}\iint\limits_{(x,y)\in\triangle ABC}|PX|\,dy\,dx\\
&=\frac{1}{\triangle ABC}\iint\limits_{(x,y)\in\triangle ABC}\frac{y}{\cos t}\,dy\,dx=\frac{h_a}{3\cos t}=\frac{|AM|}{3}
\end{align}
$

Setup 3 Given a point $M$ between $B$ and $D$, select a random point in triangle $ABC$ and draw a line (away from $BC$) parallel to $AM$ until it meets the triangle. Let $t$ be the angle between $AM$ and $AD$ (measured clockwise from $AD$).

Now we do a case distinction based on whether the random point is in $\triangle ABM$ or $\triangle AMC$.

$
\begin{align}
\displaystyle\mathbb{E}_{\triangle ABC}(L|S_3,M)&=\frac{\triangle MAB}{\triangle ABC}\mathbb{E}_{\triangle MAB}(L|S_2,A)+\frac{\triangle MCA}{\triangle ABC}\mathbb{E}_{\triangle MCA}(L|S_2,A)\\
&=\frac{\triangle ABM}{\triangle ABC}\frac{|MA|}{3}+\frac{\triangle AMC}{\triangle ABC}\frac{|MA|}{3}\\
&=\frac{|AM|}{3}\\
\end{align}
$

Surprisingly, it doesn't matter whether we draw the line towards or away from the edge $BC$, the expected value remains the same.

Setup 4 Given a point $M$ between $B$ and $D$, select a random point in triangle $ABC$ and draw a line (either towards or away from $BC$) parallel to $AM$ until it meets the triangle. Let $t$ be the angle between $AM$ and $AD$ (measured clockwise from $AD$).

From the previous discussion, we have,

$\displaystyle\mathbb{E}_{\triangle ABC}(L|S_4,M)=\frac{|AM|}{3}$

This can be equivalently written as,

$\displaystyle\mathbb{E}_{\triangle ABC}(L|S_4,t)=\frac{h_a}{3\cos t}$


Setup 5 Select a random point in triangle $ABC$ and draw a line (either towards or away from $BC$) until it meets the triangle, such that the angle $t$ between $PX$ and $AD$ (measured clockwise from $PX$) satisfies $0 \leq t \leq \tan^{-1}\left(\frac{BD}{AD}\right)$.

Using the law of the total probability,

$
\begin{align}
\mathbb{E}_{\triangle ABC}(L|S_5)&=\mathbb{E}(\mathbb{E}_{\triangle ABC}(L|S_4,t))\\
&=\frac{1}{\tan^{-1}\left(\frac{BD}{AD}\right)}\int\limits_0^{\tan^{-1}\left(\frac{BD}{AD}\right)}\frac{h_a}{3\cos t}\,dt\\
\end{align}
$

We can use the fact that $\int\limits_0^{\tan^{-1}m}\sec t\,dt=\text{sinh}^{-1}m$, we have

$\displaystyle\mathbb{E}_{\triangle ABC}(L|S_5)=\frac{h_a}{3\tan^{-1}\left(\frac{BD}{AD}\right)}\text{sinh}^{-1}\left(\frac{BD}{AD}\right)$


Setup 6 Select a random point in triangle $ABC$ and draw a line (either towards or away from $BC$) until it meets the triangle, such that the angle $t$ between $PX$ and the side $AB$ (measured clockwise from $PX$) satisfies $0 \leq t \leq \angle A$.

We again make a case distinction based on where the ray $PX$ intersects the side $BC$ - either in $BD$ or in $DC$. We can separate the angle into two cases based on this. Using the previous result, we have,

$\displaystyle\mathbb{E}_{\triangle ABC}(L|S_6)=\frac{h_a}{3\angle A}\left(\text{sinh}^{-1}\left(\frac{BD}{AD}\right)+\text{sinh}^{-1}\left(\frac{DC}{AD}\right)\right)$

This, after some basic simplifications, results in,

$\displaystyle\mathbb{E}_{\triangle ABC}(L|S_6)=\frac{h_a}{3\angle A}\text{csch}^{-1}\left(\frac{p}{a}\frac{s-a}{p-a}\right)$

where $p$ and $s$ are the perimeter and semi-perimeter of $\triangle ABC$ respectively.

Now we get into the final part of the proof.

Setup 7 Select a random point in triangle $ABC$ and draw a line at a random angle from that point until it meets the triangle.

We now again do a case distinction based on the angle and using the previous result, we finally have,

$
\begin{align}
\displaystyle\mathbb{E}_{\triangle ABC}(L)&=\sum_{x \in \{a,b,c\}}\frac{h_x}{3\pi}\text{csch}^{-1}\left(\frac{p}{x}\frac{s-x}{p-x}\right)\\
&=\frac{h_a}{3\pi}\text{csch}^{-1}\left(\frac{p}{a}\frac{s-a}{p-a}\right)+\frac{h_b}{3\pi}\text{csch}^{-1}\left(\frac{p}{b}\frac{s-b}{p-b}\right)+\frac{h_c}{3\pi}\text{csch}^{-1}\left(\frac{p}{c}\frac{s-c}{p-c}\right)
\end{align}
$

And hence the result. Hope you enjoyed this. I'll come up with something different the next time.

UPDATE (13 / 8 / 2020): Updating the 'boring calculation' used in Setup 6.

By the addition formulae for Inverse Hyperbolic sines,

$\displaystyle \text{sinh}^{-1}\left(\frac{BD}{AD}\right)+\text{sinh}^{-1}\left(\frac{CD}{AD}\right)=\text{sinh}^{-1}\left(\frac{CD}{AD}\frac{AB}{AD}+\frac{BD}{AD}\frac{AC}{AD}\right)$

Using the geometry of the triangle we know that,

$BD=c \cos B$, $CD=b \cos C$ and $AD=b \sin C=c \sin B$

$\displaystyle \text{sinh}^{-1}\left(\frac{BD}{AD}\right)+\text{sinh}^{-1}\left(\frac{CD}{AD}\right)=\text{sinh}^{-1}\left(\frac{\cos B+\cos C}{\sin B \sin C}\right)$

But
$\sin B \sin C=2\sin(B/2)\cos(B/2)\cdot 2\sin(C/2)\cos(C/2)=2\sin(B/2)\sin(C/2)\cdot 2\cos(B/2)\cos(C/2)$

With Sine and Cosine addition formula, this becomes,

$\sin B \sin C=(\cos(B/2+C/2)-\cos(B/2-C/2))(\cos(B/2+C/2)+\cos(B/2-C/2))=\cos^2(B/2+C/2)-\cos^2(B/2-C/2)$

Also, $\displaystyle \cos B+\cos C=2\cos(B/2+C/2)\cos(B/2-C/2)$

Therefore,

$\displaystyle \frac{\sin B \sin C}{\cos B+\cos C}=\frac{1}{2}\left(  \frac{\cos(B/2+C/2)}{\cos(B/2-C/2)}-\frac{\cos(B/2-C/2)}{\cos(B/2+C/2)}  \right)$

The rest follows by Mollweide's formula.

Until then,
Yours Aye
Me

Thursday, September 21, 2017

An Expected Value Problem III


In An Expected Value Problem, we found the expected length of a line segment drawn by picking a random point in a rectangle and choosing a random angle, and extending it until it meets the edge of a rectangle. We ask the same question here for an arbitrary acute angled triangle in this post.

Let $ABC$ be a triangle with $AB=c$, $BC=a$, and $CA=b$. Let $D$, $E$ and $F$ denote the feet of the altitudes from $A$, $B$ and $C$ receptively such that $AD=h_a$, $BE=h_b$ and $CF=h_c$. I considered this question in the same post above, but I was not able to solve it then.

But recently I collaborated with someone who gave me a very valuable hint which reduced the difficulty of the problem drastically. The idea pretty much solved the problem. In summary, if we denote the length of line segment as $L$, we have,

$
\begin{align}
\displaystyle\mathbb{E}(L)&=\sum_{x \in \{a,b,c\}}\frac{h_x}{3\pi}\text{csch}^{-1}\left(\frac{p}{x}\frac{s-x}{p-x}\right)\\
&=\frac{h_a}{3\pi}\text{csch}^{-1}\left(\frac{p}{a}\frac{s-a}{p-a}\right)+\frac{h_b}{3\pi}\text{csch}^{-1}\left(\frac{p}{b}\frac{s-b}{p-b}\right)+\frac{h_c}{3\pi}\text{csch}^{-1}\left(\frac{p}{c}\frac{s-c}{p-c}\right)
\end{align}
$

where $p$ and $s$ denote the perimeter and the semi-perimeter respectively.

Let's calculate the expected values for a few special cases.

$\mathbb{E}(1,1,1)\approx 0.30284835$ and $\mathbb{E}(3,4,5)\approx 1.100147755$

The interest in this question seems very low in the mathematical literature and I was not able to find any material in the internet to verify these values. However, a friend of mine wrote a simulation for the Pythagorean case and the result matched with the value given by the formulae.

Two things are to be mentioned here. First, even though we dealt with the same question for a triangle and a rectangle, note that the formulas are drastically different. Some may find it obvious that they are different but I had an intuition that they'll be pretty 'close' which turned out to be wrong.

Second, the individual terms in the above formulae can themselves are respective expected values for a different question. I'll follow up with the what those questions are and the proof of this formulae in the next few posts.


Until then,
Yours Aye
Me