Skip to content
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 a bug in simplify_expr() reading symbols with illegal characters #26531

Closed
wants to merge 2 commits into from

Conversation

nikgup11
Copy link

Fixes #26184

Description:
Issue author alfadir opened an issue about how using imported parameter names in parse_expr from sympy.parsing.sympy_parser contains symbols with special characters. This causes confusion in the parser where those imported symbols get mismatched and don't correctly align with the result. For example, "pro-duct" should match with "product". They provided a tok.py test script that they wrote which includes their proposed fix of using a dictionary to map the symbols, which only solved half of the problem, as seen in simplify_expr_new(). My changes implemented in simplify_expr_new_v2() add to their solution by including calls to the RegEx library to filter out integers (0-9) and characters
(+, -, .) from the input symbol so that the dictionary maps to that.

Release Notes

  • functions
    • Fixed a bug in simplify_expr(). Formerly, local_dict would map {'pro-duct' : 'pro-duct'} now it maps {'pro-duct' : 'product'}

nikgup11 and others added 2 commits April 23, 2024 00:16
Implemented fix in parse_expr for stringify_expr via tok.py test
script for recognizing illegal characters in symbols and
mapping inputted symbol to correct one. Achieved this by expanding
upon issue author alfadir's idea of using a local dictionary, and also
using the RegEx library to filter out illegal characters such as +, -,
or . according to what they mentioned, but this list can be expanded
later. Using this filtration system, symbols like "pro-duct" read into
stringify_expr will be mapped to the actual symbol "product" without
changing the original input symbol.
@sympy-bot
Copy link

Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • functions
    • Fixed a bug in simplify_expr(). Formerly, local_dict would map {'pro-duct' : 'pro-duct'} now it maps {'pro-duct' : 'product'} (#26531 by @nikgup11)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13.

Click here to see the pull request description that was parsed.
Fixes #26184 

Description:
Issue author alfadir opened an issue about how using imported parameter names in parse_expr from sympy.parsing.sympy_parser contains symbols with special characters. This causes confusion in the parser where those imported symbols get mismatched and don't correctly align with the result. For example, "pro-duct" should match with "product". They provided a tok.py test script that they wrote which includes their proposed fix of using a dictionary to map the symbols, which only solved half of the problem, as seen in simplify_expr_new(). My changes implemented in simplify_expr_new_v2() add to their solution by including calls to the RegEx library to filter out integers (0-9) and characters 
(+, -, .) from the input symbol so that the dictionary maps to that. 

#### Release Notes

<!-- BEGIN RELEASE NOTES -->
* functions
  * Fixed a bug in simplify_expr(). Formerly, local_dict would map {'pro-duct' : 'pro-duct'} now it maps {'pro-duct' : 'product'}
<!-- END RELEASE NOTES -->

@sympy-bot
Copy link

🟠

Hi, I am the SymPy bot. I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it.

This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75.

The following commits add new files:

If these files were added/deleted on purpose, you can ignore this message.

@oscarbenjamin
Copy link
Contributor

I don't understand what the purpose of this is but the code is not something that we would add to sympy so I'm going to close this. Please discuss on the issue what the appropriate fix for the issue should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing strings with defined Symbols with special characters
3 participants