Wednesday, December 14, 2011

Getting a little help from Newton

I've posted here on a number of topics and derivations in fundamental calculus. This is about finding the derivative for powers of x with negative or fractional exponents. It seems a trivial proof, until I got stopped in my tracks by the cofactors of the binomial distribution.

The idea is to find the slope of the curve at x by adding a little bit to x, (x + h), calculating f(x + h), then subtract f(x), and finally divide by h and finding the limit as h gets very small. It works great for y = x2. But consider

y = x1/2

We want to do:

1/h [(x + h)1/2 - x1/2]

So thinking about the binomial expansion of the x + h term, I'm trying to figure what is the expansion for the 1/2 power? I mean, what can "n choose k" mean when n is 1/2?

The other thing that is a good approach here is to bring x out of the sum as follows

(x + h)1/2
= x1/2(1 + h/x)1/2

To expand this, we just remember Newton's super-duper binomial expansion from here. If the expression is

(1 + Q)m/n

the expansion is

1 + (m/n)Q + (m/n)((m-n)/2n)Q2 + (m/n)((m-n)/2n)((m-2n)/3n)Q3 + .. 

We only need the first two terms because Q2 is (h/x)2 which we will ignore. So we have for the expansion

(1 + h/x)1/2
= 1 + 1/2(h/x)

and the derivative is the limit as h => 0 of

1/h [x1/2(1 + 1/2(h/x)) - x1/2]
= 1/h (1/2 h) 1/x1/2
= 1/2 x-1/2

Similarly for m = -2 and n = 1 the first two terms are 1 and -2 and the expansion we need will be

(1 + (h/x))-2 = 
= 1 - 2(h/x)

The derivative is the limit as h => 0 of

1/h [x-2 (1 - 2(h/x)) - x-2] =
= 1/h x-2 (-2)(h/x)
= -2 x-3

Easy when you know how.

Basic Python for Bioinformatics

I've been silent online for the last few months, due to other commitments associated with my day job. But I haven't forgotten all of you in the ether.

Just before I got busy, I wrote a book about basic programming with Python using lots of biological examples. It's been proofed once or twice, but is not quite a beta version, so let's call it the gamma release. I want to push it out now, even it could certainly use some more polish, because it's not clear when I'll get the time to do that.

The target audience is the novice programmer who is interested in biology. However, it differs from most similar material because there are lots of biological and sequence analysis examples, collected from various sources including posts on this site.

Here is a screenshot of the toc for the middle section of the book.

The book is in html format (link to Dropbox zip). It was built using the Sphinx software. One can generate a pdf version of the book as well, but it suffers from the major limitation that cut-and-paste of the code loses the indentation. The version linked to here has code examples that can be pasted directly into a text file and executed, and often will work in the interpreter as well.

I hope you like it. I would be very grateful for comments, criticisms, corrections, and even complaints. Post 'em as comments here, or find my work email through the aboutme. Enjoy!