Enhancing Convenience in Computer Algebra Systems
Written on
Chapter 1: Introduction
In the realm of computer algebra systems (CAS), my journey has been quite revealing. Despite years of engagement with these tools, I find myself still relying heavily on traditional methods for complex calculations. CAS, particularly Python's SymPy, serves as an aid for specific tedious tasks and visualizations, but it's not yet my go-to for complete workflows. The primary obstacle? Minor yet significant distractions that divert my attention from the mathematical or physical issues at hand.
Often, when faced with lengthy or intricate expressions, the subsequent step involves manipulating certain subexpressions. While CAS like SymPy offer functions to facilitate this, the process can be cumbersome. For instance, even seasoned users may take a minute to select the correct subexpression, shifting their focus from problem-solving to navigating the tool itself. I believe these distractions play a crucial role in why many of us still resort to pen and paper. However, there are solutions on the horizon! Although I don't have a definitive answer yet, I do have a helpful tool to share.
Section 1.1: A New Tool for Subexpression Selection
In this article, I introduce a handy utility that enables users to graphically select SymPy subexpressions using their mouse directly within a Jupyter notebook. To witness this tool in action, check out the brief video below:
This video provides an overview of the navigator tool's functionality, illustrating how it simplifies the selection process.
Subsection 1.1.1: Installation and Usage
To get started with this tool, you can easily install the sympytools package via pip:
pip install --upgrade sympytools
Once you've installed it, import the navigator tool in your Jupyter notebook. Create an instance of the Navigator class and invoke the navigate method on the desired SymPy expression:
from sympytools import Navigator
nav = Navigator()
nav.navigate(expr)
As demonstrated in the previous video, a panel appears displaying the expression with buttons at the top and additional subexpressions listed below. Click on the “Select” button corresponding to the subexpression you wish to manipulate. You can continue this process until you identify the desired subexpression. If you mistakenly select the wrong one, simply utilize the “Go up” button to return to the previous level. After making your selection, click “Copy” to save the path to the subexpression onto your clipboard.
Section 1.2: Understanding the Path Concept
You might wonder, what exactly is a "path"? As discussed in another article, SymPy expressions maintain their next-level subexpressions within their args tuples. Therefore, a deeply nested subexpression can be accessed in a convoluted manner, like so:
expr.args[1].args[0].args[0].args[1].args[2]
This isn't the most user-friendly approach. The concept of a "path" simplifies this into a straightforward list of indices, such as [1, 0, 0, 1, 2]. When you click the “Copy” button, this list is saved to your clipboard. You can then retrieve the subexpression by using the get_by_path function, pasting the path as follows:
from sympytools import get_by_path
subexpr = get_by_path(expr, [1, 0, 0, 1, 2])
And that's all there is to it! I hope you find this tool beneficial. If you have any questions or suggestions, feel free to reach out via comment or private message. Thank you for reading!
Chapter 2: Further Learning
To delve deeper into the functionality of computer algebra systems, consider the following video:
This video offers an insightful overview of computer algebra systems, showcasing their potential applications and features.