CPU Performance Please, help me to understand the mathematics behind the following formula of CPI. Why do we calculate CPI the way it's done on the pic? The formula reminds me the expected value from stochastic, but do we have a random value here? 

 A: Yes, there is a random value, the number of cycles per instruction (CPI).
As you rightly note, we are indeed calculating its expected value, with the distribution given by the table in 1).
This can be rephrased and presented as follows:

The probability that an instruction needs 1 clock cycle is 0.35, that
  it needs 2 is 0.4 (0.25 + 0.15) and that it needs 3 is 0.25.
  What is the expected number of cycles needed per instruction?

Which should perhaps be more familiar to you.
A: This seems to be calculating the average number of CPU cycles per operation. There are a variety of operations that occur in different relative amounts, so you must weight the cost of an operation with its relative frequency of occurrence.
If all operations occurred with equal frequency, you would just average the cycle counts. But some are more frequent than others, so they contribute more to the weighted average.
A: I will explain with a simple example.
Suppose that you have $100$ random operations, then on average:


*

*$35$ of them are ALU    operations, each one taking 1 clock cycle

*$25$ of them are Load   operations, each one taking 2 clock cycles

*$15$ of them are Store  operations, each one taking 2 clock cycles

*$25$ of them are Branch operations, each one taking 3 clock cycles


The average number of clock cycles per operation is therefore:
$$\frac{35\cdot1+25\cdot2+15\cdot2+25\cdot3}{100}$$
Which is equivalent to the formula given in your question:
$$0.35\cdot1+0.25\cdot2+0.15\cdot2+0.25\cdot3$$
