Skip to main content

FormalPowerSeries

Struct FormalPowerSeries 

Source
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

Source

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");
Source

pub fn variable(&self) -> Ex

The expansion variable.

Source

pub fn point(&self) -> Ex

The expansion point.

Source

pub fn context(&self) -> Context

The Context this series lives in.

Source

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");
Source

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).

Source

pub fn coefficients(&self, n: usize) -> Vec<Ex>

The first n coefficients a_0 … a_{n−1}.

Source

pub fn has_closed_form(&self) -> bool

Whether a closed-form general term is available (see general_term).

Source

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!");
Source

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");
Source

pub fn add(&self, other: &Self) -> Result<Self, SymplexError>

self + other.

Source

pub fn sub(&self, other: &Self) -> Result<Self, SymplexError>

self − other.

Source

pub fn mul(&self, other: &Self) -> Result<Self, SymplexError>

Cauchy product self · other.

Source

pub fn scale(&self, c: &Ex) -> Self

c · self for a constant c.

§Panics

Panics if c belongs to a different context.

Source

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");
Source

pub fn derivative(&self) -> Self

Term-wise derivative d/dx.

Source

pub fn integral(&self) -> Self

Term-wise antiderivative with zero constant term.

Source

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");
Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FormalPowerSeries

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more