3
$\begingroup$

Screenshot of code and some outputI have a Do loop where I generate quantum state equations <111||111>,<111||112>...<232||232>. This is 144 equations in total but I want both bra and kets to be seen as the same so that for example <121||111> is the same as <111||121> and only one of these is generated namely the <111||121> state. This would mean that when we move from <111| to the <112| bra we go straight to <112||112> rather than <112||111> so this would be 78 equations in total.

Here is the code for it is using the Quantum Notation Package I will also attach a screenshot of the code and some of its output for further clarity.

Do[Print[\!\(\*
TagBox[
RowBox[{"\[LeftAngleBracket]", 
TagBox[
RowBox[{
SubscriptBox["x", 
OverscriptBox["L", "^"]], ",", 
SubscriptBox["y", 
OverscriptBox["M", "^"]], ",", 
SubscriptBox["z", 
OverscriptBox["R", "^"]]}],
Quantum`Notation`zz080BraArgs,
BaseStyle->{ShowSyntaxStyles -> True},
Editable->True,
Selectable->True], "\[VerticalSeparator]"}],
Quantum`Notation`zz080Bra,
BaseStyle->{ShowSyntaxStyles -> False},
Editable->False,
Selectable->False]\) \!\(\*
TagBox[
RowBox[{"\[VerticalSeparator]", 
TagBox[
RowBox[{
SubscriptBox["i", 
OverscriptBox["L", "^"]], ",", 
SubscriptBox["j", 
OverscriptBox["M", "^"]], ",", 
SubscriptBox["k", 
OverscriptBox["R", "^"]]}],
Quantum`Notation`zz080KetArgs,
BaseStyle->{ShowSyntaxStyles -> True},
Editable->True,
Selectable->True], "\[RightAngleBracket]"}],
Quantum`Notation`zz080Ket,
BaseStyle->{ShowSyntaxStyles -> False},
Editable->False,
Selectable->False]\), {i, 1, 2}, {j, 1, 3}, {k, 1, 2}, {x, 1, 2}, {y, 
   1, 3}, {z, 1, 2}], {i, 2}, {j, 3}, {k, 2}, {x, 2}, {y, 3}, {z, 2}]
$\endgroup$
2
  • 1
    $\begingroup$ I'd suggest to use Subsets somehow... $\endgroup$ Commented Nov 26, 2021 at 18:23
  • 1
    $\begingroup$ @HenrikSchumacher Subsets won't give you the "squared" pairings, though. So you'd have to do something like Join[Subsets[states,{2}],Thread[{states,states}]] $\endgroup$
    – Hausdorff
    Commented Nov 26, 2021 at 18:37

3 Answers 3

3
$\begingroup$

Based on the suggestion of Henrik Schumacher, and the answers of Hausdorff and Daniel Huber, you can do it as follows:

 Format[braket[{{a_, b_, c_}, {d_, e_, f_}}]] := 
 Row[{"\[LeftAngleBracket]", 
   StringRiffle[{ToString[a], ToString[b], ToString[c]}], "|", "|", 
   StringRiffle[{ToString[d], ToString[e], ToString[f]}], 
   "\[RightAngleBracket]"}]

When we apply the function to all pairs of states, we obtain the following:

MapAt[braket, pairs, All]

enter image description here

Quantum Notation Package works well:

enter image description here

It's just the following:

Needs["Quantum`Notation`"]
Table[braket /. Thread[{a, b, c, d, e, f} -> Flatten@pairs[[i]]], {i, 1, Length[pairs]}]
$\endgroup$
1
  • 1
    $\begingroup$ Thanks for your answer. I am confused about the quantum notation part where you use "BraKetList3S['''']" this just outputs BraKetList3S[''''],{111},{112},etc. If you could provide some more clarity on this step that would be greatly appreciated. $\endgroup$
    – P5050
    Commented Nov 29, 2021 at 15:42
4
$\begingroup$

A more "Mathematica" way of generating your base states is via Tuples

states = Tuples[Range/@{2,3,2}]

To then get the independent pairings of states, you can use

pairs=Flatten[Table[states[[{i,j}]],{i,1,Length@states},{j,i,Length@states}],1];
{{{1, 1, 1}, {1, 1, 1}}, {{1, 1, 1}, {1, 1, 2}}, 
 {{1, 1, 1}, {1, 2, 1}}, {{1, 1, 1}, {1, 2, 2}},
 {{1, 1, 1}, {1, 3, 1}}, {{1, 1, 1}, {1, 3, 2}},
 {{1, 1, 1}, {2, 1, 1}}, {{1, 1, 1}, {2, 1, 2}},
  ...}
Length@pairs
(* 78 *)

Edit As suggested by Henrik Schumacher in the comments, you can also use Subsets here, for example via

pairs=Join[Subsets[states,{2}],Thread[{states,states}]]

Edit 2 Another fun method which generalizes more nicely to similar problems is interpreting the problem as obtaining all independent components of a symmetric two-tensor

pairs = states[[#]] & /@ 
  SymmetrizedIndependentComponents[ConstantArray[Length@states,2],Symmetric[{1,2}]]

Length @ pairs
(* 78 *)
$\endgroup$
1
$\begingroup$

Often a problem is easier, seen from another perspective.

You have different quantum states, specified by 3 integers. We may e.g. represent these as lists:

states=Flatten[Array[{#1, #2, #3} &, {3, 3, 3}], 2]

enter image description here

Now, you want bra-kets that are symmetrical, that is <a||b> and <b||a> are identified. Instetad of thinking in "bra-kets", think about it as tuples. You are looking for all tuples than can be assembled from our states. Here the command "Tuples" comes in handily:

tup=Tuples[states, 2];

Finally, we may change the representation back into the bra-ket form by::

tup /. {x1 : {__Integer}, x2 : {__Integer}} :> 
   Print["<" <> ToString /@ x1 <> "||" <> ToString /@ x2 <> ">"];

enter image description here

.......

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.