Lets say I have a Bloch sphere, where I can represent states as

  • $|0\rangle$ or $|1\rangle$ in the Z basis,
  • $|+\rangle$ or $|-\rangle$ in the X basis, or
  • $|+i\rangle$ or $|-i\rangle$ in the Y basis

Here you can think of the X and Y states as superpositions with a complex phase of the first two {0,1} states.

If I was in the 2D case where I only consider the Z,X basis', then it's conventent to be able to write a Mathematica state as:

$|\Phi (\theta \_)\rangle \text{:=}|1\rangle \sin \left(\frac{\theta }{2}\right)+|0\rangle \cos \left(\frac{\theta }{2}\right)$

Ket[Φ (θ_)] :=  Cos[θ/2] Ket[0] + Sin[θ/2] Ket[1]

This works fine, and use it functionally, ie. $|\Phi\left(\frac{\pi }{4}\right)\rangle$, or Ket[\[CapitalPhi] (\[Pi]/4)] gives back the state as I want it, $|1\rangle \sin \left(\frac{\pi }{8}\right)+|0\rangle \cos \left(\frac{\pi }{8}\right)$.

However, when trying to expand to include the third Y basis, the functional form doesn't seem to be able to be defined in the same way, ie:

$|\psi(\phi \_,\theta \_)\rangle \text{:=}|0\rangle \cos \left(\frac{\theta }{2}\right)+|1\rangle e^{i \phi } \sin \left(\frac{\theta }{2}\right);$

Ket[ψ (ϕ_, θ_)] := Cos[θ/2] Ket[0] + E^(I ϕ) Sin[θ/2] Ket[1];

How can I allow this functional ket to take two arguments?

Note, I have found how you can define operations between these states, which is extremely useful notation!

  • $\begingroup$ I would define \[Psi][\[Phi]_, \[Theta]_] = Cos[\[Theta]/2] Ket[0] + E^(I \[Phi]) Sin[\[Theta]/2] Ket[1] (and similarly for the other case). $\endgroup$ May 22, 2018 at 8:54
  • $\begingroup$ Yes, I think this is actually what I meant haha - but for some reason the curly brackets still work for the singular case. Neither curly nor square brackets work for two variables. You can use the form \ket[\[Psi]] [\[Phi]_, \[Theta]_] = ... which I guess might be as close as I get? $\endgroup$
    – Mr G
    May 22, 2018 at 11:22
  • $\begingroup$ Ket[\[Psi][\[Phi]_, \[Theta]_]] := Cos[\[Theta]/2] Ket[0] + E^(I \[Phi]) Sin[\[Theta]/2] Ket[1] seems to work just fine for me. What problems are you having with that? Be sure to try it in a fresh kernel. $\endgroup$ May 22, 2018 at 15:23

1 Answer 1


The use of circular brackets is not the correct syntax for Mathematica functions.

Consequently, both forms,

$$|\psi[\phi\_,\theta\_]\rangle = \cos\left[\frac{\theta}{2}\right]|0\rangle + e^{i\phi}\sin\left[\frac{\theta}{2}\right]|1\rangle$$

\ket[\[Psi]] [\[Phi]_, \[Theta]_] = Cos[\[Theta]/2] Ket[0] + E^(I \[Phi]) Sin[\[Theta]/2] Ket[1] 


$$|\psi\rangle[\phi\_,\theta\_] = \cos\left[\frac{\theta}{2}\right]|0\rangle + e^{i\phi}\sin\left[\frac{\theta}{2}\right]|1\rangle$$

Ket[\[Psi][\[Phi]_, \[Theta]_]] := Cos[\[Theta]/2] Ket[0] + E^(I \[Phi]) Sin[\[Theta]/2] Ket[1] 

work fine for defining ket's as functional states.

Credit to @Sjoerd Smit and @b.gatessuck in comments.


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.