Tpsa

Real truncated power series objects.

Tpsa stores real coefficients in a Descriptor-defined algebraic space. It provides arithmetic, calculus, and elementary functions on truncated multivariate power series.

class madng_tpsa.tpsa.Tpsa(descriptor, order=None)

A truncated power series in the algebraic space defined by a descriptor.

Create a zero series on descriptor.

classmethod from_ptr(ptr, descriptor=None, *, owns=False)

Return the interned Tpsa for a raw C pointer.

If a live Tpsa already wraps ptr it is returned directly, so that at most one Python object exists per C allocation, preventing a use-after-free if two owners existed for the same pointer.

Parameters:
  • ptr (Any) – Raw CFFI TPSA pointer.

  • descriptor (Descriptor | None) – Descriptor that owns this TPSA. When omitted it is inferred from the pointer via mad_tpsa_desc. Required if owns is False.

  • owns (bool) – Set it to True only when ptr points to a freshly allocated C object that has no Python wrapper yet, i.e. the call site created the allocation and is handing ownership. The default False treats an unknown pointer as a bug and will raise.

Return type:

Tpsa

property ptr: Any

Low-level TPSA pointer for consumers marshalling across an ABI.

property descriptor: Descriptor

Descriptor that defines this series’ variables, parameters, and order.

property order: int

Maximum order stored by this series.

property max_nonzero_order: int

Highest order currently containing a non-zero coefficient.

property const_part: float

Constant coefficient of the series.

get(monomial)

Return the coefficient for monomial.

Return type:

float

set_const_part(value)

Set the constant coefficient.

set(monomial, value)

Set the coefficient for monomial.

monomial_coeffs(tol=1e-14)

Return stored coefficients larger than tol in absolute value.

Keys are full monomial tuples with one entry per variable and parameter.

Return type:

dict[tuple[int, …], float]

is_zero()

Return whether this series has no non-zero coefficients.

Return type:

bool

is_constant()

Return whether this series has no non-constant coefficients.

Return type:

bool

clear()

Set all coefficients to zero in place.

grad()

First-order coefficients for the descriptor variables.

Return type:

list[float]

param_grad()

First-order coefficients for the descriptor parameters.

Return type:

list[float]

copy()

Return an independent copy of this series.

Return type:

Tpsa

integrate(variable)

Return the formal integral with respect to variable.

Parameters:

variable (int | str | Tpsa) – May be a label, a 1-based variable/parameter index, or a TPSA identity variable with exactly one first-order monomial of coefficient 1. See _resolve_single_monomial() for accepted inputs.

Return type:

Tpsa

derivative(variable)

Return a partial derivative with respect to variable.

Parameters:

variable (int | str | tuple[int, ...] | Tpsa) – May be a label, a 1-based variable/parameter index, a monomial tuple, or a TPSA with exactly one non-constant coefficient equal to one. See _resolve_single_monomial() for accepted inputs.

Return type:

Tpsa

poisson_bracket(other, num_pairs='all')

Return the Poisson bracket with other over canonical variable pairs.

Return type:

Tpsa

format(style='code')

Format this series as code, LaTeX math, or a rich table.

Parameters:

style (FormatStyle) – Output style. See madng_tpsa.formatting.FormatStyle.

Return type:

object

equals(other, tol=0.0)

Return whether this series and other have matching coefficients.

Return type:

bool

abs()

Return the TPSA absolute value determined by the constant coefficient.

Return type:

Tpsa

norm()

Return the sum of absolute values of the stored coefficients.

Return type:

float

unit()

Return this series divided by the magnitude of its constant coefficient.

Return type:

Tpsa

sqrt()

Return the square root of this series.

Return type:

Tpsa

exp()

Return the exponential of this series.

Return type:

Tpsa

log()

Return the natural logarithm of this series.

Return type:

Tpsa

sin()

Return the sine of this series.

Return type:

Tpsa

cos()

Return the cosine of this series.

Return type:

Tpsa

tan()

Return the tangent of this series.

Return type:

Tpsa

sinc()

Return \(\sin(x) / x\) for this series (the unnormalised sinc).

Return type:

Tpsa

asin()

Return the inverse sine of this series.

Return type:

Tpsa

acos()

Return the inverse cosine of this series.

Return type:

Tpsa

atan()

Return the inverse tangent of this series.

Return type:

Tpsa

sincos()

Return \((\sin(x), \cos(x))\) for this series.

Return type:

tuple[Tpsa, Tpsa]

sincosq()

Return \((\operatorname{sinc}(\sqrt{x}), \cos(\sqrt{x}))\) for this series.

Return type:

tuple[Tpsa, Tpsa]

sincosmq()

Return two related trigonometric series.

\(((\operatorname{sinc}(\sqrt{x}) - 1) / x, (\cos(\sqrt{x}) - 1) / x)\).

Return type:

tuple[Tpsa, Tpsa]

sinh()

Return the hyperbolic sine of this series.

Return type:

Tpsa

cosh()

Return the hyperbolic cosine of this series.

Return type:

Tpsa

tanh()

Return the hyperbolic tangent of this series.

Return type:

Tpsa

sinhc()

Return \(\sinh(x) / x\) for this series (the unnormalised sinhc).

Return type:

Tpsa

asinh()

Return the inverse hyperbolic sine of this series.

Return type:

Tpsa

acosh()

Return the inverse hyperbolic cosine of this series.

Return type:

Tpsa

atanh()

Return the inverse hyperbolic tangent of this series.

Return type:

Tpsa

sincosh()

Return \((\sinh(x), \cosh(x))\) for this series.

Return type:

tuple[Tpsa, Tpsa]

sincoshq()

Return \((\operatorname{sinhc}(\sqrt{x}), \cosh(\sqrt{x}))\) for this series.

Return type:

tuple[Tpsa, Tpsa]

sincoshmq()

Return two related hyperbolic series.

\(((\operatorname{sinhc}(\sqrt{x}) - 1) / x, (\cosh(\sqrt{x}) - 1) / x)\).

Return type:

tuple[Tpsa, Tpsa]

erf()

Return the error function of this series.

Return type:

Tpsa

erfc()

Return the complementary error function of this series.

Return type:

Tpsa

erfcx()

Return the scaled complementary error function of this series.

Return type:

Tpsa

erfi()

Return the imaginary error function of this series.

Return type:

Tpsa

wofz()

Return the complex-valued Faddeeva function for this series.

Return type:

ComplexTpsa

wofz_real()

Return the real-valued Faddeeva function for this series (MAD-NG’s wf).

For complex output use scipy.special.wofz of manually promote the TPSA to complex with (ComplexTpsa.from_tpsa) and then call its wofz.

Return type:

Tpsa

atan2(other)

Return atan2(self, other).

Return type:

Tpsa

hypot(other)

Return \(\sqrt{\mathrm{self}^2 + \mathrm{other}^2}\).

Return type:

Tpsa

hypot3(other, third)

Return \(\sqrt{\mathrm{self}^2 + \mathrm{other}^2 + \mathrm{third}^2}\).

Return type:

Tpsa