## Series and Progression – Arithmetic, Geometric and Harmonic

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.

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

${u}_{1},{u}_{2},{u}_{3,.....,}{u}_{n}$

Example of Series

${u}_{1}+{u}_{2}+{u}_{3}+.....+{u}_{n}$

### 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

${a}_{1},{a}_{2},{a}_{3},...,{a}_{n}$

are in Harmonic Progression(HP) if

$\frac{1}{{a}_{1}},\frac{1}{{a}_{2}},\frac{1}{{a}_{3}},...,\frac{1}{{a}_{n}}$

are in Arithmetic progression

### Python program to identify type of progression


################################################################################################
#	name:	progression.py
#	desc:	identify type of progression
#	date:	2018-09-08
################################################################################################

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 ***')