Fermat’s Last Theorem in Sonic Pi: A Ruby Gem for Modular Forms
I. Prelude
Modern number theory is often highly abstract and challenging to approach without advanced mathematical training. Among its most profound achievements is Fermat’s Last Theorem, proven by Andrew Wiles.
A few months ago, I began toying with the idea of bringing these deep mathematical concepts into Sonic Pi in a way that would be both intuitive and musically expressive (perhaps because I had them as a background image on my desktop, who knows?). What started as a fleeting thought quickly grew into a more serious reflection on how I could actually bring it to life.
A few weeks ago, I finally decided to take the plunge. Armed with my notebook, I sketched out some rough ideas and dived in. Inspired in part by tools like SageMath and the LMFDB database, and guided by literature on the subject, I set out to develop a Ruby gem called modular_forms
.
II. Goals
This gem has two main goals:
- To serve as a creative tool for generating music based on deep number theory structures in an intuitive way.
- To provide an educational bridge for those starting their journey into number theory.
III. Getting Started
Install the gem with:
gem install modular_forms
Then, try this example, where we combine eta functions to construct a weight 2 modular form of level 144 associated with an elliptic curve, and use it to create a musical representation of one of the key ideas behind Fermat’s Last Theorem: the connection between them through its L-function
.
Make sure to replace <PATH>
with the actual path where modular_forms.rb
is installed in your system:
require "<PATH>/modular_forms.rb"
# Set precision for Fourier q-expansion
prec = 20
# Build a weight 2 newform as an eta quotient
n = ModularForms.dedekind_eta_pow(12, prec, 12)
d1 = ModularForms.dedekind_eta_pow(4, prec, 6)
d2 = ModularForms.dedekind_eta_pow(4, prec, 24)
eta_prod = ModularForms.eta_product(d1, d2)
newform = ModularForms.eta_quotient(n, eta_prod, prec)
# Define elliptic curve E over F_p
p = 13
ellc = ModularForms.elliptic_curve_fp(p, [0, -1]) # y^2 = x^3 - 1
points = ModularForms.cardinality_fp(ellc)
# Modular coefficient a_p of L-function(E, s)
a_p = ModularForms.a_p(p, points)
# Sonify the modular relationship
live_loop :modularity_music do
play (chord(:a3 + a_p, :m11)[newform.ring.tick]),
amp: a_p, release: 0.125
sleep 0.125
end
You can cross-check the mathematical data in the LMFDB.
IV. Status of modular_forms
The gem is still in its early stages. You can check out the GitHub repository for a list of limitations and the modules that have been implemented so far.
Some of the features currently supported include:
- Eisenstein Series
- Eta Functions and Eta Quotients
- Theta functions
- Ramanujan Tau Function
- J-Function
- Hecke Operators
- SL(2,Z) Group
- Dirichlet Characters
- Elliptic Curves over Rationals
- Elliptic Curves over Finite Fields
- Newforms Invariants
- L-functions
V. Collaboration
If you’re interested in trying it out, providing feedback, or contributing to development, feel free to reach out via email or here. I’d be happy to collaborate and create something together!
Best regards to all fellow live coders!
Edgar Delgado Vega