[issue43420] Optimize rational arithmetics

Sergey B Kirpichev report at bugs.python.org
Sat Mar 6 09:18:17 EST 2021


New submission from Sergey B Kirpichev <skirpichev at gmail.com>:

fractions.py uses naive algorithms for doing arithmetics.

It may worth implementing less trivial versions for addtion/substraction
and multiplication (e.g. Henrici algorithm and so on), described here:
https://www.eecis.udel.edu/~saunders/courses/822/98f/collins-notes/rnarith.ps
as e.g gmplib does: https://gmplib.org/repo/gmp/file/tip/mpq/aors.c

Some projects (e.g. SymPy here: https://github.com/sympy/sympy/pull/12656) reinvent
the stdlib's Fraction just to add such simple improvements.  With big denominators (~10**6)
this really does matter, my local benchmarks suggest the order of magnitude difference for
summation of several such numbers.

----------
components: Library (Lib)
messages: 388200
nosy: Sergey.Kirpichev
priority: normal
severity: normal
status: open
title: Optimize rational arithmetics
type: enhancement
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43420>
_______________________________________


More information about the Python-bugs-list mailing list