Skip to main content

Module formal_series

Module formal_series 

Source
Expand description

Formal power series representations and algorithms. Formal power series with exact, lazily computed coefficients.

A FormalPowerSeries represents f(x) = Σ_{k≥0} a_k (x − a)^k (or a Laurent series when f has a pole at a). Every coefficient is an exact symbolic expression (Ex) — rational numbers for elementary functions with rational Maclaurin coefficients, expressions such as 2/√π or ln 2 otherwise.

§Design

Coefficients are computed lazily and memoised; there is no fixed truncation order. A series is one of:

  • a closed-form series (exp, sin, cos, sinh, cosh, tan, tanh, atan, atanh, asin, asinh, erf, W, ln(a + c·xᵐ), (a + c·xᵐ)^α), whose k-th coefficient — and general term general_term — are known in closed form;
  • an engine series for any other expression, expanded on demand by the truncated-series engine behind Ex::series (poles are allowed: negative exponents are available through truncate);
  • an explicit polynomial (finite coefficient list);
  • a derived series: add, sub, mul, scale, compose, derivative, integral, inverse (1/f, needs f(a) ≠ 0) or reversion (compositional inverse by Lagrange inversion, needs f(a) = 0, f'(a) ≠ 0) of other series. Derived coefficients are computed from the operands’ coefficients exactly, to any index.

Series are created with Ex::fps / Ex::fps_maclaurin or FormalPowerSeries::from_coefficients.

use symplex::prelude::*;

let ctx = Context::new();
let x = ctx.symbol("x");
let e = x.exp().fps_maclaurin(&x);
assert_eq!(e.coefficient(5).to_string(), "1/120");
assert_eq!(e.truncate(4).to_string(), "1/6*x^3 + 1/2*x^2 + x + 1");

// (e^x)² = e^{2x}: a_3 = 8/6 = 4/3
let sq = e.mul(&e).unwrap();
assert_eq!(sq.coefficient(3).to_string(), "4/3");

Structs§

FormalPowerSeries
A formal power series Σ a_k (x − point)^k with exact, lazily computed coefficients. See the module docs for the design.