On Sat, Sep 27, 2025 at 10:46 PM Ryan Carsten Schmidt wrote: >> > > Here's my attempt to build a Pluto GMP binding: > > > > #!/bin/bash > > > > # clang -c -fpic libpluto-gmp.c -I /opt/homebrew/Cellar/gmp/6.3.0/include/ > > # clang -O3 -fpic -shared -o libpluto-gmp.dylib libpluto-gmp.o -lgmp -L > > /opt/homebrew/Cellar/gmp/6.3.0/lib/ > > If we wanted to try to reproduce this on our systems, where would we get this > libpluto-gmp.c?
I believe the relevant link for this project is: https://rosettacode.org/wiki/Fermat_numbers#Pluto One needs to copy the code from there into a file e.g. fermat.pluto, but also follow the links to Pluto-bignum and Pluto-fmt and copy their code into additional files bignum.pluto and fmt.pluto and additionally for bignum the code of libpluto-gmp.c is given and how to compile it. I also downloaded the macOS binary of Pluto from their GitHub releases and unpacked it into /Volumes/Shared where it created a MacOS.X64 directory. Provided I have libpluto-gmp.dylib in the current directory, I'm able to run "/Volumes/Shared/MacOS.X64/pluto fermat.pluto" and get this output: The first 10 fermat numbers are: F₀ = 3 F₁ = 5 F₂ = 17 F₃ = 257 F₄ = 65537 F₅ = 4294967297 F₆ = 18446744073709551617 F₇ = 340282366920938463463374607431768211457 F₈ = 115792089237316195423570985008687907853269984665640564039457584007913129639937 F₉ = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084097 Factors of the first 9 Fermat numbers: F₀ = {3} (prime) F₁ = {5} (prime) F₂ = {17} (prime) F₃ = {257} (prime) F₄ = {65537} (prime) F₅ = {641, 6700417} F₆ = {274177, 67280421310721} sh: factor: command not found /Volumes/Shared/MacOS.X64/pluto: fermat.pluto:29: attempt to index a nil value (field 'integer index') stack traceback: fermat.pluto:29: in main chunk [C]: in ? F₇ = {}% The problem here is that "factor" is a GNU coreutils command and we install all of those with a "g" prefix. One solution is to edit bignum.pluto and find the line: os.execute($"factor {n:tostring()} > {filename}") and change it to: os.execute($"gfactor {n:tostring()} > {filename}") Then, provided the coreutils port is installed, I get hopefully the output you're looking for: The first 10 fermat numbers are: F₀ = 3 F₁ = 5 F₂ = 17 F₃ = 257 F₄ = 65537 F₅ = 4294967297 F₆ = 18446744073709551617 F₇ = 340282366920938463463374607431768211457 F₈ = 115792089237316195423570985008687907853269984665640564039457584007913129639937 F₉ = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084097 Factors of the first 9 Fermat numbers: F₀ = {3} (prime) F₁ = {5} (prime) F₂ = {17} (prime) F₃ = {257} (prime) F₄ = {65537} (prime) F₅ = {641, 6700417} F₆ = {274177, 67280421310721} F₇ = {59649589127497217, 5704689200685129054721} F₈ = {1238926361552897, 93461639715357977769163558199606896584051237541638188580280321} The smallest factor of F₉ is: 2424833 If you want this to work when libpluto-gmp.dylib is somewhere other than the current directory, you can edit bignum.pluto and find the line: case "macos" -> "./libpluto-gmp.dylib" and change the path to the absolute path where you placed the library.
