浏览代码

Add short+long aliases for most phys. constants

David Peter 2 年之前
父节点
当前提交
a2be63f82d

+ 12 - 12
book/src/list-constants.md

@@ -26,24 +26,24 @@
 
 | Description | Identifier | Dimension |
 |---|---|---|
-| The speed of light in vacuum | `speed_of_light` | `Speed` |
-| The Newtonian constant of gravitation | `gravitational_constant` | `Force × Length^2 / Mass^2` |
-| Standard acceleration of gravity on earth | `gravity` | `Acceleration` |
+| The speed of light in vacuum | `speed_of_light`, `c` | `Speed` |
+| The Newtonian constant of gravitation | `gravitational_constant`, `G` | `Force × Length^2 / Mass^2` |
+| Standard acceleration of gravity on earth | `gravity`, `g0` | `Acceleration` |
 | The Planck constant | `planck_constant` | `Mass × Length^2 / Time` |
-| The reduced Planck constant | `ℏ` | `Mass × Length^2 / Time` |
+| The reduced Planck constant | `h_bar`, `ℏ` | `Mass × Length^2 / Time` |
 | Mass of the electron | `electron_mass` | `Mass` |
 | Elementary charge (charge of the electron) | `elementary_charge`, `electron_charge` | `Charge` |
-| Magnetic constant (vacuum magnetic permeability) | `µ0`, `mu0` | `Force / Current^2` |
-| Electric constant ( vacuum electric permittivity) | `ε0`, `eps0` | `Capacitance / Length` |
-| Bohr magneton | `µ_B` | `Energy / MagneticFluxDensity` |
-| Fine structure constant | `α` | `Scalar` |
+| Magnetic constant (vacuum magnetic permeability) | `magnetic_constant`, `µ0`, `mu0` | `Force / Current^2` |
+| Electric constant (vacuum electric permittivity) | `electric_constant`, `ε0`, `eps0` | `Capacitance / Length` |
+| Bohr magneton | `bohr_magneton`, `µ_B` | `Energy / MagneticFluxDensity` |
+| Fine structure constant | `fine_structure_constant`, `alpha`, `α` | `Scalar` |
 | Proton mass | `proton_mass` | `Mass` |
-| Avogadro constant | `N_A` | `1 / AmountOfSubstance` |
-| Boltzmann constant | `k_B` | `Energy / Temperature` |
-| Ideal gas constant | `R` | `Energy / (AmountOfSubstance × Temperature)` |
+| Avogadro constant | `avogadro_constant`, `N_A` | `1 / AmountOfSubstance` |
+| Boltzmann constant | `boltzmann_constant`, `k_B` | `Energy / Temperature` |
+| Ideal gas constant | `gas_constant`, `R` | `Energy / (AmountOfSubstance × Temperature)` |
 | Planck length | `planck_length` | `Length` |
 | Planck mass | `planck_mass` | `Mass` |
 | Planck time | `planck_time` | `Time` |
 | Planck temperature | `planck_temperature` | `Temperature` |
 | Planck energy | `planck_energy` | `Energy` |
-| Bohr radius | `a0` | `Length` |
+| Bohr radius | `bohr_radius`, `a0` | `Length` |

+ 1 - 1
examples/pendulum.nbt

@@ -1,4 +1,4 @@
 fn oscillation_time(length: Length) -> Time =
-    2 pi × sqrt(length / gravity)
+    2 pi × sqrt(length / g0)
 
 assert_eq(oscillation_time(30 cm), 1.1 s, 0.1 s)

+ 0 - 2
examples/projectile_motion.nbt

@@ -1,7 +1,5 @@
 # https://en.wikipedia.org/wiki/Projectile_motion
 
-let g0 = gravity
-
 fn max_height(v: Speed, θ: Angle) -> Length = v² · sin(θ)^2 / (2 · g0)
 fn max_distance(v: Speed, θ: Angle) -> Length = v² · sin(2 θ) / g0
 fn time_of_flight(v: Speed, θ: Angle) -> Time = 2 v · sin(θ) / g0

+ 1 - 1
examples/typecheck_error/incompatible_types_in_addition.nbt

@@ -1,6 +1,6 @@
 let v: Speed = 3 m/s
 let mass: Mass = 80 kg
 let height = 10 m
-let E_pot: Energy = mass * gravity * height
+let E_pot: Energy = mass * g0 * height
 
 0.5 * mass * v + E_pot

+ 0 - 2
examples/unicode.nbt

@@ -1,5 +1,3 @@
-let c = speed_of_light
-
 let λ = 2 × 300 µm
 let ν = c / λ
 

+ 1 - 3
examples/xkcd_681.nbt

@@ -2,10 +2,8 @@
 #
 # https://xkcd.com/681/
 
-let G = gravitational_constant
-
 fn depth(mass: Mass, radius: Length) -> Length =
-    G × mass / (gravity × radius) -> km
+    G × mass / (g0 × radius) -> km
 
 let earth_mass = 5.972e24 kg
 let earth_radius = 6371 km

+ 1 - 3
examples/xkcd_687.nbt

@@ -7,6 +7,4 @@ let earth_core_pressure = 3.5 million atmospheres
 let prius_milage = 50 miles per gallon
 let english_channel_min_width = 21 miles
 
-let c: Scalar = planck_energy / earth_core_pressure * prius_milage / english_channel_min_width
-
-print(c)
+print(planck_energy / earth_core_pressure * prius_milage / english_channel_min_width)

+ 26 - 15
modules/physics/constants.nbt

@@ -5,18 +5,22 @@ use units::si
 
 # The speed of light in vacuum
 let speed_of_light: Speed = 299_792_458 m / s
+let c = speed_of_light
 
 # The Newtonian constant of gravitation
 let gravitational_constant: Force × Length^2 / Mass^2 =  6.67430e-11 m³ / (kg s²)
+let G = gravitational_constant
 
 # Standard acceleration of gravity on earth
 let gravity: Acceleration = 9.80665 m / s²
+let g0 = gravity
 
 # The Planck constant
 let planck_constant = 6.62607015e-34 J / Hz
 
 # The reduced Planck constant
 let ℏ = planck_constant / 2π
+let h_bar = ℏ
 
 # Mass of the electron
 let electron_mass: Mass = 9.1093837015e-31 kg
@@ -26,19 +30,23 @@ let elementary_charge: Charge =  1.602176634e-19 C
 let electron_charge: Charge = elementary_charge
 
 # Magnetic constant (vacuum magnetic permeability)
-let µ0: Force / Current^2 =  1.25663706212e-6 N / A²
-let mu0 = µ0
+let magnetic_constant: Force / Current^2 =  1.25663706212e-6 N / A²
+let µ0 = magnetic_constant
+let mu0 = magnetic_constant
 
 # Electric constant ( vacuum electric permittivity)
-let ε0: Capacitance / Length = 8.8541878128e-12 F / m
-let eps0 = ε0
+let electric_constant: Capacitance / Length = 8.8541878128e-12 F / m
+let ε0 = electric_constant
+let eps0 = electric_constant
 
 # Bohr magneton
-let µ_B: Energy / MagneticFluxDensity = 9.2740100783e-24 J / T
+let bohr_magneton: Energy / MagneticFluxDensity = 9.2740100783e-24 J / T
+let µ_B = bohr_magneton
 
 # Fine structure constant
-let α: Scalar = 7.2973525693e-3
-let alpha = α
+let fine_structure_constant: Scalar = 7.2973525693e-3
+let α = fine_structure_constant
+let alpha = fine_structure_constant
 
 # Proton mass
 let proton_mass: Mass =  1.67262192369e-27 kg
@@ -47,28 +55,31 @@ let proton_mass: Mass =  1.67262192369e-27 kg
 let neutron_mass: Mass = 1.67492749804e-27 kg
 
 # Avogadro constant
-let N_A: 1 / AmountOfSubstance = 6.02214076e23 / mol
+let avogadro_constant: 1 / AmountOfSubstance = 6.02214076e23 / mol
+let N_A = avogadro_constant
 
 # Boltzmann constant
-let k_B: Energy / Temperature = 1.380649e-23 J / K
+let boltzmann_constant: Energy / Temperature = 1.380649e-23 J / K
+let k_B = boltzmann_constant
 
 # Ideal gas constant
-let R: Energy / (AmountOfSubstance × Temperature) = 8.31446261815324 J / (K mol)
+let gas_constant: Energy / (AmountOfSubstance × Temperature) = 8.31446261815324 J / (K mol)
+let R = gas_constant
 
 # Planck length
-let planck_length: Length = sqrt(ℏ gravitational_constant / speed_of_light^3) -> m
+let planck_length: Length = sqrt(ℏ G / c^3) -> m
 
 # Planck mass
-let planck_mass: Mass = sqrt(ℏ speed_of_light / gravitational_constant) -> kg
+let planck_mass: Mass = sqrt(ℏ c / G) -> kg
 
 # Planck time
-let planck_time: Time = sqrt(ℏ gravitational_constant / speed_of_light^5) -> s
+let planck_time: Time = sqrt(ℏ G / c^5) -> s
 
 # Planck temperature
-let planck_temperature: Temperature = sqrt(ℏ speed_of_light^5 / (gravitational_constant * k_B^2)) -> K
+let planck_temperature: Temperature = sqrt(ℏ c^5 / (G k_B^2)) -> K
 
 # Planck energy
-let planck_energy: Energy = sqrt(ℏ speed_of_light^5 / gravitational_constant) -> J
+let planck_energy: Energy = sqrt(ℏ c^5 / G) -> J
 
 # Bohr radius
 let bohr_radius: Length = 4 pi ε0 ℏ^2 / (electron_charge^2 electron_mass)

+ 3 - 3
modules/units/stoney.nbt

@@ -2,6 +2,6 @@
 
 use physics::constants
 
-unit stoney_length: Length = sqrt(gravitational_constant × electron_charge^2 / 4 π ε0 speed_of_light^4)
-unit stoney_mass: Mass = sqrt(electron_charge^2 / 4 π ε0 gravitational_constant)
-unit stoney_time: Time = sqrt(gravitational_constant × electron_charge^2 / 4 π ε0 speed_of_light^6)
+unit stoney_length: Length = sqrt(G × electron_charge^2 / 4 π ε0 c^4)
+unit stoney_mass: Mass = sqrt(electron_charge^2 / 4 π ε0 G)
+unit stoney_time: Time = sqrt(G × electron_charge^2 / 4 π ε0 c^6)