# taylor series of expression involving modulus of a complex expression

Consider the following

sage: w = SR.var('w')
sage: a = -cos(w)^2 + 2*I*cos(w)*sin(w) + sin(w)^2 + 2.8*cos(w) - 2.8*I*sin(w) - 1.8

sage: b = abs(a)
sage: b.taylor(w, 0.1, 1)  # not the answer I expected!
-(0.8150178993589604 + 0.178042614591617*I)*w
+ 0.16258427059001673 + 0.0178042614591617*I

sage: c = sqrt(b.real()**2 + b.imag()**2)
sage: c.taylor(w, 0.1, 3)  # works as expected!
1.002855497443298*(w - 0.1)^3
+ 0.3184495453305423*(w - 0.1)^2
+ 0.8322931797904074*w
- 0.002146837324920048


So as you can see I have two mathematically equivalent expressions, b and c, but Sage is not able to directly find the Taylor series of the first.

Is there a way to convince Sage to do this correctly?

edit retag close merge delete

I'm not sure that your question has a meaning (I'm not able to understand it). Consider :

sage: c.taylor(w, 0.1, 1)-b.taylor(w,0.1,1)
0.0
sage: c.taylor(w, 0.1, 3)-b.taylor(w,0.1,3)
0.0


What do you mean ?

Thanks for the response Emmanuel - now I am confused!! Another user came in and edited my question to make it look nicer but certainly I get a different result!

Here is my original source: w=SR.var('w') tt=abs(-cos(w)^2 + 2Icos(w)sin(w) + sin(w)^2 + 2.8cos(w) - 2.8Isin(w) - 1.8) print(tt.taylor(w,0.1,3)) print("") ttt=-cos(w)^2 + 2Icos(w)sin(w) + sin(w)^2 + 2.8cos(w) - 2.8Isin(w) - 1.8 lttt=sqrt(ttt.real()2+ttt.imag()2) print(lttt.taylor(w,0.1,3))

and output:

-(77.5983311918384 + 60.00589446569399I)(w - 0.1)^3 - (8.236463209769601 + 3.57404233017743I)(w - 0.1)^2 - (0.8150178993589604 + 0.178042614591617I)w + 0.16258427059001673 + 0.0178042614591617*I

1.002855497443298(w - 0.1)^3 + 0.3184495453305423(w ...(more)

Tip: indent code fragments by four spaces so they display properly.

Your "original code" didn't make it through this editor's markup. I guessed :

w=SR.var('w')
tt=abs(-cos(w)^2 + 2*I*cos(w)*sin(w) + sin(w)^2 + 2.8*cos(w) - 2.8*I*sin(w) - 1.8)
print(tt.taylor(w,0.1,3))
print("")
ttt=-cos(w)^2 + 2*I*cos(w)*sin(w) + sin(w)^2 + 2.8*cos(w) - 2.8*I*sin(w) - 1.8
lttt=sqrt(ttt.real()^2+ttt.imag()^2)
print(lttt.taylor(w,0.1,3))


Can you confirm ? If so, it turns out that

sage: bool(abs(ttt)==tt)
True


You seem to expect that ttt and ttt.abs() have the same Taylor development. It ain't necessarily so...

Sort by » oldest newest most voted

You could expand around t=0 instead, for t = w + 0.1

var('t')
bmac = b.substitute(w=t-0.1).taylor(t,0,3)
cmac = c.substitute(w=t-0.1).taylor(t,0,3)
print(bmac)
print(cmac)


gives

(77.59833119183804 - 60.0058944656944I)t^3 - (8.236463209769589 - 3.574042330177453I)t^2 + (0.8150178993589599 - 0.1780426145916193I)t + 0.0810824806541207

(77.59833119183804 - 60.0058944656944I)t^3 - (8.236463209769589 - 3.574042330177453I)t^2 + (0.8150178993589599 - 0.1780426145916193I)t + 0.0810824806541207

more

You seem to expect that f(x).taylor(x,0 3) is equal to f(x).abs().taylor(x,0,3).

There's nothing allowing such an expectation. Simple illustrative counter-example :

sage: with assuming(x, "real"):(cos(x)+I*sin(x)).exponentialize().simplify().taylor(x,0,5)
1/120*I*x^5 + 1/24*x^4 - 1/6*I*x^3 - 1/2*x^2 + I*x + 1
sage: with assuming(x, "real"):(cos(x)+I*sin(x)).abs().exponentialize().simplify().taylor(x,0,5)
1


HTH,

more

Of course not! I was comparing (or trying to compare) the Taylor series for abs(a(w)+I*b(w)) and sqrt(a(w)^2+b(w)^2) - at least at points where things are smooth.