# 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{\alpha r_{ij}}{1 + \beta r_{ij}}\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):
    alpha, beta = symbols(r"\alpha \beta", real=True)
    exponent = Sum(alpha * r(i, j) / (1 + beta * r(i, j)), (i, 1, N - 1), (j, i + 1, N))
    return exp(exponent), (alpha, beta)


Jastrow, (alpha, beta) = 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

```

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



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

```


```python
# Manually simplify the above:
dlogJ_dXkl = Sum(
    alpha
    * beta
    * (KroneckerDelta(k, i) - KroneckerDelta(k, j))
    * (X[i, l] - X[j, l])
    / (beta * r(i, j) + 1)
    / (beta * r(i, j) * (beta * r(i, j) + 1)),
    (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.subs(beta, 0)

```


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

```


```python

```

285d05512dd894b6710a103f9ac9aae7cdc0e3b6
ipynb
Jupyter Notebook
scripts/Jastrow-Pade-sympy.ipynb
johanere/qflow
5453cd5c3230ad7f082adf9ec1aea63ab0a4312a
MIT
2019-07-24T21:46:24.000Z
2021-06-11T18:18:24.000Z
scripts/Jastrow-Pade-sympy.ipynb
johanere/qflow
5453cd5c3230ad7f082adf9ec1aea63ab0a4312a
MIT
2019-02-19T10:49:26.000Z
2019-07-18T09:42:13.000Z
scripts/Jastrow-Pade-sympy.ipynb
bsamseth/FYS4411
72b879e7978364498c48fc855b5df676c205f211
MIT
2019-04-24T06:44:33.000Z
2019-06-12T20:34:38.000Z
Qwen/Qwen-72B
1. YES
2. YES