sharkdp / insect

High precision scientific calculator with support for physical units
https://numbat.dev/
MIT License
3.17k stars 126 forks source link

Support for Planck units and Stoney units. #398

Closed archisman-panigrahi closed 1 year ago

archisman-panigrahi commented 1 year ago

It would be great if insect (and numbat in future) supports Planckian units (Planck length, Planck time, Planck mass) and Stoney units.

I am not proposing to set h_bar = c = G = 1. Rather, I am proposing to add these as new units for length, time and mass.

archisman-panigrahi commented 1 year ago

Just found that numbat already supports Planck units.

sharkdp commented 1 year ago

Just found that numbat already supports Planck units.

Yes.

and Stoney units.

I did not know about Stoney units. I will add them in Numbat. The great thing about Numbat is that you don't even need a new release to use them. Put a file called stoney.nbt in your ~/.config/numbat/modules/units folder with the following content:

# See https://en.wikipedia.org/wiki/Stoney_units

use physics::constants

unit l_s: Length = sqrt(gravitational_constant × electron_charge^2 / 4 π ε0 speed_of_light^4)

unit m_s: Mass = sqrt(electron_charge^2 / 4 π ε0 gravitational_constant)

unit t_s: Time = sqrt(gravitational_constant × electron_charge^2 / 4 π ε0 speed_of_light^6)

Then, from the REPL, you can type

use units::stoney

to include them. Or you could add use units::stoney to your ~/.config/numbat/init.nbt file. And then you're ready to use them:

>>> ℏ -> l_s^2 × m_s / t_s

    = 137.036 l_s²·m_s/t_s
archisman-panigrahi commented 1 year ago

I did not know about Stoney units.

I got to know about them today in the wikipedia article of Planck units.

unit l_s: Length = sqrt(gravitational_constant × electron_charge^2 / 4 π ε0 speed_of_light^4)

I know that the users can name as per their preference, but for the default setup, can we use the same convention as planck_length and use the name stoney_length instead of l_s?

sharkdp commented 1 year ago

can we use the same convention as planck_length and use the name stoney_length instead of l_s?

Yes, good idea.

sharkdp commented 1 year ago

You can now try this out in https://numbat.dev/ (use units::stoney). I'd be glad to get some feedback.

archisman-panigrahi commented 1 year ago

Let me know if you want me to submit bug reports in the numbat repo instead. I tested it. It works. t would be great if it is loaded by default (users may not know that numbat supports the unit otherwise).

I have a feature request. numbat does not seem to use planck_length or stoney_length as a unit, but as a constant.

>>> planck_length -> m

  planck_length ➞ meter

      = 1.61626e-35 m    [Length]
>>> m -> planck_length

  meter ➞ planck_length

      = 1 m    [Length]

I would expect it to say 6.18714e34 planck_length. Will it require significant rewrite to implement this?

sharkdp commented 1 year ago

Let me know if you want me to submit bug reports in the numbat repo instead.

Please do report issues in the numbat repo, yes.

I have a feature request. numbat does not seem to use planck_length or stoney_length as a unit, but as a constant.

It was implemented for stoney units, but not for planck units. It is fixed now: https://numbat.dev/?q=m+-%3E+planck_length (you might need to refresh the browser cache with ctrl+shift+r)

sharkdp commented 1 year ago

would be great if it is loaded by default (users may not know that numbat supports the unit otherwise).

For stoney units, I will probably not do that because they are so exotic and I don't want to clutter the global namespace too much. But the units are hopefully discoverable through the documentation (https://numbat.dev/doc/list-units.html). We should add necessary import statements there.