Mathematica Conversations 1: Sequences and Mathematica

Students and teachers using Mathematica can immediately begin to explore patterns in sequences.

by William B. Martin III

Since the invention of the counting numbers, sequences have been an important part of mathematics. Although many of the simplest problems in mathematics have to do with sequences, the study of sequences leads to results with significant implications. Mathematica, with its easily defined recursive functions and ability to handle lists, is admirably suited to the study of sequences. In this article, I will show how to generate sequences and how to write Mathematica functions to analyze them.

SEQUENCES GENERATED BY POLYNOMIALS

Many simple sequences, such as the triangular numbers: 1,  3,  6, 10,  . . ., are generated with polynomials. In this case (Subscript[t, n]) = n(n+1)/2,   n = 1,2,3,... where  (Subscript[t, n]) is the nth triangular number. In Mathematica:

seq1  =  Table[(1/2) n (n + 1), {n, 1, 10}]

This is a list of the first 10 triangular numbers. (Unless otherwise stated, all of our polynomial-generated sequences will start with n = 1, and n will be incremented by 1.) 

Suppose we did not know the generating polynomial for the triangular numbers and were simply presented with the numbers 1,3,6,10,... . One of the basic tools of sequence analysis is to take differences between successive terms. The gaps function will do this.

gaps[s_List] := 
      Table[s[[k + 1]] - 
          s[[k]], {k, 1, 
          Length[s] - 1}];

Apply gaps to our first output:

gaps[seq1]

We have an obvious pattern! Apply gaps again.

gaps[%]

The differences become constant. In general, the nth order differences of a sequence generated by an nth degree polynomial are constants. Thus we have a test for the degree of the generating polynomial. It would be convenient to have a recursive gaps function that would apply gaps any number of times. We can define recursiveGaps with the two commands:

\(recursiveGaps[s_List, \ 1] := gaps[s]; 

    recursiveGaps[s_List, \ m_]\  := \ gaps[recursiveGaps[s, m - 1]]; \)

Now we can do two successive applications of gaps to {1,3,6,...55}:

recursiveGaps[seq1, 2]

The question remains of finding the generating polynomial. There are at least two ways of doing it. Assuming a second-degree polynomial, we could use the general quadratic

               a (n^2)  + b n  + c = (Subscript[t, n]),

We can substitute three pairs of values (n, (Subscript[t, n])) to get three equations in the three unknowns  a, b and c. This method is good practice for our students in solving systems of equations.

Students should also be encouraged to pursue more elegant methods for studying integer sequences. For example, the following expression gives the nth term of the kth-order differences for the sequence {(Subscript[s, n])}:

diffTerm[s_List, n_, l_] := recursiveGaps[s, l][[n]];

The next expression (Sloane 1973) gives the (n + 1) term of a quadratic sequence {(Subscript[s, n])} for which a formula is not known:

\(\(nTerm[s_List, n_]\  := \ 
      s[\([1]\)]\  + \ diffTerm[s, \ 1, 1]\ Binomial[n, \ 1]
		 + \ 
        diffTerm[s, \ 1, 2]\ Binomial[n, \ 2]; \)\)

Take, for example, the sequence of triangular numbers.

tn10  =  {1, 3, 6, 10, 15, 21, 28, 36, 45, 55};

nTerm[tn10,  4]

Substituting n - 1 to get the general nth term:

nTerm[tn10,  n - 1] // Together

Students can create arbitrary quadratic expressions and test them with this formula. They can be encouraged to explore a generalization of the formula and test it on higher-order expressions, including square and pentagonal numbers. The Fibonacci numbers also provide an interesting test.

ABOUT THE AUTHOR

William B. Martin III is a mathematics instructor at Pima Community College, Arizona.

William B. Martin III
Pima Community College
8181 East Irvington Road
Tucson, Arizona 85709-4000
wmartin@pcc.edu