Mathematica for Poor Undergrads
Setting up Mathematica in a Jupyter Notebook using the free Wolfram Engine.
The Issue
If you’re like me, there are times when you need to use Mathematica, but your wallet says no. Recently, while computing the one-loop correction to electron-electron scattering, I ran into some nasty integrals that SymPy just couldn’t handle. I knew from experience that Mathematica would be able to do what I needed, but the $165 price for students is just egregious.
The Solution
After much searching, I discovered that Wolfram provides their engine free of charge to developers. From this point onward, we will bestow upon ourselves the title of developer.
In all seriousness, Wolfram’s own website states that
You can use this product to:
- Develop a product for yourself or your company
- Conduct personal projects at home, at school, at work
- Explore the Wolfram Language for future production projects
So we should be in the clear to use this as students.
Setting it all up
The installation process should be pretty painless, but there are a few dependencies we need to get out of the way.
Updated: Docker Image now Available
I created a docker image available on my github. If you would rather not mess with docker, follow the instructions below.
Install Jupyter
You’ll need python and pip (or preferably conda) for the following. If you’re reading this
article, I’ll assume you have these already installed. Runpip install jupyter-lab
orconda install -c conda-forge jupyter-lab
if you are using conda. Notice we are installing jupyter-lab and not
jupyter-notebook.
Jupyter-Lab
is the next generation user interface for Project Jupyter, and it will
eventually replace Jupyter Notebook. It has all the features of Jupyter
Notebook, and a lot more. However, feel free to use Jupyter Notebook instead if
you already have it installed. Everything will function the same.
Python and $PATH
Make sure your python installation is added to your PATH
environment variable.
On Mac and Linux, add
export PATH="<path to python installation>/bin:$PATH"
to your .bashrc
.
On Windows, it is not as simple. Refer to
this
guide to learn how to modify your PATH
. Make sure to add your python
installation to it.
Install the Wolfram Engine
Navigate to https://www.wolfram.com/engine/ and download the appropriate package for your operating system. Follow the installation instructions that Wolfram provides (Windows, Mac, Linux). Keep track of the installation location.
Add wolframscript to $PATH
Later, we will need to be able to execute wolframscripts from our terminal. We
need to add the wolframscript
executable to our PATH
to be able to run these scripts easily.
Wolframscript is located in the Binaries/<your-os>/
sub-directory within the Wolfram Engine
installation. Follow the below instructions to get things working correctly.
For Mac and Linux users, add the
Wolfram/WolframEngine/12.0/SystemFiles/Kernel/Binaries/<your-os>/
directory to your PATH
. I used the default installation location, and added the following to my
.bashrc
:
export PATH=$PATH:"/usr/local/Wolfram/WolframEngine/12.0/SystemFiles/Kernel/Binaries/Linux-x86-64/"
Replace this with the location of your installation.
For Windows users, also add the
Wolfram/WolframEngine/12.0/SystemFiles/Kernel/Binaries/<your-os>/
directory to your PATH
. Follow the same steps you did to add to your PATH
earlier.
Configure Jupyter
Now, we need to tell Jupyter how to talk to our Wolfram Engine. Luckily, there is a repository on Github that allows us to do just that.
On Mac or Linux run:
git clone https://github.com/WolframResearch/WolframLanguageForJupyter.git
cd WolframLanguageForJupyter
./configure-jupyter.wls add
If you are on Windows, visit https://github.com/WolframResearch/WolframLanguageForJupyter and download as a zip from the clone or download button. Unzip, and navigate to the unzipped directory. Open Powershell in this directory, and do step 3. from above.
Use Mathematica!
Now, start jupyter-lab. You may do this through a GUI or by running jupyter-lab
from a terminal. If all went well, on the launcher you should have an option to
start a Wolfram Language Notebook.
Start a Wolfram Language Notebook, and have at it!