**First**

I will ask students to gather into their problem groups. Each group
will work on their problem at one computer. I will walk around and try
to facilitate this effort. As students solve their problems, they may
also try to help other groups.

**Second**

If there is a great deal of time left, one or two groups may present
their solutions. Some other groups will present their solutions next
time. We might go on to ...

**Third**

We've been looking at sequences which are created by taking the "old
value" and adding on a some number depending on n. So, for example, we
could have looked at the sum of the squares:

`v:=n->sum(j^2,j=1..n);`

There is another way to think about this sequence. It is a sequence
which has a starting value, v(1), which equals 1, and whose growth is
defined by the equation `v(n)=v(n-1)+n^2`. So we could tell Maple that
the sequence is defined by these instructions:

This method of defining the sequence is calledifn=1thenthe number is 1elsethe number at n is the "old" number at n-1 plus n^2.

In this definition, the words ** if**
and

This is a more complicated form of instruction than the formula we had
involving `add`. The standard way to tell
`Maple` this sort of instruction is a
`procedure` statement. Here is an example
of such a statement.

`> frog:=proc(n) if (n=1) then 1 else frog(n-1)+n^2 end if end proc;`

The words `end if` tell `Maple` that the whole `if
.. then .. else` statement is done, and the words `end proc` tell `Maple` that the procedure definition is done.

The `Maple` response to this instruction
(if I type it correctly!) is

`frog := proc(n) if n = 1 then 1 else frog(n - 1) + n^2 end if end proc`

That is, `Maple` just repeats the
definition back, and stores it for later use. How can we use it? Look:

The result is the same as 1> frog(2); 5

I should warn you about something,
though. There is a penalty for using this sort of logical
construction, and that penalty is in higher running time and more
storage space. For example, the computations of frog(1000) and
add(j^2,j=1..1000) both return the same result (333833500, surely!)
*but* when I just tried both in different `Maple` sessions, the recursive definition took
twice as much time and space on my home PC as the direct
computation. This may not matter in such toy examples, but in real
computations in complicated situations, such resource demands may be
important.

**Fourth**

Let me now define a different sort of sequence, one where a recursive
definition seems to be the simplest and other ways of looking at it
may be more difficult. Here is a `Maple`
procedure defining `toad`:

`> toad:=proc(n) if (n=1) then 1 else
3*toad(n-1)+1 end if end proc;`

What will the result of `seq(toad(n),n=1..3);` be? I hope that students will think
this through but here is the idea of the computation.

`toad(1)`is computed using the`then`clause of the logical statement, so the result should be 1.- As for
`toad(2)`, since 2>1, we go to`else`and compute`toad(1)`, which is 1, multiply it by 3, and add 1. The result should be 4. - Finally, for
`toad(3)`, again we go to`else`, since 3>1. What`Maple`then does is compute`toad(2)`exactly as before (even though it had already been computed -- there are ways to encourage that old results be saved but here we're just doing simple stuff). Then we take that value, 4, multiply it by 3 and add 1. This is 13.

> seq(toad(n),n=1..3); 1, 4, 13This is just as predicted.

**Fifth**

This `toad` is a more complicated
sequence. I'd like to *try* to get a formula for it and verify
the formula. Please notice that if the "+1" were omitted in the
definition, the way we'd get from one term to the next would be just
to multiply by 3. So a formula for the sequence whose first term was 1
and which had the recursive rule s(n)=3*s(n-1) would be
3^{n-1}. I bet that the formula for our `toad` sequence is related to 3^{n}. The
variable is now in the exponent, not in the base. How can we guess the
formula? Once it is guessed, I will show you how we can verify it in a
way quite similar to what we've done.

There are ways to guess the formula, but let me show you

**How to cheat with sequences**

There is a wonderful web resource created by Neil Sloane called the
Encyclopedia of Integer Sequences. This contains over *one
hundred thousand* entries -- wonderful integer sequences and a
great deal of weird and wonderful information about them. Neil Sloane
has told me that many strange things have occurred as people have
"given" him sequences for his Encyclopedia. But let's use his data
base.

For example, look at this
`Maple` command and its response:

> seq(toad(n),n=1..10); 1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524We can take the response and put it into the search bar, and the result is Sequence A003462. The initial information given is (3^n-1)/2, a formula for the sequence!

**Verification**

Here is a complete verification that the formula is correct.

> zebra:=n->(3^n-1)/2; n zebra := n -> 1/2 3 - 1/2 > zebra(1); 1 > zebra(n)-(3*zebra(n-1)+1); n (n - 1) 3 3 3 ---- - ---------- 2 2 > simplify(%); 0The first instruction defines a function,

**Confession or boast?**

Many other people and I use the Encyclopedia a great deal. The *term
paper* project I mentioned at the first meeting will be connected
with the Encyclopedia.

**Next time ...**

Some groups will present their solutions, and I will show you some
very old and very new recursive sequences.

**
Maintained by
greenfie@math.rutgers.edu and last modified 9/21/2008.
**