A particular sequence

A sequence is an ordered list of numbers (terms). A sequence with a finite number of terms is called finite, whereas a sequence with infinitely many terms is called infinite. The list of all positive even numbers is an example of infinite sequence

\[a_n = \{2, 4, 6, 8, 10,\ldots\}\]

Sequences can sometimes be written in a condensed form, where each term of the sequence can be expressed as a function of its position \(n\):

\[a_n = \{2, 4, 6, 8, 10,\ldots\} = \left\{ 2n \right\}_{n=1}^\infty\]

Some famous infinite sequences are:

  • the Fibonacci numbers

    \(\begin{array}{l} a_0=1, \, a_1=1, \\ a_n = \{1,1,2,3,5,8,13,\ldots\} = \{a_{n-2}+a_{n-1}\}_{n=2}^\infty\end{array}\)

  • the Square Numbers sequence

    \(a_n = \{1,4,9,16,25,36,\ldots\} = \left\{n^2\right\}_{n=1}^\infty\)

  • the Lazy Caterer’s sequence (describing the maximum number of pieces in which a pizza can be cut with \(n\) straight cuts)

    \(a_n = \{1,2,4,7,11,16,\ldots\} = \left\{\dfrac{n^2+n+2}{2}\right\}_{n=0}^\infty\)

The finite sequence you will explore is defined as follows:

  1. Define \(f(x) = \left\{ \begin{array}{ll} \dfrac{x}{2}, & \text{if } x \text{ is even} \\ 3x+1, & \text{if } x \text{ is odd} \end{array} \right.\)

  2. Let \(a_1=k\), where k is a positive integer

  3. For \(n>1\), compute \(a_n=f(a_{n-1})\)

  4. The sequence ends when \(a_n=1\)

For example the sequence for \(k=5\) is:

\[\{5,16,8,4,2,1\}\]

Exercise 1. Write a Python function single_step(x) that implements the function described in 1. above. This function will compute a single step of the sequence

single_step(5)

16

Exercise 2. Write a Python function full_sequence(k) that for each positive integer k returns its corresponding sequence

\[[a_1,a_2,a_3,\ldots]\]

For example

full_sequence(5)

[5,16,8,4,2,1]

Project

Explore the properties (length, highest number reached,…) of the sequences obtained and analyze the results. Can you find any patterns or similarities?