Probability Distributions

Computing State Vector of Probability Distributions

Published on September 11, 2026

Computing State Vector of Probability Distributions

In this article, we will show how we can derive a generic circuit for probability distribution functions. Let a quantum system be described by the state

Ψ=a0+b1|\Psi\rangle = a|0\rangle + b|1\rangle

According the quantum theory, if we measure this system, we can find it in state 0\|0\rangle with probability a2\|a\|^2 and in state 1\|1\rangle with probability b2\|b\|^2, where aa and bb are complex numbers and a2+b2=1\|a\|^2 + \|b\|^2 = 1.

Suppose aa and bb are real numbers, f(x)f(x) a probability distribution with x=0,1x=\\{0,1\\} and f(0)=a2f(0) = a^2 and f(1)=b2f(1) = b^2, then we can write Ψ\|\Psi\rangle as

Ψ=f(0)0+f(1)1|\Psi\rangle = \sqrt{f(0)}|0\rangle + \sqrt{f(1)}|1\rangle

In general, if we have nn qubits and the domain of f(x)f(x) is 0,1,2,2n10,1,2,\ldots 2^n-1, then we can write Ψ\|\Psi\rangle as

Ψ=x=02n1f(x)x|\Psi\rangle = \sum_{x=0}^{2^n-1} \sqrt{f(x)}|x\rangle

If the distribution is continuous, we will need to discretize it and map it to the intervals generated by nn qubits. We will show this later in the example on Lognormal distribution.

Probability Distributions on 2-Qubits

If we have two qubits, then the following table summarizes the possibilities:

q1q0010000111011\begin{array}{cccc} q_1\downarrow & q_0\rightarrow & 0 & 1 \\ 0 & & 00 & 01 \\ 1 & & 10 & 11 \end{array}

Let P0P_0 be the probability of the first qubit to have a value of 0 and P1P_1 be the probability of the first qubit to have a value of 1. Then according to the above table

P0=P00+P10P1=P01+P11\begin{array}{rl} P_0 &= P_{00} + P_{10} \\ P_1 &= P_{01} + P_{11} \end{array}

where PijP_{ij} is the probability of getting the state ij\|ij\rangle.

Define the following

f(0)=P00f(1)=P01f(2)=P10f(3)=P11\begin{array}{rl} f(0) &= P_{00}\\ f(1) &= P_{01}\\ f(2) &= P_{10}\\ f(3) &= P_{11} \end{array}

Then we can write the probability distribution for this system as:

Ψ=P0000+P0101+P1010+P1111\begin{array}{rl} |\Psi\rangle &= \sqrt{P_{00}}|00\rangle + \sqrt{P_{01}}|01\rangle + \sqrt{P_{10}}|10\rangle + \sqrt{P_{11}}|11\rangle \end{array}

Deriving the Circuit

We will now derive a circuit for this probability distribution. We are going to use the RY(θ)RY(\theta) gate defined by

RY(θ)=(cos(θ/2)sin(θ/2)sin(θ/2)cos(θ/2))RY(\theta) = \left( \begin{array}{cc} \cos(\theta/2) & -\sin(\theta/2)\\ \sin(\theta/2) & \cos(\theta/2) \end{array} \right)

The action of RY(θ)RY(\theta) on the state 0\|0\rangle is

RY(θ)=(cos(θ2)sin(θ2)sin(θ2)cos(θ2))(10)=cos(θ2)0+sin(θ2)1RY(\theta) = \left( \begin{array}{cc} \cos(\frac{\theta}{2}) & -\sin(\frac{\theta}{2})\\ \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) \end{array} \right)\left( \begin{array}{c} 1\\ 0 \end{array} \right) = \cos(\frac{\theta}{2}) |0\rangle + \sin(\frac{\theta}{2})|1\rangle

Now that we have defined the RY(θ)RY(\theta) gate, let's define the following mappings:

P0=cos(θ0)\sqrt{P_0} = \cos(\theta_0)

From this we have

P0=cos2(θ0)=1sin2(θ0)1P0=sin2(θ0)P1=sin2(θ0)\begin{array}{rl} P_0 &= \cos^2(\theta_0)\\ &= 1-\sin^2(\theta_0)\\ 1-P_0 &= \sin^2(\theta_0) \\ P_1 &= \sin^2(\theta_0) \\ \end{array}

Therefore

P1=sin(θ0)\sqrt{P_1} = \sin(\theta_0)

Furthermore,

P0=P00+P101=P00P0+P10P0\begin{align} P_0 &= P_{00} + P_{10} \\ 1 &= \frac{P_{00}}{P_0} + \frac{P_{10}}{P_0} \end{align}

If we define

P00P0=cosθ12\sqrt{\frac{P_{00}}{P_0}} = \cos\frac{\theta_1}{2}

then

1=P00P0+P01P0=cos2θ12+P01P0P01P0=1cos2θ12=sin2θ12\begin{align} 1 &= \frac{P_{00}}{P_0} + \frac{P_{01}}{P_0} \\ &= \cos^2\frac{\theta_1}{2} + \frac{P_{01}}{P_0}\\ \frac{P_{01}}{P_0} &= 1- \cos^2\frac{\theta_1}{2} = \sin^2\frac{\theta_1}{2} \end{align}

Therefore,

P01P0=sinθ12\sqrt{\frac{P_{01}}{P_0}} = \sin\frac{\theta_1}{2}

In the same manner, we have

P10P1=cosθ22P11P1=sinθ22\begin{align} \sqrt{\frac{P_{10}}{P_1}} &= \cos\frac{\theta_2}{2}\\ \sqrt{\frac{P_{11}}{P_1}} &= \sin\frac{\theta_2}{2} \end{align}

Now we can write our probability distribution as:

Ψ=P0P00P000+P0P01P001+P1P10P110+P11P11P1111|\Psi\rangle = \sqrt{P_0}\sqrt{\frac{P_{00}}{P_0}}|00\rangle + \sqrt{P_0}\sqrt{\frac{P_{01}}{P_0}}|01\rangle + \sqrt{P_1}\sqrt{\frac{P_{10}}{P_1}}|10\rangle + \sqrt{P_{11}}\sqrt{\frac{P_{11}}{P_{11}}}|11\rangle

Subsituting the values we derived earlier, we get

=[cosθ02cosθ1200+cosθ02sinθ1201]+[sinθ02cosθ2210+sinθ02sinθ2211]\begin{array}{rl} =&\left[\cos \frac{\theta_0}{2} \cos \frac{\theta_1}{2}|0\rangle|0\rangle + \cos\frac{\theta_0}{2}\sin\frac{\theta_1}{2}|0\rangle|1\rangle \right] + \underbrace{\left[\sin\frac{\theta_0}{2}\cos\frac{\theta_2}{2}|1\rangle|0\rangle + \sin\frac{\theta_0}{2}\sin\frac{\theta_2}{2}|1\rangle|1\rangle \right]}\\ \end{array}

The term in the underbrace can be factored to get

=[cosθ02cosθ1200+cosθ02sinθ1201]+sinθ021[cosθ220+sinθ221]=\left[\cos \frac{\theta_0}{2} \cos \frac{\theta_1}{2}|0\rangle|0\rangle + \cos\frac{\theta_0}{2}\sin\frac{\theta_1}{2}|0\rangle|1\rangle \right] + \sin\frac{\theta_0}{2}|1\rangle\underbrace{\left[\cos\frac{\theta_2}{2}|0\rangle + \sin\frac{\theta_2}{2}|1\rangle \right]}\\

We can recognize that the term in the underbrace is the result of apply RY(θ2)RY(\theta_2) to 0\|0\rangle

=[cosθ02cosθ1200+cosθ02sinθ1201]+sinθ021RY(θ2)0=\left[\cos \frac{\theta_0}{2} \cos \frac{\theta_1}{2}|0\rangle|0\rangle + \cos\frac{\theta_0}{2}\sin\frac{\theta_1}{2}|0\rangle|1\rangle \right] + \sin\frac{\theta_0}{2}|1\rangle\otimes RY(\theta_2)|0\rangle\\

We can factor out the RY(θ)2)RY(\theta)2) as a controlled RY(θ2)RY(\theta_2) gate:

=CRY(θ2)[cosθ02cosθ1200+cosθ02sinθ1201+sinθ0210]\begin{array}{rl} =&\mathrm{CRY}(\theta_2) \left[\cos \frac{\theta_0}{2} \cos \frac{\theta_1}{2}|0\rangle|0\rangle + \cos\frac{\theta_0}{2}\sin\frac{\theta_1}{2}|0\rangle|1\rangle + \sin\frac{\theta_0}{2}|1\rangle|0\rangle \right] \\ \end{array}

We can factor the terms in the underbrace to expose an RYRY gate:

=CRY(θ2)[cosθ02cosθ1200+cosθ02sinθ1201+sinθ0210]=CRY(θ2)[cosθ020(cosθ120+sinθ121)+sinθ0210]=CRY(θ2)[cosθ020RY(θ1)0+sinθ0210]\begin{array}{rl} =&\mathrm{CRY}(\theta_2) \left[\underbrace{\cos \frac{\theta_0}{2} \cos \frac{\theta_1}{2}|0\rangle|0\rangle + \cos\frac{\theta_0}{2}\sin\frac{\theta_1}{2}|0\rangle|1\rangle} + \sin\frac{\theta_0}{2}|1\rangle|0\rangle \right] \\ =&\mathrm{CRY}(\theta_2) \left[\cos \frac{\theta_0}{2} |0\rangle\left(\underbrace{\cos \frac{\theta_1}{2}|0\rangle + \sin\frac{\theta_1}{2}|1\rangle}\right) + \sin\frac{\theta_0}{2}|1\rangle|0\rangle \right] \\ =&\mathrm{CRY}(\theta_2) \left[\cos \frac{\theta_0}{2} |0\rangle\otimes RY(\theta_1)|0\rangle + \sin\frac{\theta_0}{2}|1\rangle|0\rangle \right] \\ \end{array}

Notice that we can factor this RYRY gate as a controlled RYRY gate if we first flip the first qubits:

=CRY(θ2)XI[cosθ021RY(θ1)0+sinθ0200]=CRY(θ2)XICRY(θ1)[cosθ0210+sinθ0200]\begin{array}{rl} =&\mathrm{CRY}(\theta_2) \cdot X\otimes I \cdot \left[\cos \frac{\theta_0}{2} |1\rangle\otimes RY(\theta_1)|0\rangle + \sin\frac{\theta_0}{2}|0\rangle|0\rangle \right] \\ =&\mathrm{CRY}(\theta_2) \cdot X\otimes I \cdot \mathrm{CRY}(\theta_1) \left[\underbrace{\cos \frac{\theta_0}{2} |1\rangle|0\rangle + \sin\frac{\theta_0}{2}|0\rangle|0\rangle} \right] \\ \end{array}

We can factor out the righmost 0\|0\rangle qubit in the underbrace

=CRY(θ2)XICRY(θ1)[(cosθ021+sinθ020)0]\begin{array}{rl} =&\mathrm{CRY}(\theta_2) \cdot X\otimes I \cdot \mathrm{CRY}(\theta_1) \left[\left(\underbrace{\cos \frac{\theta_0}{2} |1\rangle + \sin\frac{\theta_0}{2}|0\rangle}\right) |0\rangle\right] \\ \end{array}

The terms in the underbrace looks like a RYRY gate but we have to flip the qubits first by adding the gate XIX\otimes I

=CRY(θ2)XICRY(θ1)XI[(cosθ020+sinθ021)0]\begin{array}{rl} =&\mathrm{CRY}(\theta_2) \cdot X\otimes I \cdot \mathrm{CRY}(\theta_1)\cdot X\otimes I \left[\left(\underbrace{\cos \frac{\theta_0}{2} |0\rangle + \sin\frac{\theta_0}{2}|1\rangle}\right) |0\rangle\right] \\ \end{array}

Finally, we have derived the gate for a two qubit probability distribution:

=CRY(θ2)XICRY(θ1)XI[(RY(θ0)0)0]=CRY(θ2)XICRY(θ1)XIRY(θ0)00\begin{array}{rl} =&\mathrm{CRY}(\theta_2) \cdot X\otimes I \cdot \mathrm{CRY}(\theta_1)\cdot X\otimes I \left[\left(\underbrace{RY(\theta_0)|0\rangle}\right) |0\rangle\right] \\ =&\mathrm{CRY}(\theta_2) \cdot X\otimes I \cdot \mathrm{CRY}(\theta_1)\cdot X\otimes I \cdot RY(\theta_0)|0\rangle |0\rangle\\ \end{array}
# Import the Qiskit SDK from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister from qiskit import execute, Aer import numpy as np # Create the input Quantum Register with 2 qubits. qin = QuantumRegister(2) # Create a Classical Register with 2 bits that will hold the result of the measurement c = ClassicalRegister(2) # Create the Quantum Circuit qc = QuantumCircuit(qin,c) # compute the angles P00=<input> P01=<input> P10=<input> P11=<input> P0=P00+P10 P1=P01+P11 theta0 = 2*np.arccos(np.sqrt(P0)) theta1 = 2*np.arccos(np.sqrt(P00/P0)) theta2 = 2*np.arccos(np.sqrt(P01/P0)) print(theta0) print(theta1) print(theta2) # Implement the circuit qc.ry(theta0, qin[0]) qc.x(qin[0]) qc.cry(theta1,qin[0],qin[1]) qc.x(qin[0]) qc.cry(theta2,qin[0],qin[1]) qc.barrier() # Measure and draw qc.measure(qin,c) qc.draw(output='mpl',interactive=True)

Here is how the circuit will look like:

Example: Uniform Distribution

A 2-qubit system will allow us to create 4-bins. Since this is uniform distribution, each bin will have the same probability of occuring, that is

Pij=1/4P_{ij} = 1/4

for all i,j0,1i,j \in \\{0,1\\}

This means that

P0=P00+P10=0.5P1=P01+P11=0.5P00=0.25P01=0.25\begin{align} P_0 &= P_{00}+P_{10} = 0.5\\ P_1 &= P_{01}+P_{11} = 0.5\\ P_{00} &= 0.25\\ P_{01} &= 0.25 \end{align}

Plugging in these values in the above code and simulating we get:

Example: Sum of Quantum 2-dice

Suppose we have 2 dice with each die having 2 faces whose value can be 0 or 1. We throw the dice and examine the face that shows when they land. Whatever is the value, we take the sum. The question is what value of the sum is most probable?

We can tabulate the possible sums of 2-dices as follows where the values of the sum correspond to their binary representation.

010000110110\begin{array}{|r|r|l|}\hline & 0 & 1 \\\hline 0 & 00 & 01 \\\hline 1 & 01 & 10 \\\hline \end{array}

For example, if die 1 and die 2 come up as 1 and 1, then the sum is equal to 2 which is 10 in binary.

From the table above, we can compute the following probabilities:

P00=0.25P01=0.5P10=0.25P0=P00+P01=0.25+0.25=0.5P1=P01+P11=0.5+0\begin{array}{rl} P_{00} &= 0.25\\ P_{01} &= 0.5 \\ P_{10} &= 0.25 \\ P_0 &= P_{00} + P_{01} = 0.25 + 0.25 = 0.5\\ P_1 &= P_{01} + P_{11} = 0.5 + 0 \end{array}

Note: There is no value = 11, so P11=0P_{11} = 0.

Example: LogNormal Distribution

The lognormal distribution is defined as

f(x)=1xσ2πexp((lnxμ)22σ2)f(x) = \frac{1}{x\sigma\sqrt{2\pi}}\exp\left(-\frac{(\ln x - \mu)^2}{2\sigma^2}\right)

where μ\mu is the mean and σ2\sigma^2 is the variance.

Using values μ=0\mu=0 and σ=1\sigma=1, create 4 bins with the following boundaries 0,0.25,0.5,0.75,1.00, 0.25, 0.5, 0.75, 1.0 and get the probabilities from the lognormal cumulative distribution for each bin. The following are the probabilities:

P00=0.1656570P01=0.3225602P10=0.2853729P11=0.2264099\begin{align} P_{00}&=0.1656570 \\ P_{01}&=0.3225602 \\ P_{10}&=0.2853729 \\ P_{11}&=0.2264099 \end{align}

We have learned how to derive a generic 2-qubit circuit for a probability distribution. We validated the circuit using the uniform distribution and it is what we expected it to be. We have also shown the simulation for 2 other distributions. A challenge is to derive the circuit for a 3-qubit system, and for an n-qubit system. The number of gates is expected to be exponential on the number of qubits. That would be a further challenge for the interested person.

Image Credit: "From Above (Explored)" by Derek Giovanni Photography is licensed under CC BY-NC-ND 2.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-nd-nc/2.0/jp/?ref=openverse.