algorithm for adding large lists of ration numbers
06:12 22 Jul 2026

I have lists (>3000) of (reduced) rational numbers in the form a/b.

Is there a algorithm to determine the best possible order of summing those to avoid getting overflows of a and b (assuming that for the result a reduced form exist, that does not overflow)

I already tried the following things:

  • order the numbers by denominator and sum up each group (and reduce afterwards) and repeat until all singular denominators remain

  • pull two smallest denominator-numbers - sum, reduce, put back - repeat.

I also thought about n*n-1 pairwise analysing for of least common multiples and chosing the largest group to sum first and then repeat.

But that seems quite computationally expensive for questionable success.

Are there any suggestions or keywords I could search for?

Of course One possible solution would be to use an arbitrary precision BigInt library. But I would like to avoid this.

algorithm rational-number