I've written the following code for simple quantum mechanics operators on spin states:

enter image description here

It seems to work, but the output could be better - how do I let Mathematics know that $0**\ 0==0$, and can I let it compress the up/down ket to have only the 2 arrows, not the "$**$" in between?

  • $\begingroup$ You can use Bra, Ket and you can Unprotect NonCommutativeMultiply. $\endgroup$
    – evanb
    May 8, 2015 at 23:13
  • $\begingroup$ Do you have details about Bra and Ket? I can't seem to find much documentation about these two in Mathematica's help itself... $\endgroup$
    – Frank
    May 9, 2015 at 3:41
  • $\begingroup$ Unfortunately, no. As far as I know they're Heads with no meaning (unless you give them meaning!) that simply render very nicely. $\endgroup$
    – evanb
    May 10, 2015 at 7:32

1 Answer 1


Unprotecting and giving meaning to ** (NonCommuntativeMultiply) will do the trick:

NonCommutativeMultiply[H___, 0, T___] := 0
  • $\begingroup$ Very nice! Didn't know that... thanks for the tip! $\endgroup$
    – Frank
    May 9, 2015 at 3:24

Your Answer

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

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