mabuchilab / QNET

Computer algebra package for quantum mechanics and photonic quantum networks
https://qnet.readthedocs.io/
MIT License
71 stars 23 forks source link

Applying a LocalProjector to a BasisKet does not return a simplified result #76

Closed goerz closed 6 years ago

goerz commented 6 years ago
>>> LocalProjector(1, hs=0) * BasisKet(1, hs=0)
|1⟩⟨1| |1⟩

Should be just |1⟩. Note that this does work for LocalSigma

goerz commented 6 years ago

The underlying problem is that LocalProjector only has one argument, and some of the rules for LocalSigma do not match for a LocalProjector because of this. LocalProjector would need its own rules everywhere!

LocalProjector being a sub-class of LocalSigma (as opposed to just a convenience-wrapper for instantiation a LoalSigma with j = k) was motivated only by being able to print it differently. I think this motivation is not strong enough to justify having to write a significantly larger number of algebraic rules (which add complexity and increase runtime).

Thus, the best solution is to get rid of LocalProjector as a class (refactor it into a function). As a workaround for the printing, LocalSigma could get a _identifier_projector class attribute that is used instead of _identifier when printing. It won't be possible to override this depending on the specific Hilbert space, but that would be an extremely unusual thing to do anyway.