# exponential operator

**URL:** <https://itensor.discourse.group/t/exponential-operator/585>\
**Category:** ITensor Julia Questions\
**Tags:** julia, mpo\
**Created:** [January 9, 2023, 10:11pm UTC](https://itensor.discourse.group/t/exponential-operator/585 "2023-01-09T22:11:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![asing](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@asing](https://itensor.discourse.group/u/asing)\
**Post date:** [January 9, 2023, 10:11pm UTC](https://itensor.discourse.group/t/exponential-operator/585/1 "2023-01-09T22:11:03Z")

</div>

I wish to calculate the expectation value of the following operator:

\hat{O} = e^{i \pi (S^x\_1 + S^y\_2 + S^z\_3)}

I am trying to do this in the following way

```julia
s1 = Op("Sx",1)
s2 = Op("Sy",2)
s3 = Op("Sz",3)

O = Prod{Op}()
O *= exp(im*pi*s1)
O *= exp(im*pi*s2)
O *= exp(im*pi*s3)
K = MPO(W,sites)
#for some MPS psi
l = real(inner(psi, apply(K, psi)))

```

But I keep getting error:

```auto
LoadError: MethodError: no method matching MPO(::ITensors.LazyApply.Exp{Scaled{ComplexF64, Op}}, ::Vector{Index{Int64}})

```

---

<div class="post-metadata">

**Author:** ![asing](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@asing](https://itensor.discourse.group/u/asing)\
**Post date:** [January 12, 2023, 4:23pm UTC](https://itensor.discourse.group/t/exponential-operator/585/2 "2023-01-12T16:23:41Z")

</div>

I tried a way around this by not converting exp(Op) to an MPO and just use it as an operator.

```auto
 ex1 = exp(im*pi*op("Sx",sites, 1))
 ey2 = exp(im*pi*op("Sy",sites, 2))
 ez3 = exp(im*pi*op("Sz",sites, 3))
 ez = ex1*ey2*ez3
 l = real(inner(psi, apply(ez, psi)))

```

The preliminary check seems to give the right answer, it might be a bit slow though.  
Kindly correct me if you find an error.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [January 19, 2023, 3:51pm UTC](https://itensor.discourse.group/t/exponential-operator/585/3 "2023-01-19T15:51:21Z")

</div>

That’s the best way to do that right now and what I would have suggested. In principle we could make the first one work but it would get very complicated getting general algebraic expressions to work in the `MPO` construction (it is already complicated enough with the current system of just supporting sums of products of operators).

---

<div class="post-metadata">

**Author:** ![asing](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@asing](https://itensor.discourse.group/u/asing)\
**Post date:** [January 19, 2023, 4:01pm UTC](https://itensor.discourse.group/t/exponential-operator/585/4 "2023-01-19T16:01:22Z")

</div>

Thank you for your reply. I had tested the second method for S=1/2. However, when I am performing the same calculation for S=1, the memory requirement is increasing drastically. I am providing 200Gb memory for the calculation S=1, which doesn’t seem to be enough. I had provided 100gb for S=1/2 system for the same system size and it had worked without any error.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [January 19, 2023, 9:31pm UTC](https://itensor.discourse.group/t/exponential-operator/585/5 "2023-01-19T21:31:58Z")

</div>

Maybe instead of contracting the tensors like this:

> [@asing](#):
>
> ` ez = ex1*ey2*ez3`

you meant to put them into an MPO like this:

```julia
 ez = MPO([ex1, ey2, ez3])

```

or you can put them into a list of gates and apply them like this:

```julia
apply([ex1, ey2, ez3], psi)

```

It really depends on what operations you are interested in. I assume you mean that it runs out of memory if you try to use larger system sizes, since I doubt you could be using that much memory with a system of just 3 sites.

---

<div class="post-metadata">

**Author:** ![asing](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@asing](https://itensor.discourse.group/u/asing)\
**Post date:** [January 20, 2023, 5:03pm UTC](https://itensor.discourse.group/t/exponential-operator/585/6 "2023-01-20T17:03:59Z")

</div>

Using it like the following way worked:

> [@mtfishman](#):
>
> `apply([ex1, ey2, ez3], psi)`

I am indeed using it for larger system sizes, so the way I was using it was creating some issues with memory.
