Power series rings over the integers and the rationals
Source:R/polys-series.R
power_series_rings.RdPythonPowerSeriesRingZZ(prec) and PythonPowerSeriesRingQQ(prec) are
univariate power series rings with coefficients in ZZ or QQ, as SymPy's
classes of the same names. A series is the pair (coeffs, prec): the
coefficients from the highest degree down, and the order of the error
term O(x**prec) or NULL for an exact polynomial. Call the ring on a
vector of coefficients (lowest degree first) to make a series, and use
its methods with $: add, subtract, multiply, divide, pow_int,
square, compose, inverse, reversion, truncate,
differentiate, pretty, to_list, and over QQ integrate, sqrt,
log, exp, sin, cos, tan, atan, hypot and the hyperbolic functions.
Examples
R <- PythonPowerSeriesRingZZ()
s <- R(c(1, 2, 3))
R$pretty(R$pow_int(s, 2))
#> [1] "1 + 4*x + 10*x**2 + 12*x**3 + 9*x**4"
R$pretty(R$inverse(R(c(1, 1))))
#> [1] "1 - x + x**2 - x**3 + x**4 - x**5 + O(x**6)"
Q <- PythonPowerSeriesRingQQ(4)
Q$pretty(Q$exp(Q$gen))
#> [1] "1 + x + 1/2*x**2 + 1/6*x**3 + O(x**4)"