Home Lesson-4.1

Lesson 3.6

Math and Programming

Before closing this chapter, let us spend some time at the intersection of mathematics and programming.

Limits

Consider the following number:

It is known that . From this, it follows that . Now, consider the following sequence:

As becomes very large, the values in this sequence will become smaller and smaller. This is because, if you keep multiplying a fraction with itself, it becomes smaller and smaller. In mathematical terms, the limit of this sequence as tends to infinity is zero. Let us verify this programmatically:

Try this out for a few values of . For , the value is , which is so small that for all practical purposes, it is as good as zero.

 

Recurrence relation

Now, here is another fact. For every number , there are unique integers and such that:

For , this is obvious: . What about higher values of ? . We can prove this using mathematical induction. The following is a sketch of the inductive proof. If , then:

The equation given above defines what is called a recurrence relation: each new term in the sequence is a function of the preceding terms. In this sequence we have . For , the pair of equations given below forms the recurrence relation:

Loops are useful tools when it comes to computing terms in such sequences:

 

Rational Approximation

This in turn provides a way to approximate using rational numbers:

As becomes large, this approximation will become increasingly accurate. For example, here is an approximation after 100 iterations. It is accurate up to several decimal places!

Is any of this useful? I don't know. But honestly, who cares? We don't do things because they are useful. We do them because they are interesting. And all interesting things will find their use at some point of time in the future.