Published on

Developing a Python Library for Symbolic Computation and Pedagogy | A Little Struggle

Authors

Introduction

'Yup, let's create something cool: a symbolic computation library!'

I know there are many existing libraries for this purpose, but I wanted to understand how they work from the ground up. To make things more interesting, I aimed to create a library that outputs step-by-step explanations for solving problems, similar to tools like WolframAlpha, Photomath, Symbolab, and Socratic.

Challenges and Considerations

After some research, I realized that recreating a basic version of SymPy or similar Computer Algebra Systems (CAS) wouldn't be ideal if pedagogy is a primary goal. CAS are built for efficient and accurate computations, often minimizing the number of steps used. This means that the intermediate steps crucial for human understanding might be absent.

For a deeper understanding, check out this talk on the creation of Google Mathsteps/ the earlier version of Socratic: https://youtu.be/CuZVwTnffbI?si=NnZBY3Qv5Xy1TyeH

Inspiration and Initial Approach

Knowing the limitations of replicating CAS, I explored the Google Mathsteps source code. While impressive, it's built with JavaScript. Mathsteps relies heavily on Math.js, a popular JavaScript math library. While Math.js has well-written and understandable code, it's not Python.

I attempted to replicate Math.js's functionality in Python, but it felt inelegant and un-Pythonic. With a better understanding of SymPy, Mathsteps, and Math.js, I decided to build my own library from scratch.

Development Process

Initially, I coded different ways to handle core functionalities. However, expanding from these core functionalities proved difficult due to how I initially coded them. I ended up rewriting the core multiple times until I achieved a more expandable structure.

Looking Ahead

Finally, I believe I have a solid, expandable core. Hopefully, this time, I won't need to rewrite the entire core again! In the next post, I'll document the core functionality I've created so far. I'll continue to post updates with major changes to the system.

Code is on my GitHub: https://github.com/RezSat/mathemapy

Thank you for reading!