Skip to content

apply

Applies an operator to a state \(\vert w \rangle = O \vert v\rangle\) or block of states \(\left( \vert w_1 \rangle \dots \vert w_M \rangle \right) = O \left( \vert v_1 \rangle \dots \vert v_M \rangle \right)\).

Source apply.hpp

apply(op::Op, v::State, w::State, precision::Float64 = 1e-12)
apply(ops::OpSum, v::State, w::State, precision::Float64 = 1e-12)
void apply(Op const &op, State const &v, State &w, double precision = 1e-12);
void apply(OpSum const &ops, State const &v, State &w, double precision = 1e-12);

The resulting state is handed as the third argument and is overwritten upon exit.

Parameters

Name Description
ops / op OpSum or Op defining the operator
v input state $\vert v\rangle $
w output state \(\vert w \rangle = O \vert v\rangle\)
precision precision with which checks for zero are performed (default \(10^{-12}\))

Usage Example

let 
    N = 8
    block = Spinhalf(N,  N ÷ 2)
    ops = OpSum()
    for i in 1:N
        ops += Op("HB", 1.0, [i, mod1(i+1, N)])
    end
    e0, psi = eig0(ops, block);

    blockp = Spinhalf(N,  N ÷ 2 + 1)
    phi = zeros(blockp)
    apply(Op("S+", 1.0, 2), psi, phi)
    @show inner(ops, psi)
    @show inner(ops, phi)
end
int N = 8;
auto block = Spinhalf(N,  N / 2);
auto ops = OpSum();
for (int i=0; i<N; ++i){
  ops += Op("HB", 1.0, {i, (i+1)%N});
}
auto [e0, psi] = eig0(ops, block);

auto blockp = Spinhalf(N,  N / 2 + 1);
auto phi = zeros(blockp);
apply(Op("S+", 1.0, 2), psi, phi);
XDIAG_SHOW(inner(ops, psi));
XDIAG_SHOW(inner(ops, phi));