Skip to content

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.

dot(v::State, w::State)
double dot(State const &v, State const &w);
complex dotC(State const &v, State const &w);

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.

inner(op::Op, v::State)
inner(ops::OpSum, v::State)
double inner(Op const &op, State const &v);
double inner(OpSum const &ops, State const &v);
complex innerC(Op const &op, State const &v);
complex innerC(OpSum const &ops, State const &v);

norm

Computes the 2-norm \(\parallel |v \rangle \parallel_2\) of a state \(|v \rangle\) defined as

\[ \parallel |v \rangle \parallel_2 = \sum_n |\langle n | v \rangle |^2, \]

where \(\{ |n\rangle \}\) denotes an orthonormal basis of the block.

norm(state::State)::Float64
double norm(State const &v);

norm1

Computes the 1-norm \(\parallel |v \rangle \parallel_1\) of a state \(|v \rangle\) defined as

\[ \parallel |v \rangle \parallel_1 = \sum_n |\langle n | v \rangle |, \]

where \(\{ |n\rangle \}\) denotes an orthonormal basis of the block.

norm1(state::State)::Float64
double norm1(State const &v);

norminf

Computes the \(\infty\)-norm \(\parallel |v \rangle \parallel_\infty\) of a state \(|v \rangle\) defined as

\[ \parallel |v \rangle \parallel_\infty = \max_n |\langle n | v \rangle |, \]

where \(\{ |n\rangle \}\) denotes an orthonormal basis of the block.

norminf(state::State)::Float64
double norminf(State const &v);

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());