# Applying dag on subset of indices

**URL:** <https://itensor.discourse.group/t/applying-dag-on-subset-of-indices/631>\
**Category:** ITensor Julia Questions\
**Tags:** julia\
**Created:** [February 8, 2023, 4:18am UTC](https://itensor.discourse.group/t/applying-dag-on-subset-of-indices/631 "2023-02-08T04:18:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![apateonas](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/apateonas/32/101_2.png) [@apateonas](https://itensor.discourse.group/u/apateonas)\
**Post date:** [February 8, 2023, 4:18am UTC](https://itensor.discourse.group/t/applying-dag-on-subset-of-indices/631/1 "2023-02-08T04:18:50Z")

</div>

Hello,

I am working with Kraus operators in ITensor, and would like to apply `dag` only to the site legs of a Kraus tensor, and not on the virtual index, to implement the following:

\sum\_i K\_i \rho K\_i^\dagger

Is there a good way to do this with the ITensor library? I thought there could be something like `dag(K, oninds=listofinds)` or `dag(K, ignoreids=virtualidx)`.

Thank you!

---

<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:** [February 8, 2023, 2:46pm UTC](https://itensor.discourse.group/t/applying-dag-on-subset-of-indices/631/2 "2023-02-08T14:46:40Z")

</div>

Take a look at the `apply`/`product` function, the docstring should help:

```julia
julia> using ITensors

julia> ?

help?> product
[...]

```

EDIT: I noticed the docstring doesn’t cover the keyword argument `apply_dag`, if you do `product(A, B; apply_dag=true)` or `apply(A, B; apply_dag=true)` it performs what would be comparable to the linear algebra operation ABA^{\dagger} treating the ITensors A and B as matrices from the primed to the unprimed site/external indices.

---

<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:** [February 8, 2023, 2:47pm UTC](https://itensor.discourse.group/t/applying-dag-on-subset-of-indices/631/3 "2023-02-08T14:47:22Z")

</div>

Also PastaQ.jl may be useful: [https://github.com/GTorlai/PastaQ.jl](https://github.com/GTorlai/PastaQ.jl)

---

<div class="post-metadata">

**Author:** ![apateonas](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/apateonas/32/101_2.png) [@apateonas](https://itensor.discourse.group/u/apateonas)\
**Post date:** [February 9, 2023, 6:32am UTC](https://itensor.discourse.group/t/applying-dag-on-subset-of-indices/631/4 "2023-02-09T06:32:32Z")

</div>

Thank you for the reply! I got `apply` to work for the quantum channel \rho' = \sum\_i K\_i \rho K\_i^\dagger. However, `apply` does not allow me to express the completeness condition \sum\_i K\_i^\dagger K\_i = I, since that would require running `apply(Kdag, `\delta`(...), apply_dag=true)`, and I do not have `Kdag`. Do you have any suggestions for this case? It is also inconvenient to have to include the \delta`(...)`.

---

<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:** [February 9, 2023, 5:45pm UTC](https://itensor.discourse.group/t/applying-dag-on-subset-of-indices/631/5 "2023-02-09T17:45:46Z")

</div>

What about `Kdag = swapprime(dag(K), 0 => 1)`?

---

<div class="post-metadata">

**Author:** ![apateonas](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/apateonas/32/101_2.png) [@apateonas](https://itensor.discourse.group/u/apateonas)\
**Post date:** [February 10, 2023, 6:17am UTC](https://itensor.discourse.group/t/applying-dag-on-subset-of-indices/631/6 "2023-02-10T06:17:58Z")

</div>

Thank you for the tip. This seems to work, though I have to contract the result with δ(krausidx, prime(krausidx)) to unprime the virtual index that is being summed over. Ideally, there would be a kwarg for `dag` to list indices to not dag on.
