# Request for comment: package for scientific and mathematical constants

**URL:** <https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155>\
**Category:** Numerics\
**Tags:** proposal, numbers\
**Created:** [June 8, 2017, 12:55am UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155 "2017-06-08T00:55:20Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [June 8, 2017, 12:03pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/21 "2017-06-08T12:03:21Z")

</div>

There’s also [https://github.com/ggggggggg/Physical.jl](https://github.com/ggggggggg/Physical.jl)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [June 8, 2017, 12:29pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/22 "2017-06-08T12:29:50Z")

</div>

Would be nice to consolidate something in JuliaPhysics for sure.

---

<div class="post-metadata">

**Author:** ![fasiha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fasiha/32/1146_2.png) [@fasiha](https://discourse.julialang.org/u/fasiha)\
**Post date:** [June 8, 2017, 6:05pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/23 "2017-06-08T18:05:12Z")

</div>

@giordano @mkborregaard I like [https://github.com/DataWookie/PhysicalConstants.jl](https://github.com/DataWookie/PhysicalConstants.jl), could you explain what features it needs before it’d be acceptable for JuliaPhysics?

I may not have drunk enough of the type-all-the-things koolaid yet but I’m wary of both carrying around interval/uncertainties and units in types, so PhysicalConstants.jl is really attractive—simple, offers some compromise by offering mks and cgs SI units. I’d probably get rid of the imperial module, and make the `cgs` constants dependent on `mks` (doing the dimensional analysis either manually or automatically using a units module). Would that be sufficient?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [June 8, 2017, 6:07pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/24 "2017-06-08T18:07:18Z")

</div>

> [@fasiha](#):
>
> @giordano @mkborregaard I like [GitHub - datawookie/PhysicalConstants.jl: Physical Constants for Julia.](https://github.com/DataWookie/PhysicalConstants.jl), could you explain what features it needs before it’d be acceptable for JuliaPhysics?

Looks like unmaintained.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 8, 2017, 6:25pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/25 "2017-06-08T18:25:41Z")

</div>

It really should use real Units (Unitful.jl) instead of source code comments.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [June 8, 2017, 6:30pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/26 "2017-06-08T18:30:54Z")

</div>

Adding to my previous short comment, the package looks just a collection of numerical constants in different unit systems (so probably there are some constants defined multiple times), but relying on a well-developed unit package is probably a better idea. As I said before, I’d appreciate that such package could take into account uncertainties. For example, something like this:

```julia
julia> using PhysicalConstants

julia> G
G = 6.67408e-11 m^{3} kg^{-1} s^{-2}

julia> float(G)
6.67408e-11 m^{3} kg^{-1} s^{-2}

julia> measurement(G)
6.67408e-11 ± 3.1e-15 m^{3} kg^{-1} s^{-2}

```

For these features, the package must be more developed and better designed than a simple collection of numerical constants and nothing more.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [June 8, 2017, 6:31pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/27 "2017-06-08T18:31:02Z")

</div>

> [@fasiha](#):
>
> @giordano @mkborregaard I like [GitHub - datawookie/PhysicalConstants.jl: Physical Constants for Julia.](https://github.com/DataWookie/PhysicalConstants.jl), could you explain what features it needs before it’d be acceptable for JuliaPhysics?

+1 for UnitFul. If there was ever a case for using units, this is it.

+1 for scoping (e.g. PhysicsConstants.Quantum).

?? about whether using JuliaIntervals for representing uncertainty is overkill or appropriate

---

<div class="post-metadata">

**Author:** ![fasiha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fasiha/32/1146_2.png) [@fasiha](https://discourse.julialang.org/u/fasiha)\
**Post date:** [June 8, 2017, 6:45pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/28 "2017-06-08T18:45:29Z")

</div>

Thanks for elaborating. About units, you’ve all convinced me it’s a good idea. We can probably do better than “all exported numbers are in SI units” and let users specify what units they want constants in. I do have concerns that marrying this constants library to a specific unit library might cause problems for downstream apps/libs that use a different units library (or none at all), but that can hopefully be smoothed over.

Could you elaborate a bit more on the measurement uncertainties? Propagating uncertainties from physical constants throughout the processing chain seems like something that (1) arises infrequently, and (2) when it does, I expect people to have different ideas about how to deal with the uncertainty: some might use uncertainty just for correct significant digits, others might interpret uncertainty as Bayesian priors (for which distribution? Normal? Rayleigh?), while still others might want to use interval arithmetic. I am wondering whether this library can make a reasonable decision on behalf of these specialized users, or if it’d be better to forego uncertainty for the majority of users who don’t need them.

I’ll take a look at drafting drafting a library.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 8, 2017, 7:20pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/29 "2017-06-08T19:20:40Z")

</div>

Could have that each value is defined by a tuple (value, relative uncertainty). Similar to how data is presented at e.g. [Fundamental Physical Constants from NIST](http://physics.nist.gov/cuu/Constants/index.html)

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [June 8, 2017, 7:22pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/30 "2017-06-08T19:22:02Z")

</div>

> [@fasiha](#):
>
> Thanks for elaborating. About units, you’ve all convinced me it’s a good idea. We can probably do better than “all exported numbers are in SI units” and let users specify what units they want constants in. I do have concerns that marrying this constants library to a specific unit library might cause problems for downstream apps/libs that use a different units library (or none at all), but that can hopefully be smoothed over.

Yes, I agree, there are two good competing packages for units (but I have a slight personal preference for one of them), but unless there will be an AbstractUnits.jl package that enables unifying the interfaces of all units-related packages (something like [`AbstractFFTs.jl`](https://github.com/JuliaMath/AbstractFFTs.jl) is doing with Fast Fourier Transform), you have to make a decision between the two packages.

> [@fasiha](#):
>
> Could you elaborate a bit more on the measurement uncertainties? Propagating uncertainties from physical constants throughout the processing chain seems like something that (1) arises infrequently

I agree, indeed the approach proposed above you have to explicitly request the conversion of the constant to a `Measurement` type, otherwise `float(G)` gives you a simple `Float64` wrapped by units. If you really want the constant with its uncertainty, ask for it, otherwise assume it to be exact. But if you’re doing extremely precise measurements, you may want to take into account physical constants’ uncertainties as well (`Measurements.jl` works with arbitrary precision arithmetic, a feature I couldn’t find in other [similar packages](https://en.wikipedia.org/wiki/List_of_uncertainty_propagation_software)).

> [@fasiha](#):
>
> and (2) when it does, I expect people to have different ideas about how to deal with the uncertainty: some might use uncertainty just for correct significant digits, others might interpret uncertainty as Bayesian priors (for which distribution? Normal? Rayleigh?), while still others might want to use interval arithmetic.

[`Measurements.jl`](https://github.com/giordano/Measurements.jl) assumes [linear error propagation theory](https://en.wikipedia.org/wiki/Propagation_of_uncertainty), which looks to be the most widely used in Physics. Honestly, I’ve never seen interval arithmetic in Physics to track uncertainties (but makes much more sense in Mathematics, it gives how an interval in mapped into another by a function), I don’t understand why people keep mentioning it here.

> [@fasiha](#):
>
> I am wondering whether this library can make a reasonable decision on behalf of these specialized users, or if it’d be better to forego uncertainty for the majority of users who don’t need them.

I think that [`Unitful.jl`](https://github.com/ajkeller34/Unitful.jl) has the possibility, in theory, to adapt to different unit systems (MKS, CGS, etc…), but I’m not 100% sure.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [June 8, 2017, 7:25pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/31 "2017-06-08T19:25:21Z")

</div>

Yes, that’s a possibility, but I think that making it more similar to an `Irrational` is a better approach (as I proposed above), also because there are constants that are defined to be exact and multiple of irrational numbers.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [April 4, 2019, 10:16pm UTC](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155/32 "2019-04-04T22:16:53Z")

</div>

I’ve finally released the first version of [`PhysicalConstants.jl`](https://github.com/JuliaPhysics/PhysicalConstants.jl) (see [the announcement](https://discourse.julialang.org/t/ann-rfc-new-package-physicalconstants-jl/14737/4)).

[Previous page](https://discourse.julialang.org/t/request-for-comment-package-for-scientific-and-mathematical-constants/4155.md?page=1)
