# Jastrow Factor Derivatives

This notebook calculates the expressions for the derivatives of the following Jastrow function:

$$J(\mathbf{X}) = \prod_{i < j} \exp\left[- \frac{1}{2}\left(\frac{\beta}{r}\right)^m  \right]$$

with $N$ particles in $D$ dimensions, $\mathbf{X}\in\mathbb{R}^{N\times D}$ and $r_{ij} = ||\mathbf{X_i} - \mathbf{X_j}||$.


```python
%reload_ext blackcellmagic
from sympy import *
init_printing()
```


```python
N, D, i, j, k, l, d = symbols("N D i j k l d", integer=True)
X = IndexedBase("X", shape=(N, D))

```

## Definition



```python
class r(Function):
    @classmethod
    def eval(cls, i, j):
        if i.is_Number and j.is_Number:
            return sqrt(Sum((X[i, d] - X[j, d]) ** 2, (d, 1, D)))

    def doit(self, **kwargs):
        i, j = self.args
        return sqrt(Sum((X[i, d] - X[j, d]) ** 2, (d, 1, D)))

    def _eval_derivative(self, x):
        return self.doit()._eval_derivative(x)


def J(X):
    beta = symbols(r"\beta", real=True, positive=True)
    n = symbols("n", integer=True, positive=True)
    exponent = Sum(-(beta / r(i, j)) ** n / 2, (i, 1, N - 1), (j, i + 1, N))
    return exp(exponent), (beta, n)


Jastrow, (beta, n) = J(X)
Jastrow

```


```python
log_Jastrow = expand_log(log(Jastrow), force=True)
log_Jastrow

```

## Derivative w.r.t. $\beta$



```python
dlogJ_dBeta = diff(log_Jastrow, beta, 1)
dlogJ_dBeta.simplify()

```

## Derivative w.r.t. $X_{kl}$



```python
dlogJ_dXkl = diff(log_Jastrow.doit(), X[k, l], 1)
dlogJ_dXkl

```


```python
# Manually simplify the above:
dlogJ_dXkl = Sum(
    n / 2
    * (beta / r(i, j)) ** n
    * (KroneckerDelta(k, i) - KroneckerDelta(k, j))
    * (X[i, l] - X[j, l])
    / (r(i, j).doit() ** 2),
    (i, 1, N - 1),
    (j, i + 1, N),
)
dlogJ_dXkl

```

## Second derivative w.r.t. $X_{kl}$



```python
d2J_dXkl2 = dlogJ_dXkl ** 2 + diff(dlogJ_dXkl, X[k, l], 1)
d2J_dXkl2

```


```python
# Manually simplify the above:
d2J_dXkl2 = dlogJ_dXkl ** 2 + Sum(
    n / 2
    * (beta / r(i, j)) ** n
    / (r(i, j) ** 2)
    * (KroneckerDelta(k, i) - KroneckerDelta(k, j)) ** 2
    * (1 - 2 * (X[i, l] - X[j, l]) ** 2 / (r(i, j) ** 2)   ),
    (i, 1, N - 1),
    (j, i + 1, N),
)
d2J_dXkl2

```


```python

```

882bfa5efdcccd2f42ed4a83c3d0f89b0c8f1e71
ipynb
Jupyter Notebook
scripts/Jastrow-McMillian.ipynb
johanere/qflow
5453cd5c3230ad7f082adf9ec1aea63ab0a4312a
MIT
2019-07-24T21:46:24.000Z
2021-06-11T18:18:24.000Z
scripts/Jastrow-McMillian.ipynb
johanere/qflow
5453cd5c3230ad7f082adf9ec1aea63ab0a4312a
MIT
2019-02-19T10:49:26.000Z
2019-07-18T09:42:13.000Z
scripts/Jastrow-McMillian.ipynb
bsamseth/FYS4411
72b879e7978364498c48fc855b5df676c205f211
MIT
2020-11-04T15:17:24.000Z
2021-11-03T16:37:38.000Z
Qwen/Qwen-72B
1. YES
2. YES