Interpreting the interpreter

The latest Hanselminutes podcast is an interesting conversation with Jenny Lay-Flurrie. Jenny is deaf and has an interpreter, Belinda, present during the interview. Jenny speaks perfectly well in a beautiful British accent, but Belinda is there to help listen for her.

At one point Scott brings his microphone close to Belinda to pick up the sound of her hands moving, but she shakes her head “no.” A little later Jenny explains why. Interpreters are trained to not draw attention to themselves. They are supposed to be transparent. Scott was violating custom by paying attention to an interpreter, though for good reason: he was doing a sort of documentary on the process of interpreting itself and not just interviewing Jenny. I thought it was interesting that Jenny was interpreting for her interpreter. Though presumably Belinda has no physical communication disability, she was in a sense disabled by her position, forbidden by professional ethics from directly engaging with Scott.

Continued fractions with Sage

My previous post looked at continued fractions and rational approximations for e and gave a little Python code.  I found out later there’s a more direct way to do this in Python using Sage.

At its simplest, the function continued_fraction takes a real number and returns a truncated continued fraction representation. For example, continued_fraction(e) returns

[2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1]

Optionally, you can also specify the number of bits of precision in the real argument and the number of terms desired.

By calling the convergents method on the return value of continued_fraction(e) you can find a sequence of rational approximations based on the continued fraction. For example,

print continued_fraction(e).convergents()


[2, 3, 8/3, 11/4, 19/7, 87/32, 106/39, 193/71, 1264/465,
1457/536, 2721/1001, 23225/8544, 25946/9545, 49171/18089,
517656/190435, 566827/208524, 1084483/398959,
13580623/4996032, 14665106/5394991, 28245729/10391023].

To get higher precision output, you need higher precision input. For example, you could pass in


rather than simply e to tell Sage that you’d like to use the 200-bit representation of e rather than the default precision.

Rational approximations to e

This morning Dave Richeson posted a humorous fake proof that depends on the famous approximation 22/7 for pi. It occurred to me that nearly everyone knows a decent rational approximation to pi. Some people may know more. But hardly anyone, myself included, knows a decent rational approximation for e.

Another approximation for pi is 355/113. I like this approximation because it’s easy to remember: take the sequence 113355, split it in the middle, and make it into a fraction. It’s accurate to six decimal places, which is sufficient for most practical applications.

The approximations 22/7 and 355/113 are part of the sequence of approximations coming from the continued fraction approximation for pi. So to come up with rational approximations for e, I turned to its continued fraction representation.

The best analog of the approximation 22/7 for pi may be the approximation 19/7 for e. Obviously the denominators are the same, and the accuracy of the two approximations is roughly comparable.

Here’s how you can make your own rational approximations for e. Find the coefficients in the continued fraction for e, for example here. You can turn this into a sequence of approximations by using the following Python code:

from __future__ import division
from math import e

e_frac = [2,1,2,1,1,4,1,1,6,1,1,8]

def display(n, d, exact):
    print n, d, n/d, n/d - exact

def approx(a, exact):
    # initialize the recurrence
    n0 = a[0]
    d0 = 1
    n1 = a[0]*a[1] + 1
    d1 = a[1]

    display(n0, d0, exact)
    display(n1, d1, exact)

    for x in a[2:]:
        n = x*n1 + n0 # numerator
        d = x*d1 + d0 # denominator
        display(n, d, exact)
        n1, n0 = n, n1
        d1, d0 = d, d1

approx(e_frac, e)

This will print the numerator, denominator, value, and error for each approximation. You could include more terms in the continued fraction for e if you’d like. Here are some of the results: 19/7, 87/32, 106/39, etc. Unfortunately it doesn’t look like there are any approximations as memorable as 355/113 for pi.

You could also use the code to create rational approximations to other numbers if you’d like. For example, you can find the continued fraction expansion for pi here and use the code above to find rational approximations for pi.

Update: There’s a more direct way to find continued fractions and rational approximations in Python using Sage. See the next post.

Footnote: The continued fraction coefficients for e have a nice pattern:
… 1, 1, 4, 1, 1, 6, 1, 1, 8, … 1, 1, 2k, 1, 1, 2k+2, …

Related posts:

For daily posts on analysis, follow @AnalysisFact on Twitter.

AnalysisFact twitter icon

Python / Emacs setup

When I got a new computer a few days ago, I installed the latest version of Emacs, 24.2, and broke my Python environment. I decided to re-evaluate my environment and start over. I asked a question on the Python Google+ group and here’s a summary of the Emacs packages recommended.

  • python-mode
  • rainbow-mode, rainbow-delimiters-mode
  • flymake-mode (hooked up to flymake-pyflakes)
  • linum-on
  • jedi
  • pycheckers + pyflakes
  • rope
  • electric-pair
  • show-paren
  • auto-complete
  • yassnippets

What recommendations do you have for packages? Links to relevant articles?

It might be better to leave your comments on Google+ rather than here so the answers will be in one place.

Self-employment FAQ

Today is my first day of full-time self-employment. Here are some of the questions people have been asking. Note that my answers are my answers as of today and subject to change.

Do you have health insurance?


Are you staying in Houston?


Will you be working from home?

I’ll be traveling more but commuting less. I’ll either walk to my study or fly out of town. No more spending 2-3 hours on freeways driving to work and back.

Will you come work for us as a salaried employee?

No thank you. Maybe we could discuss a retainer arrangement instead.

Will you be hiring other consultants?

I will be partnering with other consultants — trading favors, sharing leads, subcontracting, etc. — but I do not want to have employees at this time.

What kind of work will you be doing?

Anything I can do well that pays well.

Will you be doing mostly medical statistics?

I’m doing some medical statistics, but most of my consulting lately has been in other sectors: software, manufacturing, legal, etc. Applied math cuts across industry sectors.

Teaching an imbecile to play bridge

From Data and Reality:

The thing that makes computers so hard to deal with is not their complexity, but their utter simplicity. … The real mystique behind computers is how anybody can manage to get such elaborate behavior out of such a limited set of basic capabilities. The art of computer programming is somewhat like the art of getting an imbecile to play bridge or to fill out his tax return by himself. It can be done, provided you know how to exploit the imbecile’s limited talents, and are willing to have enormous patience with his inability to make the the most trivial common sense deductions on his own.

Emphasis added.

The quote comes from the 1st edition, published in 1978, because that’s what I ran across. The link is to the 3rd edition, published last year.

Statistics stories wanted

Andrew Gelman is trying to collect 365 stories about life as a statistician:

So here’s the plan. 365 of you write vignettes about your statistical lives. Get into the nitty gritty—tell me what you do, and why you’re doing it. I’ll collect these and then post them at the Statistics Forum, one a day for a year. I think that could be great, truly a unique resource into what statistics and quantitative research is really like. Also it will be perfect for the Statistics Forum: people will want to tune in every day to see what comes next.

If you’re interested in contributing, please contact Andrew. You can read more about the project here and you can find Andrew’s contact info here.

Narcissus prime in Python

I’ve been looking back on some of my blog posts that included Mathematica code to see whether I could rewrite them using Python. For example, I rewrote my code for finding sonnet primes in Python a few days ago. Next I wanted to try testing the Narcissus prime.

Futility closet describes the Narcissus prime as follows:

Repeat the string 1808010808 1560 times, and tack on a 1 the end. The resulting 15601-digit number is prime, and because it’s a palindrome made up of the digits 1, 8, and 0, it remains prime when read backward, upside down, or in a mirror.

My Mathematica code for verifying this claim is posted here. Here’s Python code to do the same thing:

    from sympy.ntheory import isprime
    isprime(int("1808010808"*1560 + "1"))

This does indeed return True. However, the Mathematica code ran for about 2 minutes and the SymPy code took 17.5 hours, about 500 times longer.

My next endeavor

After over 12 years at MD Anderson Cancer Center, I turned in my resignation last week. I’m leaving my steady job for self-employment.

I have done occasional consulting for 20 years, but I haven’t done it as my only source of income before, other than a salaried position I once had with a consulting company. I enjoy consulting, and I’ve wanted for some time now to do it for a living. Recently, my wife and I agreed that this was the time to make the leap.

I plan to offer consulting in applied math, statistics, and software development. At a high level, this means helping businesses formulate and solve problems, as well as helping them to interpret and apply the solutions. At a lower level, this means using Bayesian inference, number crunching, or whatever else it takes to get the job done. I am also available for speaking and training.

The hard part of consulting is finding enough work. I would appreciate your help in this. Please contact me if you would like to work together, or if you have suggestions for people I should talk to.

Management principle from Dune

The other day Atamert Ölçgen quoted a passage from Dune in response to something I’d posted on Google+. I haven’t read the Dune books, but the passage puts generalists in a favorable light, and since I’m something of a generalist, I’m inclined to like such quotes. Here’s the part I particularly liked. It says that the mentat must be able to say

There’s no real mystery about this at the moment. This is what we want now. It may prove wrong later, but we’ll correct that when we come to it.

Too often we act as if every decision is weighty and permanent. Of course some decisions are weighty and permanent, but most are not. Wisdom is knowing which decisions are and which are not. Sometimes it pays to not try to look too far ahead, conceding that if you’re wrong “we’ll correct that when we come to it.”

Related posts:

Elementary statistics book recommendation

I’ve thought about making a personal FAQ page. If I do, one of the questions would be what elementary statistics book I recommend. Unfortunately, I don’t have an answer for that one. I haven’t seen such a book I’d recommend enthusiastically.

When asked for book recommendations, people will often recommend the textbook used in a course they had. But I never had an elementary statistics course. I had a PhD in math before I became interested in statistics, so I learned statistics from more advanced books. I’ve looked at a number of elementary books, but I haven’t found one I’m excited about.

Elementary statistics books may do more harm than good. They often brush difficulties under the rug. They avoid mathematical and philosophical details. They don’t define terms carefully, and even say things that are false. And they imply that statistical analysis is a matter of applying a set of rules by rote. (And it is, for many statisticians. But that’s a topic for another time.) If a statistics book doesn’t have fairly steep prerequisites, it will be hard for it not to be misleading.

This leads to another frequently asked question: Do I intend to write my own elementary statistics book? No. I don’t know whether I could write such a book that I’d be proud of. And if I could, it would take more time than I could afford to devote to it at this point in my life.

(I’ll write soon about what “this point in my life” is. If you don’t want to wait, here’s the news in a nutshell.)

Rifle-shaped wine bottle

Ever since I posted a photo of an odd wine bottle four years ago, I’ve periodically had people leave comments or send me email about odd wine bottles!

Here’s the latest, an Italian wine bottle shaped like a riffle:

Here’s a close-up of the cap.

If you know anything about this bottle of wine or what it might be worth, let me know and I’ll pass the info on to the fellow who sent me the photos.