[ANN & RFC] New package: PhysicalConstants.jl

#1

During the last days I’ve been working on a small new package:

The physical constants are defined as Constant objects, which can be turned into Quantity objects (from
Unitful.jl package) or Measurement objects (from Measurements.jl package) at request.

An example is worth a thousand words:

julia> using PhysicalConstants.CODATA2014

julia> c
Speed of light in vacuum (c)
Value                         = 2.99792458e8 m s^-1
Standard uncertainty          = (exact)
Relative standard uncertainty = (exact)
Reference                     = CODATA 2014

julia> G
Newtonian constant of gravitation (G)
Value                         = 6.67408e-11 m^3 kg^-1 s^-2
Standard uncertainty          = 3.1e-15 m^3 kg^-1 s^-2
Relative standard uncertainty = 4.6e-5
Reference                     = CODATA 2014

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

julia> 4pi * float(G) / float(c)^2
9.331680614932136e-27 m kg^-1

julia> using Measurements

julia> measurement(ħ)
1.0545718001391127e-34 ± 1.2891550390443523e-42 J s

julia> measurement(BigFloat, ħ)
1.054571800139112651153941068725066773746246506229852090971714108355028066256094e-34 ± 1.289155039044352219727958483317366332479123130497697234856105486877064060837251e-42 J s

julia> big(ħ) / (big(h) / (2 * big(pi)))
1.0

Constants.jl is not yet registered because I’d like first to address a couple of design issues. If you’re interested in this package, please chime in: https://github.com/JuliaPhysics/PhysicalConstants.jl/issues

13 Likes

#2

There are many types of constants. Perhaps a prefix to the package name (Physical) would be suitable?

4 Likes

#3

Good idea, I was thinking about this, too. BTW, is there an easy way to rename a package locally besides manually editing the toml files in ~/.julia/environments/vX.Y?

0 Likes

#4

A few days ago, the first official version of PhysicalConstants.jl has been released :tada:

Features

  • physical constants with physical units (from Unitful.jl) and optionally with uncertainty (from Measurements.jl)
  • support for any AbstractFloat type that can be converted from Float64, and for BigFloat. This could be particularly useful for exact constants (like speed of light, and more coming in next CODATA 2018 dataset!), they’ll be always exact!
  • the package is modular in the sense that you can import the dataset that you want to use. The idea is that the package will provide different dataset (e.g., different versions of CODATA constants), but the user will load only the one they are interested in
  • informative printing of constants in the REPL
  • constants can be readily used in any mathematical operations supported by AbstractQuantity (the type in terms of which are defined the operations in Unitful.jl)

Example

julia> using PhysicalConstants.CODATA2014

julia> SpeedOfLightInVacuum
Speed of light in vacuum (c_0)
Value                         = 2.99792458e8 m s^-1
Standard uncertainty          = (exact)
Relative standard uncertainty = (exact)
Reference                     = CODATA 2014

julia> NewtonianConstantOfGravitation
Newtonian constant of gravitation (G)
Value                         = 6.67408e-11 m^3 kg^-1 s^-2
Standard uncertainty          = 3.1e-15 m^3 kg^-1 s^-2
Relative standard uncertainty = 4.6e-5
Reference                     = CODATA 2014

julia> import PhysicalConstants.CODATA2014: c_0, ε_0, μ_0, ħ, h

julia> 2 * ε_0
1.7708375635240778e-11 F m^-1

julia> ε_0 - 1 / (μ_0 * c_0 ^ 2)
0.0 A^2 s^4 kg^-1 m^-3

julia> big(ε_0) - inv(big(μ_0) * big(c_0)^2)
0.0 A^2 s^4 kg^-1 m^-3

julia> using Measurements

julia> ħ
Planck constant over 2pi (ħ)
Value                         = 1.0545718001391127e-34 J s
Standard uncertainty          = 1.2891550390443523e-42 J s
Relative standard uncertainty = 1.2e-8
Reference                     = CODATA 2014

julia> measurement(ħ)
1.0545718001391127e-34 ± 1.2891550390443523e-42 J s

julia> measurement(Float32, ħ)
1.0545718e-34 ± 1.289e-42 J s

julia> measurement(BigFloat, ħ)
1.054571800139112651153941068725066773746246506229852090971714108355028066256094e-34 ± 1.289155039044352219727958483317366332479123130497697234856105486877064060837251e-42 J s

julia> measurement(BigFloat, ħ) / (measurement(BigFloat, h) / (2 * big(pi)))
1.0 ± 0.0
9 Likes

Request for comment: package for scientific and mathematical constants
PhysicalConstants package with Julia 1.0.1.1?
#5

Excellent package!, a little question, how do i use the value without the units?

0 Likes

#6

See here: http://ajkeller34.github.io/Unitful.jl/latest/manipulations/#Unitful.ustrip

2 Likes

#7

thanks!

0 Likes