1

I'm trying to use Dirac Bra-Ket notation in Maxima using the code from here http://raoul.koalatux.ch/sites/ladderoperator/ladder_operator.html

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));

For most expressions it works:

bra(0) . ket(0);
ket(1) . bra(0) . ket(0);
bra(1) . ket(1) . bra(0) . ket(0);

all simplify correctly, but

bra(1) . ket(1) . bra(0);

fails to simplify to bra(0). How can I get Maxima to simplify this case?

cwitte
  • 140
  • 4

1 Answers1

2

I think you can start with this:

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);
slitvinov
  • 5,693
  • 20
  • 31
  • Excellent, that works, but why do I need to redefine the associativity of `.` ? – cwitte May 06 '13 at 09:27
  • I think `.` is not associative. Consider this example `[a, b]: [[1, 0], [0, 1]]; a . (b . b); (a . b) . b;` – slitvinov May 07 '13 at 10:41
  • From the manual: Option variable: dotassoc Default value: true When dotassoc is true, an expression (A.B).C simplifies to A.(B.C). – cwitte May 07 '13 at 15:45