# How to calculate von Neumann entropy from MPS

**URL:** <https://itensor.discourse.group/t/how-to-calculate-von-neumann-entropy-from-mps/292>\
**Category:** ITensor Julia Questions\
**Created:** [July 27, 2022, 1:38pm UTC](https://itensor.discourse.group/t/how-to-calculate-von-neumann-entropy-from-mps/292 "2022-07-27T13:38:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![coolgas](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/coolgas/32/72_2.png) [@coolgas](https://itensor.discourse.group/u/coolgas)\
**Post date:** [July 27, 2022, 1:38pm UTC](https://itensor.discourse.group/t/how-to-calculate-von-neumann-entropy-from-mps/292/1 "2022-07-27T13:38:41Z")

</div>

Hi all. So I am trying to calculate von Neumann entropy (not entanglement entropy, namely I am not trying to bipartite the system) by using the ground state psi after DMRG. The ground state energy matches well with exact diagonalization (ED), so I am trying to find out whether the von Neumann entropy of the density matrix constructed from psi matches that from ED.

I fully realize that there is an official way of computing entanglement entropy from psi provided by itensors team. The code is as following:

```auto
orthogonalize!(psi, b)
U,S,V = svd(psi[b], (linkind(psi, b-1), siteind(psi,b)))
SvN = 0.0
for n=1:dim(S, 1)
  p = S[n,n]^2
  SvN -= p * log(p)
end

```

However, this is not what I want. I am asking how to modify this block of code to calculate just von Neumann entropy. Thanks!

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [July 27, 2022, 2:03pm UTC](https://itensor.discourse.group/t/how-to-calculate-von-neumann-entropy-from-mps/292/2 "2022-07-27T14:03:53Z")

</div>

Hi, so the code should compute the von Neumann entropy, as defined here:  
[https://en.wikipedia.org/wiki/Von\_Neumann\_entropy](https://en.wikipedia.org/wiki/Von_Neumann_entropy)  
If you believe it isn’t, please let us know why not but I think it is.

---

<div class="post-metadata">

**Author:** ![coolgas](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/coolgas/32/72_2.png) [@coolgas](https://itensor.discourse.group/u/coolgas)\
**Post date:** [July 27, 2022, 2:09pm UTC](https://itensor.discourse.group/t/how-to-calculate-von-neumann-entropy-from-mps/292/3 "2022-07-27T14:09:33Z")

</div>

Hi Miles. Thank you! It seems like I have some misunderstanding of the code I posted.

---

<div class="post-metadata">

**Author:** ![ZhiguangLu](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/zhiguanglu/32/172_2.png) [@ZhiguangLu](https://itensor.discourse.group/u/ZhiguangLu)\
**Post date:** [March 14, 2023, 7:48am UTC](https://itensor.discourse.group/t/how-to-calculate-von-neumann-entropy-from-mps/292/4 "2023-03-14T07:48:01Z")

</div>

Can we apply the method for the matrix product density operator (MPDO).

---

<div class="post-metadata">

**Author:** ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)\
**Post date:** [March 14, 2023, 12:53pm UTC](https://itensor.discourse.group/t/how-to-calculate-von-neumann-entropy-from-mps/292/5 "2023-03-14T12:53:56Z")

</div>

If the definition of entropy you are wanting to compute would be the same as if you treated an MPDO as an MPS i.e. a “purification” of the density matrix then yes. However, if you are asking if you can compute the thermodynamic entropy (i.e. the entropy in the formula F = E-TS) this way then no, because that entropy is defined differently.
