# List manipulation, averaging over lists and fidelity

I want to create vectors from a function poly[α_, β_, δ_, ϕ1_] were several variables (α, β, δ) are randomly sampled from a unit sphere. Then I want to vary another parameter of the function (ϕ1) over a specific range.

So I will end up with many vectors from poly[α, β, δ, ϕ1]. I want to find the fidelity (modulus of the inner product of two vectors squared) of the function poly[α, β, δ, ϕ1] with poly[α, β, -δ, 0] for each of these vectors.

Then I want to average the fidelity for each different instance of ϕ1.

So I can create a graph Δϕ1 vs Fidelity

So far I believe that I have gotten 80% of the way there, I have created the random input states and varied over ϕ1, but I am struggling in list manipulation to find the fidelities and average over them.

Any help would be greatly appreciated.

Function:

poly[α_, β_, δ_, ϕ1_] := { α (Cos[theta1] Cos[theta2] Cos[theta3] -
Sin[theta1] Sin[theta3]), β E^(I ϕ1) (-Cos[theta1] Cos[theta2]^2 Cos[theta3] + Cos[theta1] Cos[theta3] Sin[theta2]^2 +
Cos[theta2] Sin[theta1] Sin[theta3]), δ E^(2 I ϕ1) (
Cos[theta1] Cos[theta2]^3 Cos[theta3] -
2 Cos[theta1] Cos[theta2] Cos[theta3] Sin[theta2]^2 -
Cos[theta2]^2 Sin[theta1] Sin[theta3])};

theta1 = -2.74889;
theta2 = -1.14372;
theta3 = 2.74889;


Calculate the random input states:

random = {};

n = 10; (*Number of input states for α, β, δ*)

Do[

list = ({1, I}.#) & /@
Partition[Normalize@RandomVariate[NormalDistribution[], 2 3], 2];

α = list[[1]];
β = list[[2]];
δ = list[[3]];

AppendTo[random, {list}];

, {n}];

random;


Collect all α, β, δ terms in lists

cat = Flatten[random];
α = cat[[1 ;; All ;; 3]];
β = cat[[2 ;; All ;; 3]];
δ = cat[[3 ;; All ;; 3]];


Vary ϕ1 to obtain various α, β, δ

start = 0;
end = 1;
increment = 1;
total = 1 + (end - start)/increment ;

offset = Flatten[Table[poly[α, β, δ, ϕ1], {ϕ1, start, end, increment}]] ;


Create an ideal list of α, β, δ with the same dimensions of offset:

ideal2 = Flatten[poly[α, β, -δ, 0]];
ideal3 = Flatten[Table[ideal2, total]];

• I'm not sure what the question is, but you can shorten parts of your code quite a bit. If you want to get a uniform sample of points in the unit sphere, a quicker way to do it would be random = RandomPoint[Ball[], n] + I RandomPoint[Ball[], n]; Then you can define {α, β, δ} = Transpose[random] – Jason B. Apr 22 '16 at 12:34
• Please, just post the essential to understand what you are asking and define things like fidelity for example. – jonaprieto Apr 28 '16 at 16:36