# define more than two different sitetypes

**URL:** <https://itensor.discourse.group/t/define-more-than-two-different-sitetypes/458>\
**Category:** ITensor Julia Questions\
**Created:** [October 10, 2022, 8:04am UTC](https://itensor.discourse.group/t/define-more-than-two-different-sitetypes/458 "2022-10-10T08:04:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zz123](https://avatars.discourse-cdn.com/v4/letter/z/b5e925/32.png) [@zz123](https://itensor.discourse.group/u/zz123)\
**Post date:** [October 10, 2022, 8:04am UTC](https://itensor.discourse.group/t/define-more-than-two-different-sitetypes/458/1 "2022-10-10T08:04:18Z")

</div>

Hi! I’ve a quick question about defining three types of sites at different positions. Specifically, I’m trying to have 3N sites, with 1~N as Electron sites, N+1~2N as Spin1/2 sites, and 2N+1~3N also as Spin1/2 sites, because I want to use these to represent three chains. Currently, I only find cases with at most two types of sites, where the example use:

`sites=[isodd(n) ? siteind(...) : siteind(...) for n=1:2N]`

to separate two types of sites, and I’ve tried things like:

`sites=[isless(n-(N+1),0) ? siteind(...) : isless(0,n-N) & isless(n-(2*N+1),0) ?siteind(...) : isless(0,n-2N) & isless(n-(3*N+1),0) ?siteind(...) for n=1:3N]` , but it doesn’t work.  
Thanks you!

---

<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:** [October 10, 2022, 3:36pm UTC](https://itensor.discourse.group/t/define-more-than-two-different-sitetypes/458/2 "2022-10-10T15:36:10Z")

</div>

Thanks for the question. I think the key thing to understand about this topic is that all the constructs such as

```auto
sites=[isodd(n) ? siteind(...) : siteind(...) for n=1:2N]

```

are doing is making a Julia array with ITensor Index objects in certain locations. The site type information is just coming from the “tags” that the Index objects have, and `siteind` is nothing but a convenient way to make an Index object with certain tags (such as “Site,S=1/2”) and the right dimensions.

So my answer is that rather than using an array comprehension, which can get rather complicated for a case like yours, I would suggest just using a for loop, like this:

```auto
sites = Vector{Index}(undef,3N)
for j=1:N
  sites[j] = siteind("Electron")
end
for j=N+1:2N
  sites[j] = siteind("S=1/2")
end
for j=2N+1:3N
  sites[j] = siteind("S=1/2")
end

```

If you want to turn on quantum number conservation, you can just modify the calls to `siteind` above by passing keyword arguments such as `conserve_qns=true`.

---

<div class="post-metadata">

**Author:** ![zz123](https://avatars.discourse-cdn.com/v4/letter/z/b5e925/32.png) [@zz123](https://itensor.discourse.group/u/zz123)\
**Post date:** [October 11, 2022, 3:08am UTC](https://itensor.discourse.group/t/define-more-than-two-different-sitetypes/458/3 "2022-10-11T03:08:42Z")

</div>

I see. Thank you so much!
