Ideally series would produce something more like a Poly object rather than just an Add with an O() term. You can use Poly to get the coefficients in order:
In [6]: sin(x).series(x,0,10).removeO().as_poly(x).coeffs()[::-1] Out[6]: [1, -1/6, 1/120, -1/5040, 1/362880] In [7]: sin(x).series(x,0,10).removeO().as_poly(x).all_coeffs()[::-1] Out[7]: [0, 1, 0, -1/6, 0, 1/120, 0, -1/5040, 0, 1/362880] -- Oscar On Tue, 9 Jul 2024 at 10:41, [email protected] <[email protected]> wrote: > > Doesn't matter : > > ``` > >>> from sympy import * > >>> x=symbols("x") > >>> sin(x).series(x,0,10).args > (x, -x**3/6, -x**7/5040, x**5/120, x**9/362880, O(x**10)) > ``` > > The arguments tuple doesn't order `x` powers (and this isn't a problem, since > (complex) multiplication is commutative. But > > ``` > >>> sin(x).series(x,0,10) > x - x**3/6 + x**5/120 - x**7/5040 + x**9/362880 + O(x**10) > ``` > > The expression is still printed with ordered powers of `x`. > > HTH, > > Le mardi 9 juillet 2024 à 05:59:20 UTC+2, [email protected] a écrit : >> >> Hi, I am a new user of SymPy. I wonder if the following result is a bug? >> Anyway, the following code is a nuance. I am using the latest SymPy >> >> class TestSymPy (unittest.TestCase): >> def testSin(self): >> ''' >> The expansion is not ordered by x**n: x**7 before x**5 >> ''' >> x = sympy.Symbol('x') >> sin = sympy.sin(x) >> self.assertTupleEqual(sin.args, (x,)) >> e = sin.series(x, 0, 10) >> self.assertTupleEqual(e.args, (x, -x**3/6, -x**7/5040, x**5/120, >> x**9/362880, sympy.O(x**10))) >> >> > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/2e33ae1e-9c71-4e58-9887-ea5dffe08e3an%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxRWHnjTJ3OPShDR8A%2BS%3Dvm5QAy_rHJjMf8X4xbj%2B9Jfxg%40mail.gmail.com.
