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

Add .is_square() function for symbolic expression #25460

Closed
vinklein mannequin opened this issue May 29, 2018 · 22 comments
Closed

Add .is_square() function for symbolic expression #25460

vinklein mannequin opened this issue May 29, 2018 · 22 comments

Comments

@vinklein
Copy link
Mannequin

vinklein mannequin commented May 29, 2018

Fix the following behaviour :

sage: f(n)=n^2
sage: f(2).is_square()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-2-07de71372bf0> in <module>()
----> 1 f(Integer(2)).is_square()

/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.CommutativeRingElement.is_square (build/cythonized/sage/structure/element.c:20900)()
   3020             framework.
   3021         """
-> 3022         raise NotImplementedError("is_square() not implemented for elements of %s" % self.parent())
   3023 
   3024     def sqrt(self, extend=True, all=False, name=None):

NotImplementedError: is_square() not implemented for elements of Symbolic Ring

CC: @videlec

Component: symbolics

Author: Vincent Klein

Branch/Commit: 88a1145

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/25460

@vinklein vinklein mannequin added this to the sage-8.3 milestone May 29, 2018
@vinklein vinklein mannequin added c: symbolics labels May 29, 2018
@vinklein vinklein mannequin self-assigned this May 29, 2018
@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 29, 2018

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 29, 2018

Author: Vincent Klein

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 29, 2018

Commit: ac0dc8e

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 29, 2018

New commits:

ac0dc8eTrac #25460: Add is_square method to symbolic expression

@vinklein vinklein mannequin added the s: needs review label May 29, 2018
@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 29, 2018

comment:4

Currently is_square((x-1)^2) return True the last commit don't do that.

@vinklein vinklein mannequin added s: needs work and removed s: needs review labels May 29, 2018
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Changed commit from ac0dc8e to d3fdcae

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Branch pushed to git repo; I updated commit sha1. New commits:

d3fdcaeTrac #25460: enable is_square to manage non numeric ...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

c1c77e7Trac #25460: enable is_square to manage non numeric ...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Changed commit from d3fdcae to c1c77e7

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 30, 2018

comment:7

Enable is_square to manage non numeric expression.

@vinklein vinklein mannequin added s: needs review and removed s: needs work labels May 30, 2018
@videlec
Copy link
Contributor

videlec commented May 30, 2018

comment:8

Note that is_square is completely broken for symbolic expression. Moving it as a method is not helping in any way.

sage: x = SR.var('x')
sage: is_square((cos(x) + 1)^2)
True
sage: is_square((cos(x) + 1)^2, True)   # WTF?
Traceback (most recetn call last):
...
TypeError: unable to convert 2 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 + 1/40320*x^8 - 1/3628800*x^10 + 1/479001600*x^12 - 1/87178291200*x^14 + 1/20922789888000*x^16 + O(x^18) to a symbolic expression

And for example, the following should be False

sage: is_square(cos(x) - cos(x).taylor(x, 0, 20))
True

I would suggest to let this method raise NotImplementedError whenever it is not possible to call is_square on the underlying pyobject.

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 30, 2018

comment:9

This mean is_square((x-1)^2) (with #24677) will have a different behaviour, are you ok with that ?

@videlec
Copy link
Contributor

videlec commented May 30, 2018

comment:10

Replying to @vinklein:

This mean is_square((x-1)^2) (with #24677) will have a different behaviour, are you ok with that ?

yes

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Changed commit from c1c77e7 to db90194

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

db90194Trac #25460: Raise NotImplementedError when is_square ...

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 30, 2018

comment:12

Done

@videlec
Copy link
Contributor

videlec commented May 30, 2018

comment:13
try:
    obj = self.pyobject()
except TypeError:
    raise NotImplementedError("is_square() not implemented for non numeric elements of Symbolic Ring")

return obj.is_square()

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

88a1145Trac #25460: Raise NotImplementedError when is_square ...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2018

Changed commit from db90194 to 88a1145

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented May 30, 2018

comment:15

Ok

@videlec
Copy link
Contributor

videlec commented May 30, 2018

Reviewer: Vincent Delecroix

@vbraun
Copy link
Member

vbraun commented Jun 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants