# plasma_plots.theory.special

*module*

Special functions of plasma theory: the Faddeeva function, the plasma dispersion function and
complete elliptic integrals, in plain numpy (no scipy needed).

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/theory/special.py#L1-L1)

## plasma_plots.theory.special.elliptic_e

*function*

```python
def elliptic_e(m)
```

Compute the complete elliptic integral of the second kind E(m), with parameter m = k².

E(m) = ∫₀^{π/2} √(1 − m sin²θ) dθ, by the arithmetic-geometric mean.

**Parameters**

- `m` (`float or array_like`) — The parameter, m ≤ 1.

**Returns**

- (`float or numpy.ndarray`) — E(m); ``nan`` for m > 1.

**Examples**

```pycon
>>> round(float(elliptic_e(1.0)), 12)
1.0
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/theory/special.py#L142-L174)

## plasma_plots.theory.special.elliptic_k

*function*

```python
def elliptic_k(m)
```

Compute the complete elliptic integral of the first kind K(m), with parameter m = k².

K(m) = ∫₀^{π/2} dθ / √(1 − m sin²θ), by the arithmetic-geometric mean.

**Parameters**

- `m` (`float or array_like`) — The parameter, m < 1 (K diverges logarithmically as m → 1).

**Returns**

- (`float or numpy.ndarray`) — K(m); ``inf`` at m = 1, ``nan`` for m > 1.

**Examples**

```pycon
>>> round(float(elliptic_k(0.0)), 12)  # π/2
1.570796326795
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/theory/special.py#L114-L139)

## plasma_plots.theory.special.faddeeva

*function*

```python
def faddeeva(z)
```

Compute the Faddeeva function w(z) = exp(−z²) erfc(−iz).

Weideman's rational approximation with 64 terms in the upper half plane (relative accuracy
about 1e-13), continued to the lower half plane with w(z) = 2 exp(−z²) − w(−z).

**Parameters**

- `z` (`complex or array_like`) — The argument.

**Returns**

- (`complex or numpy.ndarray`) — w(z), with the shape of ``z``.

> **References**
>
> J. A. C. Weideman, "Computation of the complex error function", SIAM J. Numer. Anal. 31,
> 1497 (1994).

**Examples**

```pycon
>>> # erfc(1) e¹ at z = i
>>> round(faddeeva(0.0).real, 12), round(faddeeva(1j).real, 6)
(1.0, 0.427584)
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/theory/special.py#L32-L69)

## plasma_plots.theory.special.plasma_dispersion

*function*

```python
def plasma_dispersion(zeta, derivative: int = 0)
```

Compute the plasma dispersion function Z(ζ) of Fried and Conte, or its first derivative.

Z(ζ) = i √π w(ζ) is the analytic continuation of (1/√π) ∫ exp(−x²)/(x − ζ) dx from the upper
half plane (Landau's prescription), and Z'(ζ) = −2 [1 + ζ Z(ζ)]. For a Maxwellian
f ∝ exp(−v²/(2 v_th²)) the argument is ζ = ω/(√2 k v_th).

**Parameters**

- `zeta` (`complex or array_like`) — The argument ζ.
- `derivative` (`(0, 1)`) (default: `0`) — 0 for Z(ζ), 1 for Z'(ζ). Default: ``0``.

**Returns**

- (`complex or numpy.ndarray`) — Z(ζ) or Z'(ζ), with the shape of ``zeta``.

**Raises**

- `ValueError` — If ``derivative`` is not 0 or 1.

> **References**
>
> B. D. Fried and S. D. Conte, The Plasma Dispersion Function (Academic Press, 1961).

**Examples**

```pycon
>>> round(plasma_dispersion(0.0).imag, 6)  # i √π at the origin
1.772454
>>> plasma_dispersion(0.0, derivative=1)
(-2+0j)
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/theory/special.py#L72-L111)
