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 Oersted: unit of auxiliary magnetic field strength H #397

Closed archisman-panigrahi closed 1 year ago

archisman-panigrahi commented 1 year ago

I propose the unit Oersted for auxiliary magnetic field H be included in insect.

The value of the unit is 1 Oersted = (4π)^(−1)×10^3 A/m = 10^(-4) Tesla/μ₀ = 1 Gauss/μ₀

In insect syntax, Oe = gauss/magneticConstant

This unit is still used in experimental research papers (like this), so it would be useful to have this in insect.

sharkdp commented 1 year ago

Ha! I also saw that paper (and the thread on HN), and immediately added oersted/Oe to the rewrite of Insect, that we are currently working on:

image

So in the new version you can do this:

image

Unfortunately, the new version is not yet public. But if you are interested, I can send you a pre-release (Linux binary, command-line version). It's pretty much on the same level, feature wise, as Insect. But has quite a few advantages.

archisman-panigrahi commented 1 year ago

Ha! I also saw that paper

:)

(and the thread on HN)

Which thread are you referring to?

But if you are interested, I can send you a pre-release

Sure, I will be happy to test/use it. What are the planned new features? You can upload the binary right here. In case you don't want to do that, you can also send me an email (can be found on my GitHub profile page).

sharkdp commented 1 year ago

(and the thread on HN)

Which thread are you referring to?

https://news.ycombinator.com/item?id=36864624

But if you are interested, I can send you a pre-release

Sure, I will be happy to test/use it.

Some beta testing would be great! I have attached a pre-release to this post. In order to use it, you need to create ~/.config/numbat and then move the modules folder from the archive to that directory.

You can find some preliminary documentation (tutorial, examples, reference) here: https://numbat.dev/doc/

numbat.zip

What are the planned new features?

The major new feature is that users can define their own units. We also introduce the concept of physical dimensions and statically check all code before executing it. All the predefined units/constants/functions are now also written in the "Numbat" language itself. Numbat is also orders of magnitude faster than Insect. It has much better error messages. It fixes some open bugs in Insect. And a lot of other things :-)

archisman-panigrahi commented 1 year ago

I get the following error in Linux Mint 21.2

./numbat: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

I tried sudo apt install libssl-dev, but that did not help.

sharkdp commented 1 year ago

@archisman-panigrahi Thank you for trying. I now built a new recent release without a libssl dependency. You can find the download link and instructions here: https://numbat.dev/

Looking forward to your feedback!

archisman-panigrahi commented 1 year ago

Now it runs! Should I submit bug reports for numbat right here? I just realized that it does not have magneticConstant and electricConstant. Maybe it supports greek symbols, but it is hard to write greek alphabets on a regular keyboard.

It would be great if numbat already contains all the constants of insect (it is fine if they are renamed, like planckConstant -> planck_constant)

sharkdp commented 1 year ago

Now it runs!

Great — thank you for the feedback!

Should I submit bug reports for numbat right here?

I wanted to add you to the numbat repository, but GitHubs permission system for private repositories is not very granular... it's either all or nothing. So please feel free to report Numbat issues in this ticket. Or if they apply to Insect as well, feel free to open new tickets.

I just realized that it does not have magneticConstant and electricConstant.

It does, but not under those names. We should add those long names as well. In the meantime, you can also create a ~/.config/numbat/init.nbt file and add

let magnetic_constant = µ0
let electric_constant = ε0

Maybe it supports greek symbols, but it is hard to write greek alphabets on a regular keyboard.

Yes, you can use µ0/ε0 — but mu0/eps0 are also supported.

It would be great if numbat already contains all the constants of insect (it is fine if they are renamed, like planckConstant -> planck_constant)

I think it does. See https://numbat.dev/doc/list-constants.html for a list of all builtin constants. You can also type list in the REPL. And feel free to report it here if you think something is missing.

archisman-panigrahi commented 1 year ago

Great. Now I have realized how to add custom units.

It will be handy to have let c = speed_of_light as a part of default setup. Since numbat is not trying to be a general purpose programming language (and everyone uses c for speed of light), having a default value for the variable c will not harm the user experience, in my opinion.

archisman-panigrahi commented 1 year ago

I propose all the following for more convenience in the default user experience.


let c = speed_of_light
let G = gravitational_constant
let h_bar = ℏ
let magnetic_constant = µ0
let electric_constant = ε0
let bohr_Magneton = µ_B
let fine_structure_constant = α
let avogadro_Constant = N_A
let boltzmann_Constant = k_B
let gas_Constant = R
let bohr_Radius = a0
sharkdp commented 1 year ago

Thank you for the suggestions. I refrained from adding some short aliases since I didn't want to pollute the one-character namespace even further. But I also missed having c for speed_of_light already.

I implemented all of your suggestions (but long names always lowercase / snake case), pushed a new beta release and updated the documentation: https://numbat.dev/doc/list-constants.html

archisman-panigrahi commented 1 year ago

but long names always lowercase / snake case)

I mixed up uppercase and lowercase. Thanks for making everything lowercase.

archisman-panigrahi commented 1 year ago

One more thing I just found in the new version.

>>> bohr_radius

  bohr_radius

    = 5.29177e-11 F·J²/(C²·kg·m·Hz²)

It would be great if it reports 5.29177e-11 m instead.

sharkdp commented 1 year ago

Yes, thanks. I found that too. It's a limitation of our unit simplification right now. I fixed it for now with a manual -> meter conversion in the unit definition, so now you should have the desired result.

sharkdp commented 1 year ago

You can now try this online here: https://numbat.dev/?q=mu0+*+2500+Oe+-%3E+T

archisman-panigrahi commented 1 year ago

Works. I verified that T/mu0 -> Oe works too. I am closing the issue.