jfeist / QuantumAlgebra.jl

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

String macro for parameter that is complex-conjugated #13

Closed tomsturges closed 2 years ago

tomsturges commented 2 years ago

Parameters are created with param(:name,state,indices...), where state = 'r','n','c' stands for real, non-conjugated, or conjugated. Currently the equivalent string macros do not support conjugated complex parameters. My suggestion is to have:

Pr"name_i,j" = param(:name,'r',:u,:j) Pn"name_i,j" = param(:name,'n',:u,:j) Pc"name_i,j" = param(:name,'c',:u,:j)

jfeist commented 2 years ago

It's true that the names are not fully consistent (Pc"g" is param(:g,'n'), not param(:g,'c')), but since this is the released interface, changing it now would make the new version incompatible with previous ones. This could be done at most in the next major version, but even there I would value compatibility over consistency. In particular, I don't think I'd ever do this since Pc"g" would continue to exist, but change meaning, which can lead to really annoying bugs.

I don't worry too much about this since the string macros are really the preferred interface, and param is more of an implementation detail/leftover. The "canonical" way is to use Pr"g" for real variables and Pc"g" for complex ones, and use the adjoint operator ' for complex conjugation:

julia> Pc"g"'
g*

This is compact enough that I didn't feel the need to introduce another string macro. In fact I've thought a few times about removing the explicit "dagger" operators adag(), fdag() in favor of just using the adjoint a()', f()', etc (which I won't do to maintain compatibility, but doing so would at least just raise an error).

If you are not happy with using ' to get the adjoint, you could define a short string macro yourself (I called it Pcᴴ, but obviously you can use whatever name you prefer):

julia> macro Pcᴴ_str(x) :((@Pc_str $x)') end
@Pcᴴ_str (macro with 1 method)

julia> Pcᴴ"g"
g*
tomsturges commented 2 years ago

I agree with your points, and thanks for the suggestions! Best, Tom

On Tue, Nov 23, 2021 at 12:09 PM Johannes Feist @.***> wrote:

It's true that the names are not fully consistent (Pc"g" is param(:g,'n'), not param(:g,'c')), but since this is the released interface, changing it now would make the new version incompatible with previous ones. This could be done at most in the next major version, but even there I would value compatibility over consistency. In particular, I don't think I'd ever do this since Pc"g" would continue to exist, but change meaning, which can lead to really annoying bugs.

I don't worry too much about this since the string macros are really the preferred interface, and param is more of an implementation detail/leftover. The "canonical" way is to use Pr"g" for real variables and Pc"g" for complex ones, and use the adjoint operator ' for complex conjugation:

julia> Pc"g"' g*

This is compact enough that I didn't feel the need to introduce another string macro. In fact I've thought a few times about removing the explicit "dagger" operators adag(), fdag() in favor of just using the adjoint a()', f()', etc (which I won't do to maintain compatibility, but doing so would at least just raise an error).

If you are not happy with using ' to get the adjoint, you could define a short string macro yourself (I called it Pcᴴ, but obviously you can use whatever name you prefer):

julia> macro Pcᴴ_str(x) @.***_str $x)') end @Pcᴴ_str (macro with 1 method)

julia> Pcᴴ"g"

g*

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jfeist/QuantumAlgebra.jl/issues/13#issuecomment-976409142, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSO4SAZDQH75M25YRR7N5LUNNY6PANCNFSM5ITDXBIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.