Skip to content

support Infty and NaN in has_symbol(...)#2105

Closed
bjodah wants to merge 5 commits into
symengine:masterfrom
bjodah:has_symbol-Infty-NaN
Closed

support Infty and NaN in has_symbol(...)#2105
bjodah wants to merge 5 commits into
symengine:masterfrom
bjodah:has_symbol-Infty-NaN

Conversation

@bjodah

@bjodah bjodah commented Jul 2, 2025

Copy link
Copy Markdown
Contributor

No description provided.

bjodah added a commit to bjodah/symengine.py that referenced this pull request Jul 2, 2025
@isuruf

isuruf commented Jul 28, 2025

Copy link
Copy Markdown
Member

I'm not sure about this. has_symbol is for symbolic variables, but infty and nan are not symbolic variables.

@bjodah

bjodah commented Jul 28, 2025 via email

Copy link
Copy Markdown
Contributor Author

@isuruf

isuruf commented Jul 28, 2025

Copy link
Copy Markdown
Member

What does SymPy do with has_symbol?

@bjodah

bjodah commented Jul 28, 2025

Copy link
Copy Markdown
Contributor Author

You can take a look at the suggested tests in symengine/symengine.py#515

That behavior matches SymPy. But perhaps we should not use has_symbol to implement the method has?

@isuruf

isuruf commented Jul 28, 2025

Copy link
Copy Markdown
Member

Yeah, has is very broad. For eg:

>>> from sympy import *
>>> var("x y z")
(x, y, z)
>>> (2*x*y).has(2*x)
True
>>> (2*x*y).has(2)
True

@bjodah

bjodah commented Jul 28, 2025

Copy link
Copy Markdown
Contributor Author

I know, in this case, I need to check if a symbolic expression contains infinity. has is useful, but perhaps there's another method?

@certik

certik commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

It looks like we already support infinity as a symbol, correct?

If so, adding the support for checking it makes sense.

How is the infinite symbol implemented exactly in SymEngine? That should guide us how to check for it.

@bjodah

bjodah commented Jul 28, 2025

Copy link
Copy Markdown
Contributor Author

@certik, this is the definition:

class Infty : public Number
{
RCP<const Number> _direction;

In this case, a "HasBasicVisitor" that allows matching for more Basic subclasses than only Symbol would be useful for me.

If we want symengine.py to be a drop-in replacement for SymPy we need to figure out how to match subtrees I guess? (what I think @isuruf alluded to).

@isuruf

isuruf commented Jul 28, 2025

Copy link
Copy Markdown
Member

Yeah, a HasBasicVisitor would be the correct thing to have.

@bjodah

bjodah commented Jul 28, 2025

Copy link
Copy Markdown
Contributor Author

Alright, I will try to implement a HasBasicVisitor tomorrow (it's getting late here), and hopefully get back with a new PR soon. Thanks!

@bjodah

bjodah commented Jul 29, 2025

Copy link
Copy Markdown
Contributor Author

Closing in favor of gh-2120

@bjodah bjodah closed this Jul 29, 2025
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