Skip to content

Keep SymPy symbol assumptions when converting to SymEngine - #539

Open
isuruf wants to merge 1 commit into
symengine:mainfrom
isuruf:symbol
Open

isuruf wants to merge 1 commit into
symengine:mainfrom
isuruf:symbol

Conversation

@isuruf

@isuruf isuruf commented Nov 26, 2026

Copy link
Copy Markdown
Member

Fixes #522

SymPy symbols with assumptions (or non-commutative symbols / subclasses of sympy.Symbol) are now converted to SympySymbol, a PySymbol-backed Symbol subclass that stores the original SymPy object (with store_pickle=True to avoid the reference cycle).

  • Converting back to SymPy returns the original symbol, so assumptions survive a round trip through SymEngine.
  • is_real, is_positive, is_negative, is_nonpositive, is_nonnegative, is_zero, is_integer, is_complex are answered by SymPy.
  • Plain SymPy symbols without assumptions are still converted to a regular Symbol, so the common path is unchanged.
>>> import sympy, symengine
>>> x = sympy.Symbol('x', real=True)
>>> symengine.sympify(x).is_real
True
>>> sympy.sympify(symengine.sympify(x**2 + 1) - 1).args[0] is x
True

Note: SymEngine still compares symbols by name, so Symbol('x') == sympify(sympy.Symbol('x', real=True)) is True.

🤖 Generated with Claude Code

SymPy symbols with assumptions are converted to SympySymbol, a PySymbol
backed Symbol subclass that stores the original SymPy object. Converting
back returns the original symbol and assumption queries like is_real are
answered by SymPy.

Fixes symengine#522

This branch has not been deployed

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

is_real is None when sympyfing a sympy Symbols where real=True

1 participant