Proper Workflow for storing Symbols and Expressions #25584
Unanswered
PascalGitz
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey
I guess my problem/question is due to sympy being used in python (programming language in general), rather than in a special math-language. I would still like to hear your suggestions.
Goal
I have been using sympy for a while now. My goal is to create calculations as reproducible as possible only via the output. As I have done in the following image (documentation via Quarto):
Problem
Something that I'm always struggling with, is how to structure my code / storing in variables.
Some different approaches that i came up with on an example calculating the area and volume:
the desired output would be:
First approach
The first approach is storing them in sp.Eq:
This approach seems to be too tedious and prone to errors because i have to keep resubbing the symbols with its equation-counterpart.
Second approach
The next approach i took was to overwrite the symbols:
It feels natural to do calculations in this manner. The problem is, that i overwrite the symbols, which hinders me to get the desired output of
sp.Eq(V, A*h)
. Especially when the calculations in the variables are getting bigger, a substitution with a simple Symbol is necessary to keep the overview (an example out of context):where:
and the output i get in my u_p-variable due my workflow:
Which is not easy to handle anymore.
Third approach
The last approach i had, was to somehow create a store for my expressions:
Which works not too bad, but as it can be seen in the display function: To get the final display of the volume in need to sub V 2 times. With increasing dict-size with equations building on each other, the n-subs increase, which is not feasable anymore by hand (maybe write a function that subs for n times where n is the length of the dict).
Outlook
Wouldn't it be great to have a class simillar to sp.symbols() where i can store the symbol and the corresponding expression. The class is capable of doing all the operations in sympy on the symbol and the expression. With some defined functions i could then display only with the symbols, with a different function i could render it with the expressions. Some pseudocode to illustrate what i mean:
So my question is, how do you handle this? What would you suggest that i can achieve my goal?
Beta Was this translation helpful? Give feedback.
All reactions