Skip to content

Instantly share code, notes, and snippets.

@tymat
Created December 31, 2015 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tymat/d7d475a7d8c87f9be120 to your computer and use it in GitHub Desktop.
Save tymat/d7d475a7d8c87f9be120 to your computer and use it in GitHub Desktop.
Maxima - Proper use of Dirac bra-ket notation.
declare(bra, nonscalar);
declare(ket, nonscalar);
dotscrules:true;
matchdeclare(m,lambda([t],featurep(t,integer)));
matchdeclare(n,lambda([t],featurep(t,integer)));
tellsimp(bra(m).ket(n), kron_delta(m,n));
simp:false;
matchdeclare(aa, true);
matchdeclare(bb, true);
matchdeclare(cc, true);
tellsimp (aa.(bb.cc),(aa.bb).cc);
simp:true;
/* Tests */
bra(0) . ket(0);
ket(1) . bra(0) . ket(0);
bra(1) . ket(1) . bra(0) . ket(0);
bra(1) . ket(1) . bra(0);
ket(1) . bra(1) . ket(1);
@matan-bebop
Copy link

That is very helpful! Though I would add dotdistrib:true; for (bra(2) + 1) . ket(2); to give the correct result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment