# Model equations

$$ \dot{x}_i = \frac{f_i(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)} - x_i $$

where the number of offspring with genotype $i$ (i.e., fitness), f $f_i$, is an average of partial fecundities

$$ f_i(x; T, R, P, S, M, \epsilon) = x_1F_{i,1}(x; T, R, P, S, M, \epsilon) + x_2F_{i,2}(x; T, R, P, S, M, \epsilon) + x_3F_{i,3}(x; T, R, P, S, M, \epsilon) + (1 - x_1 - x_2 - x_3)F_{1,4}(x; T, R, P, S, M, \epsilon) $$

and the number of total offpspring across all genotypes, $F$, is the average of the total fecundities of the two females.

$$ F(x; T, R, P, S, M) = x_G F_G(x_A; T, R, P, S, M) + (1 - x_G)F_g(x_A; T, R, P, S, M) $$

# Partial derivatives

\begin{align}
    \frac{\partial \dot{x}_i}{\partial x_i} =& \frac{1}{F(x; T, R, P, S, M)}\left(\frac{\partial f_i(x; T, R, P, S, M, \epsilon)}{\partial x_i} - \frac{f_i(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_i}\right) - 1 \\
    \frac{\partial \dot{x}_i}{\partial x_j} =& \frac{1}{F(x; T, R, P, S, M)}\left(\frac{\partial f_i(x; T, R, P, S, M, \epsilon)}{\partial x_j} - \frac{f_i(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_j}\right)
\end{align}

## Jacobian

$$
\frac{1}{F(x; T, R, P, S, M)}
\begin{bmatrix}
    \left(\frac{\partial f_1(x; T, R, P, S, M, \epsilon)}{\partial x_1} - \frac{f_1(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_1}\right) & \left(\frac{\partial f_1(x; T, R, P, S, M, \epsilon)}{\partial x_2} - \frac{f_1(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_2}\right) & \left(\frac{\partial f_1(x; T, R, P, S, M, \epsilon)}{\partial x_3} - \frac{f_1(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_3}\right) \\
    \left(\frac{\partial f_2(x; T, R, P, S, M, \epsilon)}{\partial x_1} - \frac{f_2(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_1}\right) & \left(\frac{\partial f_2(x; T, R, P, S, M, \epsilon)}{\partial x_2} - \frac{f_2(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_2}\right) & \left(\frac{\partial f_2(x; T, R, P, S, M, \epsilon)}{\partial x_3} - \frac{f_2(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_3}\right) \\
    \left(\frac{\partial f_3(x; T, R, P, S, M, \epsilon)}{\partial x_1} - \frac{f_3(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_1}\right) & \left(\frac{\partial f_3(x; T, R, P, S, M, \epsilon)}{\partial x_2} - \frac{f_3(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_2}\right) & \left(\frac{\partial f_3(x; T, R, P, S, M, \epsilon)}{\partial x_3} - \frac{f_3(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\frac{\partial F(x; T, R, P, S, M)}{\partial x_3}\right)
\end{bmatrix}
-
I
$$

which we can further simplify as follows.

$$ \frac{1}{F(x; T, R, P, S, M)} \left( \nabla f(x; T, R, P, S, M, \epsilon) - \left[\frac{f(x; T, R, P, S, M, \epsilon)}{F(x; T, R, P, S, M)}\right]^T \nabla F(x; T, R, P, S, M) \right) - I $$

## Equilibrium

Note that in any equilibrium $x^*$ we have that.

$$ \frac{1}{F(x^*; T, R, P, S, M)} \bigg( \nabla f(x^*; T, R, P, S, M, \epsilon) - x^{*T} \nabla F(x^*; T, R, P, S, M) \bigg) - I $$


## Stability

Need the roots of the following polynomial to have negative real parts.

$$ \det \Bigg[\frac{1}{F(x^*; T, R, P, S, M)} \bigg( \nabla f(x^*; T, R, P, S, M, \epsilon) - x^{*T} \nabla F(x^*; T, R, P, S, M) \bigg) - \lambda I\Bigg] = 0 $$

### Trace

Computing the partial derivatives from above.

\begin{align}
    \frac{\partial f_1(x; T, R, P, S, M, \epsilon)}{\partial x_1} =& F_{1,1} - F_{1,4} + \left(x_1\left(\frac{\partial F_{1,1}(x; T, R, P, S, M, \epsilon)}{\partial x_1} - \frac{\partial F_{1,4}(x; T, R, P, S, M, \epsilon)}{\partial x_1}\right) + x_2\frac{\partial F_{1,2}(x; T, R, P, S, M, \epsilon)}{\partial x_1} + x_3\frac{\partial F_{1,3}(x; T, R, P, S, M, \epsilon)}{\partial x_1}\right) \\
    \frac{\partial f_2(x; T, R, P, S, M, \epsilon)}{\partial x_2} =& F_{2,2} - F_{2,4} + \left(x_1\frac{\partial F_{2,1}(x; T, R, P, S, M, \epsilon)}{\partial x_2}  + x_2\left(\frac{\partial F_{2,2}(x; T, R, P, S, M, \epsilon)}{\partial x_2} - \frac{\partial F_{2,4}(x; T, R, P, S, M, \epsilon)}{\partial x_2}\right) + x_3\frac{\partial F_{2,3}(x; T, R, P, S, M, \epsilon)}{\partial x_2}\right) \\
    \frac{\partial f_3(x; T, R, P, S, M, \epsilon)}{\partial x_3} =& F_{3,3} - F_{3,4} + \left(x_1\frac{\partial F_{3,1}(x; T, R, P, S, M, \epsilon)}{\partial x_3} + x_2\frac{\partial F_{3,2}(x; T, R, P, S, M, \epsilon)}{\partial x_3} + x_3\left(\frac{\partial F_{3,3}(x; T, R, P, S, M, \epsilon)}{\partial x_3} - \frac{\partial F_{3,4}(x; T, R, P, S, M, \epsilon)}{\partial x_3}\right)\right) \\
\end{align}

and 

\begin{align}
    \frac{\partial F(x; T, R, P, S, M)}{\partial x_1} =& F_G(x_A; T, R, P, S, M) - F_g(x_A; T, R, P, S, M) + \left(x_G\frac{\partial F_G(x_A; T, R, P, S, M)}{\partial x_A} + (1 - x_G)\frac{\partial F_g(x_A; T, R, P, S, M)}{\partial x_A}\right) \\
    \frac{\partial F(x; T, R, P, S, M)}{\partial x_2} =& F_G(x_A; T, R, P, S, M) - F_g(x_A; T, R, P, S, M) \\
    \frac{\partial F(x; T, R, P, S, M)}{\partial x_3} =& \frac{\partial F(x; T, R, P, S, M)}{\partial x_1} - \frac{\partial F(x; T, R, P, S, M)}{\partial x_2} \\
\end{align}

We can compute the $Tr(J)$ as follow.

$$ Tr(J) = \frac{1}{F(x^*; T, R, P, S, M)}\Bigg[\left(F_{1,1} + F_{2,2} + F_{3,3} - \left(F_{1,4} + F_{2,4} + F_{3,4}\right) + \left(x_1\left(\frac{\partial F_{1,1}(x; T, R, P, S, M, \epsilon)}{\partial x_1} - \frac{\partial F_{1,4}(x; T, R, P, S, M, \epsilon)}{\partial x_1}\right) + x_2\frac{\partial F_{1,2}(x; T, R, P, S, M, \epsilon)}{\partial x_1} + x_3\frac{\partial F_{1,3}(x; T, R, P, S, M, \epsilon)}{\partial x_1}\right) + \left(x_1\frac{\partial F_{2,1}(x; T, R, P, S, M, \epsilon)}{\partial x_2}  + x_2\left(\frac{\partial F_{2,2}(x; T, R, P, S, M, \epsilon)}{\partial x_2} - \frac{\partial F_{2,4}(x; T, R, P, S, M, \epsilon)}{\partial x_2}\right) + x_3\frac{\partial F_{2,3}(x; T, R, P, S, M, \epsilon)}{\partial x_2}\right) + \left(x_1\frac{\partial F_{3,1}(x; T, R, P, S, M, \epsilon)}{\partial x_3} + x_2\frac{\partial F_{3,2}(x; T, R, P, S, M, \epsilon)}{\partial x_3} + x_3\left(\frac{\partial F_{3,3}(x; T, R, P, S, M, \epsilon)}{\partial x_3} - \frac{\partial F_{3,4}(x; T, R, P, S, M, \epsilon)}{\partial x_3}\right)\right)\right) - \left(x_G^*\left(2\big(F_G(x_A^*; T, R, P, S, M) - F_g(x_A^*; T, R, P, S, M)\big) + \left(x_G^*\frac{\partial F_G(x_A; T, R, P, S, M)}{\partial x_A} + (1 - x_G^*)\frac{\partial F_g(x_A; T, R, P, S, M)}{\partial x_A}\right)\right) - x_A^*\left(F_G(x_A^*; T, R, P, S, M) - F_g(x_A^*; T, R, P, S, M)\right)\right)\Bigg] - 3 $$

## Suppose that $x_2=1-x_1$, $x_3=0$, $U_G=1$

$$ Tr(J) = \frac{1}{2(R - M)}\Bigg[\left((1 - \epsilon)2(R - M) + \frac{1}{2}2(R - M) - \frac{1}{4}\epsilon F_g(x_A^*, T, R, P, S, M) - \frac{1}{4}\epsilon L_g(x_A^*, R, S, M) - \frac{1}{4}F_g(x_A^*, T, R, P, S, M) + \left(x_1\left(\frac{\partial F_{1,1}(x; T, R, P, S, M, \epsilon)}{\partial x_1} - \frac{\partial F_{1,4}(x; T, R, P, S, M, \epsilon)}{\partial x_1}\right) + (1 - x_1)\frac{\partial F_{1,2}(x; T, R, P, S, M, \epsilon)}{\partial x_1}\right) + \left(\frac{1}{4}\epsilon - \frac{1}{2}\right)(F_g(x_A^*, T, R, P, S, M) - L_g(x_A^*, R, S, M)) + \frac{1}{2}2(R - M)\frac{1}{x_1}\right) - \left(2\big(2(R - M) - F_g(x_A^*; T, R, P, S, M)\big) + \frac{\partial F_G(x_A; T, R, P, S, M)}{\partial x_A} - x_A^*\left(2(R - M) - F_g(x_A^*; T, R, P, S, M)\right)\right)\Bigg] - 3 $$

$$ (\frac{1}{4}\epsilon(F_g(x_A^*,T,R,P,S,M) - L_g(x_A^*, R,S,M)) + (x_1 - 1)(-\frac{1}{4}\epsilon(\frac{\partial F_g(x_A,T,R,P,S,M)}{\partial x_1} - \frac{\partial L_g(x_A, R, S, M)}{\partial x_1}) - (\epsilon - 1)\frac{\partial L_G(x_A, R, S, M)}{\partial x_1} + \frac{1}{2}\frac{\partial F_G(x_A,T,R,P,S,M)}{\partial x_1} - \frac{1}{2}\frac{\partial L_G(x_A, R, S, M)}{\partial x_1} - \frac{1}{4}\frac{\partial L_g(x_A, R, S, M)}{\partial x_1}))/(x_1 - 1) $$


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```

Here we go...

\begin{align}
\det
\begin{bmatrix}
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) - \lambda & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) \\
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) - \lambda & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) \\
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) - \lambda
\end{bmatrix}
\end{align} 

\begin{align}
   = & (-1)^{(2+1)}\frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) \det
\begin{bmatrix}
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) \\
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) - \lambda
\end{bmatrix}
 + \\
 & (-1)^{(2+2)} \bigg(\frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) - \lambda\bigg) \det 
 \begin{bmatrix}
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) - \lambda & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) \\
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) - \lambda
\end{bmatrix}
+ \\
 & (-1)^{(2+1)}\frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) \det
 \begin{bmatrix}
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) - \lambda & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) \\
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right)
\end{bmatrix}
\end{align}

\begin{align}
   = & -\frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) \Bigg[\frac{1}{F(x^*; T, R, P, S, M)^2}\Bigg(\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right)\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) - \left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right)\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right)\Bigg) - \lambda\Bigg]
 + \\
 & (-1)^{(2+2)} \bigg(\frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) - \lambda\bigg) \det 
 \begin{bmatrix}
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) - \lambda & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) \\
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) - \lambda
\end{bmatrix}
+ \\
 & (-1)^{(2+1)}\frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_2(x^*; T, R, P, S, M, \epsilon)}{\partial x_3} - x_2^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_3}\right) \det
 \begin{bmatrix}
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) - \lambda & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_1(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_1^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right) \\
    \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_1} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_1}\right) & \frac{1}{F(x^*; T, R, P, S, M)}\left(\frac{\partial f_3(x^*; T, R, P, S, M, \epsilon)}{\partial x_2} - x_3^*\frac{\partial F(x^*; T, R, P, S, M)}{\partial x_2}\right)
\end{bmatrix}
\end{align}


```python

```

42e684b5ec9c12b81b1d65e2164d03eb2c9279a1
ipynb
Jupyter Notebook
Untitled3.ipynb
davidrpugh/evolution-of-social-behavior
52e8370613ab4f246759f28e578a631b86d8e712
MIT
2019-01-16T04:19:13.000Z
2020-01-28T11:45:17.000Z
Untitled3.ipynb
davidrpugh/evolution-of-social-behavior
52e8370613ab4f246759f28e578a631b86d8e712
MIT
2018-01-17T11:09:59.000Z
2018-01-17T11:09:59.000Z
Untitled3.ipynb
davidrpugh/evolution-of-social-behavior
52e8370613ab4f246759f28e578a631b86d8e712
MIT
2020-05-12T13:43:08.000Z
2021-04-19T07:14:14.000Z
Qwen/Qwen-72B
1. YES
2. YES