# BUG: Why is Series[] getting this expression wrong?

EDIT: Wolfram confirmed this is a bug in Series[], and they're looking into it.

I'm trying to generate a 2nd-order Taylor series in theta for a complicated expression "mdel" using Series[mdel,{theta,0,2}]. The first two terms of this series should be 0's, so the correct expansion should be 0 + 0 + (-Cot[q]/4)*theta^2 + O(theta^3). What am I doing wrong?

The first code block below generates the expression mdel, then the second block attempts to use Series[] with and without pertinent Assumptions, but both just generate a mess.

What have I done wrong here, and what must I modify in my approach to make Series[] get this expansion right? Thanks!

x = S/(Sin[q - theta/2]/Tan[phi] + Cos[q - theta/2]);
frac = x/(x /. phi -> theta);
phif = phi /. Solve[f == frac, phi][[1]];
phif = phif /. C[1] -> 0;
del = phif - (phif /. q -> Pi/2);
expr = D[del, f];
f0 = f /. Solve[expr == 0, f][[1]];
f0 = FullSimplify[f0,
Assumptions -> {q > theta, q < Pi - theta, theta > 0, theta < Pi/10}]
mdel = FullSimplify[del /. f -> f0];

Series[mdel, {theta, 0, 2}]
Series[mdel, {theta, 0, 2},
Assumptions -> {q > theta, q < Pi - theta, theta > 0, theta < Pi/10}]


The output:

1/2 ((-1)^ Floor[1/2 + Arg[1/(Cot[q - theta/2] Sqrt[ Csc[q + theta/2] Sin[q - theta/2]] + Cot[theta] (1 + Sqrt[ Csc[q + theta/2] Sin[q - theta/2]]))]/[Pi]] [Pi] - (-1)^ Floor[1/2 + Arg[Sin[theta]/( Cos[theta] + Sqrt[ Csc[q + theta/2] Sin[q - theta/2]])]/[Pi]] [Pi] + ( SeriesData[theta, 0, {Rational[-1, 2] Cot[q]}, 2, 3, 1]))

1/2 (-1)^ Floor[1/2 - Arg[Cos[q - theta/2] Sqrt[Csc[q - theta/2] Csc[q + theta/2]] + Cot[theta] (1 + Sqrt[ Csc[q + theta/2] Sin[q - theta/2]])]/[Pi]] [Pi] + ( SeriesData[theta, 0, {Rational[-1, 4] Cot[q]}, 2, 3, 1]) + Abs[Cot[q - theta/2] Sqrt[Csc[q + theta/2] Sin[q - theta/2]] + Cot[theta] (1 + Sqrt[Csc[q + theta/2] Sin[q - theta/2]])] ( SeriesData[ theta, 0, {Rational[-1, 4] Pi, Rational[1, 16] Pi Cot[q]}, 1, 3, 1] )

• This is more complicated than it needs to be. Start with mdel. After running your code, I have this. mdel = 1/(1 + Sqrt[Csc[q + theta/2]*Sin[q - theta/2]]);. If your result is different, look for why that happens. Did you have one of the parameters set to a value? Perhaps you had q=Pi/4? If none of this is the case maybe people can look further. But I would not expect the first derivative to be free of q (I bring that up because zero is independent of q). Jan 3 at 21:45
• @DanielLichtblau Thanks for the reply. I get exactly what you get for mdel. But I'm expanding the Taylor series in theta not q. The 0th and 1st derivs of mdel in theta are both zero. The 2nd deriv of mdel wrt theta at theta==0 is -cot(q)/2. So the series in theta should simply be 0 + 0 + (-Cot[q]/4)*theta^2 + O(theta^3) Jan 4 at 22:48
• I am unable to replicate the claim that the first derivative (for example) in theta vanishes at the origin. In[21]:= InputForm[D[mdel,theta]/.theta->0] Out[21]//InputForm= Cot[q]/8. And indeed this agrees with the result I get from Series. But I can get zero by setting q to Pi/2: InputForm[D[mdel/.q->Pi/2,theta]/.theta->0] Out[24]//InputForm= 0. This is why I raised that possibility in my prior comment. Jan 4 at 23:39
• @DanielLichtblau Limit[D[mdel, theta], theta -> 0] gives me 0, the correct answer. You can also plug in small values and see that for small theta, mdel is proportional to theta^2. For example, mdel /. {q -> .1, theta -> .01} yeilds -.000249 while mdel /. {q -> .1, theta -> .001} yield -.00000249, both of which are very good matches to my 2nd order expansion 0 + 0 -(cot(q)/4)*theta^2 Jan 6 at 0:28
• I’ll check again when I’m at my desk. Maybe I lost a factor of theta somewhere. Jan 6 at 4:49

\$Version

(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)

Clear["Global*"]

x = S/(Sin[q - theta/2]/Tan[phi] + Cos[q - theta/2]);
frac = x/(x /. phi -> theta);
phif = phi /. Solve[f == frac, phi][[1]];
phif = phif /. C[1] -> 0;
del = phif - (phif /. q -> Pi/2);
expr = D[del, f];
f0 = f /. Solve[expr == 0, f][[1]];
f0 = FullSimplify[f0,
Assumptions -> {q > theta, q < Pi - theta, theta > 0,
theta < Pi/10}];
mdel = FullSimplify[del /. f -> f0];

Limit[{mdel, D[mdel, theta], D[mdel, {theta, 2}]}, theta -> 0]

(* {0, 0, -(Cot[q]/2)} *)

Assuming[
{q > theta, q < Pi - theta, theta > 0, theta < Pi/10},
Series[#, {theta, 0, 0}] // Simplify // Normal] & /@
{mdel, D[mdel, theta], D[mdel, {theta, 2}]}

(* {0, 0, -(Cot[q]/2)} *)

• Okay, I see you used different code than I did for the Series and got the right result. But could you give some idea why mine didn't work? Seems like it should have. Is what you've written here just a workaround to something MMa fails at? Or did I use it wrong? Thanks for the reply. Dec 31, 2023 at 19:33
• To get the limit of f[theta] as theta -> 0 using Series, use either Series[f[theta], {theta, 0, 0}] or Series[f[theta], theta -> 0]` Dec 31, 2023 at 19:47
• Right, but I'm still trying to understand why the Series[] function isn't working properly they way I used it. Dec 31, 2023 at 22:59
• Because the series you calculated is not equivalent to the limit. If you want equivalent results you need to use equivalent expressions. Dec 31, 2023 at 23:35
• The Limits I calculated above are the 0th, 1st, & 2nd derivates at theta = 0, which are the coefficients of the first three terms of a Taylor Series. So the first three terms of the Taylor Series of my function is 0 + 0 + (cot[q]/4)*theta^2. Series[] is not correctly calculating that. I'm trying to figure out how to make Series work correctly, not just find a different way to calculated the individuals limits I already calculated. Do you understand that Series[f,{x,0,n}] is supposed to give you an nth order Taylor Series? Jan 1 at 0:03