# L3 (Maschberger 2013)
## Form
[Maschberger (2013)](https://ui.adsabs.harvard.edu/abs/2013MNRAS.429.1725M/abstract) suggest an IMF that can capture the high and low mass behaviour we observe, while being continuous, and suggest the following form $$\xi(M) = \xi_0 \left(\frac{M}{\mu}\right)^{-\alpha}\left(1 + \left(\frac{M}{\mu}\right)^{1-\alpha}\right)^{-\beta}$$

With the values $$\begin{gather*}\alpha=2.3\\ \beta=1.4\\ \mu=0.2\end{gather*}$$ to mimic a [Kroupa (2001)](./kroupa.md) or [Chabrier (2003)](./chabrier.md) IMF.

```{note}
We typically define power laws like $M^\alpha$, with $\alpha < 0$, as opposed to having $\alpha > 0$ and $M^{-\alpha}$. This is an exception, as it would potentially be more confusing to switch all the signs compared to the original paper.
```

## Implemented in
This is implemented in the {py:class}`~pimf.initialmassfunction.L3IMF` class, where the user is free to pick whatever parameters they like or use the default (same as above).

## Integrals
The integrals of interest are provided in the original paper, [Maschberger (2013)](https://ui.adsabs.harvard.edu/abs/2013MNRAS.429.1725M/abstract), modulo some manipulation. As such we do not derive the integrals from first principles, like other IMFs, but rather describe how to convert them into a form we are interested in.

For this we will use the auxillary function: $$G(M) = \left( 1 + \left( \frac{M}{\mu} \right)^{1-\alpha} \right)^{1-\beta}.$$

It is informative to first take the derivative $$\frac{\mathrm{d}G}{\mathrm{d}M} = \frac{(1-\alpha)(1-\beta)}{\mu}\left(\frac{M}{\mu}\right)^{-\alpha}\left(1 + \left(\frac{M}{\mu}\right)^{1-\alpha}\right)^{-\beta}$$

and note the relation to the IMF $$\xi(M) = \xi_0\frac{\mu}{(1-\alpha)(1-\beta)}\frac{\mathrm{d}G}{\mathrm{d}M}.$$

### Total number of stars
For this integral we use the form of the IMF directly above. See also eqn 21 of [Maschberger (2013)](https://ui.adsabs.harvard.edu/abs/2013MNRAS.429.1725M/abstract).
$$\begin{align}
\int^{M_\textrm{max}}_{M_\textrm{min}}\xi(M)\mathrm{d}M 
    &= \xi_0\frac{\mu}{(1-\alpha)(1-\beta)}\int^{M_\textrm{max}}_{M_\textrm{min}}\frac{\mathrm{d}G}{\mathrm{d}M}\mathrm{d}M \\
    &= \xi_0\frac{\mu}{(1-\alpha)(1-\beta)}\left[G(M)\right]^{M_\textrm{max}}_{M_\textrm{min}} \\
    &= \xi_0\frac{\mu}{(1-\alpha)(1-\beta)}\left\{G(M_\textrm{max}) - G(M_\textrm{min})\right\}.
\end{align}$$


### Total mass of stars
For this integral we use the parameterisation in eqns 24--25 of [Maschberger (2013)](https://ui.adsabs.harvard.edu/abs/2013MNRAS.429.1725M/abstract). This requires the incomplete beta function. Under the hood we will use [`scipy.special.beta`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.beta.html) and [`scipy.special.betainc`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.betainc.html).
Define the incomplete beta function $B(a, b, t)$ as it is by `scipy`:
$$
B(a, b, t) = \frac{1}{\mathtt{beta}(a, b)}\int_0^t x^{a-1}(1-x)^{b-1}\mathrm{d}x,
$$

with the fact $\int^{b}_{a}f(x)\mathrm{d}x = \int^{b}_{0}f(x)\mathrm{d}x - \int^{a}_{0}f(x)\mathrm{d}x$ we can write the integral with arbitrary limits
$$\int_{t_1}^{t_2} x^{a-1}(1-x)^{b-1}\mathrm{d}x = \mathtt{beta}(a, b)\{B(a, b, t_2) - B(a, b, t_1)\}$$

We will also use the substitution and it's derivative
$$
t(M) = \left(\frac{M}{\mu}\right)^{1-\alpha}\left(1 + \left(\frac{M}{\mu}\right)^{1-\alpha}\right)^{-1} \\
\frac{\mathrm{d}t}{\mathrm{d}M} = \frac{1-\alpha}{\mu}\left(\frac{t}{1-t}\right)^{\frac{-\alpha}{1-\alpha}}(1-t)^2 
.$$

$$\begin{align}
\int^{M_\textrm{max}}_{M_\textrm{min}}M\xi(M)\mathrm{d}M 
    &= \xi_0\int^{M_\textrm{max}}_{M_\textrm{min}}\left(\frac{\mu}{\mu}\right)M\left(\frac{M}{\mu}\right)^{-\alpha}\left(1 + \left(\frac{M}{\mu}\right)^{1-\alpha}\right)^{-\beta}\mathrm{d}M \\
    &= \mu\xi_0\int^{M_\textrm{max}}_{M_\textrm{min}}\left(\frac{M}{\mu}\right)^{1-\alpha}\left(1 + \left(\frac{M}{\mu}\right)^{1-\alpha}\right)^{-\beta}\mathrm{d}M \\
    &= \xi_0\frac{\mu^2}{1-\alpha}\int^{t(M_\textrm{max})}_{t(M_\textrm{min})}t^{a-1}(1-t)^{b-1}\mathrm{d}t \\
    &= \xi_0\frac{\mu^2}{1-\alpha}\mathtt{beta}(a, b)\{B(a, b, t(M_\textrm{max})) - B(a, b, t(M_\textrm{min}))\}
\end{align}$$
with $a = \frac{2-\alpha}{1-\alpha}, b = \beta - a$.