Sequences and Series

In pre-algebra and algebra, we encounter <#30939#>sequences<#30939#> (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:

#displaymath73340#

It is easy to see from this table that the every even number is #tex2html_wrap_inline73342# for its index <#30950#>i<#30950#> and that an odd number is #tex2html_wrap_inline73344#. Both statements can be translated into simple Scheme functions:

<#71414#>;; <#65800#><#30955#>make-even<#30955#> <#30956#>:<#30956#> <#30957#>N<#30957#> <#30958#><#30958#><#30959#>-;SPMgt;<#30959#><#30960#><#30960#> <#30961#>N<#30961#><#30962#>[<#30962#><#30963#>even]<#30963#><#65800#><#71414#>
<#71415#>;; to compute the <#65801#><#30964#>i<#30964#><#65801#>-th even number<#71415#> 
<#30965#>(d<#30965#><#30966#>efine<#30966#> <#30967#>(make-even<#30967#> <#30968#>i)<#30968#> 
  <#30969#>(*<#30969#> <#30970#>2<#30970#> <#30971#>i))<#30971#> 
<#71416#>;; <#65802#><#30977#>make-odd<#30977#> <#30978#>:<#30978#> <#30979#>N<#30979#> <#30980#><#30980#><#30981#>-;SPMgt;<#30981#><#30982#><#30982#> <#30983#>N<#30983#><#30984#>[<#30984#><#30985#>odd]<#30985#><#65802#><#71416#>
<#71417#>;; to compute the <#65803#><#30986#>i<#30986#><#65803#>-th odd number<#71417#> 
<#30987#>(d<#30987#><#30988#>efine<#30988#> <#30989#>(make-odd<#30989#> <#30990#>i)<#30990#> 
  <#30991#>(+<#30991#> <#30992#>(*<#30992#> <#30993#>2<#30993#> <#30994#>i)<#30994#> <#30995#>1))<#30995#> 
In short, functions from natural numbers to numbers are representations of infinite sequences. A mathematical <#30999#>series<#30999#> 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. For example, adding 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 <#65804#><#31001#>n<#31001#><#65804#> odd or even numbers, respectively, using <#65805#><#31002#>make-even<#31002#><#65805#> and <#65806#><#31003#>make-odd<#31003#><#65806#> to compute the required numbers:
<#71418#>;; <#65807#><#31008#>series-even<#31008#> <#31009#>:<#31009#> <#31010#>N<#31010#> <#31011#><#31011#><#31012#>-;SPMgt;<#31012#><#31013#><#31013#> <#31014#>number<#31014#><#65807#><#71418#>
<#71419#>;; to sum up the first
;; <#65808#><#31015#>n<#31015#><#65808#> even numbers<#71419#> 
<#31016#>(d<#31016#><#31017#>efine<#31017#> <#31018#>(series-even<#31018#> <#31019#>n)<#31019#> 
  <#31020#>(c<#31020#><#31021#>ond<#31021#> 
    <#31022#>[<#31022#><#31023#>(=<#31023#> <#31024#>n<#31024#> <#31025#>0)<#31025#> <#31026#>(make-even<#31026#> <#31027#>n)]<#31027#> 
    <#31028#>[<#31028#><#31029#>else<#31029#> <#31030#>(+<#31030#> <#31031#>(make-even<#31031#> <#31032#>n)<#31032#> 
             <#31033#>(series-even<#31033#> <#31034#>(-<#31034#> <#31035#>n<#31035#> <#31036#>1)))]<#31036#><#31037#>))<#31037#>  
<#71420#>;; <#65809#><#31043#>series-odd<#31043#> <#31044#>:<#31044#> <#31045#>N<#31045#> <#31046#><#31046#><#31047#>-;SPMgt;<#31047#><#31048#><#31048#> <#31049#>number<#31049#><#65809#><#71420#>
<#71421#>;; to sum up the first
;; <#65810#><#31050#>n<#31050#><#65810#> odd numbers<#71421#> 
<#31051#>(d<#31051#><#31052#>efine<#31052#> <#31053#>(series-odd<#31053#> <#31054#>n)<#31054#> 
  <#31055#>(c<#31055#><#31056#>ond<#31056#> 
    <#31057#>[<#31057#><#31058#>(=<#31058#> <#31059#>n<#31059#> <#31060#>0)<#31060#> <#31061#>(make-odd<#31061#> <#31062#>n)]<#31062#> 
    <#31063#>[<#31063#><#31064#>else<#31064#> <#31065#>(+<#31065#> <#31066#>(make-odd<#31066#> <#31067#>n)<#31067#> 
             <#31068#>(series-odd<#31068#> <#31069#>(-<#31069#> <#31070#>n<#31070#> <#31071#>1)))]<#31071#><#31072#>))<#31072#> 
The two functions are natural candidates for abstraction and here is the result of following our basic abstraction recipe:
<#71422#>;; <#65811#><#31080#>series<#31080#> <#31081#>:<#31081#> <#31082#>N<#31082#> <#31083#>(<#31083#><#31084#>N<#31084#> <#31085#><#31085#><#31086#>-;SPMgt;<#31086#><#31087#><#31087#> <#31088#>number)<#31088#> <#31089#><#31089#><#31090#>-;SPMgt;<#31090#><#31091#><#31091#> <#31092#>number<#31092#><#65811#><#71422#>
<#71423#>;; to sum up the first <#65812#><#31093#>n<#31093#><#65812#> numbers in the sequence <#65813#><#31094#>a-term<#31094#><#65813#>,<#71423#> 
<#31095#>(d<#31095#><#31096#>efine<#31096#> <#31097#>(series<#31097#> <#31098#>n<#31098#> <#31099#>a-term)<#31099#> 
  <#31100#>(c<#31100#><#31101#>ond<#31101#> 
    <#31102#>[<#31102#><#31103#>(=<#31103#> <#31104#>n<#31104#> <#31105#>0)<#31105#> <#31106#>(a-term<#31106#> <#31107#>n)]<#31107#> 
    <#31108#>[<#31108#><#31109#>else<#31109#> <#31110#>(+<#31110#> <#31111#>(a-term<#31111#> <#31112#>n)<#31112#> 
             <#31113#>(series<#31113#> <#31114#>(-<#31114#> <#31115#>n<#31115#> <#31116#>1)<#31116#> <#31117#>a-term))]<#31117#><#31118#>))<#31118#> 
The first argument specifies where the addition starts. The second argument of <#65814#><#31122#>series<#31122#><#65814#> is a function that maps a natural number to the corresponding term in the series. To test <#65815#><#31123#>series<#31123#><#65815#>, we apply it to <#65816#><#31124#>make-even<#31124#><#65816#> and <#65817#><#31125#>make-odd<#31125#><#65817#>:
<#71424#>;; <#65818#><#31130#>series-even1<#31130#> <#31131#>:<#31131#> <#31132#>N<#31132#> <#31133#><#31133#><#31134#>-;SPMgt;<#31134#><#31135#><#31135#> <#31136#>number<#31136#><#65818#><#71424#>
<#31137#>(d<#31137#><#31138#>efine<#31138#> <#31139#>(series-even1<#31139#> <#31140#>n)<#31140#> 
  <#31141#>(series<#31141#> <#31142#>n<#31142#> <#31143#>make-even))<#31143#> 
<#71425#>;; <#65819#><#31149#>series-odd1<#31149#> <#31150#>:<#31150#> <#31151#>N<#31151#> <#31152#><#31152#><#31153#>-;SPMgt;<#31153#><#31154#><#31154#> <#31155#>number<#31155#><#65819#><#71425#>
<#31156#>(d<#31156#><#31157#>efine<#31157#> <#31158#>(series-odd1<#31158#> <#31159#>n)<#31159#> 
  <#31160#>(series<#31160#> <#31161#>n<#31161#> <#31162#>make-odd))<#31162#> 
For over a century, mathematicians have used the Greek symbol #tex2html_wrap_inline73350# to communicate about series. The two series above would be expressed as

#displaymath73352#

A true (lazy) mathematician would also replace <#65820#><#31172#>make-even<#31172#><#65820#> and <#65821#><#31173#>make-odd<#31173#><#65821#> by their definitions, <#31174#>i.e.<#31174#>, #tex2html_wrap_inline73354# and #tex2html_wrap_inline73356#, but we refrain from doing so to emphasize the analogy to our (well-organized) functions.
<#31177#>Exercise 23.1.1<#31177#> Use <#65822#><#31179#>local<#31179#><#65822#> to create <#65823#><#31180#>series-local<#31180#><#65823#> from <#65824#><#31181#>series-even<#31181#><#65824#> and <#65825#><#31182#>series-odd<#31182#><#65825#>. Show with a hand-evaluation that <#65826#><#31183#>(series-local<#31183#>\ <#31184#>make-even)<#31184#><#65826#> is equivalent to <#65827#><#31185#>series-even<#31185#><#65827#>.~ external Solution<#65828#><#65828#>