Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-36845: Give more precise answer on symbolic power of a matrix
- Changed _matrix_power_symbolic function to consider mk=0 case - Changed the _matrix_power_symbolic function to handle all the cases - Created tests covering the changes This PR improves the answer given by _matrix_power_symbolic() function, which involves finding the symbolic power of a matrix, and also gives more precise answer on evalution. eg, before, when we were evaluating the zeroth power of a matrix sometimes it was giving wrong answer like below, ```python sage: n = var("n") sage: A = matrix(ZZ, [[1,-1], [-1,1]]) sage: An = A^(n) [ 1/2*2^n -1/2*2^n] [-1/2*2^n 1/2*2^n] sage: An({n:0}) [ 1/2 -1/2] [-1/2 1/2] ``` Here, for n=0, it is not giving an identity matrix which is wrong, but after the change it will give answer as below, ```python sage: n = var("n") sage: A = matrix(ZZ, [[1,-1], [-1,1]]) sage: An = A^(n) [ 1/2*2^(2*n + 1) + 1/2*kronecker_delta(0, 2*n + 1) -1/2*2^(2*n + 1) + 1/2*kronecker_delta(0, 2*n + 1)] [-1/2*2^(2*n + 1) + 1/2*kronecker_delta(0, 2*n + 1) 1/2*2^(2*n + 1) + 1/2*kronecker_delta(0, 2*n + 1)] sage: An({n:0}) [1 0] [0 1] ``` Also, This patch fixes #36838 . The function, _matrix_power_symbolic() was giving symbolic power of a nilpotent matrix as a null matrix but the correct answer should be represented in the form of kronecker_delta() function. In the case of mk=0, simplifying only binomial term should work because afterall the form 0^(n-i) should be simplifed to kronecker_delta() function and no further simplification is needed. And in every other case it is simplifying whole term so it will handle all other cases. <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> None URL: #36845 Reported by: Ruchit Jagodara Reviewer(s): Dima Pasechnik, phul-ste, Ruchit Jagodara
- Loading branch information