+1 vote
asked by (590 points)

Hi,

I'm trying to compare two tensors of the same rank but different indices. For example, some thing like

auto T1 = ITensor(s1,prime(s1));
auto T2 = ITensor(s2,prime(s2));

//not implemented
cout<<norm(T1+ (-1*T2))<<endl;

Where I'd want to have s2 become s1 and s2' go to s1' prime and then (I assume) easily compare them using the norm. My specific use case is that these are Site type indices if that helps.

Is there a way to do this efficiently?

Thanks!

1 Answer

0 votes
answered by (70.1k points)
selected by
 
Best answer

Hi, good question. So first of all it's a good thing that ITensor throws an error here, because in a general case one shouldn't be able to add or subtract tensors with different indices.

But we've been needing a feature for a while that will conveniently replace indices with equivalent ones. A key use case would be making an operator once, then "sliding" it down a chain of sites.

So I added a function just now to ITensor called "reindex". Here is the documentation for it:
http://itensor.org/docs.cgi?page=classes/itensor#reindex

You can use it in your case by replacing T2 by reindex(T2,s2,s1) in your norm calculation. (Also no need for the separate -1*T2; it's ok to subtract ITensors, once they have the same indices.)

Best regards,
Miles

commented by (590 points)
Exactly what I was looking for, thanks!
Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...