State algebra
Several basic algebraic operations for states and operators.
Sources: dot.hpp · inner.hpp · norm.hpp
dot
Computes the dot product \(\langle v \vert w \rangle\) between two states \(\vert v \rangle\) and \(\vert w \rangle\). In C++, please use the dotC function if one of the two states is expected to be complex.
inner
Computes the expectation value \(\langle v | O |v \rangle\) of an operator \(O\) and a state \(|v\rangle\). The operator can either be an Op or an OpSum object. In C++, please use the innerC function if either the operator or the state are complex.
norm
Computes the 2-norm \(\parallel |v \rangle \parallel_2\) of a state \(|v \rangle\) defined as
where \(\{ |n\rangle \}\) denotes an orthonormal basis of the block.
norm1
Computes the 1-norm \(\parallel |v \rangle \parallel_1\) of a state \(|v \rangle\) defined as
where \(\{ |n\rangle \}\) denotes an orthonormal basis of the block.
norminf
Computes the \(\infty\)-norm \(\parallel |v \rangle \parallel_\infty\) of a state \(|v \rangle\) defined as
where \(\{ |n\rangle \}\) denotes an orthonormal basis of the block.
Usage Examples
let
N = 8
block = Spinhalf(N, N ÷ 2)
ops = OpSum()
for i in 1:N
ops += Op("SdotS", [i, mod1(i+1, N)])
end
e0, psi = eig0(ops, block);
@show norm(psi)
@show norm1(psi)
@show norminf(psi)
@show dot(psi, psi)
@show e0, inner(ops, psi)
phi = random_state(block)
display(vector(phi))
display(vector(psi))
display(vector(psi + 2.0*phi))
display(vector(psi*3.0im + phi/2.0))
end
int N = 8;
auto block = Spinhalf(N, N / 2);
auto ops = OpSum();
for (int i=0; i<N; ++i) {
ops += Op("SdotS", {i, (i+1)%N});
}
auto [e0, psi] = eig0(ops, block);
XDIAG_SHOW(norm(psi));
XDIAG_SHOW(norm1(psi));
XDIAG_SHOW(norminf(psi));
XDIAG_SHOW(dot(psi, psi));
XDIAG_SHOW(e0);
XDIAG_SHOW(inner(ops, psi));
auto phi = random_state(block);
XDIAG_SHOW(phi.vector());
XDIAG_SHOW(psi.vector());
XDIAG_SHOW((psi + 2.0*phi).vector());
XDIAG_SHOW((psi*complex(0,3.0) + phi/2.0).vectorC());