Sequences
A sequence is just a set of elements listed in a row. So A1, A2, A3, …, A10 (where subscripts indicate order) or Am, Am + 1, Am + 2, …, An are sequences. Most of our sequences will be numbers, but can be other things as well (e.g. sets, predicates, etc.) Will mostly be finite, but can be infinite like 1, 1/2, 1/3, 1/4, … ( the ellipses mean "and so forth".)

Notation:

  1. List in a row: a1, a2, …, an.
  2. Specifiy a general formula: an = 1/n, n = 1, 2, …, 10.

Example:
Consider 1/2, 1/3, 1/4, 1/5, …, 1/10. Find a formula for the general term of this sequence.

Some solutions:

an

=

1/n, n = 2, 3, …, 10

an

=

1/(n + 1), n = 1, 2, …, 9

an

=

1/(n + 2), n = 0, 1, …, 8

Operations with Sequences
Summing the terms of a sequence.
Example: Consider 1, 1/2, 1/3, …, 1/10. The sum is 1 + 1/2 + 1/3 + … + 1/10.
Notation:

Examples:

Sum of an Arithmetic Sequence:

 .

Sum of a Geometric Sequence:

.

Multiplying by a constant or an expression
If C is a constant,


Product notation
The notation for the product of a sequence of numbers is analogous to the notation for their sum. The Greek capital letter pi,
P , denotes a product. Generally, the product from k equals m to n of ak is the product of all the terms am, am + 1, am + 2,…, an. That is,

Theorem 4.1.1 Properties of Summations and Products
If am, am + 1, am + 2,… and bm, bm + 1, bm + 2,…are sequences of real numbers and c is any real number, then the following equations hold for any integer n
³ m:

Factorial Notation
The product of all consecutive integers up to a given integer occurs so often in mathematics that is given a special notation
Ύ factorial notation.
If n is a positive integer, we define n! = n(n -1)(n -2)…
Χ 2Χ 1. We also define 0! = 1.
Now, n! = n(n -1)! = n(n -1)(n -2)!

Example: n! / (n -3)! = n(n -1)(n -2)(n -3)! / (n -3)! = n(n -1)(n -2).

Sequences in Computer Programming
An important data type in computer programming consists of finite sequences known as one-dimensional arrays. A single variable in which a sequence of variables may be stored: Say we name an array of k Image objects "image", then image = image[0], image[1],  image[2]… image[k - 1]. Consider the following applet:
import java.awt.*;
import java.applet.*;

public class Clem extends Applet
{
    private int NUM_IMAGES = 10;
    private int MILLI_SECS = 250;
    private Image image[ ] = new Image[NUM_IMAGES];
    private int imageN = 0;

    public void init()
    {
        for (int k = 0; k < image.length; k++) // Read each image into the array
            image[k] = getImage(getDocumentBase(), "clem" + (k+1) + ".gif");
        setBackground(Color.white);
        setSize(440, 200);
    } // init()

    public void paint(Graphics g) 
    {
        g.drawImage(image[imageN], 20, 20, this);
        imageN = ++imageN % NUM_IMAGES;
        delay();
        repaint(); //recursive call to paint
    } // paint()

    private void delay() 
    { 
        try 
        {
            Thread.sleep(MILLI_SECS);
        } 
        catch (InterruptedException e) 
        {
            System.out.println(e.toString());
        }
    } // delay()
} // Clem

Application: Converting from base 10 to base 2 using repeated division by 2.
The quotient-remainder theorem gives use an efficient algorithm for calculating base conversion: Divide the number to be converted (dividend) by the base (divisor) to get a quotient q[0] and remainder r[0]. Repeat this operation, divide q[0] by the base to get a quotient q[1] and remainder r[1]. Continue in this manner until q[k] = 0 and we have r[k]. In general, if a nonnegative integer n is repeatedly divided by 2 until a quotient of zero is obtained and the remainders are found to be r[0], r[1], …, r[k].
n = 2k
Χ r[k] + 2k - 1Χ r[k - 1] + … + 22Χ r[2] + 21Χ r[1] + 20Χ r[0]. So the binary representation for n is then:
n = (r[k] r[k - 1] … r[2] r[1] r[0])2.

Example: Convert 25 to base 2.