The Limits of Python in Computational Mathematics and Their Extension with JAX: An Application on Harmonic Numbers
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.

Creator
Submitter
Views: 44 Downloads: 3
Created: 29th Jul 2025 at 18:19

None
Version History
Version 1 (earliest) Created 29th Jul 2025 at 18:19 by Mehmet Keçeci
No revision comments