Not summing over indices

Apologies for the (perhaps overly-simplistic) question, but it is just unclear to me what the most efficient & acceptable syntax is to perform a summation like the following: A_{ij} = \sum_n a_{in} b_{nj} c_{ij}
That is to say, I would like to NOT sum over i,j, even though I must specify their indices in order to perform the sum correctly. Thanks very much for the help!

1 Like

The recommended way of doing that with ITensor would be with delta/δ tensors:

julia> using ITensors

julia> i, j, n = Index.((2, 2, 2), ("i", "j", "n"));

julia> a = randomITensor(i', n);

julia> b = randomITensor(n, j');

julia> c = randomITensor(i'', j'');

julia> A = a * b * c * delta(i', i'', i) * delta(j', j'', j)
ITensor ord=2 (dim=2|id=353|"i") (dim=2|id=400|"j")
NDTensors.Dense{Float64, Vector{Float64}}

As far as I know, you can always rewrite expressions like the one you wrote as traditional einsum expressions (i.e. rewrite as a traditional tensor network expression either in terms of pairs of contracted indices or unique uncontracted indices) by making use of delta/copy tensors.

You can alternatively use δ as an alternative to delta:

julia> A = a * b * c * δ(i', i'', i) * δ(j', j'', j)
ITensor ord=2 (dim=2|id=353|"i") (dim=2|id=400|"j")
NDTensors.Dense{Float64, Vector{Float64}}

You can type δ in the Julia REPL with \delta[TAB], see The Julia REPL · The Julia Language, Unicode Input · The Julia Language, and for editor support see JuliaEditorSupport · GitHub.

2 Likes