David A. Antler
Mathematica on the cheap
Wolfram offers a free trial of Mathematica, but the two weeks elapse quickly. After that, the Personal/Hobby license starts off at a steep $344. If you’re a light user, this seems a bit high!
Fortunately I have a scheme which saved me about $240 and allowed me to tinker with Mathematica for as long as I want.
Why do I use Mathematica?
During the COVID-19 pandemic, I became frustrated with having to rely on information from newspapers and various online dashboards.
Plots found online are interesting, but each plot seems to have a shortcoming. Often the axis origin is deceptive, or the data isn’t granular enough to show the specific county I’m interested in, or the data isn’t normalized by population (when it should be). These issues, plus the seriousness of the pandemic, gave me a new appetite for data processing.
Cobbling together datasets is tedious. But this is where Wolfram Language really shines. For instance, it might be useful to query the population of a US county. Here is what happens when you submit this as a natural language query to Wolfram|Alpha’s web interface.
Not only does it return a result, but it also outputs Wolfram Language code which can be copied directly into your notebook for further analysis.[1]
Due to the extensive built-in knowledge base and a vague interest in functional programming, I find Mathematica to be useful in scratching my data-processing itch.
The trick
Raspberry Pi has traditionally been known as an inexpensive and underpowered Linux computer. Not suitable for daily use. Not great for crunching a lot of numbers, either. Many people still like them for tinkering, or to setup as a PiHole DNS server.
However, the latest version of the Raspberry Pi computer (model 4B) is finally a reasonably fast machine. The addition of USB3 and Gigabit Ethernet have increased its usefulness tremendously.
Did you know that Raspberry Pi also comes with a free[2] copy of Mathematica?
It would be annoying to maintain a whole second computer (with a keyboard, mouse, display, etc) just to run Mathematica. But fortunately you don’t need the peripherals. With the magic of old-school X Window Forwarding, your Mathematica on Pi can run on your existing computer next to all your favorite apps (See my screenshot above).
Here is how I setup my system.
Setup instructions
- Buy a Raspberry Pi 4B from your favorite retailer.
- I recommend the fastest model possible.
- Don’t forget to get a SD card with at least 8GB of storage.
- The exact items I bought to get started were $106 in February.
- RasPi computer $61
- 32GB SD Card $8
- RasPi Case $16
- USB-C power supply $10
- SD Card reader $11
- Provision raspbian onto your SD card.
- If you don’t want to hook up a monitor/keyboard/mouse, you can pre-configure the device to connect to your Wi-Fi access point. See more info on headless mode.
- Install MobaXterm (or an alternative SSH client and X Windowing Server)
- Launch MobaXterm and use it SSH into your RasPi with default credentials (hostname:
raspberrypi.local
, user:pi
, pass:raspberry
)- Note: you should change your password ASAP. Maybe change your hostname, too, to avoid future collisions with other pi’s on the network.
- Optional: upgrade to latest Mathematica version using this script on your Raspberry Pi
- Run the
mathematica
command, and voila, it should pop up on your screen just like the real thing.
Caveats
Mathematica on Pi via an X Window Server looks slick, but there are some practical issues. It is still not as fast as running it natively on your machine. The X Window Server gets quite unresponsive with 3D plots and animations, despite my hardwired connection. And sometimes it’s difficult to tell where the cursor is located.
You may be thinking: why do you need a Raspberry Pi at all? Mathematica is just software, bundled with a free OS, and you can emulate the ARM64 hardware!
Unfortunately I’ve tried emulation, and it didn’t work. Booting Raspbian in QEMU worked fine, but sadly I found a blocker. Launching Mathematica failed when trying to access the GPU. So unfortunately QEMU’s emulation isn’t sufficiently complete to fool Mathematica into thinking it’s on a real Raspberry Pi. D’oh!
Gateway drug
After playing with Mathematica on your Pi for a while, you may find you’ve become accustomed to it. It’s a very comfortable environment. Equations look beautiful. The Notebook interface is excellent, especially for producing documents and reports with data. Computational essays are awesome!
The biggest downside to full Mathematica is the pricetag. As mentioned, the single machine hobby license is currently $344. It becomes particularly expensive if you want to use it for non-hobby purposes. A single professional user license is $3157.
Fortunately, every big company I’ve worked for has had licenses available.
Not at a big company? Don’t fret; there is hope for personal users. If you end up developing a something useful in Mathematica, and you want it to run fast, you can run it on your real computer using the more permissively licensed Wolfram Engine.[3]. This is how I generate lots of my COVID plots quickly, when the Pi just doesn’t have the juice.
Note that Wolfram Language code for your query is only made visible if you hit the “Plain Text” button under the “Input interpretation” box. ↩
personal, non-commercial. See https://www.wolfram.com/legal/agreements/wolfram-mathematica-raspberry-pi/ ↩
pre-production license. See https://www.wolfram.com/engine/ ↩