sharkdp / insect

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

Add hidden values for sub-one range (milli, micro, etc.) #372

Closed intervall-ludger closed 1 year ago

intervall-ludger commented 1 year ago

This pull request adds support for smaller scale prefixes (i.e., values less than 1) in the Insect calculator by including hidden values for milli, micro, nano, pico, femto, atto, zepto, and yocto.

Before

Up to now, only the specification of milli etc. in connection with a unit was supported.

image

Now

With this changes, smaller numbers no longer have to be written out with zeros (Analogous to the support of positive powers of ten).

image
triallax commented 1 year ago

If we're going to add hidden values for these prefixes, is there any reason not to go all-out and add them for ALL prefixes (preferably not manually but by iterating over all the existing prefixes)?

intervall-ludger commented 1 year ago

If we're going to add hidden values for these prefixes, is there any reason not to go all-out and add them for ALL prefixes (preferably not manually but by iterating over all the existing prefixes)?

Hey @mhmdanas

I have scaled the value range analog to the value range already implemented so far. Therefore, a coverage from 10^-18 to 10^18 is now possible, which is probably sufficient.

sharkdp commented 1 year ago

Hi @ludgerradke, thank you for your contribution.

I guess the question is: why should we allow "milli meter" but not "kilo meter"?

(Note that you can already write full long forms: "millimeter" and "kilometer")

intervall-ludger commented 1 year ago

@sharkdp

If units are used, this is already supported. I had an issue calculating concentrations of phantoms where I wanted to perform intermediate calculations without units. This led me to realize that large numbers can be inputted using words, but small numbers can only be expressed in powers of 10.

But of course, the primary purpose of "insect" is to convert and calculate different units and not to calculate quickly without units.

image

triallax commented 1 year ago

I see where you're coming from, but I don't think it would be nice to allow only sub-1 prefixes but not the others, hence my suggestion to allow all prefixes to be standalone.

intervall-ludger commented 1 year ago

@mhmdanas What exactly do you mean by that? So I should also add Dezi and Centi? That would make sense, I'll be happy to implement it tomorrow.

sharkdp commented 1 year ago

I think what both of us mean is the following:

image

Look how we have "thousand", "million", etc. for positive power-of-ten exponents. We don't have "kilo" or "mega" there.

So to extend this to negative power-of-ten exponents in an analogous way, we should rather add "thousandth", "millionth", etc. instead of "milli" or "micro". This way, you could do something like 3 thousandth to get 0.003. But I'm not entirely sure if that's a good idea (linguistics-wise :smile:).

Whether or not we also add metric SI prefixes like "milli" or "kilo" as standalone identifiers is another discussion. I think I'd rather avoid it, if possible.

intervall-ludger commented 1 year ago

@sharkdp @mhmdanas Ok. I agree with both of you, because in this way the implementation would be analogous to the positive powers of 10. Moreover, the implementation in this way is quite different from the SI terms with units.

intervall-ludger commented 1 year ago

@sharkdp I'll think about the best way to name it so that it is clearly distinguishable from the SI designations and get back to you.

sharkdp commented 1 year ago

I had an issue calculating concentrations of phantoms where I wanted to perform intermediate calculations without units.

I'd actually be interested in a few details here. What are "concentrations of phantoms"? Is there something we could do to support this use case better in Insect? (missing units?)

But of course, the primary purpose of "insect" is to convert and calculate different units and not to calculate quickly without units.

Well, not necessarily. Ideally, calculations without units should also be as convenient as possible.

intervall-ludger commented 1 year ago

I had an issue calculating concentrations of phantoms where I wanted to perform intermediate calculations without units.

I'd actually be interested in a few details here. What are "concentrations of phantoms"? Is there something we could do to support this use case better in Insect? (missing units?)

But of course, the primary purpose of "insect" is to convert and calculate different units and not to calculate quickly without units.

Well, not necessarily. Ideally, calculations without units should also be as convenient as possible.

All required units and constants were available for the calculations. It was about mixing phantoms for CEST MR experiments.

It would be possible to include additional MR parameters, such as the gyromagnetic ratio of the different atoms. I have tried this before, but unfortunately it did not work. I can create an issue about this or we can write on slack, but I think it is quite specific.

intervall-ludger commented 1 year ago

@sharkdp @mhmdanas

I don't think the nomination is that good either unfortunately, it was just the best so far.

What do you think about ppm (parts per million), ppb (parts per billion), ppt (parts per trillion), ppq (parts per quadrillion)?

Alternatively, also than percent and per mille.

Scientifically it would be so clear, but perhaps not intuitively.

sharkdp commented 1 year ago

What do you think about ppm (parts per million), ppb (parts per billion), ppt (parts per trillion), ppq (parts per quadrillion)?

Ha! We already have those, I completely forgot :smile:

https://github.com/sharkdp/insect/blob/252a6c01a2380fa3bf042f49fcec5620b3bb87df/src/Insect/Parser.purs#L267-L271

See also: https://en.wikipedia.org/wiki/Parts-per_notation

In that case... let's skip adding those new constants for now?

intervall-ludger commented 1 year ago

@sharkdp Yes, I also find the solution better and it fits with my statement that it is not very intuitive, but clearly more scientific.

So I will close the pull request.