Enhancing Python With Mathematical Summa
Enhancing Python With Mathematical Summa
Summation Functions
Andrew Lehti1
1 Introduction
2 Summation up to n (!n)
The function [ !n! ] extends the concept of summation and factorial by cal-
culating the sum of all natural numbers up to the factorial of n. This function
can be instrumental in combinatorial computations and probability, providing a
quick way to sum a range of factorials.
5 Exponential Functions
1
5.3 Power Sum Inverse (a !n )
1
5.4 Sum Power Inverse (!a !n )
7 Additional Formulations
8 Conclusion
By incorporating these mathematical summation functions into Python, we
achieve a higher level of syntactical elegance and computational efficiency. These
functions make the code more intuitive to mathematicians and scientists, bridg-
ing the gap between mathematical notation and programming. Moreover, the
reduction in computational complexity and the ability to handle a broader spec-
trum of mathematical problems make these additions invaluable to the Python
community.
4 Andrew Lehti
1 def sumUpTo ( n ) : # ! n
2 return n * ( n + 1) / 2
3
4 def sumSeries (a , n ) : # a ^! n | a ** ! n
5 if n == 1: return a
6 return a * (( a ** n ) - 1) / ( a - 1)
7
8 def sumFactorial ( n ) : # ! n !
9 factorial = 1
10 for i in range (1 , n + 1) :
11 factorial *= i
12 return sumUpTo ( factorial )
13
14 def sumFraction ( n ) : # ! f
15 return sumUpTo ( n )
16
17 def sumPowerN (a , n ) :
18 return sum ( i ** n for i in range (1 , a + 1) )
19
20 def sumSeriesPowers (a , n ) :
21 return sum ( i ** j for i in range (1 , a + 1) for j in range
(1 , n + 1) )
22
23 def powerSumInverse (a , n ) :
24 return a ** (1 / ( n * ( n + 1) / 2) )
25
26 def sumPowerInverse (a , n ) :
27 return sum ( i ** (1 / ( n * ( n + 1) / 2) ) for i in range (1 ,
a + 1) )
28
29 def seriesPowerSum (a , n ) :
30 return sum ( a ** i for i in range (1 , n + 1) )
Listing 1.3: Python !Summation Functions