(* Mathematica code for the generation of mutually unbiased bases

based on

@article{Schwinger.60,
author = {Julian Schwinger},
title = {Unitary operators bases},
booktitle = {Proceedings of the National Academy of Sciences (PNAS)},
year = {1960},
volume = {46},
issue={4},
pages = {570-579},
url = {http://dx.doi.org/10.1073/pnas.46.4.570},
doi = {10.1073/pnas.46.4.570}
}

Created by Karl Svozil 2012
Revised 2014


*)



(* Definition of the Dyadic Product *)

DyadicProductVec[x_] :=
  Table[x[[i]] Conjugate[x[[j]]], {i, 1, Length[x]}, {j, 1,
    Length[x]}];

DyadicProduct2Vec[x_, y_] :=
  Table[x[[i]] Conjugate[y[[j]]], {i, 1, Length[x]}, {j, 1,
    Length[y]}];


(*Definition of some bases*)

BellBasis = (1/Sqrt[2]) {{1, 0, 0, 1}, {0, 1, 1, 0}, {0, 1, -1,
     0}, {1, 0, 0, -1}};


CartesianBasisNDim[N_] :=
  Table[Table[KroneckerDelta[i, j], {j, 1, N}], {i, 1, N}];

(*Unitary operator transform generated by two orthogonal bases \
{a[[i]]} and {b[[i]]}*)

UnitaryOperatorFromBases[a_, b_] :=
  Sum[DyadicProduct2Vec[a[[i]], b[[i]]], {i, 1, Length[a]}];


(*create shift-permuted basis from original one*)

ShiftPermutedBasis[a_] := Delete[Append[a, a[[1]]], 1];


(*Unitary operator generated by original and shift-permuted basis*)

UU[n_] :=
  UnitaryOperatorFromBases[CartesianBasisNDim[n],
   ShiftPermutedBasis[CartesianBasisNDim[n]]];

U[n_] := Table[UU[n][[i]]/Norm[UU[n][[i]]], {i, n}]

VV[n_] := Eigenvectors[U[n]];

V[n_] := Table[VV[n][[i]]/Norm[VV[n][[i]]], {i, n}];

V[2]


MatrixForm[FullSimplify[VV[8]]]

FullSimplify[(VV[8]).ConjugateTranspose[VV[8]]]
