A tensor network is often clearly represented as a contraction graph, however, in programming, it is hard to represent a contraction graph.
- take leg, bond, tensor must be at least same priority as
prec-times
t ⧷ 3 # get the third leg of a tensor
l1 ∾ l2 # connect two legs, equivalent to tensordot
l1 ⊶ l2 # left canonical a bond
l1 ⊷ l2 # right canonical a bond
l1 ⪥ l2 # swap two legs, equivalent to swap axes.
(l1, l2, l3) ⪥ (l2, l1, l3) # permute legs
l1 ⋎ l2 ⋎ l3 # merge legs
l1 ∈ (4, 2) # split a leg into two of sizes (4, 2)
- contract two tensors
t3 = t1 ⧷ 3 ∾ t2 ⧷ 1
- multiply a vector on a dimension of tensor
(t ⧷ 3) *= v
# t1 ⌶ t2 # transfer matrix, desired but not allowed
t1[→] # t1 ⧷ <last axis>
t1[←] # t1 ⧷ 1
t1[↑] # t1 ⧷ 2 for both mps and mpo
t1[↓] # t1 ⧷ 3 for only mpo
t1 ⊂ (t2, [t3]) # contract from left (appear in inner product of MPS)
(t1, [t2]) ⊃ t3 # contract from right
t1 ⪽ (t2, O, [t3]) # contract with operator from left (appear in operator expectation of MPS)
(t1, O, [t2]) ⪾ t3 # contract with operator from right
mps ∘ 5 # 5th tensor, equivalent to mps[5]
# warning: voilation of guide rule!
mps ↑ 5 # 5th upward physical leg
mpo ↓ 5 # 5th downward physical leg of an mpo
mps ⨲ 5 # 5th virtual bond (a bond is a pair of legs)