# How to exponentiate an operator and calculate expectation of multiple operators in ITENSOR julia?

**URL:** <https://itensor.discourse.group/t/how-to-exponentiate-an-operator-and-calculate-expectation-of-multiple-operators-in-itensor-julia/846>\
**Category:** ITensor Julia Questions\
**Tags:** julia, dmrg, mps, mpo\
**Created:** [May 10, 2023, 1:23pm UTC](https://itensor.discourse.group/t/how-to-exponentiate-an-operator-and-calculate-expectation-of-multiple-operators-in-itensor-julia/846 "2023-05-10T13:23:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aditya214](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/aditya214/32/231_2.png) [@Aditya214](https://itensor.discourse.group/u/Aditya214)\
**Post date:** [May 10, 2023, 1:23pm UTC](https://itensor.discourse.group/t/how-to-exponentiate-an-operator-and-calculate-expectation-of-multiple-operators-in-itensor-julia/846/1 "2023-05-10T13:23:42Z")

</div>

Hi !  
I am trying to calculate the quantity given by:  
O\_{str}=-\langle z\_{i}e^{i\frac{\pi}{2}\sum\_{k=3}^{L-2}z\_{k}}z\_{j}\rangle  
where z = 1-2c^{\dagger}c here c is the fermionic operator. I have tried a lot but could not develop a suitable julia code. This quantity, widely known as string order parameter, in literature and its calculation is crucial for my work. For your reference you can look at H. Tasaki, Phys. Rev. Lett. 66, 798 (1991).  
41 K. Hida, Phys. Rev. B 45, 2207 (1992).  
Kindly help

---

<div class="post-metadata">

**Author:** ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)\
**Post date:** [May 11, 2023, 1:10pm UTC](https://itensor.discourse.group/t/how-to-exponentiate-an-operator-and-calculate-expectation-of-multiple-operators-in-itensor-julia/846/2 "2023-05-11T13:10:33Z")

</div>

Your z looks awfully like the [S\_z operator](https://itensor.github.io/ITensors.jl/dev/examples/Physics.html). Can you do e^{i\pi/2 \sum z\_k}=\prod\_k e^{i \pi/2 z\_k} and apply these as one site operators? The form of e^{i \pi/2 z\_k} should be able to be derived analytically even. Then you can apply them manually or form a custom MPO.

---

<div class="post-metadata">

**Author:** ![Aditya214](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/aditya214/32/231_2.png) [@Aditya214](https://itensor.discourse.group/u/Aditya214)\
**Post date:** [May 12, 2023, 7:14pm UTC](https://itensor.discourse.group/t/how-to-exponentiate-an-operator-and-calculate-expectation-of-multiple-operators-in-itensor-julia/846/3 "2023-05-12T19:14:32Z")

</div>

Hey thanks for your response. Could you please share the code to exponentiate z and multiply it and convert it to MPO?

---

<div class="post-metadata">

**Author:** ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)\
**Post date:** [May 15, 2023, 11:56am UTC](https://itensor.discourse.group/t/how-to-exponentiate-an-operator-and-calculate-expectation-of-multiple-operators-in-itensor-julia/846/4 "2023-05-15T11:56:30Z")

</div>

If you don’t want to work it out by hand, you can do something like `exp(im*pi/2*op("Sz",sites[1]))`. Then check out how to [apply a list of gates here](https://itensor.github.io/ITensors.jl/stable/tutorials/MPSTimeEvolution.html). This will scale as the distance between i and j.

For making an MPO, you can make a list of operators starting with the identity (`O_ops = [op("I",sites[i]) for i=1:L]`), modify any of these to be the operators of your O\_{str}, then make an MPO via `O = MPO(O_ops)`. This will scale as L however so I’m not sure its the best. There may be a better way to do this though (maybe with [correlators](https://github.com/ITensor/ITensorCorrelators.jl)?)
