# 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?

edit retag close merge delete

Sort by » oldest newest most voted

[Side remark: Use the button with 101 and 010 to format your code.]

You simply need to ask for the taylor expansion in z at $0$:

sage: i,z = var('i,z')
sage: c = function('c')
sage: p = sum(c(i)*z^i,i,0,6)
sage: psqrt = sqrt(p)
sage: psqrt.taylor(z, 0, 3) # I take 3 to limit the size of the output...
1/2*z*c(1)/sqrt(c(0)) + 1/16*(c(1)^3*sqrt(c(0)) - 4*c(2)*c(1)*c(0)^(3/2) + 8*c(3)*c(0)^(5/2))*z^3/c(0)^3 - 1/8*(c(1)^2*sqrt(c(0)) - 4*c(2)*c(0)^(3/2))*z^2/c(0)^2 + sqrt(c(0))

more

I will suppose c0 is 1, else we divide with its square root, which should exist in the ground field for the coefficients. (Feel free to change the following code, so that c0 is also a general variable.)

The following does the job for me:

c = [1,] + list( var( 'c1,c2,c3,c4,c5,c6' ) )
print "c is", c
var( 'x' );
T = taylor( sqrt( 1 + sum( [ c[k]*x^k for k in [1..6] ] ) ), x, 0, 6 )
# print T # for a long story
print "T has the following coefficients:"
for coeff, deg in T.coefficients( x ):
print "Degree %s: %s" % ( deg, coeff )


Results:

c is [1, c1, c2, c3, c4, c5, c6]
x
T has the following coefficients:
Degree 0: 1
Degree 1: 1/2*c1
Degree 2: -1/8*c1^2 + 1/2*c2
Degree 3: 1/16*c1^3 - 1/4*c1*c2 + 1/2*c3
Degree 4: -5/128*c1^4 + 3/16*c1^2*c2 - 1/8*c2^2 - 1/4*c1*c3 + 1/2*c4
Degree 5: 7/256*c1^5 - 5/32*c1^3*c2 + 3/16*c1*c2^2 + 1/16*(3*c1^2 - 4*c2)*c3 - 1/4*c1*c4 + 1/2*c5
Degree 6: -21/1024*c1^6 + 35/256*c1^4*c2 - 15/64*c1^2*c2^2 + 1/16*c2^3 - 1/32*(5*c1^3 - 12*c1*c2)*c3 - 1/8*c3^2 + 1/16*(3*c1^2 - 4*c2)*c4 - 1/4*c1*c5 + 1/2*c6

more

Somebody wanted really to see the c(0) squared appearing explicitly at all places and/or c(1), c(2), c(3), c(4), c(5), c(6) instead of c1, c2, c3, c4, c5, c6... else i cannot figure out the reason for the downgrade.

(There was some effort to make the output shorter and without this obvious squared root, so that the result is an algebraic, weighted homogenous expression in each x^k with predictible polynomials in c(1)^k and c(k)... This was the reason for setting c(0)=1 explicitly.)

Next time the solution will be:

Copy+format the given code:

k, z = var( 'k,z' );
c = function('c')
p = sum( c(k)*z^k, k, 0, 6 )


Then deliver the one line solution

T = taylor( sqrt(p), z, 0, 6 )


as required till degree 6 without showing the lenghty answer.

( 2017-12-07 11:08:37 -0500 )edit