|
3 | 3 |
|
4 | 4 | If an `index` is given, it assumes that `op` is defined in the subsystem specified by this number. |
5 | 5 | """ |
6 | | -function expect(indices, op::AbstractOperator{B1,B2}, state::AbstractOperator{B3,B3}) where {B1,B2,B3<:CompositeBasis} |
7 | | - N = length(state.basis_l.shape) |
8 | | - indices_ = complement(N, indices) |
9 | | - expect(op, ptrace(state, indices_)) |
10 | | -end |
| 6 | +expect(indices, op::AbstractOperator, state::AbstractOperator) = |
| 7 | + expect(op, ptrace(state, complement(nsubsystems(state), indices))) |
| 8 | + |
| 9 | +expect(index::Integer, op::AbstractOperator, state::AbstractOperator) = expect([index], op, state) |
11 | 10 |
|
12 | | -expect(index::Integer, op::AbstractOperator{B1,B2}, state::AbstractOperator{B3,B3}) where {B1,B2,B3<:CompositeBasis} = expect([index], op, state) |
13 | 11 | expect(op::AbstractOperator, states::Vector) = [expect(op, state) for state=states] |
| 12 | + |
14 | 13 | expect(indices, op::AbstractOperator, states::Vector) = [expect(indices, op, state) for state=states] |
15 | 14 |
|
16 | | -expect(op::AbstractOperator{B1,B2}, state::AbstractOperator{B2,B2}) where {B1,B2} = tr(op*state) |
| 15 | +expect(op::AbstractOperator, state::AbstractOperator) = |
| 16 | + (check_multiplicable(state, state); check_multiplicable(op,state); tr(op*state)) |
17 | 17 |
|
18 | 18 | """ |
19 | 19 | variance(index, op, state) |
20 | 20 |
|
21 | 21 | If an `index` is given, it assumes that `op` is defined in the subsystem specified by this number |
22 | 22 | """ |
23 | | -function variance(indices, op::AbstractOperator{B,B}, state::AbstractOperator{BC,BC}) where {B,BC<:CompositeBasis} |
24 | | - N = length(state.basis_l.shape) |
25 | | - indices_ = complement(N, indices) |
26 | | - variance(op, ptrace(state, indices_)) |
27 | | -end |
| 23 | +variance(indices, op::AbstractOperator, state::AbstractOperator) = |
| 24 | + variance(op, ptrace(state, complement(nsubsystems(state), indices))) |
| 25 | + |
| 26 | +variance(index::Integer, op::AbstractOperator, state::AbstractOperator) = variance([index], op, state) |
28 | 27 |
|
29 | | -variance(index::Integer, op::AbstractOperator{B,B}, state::AbstractOperator{BC,BC}) where {B,BC<:CompositeBasis} = variance([index], op, state) |
30 | 28 | variance(op::AbstractOperator, states::Vector) = [variance(op, state) for state=states] |
| 29 | + |
31 | 30 | variance(indices, op::AbstractOperator, states::Vector) = [variance(indices, op, state) for state=states] |
32 | 31 |
|
33 | | -function variance(op::AbstractOperator{B,B}, state::AbstractOperator{B,B}) where B |
34 | | - expect(op*op, state) - expect(op, state)^2 |
| 32 | +function variance(op::AbstractOperator, state::AbstractOperator) |
| 33 | + check_multiplicable(op,op) |
| 34 | + check_multiplicable(state,state) |
| 35 | + check_multiplicable(op,state) |
| 36 | + @compatiblebases expect(op*op, state) - expect(op, state)^2 |
35 | 37 | end |
0 commit comments