# Jastrow Factor Derivatives

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

$$J(X) = \prod_{i < j} \exp\left(-\frac{\beta^2}{2}r_{ij}^2 + |\beta\gamma|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
def r(i, j):
    return sqrt(Sum((X[i, d] - X[j, d]) ** 2, (d, 1, D)))


# r = Function('r', positive=True)


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


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

```


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

```

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



```python
dlogJ_dGamma = diff(log_Jastrow, gamma, 1)
dlogJ_dGamma

```

## 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(
    (KroneckerDelta(k, i) - KroneckerDelta(k, j))
    * (X[i, l] - X[j, l])
    * (-beta ** 2 + Abs(beta * gamma) / r(i, j)),
    (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(
    (KroneckerDelta(k, i) - KroneckerDelta(k, j)) ** 2
    * (-beta ** 2 + Abs(beta * gamma) / r(i, j))
    - (KroneckerDelta(k, i) - KroneckerDelta(k, j))
    * (X[i, l] - X[j, l]) ** 2
    * Abs(beta * gamma)
    / r(i, j) ** 3,
    (i, 1, N - 1),
    (j, i + 1, N),
)
d2J_dXkl2

```


```python

```

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