# Compare two (same rank) tensors

+1 vote

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!

selected by

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!