# Problem using Taylor several times I have a sage worksheet using small functions such as

def vMatrix(M):
Lmat=[]
for i in [0..1]:
for j in [0..1]:
Lmat.append(M.subs(y==1-m^2-m^4)[i,j].taylor(m,0,4))
return Matrix(2,Lmat)


At the beginning, it works perfectly (computing approximations of matrices with parameters) but after using it several times, it stops computing the Taylor expansion of the coefficients, and simply returns the matrix.

I'm getting crazy with that :(

Does someone has an idea on what's happening?

Thx Leo

edit retag close merge delete

Please give an example of what you don't understand. If the matrix does not contain any y then nothing happens...

For example, first it gave the correct result, and now: Applying the function vMatrix to the following matrix: [ (m^3 + my - m)/(m^2 - 1) -(m^4 + m^2y - 2m^2 + 1)/(m^5 - 2m^3 + m)] [ my -(m^2y - m^2 + 1)/(m^3 - m)]

It gives: [ -m^5/(m^2 - 1) (m^6 + m^2 - 1)/(m^5 - 2*m^3 + m)] [ -m^5 - m^3 + m (m^6 + m^4 - 1)/(m^3 - m)] which is just the result of the substitution.

Sorry, I was wrong, it should do the expansion. When I try it with that first matrix in SageMath 9.0, it does do the expansion. What version are you using? Please add a complete example to your post.

I'm using 8.0 The problem is that the false result does not occurs directly. If I run the function, it gives me the expansion as well. But after running more cells, then it starts to mess up completely. In fact I see where the problem comes from: the matrices are defined over "Symbolic Ring" (with formal variable m and y) Then I run a function that uses matrices with some other variables (and after that it starts to mess up). At some point, my guess is that Sage doesn't know anymore that my matrices coeffs are functions of m, and so the taylor command is kind of empty for him. Any idea how to fix that?

Sort by » oldest newest most voted The function is fine as long as the external variables y and m are defined in the way you expect (as var('y') and var('m') respectively). To ensure that a function works consistently (equal inputs always resulting in equal outputs), it should not depend on external variables. So you can modify the function to use var('y') and var('m') directly, or change the definition to accept y and m as parameters (and making sure to always pass in the correct ones).

more