Table of Contents
Fetching ...

ForeignFunctions package for Macaulay2

Douglas A. Torrance

TL;DR

The paper presents a libffi-backed foreign-function interface for Macaulay2 that enables runtime calls to external libraries without prior linking, addressing limitations of traditional compile-time wrappers and shell-based interprocess communication. It formalizes the interface via types such as SharedLibrary, ForeignType, ForeignObject, and ForeignFunction, and shows how to create and invoke wrappers with foreignFunction, including handling of C/C++ function calls. Through three concrete examples—the FFTW-based FFT for polynomial multiplication, a LAPACK-based general Gauss-Markov linear model solver, and a JIT compilation approach for Fibonacci numbers—the work demonstrates practical interoperation with existing numerical libraries and significant potential performance gains. The contributions underscore the practicality and versatility of dynamic foreign-function interfaces in computational algebra, enabling both efficiency improvements and flexible integration with high-performance libraries.

Abstract

We introduce 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 examples, we use the library FFTW to multiply polynomials using fast Fourier transforms, call a LAPACK function to solve a general Gauss-Markov linear model problem, and use JIT compilation to compute Fibonacci numbers.

ForeignFunctions package for Macaulay2

TL;DR

The paper presents a libffi-backed foreign-function interface for Macaulay2 that enables runtime calls to external libraries without prior linking, addressing limitations of traditional compile-time wrappers and shell-based interprocess communication. It formalizes the interface via types such as SharedLibrary, ForeignType, ForeignObject, and ForeignFunction, and shows how to create and invoke wrappers with foreignFunction, including handling of C/C++ function calls. Through three concrete examples—the FFTW-based FFT for polynomial multiplication, a LAPACK-based general Gauss-Markov linear model solver, and a JIT compilation approach for Fibonacci numbers—the work demonstrates practical interoperation with existing numerical libraries and significant potential performance gains. The contributions underscore the practicality and versatility of dynamic foreign-function interfaces in computational algebra, enabling both efficiency improvements and flexible integration with high-performance libraries.

Abstract

We introduce 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 examples, we use the library FFTW to multiply polynomials using fast Fourier transforms, call a LAPACK function to solve a general Gauss-Markov linear model problem, and use JIT compilation to compute Fibonacci numbers.
Paper Structure (6 sections, 2 equations)