## Thursday, June 30, 2011

### Governors of Illinois (The Daily Show Edition)

Jon Stewart (2:50): Here's the truly astonishing part of this story. Rod Blagojevich is now the 4th out of the last 7 elected governors of Illinois to be convicted of a felony. 4 out of the last 7. 57%. If you were an individual in Illinois, you would have a better chance of avoiding jail by flipping a coin - heads being jail, tails being no jail - than by being elected governor of Illinois.

Jon Stewart (3:21): Let's say you're the present governor of Illinois and you're in a room with a former governor of Illinois on your right and a former governor of Illinois on your left, chances are the room you are in is jail.

Any interesting questions we can ask here?

## Monday, June 27, 2011

### Cleverbot

Around April, a student asked me if I knew of a game called Cleverbot. I didn't. He tells me that the goal of the game is to convince Cleverbot that it is a robot by:
1. Making Cleverbot admit that it's a robot
2. Trick Cleverbot into saying that it's a robot.
He wanted me to try it, so I took a look. Turns out it's not a game. It's a chatbot that tries to mimic a human in conversation. Here are some of the screenshots from my chat with Cleverbot. You decide how human it appears (my text in black and Cleverbot's is in blue):

You can see the chat above either as a win or fail. You could see it as a fail for Cleverbot because I tricked it into saying that it is a robot. Or you could see it as a win for Cleverbot because Cleverbot seems to have figured out my logic and answered me correctly. However, I think it's a qualified win. Real humans would've understood the context and clarified their meaning by saying that "I am a robot, but by robot I really mean that I am human" so as to clarify that they knew that it was a trick to get them to say that they are robots.

So I continue. After a few more screens of chat we get:
In this context, the "Be quiet" appears to be an acknowledgement by Cleverbot that it is a robot. Behaviorally, it's very human. Logically, though, it admitted to being a robot. When I ask for clarification with "So you agree?" the "Yes" from Cleverbot confirms it. It's possible Cleverbot does not check previous questions for context and may just agree in general. Either way, it's another sign that it is not human.

I try another way of getting it to explicitly state or imply that it is a robot.
Seems Cleverbot employs misdirection tactics to avoid answering in a way that gives it away. So we continue with our chat. Somehow it brings up Harry Potter and we have this exchange:

Not bad! It guesses that Jean-Luc is a female. In English, Jean is more common as a female name. It falls for the I_am_a_robot trick for my name. What it shows though is there's some retention or some attempt to use context and our chat history for information to be used in responses. Very human!

Cleverbot came with the following notice.
PLEASE NOTE: Cleverbot learns from real people - things it says may seem inappropriate - use with discretion, and at YOUR OWN RISK
Apparently it has won a Turing Test competition. According to the site:
A special version of the Cleverbot application has won the BCS Machine Intelligence Competition 2010, after taking part in a quick-fire Turing Test.

Cleverbot was running with notably more power behind it than is possible for the online version, with 24 separate instances conferring on their answer.

10 volunteers talked for 2 minutes each using a plain text interface, and the whole of the event audience voted on 'how human' each conversation appeared to be.

Cleverbot achieved an average rating of 42.1% human!
I was very impressed! My prior experiences with chatbots is that you can quickly figure out whether it is a chatbot with about 2 or 3 questions. Most aren't on topic or use misdirection or generic answers. Cleverbot's use of chats with humans to respond gets it a little closer. Behaviorally, some of the ways it answers also seem human.

You can judge for yourself how convincing it is. You can talk to Cleverbot here.

## Friday, June 24, 2011

### Learning Math

Saw the following comic at Abstruse Goose. The title is Nocturne.

(Image is CC BY-NC 3.0)

My family moved often when I was little. My parents were also too busy working to have time to watch over me. I was often asleep by the time they got home and awake only after they've left for work. Learning math made me feel less lonely. I thought to myself that what was going through my head also was also going through someone else's head hundreds or thousands of years ago. There was this sense of connection to someone I've never met. It's as if we grokked one another (I didn't know the word at the time) and had this shared marvel at the mathematical beauty and wonder about an universal truth. We were part of some special club. My parents weren't completely absent. So math wasn't to me what it was for Bertrand Russell. It nonetheless helped me deal with my sense of loneliness.

It would be a long time before I moved past the consumer model of the shared experience depicted above. Math is more than just retracing steps and appreciating the beauty of what's been done. I would've liked the comic more if the protagonist were playing the musical piece, even more if he were playing a variation or was creating a piece with same theme. When I first read it though, it got me reminiscing about why I first fell in love with the subject that I teach.

## Wednesday, June 22, 2011

### Ngon Dartboard Probability Limit

Continuing from our last post on simulations where we compared our solution analytically and from simulations to answer the following question:
Given an integer n>2, what is the probability that a randomly-thrown dart will land closer to the center of the dartboard than to an edge of a regular polygon with n sides? What is the probability as n approaches infinity?

This post will be focused on the limit as n approaches infinity.

We evaluated our formula:
\begin{align*} P \left ( d_{c}\lt d_{e} \right) &= \frac{ tan^3 \frac{\pi}{2n} + 3 tan \frac{\pi}{2n} }{ 6 tan \frac{\pi}{n} } \\ \end{align*}
...for several different values of n.

Let's also try to evaluate using the built-in definite integral function in the TI calculator. Doing this way, we should be able to bypass all steps to get to the end by just setting up the question.
\begin{align*} P \left ( d_{c}\lt d_{e} \right) &= \frac{A_{shaded} }{A_{triangle} } \\ &= \frac { \frac{1}{2} \int_{0}^{\frac{\pi}{n}} \left ( \frac{ 1 }{1 + cos \theta} \right ) ^{2} d\theta }{ \frac{1}{2} tan \frac{\pi}{n} } \\ &= \frac { \int_{0}^{\frac{\pi}{n}} \left ( \frac{ 1 }{1 + cos \theta} \right ) ^{2} d\theta }{ tan \frac{\pi}{n} } \end{align*}

To do it quickly on a TI calculator we'll be using the TABLE feature. We'll enter the equations into Y1 and Y2 and we'll go TABLE SETUP (TBLSET) and change Indpnt: to Ask and enter the values of n:
Y1=(tan(π/(2X))^3+3tan(π/(2X)))/(6tan(π/X))
For the definite integral we have:
Y2=fnInt(1/(1+cos(A))2,A,0,π/X)/tan(π/X)
Using a TI-83 Plus we have:
n Probability
Y1 Y2
3 .185185185185.185185185185
4 .218951416497.218951416497
5 .231475730333.231475730333
6 .237604307034.237604307034
7 .241091327922.241091327922
8 .243275188464.243275188464
9 .244737577398.244737577398
10 .245766620771.245766620771
100 .249958864808.249958864808
1,000 .249999588765.249999588765
10,000 .249999995888.249999995888
100,000 .249999999959.249999999959
1,000,000 .25.25
109 .25.25
1025 .25.25
1050 .25.25
1075 .25.25
1098 .25.25
1099 .250
That's not a typo in the last cell of the table, but it's an issue for some other post. It would seem that the limit as n approaches infinity of our probability is .25.

It matches nicely the graph of prob vs n created by Andy Rundquist:
The graph of the function is asymptotic to 0.25 as n increases. Besides looking at the graph, we can also evaluate:
\begin{align*} L &= \lim_{x \rightarrow \infty } \frac{ tan^3 \frac{\pi}{2x} + 3 tan \frac{\pi}{2x} }{ 6 tan \frac{\pi}{x} } \\ &= \frac{ 0 + 0 }{ 0 } \\ &= \frac{ 0 }{ 0 } \\ \end{align*}
But we encounter an indeterminate form, so we'll apply l'Hôpital's rule:
\begin{align*} \lim_{x \rightarrow \infty } \frac{ f(x) }{ g(x) } &= \lim_{x \rightarrow \infty } \frac{ f'(x) }{ g'(x) } \\ \end{align*}
Applying it, we obtain the following:
\begin{align*} L &= \lim_{x \rightarrow \infty } \frac{ tan^3 \frac{\pi}{2x} + 3 tan \frac{\pi}{2x} }{ 6 tan \frac{\pi}{x} } \\ &= \lim_{x \rightarrow \infty } \frac{ \frac{d}{dx} \left [ tan^3 \frac{\pi}{2x} + 3 tan \frac{\pi}{2x} \right ] }{ \frac{d}{dx} \left [ 6 tan \frac{\pi}{x} \right ] } \\ &= \lim_{x \rightarrow \infty } \frac{ 3 tan^2 \frac{\pi}{2x} sec^2 \frac{\pi}{2x} \left ( - \frac{\pi}{2x^2} \right ) + 3 sec^2 \frac{\pi}{2x}\left ( - \frac{\pi}{2x^2} \right ) }{ 6 sec^2 \frac{\pi}{x} \left ( - \frac{\pi}{x^2} \right )} \\ &= \lim_{x \rightarrow \infty } \frac{ \left ( - \frac{\pi}{x^2} \right ) \left( \frac{3}{2} tan^2 \frac{\pi}{2x} sec^2 \frac{\pi}{2x} + \frac{3}{2} sec^2 \frac{\pi}{2x} \right ) }{\left ( - \frac{\pi}{x^2} \right ) 6 sec^2 \frac{\pi}{x} } \\ &= \lim_{x \rightarrow \infty } \frac{ \frac{3}{2} tan^2 \frac{\pi}{2x} sec^2 \frac{\pi}{2x} + \frac{3}{2} sec^2 \frac{\pi}{2x} }{ 6 sec^2 \frac{\pi}{x} } \\ &= \frac{ \frac{3}{2} tan^2 (0) sec^2 (0) + \frac{3}{2} sec^2 (0) }{ 6 sec^2 (0) } \\ &= \frac{ \frac{3}{2} (0)^2 (1)^2 + \frac{3}{2} (1)^2 }{ 6 (1)^2 } \\ &= \frac{ 0 + \frac{3}{2} }{ 6 } \\ &= \frac{ 1 }{ 4 } = .25 \\ \end{align*}
Looks like we get the same answer.

Intuitively we know the answer should be one-fourth as n (the number of sides) increases. Because as n grows without bound, the polygon gets closer and closer to a circle. If you want a copy of the applet, click on File then Save As. Be sure to move some of the controls and check and uncheck the checkboxes.

This is a Java Applet created using GeoGebra from www.geogebra.org - it looks like you don't have Java installed, please go to www.java.com

Given that the distance from the focus (center of polygon) to the sides of the polygon (directrix) is twice that of the focus to the parabola (edge of shaded region). We have R=2r. So using area of a circle, we have:
\begin{align*} P \left ( d_{c}\lt d_{e} \right) &= \frac{A_{shaded} }{A_{polygon} } \\ &= \frac { \pi r^2 }{ \pi R^2 } \\ &= \frac { \pi r^2 }{ \pi (2r)^2} \\ &= \frac { \pi r^2 }{ 4 \pi r^2}\\ &= \frac { 1 }{ 4} \\ \end{align*}
Turns out, the case that is easiest to solve is when n approaches infinity where the polygon gets closer to a circle.

Square Dartboard Probability
Ngon Dartboard Probability
Ngon Dartboard Probability Simulation
Ngon Dartboard Probability Limit

## Monday, June 20, 2011

### Ngon Dartboard Probability Simulation

While I was working on the extension problem, Andy Rundquist sent me the results of his simulations along with the screencast showing how he did it in Mathematica.

Evaluating the formula from the last post
\begin{align*} P \left ( d_{c}\lt d_{e} \right) &= \frac{ tan^3 \frac{\pi}{2n} + 3 tan \frac{\pi}{2n} }{ 6 tan \frac{\pi}{n} } \\ \end{align*}
... for several different n, we have:
n Probability Andy's Simulation
3 .1851851852

4 .2189514165

5 .2314757303

6 .237604307

7 .2410913279

8 .2432751885
9 .2447375774
10 .2457666208
Most of the results are fairly close. I think seeing the results of Andy's simulations definitely gave me a little more confidence about posting my attempted solution online.

Some of the numbers from the simulations are a little off and that's expected. Run the simulation a few more times and you'll get a slightly different result every time. They fluctuate around the "true" proportion of darts that will land closer to the center. For the simulation diagrams above, Andy used 30,000 as the number of trials.

Extension (Statistics): What is the number of trials that should be used for simulations if we want most of our simulations to be near our "true" proportion (e.g. within 0.01, 0.001, 0.0001, etc)?

Square Dartboard Probability
Ngon Dartboard Probability
Ngon Dartboard Probability Simulation
Ngon Dartboard Probability Limit

### Ngon Dartboard Probability

This is an update to the Square Dartboard Probability question found at Infinigons.

The extension I offered was:
Given an integer n>2, what is the probability that a randomly-thrown dart will land closer to the center of the dartboard than to an edge of a regular polygon with n sides? What is the probability as n approaches infinity?

The solution below concerns only the first part of the extension question about probability that a randomly-thrown dart will land closer to the center than to any edge in a regular ngon.

Continuing from the diagram in the last post.

Taking advantage of symmetry, we need to only focus only on a slice.

For the case where n=4 (square), the probability will be the ratio of 8 times the area of the shared region divided by 8 times the area of the triangle. Turns out, the 8s reduce to 1 so we need only find the ratio of area of shaded region divided by area of triangle.

To find the area of the shaded region without solving for the intersection of the parabola and the radius, we'll use polar coordinates.

The equation for the parabola is given by
\begin{align*} r &= \frac{ 1 }{1 + cos \theta} \end{align*}
The area of the shaded region is given by
\begin{align*} A_{shaded} &= \frac{1}{2} \int_{0}^{\frac{\pi}{n}} r^{2} d\theta \\ &= \frac{1}{2} \int_{0}^{\frac{\pi}{n}} \left ( \frac{ 1 }{1 + cos \theta} \right ) ^{2} d\theta \end{align*}
where n is the number of sides of the ngon.

Using the half-angle formula and noticing that all angles are in quadrant I, we have:
\begin{align*} cos \frac{\theta}{2} &= \sqrt{ \frac{1 +cos \theta}{2}} \\ cos^2 \frac{\theta}{2} &= \frac{1 +cos \theta}{2} \\ 2cos^2 \frac{\theta}{2} &= 1 +cos \theta \\ \frac{1}{2} sec^2 \frac{\theta}{2} &= \frac{1}{1 + cos \theta} \end{align*}

Returning to the area of the shaded region an using the trigonometric identities, we have:
\begin{align*} A_{shaded} &= \frac{1}{2} \int_{0}^{\frac{\pi}{n}} \left ( \frac{ 1 }{1 + cos \theta} \right ) ^{2} d\theta \\ &= \frac{1}{2} \int_{0}^{\frac{\pi}{n}} \left ( \frac{1}{2}sec^2 \frac{\theta}{2} \right ) ^{2} d\theta \\ &= \frac{1}{8} \int_{0}^{\frac{\pi}{n}} sec^4 \frac{\theta}{2} d\theta \\ &= \frac{1}{8} \int_{0}^{\frac{\pi}{n}} sec^2 \frac{\theta}{2} \left ( tan^2 \frac{\theta}{2} + 1 \right ) d\theta \\ &= \frac{1}{8} \int_{0}^{\frac{\pi}{n}} sec^2 \frac{\theta}{2} tan^2 \frac{\theta}{2} + sec^2 \frac{\theta}{2} d\theta \\ &= \frac{1}{8} \int_{0}^{\frac{\pi}{n}} sec^2 \frac{\theta}{2} tan^2 \frac{\theta}{2}d\theta + \frac{1}{8} \int_{0}^{\frac{\pi}{n}} sec^2 \frac{\theta}{2} d\theta \\ \end{align*}
Using substitution
\begin{align*} u &= tan \frac{\theta}{2} \\ du &= \frac{1}{2} sec^2 \frac{\theta}{2} d\theta\\ 2 du &= sec^2 \frac{\theta}{2} d\theta \end{align*}
Another substitution
\begin{align*} v &= \frac{\theta}{2} \\ dv &= \frac{1}{2} d\theta \\ 2 dv &= d\theta \end{align*}
we have:
\begin{align*} A_{shaded} &= \frac{1}{8} \int_{0}^{\frac{\pi}{n}} sec^2 \frac{\theta}{2} tan^2 \frac{\theta}{2}d\theta + \frac{1}{8} \int_{0}^{\frac{\pi}{n}} sec^2 \frac{\theta}{2} d\theta \\ &= \frac{1}{8} \int_{0}^{tan\frac{\pi}{2n}} u^2 2 du + \frac{1}{8} \int_{0}^{\frac{\pi}{2n}} sec^2 v 2 dv \\ &= \frac{1}{8} \left [ \frac{ 2 u^3 }{3} \right ]_{0}^{ tan\frac{\pi}{2n}} + \frac{1}{8} \left [ 2 tan v \right ]_{0}^{\frac{\pi}{2n}} \\ &= \frac{1}{8} \left [ \frac{ 2 tan^3 \frac{\pi}{2n} }{3} - 0 \right ] + \frac{1}{8} \left [ 2 tan \frac{\pi}{2n} - 0 \right ] \\ &= \frac{1}{12} tan^3 \frac{\pi}{2n} + \frac{1}{4} tan \frac{\pi}{2n} \\ \end{align*}
In retrospect, it would've been cleaner if I worked on the indefinite integral and left out the lower and upper limit of integration.

For the area of the triangle, we need the length of base and height. The base is 1 and is the side adjacent to our central angle, the height is is the side opposite our angle:
\begin{align*} tan \frac{\pi}{n} &= \frac{h}{1} \\ tan \frac{\pi}{n} &= h \\ \end{align*}
So for the area of the triangle we have:
\begin{align*} A_{triangle} &= \frac{1}{2}bh \\ &= \frac{1}{2} \left ( 1 \right ) \left ( tan \frac{\pi}{n} \right ) \\ &= \frac{1}{2} tan \frac{\pi}{n} \\ \end{align*}
Combining the equations we have:
\begin{align*} P \left ( d_{c}\lt d_{e} \right) &= \frac{A_{shaded} }{A_{triangle} } \\ &= \frac{\frac{1}{12} tan^3 \frac{\pi}{2n} + \frac{1}{4} tan \frac{\pi}{2n} }{\frac{1}{2} tan \frac{\pi}{n} } \\ &= \frac{\frac{1}{12} \left ( tan^3 \frac{\pi}{2n} + 3 tan \frac{\pi}{2n} \right ) }{ \frac{1}{2} tan \frac{\pi}{n} } \\ &= \frac{ tan^3 \frac{\pi}{2n} + 3 tan \frac{\pi}{2n} }{ 6 tan \frac{\pi}{n} } \\ \end{align*}
So, given an integer n>2, the probability that a randomly thrown dart will land closer center than to the edge is:
\begin{align*} P \left ( d_{c}\lt d_{e} \right) &= \frac{ tan^3 \frac{\pi}{2n} + 3 tan \frac{\pi}{2n} }{ 6 tan \frac{\pi}{n} } \\ \end{align*}
... assuming no mistakes were made.

To verify for the case where n=4 (square):
\begin{align*} P \left ( d_{c}\lt d_{e} \right) &= \frac{ tan^3 \frac{\pi}{2n} + 3 tan \frac{\pi}{2n} }{ 6 tan \frac{\pi}{n} } \\ &= \frac{ tan^3 \frac{\pi}{8} + 3 tan \frac{\pi}{8} }{ 6 tan \frac{\pi}{4} } \\ \end{align*}
Using half-angle formula for tangent:
\begin{align*} tan \frac{\theta}{2} &= \frac{1 - cos \theta}{sin \theta} \end{align*}
Evaluating using the half-angle formula, we have:
\begin{align*} tan \frac{\pi}{8} &= tan \frac{\frac{\pi}{4}}{2}\\ &= \frac{1- cos \frac{\pi}{4}}{sin \frac{\pi}{4}}\\ &= \frac{1- \frac{\sqrt{2}}{2}}{\frac{\sqrt{2}}{2}}\\ &= \sqrt{2} - 1\\ \end{align*}
Cubing, we have:
\begin{align*} tan^3 \frac{\pi}{8} &= \left ( \sqrt{2} - 1 \right )^3 \\ &= 2\sqrt{2} - 3 (2) + 3\sqrt{2} - 1 \\ &= 5\sqrt{2} - 7 \\ \end{align*}
Returning to our case where n=4 (square):
\begin{align*} P \left ( d_{c}\lt d_{e} \right) &= \frac{ tan^3 \frac{\pi}{2n} + 3 tan \frac{\pi}{2n} }{ 6 tan \frac{\pi}{n} } \\ &= \frac{ tan^3 \frac{\pi}{8} + 3 tan \frac{\pi}{8} }{ 6 tan \frac{\pi}{4} } \\ &= \frac{ \left ( 5\sqrt{2} - 7 \right ) + 3 \left (\sqrt{2} - 1 \right ) }{ 6 \left ( 1 \right ) } \\ &= \frac{ 5\sqrt{2} - 7 + 3 \sqrt{2} - 3 }{ 6 } \\ &= \frac{ 8\sqrt{2} - 10 }{ 6 } \\ &= \frac{ 4\sqrt{2} - 5}{ 3 } \approx .2189514165 \end{align*}
...which matches Allison's solution and Ms. Cookie's solution.

I'll update soon about simulations to find probability and limits.

Square Dartboard Probability
Ngon Dartboard Probability
Ngon Dartboard Probability Simulation
Ngon Dartboard Probability Limit

## Saturday, June 18, 2011

### Square Dartboard Probability

Found a nice little puzzle over at Infinigons:
You have a square dartboard. What is the probability that a randomly-thrown dart will land closer to the center of the dartboard than to an edge?
Go on. Try it now.

Here are some of my sketches as I attempted solutions.
Here's a different formulation as I thought more about the question.
Here's a a quick check to see if I'm on the right path.

Extension: Given an integer n>2, what is the probability that a randomly-thrown dart will land closer to the center of the dartboard than to an edge of a regular polygon with n sides? What is the probability as n approaches infinity?

I had a lot of fun working this out. Be sure to read Allison's original post on problem solving, persistence, and fearlessness.

If you just want to see the solution, you can find it at the bottom of the next post. In that post, I first find the solution to the Ngon Dartboard Probability (the extension offered above) followed by finding the solution to the instance when n=4 or square.

Square Dartboard Probability
Ngon Dartboard Probability
Ngon Dartboard Probability Simulation
Ngon Dartboard Probability Limit

UPDATE: Added conditions and changed wording.