Skip to content

Underscore instead of grave tilde in sympy names as context separators - #1536

Merged
mmatera merged 5 commits into
good_bye_sympy_dummy_attributefrom
underline_instead_of_grave_tilde_in_sympy_names
Dec 2, 2025
Merged

mmatera merged 5 commits into
good_bye_sympy_dummy_attributefrom
underline_instead_of_grave_tilde_in_sympy_names

Conversation

@mmatera

@mmatera mmatera commented Nov 30, 2025

Copy link
Copy Markdown
Contributor

This continues #1535, by changing the way in which symbol names are translated to sympy.

@mmatera
mmatera changed the base branch from master to good_bye_sympy_dummy_attribute November 30, 2025 18:08
Comment thread mathics/core/convert/sympy.py Outdated
return Expression(SymbolC, Integer(int(name[1:])))
if name.startswith(SYMPY_SYMBOL_PREFIX):
name = name[len(SYMPY_SYMBOL_PREFIX) :]
name = name[len(SYMPY_SYMBOL_PREFIX) :].replace("_", "`")

@rocky rocky Dec 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This idiom appears about 3 times in this PR. Maybe it should be a little function?

Comment thread mathics/core/symbols.py
def sympy_name(mathics_symbol: Symbol):
"""Convert a mathics symbol name into a sympy symbol name"""
return SYMPY_SYMBOL_PREFIX + mathics_symbol.name
return SYMPY_SYMBOL_PREFIX + mathics_symbol.name.replace("`", "_")

@rocky rocky Dec 1, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SYMPY_SYMBOL_PREFIX + mathics.symbol.name.replace("``'", "_") seems like an idiom. Maybe it could be turned into a function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, is already a function. What is not a function yet is the conversion in the opposite direction.

Comment thread test/core/test_sympy_python_convert.py Outdated

def testSymbol(self):
self.compare(Symbol("Global`x"), sympy.Symbol(f"{SYMPY_SYMBOL_PREFIX}Global`x"))
self.compare(Symbol("Global`x"), sympy.Symbol(f"{SYMPY_SYMBOL_PREFIX}Global_x"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too, feels like an idiom that is used a couple of times. Maybe turn into a function, too.

The thing about making functions like this that I appreciate is that the function name signals something, and a docstring is available to explain what's going on better.

@rocky

rocky commented Dec 1, 2025

Copy link
Copy Markdown
Member

LGTM. Please consider DRYing the code.

@rocky rocky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional changes.

@mmatera
mmatera force-pushed the underline_instead_of_grave_tilde_in_sympy_names branch from 4cd7284 to ba2c6bf Compare December 2, 2025 01:19
@mmatera
mmatera merged commit 5ea915b into good_bye_sympy_dummy_attribute Dec 2, 2025
12 checks passed
@mmatera
mmatera deleted the underline_instead_of_grave_tilde_in_sympy_names branch December 2, 2025 02:02
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.

2 participants