[previous] [up] [next]     [index]
Next: Arithmetic Sequences and Series Up: Mathematical Examples Previous: Mathematical Examples

Sequences and Series

In pre-algebra and algebra, we encounter sequences (also known as progressions) of numbers. Here are three examples:

  1. 0, 2, 4, 6, 8;
  2. 1, 3, 5, 7, 9;
  3. 5, 10, 15, 20, 25.
The first two enumerate the first five even and odd natural numbers, respectively; the last one lists the first five positive integers, evenly divisible by 5. Sequences can also be infinite:
  1. 0, 2, 4, 6, 8, ...;
  2. 1, 3, 5, 7, 9, ...;
  3. 5, 10, 15, 20, 25, ...
Following mathematical tradition, infinite sequences end in ``...'' and the reader must determine how to find more of the terms in the sequence.

One way to understand sequences of numbers, especially infinite ones, is to match them up with an enumeration of the natural numbers. For example, the even and odd (natural) numbers match up like this:

displaymath72362

It is easy to see from this table that every even number is tex2html_wrap_inline72364 for its index i and that an odd number is tex2html_wrap_inline72368 .

Both statements can be translated into simple Scheme functions:

;; make-even : N -> N[even]
;; to compute the i-th even number 
(define (make-even i) 
  (* 2 i)) 
;; make-odd : N -> N[odd]
;; to compute the i-th odd number 
(define (make-odd i) 
  (+ (* 2 i) 1)) 

In short, functions from natural numbers to numbers are representations of infinite sequences.

A mathematical series is the sum of a sequence. The three finite sequences have the sums 20, 25, and 75, respectively. In the case of infinite sequences it is often interesting to consider a finite portion, staring with the first one.[footnote] For example, adding the first 10 even numbers yields 90, and adding the first 10 odd numbers yields 100. Computing a series is clearly a job for a computer. Here are functions that add up the first n odd or even numbers, respectively, using make-even and make-odd to compute the required numbers:

;; series-even : N -> number
;; to sum up the first
;; n even numbers 
(define (series-even n) 
  (cond 
    [(= n 0) (make-even n)] 
    [else (+ (make-even n) 
             (series-even (- n 1)))]))  
;; series-odd : N -> number
;; to sum up the first
;; n odd numbers 
(define (series-odd n) 
  (cond 
    [(= n 0) (make-odd n)] 
    [else (+ (make-odd n) 
             (series-odd (- n 1)))])) 

The two functions are natural candidates for abstraction and here is the result of following our basic abstraction recipe:

;; series : N (N -> number) -> number
;; to sum up the first n numbers in the sequence a-term, 
(define (series n a-term) 
  (cond 
    [(= n 0) (a-term n)] 
    [else (+ (a-term n) 
             (series (- n 1) a-term))])) 
The first argument specifies where the addition starts. The second argument of series is a function that maps a natural number to the corresponding term in the series. To test series, we apply it to make-even and make-odd:
;; series-even1 : N -> number
(define (series-even1 n) 
  (series n make-even)) 
;; series-odd1 : N -> number
(define (series-odd1 n) 
  (series n make-odd)) 

For over a century, mathematicians have used the Greek symbol tex2html_wrap_inline72374 to communicate about series. The two series above would be expressed as

displaymath72376

A true (lazy) mathematician would also replace make-even and make-odd by their definitions, that is, tex2html_wrap_inline72364 and tex2html_wrap_inline72368 , but we refrain from doing so to emphasize the analogy to our (well-organized) functions.


Exercises Exercise 23.1.1

Use local to create series-local from series-even and series-odd. Show with a hand-evaluation that (series-local make-even) is equivalent to series-evenSolution



[previous] [up] [next]     [index]
Next: Arithmetic Sequences and Series Up: Mathematical Examples Previous: Mathematical Examples

PLT