ForeignFunctions package for Macaulay2

Douglas A. Torrance
2024-05-21
Abstract:We introduction the ForeignFunctions package for Macaulay2, which uses libffi to provide the ability to call functions from external libraries without needing to link against them at compile time. As an example, we use the library FFTW to compute fast Fourier transforms inside Macaulay2.
Algebraic Geometry,Commutative Algebra
What problem does this paper attempt to address?
The paper attempts to address the issues of flexibility and efficiency when calling external library functions in Macaulay2. Specifically, the traditional methods—statically or dynamically linking external libraries and communicating with external programs via command-line interfaces—have certain limitations. The former requires recompiling Macaulay2, while the latter involves the creation of temporary files and additional communication overhead. To solve these problems, the author introduces the ForeignFunctions package, which utilizes the libffi library to dynamically call functions from external libraries at runtime without the need to link these libraries at compile time. This not only improves flexibility but also reduces the overhead of communicating with external programs. The main contributions of the paper include: 1. **Introduction of the ForeignFunctions package**: This package allows users to open shared libraries and call functions within them at runtime, without the need to link these libraries at compile time. 2. **Implementation details**: Describes how this functionality is implemented in Macaulay2, including the addition of new data types and low-level conversion functions. 3. **Example applications**: Demonstrates how to use the package to call the Fast Fourier Transform (FFT) functions from the FFTW library and apply them to polynomial multiplication, significantly improving the efficiency of large polynomial multiplications. Through these improvements, the ForeignFunctions package provides Macaulay2 users with a more flexible and efficient way to call external library functions, especially when handling large-scale computational tasks.