Skip to content

Make Basic.has behave more like SymPy, use new visitor #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 4, 2025

Conversation

bjodah
Copy link
Contributor

@bjodah bjodah commented Jul 29, 2025

@@ -19,7 +19,7 @@
Max, Min, DenseMatrix, Matrix,
ImmutableMatrix, ImmutableDenseMatrix, MutableDenseMatrix,
MatrixBase, Basic, DictBasic, symarray, series, diff, zeros,
eye, diag, ones, Derivative, Subs, expand, has_symbol,
eye, diag, ones, Derivative, Subs, expand, has_basic, has_symbol,
Copy link
Member

Choose a reason for hiding this comment

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

Let's not export has_basic and use .has

def has(self, *symbols):
return any([has_symbol(self, symbol) for symbol in symbols])
def has(self, *args):
for arg in args:
Copy link
Contributor Author

@bjodah bjodah Jul 29, 2025

Choose a reason for hiding this comment

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

The loop here begs the question:
Should HasBasicVisitor's looking_for_ rather be a vec_basic instead of a simple rcp_basic? If it's common to query with multiple arguments, then a vec_basic would avoid traversing the (possibly large) syntax tree multiple times, but if the majority of use cases only matches against a single argument, that would be a pessimisation, what do you think?

@bjodah bjodah marked this pull request as ready for review August 4, 2025 21:22
@bjodah
Copy link
Contributor Author

bjodah commented Aug 4, 2025

ready for review.

@isuruf isuruf changed the title [WIP] Make Basic.has behave more like SymPy, use new visitor Make Basic.has behave more like SymPy, use new visitor Aug 4, 2025
@bjodah bjodah merged commit 630a2b0 into symengine:master Aug 4, 2025
19 of 20 checks passed
@bjodah
Copy link
Contributor Author

bjodah commented Aug 4, 2025

thanks!

@bjodah bjodah deleted the has_basic branch August 4, 2025 21:28
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