Skip to content

Commit

Permalink
Changed _matrix_power_symbolic function to condier mk=0 case
Browse files Browse the repository at this point in the history
This fixes sagemath#36838. Here, I have added a condition to check whether
mk=0 or not. Because whenever mk=0 we should give mk^(n-i) (i.e. 0^(n-i))
instead of only 0 considering (n-i) can be equal to zero and in this
case 0^(n-i) will be more accurate than only 0.
  • Loading branch information
RuchitJagodara committed Dec 9, 2023
1 parent 272582b commit 7f03ea9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18656,8 +18656,14 @@ def _matrix_power_symbolic(A, n):
# D^i(f) / i! with f = x^n and D = differentiation wrt x
if hasattr(mk, 'radical_expression'):
mk = mk.radical_expression()
vk = [(binomial(n, i) * mk**(n-i)).simplify_full()
for i in range(nk)]

# Return mk^(n-i) instead of mk**(n-i) if mk=0
if mk:
vk = [(binomial(n, i) * mk**(n-i)).simplify_full()
for i in range(nk)]
else:
vk = [(binomial(n, i)).simplify_full() * (mk^(n-i))
for i in range(nk)]

# Form block Mk and insert it in M
Mk = matrix(SR, [[SR.zero()]*i + vk[:nk-i] for i in range(nk)])
Expand Down

0 comments on commit 7f03ea9

Please sign in to comment.