I created a web-calculator with support for physical units

AI Thread Summary
David, a theoretical physicist from Stuttgart, has developed an open-source scientific calculator called Insect, which supports physical units and aims to simplify unit conversions. Users have expressed the need for better handling of unit systems, particularly natural units, and the ability to easily convert between different units without tedious calculations. The calculator currently interprets time inputs in a way that can lead to confusion, and there are suggestions for implementing a special conversion operator to enhance usability. Additionally, there is interest in creating a pool of common constants to avoid naming conflicts, as well as the potential for predefined unit systems to streamline calculations. Overall, the community is engaged in providing feedback to improve the functionality and user experience of Insect.
sharkdp
Hi!

My name is David. I'm a theoretical physicist from Stuttgart, Germany. Over the past months I have been developing an open source application called Insect, which I hope would be of interest to some of you. Insect is a high-precision scientific calculator that comes with full support for physical units. Here's a short demo:

insect-demo.png


You can try the web-version here: https://insect.sh/

The full documentation, the source code and a terminal version are available here: https://github.com/sharkdp/insect

Anyway, I would really love to hear your feedback!Full disclosure: This is my first post on this forum. I was careful to read the Forum Guidelines and I hope that this post does not contradict any of the rules. There is no personal gain for me: Insect is an open-source project and is completely free.
 
  • Like
Likes FactChecker, vanhees71 and Stavros Kiri
Physics news on Phys.org
As a particle physicist, I would like to see support for different unit systems, in my case natural units. Converting km to eV^-1 is tedious and error prone. I currently usually use Wolfram Alpha for fast conversions, but there as here you need to get the appropriate factors of c and hbar in there. It would be significantly more convenient to just type 1 km -> eV^-1.
 
  • Like
Likes Stavros Kiri
I had problems with 4 km/h * 5h 30m 7s.
 
Orodruin said:
As a particle physicist, I would like to see support for different unit systems, in my case natural units.

Thank you for the feedback! A similar request has been discussed here: https://github.com/sharkdp/insect/issues/112
I'd be happy to re-open the ticket to discuss this again.

Orodruin said:
Converting km to eV^-1 is tedious and error prone.

I can understand why it is tedious, but error prone? Using a calculator that understands physical units, there is actually no way you can make an error by inserting factors of h_bar and c (as you would get the result in wrong units):

upload_2017-8-20_17-46-1.png
 
sharkdp said:
I can understand why it is tedious, but error prone?
It is error prone when you do it by hand. Using Wolfram Alpha will always get you the right result, but you have to find the correct powers of c and hbar, which is tedious.
 
fresh_42 said:
I had problems with 4 km/h * 5h 30m 7s.

Thank you for the feedback! Your input "5h 30m 7s" is currently interpreted as "5 hours × 30 meters × 7 seconds". I'm assuming you want to calculate "4 km/h * (5h + 30min + 7s)" (which would work as input). Unfortunately, there is currently no shorter way to enter times in the HH:MM:SS format - but I'd be happy to discuss possible variants of that. You can define your own functions, so sth. like this could be an option:

Code:
time(x, y, z) = x hours + y minutes + z seconds
4km/h * time(5, 30, 7)
 
  • Like
Likes fresh_42
sharkdp said:
I'm a theoretical physicist from Stuttgart, Germany.
sharkdp said:
There is no personal gain for me: Insect is an open-source project and is completely free.
Hmm, uncommon combination. Do you plan to make money at some later stage of the project?
 
  • Like
Likes sharkdp
fresh_42 said:
Hmm, uncommon combination. Do you plan to make money at some later stage of the project?

Ouch! :-)

No, I don't have any plans to make money with the project...
(I work as a software developer...)
 
Interesting and useful. I like it (first impression).
[And welcome to PF!]
 
  • Like
Likes sharkdp
  • #10
sharkdp said:
Ouch! :-)

No, I don't have any plans to make money with the project...
(I work as a software developer...)
Sorry, couldn't resist. :wink:

Do you have a control sign for constants like ##h,\hbar,N_A,k_B,G## or ##c##? I found this as a major disadvantage on Wolfram as ##h## is automatically interpreted as hour. Would be easier to have a pool of common constants available.
 
  • Like
Likes sharkdp and Stavros Kiri
  • #11
fresh_42 said:
Sorry, couldn't resist. :wink:

Do you have a control sign for constants like ##h,\hbar,N_A,k_B## or ##c##? I found this as a major disadvantage on Wolfram as ##h## is automatically interpreted as hour. Would be easier to have a pool of common constants available.

What do you mean by control sign? A special character that introduces a constant (like $hbar)? No - constants and units currently share the same namespace, so there might be problems like the one you mentioned (hbar is "hector bar" :frown:) - but I like the idea. Insect has a "pretty printer" which prints units in green and constants/variables in orange - so this might help.

For reference, ##h## = PlanckConstant, ##\hbar## = h_bar or ℏ, ##N_A## = N_A, ##k_B## = k_B, ##c## = c, speedOfLight, ##G## = G. You can type "list" to see all constants.
 
  • Like
Likes Stavros Kiri
  • #12
I just thought that $h would be a lot shorter than to type in PlanckConstant. E.g. I use a tiny program to abbreviate LaTeX commands, like Alt+M for ##\text{ \begin{bmatrix}\end{bmatrix}}\,.## Makes life easier. Btw. do you need the distinction between upper and lower case characters? And if so, wouldn't it be natural to write Planckconstant than PlanckConstant - not that it is important.
 
  • Like
Likes sharkdp
  • #13
fresh_42 said:
I just thought that $h would be a lot shorter than to type in PlanckConstant.

True, I'll consider adding this. Thanks!
Note that you can use tab-completion, so "pl<tab>" also works :wink:.

fresh_42 said:
Btw. do you need the distinction between upper and lower case characters?

It's definitely useful. C = Coulomb, c = speed of light. G = gravitational constant, g = gram. H = henry, h = hour. S = Sievert, s = second. T = Tesla, t = ton.

fresh_42 said:
And if so, wouldn't it be natural to write Planckconstant than PlanckConstant - not that it is important.

I probably chose this from a programmer perspective where variable names are usually lowercase (and often Camel case). Note that user-defined variables are supported (simply type "Planckconstant = PlanckConstant"). It's not very practical at the moment because user-sessions can not be stored, yet (I definitely plan to support this).
 
  • #14
Cool stuff.

Regarding the natural units Orodruin brought up, it might be interesting to look into an algorithmic way to do this.
A great starting point is already present as proven by your error message.
E.g. for $$2\mathrm{km}\rightarrow(neV)^{-1}$$ you convert the units on both sides of the arrow to $$[\mathrm{L}]$$ resp. $$[M]^{-1}[L]^{-2}[T]^2$$ (here I used the quantity short-hands M = mass, L = length and T = time)
Next it should be possible to find the conversion factor, although I'm not certain in which way this is done best.

If I find the time I'll try and look into this sometime this week and get back to you.
 
  • Like
Likes sharkdp
  • #15
JorisL said:
Next it should be possible to find the conversion factor, although I'm not certain in which way this is done best.

Yes, it can be posed as a simple linear algebra problem (where different base units represent different dimensions). ##\hbar## with units ##[\hbar] = \text{kg} \cdot \text{m}^2 \cdot \text{s}^{-1}##, for example, is represented as a vector ##(1, 2, -1)^T## in the "(KG, M, S)" space. In this way, it would be easy to solve for the exponents of ##\hbar, c##, etc. [One problem is: there are different sets of natural units].

I really don't want the normal conversion operator "->" to have any "magic" funtionality. This could definitely lead to confusion if random factors of ##\hbar##, etc. are inserted when a user makes an error in asking for a certain conversion (for example).

Coming to think of it, it could be an option to introduce a special conversion operator ("~>" ? :smile:) that would support this. So "2 km ~> neV^-1" would work.
 
  • #16
Hmm, how much time would it take to implement named functions?
Because in this case it could be useful to define a function like PlanckToSI (c=h=g=k_b=k_e=1) or geometrizedToSi (c = G = 1).
Each of them defines the linear algebra problem internally et voila you're done.

I bet it would lead to quite some attention as well.
 
  • #17
JorisL said:
Hmm, how much time would it take to implement named functions?

Named functions are already supported. You can define "f(x, y) = 2*x*y + 3 cos(x/5) sin(y)", for example.

JorisL said:
it could be useful to define a function like PlanckToSI (c=h=g=k_b=k_e=1)

That would be a completely new syntax, but I see your point. Maybe it would be easier to store a few predefined unit-systems and the user could simply type "set natural_units gauss" or something similar.
 
  • #18
This made me think of Mathcad, which automatically converts units and checks equations for compatibility of units. I really liked it for that.
 
  • Like
Likes sharkdp
Back
Top