Student 1

Code: A (40%)Narrative: A (40%)Total: A (20%)
I think one graph of each type is enough. You don't need to have three graphs with different ranges of inputs, just stick with the bigger range.
Presentation: ABonus:

MTH 337 Project 1

Student

Introduction

A sequence is a list of numbers that are in a particular order and there are two main types of sequences. Infinite sequences are so called because they have an infinite number of terms in the sequences; these are different from a finite sequences which has a finite number of terms. An example of an infinte sequence wouuld be (1, 2, 4, 8, 16...) where every term doubles the previous term and it continues infinitely. In this project finite sequences are the focus, in particular the sequence that will be studied in this report is as follows: $$ f(x) = \begin{cases} \frac{x} {2}, \text{ if x is even } \\ 3x+1, \text{ if x is odd } \end{cases} $$

In this sequence, the resulting value from a step of the process is again plugging in to the equation resulting in a new value; a process that is repeated until the end point is reached. This sequence is set up so that it continues to use the last number generated to generate the next term in the sequence until it hits the final number of 1 when it terminates; so, for an $x$ >1 the sequence will continue to produce terms until it reaches 1. For an example in how this sequence works take $x$=3 for example, this would generate the sequences of (3, 10, 5, 16, 8, 4, 2, 1). This sequences works by plugging the input, in this case 3, into the equation. Because 3 is an odd number, the next term is calculated by $(3*3)$ +1 resulting in 10. The number 10 is even, so it is divided by 2 resulting in 5, the number 5 would then be plugged in to the sequence repeating the process until arriving at 1 at which point the sequence terminates. By studying sequences it is possible to find patterns and understand their use in science, math and how these patterns might be useful in the real world.

The goal in this report is to research some of the properties of a finite sequence. Three properties will be investigated in this report with the focus being on finding any observable patterns or similarities between the results. In the first portion of the report the main focus will be about the length of the sequences and how this changes depending on whether it is odd or even starting number. There will also be a comparison between odd and even numbers in terms of length to look for patterns. In the second half of the report, research will be conducted about the maximum number that is reached in the sequences, seeking to find a pattern between using odd and even numbers, and patterns that may exist regardless of what type of number it is. The final property of interest will be in observing a pattern in the end of the sequence, basically observing if there is a pattern about how the sequence terminates. It will be explores whether this is dependent which type of number,odd or even, are inputted or if this is independent of starting number. By evaluating each of these properties the goal is to be able to find generalizable statements that would provide information about any number plugged into the sequence, this would be valuable in understanding the behavior of any starting number in the sequence.

Procedure

For this project, some of the properties of the sequence that is going to be explored include length and maximum values reached by the sequence. I plan to first focus on comparing the differences between lengths looking at odd and even inputs individually. Looking at the odd numbers as starting input values, two graphs including different ranges of inputted values will be calculated to display any patterns in length. For both the odd numbers and the even numbers I will experiment with different ranges to find something that best captures the data. A similar methodology will be repeated with the even numbers, again looking at the data in graph format using different ranges. Any patterns observed will be explained in full detail with further investigation and data provided as needed. For the second portion of part 1, I will being looking at the lengths of sequences comparing both odd and even numbers to observe any possible pattern between the two different classifications of numbers. I plan to use several graphs with different ranges to see if the range would have any effect on the observed patterns or if each range will provide similar data.My hypothesis is that odd numbers will result in longer sequences than even numbers. For this section, if no patterns or similarities are observed I will continue to adjust the range and look at more data points as needed in search of a pattern.

For the second portion of the project, I will focus on the maximum numbers reached by each sequence and will repeat the same procedure, first looking seperately at the odd and even numbers seeking patterns. Secondly I will compare the odd and even numbers together again looking for any similarities or patterns. Similar to the previous sections on length the data will displayed in graphs, using at least two graphs with different ranges to best capture any observations made about the data. Besides looking for patterns within groups or between groups I will also be looking for any differences that using different ranges will result in. Similar to the length section if I don't find any similarities in comparing these values I will continue to adjust the range and see if that yields different results.

For the final section of this report I will be looking to understand patterns in the termination of the sequence and will be working backwards from the end of the sequence to make observations. To study this I will looks at several odd numbers and even numbers between 1-100 to form ideas about how the sequences terminate. From there I will use these observations to formulate an understanding of how the sequence terminates and moving backwards I will seek to be able to explain how this sequence terminates and why this might happen with a particular pattern.

Getting started: Understanding the code

In order to be able to understand the sequence and be able to use it to analyze patterns it is first necessary to create a code that will calculate a single step of the function. The code cells that follow show how the use of an if/else statement allows for the creation of a code that will take an input and perform the correct function based on whether it is an odd or even number. This code will be developed to perform the functions of $f(x)$, based on whether the number is odd or even.

First the code will be developed that can generate the output of the next term of the sequence. This is tested with both odd and even numbers, to make sure that the code is working properly. First an even number is inputted into the code.

In [1]:
#In this cell, the following code is used to calculate the value of the next term in the sequence, using an even number. 
num=6                #Initialize the variable that will be used
if num%2==0:         #Check if the number is even: remainder =0 when dividing by 2
    y=num//2         #If the number is even divide by two (perform the function from f(x) for even numbers)
else:                #Check if the number is not even (odd): remainder is not = to 0 when dividing by 2
    y=3*num+1        #If the number is odd multiply by 3 and then add one (perform the function from f(x) for odd numbers)
print(y)             #Print the number
3

This code returned the expected output of taking the even number and dividing it by 2. Next, the code will be run with an odd number to make sure that this also functions properly.

In [2]:
#In this cell, the following code is used to calculate the value of the next term in the sequence, using an odd number. 
num=7                #Initialize the variable that will be used
if num%2==0:         #Check if the number is even: remainder =0 when dividing by 2
    y=num//2         #If the number is even divide by two (perform the function from f(x) for even numbers)
else:                #Check if the number is not even (odd): remainder is not = to 0 when dividing by 2
    y=3*num+1        #If the number is odd multiply by 3 and then add one (perform the function from f(x) for odd numbers)
print(y)             #Print the number
22

Now that a code has been developed that will print the next term of the sequence for both odd and even numbers, a code must be generated that will calculate the full sequence for any positive integer that is put into the function. The variable num is introduced to represent any positive integer that is put into the function.

In [3]:
def function(num):          #Define the function with input num, the number to be inserted into the sequence
    remainder = num%2       #Define remainder to be used in following steps
    if remainder ==0:       #Check if the number is even: remainder =0 when dividing by 2
        y = num//2          #If the number is even divide by two (perform the function from f(x) for even numbers)
    else:                   #Check if the number is not even (odd): remainder is not = to 0 when dividing by 2
        y = (3*num) + 1     #If the number is odd multiply by 3 and add one (perform the function from f(x) for odd numbers)
    return(y)               #Return the resulting value
In [4]:
#In this cell the code that will produce the full sequence given an input is shown.
def sequence(num):                  #Define the sequence with input num, the number to be inserted into the sequence
    current = num                   #Initialize the second variable that will be used to calculate the next term 
    new_list = [num]                #Initialize the variable used to generate the list of sequence terms
    while current >= 2:             #If the previous term in the sequence is greater or equal to 2 continue calculating
        current = function(current) #Calculate the next value of the sequence
        new_list.append(current)    #Adds the new number to the list of numbers in the sequence
    return new_list                 #Return the resulting sequence

Section 1.1: Length of sequence: a seperate look at odd vs even inputs

In this section of the report I will generate the length of sequences using odd numbers as the starting input values, repeating for every odd number between 1 and 100. This is be calculated by using the sequence described in the previous section of the report, along with a code cell that calculates the length of the sequence. The results of this will be displayed in a graphing format to appropriate display the large amount of data. The cell below explains how the code from the previous section is used to generate the length of the sequence.

In [5]:
#The code in this cell will calculate the length of the sequence generated in the previous cell for input=3
len(sequence(3))
Out[5]:
8

Each of the rest of the values in the graph will be calculated the same way as the example cell above, using the length function to calculate the length of the sequence.

In [6]:
import matplotlib.pyplot as plt    #import the library with the graphing tools used for this project

Now, I need to create a way to generate a list of odd numbers that can be used in a loop to generate the graph since the odd numbers will be observed seperately from the even numbers. This will be done by creating a for loop that will determine if a number is odd or even; after storing this with a variable ($x$) it is possible to use $x$ in further steps as it will insert only odd numbers.

In [7]:
for x in range(10):     #for loop to generate list of odd numbers
    if x%2 !=0:         #Check if the number is odd determined by a remainder not equal to 0 when dividing by 2
        print(x)        #Print the values to generate list of odd numbers
1
3
5
7
9

Now that I have a method to generate a list of odd outputs and have used this as variable $x$ I am able to use this to generate a graph by having the inputs being odd numbers in the range of 0 to 100, and using the length calculating function the outputs graphed will be the length of the sequence.

In [8]:
inputs = [x for x in range(101) if x%2 !=0]      #For each odd number in the range 0 to 100
outputs = [len(sequence(x)) for x in inputs]     #Outputs= the length for the input of odd numbers in the range
In [9]:
plt.plot(inputs,outputs, "r.")                #Tells which variables to graph 
plt.title('Graph of Length of odd inputs')    #Title of the graph
plt.xlabel('Input value')                     #x axis label
plt.ylabel('Length of sequence')              #y axis label
plt.show()                                    #Display the labels and graph below

Using the graph generated above, it is possible to address the question asked about any patterns noticable amongst the odd numbers. With this graph we can see a general increase in the length of the sequence as the input value is increased from inputs values of 0 to 40 but once we reach an input value of 40 the lengths of the sequences appear to remain relatively consistent. On this graph we see that input values between 40 and 100 appear to be have relatively consistant lengths, but to further investigate this another graph displaying a larger range of data must be used. There also appears to be some outliers with the odd numbers, with several cases of inputted odd numbers generating very long sequences, upwards of 120 numbers long.

The graph below is displaying the odd numbers in an increased range of 0 to 200 to further investigate the pattern observed in the previous graph.

In [10]:
inputs = [x for x in range(201) if x%2 !=0]      #For each odd number in the range 0 to 200
outputs = [len(sequence(x)) for x in inputs]     #Outputs= the length for the input of odd numbers in the range
In [11]:
plt.plot(inputs,outputs, "r.")                #Tells which variables to graph 
plt.title('Graph of Length of odd inputs')    #Title of the graph
plt.xlabel('Input value')                     #x axis label
plt.ylabel('Length of sequence')              #y axis label
plt.show()                                    #Display the labels and graph below

Looking at the graph above with a larger range of sequence lengths, it is possible to see that generally as the input values increase so does the length of the sequence. With a larger range it is possible to see that as the input values move from 0 to 200 there is a continued increase in the length of the sequence, unlike what was observed on the graph above, which looked like a possible consistent length of the sequence. This is an importance of looking at many data points as compared to few, with few points something might resemble a pattern that is not representative of the majority of the data. Also interestingly with this graph we get more information about the outliers on the graph, here is looks like a reverse trend as we move from inputs around 25 to 200 there becomes more outliers with shorter lengths. Basically with inputs around 25 the only outliers are lengths of in the range of 100 to 120 but when we get closer to inputs of 200 there is more outliers in the range of 80 to 120. It is possible though, as the input values get larger that there so called "outliers" perhaps aren't outliers and are more of the pattern of increased length of the sequence.

I will then repeat this process for the even numbers between 1 and 20. This is be calculated by using the sequence described in the previous section of the report, along with a code cell that calculates the length of the sequence. The results of this will be displayed in a graph.

Adapting from the loop used above, a loop that generates a list of even numbers will be created, this time the loop with display values that have a remainder of 0 when divided by 2. This will be stored with a new variable, t which will be used in further steps to calculate the length of even numbers in a range.

In [12]:
for t in range(10):    #for loop to generate list of even numbers
    if t%2 ==0:         #Check if the number is even determined by a remainder equal to 0 when dividing by 2
        print(t)        #Print the values to generate list of even numbers
0
2
4
6
8

Now that I have a method to generate a list of even outputs and have used this as variable $t$ I am able to use this to generate a graph by having the inputs being even numbers in the range of 0 to 20, and using the length calculating function the outputs graphed will be the length of the sequence.

In [13]:
inputs_even = [t for t in range(21) if t%2 == 0]           #For each even number in the range 0 to 20
outputs_even = [len(sequence(t)) for t in inputs_even]     #Outputs= the length for the input of even numbers in the range
In [14]:
plt.plot(inputs_even, outputs_even, "r.")      #Tells which variables to graph 
plt.title('Graph of Length of even inputs')    #Title of the graph
plt.xlabel('Input value')                      #x axis label
plt.ylabel('Length of sequence')               #y axis label
plt.show()                                     #Display the labels and graph below

Looking at a small portion of the even numbers, is it possible to see the beginning of a pattern, for the even numbers any input that is equal to 2 raised to a power these inputs result in a shorter length. This is due to the fact that the number would be constantly divided by 2, as no odd number would result. Since odd numbers are the only way a term in the sequence can increase, if a sequence was of all even numbers it would continue to decrease because it would be divided by 2. To explain this, take the number 16 for example, it is equivalent to 2 raised to the 4th power, when calculating the sequence the results would be (16, 8, 4, 2, 1), so each term in the sequence is reduced. This is different than a different starting input that would result in odd numbers in the sequence, for example if the number 6 is inputted the second term in the sequence would be 3, which is an odd number and would thus then be multiplied to produce a larger number. The larger a number is the longer it will take to decrease down to 1 and reach the end of the sequence, so any input that results in only even numbers of the sequence would likely therefore have the shortest lengths.So, in summary the noticable different when comparing the even numbers is that if it is something that is equal to 2 raised to a power then it will only produce even numbers before the sequence terminated and will thus be only decreasing, any other input will result in at least one odd number and therefore will increase at some point in the sequence prolonging its length.

If we take a look at a graph that is further has a larger range we notice that this pattern continues and that it is possible to point out terms that might be the result of 2 raised to a power.

In [15]:
inputs_even = [t for t in range(51) if t%2 == 0]           #For each even number in the range 0 to 50
outputs_even = [len(sequence(t)) for t in inputs_even]     #Outputs= the length for the input of even numbers in the range
In [16]:
plt.plot(inputs_even, outputs_even, "r.")      #Tells which variables to graph 
plt.title('Graph of Length of even inputs')    #Title of the graph
plt.xlabel('Input value')                      #x axis label
plt.ylabel('Length of sequence')               #y axis label
plt.show()                                     #Display the labels and graph below

Looking at this graph above, we see that similar to the first graph there is a general increase in the length of the sequence as the input value increases, but this is a looser association as there is a is not as much of an increase. More interesting here is that certain points are lower than the corresponding data and indicate points that are equal to 2 raised to a power. For example we can see the point at input value of 16 and the point at input value of 32 having a shorter sequence than the closest input values. From this we can hypothesize that these values might be equvialent to 2 raised to a power which can be confirmed by looking at the sequence and seeing if it is all even numbers that have been divided by 2.

In [17]:
sequence(16)     #plugging input value of 16 to generate the sequence
Out[17]:
[16, 8, 4, 2, 1]
In [18]:
sequence(32)    #plugging input value of 32 to generate the sequence
Out[18]:
[32, 16, 8, 4, 2, 1]

Looking at the sequences that result for 16 and 32 it is possible to see that this is confirmed, that both are sequences containing only even numbers that are each divided by 2 to generate the next term. This along with the fact that $2^4$ and $2^5$ are equal to 16 and 32 respectively. This is an example of how a sequence input value that is equal to 2 raised to a power generates a shorter sequence length and thus is possible to pick out from the general trend in the rest of the graphed data.

Section 1.2: Length of sequence: a combined look at odd vs. even inputs

In this section of the report, the goal is to look for a pattern related to the length of the sequence when looking at both odd and even data. The working hypothesis moving into this section of the project is that odd numbered inputs will generally result in a longer length of the sequence than even numbers. To look at thess trends, a graph will be developed that displays both the resulting lengths of odd and even inputs in different colors to distinguish between them. Then, using different ranges the data will be looked at to see if range makes a different in any observable pattern.

Similar to the process used in the previous sequence, the same code will be used to generate the graph, though at this stage the data of both will be displayed on the same graph allowing for obersavtions about associations to be made.

In [19]:
inputs_o = [x for x in range(101) if x%2 !=0]      #For each odd number in the range 0 to 100
outputs_o = [len(sequence(x)) for x in inputs_o]   #Outputs= the length for the input of odd numbers in the range
In [20]:
inputs_e = [t for t in range(101) if t%2 == 0]           #For each even number in the range 0 to 100
outputs_e = [len(sequence(t)) for t in inputs_e]        #Outputs= the length for the input of even numbers in the range
In [21]:
plt.plot(inputs_e, outputs_e, "r.", inputs_o, outputs_o, "g." ) #Tells which variables to graph 
plt.title('Graph of Length of even and odd inputs')             #Title of the graph
plt.xlabel('Input value')                                       #x axis label
plt.ylabel('Length of sequence')                                #y axis label
plt.legend(['even','odd'])                                      #display legend to label which color represents odd and even
plt.show()                                                      #Display the labels and graph below

As notated by the legend, in the graph above the even inputs are represented by red points and the green points represent the odd inputs. From this graph it is possible to see that the different types of numbers don't differ drastically in the lengths of their sequences and that both feature a general increase in length with increased input values. Both odd and even numbers have outliers that have lengths much longer than the majority of the data, but it is notable that the odd numbers appear to have more outliers. With the main pattern of lengths, generally there are more odd numbers with slightly longer lengths and more even numbers with slighlty shorter lengths represented by more green dots being above the section of the graph with the most overlapping dot, and more red points being below. It is possible to also look at different ranges with this graph to see if the observed trend appears the same in both a larger and smaller range.

A graph displaying lengths of odd and even numbers will now be created with a smaller range than the previous graph. This new graph will display data in a range of 0 to 50.

In [22]:
inputs_o = [x for x in range(51) if x%2 !=0]      #For each odd number in the range 0 to 50
outputs_o = [len(sequence(x)) for x in inputs_o]   #Outputs= the length for the input of odd numbers in the range
inputs_e = [t for t in range(51) if t%2 == 0]           #For each even number in the range 0 to 50
outputs_e = [len(sequence(t)) for t in inputs_e]        #Outputs= the length for the input of even numbers in the range
In [23]:
plt.plot(inputs_e, outputs_e, "r.", inputs_o, outputs_o, "g." ) #Tells which variables to graph 
plt.title('Graph of Length of even and odd inputs')             #Title of the graph
plt.xlabel('Input value')                                       #x axis label
plt.ylabel('Length of sequence')                                #y axis label
plt.legend(['even','odd'])                                      #display legend to label which color represents odd and even
plt.show()                                                      #Display the labels and graph below

The graph above shows the odd and even inputs of over a range of 0 to 50, where we can see again that there is a general increase in the length of sequence as the input values increase. We can also see that odd and even inputs have lengths that are relatively close to each other, and that similar to the previous graph with a range of 0 to 100 there is more outliers that are odd numbers than even numbers. Particularly on this graph we notice that there are no even numbered outliers and that the outliers with long lengths are all odd numbers. This means that what was observed on this graph is similar to the trend observed on the previous graph with the range 0 to 100. To further study this a graph with a larger range will be introduced.

A graph displaying lengths of odd and even numbers will now be created with a larger range than the previous two graph. This new graph will display data in a range of 0 to 200.

In [24]:
inputs_o = [x for x in range(201) if x%2 !=0]      #For each odd number in the range 0 to 200
outputs_o = [len(sequence(x)) for x in inputs_o]   #Outputs= the length for the input of odd numbers in the range
inputs_e = [t for t in range(201) if t%2 == 0]           #For each even number in the range 0 to 200
outputs_e = [len(sequence(t)) for t in inputs_e]        #Outputs= the length for the input of even numbers in the range
In [25]:
plt.plot(inputs_e, outputs_e, "r.", inputs_o, outputs_o, "g." ) #Tells which variables to graph 
plt.title('Graph of Length of even and odd inputs')             #Title of the graph
plt.xlabel('Input value')                                       #x axis label
plt.ylabel('Length of sequence')                                #y axis label
plt.legend(['even','odd'])                                      #display legend to label which color represents odd and even
plt.show()                                                      #Display the labels and graph below

The graph above shows the odd and even inputs of over a range of 0 to 200, and it results in similar patterns to the other two graphs with smaller ranges. We can see again that there is a general increase in the length of sequence as the input values increase. We can also see that odd and even inputs have lengths that are relatively close to each other, and that similar to the previous graph with a range of 0 to 100 there is more outliers that are odd numbers. Similar to the graph with range of 0 to 100, it is noticable that in the band where most of the data falls there is generally more odd numbers with longer lengths and more even numbers with shorter lengths. From this it is possible to state that the lenghts of odd and even inputs would be expected to relatively similar in length but that odd inputs are more likley to be longer than even inputs.

Section 2.1 Maximum values: a seperate look at odd vs even inputs

For the second section, I will focus on the maximum numbers reached by each sequence and will compare look at only odd inputs, and secondly I will look at only the even numbers. I will be looking for any patterns that are observed within the input values of the same classification, and the results will be dispplayed in a graphing format. For both the odd and even numbers, several different ranges will be used to look for patterns and similarities amongst the data.

The first step in this process is to devleop a method or a way of looking at what the maximum value of each sequence will be. The following code is a method that will return the maximum value of a sequence.

In [26]:
#The code in this cell will calculate the maximum value of the sequence for an input of 3 
max(sequence(3))
Out[26]:
16

Each of the rest of the values in the graph will be calculated the same way as the example cell above to calculate the maximum value of the sequence but I will be using a loop to calculate the values, using the same loop as used in section 1.1 to generate a list of odd numbers.

In [27]:
for x in range(10):    #for loop to generate list of odd numbers
    if x%2 !=0:         #Check if the number is odd determined by a remainder not equal to 0 when dividing by 2
        print(x)        #Print the values to generate list of odd numbers
1
3
5
7
9

Now that I have a method to generate a list of odd outputs and have used this as variable $m$ I am able to use this to generate a graph by having the inputs being odd numbers in the range of 0 to 25, and using the maximum value calculating function the outputs graphed will display the maximum value of the sequence.

In [28]:
inputs = [m for m in range(25) if m%2 !=0]        #for each odd number in range 0 to 24      
outputs = [max(sequence(m)) for m in inputs]     #Outputs= the maximum value for the input of odd numbers in the range
In [29]:
plt.plot(inputs,outputs, "r.")                      #Tells which variables to graph 
plt.title('Graph of Maximum values of odd inputs')  #Title of the graph
plt.xlabel('Input value')                           #x axis label
plt.ylabel('Maxmium value of sequence')             #y axis label
plt.show()                                          #Display the labels and graph below

Using the graph generated above, it is possible to look for patterns that are noticeable about the maxmium value of the sequence with odd number inputs. With this graph displaying a small range of data from 0 to 24 we see that there is a general increase in the maximum value of the sequence as the input value increases but that this is not consistent with all of the data. There are a few data points where there is a decrease in the maximum value of the sequence when input is increase compared to the points immediately surrounding it. For example, moving from an input of 11 to an input of 13 the maximum value of the sequence decreases. There are also two maximum values on the graph that could be considered outliers, as they are both at 160 when the rest of the data is under 100 as the maximum value. It is interesting that both of these points have the same maximum value, possible there is some pattern with the maximum value that can be observed over a larger range. Because of these several inconsistencies, further graphs were generated with different ranges to see if there is a consistent pattern.

The next graph below has a different range, including more odd inputs, with a range of 0 to 100.

In [30]:
inputs = [m for m in range(101) if m%2 !=0]      #for each odd number in range 0 to 100    
outputs = [max(sequence(m)) for m in inputs]     #Outputs= the maximum value for the input of odd numbers in the range 
In [31]:
plt.plot(inputs,outputs, "r.")                        #Tells which variables to graph 
plt.title('Graph of Maximum values of odd inputs')    #Title of the graph
plt.xlabel('Input value')                             #x axis label
plt.ylabel('Maxmium value of sequence')               #y axis label
plt.show()                                            #Display the labels and graph below

On this graph the range of the data represented is the odd numbers in range 0 to 100 and with this graph we get the emergence of something interesting, the majority of the data is relatively small, under 1000 as the maximum length but then there is 12 points that have very high maximum numbers of nearly 10,000. This is very interesting because these few points have a maximum value that is nearly 10 times the amount of the majority of the data; the most likely reason for this is because they have a large amount of odd numbers in the sequence which continue to increase the maximum value. For all odd inputs becasue you are multying by 3 and then adding 1 the next term will be even, but if the term after that is odd the sequence has the potential to keep growing. If this pattern continued and every other term was odd the sequence could continue to grow, growing until evertually hitting its maximum. If this happens many times it would be easy to get a sequence to increase to a high maximum value, versus a sequence that has an odd input and then even numbers which will reduce the sequence. We do still see that in the majority of the data that there is a gradual increase in the maximum value of the sequence as the input value increases.

The next graph below has a different range, including more odd inputs, with a range of 0 to 500.

In [32]:
inputs = [m for m in range(501) if m%2 !=0]      #for each odd number in range 0 to 500     
outputs = [max(sequence(m)) for m in inputs]     #Outputs= the maximum value for the input of odd numbers in the range 
In [33]:
plt.plot(inputs,outputs, "r.")                #tells which variables to graph 
plt.title('Graph of Maximum values of odd inputs')    #Title of the graph
plt.xlabel('Input value')                     #x axis label
plt.ylabel('Maxmium value of sequence')              #y axis label
plt.show()                                    #Display the labels and graph below

On this graph the range of the data represented is the odd numbers in range 0 to 500. On this graph we can see that there is a general trend along the bottom portion of the graph that as the input value increases the maximum value of the sequence increases. We do get an interesting pattern emerging with a maximum value of approxiamtely 10,000 as there are dozens of data points forming nearly a line across the graph. This is interesting becasue it means for these specific input values that there is no increasing maximum value trend and that the value is similar between inputs that span 0 to 500. Like mentioned in the discussion about the previous graph odd inputs have a potential to keep increasing if the third term of the sequence is an odd number. There are a few outlier points that are above the two trends in the data but there are only 4 points that are in this range. This graph brings up an interesting point about the odd numbers, there isn't a way to predict, just from knowing that it is an odd number is it will have a maximum value of approximately 10,000 or if it will following the general increasing trend.

I will then repeat this process for the even number. This is be calculated by using the sequence described in the previous section of the report, along with a code cell that calculates the maximum value of the sequence. The results of this will be displayed in a graph.

Adapting from the loop used above, a loop that generates a list of even numbers will be created, this time the loop with display values that have a remainder of 0 when divided by 2. This will be stored with a new variable, n.

In [34]:
for n in range(10):    #for loop to generate list of even numbers
    if n%2 ==0:         #Check if the number is even determined by a remainder equal to 0 when dividing by 2
        print(n)        #Print the values to generate list of eveb numbers
0
2
4
6
8

Now that I have a method to generate a list of even outputs and have used this as variable $n$ I am able to use this to generate a graph by having the inputs being even numbers in a choosen range, and using the maximum value calculating function the outputs graphed.

In [35]:
inputs_even = [n for n in range(21) if n%2 == 0]        #for each even number in range 0 to 20     
outputs_even = [max(sequence(n)) for n in inputs_even] #Outputs= maximum value for the input of even numbers in the range 
In [36]:
plt.plot(inputs_even, outputs_even, "r.")              #Tells which variables to graph 
plt.title('Graph of maximum values of even inputs')    #Title of the graph
plt.xlabel('Input value')                              #x axis label
plt.ylabel('Maximum values of sequence')               #y axis label
plt.show()                                             #Display the labels and graph below

The graph above displayed the maximum value for even inputs in the range of 0 to 20. With this graph we can make a few different observations about the data and what patterns might need further investigation to make a conclusion about any pattern. The first pattern that is noticable is that most of the points of the graph have a general upward trend, having increasing maximum values for increasing input values. There are several outliers, for example the points at 6, 14 and 18, which do not fit into the general trend of the graph. Interestingly for all 3 of these points, the second term in the sequence would be an odd number, meaning then that the third term of the sequence would be increased since odd numbers are the way of increasing in the sequence. For example, take input of 14, the second term in the sequence would be 7 which since it is an odd number it would be multiplied by 3 and have 1 added to it to generate 22 as the third value of the sequence. With this the main point is that the third term of the sequence ends up being an increase from the starting point and the second term, versus other even numbers which don't have an odd number as the second term of the sequence. Comparing an input of 16, which would return second and third terms of 8 and 4, these are even numbers which tend to decrease. This is an interesting trend becasue it depends more on the second term of the sequence than on the fact that the first term in the sequence is an even number.

The following graph displays the data for even numbers in the range of 0 to 100, to get a further look at the maximum value of the sequence for even inputs to see if any of the same patterns are observable.

In [37]:
inputs_even = [n for n in range(101) if n%2 == 0]        #for each even number in range 0 to 101    
outputs_even = [max(sequence(n)) for n in inputs_even]   #Outputs= maximum value for the input of even numbers in the range 
In [38]:
plt.plot(inputs_even, outputs_even, "r.")                #Tells which variables to graph 
plt.title('Graph of maximum values of even inputs')      #Title of the graph
plt.xlabel('Input value')                                #x axis label
plt.ylabel('Maximum values of sequence')                 #y axis label
plt.show()                                               #Display the labels and graph below

The graph above shows the maximum values for even inputs in the range of 0 to 100, in this graph we can see the pattern that we observed in the previous graph. We see, although small in the bottom of the graph, that as the input value increases the majority of the data has an increasing maximum value in the sequence. There is again 4 outliers in the graph, which have much higher maximum value than the rest of the data.This is likely due to the same reasoning that was discussed in the previous graph, that maximum value of the sequence depends more on the second term and whether that is odd or even than on if the input value is odd or even. This is also similar to what was observed when looking at the odd numbers and will be further discussed on the following section, section 2.2 which compares the odd and the even numbers together.

The next graph displays the maximum values of even number inputs in the range of 0 to 500.

In [39]:
inputs_even = [n for n in range(501) if n%2 == 0]       #for each even number in range 0 to 500
outputs_even = [max(sequence(n)) for n in inputs_even]  #Outputs= maximum value for the input of even numbers in the range 
In [40]:
plt.plot(inputs_even, outputs_even, "r.")                #Tells which variables to graph 
plt.title('Graph of maximum values of even inputs')      #Title of the graph
plt.xlabel('Input value')                                #x axis label
plt.ylabel('Maximum values of sequence')                 #y axis label
plt.show()                                               #Display the labels and graph below

In this graph the maximum values of the sequence are displayed in the range with inputs for 0 to 500. In this graph we can see two observable trends. The first trend is the general increase in maximum value in the sequence as the input value also increases. The second observable trend on this graph is that there appears to be a line of points with approximately the same maximum value, somewhere approximately aorund the maximum value of 10,000. This means that for the even numbers, there is no one general trend, instead there is two trends data that has an increasing maximum value as input increases and data that has the similar maximum values as the inputs increase.

Section 2.2 Maximum values achieved by sequence: a combined look at odd vs. even inputs

In this section of the report, the goal is to look for a pattern related to the maximum value achieved by the sequence when looking at both odd and even data. The working hypothesis moving into this section of the project is that odd numbered inputs will generally result in a higher maximum value in their sequence compared to the even numbered inputs. To look at these trends, a graph will be developed that displays both the resulting lengths of odd and even inputs in different colors to distinguish between them. Then, using different ranges the data will be looked at to see if range makes a different in any observable pattern.

Similar to the process used in the previous sequence, the same code will be used to generate the graph, though at this stage the data of both will be displayed on the same graph allowing for obersavtions about associations to be made.

In [41]:
inputs_o = [m for m in range(25) if m%2 !=0]        #for each odd number in range 0 to 25   
outputs_o = [max(sequence(m)) for m in inputs_o]    #Outputs= the maximum value for the input of odd numbers in the range 
inputs_e = [n for n in range(25) if n%2 == 0]       #for each even number in range 0 to 25
outputs_e = [max(sequence(n)) for n in inputs_e]    #Outputs= maximum value for the input of even numbers in the range 
In [42]:
plt.plot(inputs_e, outputs_e, "r.", inputs_o, outputs_o, "g." )          #Tells which variables to graph 
plt.title('Graph of maximum values of odd and even inputs')              #Title of the graph
plt.xlabel('Input value')                                                #x axis label
plt.ylabel('Maximum values of sequence')                                 #y axis label
plt.legend(['even','odd'])                                               #Legend to label data
plt.show()                                                               #Display the labels and graph below

When first looking at this data over a small range of 0 to 24, there is not a strong pattern, but there is a general increasing of maximum value of the sequence as the input value increases. To further investigate this trend, different ranges will be used to further evluate the pattern.

Similar to the process used in the above graph, the new range for the following graph is from 0 to 101.

In [43]:
inputs_o = [m for m in range(101) if m%2 !=0]       #for each odd number in range 0 to 100   
outputs_o = [max(sequence(m)) for m in inputs_o]    #Outputs= the maximum value for the input of odd numbers in the range 
inputs_e = [n for n in range(101) if n%2 == 0]      #for each even number in range 0 to 100
outputs_e = [max(sequence(n)) for n in inputs_e]    #Outputs= maximum value for the input of even numbers in the range 
In [44]:
plt.plot(inputs_e, outputs_e, "r.", inputs_o, outputs_o, "g." )          #Tells which variables to graph 
plt.title('Graph of maximum values of odd and even inputs')              #Title of the graph
plt.xlabel('Input value')                                                #x axis label
plt.ylabel('Maximum values of sequence')                                 #y axis label
plt.legend(['even','odd'])                                               #Legend to label data
plt.show()                                                               #Display the labels and graph below

On this graph the range of the data represented is both the odd and even numbers in range 0 to 100. With this graph we get the emergence of the same patterns that we saw on each of the individual graphs, two different observable trends, but we can see that both the odd and even numbers follow relatively the same pattern. On the bottom portion of this graph we see that as the input values increases so does the maximum value of the sequence, a pattern that happens with both the odd and even numbers. We can see though that the even numbers tend to have a slightly lower maximum value, by observing that more of the green dots (odd numbers) are slightly above the red dots. The second trend we observe is that there are outlier points that appear at approximately the same maximum value for both the odd and even numbers; there are more odd numbers that are outliers at this maximum value than even numbers. To continue to look at these patterns one more range will be observed.

Similar to the process used in the above graph, the new range for the following graph is from 0 to 500.

In [45]:
inputs_o = [m for m in range(501) if m%2 !=0]       #for each odd number in range 0 to 500 
outputs_o = [max(sequence(m)) for m in inputs_o]    #Outputs= the maximum value for the input of odd numbers in the range 
inputs_e = [n for n in range(501) if n%2 == 0]      #for each even number in range 0 to 500
outputs_e = [max(sequence(n)) for n in inputs_e]    #Outputs= maximum value for the input of even numbers in the range 
In [46]:
plt.plot(inputs_e, outputs_e, "r.", inputs_o, outputs_o, "g." )          #Tells which variables to graph 
plt.title('Graph of maximum values of odd and even inputs')              #Title of the graph
plt.xlabel('Input value')                                                #x axis label
plt.ylabel('Maximum values of sequence')                                 #y axis label
plt.legend(['even','odd'])                                               #Legend to label data
plt.show()                                                               #Display the labels and graph below

In this graph, similar to the previous graphs we can see two different patterns emerging. The first trend is the general increase in maximum value in the sequence as the input value also increases, we observe this with both the odd and even inputs. Zooming in on this specifc trend we can see that while both the odd and even numbers follow this pattern, the even numbers tend to have slightly lower maximum values as compared to the odd numbered inputs. The second observable trend on this graph is that there appears to be a line of points with approximately the same maximum value, somewhere approximately aorund the maximum value of 10,000. We see this will both odd and even numbers, but there are generally more odd numbers with this maximum value than even numbers. Finally there are 4 odd input values that result in maximum values that are much higher than the rest of the data on the graph. This means that for both the odd and even numbers, there is no one general trend, instead there is two trends data that has an increasing maximum value as input increases and data that has the similar maximum values as the inputs increase.

3.1: Termination of sequences

For the final section the additional property that I will be observing is in the termination of the sequence and any observable pattern that is produced. To do this I will be using a few examples of odd numbers between 1-100 and a few examples of even numbers between 1-100 and will make observations about the possible patterns observed in these sequences. From these patterns, it will be possible to discuss how the sequence terminates and why this might be the reason.

There are many numbers that could have been used for this section, but they each will point out a similar pattern with the ending of the sequence. The specific numbers were picked becasue they did not generate a very long sequence (which is not necessary in a study focused on the end of the seuqence) and it is easier to look at the data about how they terminate. The following code will be used to generate the full sequence for 2 odd numbers and 2 even numbers. These sequences that are generated will be used to create a graph which will allow for observations to be made.

In [47]:
sequence(32)
Out[47]:
[32, 16, 8, 4, 2, 1]
In [48]:
sequence(64)
Out[48]:
[64, 32, 16, 8, 4, 2, 1]
In [49]:
sequence(13)
Out[49]:
[13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
In [50]:
sequence(17)
Out[50]:
[17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
In [51]:
import matplotlib.pyplot as plt
In [52]:
inputs_32 = [1,2,3, 4, 5, 6,]
inputs_64 = [1,2,3, 4, 5, 6, 7]
inputs_13 = [1,2,3, 4, 5, 6, 7, 8, 9, 10]
inputs_17 = [1,2,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
outputs_32 = [32, 16, 8, 4, 2, 1]
outputs_64 = [64, 32, 16, 8, 4, 2,1]
outputs_13 = [13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
outputs_17 = [17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
In [53]:
plt.figure(figsize=[12,10])
# plot 1
plt.subplot(221)
plt.plot(inputs_32,outputs_32)
plt.title('Graph of sequence with input 32')
plt.xlabel('Number of term in sequence')
plt.ylabel('Sequence value')

# plot 2
plt.subplot(222)
plt.plot(inputs_64,outputs_64)
plt.title('Graph of sequence with input 64')
plt.xlabel('Number of term in sequence')
plt.ylabel('Sequence value')

#plot 3 
plt.subplot(223)
plt.plot(inputs_13,outputs_13)
plt.title('Graph of sequence with input 13')
plt.xlabel('Number of term in sequence')
plt.ylabel('Sequence value')

#plot 4 
plt.subplot(224)
plt.plot(inputs_17,outputs_17)
plt.title('Graph of sequence with input 17')
plt.xlabel('Number of term in sequence')
plt.ylabel('Sequence value')
plt.show()

There is a noticable pattern in the ending of the sequences when looking at both the odd and even numbers, for every sequence, they each share the ending sequence of that goes as follows: 16, 8, 4, 2, 1. This is a particular interesting pattern, becasue for the majority of inputs into the sequence, they will each have this termination (the few exceptions would be numbers like 4 and 2 which have shorter sequences). In these cases they still follow the pattern of termination they just don't have as many values as is shared by the majority of input values in the sequence. This brings up the question of why each sequence seems to end this way, which is answerable when thinking about the properties of the sequence.

If thinking about the sequence working backwards, all groups in this sequence must end with value of 1 since that is what causes the sequence to terminate. The only way to get to the number 1 is by having 2 divided by 2 meaning that the only option for the second to last term is 2. Following this similar idea using the two equations of the sequence the only way to generate the number 2 is from dividing 4 by 2 thus the sequence must end as follows: 4,2,1. This is the exact same reason that the number previous to this must be 8, becasue although it is possible to generate 4 using the odd portion of the function this would never happen becasue the value inputted must be 1. So although $3*1$ +1 = 4, if the sequence has already reached 1 it would already have ended, thus the only way to get 4 is taking 8 divided by 2. Similarly the previous number 16 must be developed the same way, generating the sequence of numbers as 16, 8, 4, 2 and 1. Continuing to think backwards from there this is when the sequences differ, it is possible to reach the number 16 in two different way, either through inputting 32 into $f(x)$ or inputting 5 into $f(x)$ both of which would generate 16 as the next term in the sequence. Therefore this is the point, moving backwards from the end, where the sequences would begin to differentiate from each other and fall into two basic categories, some would have the value of 32 and some 5.

Looking at the graphs previously it is possible to observe this, each graph shows the decline of 16,8,4,2,1 but the graphs differ in the terms that come earlier in the sequence. The first and second graphs display sequences for input values of 32 and 64, and as shown above they each have 32 as the previous term and therefore show a pattern of decreasing as each term is divided by two. Thus their sequence ends with 32, 16, 8, 4, 2, 1 and is decreasing. The bottom two graphs display the sequences for input values of 13 and 17 and these graphs each have 5 as the term before the same shared ending sequence. This can also be observed on the graphs. For example, the value of 5 is the 8th term in the sequence for input of 17 and after that the graph follows the same patterns of decreasing from 16 down to 1. All numbers of this sequence, beside the few small numbers which only share some of the digits with the sequence, will thus have the same decline at the end of the sequence graphing 16, 8, 4, 2, and 1 and each of these sequences must either have 32 or 5 as the preceeding number. It would be possible to continue working backwards on the sequence to calculate the next possible values, but the portion that all inputs share is always going to be 16, 8, 4, 2, and 1.

Conclusion

In this report the problem that was seeking to be understood is about the following sequence: $$ f(x) = \begin{cases} \frac{x} {2}, \text{ if x is even } \\ 3x+1, \text{ if x is odd } \end{cases} $$

In particular this finite sequence is studied to look for patterns or similarities in several variables, including length, maximum number achieved and termination of the sequence. The goals of this report is to research some of the properties of a finite sequence, looking for observable patterns. The first goal in the section 1 of the project was about length, and how length of the sequences changes depending on whether it is odd or even starting number. The second goal of section 1 was to study how the length changes with the magnitude of the starting value. In the second section of the report, research was conducted about the maximum number that is reached in the sequences, seeking to find a pattern between using odd and even numbers. The section portion of section 2 also looked for a pattern in maximum value reached with numbers within each category that differ in magnitude. In the third section of the report the goal was to understand the pattern between the patterns of the ends of the sequences and if this is dependent on whether odd or even numbers are inputted or if this is independent of starting number.

The methods used in this report were similar between each of the sections of the report, similar methods were followed in sections 1 and 2. In the first section length was observed for odd numbers over several ranges, and this was then repeated for even numbered inputs over several ranges. For the second portion of this sequence the odd and even inputs values were comapred together, over several different ranges to observe trends. For the second portion of the project, this procedure is repeated except the focus is on the maximum numbers reached by each sequence. The two parts of this section are the same as the previous section of the project, first the odd and even inputs are looked at seperately and then they are looked at comparing the two to each other. For the final section of this report, using examples of both odd and even numbers, graphs were generated to look at the ending of the sequences and to develop observations about why the sequence ends as it does.

In this study several patterns and similarities were observed for each different section of the report. In discussion of the results then it is possible to summarize them by each section. For section 1 of the report similar trends were observed for both the odd and even numbers, that there is an increase in the length of the sequence as the input values increase. While both numbers follow the same pattern, generally more odd numbers have longer lengths and more even numbers with shorter lengths. In the section 2 of the project two observations were made: there is a general trend of increasing maximum values as input values increases but there is also a line of points with approximately the same maximum value. Also noticed was that for even numbers, there is more dependence on the subsequent oddness or evenness of terms in the sequence than on the fact the input was even. Similar to length more odd numbers had a higher maximum value than even numbers but still followed the same increasing pattern. In the final section, observations and reasons were provided for why each input in the sequence ends with the same termination sequence and why this is always 16,8,4,2,1.