-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix tests for sympy conversions #1073
Conversation
(These were noticed in working on event tracing) `mathics/builtin/numbers/algebra.py`: black changes its autoformating `mathics/builtin/numbers/numbertheory.py`: some linting prefers triples quotes for docstrings `mathics/core/convert/sympy.py`: use accurate location for singleton class. This reduces unnecessary sympy imports `mathics/core/symbols.py`: shorten prefix and context names for SymPy variables. In tracing we will see these names a lot. A shorter prefix makes understanding expressions involving these easier to follow `CHANGES.rst`: document recent SetEnvironment addition and GetEnvironment changes `test/numbers/__init__.py`: needed if test/numbers is tested separately
mathics/builtin/numbers/algebra.py: black changes its autoformatting mathics/builtin/numbers/numbertheory.py: some linting prefers triples quotes for docstrings mathics/core/convert/sympy.py: use accurate location for singleton class. This reduces unnecessary sympy imports CHANGES.rst: document recent SetEnvironment addition and GetEnvironment changes test/builtin/numbers/__init__.py: needed if testing in this directory is done separately.
Thanks for doing this! I love the fact that some of the hard-coded context strings are now variables. I have been thinking about shortening the prefix by removing the "m". That is instead of "mu" and "ms", just "u" and "s". What strikes me odd about all of this is that basically all SymPy variables or symbols are Mathics3 related. We don't have a way to pass in SymPy variables that are are not Mathics3 related. And just adding any sort of thing before the backtick (which I think is just treated as a character in SymPy) is enough. What I think we want to "optimize" is the ability to understand how Mathics3 expressions (which generally don't have any context designators) are translated to SymPy and track how these things are propagated and translated. Adding additional text detracts from where the focus should be by making the correspondence more different than it need be. Adding to the length in debug output also makes harder to read by making long lines of text even longer. It is not the same thing as using longer more explicit variable names. Your thoughts? |
here what is important is to avoid stepping over names of existing symbols in Sympy. Maybe the underscores and just a letter would be enough for that.
I guess that the only case where this is not completely true is with slots and anonymous functions. But currently, we are not handling them properly either.
Something that I was thinking about is when it makes sense to do the conversion, and how deep the conversion to sympy should go in a nested function. For example, let's say we have something like this:
When the integral can be evaluated, then what we actually convert to sympy is its numerical value. On the other hand, if the integral does not have a numerical value, the conversion to Sympy is useless: we know beforehand that after the conversion which is the result.
then it makes sense to go inside until reaching the atomic parts. Probably we want to take this into account to optimize the conversion.
In debugging, I think that a short prefix can help distinguish what is happening at the level of Sympy and what is at the level of Mathics.
|
Ok. LGTM - merge when you are satisfied. |
This kind of thing is typically done as part of a type inference and special "optimize" pass. Over time I think there will be more type information included. |
This PR just fixes the pytest, and marks some issues in the conversion of Lambda functions. --------- Co-authored-by: rocky <[email protected]>
This PR just fixes the pytest, and marks some issues in the conversion of Lambda functions. --------- Co-authored-by: rocky <[email protected]>
This PR just fixes the pytest, and marks some issues in the conversion of Lambda functions. --------- Co-authored-by: rocky <[email protected]>
@mmatera I was revisiting your example with
using the debugger to see what I can learn using the debugger. First I activate tracing for SymPy and then I run this expression:
Ok, so now I want to see what is going on with what looks like two duplicate SymPy calls to
And when I now run the expression and look at the Backtrace, I see the duplicate call is coming from the same location in rule replacement
|
This PR just fixes the pytest, and marks some issues in the conversion of Lambda functions.