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()

produces

[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

RealField(200)(e)

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 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

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?

Yes.

Are you staying in Houston?

Yes.

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 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.