GMP Large Integer Library and Dyalog APL

General APL language issues

GMP Large Integer Library and Dyalog APL

Postby petermsiegel on Wed Jun 01, 2016 11:01 pm

I've had good luck developing an interface to GMP from Dyalog APL on OS X-- notably for manipulation of large integers of thousands of digits. It performs well and I've managed to do it, so far, with ⎕NA and APL, i.e. without having to write any C glue routines-- only APL mechanisms and standard GMP routines (e.g. to prevent divide by zero, which if uncaught is quite fatal to the interpreter).

Is anyone else working with GMP. I haven't polished it up to look APL-ish, but am so far calling things GMP-style:
Code: Select all
      ⍝ Pseudo-code
      ⍝ load in large ints a, and b; initialize c to hold the result of calculations
      ⍝ c, a, b are pointers to GMP Big Integer structures...
      ⍝ a is imported as decimal, b is imported as hex.
        c a b ← GMPImport 0 '1233123123...999' '0X23434423AB0ABBE0...F'
        GMPadd c a b             ⍝  For  {c ← a + b}
        ...                      ⍝  Use ptrs internally to save on import/export costs
        ⎕ ← c                    ⍝  Show that c is a magic pointer to a GMP structure,
4302308144                       ⍝  which is in APL a ⎕DR 1287 "int".
        cString ← GMPExport c    ⍝  Now export <c> as an APL string. Default base 10

and it works perfectly for very large #s of digits (the export to base-10 is much slower than the math steps).

I'm interested in using calling conventions that could work for others (esp. if others are adding MPFR (the preferred choice for arbitrary floats) or other libraries. So far I'm only using large integers and have tested to about 10 M digits.

Also, if anyone has implemented a high-performance big integer library of any sort in APL, I'd be interested in benchmarking vs GMP. So far, the GMP interface significantly outperforms any pure dfn-based routines I've come across, most especially when the libraries are loaded once per session, rather than once per call. I could imagine a careful APL version (using internal numeric "limbs" in place of character strings) could be relatively competitive, though GMP should still "win" where it is calling assembly language routines.

If Dyalog is close to implementation of big integers, I'd be interested in the strategy, e.g. GMP for Integer, MPFR for float, and MPC for complex numbers, or ???.
*** Anyone already working on this, or interested in validating the approach and/or in sharing ideas on the APL-side interface (given the GMP-to-APL logic appears to work, at least on OS X).
petermsiegel
 
Posts: 141
Joined: Thu Nov 11, 2010 11:04 pm

Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest