Let us clarify few terms first.
A sequence is a set of numbers written in a particular order.
A series is something we obtain from a sequence by adding all the terms together. Please note its not sequence of numbers, its sum of numbers in sequence.
A progression has a specific formula to calculate its nth term, whereas a sequence can be based on a logical rule like ‘a group of prime numbers
Here is an example of sequence
Example of Series
Arithmetic Series
Arithmetic sequence is a sequence of numbers in which each term after the first is obtained by adding a constant (d).
An arithmetic progression is given by following formula
where a = the first term , d = the common difference
Some of the important formulae
Geometric Progression
A geometric progression, or GP, is a sequence where each new term after the first is obtained by multiplying the preceding term by a constant r.
Where a : first term and r is constant
Harmonic Progression
harmonic progression is closely related with arithmetic progression. Non-zero numbers
are in Harmonic Progression(HP) if
are in Arithmetic progression
Python program to identify type of progression
################################################################################################
# name: progression.py
# desc: identify type of progression
# date: 2018-09-08
# Author: conquistadorjd
################################################################################################
import numpy
def type_of_progression(input_sequence):
delta = []
current = 0
while current < len(input_sequence)-1:
delta.append(input_sequence[current+1]-input_sequence[current])
current = current+1
delta_unique= set(delta)
if len(delta_unique) == 1 :
return "arithmetic"
delta = []
current = 0
while current < len(input_sequence)-1:
delta.append(input_sequence[current+1]/input_sequence[current])
current = current+1
delta_unique= set(delta)
if len(delta_unique) == 1 :
return "geometric"
delta = []
current = 0
while current < len(input_sequence)-1:
delta.append(1/input_sequence[current+1]-1/input_sequence[current])
current = current+1
delta_unique= set(delta)
if len(delta_unique) == 1 :
return "harmonic"
else:
return "nothing"
print('*** Program Started ***')
input_sequence = input('Please input sequence separated by "," : ')
input_sequence = eval('[' + input_sequence + ']')
result = type_of_progression(input_sequence)
print("result :" , result)
print('*** Program Ended ***')