pub struct FormalPowerSeries { /* private fields */ }Expand description
A formal power series Σ a_k (x − point)^k with exact, lazily computed
coefficients. See the module docs for the design.
Implementations§
Source§impl FormalPowerSeries
impl FormalPowerSeries
Sourcepub fn from_coefficients(var: &Ex, point: &Ex, coeffs: &[Ex]) -> Self
pub fn from_coefficients(var: &Ex, point: &Ex, coeffs: &[Ex]) -> Self
A polynomial series Σ coeffs[k] (var − point)^k from explicit
coefficients (all in the same context as var).
§Panics
Panics if the expressions come from different contexts.
use symplex::prelude::*;
use symplex::formal_series::FormalPowerSeries;
let ctx = Context::new();
let x = ctx.symbol("x");
let p = FormalPowerSeries::from_coefficients(&x, &ctx.int(0), &[ctx.int(1), ctx.int(2)]);
assert_eq!(p.truncate(5).to_string(), "2*x + 1");Sourcepub fn coefficient(&self, k: usize) -> Ex
pub fn coefficient(&self, k: usize) -> Ex
The k-th coefficient a_k as an exact expression.
For series with a pole at the expansion point this is the Laurent
coefficient of (x − a)^k for k ≥ 0; use
truncate to see the negative powers.
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let s = x.sin().fps_maclaurin(&x);
assert_eq!(s.coefficient(3).to_string(), "-1/6");
assert_eq!(s.coefficient(4).to_string(), "0");Sourcepub fn coefficient_rational(&self, k: usize) -> Option<Ratio<BigInt>>
pub fn coefficient_rational(&self, k: usize) -> Option<Ratio<BigInt>>
The k-th coefficient as an exact rational, or None if it is not
a rational number (e.g. ln 2, 2/√π, or a symbolic parameter).
Sourcepub fn has_closed_form(&self) -> bool
pub fn has_closed_form(&self) -> bool
Whether a closed-form general term is available (see
general_term).
Sourcepub fn general_term(&self, k: &Ex) -> Option<Ex>
pub fn general_term(&self, k: &Ex) -> Option<Ex>
The general coefficient a_k as a closed-form expression in the
symbolic index k, when known.
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let k = ctx.symbol("k");
let e = x.exp().fps_maclaurin(&x);
assert_eq!(e.general_term(&k).unwrap().to_string(), "1/k!");Sourcepub fn truncate(&self, n: usize) -> Ex
pub fn truncate(&self, n: usize) -> Ex
The truncated series Σ_{k<n} a_k (x − point)^k.
For series with a pole at the point, negative powers down to the pole order are included.
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let s = x.cos().fps_maclaurin(&x);
assert_eq!(s.truncate(5).to_string(), "1/24*x^4 - 1/2*x^2 + 1");Sourcepub fn add(&self, other: &Self) -> Result<Self, SymplexError>
pub fn add(&self, other: &Self) -> Result<Self, SymplexError>
self + other.
Sourcepub fn sub(&self, other: &Self) -> Result<Self, SymplexError>
pub fn sub(&self, other: &Self) -> Result<Self, SymplexError>
self − other.
Sourcepub fn mul(&self, other: &Self) -> Result<Self, SymplexError>
pub fn mul(&self, other: &Self) -> Result<Self, SymplexError>
Cauchy product self · other.
Sourcepub fn compose(&self, other: &Self) -> Result<Self, SymplexError>
pub fn compose(&self, other: &Self) -> Result<Self, SymplexError>
Composition self(other); requires other to have zero constant term.
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
let e = x.exp().fps_maclaurin(&x);
let s = x.sin().fps_maclaurin(&x);
// exp(sin x) = 1 + x + x²/2 − x⁴/8 + …
let c = e.compose(&s).unwrap();
assert_eq!(c.truncate(5).to_string(), "-1/8*x^4 + 1/2*x^2 + x + 1");Sourcepub fn derivative(&self) -> Self
pub fn derivative(&self) -> Self
Term-wise derivative d/dx.
Sourcepub fn inverse(&self) -> Result<Self, SymplexError>
pub fn inverse(&self) -> Result<Self, SymplexError>
Multiplicative inverse 1/self; requires a non-zero constant term.
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
// 1/cos x = sec x = 1 + x²/2 + 5x⁴/24 + …
let sec = x.cos().fps_maclaurin(&x).inverse().unwrap();
assert_eq!(sec.truncate(5).to_string(), "5/24*x^4 + 1/2*x^2 + 1");Sourcepub fn reversion(&self) -> Result<Self, SymplexError>
pub fn reversion(&self) -> Result<Self, SymplexError>
Compositional inverse (series reversion) by Lagrange inversion;
requires a_0 = 0 and a_1 ≠ 0.
use symplex::prelude::*;
let ctx = Context::new();
let x = ctx.symbol("x");
// reversion of sin is asin: x + x³/6 + 3x⁵/40
let asin = x.sin().fps_maclaurin(&x).reversion().unwrap();
assert_eq!(asin.truncate(6).to_string(), "3/40*x^5 + 1/6*x^3 + x");Trait Implementations§
Source§impl Clone for FormalPowerSeries
impl Clone for FormalPowerSeries
Auto Trait Implementations§
impl !Freeze for FormalPowerSeries
impl !RefUnwindSafe for FormalPowerSeries
impl !UnwindSafe for FormalPowerSeries
impl Send for FormalPowerSeries
impl Sync for FormalPowerSeries
impl Unpin for FormalPowerSeries
impl UnsafeUnpin for FormalPowerSeries
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more