1 | initial version |
The expression x[n]
is an error because n
is the Sage function numerical_approx
rather than an integer. The notation for series that you try to use is valid when n
is symbolic, i.e. var('n')
, but that won't do here because x[n]
will still be an error. It seems that PowerSeriesRing
is for finite power series expansions with specified (possibly infinite) precision. So you can do e.g.
sage: sum(x[n]*t^n for n in range(5)) + O(t^5)
x_0 + x_1*t + x_2*t^2 + x_3*t^3 + x_4*t^4 + O(t^5)
Maybe you want a Lazy Power Series instead:
P.<x> = InfinitePolynomialRing(QQ)
L.<t> = LazyPowerSeriesRing(P)
f = L()
f.order = 1
f.aorder = 1
f.initialize_coefficient_stream(lambda ao: iter(x[n] for n in NN))
Then you can do:
sage: f.coefficients(5)
[0, x_1, x_2, x_3, x_4]
sage: f
x_0*1 + x_1*t + x_2*t^2 + x_3*t^3 + x_4*t^4 + O(x^5)
sage: f.coefficients(7)
[0, x_1, x_2, x_3, x_4, x_5, x_6]
sage: f
x_0*1 + x_1*t + x_2*t^2 + x_3*t^3 + x_4*t^4 + x_5*t^5 + x_6*t^6 + O(x^7)
Here the + O(x^7)
is a bug in sage.combinat.species.series.LazyPowerSeries.__repr__
which forgets to use the name of the actual power series variable.
Actually I am not sure how one can properly manipulate such a LazyPowerSeries
further. Things like multiplying by a constant already seem to be tricky.