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

[WIP] Modifed sympy.assumptions.handlers for DenseMatrix #17336

Merged
merged 5 commits into from Aug 11, 2019

Conversation

@czgdp1807
Copy link
Member

commented Aug 4, 2019

References to other Issues or PRs

Brief description of what is fixed or changed

The AskHermitianHandler has been modified for return correct results.

Before

>>> from sympy import Q, ask, I, Matrix
>>> M = Matrix([[2, 2 + I, 4], [2 - I, 3, I], [4, -I, 1]])
>>> ask(Q.hermitian(M))
False

After

>>> from sympy import Q, ask, I, Matrix
>>> M = Matrix([[2, 2 + I, 4], [2 - I, 3, I], [4, -I, 1]])
>>> ask(Q.hermitian(M))
True

Other comments

Currently only, AskHermitianHandler has been modified. More changes will be made to other handlers on receiving reviews on the approach used in the last commit.
ping @asmeurer @Upabjojr

Release Notes

  • assumptions
    • Queries for properties of matrices have been fixed, like. Q.hermitian, etc.
@sympy-bot

This comment has been minimized.

Copy link

commented Aug 4, 2019

Hi, I am the SymPy bot (v147). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • assumptions
    • Queries for properties of matrices have been fixed, like. Q.hermitian, etc. (#17336 by @czgdp1807)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed
The `AskHermitianHandler` has been modified for return correct results.

**Before**
```python
>>> from sympy import Q, ask, I, Matrix
>>> M = Matrix([[2, 2 + I, 4], [2 - I, 3, I], [4, -I, 1]])
>>> ask(Q.hermitian(M))
False
```
**After**
```python
>>> from sympy import Q, ask, I, Matrix
>>> M = Matrix([[2, 2 + I, 4], [2 - I, 3, I], [4, -I, 1]])
>>> ask(Q.hermitian(M))
True
```
#### Other comments
Currently only, `AskHermitianHandler` has been modified. More changes will be made to other handlers on receiving reviews on the approach used in the last commit.
ping @asmeurer @Upabjojr 

#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* assumptions
  * Queries for properties of matrices have been fixed, like. `Q.hermitian`, etc.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov

This comment has been minimized.

Copy link

commented Aug 4, 2019

Codecov Report

Merging #17336 into master will increase coverage by 0.062%.
The diff coverage is 100%.

@@              Coverage Diff              @@
##            master    #17336       +/-   ##
=============================================
+ Coverage   74.625%   74.687%   +0.062%     
=============================================
  Files          627       631        +4     
  Lines       162775    163189      +414     
  Branches     38185     38287      +102     
=============================================
+ Hits        121471    121882      +411     
- Misses       35930     35975       +45     
+ Partials      5374      5332       -42
sympy/assumptions/ask.py Outdated Show resolved Hide resolved
sympy/assumptions/handlers/sets.py Outdated Show resolved Hide resolved
sympy/assumptions/handlers/sets.py Outdated Show resolved Hide resolved
sympy/assumptions/tests/test_query.py Outdated Show resolved Hide resolved

czgdp1807 added some commits Aug 8, 2019

def Expr(expr, assumptions):
if isinstance(expr, MatrixBase):
return None
return AskRealHandler.Expr(expr, assumptions)

This comment has been minimized.

Copy link
@Upabjojr

Upabjojr Aug 11, 2019

Contributor

well... Expr may be anything, you cannot just exclude matrices. This redirection is potentially dangerous.

This comment has been minimized.

Copy link
@czgdp1807

czgdp1807 Aug 11, 2019

Author Member

I introduced this method because, otherwise, the call was re-directed to AskRealHandler.Expr which was giving incorrect results. It seems that some refactoring is required for fixing this.

This comment has been minimized.

Copy link
@Upabjojr

Upabjojr Aug 11, 2019

Contributor

Maybe AskHermitianHandler should not inherit AskRealHandler.

@@ -336,6 +338,12 @@ class AskHermitianHandler(AskRealHandler):
Test that an expression belongs to the field of Hermitian operators
"""

@staticmethod
def Expr(expr, assumptions):
if isinstance(expr, MatrixBase):

This comment has been minimized.

Copy link
@Upabjojr

Upabjojr Aug 11, 2019

Contributor

subclasses should have their own method. Define def MatrixBase( ... ): instead of using isinstance.

This comment has been minimized.

Copy link
@czgdp1807

czgdp1807 Aug 11, 2019

Author Member

Yes, actually, according to the current logic, if subclasses, give None then the call is transferred to the methods up in the hierarchy in the __mro__. So, probably, a fix is needed somewhere there.

@Upabjojr Upabjojr merged commit 1b99ff5 into sympy:master Aug 11, 2019

3 checks passed

codecov/project 74.687% (target 0%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
sympy-bot/release-notes The release notes look OK
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.