Skip to content

Conversation

@bjodah
Copy link
Contributor

@bjodah bjodah commented Jul 2, 2025

No description provided.

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

isuruf commented Jul 28, 2025

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

@bjodah
Copy link
Contributor Author

bjodah commented Jul 28, 2025 via email

@isuruf
Copy link
Member

isuruf commented Jul 28, 2025

What does SymPy do with has_symbol?

@bjodah
Copy link
Contributor Author

bjodah commented Jul 28, 2025

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

isuruf commented Jul 28, 2025

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
Copy link
Contributor Author

bjodah commented Jul 28, 2025

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

certik commented Jul 28, 2025

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
Copy link
Contributor Author

bjodah commented Jul 28, 2025

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

isuruf commented Jul 28, 2025

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

@bjodah
Copy link
Contributor Author

bjodah commented Jul 28, 2025

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
Copy link
Contributor Author

bjodah commented Jul 29, 2025

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