Re:SymPy: Symbolic Mathematics in Python
by bloaf on Wednesday February 28, 2024 @10:41AM
(#39539384)
The biggest drawback of SymPy is the need to pre-define all your symbols. That makes it more difficult to handle scenarios where you're taking formulas as input because you either need to parse the equation yourself to figure out what variables were used, or have the user manually supply the symbols.
Re:SymPy: Symbolic Mathematics in Python
by staplung on Wednesday February 28, 2024 @11:28AM
(#39540157)
Might not handle exactly the difficulties you're having but you can do
`from sympy.abc import *`. This will create symbols for pretty much all letters (lower and upper) as well as a bunch of greek symbols (but written out, e.g. "delta").
Re:SymPy: Symbolic Mathematics in Python
by bloaf on Wednesday February 28, 2024 @11:49AM
(#39540543)
Imagine a scenario where you've got a database of timeseries data, say stock prices. Each price trend is identified by the stock ticker, and your users have an excel spreadsheet of several thousand equations in terms of the stock ticker (e.g. (AAPL-TSLA)/AAPL) and you want to calculate the derivative of each one of those equations with respect to each ticker symbol in each equation before pulling the data.
Obviously you could find a list of every ticker symbol and create a few thousand symbols before parsing, but you don't always have the luxury of a complete/up-to-date list, or doing so might create too many symbol objects and cause performance problems.
There `isympy -I`, which runs an IPython REPL with a preprocessor that changes unknown variables into sympy symbols, but that only helps you for interactive usage.
Re:SymPy: Symbolic Mathematics in Python
by throw4023042q0 on Wednesday February 28, 2024 @03:09PM
(#39542866)
I usually run a pre-processing step to identify all needed symbols and then create them dynamically. I find sympy works fine for such on-the-fly workflow. My experience is with predictive statistics and financial models.
Here is a little tutorial for anyone looking to get started: https://minireference.com/static/tutorials/sympy_tutorial.pd...
Also available in runnable notebook format: https://colab.research.google.com/github/minireference/sympy... (read only = http://nbviewer.ipython.org/github/minireference/sympytut_no... )
Last but not least, for anyone interested in trying SymPy without installing anything, there is always the SymPy live shell: https://live.sympy.org/ (runs Python + SymPy in the browser thanks to WebAssembly)