Efficient and formally proven reduction of large integers by small moduli

  • Authors:
  • Luc Rutten;Marko Van Eekelen

  • Affiliations:
  • IBM, Delft, The Netherlands;Radboud University Nijmegen and Open University of the Netherlands, Nijmegen, The Netherlands

  • Venue:
  • ACM Transactions on Mathematical Software (TOMS)
  • Year:
  • 2010

Quantified Score

Hi-index 0.00

Visualization

Abstract

On w-bit processors which are much faster at multiplying two w-bit integers than at dividing 2w-bit integers by w-bit integers, reductions of large integers by moduli M smaller than 2w-1 are often implemented suboptimally, leading applications to take excessive processing time. We present a modular reduction algorithm implementing division by a modulus through multiplication by a reciprocal of that modulus, a well-known method for moduli larger than 2w-1. We show that application of this method to smaller moduli makes it possible to express certain modular sums and differences without having to compensate for word overflows. By embedding the algorithm in a loop and applying a few transformations to the loop, we obtain an algorithm for reduction of large integers by moduli up to 2w-1. Implementations of this algorithm can run considerably faster than implementations of similar algorithms that allow for moduli up to 2w. This is substantiated by measurements on processors with relatively fast multiplication instructions. It is notoriously hard to specify efficient mathematical algorithms on the level of abstract machine instructions in an error-free manner. In order to eliminate the chance of errors as much as possible, we have created formal correctness proofs of our algorithms, checked by a mechanized proof assistant.