jfeist / QuantumAlgebra.jl

Quantum operator algebra in Julia
MIT License
60 stars 10 forks source link

Avac(1) throws an error #14

Closed fremling closed 2 months ago

fremling commented 1 year ago

I have been playing a bit with your package and i like it :)

There are however certain operations that seem natural to me that does not work.

For instance Avac(1) throws an error instead or returning 1. I payed a bit an constructed an operators version of "1" through Avac(fdag(1)*f(1)+f(1)*fdag(1)), but this is a much more complicated object. I could not find any nice way to construct the operator 1 in your package. Maybe i missed something....

jfeist commented 1 year ago

Thanks!

Yes, in the current interface, numbers are not promoted to QuantumAlgebra expressions (type QuExpr) for all functions automatically. I agree that this would be nice, and it is already implemented for some operations (such as multiplication or addition, i.e., 0*a() + 1 gives you 1 as a QuExpr). It would be good (and not too much work) to make this more general.

In any case, there are already several straightforward options to get a number as a QuExpr. The "canonical" way to get the identity operator is one(QuExpr) (you can also call one with any QuantumAlgebra expression, i.e., one(a())). To get an arbitrary number, you can do x*one(QuExpr). Another option is calling the argument-less constructor, QuExpr(), which gives zero as a quantum operator, so QuExpr() + x gives the number x as a quantum operator. I hope you're happy with one of these options. Still, I'll leave the issue open, as it would be nice to make these interfaces more convenient and directly accept Number types anywhere that QuExprs are expected.

jfeist commented 2 months ago

In version 1.4, most routines should now also accept any Number type directly, so I'll close this issue.