Skip to content
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

Should is_square be in the main namespace? #16830

Open
asmeurer opened this issue May 13, 2019 · 4 comments
Open

Should is_square be in the main namespace? #16830

asmeurer opened this issue May 13, 2019 · 4 comments
Labels
Needs Decision This needs discussion to resolve an undecided issue before further work can be done. ntheory

Comments

@asmeurer
Copy link
Member

We have is_square in sympy.ntheory.primetest, but it isn't included in the main __init__.py.

It seems to do a lot more than the naive test that most people would use, and also more than perfect_power(x, [2]), which it falls back on.

Should we add it to the main namespace?

@asmeurer asmeurer added ntheory Needs Decision This needs discussion to resolve an undecided issue before further work can be done. labels May 13, 2019
@smichr
Copy link
Member

smichr commented May 14, 2019

I recall working with those functions a fair amount. That function is optimal for determining, as docstring says, whether something is not square -- i.e. it should be used as a confirmation that something is not square. So if is_square(n) reads "I doubt that n is square, but it it is...". To use perfect_power requires two steps: q = perfect_power(n, [2]); if q and not q[1]%2.

@sylee957
Copy link
Member

is_square is also used in matrix predicates for completely different purpose, but it can be managable if matrix module doesn't make those predicates loose.

@asmeurer
Copy link
Member Author

asmeurer commented May 14, 2019

We could rename it to is_square_number, although there are a lot of functions that use scalar names that apply differently when used in a matrix context.

@asmeurer
Copy link
Member Author

That function is optimal for determining, as docstring says, whether something is not square -- i.e. it should be used as a confirmation that something is not square.

What would be an example of misuse? Most numbers aren't squares, so I would expect generic use of the function to have this condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Decision This needs discussion to resolve an undecided issue before further work can be done. ntheory
Projects
None yet
Development

No branches or pull requests

3 participants