Skip to content

Conversation

@mmatera
Copy link
Contributor

@mmatera mmatera commented Nov 30, 2025

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
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("_", "`")
Copy link
Member

@rocky rocky Dec 1, 2025

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?

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("`", "_")
Copy link
Member

@rocky rocky Dec 1, 2025

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
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.


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
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
Copy link
Member

rocky commented Dec 1, 2025

LGTM. Please consider DRYing the code.

Copy link
Member

@rocky rocky left a comment

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.

3 participants