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

Fix matrix-matrix hadamard power #16508

Merged
merged 4 commits into from Aug 30, 2019

Conversation

sylee957
Copy link
Member

@sylee957 sylee957 commented Mar 31, 2019

References to other Issues or PRs

Fixes #16505

Brief description of what is fixed or changed

If both base and exponent are matrix, hadamard power can be defined from hadamard exponential and logarithm as usual definition for the matrix power.
image

And since hadamard exponential and hadamard log are elementwise exponential and logarithm, it can be reduced to
image
for each matrix elements.

Still the definition for the hadamard power between a matrix and a scalar is unclear, however, if it is defined as usual matrix-scalar product, it can easily be reduced to the elementwise power.

Other comments

Release Notes

  • matrices
    • HadamardProduct.as_explicit now supports matrix to matrix power.
    • Added missing doc for HadamardProduct and HadamardPower.

@sympy-bot
Copy link

sympy-bot commented Mar 31, 2019

Hi, I am the SymPy bot (v148). 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:

  • matrices
    • HadamardProduct.as_explicit now supports matrix to matrix power. (#16508 by @sylee957)

    • Added missing doc for HadamardProduct and HadamardPower. (#16508 by @sylee957)

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. -->

Fixes #16505

#### Brief description of what is fixed or changed

If both base and exponent are matrix, hadamard power can be defined from hadamard exponential and logarithm as usual definition for the matrix power. 
![image](https://user-images.githubusercontent.com/34944973/63642286-eb650a00-c6f7-11e9-87d2-96f4e7922cb9.png)


And since hadamard exponential and hadamard log are elementwise exponential and logarithm, it can be reduced to
![image](https://user-images.githubusercontent.com/34944973/55284069-53fac580-53aa-11e9-9560-cdc6ebdd1579.png)
for each matrix elements.

Still the definition for the hadamard power between a matrix and a scalar is unclear, however, if it is defined as usual matrix-scalar product, it can easily be reduced to the elementwise power.

#### Other comments


#### 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 -->
- matrices
  - `HadamardProduct.as_explicit` now supports matrix to matrix power.
  - Added missing doc for `HadamardProduct` and `HadamardPower`.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov
Copy link

codecov bot commented Mar 31, 2019

Codecov Report

Merging #16508 into master will decrease coverage by 0.004%.
The diff coverage is 70%.

@@              Coverage Diff              @@
##            master    #16508       +/-   ##
=============================================
- Coverage   74.699%   74.694%   -0.005%     
=============================================
  Files          633       633               
  Lines       164460    164487       +27     
  Branches     38611     38623       +12     
=============================================
+ Hits        122850    122863       +13     
- Misses       36219     36223        +4     
- Partials      5391      5401       +10

@sylee957
Copy link
Member Author

sylee957 commented Apr 9, 2019

I see sympy raises error when hadamard product between matrix and scalar.
I'm not very clear that hadamard power can be defined with scalar base if it is that way,
Neither am I clear about hadamard power can be defined in this way, because I cannot understand if hadamard exponential is possible (With using taylor series expansion with hadamard product, like as in ordianry matrix exponential is defined), but no scalar-to-matrix power is possible.

We may need some other source to verify

@oscarbenjamin
Copy link
Contributor

This has merge conflicts now...

@sylee957
Copy link
Member Author

Whatever, I couldn't find any good article for the hadamard product notation to be defined between a matrix and scalar, or the hadamard power notation to be defined between a matrix and a matrix, but at least having an option to raise a matrix base to a matrix exponent can be convenient if defined.

If other properties related to the hadamard product or hadamard power do not break with such new definition,
I would define a hadamard product between a matrix and a scalar as a usual matrix-scalar multiplication, and
hadamard power between matrices as entrywise power between each matrix elements, as used in most of the numeric libraries, unless some other people can tackle in.

@sylee957
Copy link
Member Author

sylee957 commented Aug 24, 2019

image

I've got the sphinx render, but just wonder why \hdots are showing like that, while the same LaTeX works for https://www.codecogs.com/latex/eqneditor.php And horizontal dots are fixed after changing \hdots to \cdots

@oscarbenjamin
Copy link
Contributor

Looks good. Merging

@oscarbenjamin oscarbenjamin merged commit be65c83 into sympy:master Aug 30, 2019
@sylee957 sylee957 deleted the fix_hadamard_power branch October 15, 2019 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HadamardPower(A, B).as_explicit() fails
3 participants