Need Help in Understanding expval() in class MeasureAll

Hi Quantum People,

I have a question about the expval() function that is used in the class MeasureAll. The line of code that I don’t understand is shown in the following figure.

Let’s ignore the batch size. So, probs is a vector [p0, p1] where p0 is the marginal probability of 0 and p1 is the marginal probability of 1. And observable.eigenvals is [1, -1] for PauliZ. Thus, res = [p0, p1] * [1, -1] = p0 - p1.

Question: what is the math meaning of doing And what is the physical meaning?

Thanks for your time,
Caitao Zhan

My question is resolved. It is the formula for calculating the expectation value of the Pauli Z operator. It is a measure of how much the probabilities are biased toward |0> and |1>.

|psi> = alpha |0> + beta |1>
<Z> = |alpha|^2 - |beta|^2

For more, see this wonderful lecture on Youtube from NYU Quantum: