Ask Your Question

charleslebarron's profile - activity

2021-06-28 21:37:59 +0200 received badge  Notable Question (source)
2021-06-28 21:37:59 +0200 received badge  Popular Question (source)
2018-01-23 19:33:04 +0200 asked a question recursively solve and substitute

I'm working on a pretty complicated problem (theoretically, not necessarily computationally). I'm not sure how to distill my question down to a simple example. But basically I have a system of equations over the ring of polynomials (or power series) over the symbolic ring. I want to be able to recursively solve for one symbolic function in terms of another, substitute the solution, and repeat. The ultimate goal is to extract relevant data all as a function of some positive integer k. It seems like I should be able to build a loop to do this, but I'm new to sage and programming in general. I haven't been able to find anything quite like what I'm trying to do online. So I'm asking for suggestions.

Here are some more details:

I have several polynomial expressions

j,k,z = var('j,k,z')
a,f=function('a,f')
p= lambda k : z^(-2*k) + sum(a(j)*z^(-j) for j in range(2*k-1))
F= lambda k : sum(f(j)*z^j, j, 2, 2*k)

which I plug into a formal matrix valued function and perform a series of algebraic manipulations. In the end I get a matrix whose entries are polynomials in the a(j)'s and f(j)'s. I want to recursively solve for the f(j)'s in terms of the a(j)'s so as to diagonalize this matrix expression. I can do this "by hand" but I want a function that will just spit out the end result. For example I know that f(2) = 1/4a(2k-2) for any k.

I've tried, for example:

def A1(k) :
     for j in range(2,2*k) :
          A0(k)=A0(k).substitute(f0(k,j)[0])
          return A0(k)

Here A0(k) is a previously defined matrix expression and f0(k,j) is a function that solves for f(j). This code actually runs but then trying to call A1(2), etc., leads to errors.

Another attempt was to define

A1= lambda k,j : coef(A0(k),-k-2+j).substitute(f0(k,j)[0])

and then try to define a function of k in terms of the A1(k,j)'s using the sum() command. (In the code above coef(A,j) is a function that returns the coefficient of the z^j term in a polynomial over a ring of matrices).

The problem with this last attempt is that A1(k,j) for j bigger than 2 returns terms that include f(2), f(3), etc. I need something that solves for f(2), substitutes this value for f(2) into all future computations; then solves for f(3), substitutes this values for f(3) into all future computations; and so on until f(2*k).

I apologize if this question is too broad somehow. In looking over some of the literature on loops, solve(), substitute(), etc., I haven't found anything quite like this. Any suggestions? And thank you.

2017-12-20 18:03:05 +0200 commented answer working with coefficients of formal series

But also, what makes the difference in whether Sage returns the expanded expression or the just something like

sum(z^i*f(i), i, 1, 2)*sum(z^i*g(i), i, 1, 2)
2017-12-20 18:00:51 +0200 commented answer working with coefficients of formal series

Ideally, we would leave n as a variable, only specifying n=3 when necessary to return meaningful results. Something more like:

F(n)=sum(f(i)*z^i,i,1,n)
G(n)=sum(g(i)*z^i,i,1,n)
F(3)*G(3)

...

2017-12-20 15:44:55 +0200 asked a question working with coefficients of formal series

I want to define a truncated series or polynomial of arbitrary degree and then work algebraically with the polynomial to solve for various quantities in terms of the coefficients. When I write something like

i,n,z=var('i,n,z')
c=function('c')
p=z^(-4)+sum(c(i)/z^i,i,0,2)
p

this returns

(z^2*c(0) + z*c(1) + c(2))/z^2 + 1/z^4

But if I try to define an arbitrary polynomial of this type

p(n)=z^(-2n) + sum(c(i)/z^i,i,0,2n-2)
p(2)

returns

z^4 + sum(z^(-i)*c(i), i, 0, 2)

What is the crucial difference here?

I had a similar problem when working with truncated power series over the ring PowerSeriesRing(SR). I want to manipulate these expressions algebraically as elements of a ring then ask for info about certain coefficients. But working with formal sums and substituting values of n returns power series coefficients, e.g. the following expression as the coefficient of z^-4 (after some computations...f and g are symbolic functions)

1/4*(sum(z^i*f(i), i, 1, 3)*sum(z^i*g(i), i, 1, 3) + 2)^2 + sum(z^i*f(i), i, 1, 3)*sum(z^i*g(i), i, 1, 3)

How do I get sage to work with the series and also give info about the coefficients, i.e. multiply series expressions but then expand them out in z? I've tried expand() in this setting with mixed success.

2017-12-19 22:36:51 +0200 received badge  Supporter (source)
2017-12-19 22:35:31 +0200 received badge  Scholar (source)
2017-12-19 22:33:44 +0200 asked a question truncated exponential series over ring of matrices over symbolic ring

I want to do the following:

R.<z>=PowerSeriesRing(SR)
i,n,z=var('i,n,z')
f,g=function('f,g')
F=sum(f(i)*z^i,i,1,n)
G=sum(g(i)*z^i,i,1,n)
gamma=matrix([[0,F],[G,0]])

I then want to define a function as the first several terms of the exponential series exp(gamma). Something like

Gamma=sum(gamma^i/factorial(i),i,0,n)

This will return an error like: 'too many values to unpack'

I only want to work with this function formally until I need to specify a value of n and eventually solve for the value f(i), g(i) in terms of some other parameters (yet to be defined in this code). What are some ways to clean this up so I can work with the truncated power series with matrix coefficients?

A possibly simpler but related question is how does one build a function that will sum several powers of a matrix?

2017-12-07 01:41:01 +0200 received badge  Student (source)
2017-12-07 01:35:49 +0200 asked a question polynomial with matrix coefficients

Is there a way in sage to work with polynomials or power series over a ring of matrices? For example, I can write something like:

z=var('z') A=matrix([[z^2+z+1,z],[0,z^2]])

But then lets say I do some transformations and want to recover from the result the matrix coefficient of a particular term. With the matrix above I can write something like

A[0,1].coefficient(z)

or

A[1,0].coefficient(z)

to try to get the individual entries. But what I want is a function that takes A.coefficient(z,2) and returns

[1 0] [0 1]

Is there a way to do this?

2017-12-07 01:35:49 +0200 asked a question computing the square root of a polynomial with variable coefficients

I am new to sage and programming in general. I want to compute the power series representation of the square root of a polynomial with variable coefficients. Here is my attempt:

i,z=var('i,z') c=function('c') p=sum(c(i)*z^i,i,0,6) sqrt(p)

This returns

sqrt(z^6c(6) + z^5c(5) + z^4c(4) + z^3c(3) + z^2c(2) + zc(1) + c(0)).

How can I get sage to return a power series expression?

2017-12-07 01:35:49 +0200 asked a question square root of a polynomial with variable coefficients

I want to calculate the square root of a polynomial with variable coefficients in sage. For example:

i,z=var('i,z') c=function('c') p=sum(c(i)*z^i,i,0,6) sqrt(p)

returns

sqrt(z^6c(6) + z^5c(5) + z^4c(4) + z^3c(3) + z^2c(2) + zc(1) + c(0))

I want a Taylor or Laurent expansion in z. How do I get this?