A Comparative Study of Pure Python and JAX-Based Approaches in Computing Harmonic Series
Description
A Comparative Study of Pure Python and JAX-Based Approaches in Computing Harmonic Series
Mehmet Keçeci
ORCID: https://orcid.org/0000-0001-9937-9839, Independent Researcher
Received: 29.07.2025
Abstract:
This study presents a comparative analysis of a traditional, pure Python-based approach and a modern, JAX library-based approach for calculating the harmonic series, focusing on performance, scalability, and efficiency. The harmonic series is a divergent series of significant importance in mathematical analysis. In computational mathematics, the effective evaluation of such series is critical, particularly in applications requiring large-scale data and high precision. The traditional pure Python approach utilises the fractions.Fraction class to provide exact arithmetic, enhancing the code's readability and accuracy. However, this method exhibits linear time complexity for large values of n, limiting its performance in the context of repetitive calculations. Furthermore, memory usage and processing time increase linearly with n. In contrast, the JAX-based approach (the Oresmej module) leverages the advanced features of JAX, a library designed for high-performance scientific computing, including vectorisation (vmap), just-in-time (JIT) compilation, and automatic differentiation. This approach yields a significant speed advantage, especially in large-scale and repetitive operations. Additionally, caching is supported via @lru_cache, which prevents re-computation for identical inputs. The return value is defined as a tuple, thereby enhancing data integrity and cache compatibility. The comparative analysis was conducted using micro-benchmarking techniques. Following a warm-up period, the JAX-based approach was found to be several hundred times faster than pure Python, with cached functions producing results almost instantaneously. Therefore, for scientific research demanding high performance, scalability, and sustainable computation, approaches based on Cython (Cythonize), Numba, JAX, NumPy, and parallel processing (multiprocessing, joblib) are strongly recommended.
Keywords:
Harmonic Series, Pure Python, JAX, Scientific Computing, Performance Comparison, Caching, Vectorisation, JIT Compilation, Exact Arithmetic, Sustainable Coding, Green Coding, Yeşil Kodlama, Oresme, Oresmej, Numba, Cython, Cythonize, NumPy, Multiprocessing, joblib, Divergent series.
Files
A Comparative Study of Pure Python and JAX-Based Approaches in Computing Harmonic Series.pdf
Files
(1.1 MB)
Name | Size | Download all |
---|---|---|
md5:2bf18abd46f363dac45a2141dbb63c91
|
1.1 MB | Preview Download |