# Derivatives of the $\Lambda$ function

#### Validation of the derivatives of the $\Lambda$ function for linearly limb-darkened transits

Let's import some stuff.


```python
import numpy as np
import matplotlib.pyplot as pl
%matplotlib notebook
from IPython.display import display, Math
import sympy
from sympy import *
from sympy.functions.special.delta_functions import Heaviside
from sympy.functions.special.elliptic_integrals import elliptic_k, elliptic_e, elliptic_pi

# Initialize the session
init_session(quiet=True)

# Let's report what version of sympy this is
print("Using sympy version", sympy.__version__)
```

    
    Using sympy version 1.3


We're going to take all the derivatives analytically using `sympy`.


```python
Lambda, r, b, ksq = symbols("\Lambda r b, k^2")
ksq = (1 - r ** 2 - b ** 2 + 2 * b * r) / (4 * b * r)
```

## $k^2$ < 1

Here's the expression from the paper, in terms of the standard elliptic integrals $E$, $K$, and $\Pi$ (which `sympy` knows how to compute):


```python
f1 = 1 / (9 * pi * sqrt(b * r))
f2 = ((r + b) ** 2 - 1) / (r + b)
f3 = -2 * r * (2 * (r + b) ** 2 + (r + b) * (r - b) - 3)
f4 = 3 * (b - r)
f5 = -4 * b * r * (4 - 7 * r ** 2 - b ** 2)
K = elliptic_k(ksq)
E = elliptic_e(ksq)
PI = elliptic_pi(ksq * (b + r) ** 2, ksq)
Lambda = f1 * (f2 * (f3 * K + f4 * PI) + f5 * E)
Lambda
```




$$\frac{- 4 b r \left(- b^{2} - 7 r^{2} + 4\right) E\left(\frac{- b^{2} + 2 b r - r^{2} + 1}{4 b r}\right) + \frac{\left(- 2 r \left(\left(- b + r\right) \left(b + r\right) + 2 \left(b + r\right)^{2} - 3\right) K\left(\frac{- b^{2} + 2 b r - r^{2} + 1}{4 b r}\right) + \left(3 b - 3 r\right) \Pi\left(\frac{\left(b + r\right)^{2} \left(- b^{2} + 2 b r - r^{2} + 1\right)}{4 b r}\middle| \frac{- b^{2} + 2 b r - r^{2} + 1}{4 b r}\right)\right) \left(\left(b + r\right)^{2} - 1\right)}{b + r}}{9 \pi \sqrt{b r}}$$



### Derivative with respect to $r$

The derivative of this expression with respect to $r$ is


```python
dLdr = simplify(diff(Lambda, r))
dLdr
```

We claim this simplifies to:


```python
dLdr_paper = (8 * b * r ** 2 * elliptic_e(ksq) + 2 * r * (1 - (b + r) ** 2) * elliptic_k(ksq)) / (pi * sqrt(b * r))
dLdr_paper
```

Do the expressions agree?


```python
simplify(dLdr_paper - dLdr) == 0
```




    True



**QED**

Now, using the relation

$\ \ \ \ \ \ \ \ \ \lambda K(k^2) + q E(k^2) = \mathrm{cel}(k_c, 1, \lambda + q, \lambda + q k_c^2)$

with 

$\ \ \ \ \ \ \ \ \ \lambda = 2 r (1 - (b + r)^2)$ 

and 

$\ \ \ \ \ \ \ \ \ q = 8 b r^2$,

we have

$\ \ \ \ \ \ \ \ \ \lambda + q =$


```python
lam = 2 * r * (1 - (b + r) ** 2)
q = 8 * b * r ** 2
factor(simplify(lam + q))
```

$=2 r (1 − (b − r)^2 )$

and

$\ \ \ \ \ \ \ \ \ \lambda + q k_c^2 =$


```python
simplify(lam + q * (1 - ksq))
```

We can then re-write the derivative as

$\frac{1}{\pi \sqrt{b r}} \mathrm{cel}(k_c, 1, 2 r (1 − (b − r)^2 ), 0)$

**QED**

### Derivative with respect to $b$

The derivative of this expression with respect to $b$ is


```python
dLdb = simplify(diff(Lambda, b))
dLdb
```

We claim this simplifies to:


```python
dLdb_paper = (4 * r * (r ** 2 + b ** 2 - 1) * elliptic_e(ksq) + 2 * r * (1 - (b + r) ** 2) * elliptic_k(ksq)) / (3 * pi * sqrt(b * r))
dLdb_paper
```

Do the expressions agree?


```python
simplify(dLdb_paper - dLdb) == 0
```




    True



**QED**

Now, using the relation

$\ \ \ \ \ \ \ \ \ \lambda K(k^2) + q E(k^2) = \mathrm{cel}(k_c, 1, \lambda + q, \lambda + q k_c^2)$

with 

$\ \ \ \ \ \ \ \ \ \lambda = \frac{2r(1 - (b + r)^2)}{1 - (b - r)^2}$

and 

$\ \ \ \ \ \ \ \ \ q = \frac{4r(r^2 + b^2 - 1)}{1 - (b - r)^2}$

we have

$\ \ \ \ \ \ \ \ \ \lambda + q =$


```python
lam = 2 * r * (1 - (b + r) ** 2) / (1 - (b - r) ** 2)
q = 4 * r * (r ** 2 + b ** 2 - 1) / (1 - (b - r) ** 2)
factor(simplify(lam + q))
```

and

$\ \ \ \ \ \ \ \ \ \lambda + q k_c^2 =$


```python
factor(simplify(lam + q * (1 - ksq)))
```

$=\frac{1 - (b + r)^2}{b}$

We can then re-write the derivative as

$\frac{1 - (b - r)^2}{3\pi \sqrt{b r}} \mathrm{cel}(k_c, 1, -2r, \frac{1 - (b + r)^2}{b})$

**QED**

## $k^2$ > 1

Here's the expression from the paper, in terms of the standard elliptic integrals $E$, $K$, and $\Pi$ (which `sympy` knows how to compute):


```python
f1 = 2 / (9 * pi)
f2 = 1 - (r + b) ** 2
f3 = sqrt(1 - (b - r) ** 2)
f4 = 3 * (b - r) / ((b + r) * sqrt(1 - (b - r) ** 2))
f5 = -sqrt(1 - (b - r) ** 2) * (4 - 7 * r ** 2 - b ** 2)
K = elliptic_k(1 / ksq)
E = elliptic_e(1 / ksq)
PI = elliptic_pi(1 / (ksq * (b + r) ** 2), 1 / ksq)
Lambda = f1 * (f2 * (f3 * K + f4 * PI) + f5 * E)
Lambda
```




$$\frac{2 \left(\left(\sqrt{- \left(b - r\right)^{2} + 1} K\left(\frac{4 b r}{- b^{2} + 2 b r - r^{2} + 1}\right) + \frac{\left(3 b - 3 r\right) \Pi\left(\frac{4 b r}{\left(b + r\right)^{2} \left(- b^{2} + 2 b r - r^{2} + 1\right)}\middle| \frac{4 b r}{- b^{2} + 2 b r - r^{2} + 1}\right)}{\left(b + r\right) \sqrt{- \left(b - r\right)^{2} + 1}}\right) \left(- \left(b + r\right)^{2} + 1\right) - \sqrt{- \left(b - r\right)^{2} + 1} \left(- b^{2} - 7 r^{2} + 4\right) E\left(\frac{4 b r}{- b^{2} + 2 b r - r^{2} + 1}\right)\right)}{9 \pi}$$



### Derivative with respect to $r$

The derivative of this expression with respect to $r$ is


```python
dLdr = simplify(diff(Lambda, r))
dLdr
```

We claim this simplifies to:


```python
dLdr_paper = 4 * r / pi * sqrt(1 - (b - r) ** 2) * elliptic_e(1 / ksq)
dLdr_paper
```

Do the expressions agree?


```python
simplify(dLdr_paper - dLdr) == 0
```




    True



**QED**

Now, using the relation

$\ \ \ \ \ \ \ \ \ E(m_k) = \mathrm{cel}(k_c,1,1,1 − m_k)$

the derivative may be written as

$\ \ \ \ \ \ \ \ \ \frac{4 r}{\pi} \sqrt{1 - (b - r)^2} \mathrm{cel}(k_c,1,1,k_c^2)$

**QED**

### Derivative with respect to $b$

The derivative of this expression with respect to $b$ is


```python
dLdb = simplify(diff(Lambda, b))
dLdb
```

We claim this simplifies to:


```python
dLdb_paper = 2 / (3 * b * pi) * sqrt(1 - (b - r) ** 2) * ((r ** 2 + b ** 2 - 1) * elliptic_e(1 / ksq) + (1 - (b + r) ** 2) * elliptic_k(1 / ksq))
dLdb_paper
```

Do the expressions agree?


```python
simplify(dLdb_paper - dLdb) == 0
```




    True



**QED**

Now, using the relation

$\ \ \ \ \ \ \ \ \ \lambda K(k^2) + q E(k^2) = \mathrm{cel}(k_c, 1, \lambda + q, \lambda + q k_c^2)$

with 

$\ \ \ \ \ \ \ \ \ \lambda = \frac{1 - (b + r)^2}{2 b r}$

and 

$\ \ \ \ \ \ \ \ \ q = \frac{r^2 + b^2 - 1}{2 b r}$

we have

$\ \ \ \ \ \ \ \ \ \lambda + q =$


```python
lam = (1 - (b + r) ** 2) / (2 * b * r)
q = (r ** 2 + b ** 2 - 1) / (2 * b * r)
factor(simplify(lam + q))
```

and

$\ \ \ \ \ \ \ \ \ \lambda + q k_c^2 =$


```python
kc2 = (1 - 1 / ksq)
factor(simplify(lam + q * kc2))
```

$=$


```python
factor(kc2)
```

$=k_c^2$

We can then re-write the derivative as

$\frac{4 r}{3\pi} \sqrt{1 - (b - r)^2} \mathrm{cel}(k_c, 1, -1, k_c^2)$

**QED**

## r = 0

In this case, $\Lambda(r, b) = 0$, so the derivatives are trivially equal to zero.

**QED**

## |r - b| $\ge$ 1

Same here. The derivatives are just zero.

**QED**

## b = 0


```python
Lambda = -Rational(2, 3) * (1 - r ** 2) ** Rational(3, 2)
```

The expression for lambda is


```python
Lambda
```

The derivative with respect to $r$ is


```python
diff(Lambda, r)
```

The expression for $\Lambda$ does not depend on $b$, so the derivative with respect to $b$ is zero.

**QED**

## b = r < 1/2

Let's differentiate the expression for $k^2 > 1$ and substitute $b = r$:


```python
dLdr_paper = 4 * r / pi * sqrt(1 - (b - r) ** 2) * elliptic_e(1 / ksq)
simplify(dLdr_paper.subs({"b": r}))
```

**QED**

Let's do the same for the $b$ derivative:


```python
dLdb_paper = 2 / (3 * b * pi) * sqrt(1 - (b - r) ** 2) * ((r ** 2 + b ** 2 - 1) * elliptic_e(1 / ksq) + (1 - (b + r) ** 2) * elliptic_k(1 / ksq))
simplify(dLdb_paper.subs({"b": r}))
```

Now, using the relation

$\ \ \ \ \ \ \ \ \ \lambda K(k^2) + q E(k^2) = \mathrm{cel}(k_c, 1, \lambda + q, \lambda + q k_c^2)$

with 

$\ \ \ \ \ \ \ \ \ \lambda = -2 + \frac{1}{2 r ^ 2}$ 

and 

$\ \ \ \ \ \ \ \ \ q = 1 -  \frac{1}{2 r ^ 2}$,

we have

$\ \ \ \ \ \ \ \ \ \lambda + q =$


```python
lam = -2 + 1 / (2 * r ** 2)
q = 1 - 1 / (2 * r ** 2)
factor(simplify(lam + q))
```

and

$\ \ \ \ \ \ \ \ \ \lambda + q k_c^2 =$


```python
kc2 = (1 - 1 / ksq).subs({"b": r})
simplify(factor(simplify(lam + q * kc2)))
```

$=$


```python
kc2
```

We can then re-write the derivative as

$\frac{4r}{3\pi} \mathrm{cel}(k_c, 1, -1, k_c^2)$

**QED**

## b = r > 1/2

Let's differentiate the expression for $k^2 < 1$ and substitute $b = r$:


```python
dLdr_paper = (8 * b * r ** 2 * elliptic_e(ksq) + 2 * r * (1 - (b + r) ** 2) * elliptic_k(ksq)) / (pi * sqrt(b * r))
simplify(dLdr_paper.subs({"b": r}))
```

Now, using the relation

$\ \ \ \ \ \ \ \ \ \lambda K(k^2) + q E(k^2) = \mathrm{cel}(k_c, 1, \lambda + q, \lambda + q k_c^2)$

with 

$\ \ \ \ \ \ \ \ \ \lambda = -(4 r ^ 2 - 1)$ 

and 

$\ \ \ \ \ \ \ \ \ q = 4 r ^ 2$,

we have

$\ \ \ \ \ \ \ \ \ \lambda + q =$


```python
lam = -(4 * r ** 2 - 1)
q = 4 * r ** 2
factor(simplify(lam + q))
```

and

$\ \ \ \ \ \ \ \ \ \lambda + q k_c^2 =$


```python
kc2 = (1 - ksq).subs({"b": r})
simplify(factor(simplify(lam + q * kc2)))
```

We can then re-write the derivative as

$\frac{2}{\pi} \mathrm{cel}(k_c, 1, 1, 0)$

**QED**

Let's do the same for the $b$ derivative:


```python
dLdb_paper = (4 * r * (r ** 2 + b ** 2 - 1) * elliptic_e(ksq) + 2 * r * (1 - (b + r) ** 2) * elliptic_k(ksq)) / (3 * pi * sqrt(b * r))
simplify(dLdb_paper.subs({"b": r}))
```

Now, using the relation

$\ \ \ \ \ \ \ \ \ \lambda K(k^2) + q E(k^2) = \mathrm{cel}(k_c, 1, \lambda + q, \lambda + q k_c^2)$

with 

$\ \ \ \ \ \ \ \ \ \lambda = 4r^2 - 1$ 

and 

$\ \ \ \ \ \ \ \ \ q = -2(2r^2 - 1)$,

we have

$\ \ \ \ \ \ \ \ \ \lambda + q =$


```python
lam = (4 * r ** 2 - 1)
q = -2 * (2 * r ** 2 - 1)
factor(simplify(lam + q))
```

and


```python
kc2 = (1 - ksq).subs({"b": r})
simplify(factor(simplify(lam + q * kc2)))
```

$=$


```python
2 * kc2
```

We can then re-write the derivative as

$-\frac{2}{3\pi} \mathrm{cel}(k_c, 1, 1, 2k_c^2)$

**QED**

## b + r = 1

Let's differentiate the expression for $k^2 > 1$ and substitute $b = 1 - r$:


```python
dLdr_paper = 4 * r / pi * sqrt(1 - (b - r) ** 2) * elliptic_e(1 / ksq)
```


```python
simplify(dLdr_paper.subs({"b": 1 - r}))
```

**QED**

Let's do the same for the $b$ derivative:


```python
dLdb_paper = 2 / (3 * b * pi) * sqrt(1 - (b - r) ** 2) * ((r ** 2 + b ** 2 - 1) * elliptic_e(1 / ksq) + (1 - (b + r) ** 2) * elliptic_k(1 / ksq))
```


```python
simplify(dLdb_paper.subs({"b": 1 - r}))
```

**QED**

## b = r = 1/2

This is a special case of $b + r = 1$. The derivative with respect to $r$ is thus


```python
simplify((8 * r * sqrt(r * (-r + 1)) / pi).subs({"r": Rational(1, 2)}))
```

**QED**

The derivative with respect to $b$ is


```python
simplify((-8 * r * sqrt(r * (-r + 1)) / (3 * pi)).subs({"r": Rational(1, 2)}))
```

**QED**

51f7f037f7e9c5efe7c85d12bc5a9b6045964af9
ipynb
Jupyter Notebook
proofs/biglam_deriv.ipynb
langfzac/Limbdark.jl
a6a30c52e14686a9a01d7b4437f4f171c9c53a24
MIT
2019-05-08T09:03:56.000Z
2021-02-14T20:53:23.000Z
proofs/biglam_deriv.ipynb
langfzac/Limbdark.jl
a6a30c52e14686a9a01d7b4437f4f171c9c53a24
MIT
2018-04-23T20:41:25.000Z
2019-05-02T01:50:19.000Z
proofs/biglam_deriv.ipynb
langfzac/Limbdark.jl
a6a30c52e14686a9a01d7b4437f4f171c9c53a24
MIT
2019-05-15T08:06:04.000Z
2020-02-24T19:11:47.000Z
Qwen/Qwen-72B
1. YES
2. YES