From 239589f2d622eb0271c2b33e37e80b9b559e1985 Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 21 Sep 2023 19:37:01 +0200 Subject: [PATCH 01/10] Draft: prelude with dimensionful angles --- examples/dimensionful_angles.nbt | 28 +++++++++++++ modules/dimensionful_angles/prelude.nbt | 56 +++++++++++++++++++++++++ numbat/modules/core/dimensions.nbt | 2 +- numbat/modules/units/si.nbt | 2 +- 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 examples/dimensionful_angles.nbt create mode 100644 modules/dimensionful_angles/prelude.nbt diff --git a/examples/dimensionful_angles.nbt b/examples/dimensionful_angles.nbt new file mode 100644 index 000000000..ec73fc001 --- /dev/null +++ b/examples/dimensionful_angles.nbt @@ -0,0 +1,28 @@ +# This file uses the dimensionful_angles prelude + +print("h = {planck_constant}") +print("ћ = {ћ}") +print("ȟ = {ȟ}") + +# harmonic oscillation +let ω = 2π rad / s +let t = 0.4 s +let amplitude = Sin(ω·t) +print("Amplitude: {amplitude}") + +# Tangential velocity +let r = 20 cm +let v: Speed = r ω / θC # This is one of the "text book formulas" that needs adaptation +print("Linear velocity: {v}") + +# Arc length +fn arc_length(radius: Length, θ: Angle) -> Length = radius × θ / θC +print(arc_length(1 m, 45°)) + +# Rotational energy +let mass = 1 kg +let radius = 1 m +let I: MomentOfInertia = mass × radius^2 / θC^2 +let ω_rot: AngularFrequency = 180° / 5 s +let E_rot: Energy = 1/2 * I * ω_rot^2 +print("E_rot = {E_rot -> J}") diff --git a/modules/dimensionful_angles/prelude.nbt b/modules/dimensionful_angles/prelude.nbt new file mode 100644 index 000000000..48d8c3d3b --- /dev/null +++ b/modules/dimensionful_angles/prelude.nbt @@ -0,0 +1,56 @@ +# The following prelude is based on a proposal to treat angles +# as dimensionful quantities [1]. +# +# +# Literature +# ---------- +# +# Pro: +# - [1] Angles in the SI: a detailed proposal for solving the problem, https://arxiv.org/abs/2108.05704 +# - [2] Angles are inherently neither length ratios nor dimensionless, https://arxiv.org/abs/1909.08389 +# - [3] Brownstein K R, Angles—let’s treat them squarely, Am. J. Phys. 65 605–14 (1997). +# - [4] Dimensionless units in the SI, https://arxiv.org/abs/1409.2794 +# +# Contra: +# - [4] Dimensional angles and universal constants, https://doi.org/10.1119/1.18964 +# - [5] M. Grötschel, H. Hanche-Olsen, H. Holden, Comment on ‘Angles are inherently neither length ratios nor dimensionless’. +# (and companion paper https://arxiv.org/abs/2011.05779v4) +# - [6] Comment on 'Angles in the SI: a detailed proposal for solving the problem', B P Leonard, https://iopscience.iop.org/article/10.1088/1681-7575/ac5433/meta +# (and reply to comment: https://iopscience.iop.org/article/10.1088/1681-7575/ac5434) +# +# Review: +# - [7] Implications of adopting plane angle as a base quantity in the SI, https://arxiv.org/pdf/1604.02373.pdf + +use core::scalar +use core::quantity +use core::dimensions + +use math::constants +use math::functions +use math::trigonometry_extra + +use units::si +use units::time +use units::misc + +use physics::temperature_conversion + +dimension AngularFrequency = Angle / Time +dimension AngularVelocity = Angle / Time +dimension AngularAcceleration = Angle / Time^2 + +# The "Cotes angle" +let theta_C = 1 rad +let θC = theta_C + +fn Sin(θ: Angle) -> Scalar = sin(θ / θC) +fn Cos(θ: Angle) -> Scalar = cos(θ / θC) +fn Tan(θ: Angle) -> Scalar = tan(θ / θC) +fn ASin(x: Scalar) -> Angle = asin(x) × θC +fn ACos(x: Scalar) -> Angle = acos(x) × θC +fn ATan(x: Scalar) -> Angle = atan(x) × θC +fn ATan2(y: Q, x: Q) -> Angle = atan2(y, x) × θC + +let planck_constant: Action = 6.62607015e-34 J s +let ћ: AngularMomentum = planck_constant / 2π θC +let ȟ: Action = planck_constant / 2π diff --git a/numbat/modules/core/dimensions.nbt b/numbat/modules/core/dimensions.nbt index 847372565..3fdb7181c 100644 --- a/numbat/modules/core/dimensions.nbt +++ b/numbat/modules/core/dimensions.nbt @@ -1,6 +1,6 @@ ### Physical dimensions -dimension Angle = 1 # SI: plane angle +dimension Angle # SI: plane angle dimension SolidAngle = Angle^2 dimension Length diff --git a/numbat/modules/units/si.nbt b/numbat/modules/units/si.nbt index 947bb04a0..91855421c 100644 --- a/numbat/modules/units/si.nbt +++ b/numbat/modules/units/si.nbt @@ -35,7 +35,7 @@ unit candela: LuminousIntensity @metric_prefixes @aliases(radians, rad: short) -unit radian: Angle = meter / meter +unit radian: Angle @metric_prefixes @aliases(steradians, sr: short) From 3258306652fa0dde5bbd931f1cd8802f3d216566 Mon Sep 17 00:00:00 2001 From: David Peter Date: Fri, 22 Sep 2023 23:00:02 +0200 Subject: [PATCH 02/10] Fix merge conflict --- {modules => numbat/modules}/dimensionful_angles/prelude.nbt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {modules => numbat/modules}/dimensionful_angles/prelude.nbt (100%) diff --git a/modules/dimensionful_angles/prelude.nbt b/numbat/modules/dimensionful_angles/prelude.nbt similarity index 100% rename from modules/dimensionful_angles/prelude.nbt rename to numbat/modules/dimensionful_angles/prelude.nbt From d264493ddfdd16a4cc03a9420e9366bcfabcf031 Mon Sep 17 00:00:00 2001 From: David Peter Date: Fri, 22 Sep 2023 23:06:12 +0200 Subject: [PATCH 03/10] Add RPM --- examples/dimensionful_angles.nbt | 3 +++ numbat/modules/dimensionful_angles/prelude.nbt | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/examples/dimensionful_angles.nbt b/examples/dimensionful_angles.nbt index ec73fc001..0e75d6451 100644 --- a/examples/dimensionful_angles.nbt +++ b/examples/dimensionful_angles.nbt @@ -15,6 +15,9 @@ let r = 20 cm let v: Speed = r ω / θC # This is one of the "text book formulas" that needs adaptation print("Linear velocity: {v}") +# Rotational motion +assert_eq(60 rpm, 360° / s) + # Arc length fn arc_length(radius: Length, θ: Angle) -> Length = radius × θ / θC print(arc_length(1 m, 45°)) diff --git a/numbat/modules/dimensionful_angles/prelude.nbt b/numbat/modules/dimensionful_angles/prelude.nbt index 48d8c3d3b..a5cf98f62 100644 --- a/numbat/modules/dimensionful_angles/prelude.nbt +++ b/numbat/modules/dimensionful_angles/prelude.nbt @@ -54,3 +54,8 @@ fn ATan2(y: Q, x: Q) -> Angle = atan2(y, x) × θC let planck_constant: Action = 6.62607015e-34 J s let ћ: AngularMomentum = planck_constant / 2π θC let ȟ: Action = planck_constant / 2π + +unit rev: Angle = 360° + +@aliases(RPM: short) +unit rpm: Angle / Time = rev/min From c7f4657c9f1fd777003a334533a9bc940bb6405c Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 28 Sep 2023 22:01:34 +0200 Subject: [PATCH 04/10] Fix unit tests --- examples/consistency_others.nbt | 2 +- examples/consistency_si.nbt | 2 - examples/dimensionful_angles.nbt | 2 +- examples/projectile_motion.nbt | 6 +- examples/readme-demo.nbt | 4 +- examples/unicode.nbt | 2 +- numbat/modules/core/dimensions.nbt | 2 + .../modules/dimensionful_angles/prelude.nbt | 61 ------------------- numbat/modules/physics/constants.nbt | 9 +-- numbat/modules/prelude.nbt | 31 ++++++++++ numbat/modules/units/hartree.nbt | 2 +- numbat/modules/units/misc.nbt | 2 +- numbat/modules/units/planck.nbt | 10 +-- numbat/modules/units/si.nbt | 4 ++ numbat/modules/units/stoney.nbt | 6 +- numbat/tests/interpreter.rs | 16 ++--- 16 files changed, 68 insertions(+), 93 deletions(-) delete mode 100644 numbat/modules/dimensionful_angles/prelude.nbt diff --git a/examples/consistency_others.nbt b/examples/consistency_others.nbt index aac055c57..da7b5f4a8 100644 --- a/examples/consistency_others.nbt +++ b/examples/consistency_others.nbt @@ -51,7 +51,7 @@ assert_eq(1 calorie, 4.184 J) assert_eq(1 BTU, 1055.05585262 J) assert_eq(1 lbf, 4.448222 N) assert_eq(1 ozf, (4.448222 / 16.0) N, 1e-5 N) -assert_eq(60 RPM, 1 Hz) +assert_eq(60 RPM, 1 rev / s) assert_eq(1 fortnight, 2 week) assert_eq(1 mmHg, 133.322387415 Pa, 1e-5 Pa) assert_eq(1 PSI, 6.894757 kPa) diff --git a/examples/consistency_si.nbt b/examples/consistency_si.nbt index e22487694..5e70ce51c 100644 --- a/examples/consistency_si.nbt +++ b/examples/consistency_si.nbt @@ -1,5 +1,3 @@ -assert_eq(1 rad , 1 m² / m²) -assert_eq(1 sr , 1 m² / m²) assert_eq(1 Hz , 1 / s) assert_eq(1 N , 1 kg * m / s^2) assert_eq(1 Pa , 1 N / m²) diff --git a/examples/dimensionful_angles.nbt b/examples/dimensionful_angles.nbt index 0e75d6451..ba4eb01ff 100644 --- a/examples/dimensionful_angles.nbt +++ b/examples/dimensionful_angles.nbt @@ -1,7 +1,7 @@ # This file uses the dimensionful_angles prelude print("h = {planck_constant}") -print("ћ = {ћ}") +print("ℏ = {ℏ}") print("ȟ = {ȟ}") # harmonic oscillation diff --git a/examples/projectile_motion.nbt b/examples/projectile_motion.nbt index 426821dda..714fa5b7e 100644 --- a/examples/projectile_motion.nbt +++ b/examples/projectile_motion.nbt @@ -1,8 +1,8 @@ # https://en.wikipedia.org/wiki/Projectile_motion -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 +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 assert_eq(max_height(10 m/s, 45 deg), 2.55 m, 1 cm) assert_eq(max_distance(10 m/s, 45 deg), 10.20 m, 1 cm) diff --git a/examples/readme-demo.nbt b/examples/readme-demo.nbt index 613d49462..de85bff7d 100644 --- a/examples/readme-demo.nbt +++ b/examples/readme-demo.nbt @@ -2,6 +2,6 @@ use units::currencies 8 km / (1 h + 25 min) 140 € -> GBP -atan2(30 cm, 1 m) -> deg -let ω = 2π c / 660 nm +ATan2(30 cm, 1 m) -> deg +let ω = 2π θC c / 660 nm print("Energy of red photon: {ℏ ω -> eV}") diff --git a/examples/unicode.nbt b/examples/unicode.nbt index 78487a9f7..48eb98f5c 100644 --- a/examples/unicode.nbt +++ b/examples/unicode.nbt @@ -3,7 +3,7 @@ let ν = c / λ assert_eq(ν, 499.7 GHz, 0.1 GHz) -let ω = 2 π ν +let ω = 2 π θC ν let E = ℏ ω assert_eq(E, 2 meV, 0.1 meV) diff --git a/numbat/modules/core/dimensions.nbt b/numbat/modules/core/dimensions.nbt index 3fdb7181c..7bda00775 100644 --- a/numbat/modules/core/dimensions.nbt +++ b/numbat/modules/core/dimensions.nbt @@ -14,6 +14,8 @@ dimension Speed = Length / Time # also: velocity dimension Acceleration = Length / Time^2 dimension Jerk = Length / Time^3 dimension FlowRate = Volume / Time +dimension AngularFrequency = Angle / Time +dimension AngularAcceleration = Angle / Time^2 dimension Mass dimension Momentum = Mass × Speed diff --git a/numbat/modules/dimensionful_angles/prelude.nbt b/numbat/modules/dimensionful_angles/prelude.nbt deleted file mode 100644 index a5cf98f62..000000000 --- a/numbat/modules/dimensionful_angles/prelude.nbt +++ /dev/null @@ -1,61 +0,0 @@ -# The following prelude is based on a proposal to treat angles -# as dimensionful quantities [1]. -# -# -# Literature -# ---------- -# -# Pro: -# - [1] Angles in the SI: a detailed proposal for solving the problem, https://arxiv.org/abs/2108.05704 -# - [2] Angles are inherently neither length ratios nor dimensionless, https://arxiv.org/abs/1909.08389 -# - [3] Brownstein K R, Angles—let’s treat them squarely, Am. J. Phys. 65 605–14 (1997). -# - [4] Dimensionless units in the SI, https://arxiv.org/abs/1409.2794 -# -# Contra: -# - [4] Dimensional angles and universal constants, https://doi.org/10.1119/1.18964 -# - [5] M. Grötschel, H. Hanche-Olsen, H. Holden, Comment on ‘Angles are inherently neither length ratios nor dimensionless’. -# (and companion paper https://arxiv.org/abs/2011.05779v4) -# - [6] Comment on 'Angles in the SI: a detailed proposal for solving the problem', B P Leonard, https://iopscience.iop.org/article/10.1088/1681-7575/ac5433/meta -# (and reply to comment: https://iopscience.iop.org/article/10.1088/1681-7575/ac5434) -# -# Review: -# - [7] Implications of adopting plane angle as a base quantity in the SI, https://arxiv.org/pdf/1604.02373.pdf - -use core::scalar -use core::quantity -use core::dimensions - -use math::constants -use math::functions -use math::trigonometry_extra - -use units::si -use units::time -use units::misc - -use physics::temperature_conversion - -dimension AngularFrequency = Angle / Time -dimension AngularVelocity = Angle / Time -dimension AngularAcceleration = Angle / Time^2 - -# The "Cotes angle" -let theta_C = 1 rad -let θC = theta_C - -fn Sin(θ: Angle) -> Scalar = sin(θ / θC) -fn Cos(θ: Angle) -> Scalar = cos(θ / θC) -fn Tan(θ: Angle) -> Scalar = tan(θ / θC) -fn ASin(x: Scalar) -> Angle = asin(x) × θC -fn ACos(x: Scalar) -> Angle = acos(x) × θC -fn ATan(x: Scalar) -> Angle = atan(x) × θC -fn ATan2(y: Q, x: Q) -> Angle = atan2(y, x) × θC - -let planck_constant: Action = 6.62607015e-34 J s -let ћ: AngularMomentum = planck_constant / 2π θC -let ȟ: Action = planck_constant / 2π - -unit rev: Angle = 360° - -@aliases(RPM: short) -unit rpm: Angle / Time = rev/min diff --git a/numbat/modules/physics/constants.nbt b/numbat/modules/physics/constants.nbt index 49f57692a..4e12b6869 100644 --- a/numbat/modules/physics/constants.nbt +++ b/numbat/modules/physics/constants.nbt @@ -19,8 +19,9 @@ let g0 = gravity let planck_constant = 6.62607015e-34 J / Hz # The reduced Planck constant -let ℏ: AngularMomentum = planck_constant / 2π +let ℏ: AngularMomentum = planck_constant / 2π θC let h_bar = ℏ +let ȟ: Action = planck_constant / 2π # Mass of the electron let electron_mass: Mass = 9.1093837015e-31 kg @@ -30,12 +31,12 @@ let elementary_charge: ElectricCharge = 1.602176634e-19 C let electron_charge: ElectricCharge = elementary_charge # Magnetic constant (vacuum magnetic permeability) -let magnetic_constant: MagneticPermeability = 1.25663706212e-6 N / A² +let magnetic_constant: MagneticPermeability = 1.25663706212e-6 N / A² / rad let µ0 = magnetic_constant let mu0 = magnetic_constant # Electric constant ( vacuum electric permittivity) -let electric_constant: ElectricPermittivity = 8.8541878128e-12 F / m +let electric_constant: ElectricPermittivity = 8.8541878128e-12 F / m × rad let ε0 = electric_constant let eps0 = electric_constant @@ -70,5 +71,5 @@ let gas_constant: Energy / (AmountOfSubstance × Temperature) = 8.31446261815324 let R = gas_constant # Bohr radius -let bohr_radius: Length = 4 pi ε0 ℏ^2 / (electron_charge^2 electron_mass) +let bohr_radius: Length / Angle = 4 pi ε0 ℏ^2 / (electron_charge^2 electron_mass) -> m/rad let a0 = bohr_radius diff --git a/numbat/modules/prelude.nbt b/numbat/modules/prelude.nbt index 7d6a2b095..bd702ebaf 100644 --- a/numbat/modules/prelude.nbt +++ b/numbat/modules/prelude.nbt @@ -1,3 +1,26 @@ +# The following prelude is based on a proposal to treat angles +# as dimensionful quantities [1]. +# +# +# Literature +# ---------- +# +# Pro: +# - [1] Angles in the SI: a detailed proposal for solving the problem, https://arxiv.org/abs/2108.05704 +# - [2] Angles are inherently neither length ratios nor dimensionless, https://arxiv.org/abs/1909.08389 +# - [3] Brownstein K R, Angles—let’s treat them squarely, Am. J. Phys. 65 605–14 (1997). +# - [4] Dimensionless units in the SI, https://arxiv.org/abs/1409.2794 +# +# Contra: +# - [4] Dimensional angles and universal constants, https://doi.org/10.1119/1.18964 +# - [5] M. Grötschel, H. Hanche-Olsen, H. Holden, Comment on ‘Angles are inherently neither length ratios nor dimensionless’. +# (and companion paper https://arxiv.org/abs/2011.05779v4) +# - [6] Comment on 'Angles in the SI: a detailed proposal for solving the problem', B P Leonard, https://iopscience.iop.org/article/10.1088/1681-7575/ac5433/meta +# (and reply to comment: https://iopscience.iop.org/article/10.1088/1681-7575/ac5434) +# +# Review: +# - [7] Implications of adopting plane angle as a base quantity in the SI, https://arxiv.org/pdf/1604.02373.pdf + use core::scalar use core::quantities use core::dimensions @@ -26,3 +49,11 @@ use units::placeholder use physics::constants use physics::temperature_conversion + +fn Sin(θ: Angle) -> Scalar = sin(θ / θC) +fn Cos(θ: Angle) -> Scalar = cos(θ / θC) +fn Tan(θ: Angle) -> Scalar = tan(θ / θC) +fn ASin(x: Scalar) -> Angle = asin(x) × θC +fn ACos(x: Scalar) -> Angle = acos(x) × θC +fn ATan(x: Scalar) -> Angle = atan(x) × θC +fn ATan2(y: Q, x: Q) -> Angle = atan2(y, x) × θC diff --git a/numbat/modules/units/hartree.nbt b/numbat/modules/units/hartree.nbt index e9ab2d412..417a3300f 100644 --- a/numbat/modules/units/hartree.nbt +++ b/numbat/modules/units/hartree.nbt @@ -3,4 +3,4 @@ use physics::constants @aliases(hartrees) unit hartree: Energy = ℏ^2 / (electron_mass a0^2) -unit bohr: Length = a0 +unit bohr: Length = a0 × θC diff --git a/numbat/modules/units/misc.nbt b/numbat/modules/units/misc.nbt index ca8b460b9..1206d90c0 100644 --- a/numbat/modules/units/misc.nbt +++ b/numbat/modules/units/misc.nbt @@ -37,7 +37,7 @@ unit horsepower: Power = 735.49875 W unit revolution: Angle = 360° @aliases(RPM: short) -unit rpm: Frequency = 1 / minute +unit rpm: Angle / Time = rev/min unit mmHg: Pressure = 133.322387415 pascal diff --git a/numbat/modules/units/planck.nbt b/numbat/modules/units/planck.nbt index f214cdf53..886abfb1e 100644 --- a/numbat/modules/units/planck.nbt +++ b/numbat/modules/units/planck.nbt @@ -3,16 +3,16 @@ use physics::constants # Planck length -unit planck_length: Length = sqrt(ℏ G / c^3) -> m +unit planck_length: Length = sqrt(ȟ G / c^3) -> m # Planck mass -unit planck_mass: Mass = sqrt(ℏ c / G) -> kg +unit planck_mass: Mass = sqrt(ȟ c / G) -> kg # Planck time -unit planck_time: Time = sqrt(ℏ G / c^5) -> s +unit planck_time: Time = sqrt(ȟ G / c^5) -> s # Planck temperature -unit planck_temperature: Temperature = sqrt(ℏ c^5 / (G k_B^2)) -> K +unit planck_temperature: Temperature = sqrt(ȟ c^5 / (G k_B^2)) -> K # Planck energy -unit planck_energy: Energy = sqrt(ℏ c^5 / G) -> J +unit planck_energy: Energy = sqrt(ȟ c^5 / G) -> J diff --git a/numbat/modules/units/si.nbt b/numbat/modules/units/si.nbt index 91855421c..6d69a3ee5 100644 --- a/numbat/modules/units/si.nbt +++ b/numbat/modules/units/si.nbt @@ -37,6 +37,10 @@ unit candela: LuminousIntensity @aliases(radians, rad: short) unit radian: Angle +# The "Cotes angle" +let theta_C = 1 rad +let θC = theta_C + @metric_prefixes @aliases(steradians, sr: short) unit steradian: SolidAngle = radian^2 diff --git a/numbat/modules/units/stoney.nbt b/numbat/modules/units/stoney.nbt index 4be3be2f5..c80be1b63 100644 --- a/numbat/modules/units/stoney.nbt +++ b/numbat/modules/units/stoney.nbt @@ -2,6 +2,6 @@ use physics::constants -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) +#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) diff --git a/numbat/tests/interpreter.rs b/numbat/tests/interpreter.rs index 494c748b5..b71a304b6 100644 --- a/numbat/tests/interpreter.rs +++ b/numbat/tests/interpreter.rs @@ -147,8 +147,8 @@ fn test_function_inverses() { #[test] fn test_math() { - expect_output("sin(90°)", "1"); - expect_output("sin(30°)", "0.5"); + expect_output("Sin(90°)", "1"); + expect_output("Sin(30°)", "0.5"); expect_output("sin(pi/2)", "1"); expect_output("atan2(10, 0) / (pi / 2)", "1"); @@ -174,12 +174,12 @@ fn test_incompatible_dimension_errors() { expect_exact_failure( "kg m / s^2 + kg m^2", " left hand side: Length × Mass × Time⁻² [= Force]\n\ - right hand side: Length² × Mass [= MomentOfInertia]\n\n\ + right hand side: Length² × Mass\n\n\ Suggested fix: multiply left hand side by Length × Time²", ); expect_exact_failure( "1 + m", - " left hand side: Scalar [= Angle, Scalar, SolidAngle]\n\ + " left hand side: Scalar [= Scalar]\n\ right hand side: Length\n\n\ Suggested fix: multiply left hand side by Length", ); @@ -198,7 +198,7 @@ fn test_incompatible_dimension_errors() { expect_exact_failure( "kW -> J", " left hand side: Length² × Mass × Time⁻³ [= Power]\n\ - right hand side: Length² × Mass × Time⁻² [= Energy, Torque]\n\n\ + right hand side: Length² × Mass × Time⁻² [= Energy]\n\n\ Suggested fix: multiply left hand side by Time", ); } @@ -250,14 +250,14 @@ fn test_misc_examples() { expect_output("2min + 30s -> sec", "150 s"); expect_output("4/3 * pi * (6000km)³", "9.04779e11 km³"); expect_output("40kg * 9.8m/s^2 * 150cm", "588 kg·m²/s²"); - expect_output("sin(30°)", "0.5"); + expect_output("Sin(30°)", "0.5"); expect_output("60mph -> m/s", "26.8224 m/s"); expect_output("240km/day -> km/h", "10 km/h"); expect_output("1mrad -> °", "0.0572958°"); expect_output("52weeks -> days", "364 day"); expect_output("5in + 2ft -> cm", "73.66 cm"); - expect_output("atan(30cm / 2m) -> deg", "8.53077°"); + expect_output("ATan(30cm / 2m) -> deg", "8.53077°"); expect_output("6Mbit/s * 1.5h -> GB", "4.05 GB"); expect_output("6Mbit/s * 1.5h -> GiB", "3.77186 GiB"); @@ -269,7 +269,7 @@ fn test_misc_examples() { #[test] fn test_bohr_radius_regression() { // Make sure that the unit is 'm', and not 'F·J²/(C²·kg·m·Hz²)', like we had before - expect_output("bohr_radius", "5.29177e-11 m"); + expect_output("bohr_radius", "5.29177e-11 m/rad"); } #[test] From 81645d65d76c6212e853ea0b3243dede86b46700 Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 28 Sep 2023 22:03:16 +0200 Subject: [PATCH 05/10] Use AngularFrequency --- numbat/modules/core/dimensions.nbt | 2 +- numbat/modules/units/misc.nbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/numbat/modules/core/dimensions.nbt b/numbat/modules/core/dimensions.nbt index 7bda00775..3384b8c3a 100644 --- a/numbat/modules/core/dimensions.nbt +++ b/numbat/modules/core/dimensions.nbt @@ -26,7 +26,7 @@ dimension Pressure = Force / Area = Energy / Volume # also: stress dimension Action = Energy × Time dimension MassDensity = Mass / Length^3 dimension MomentOfInertia = Mass × Length^2 / Angle^2 -dimension AngularMomentum = MomentOfInertia × Angle / Time = Mass × Length^2 / Time / Angle +dimension AngularMomentum = MomentOfInertia × AngularFrequency = Mass × Length^2 / Time / Angle dimension Torque = Length × Force / Angle # also: moment of force dimension EnergyDensity = Energy / Volume diff --git a/numbat/modules/units/misc.nbt b/numbat/modules/units/misc.nbt index 1206d90c0..dfa9c0233 100644 --- a/numbat/modules/units/misc.nbt +++ b/numbat/modules/units/misc.nbt @@ -37,7 +37,7 @@ unit horsepower: Power = 735.49875 W unit revolution: Angle = 360° @aliases(RPM: short) -unit rpm: Angle / Time = rev/min +unit rpm: AngularFrequency = rev/min unit mmHg: Pressure = 133.322387415 pascal From ad5679ae6ff51675c9ad7d08c3f20f1b030ba98a Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 28 Sep 2023 22:04:20 +0200 Subject: [PATCH 06/10] Proper definition for rev --- numbat/modules/units/misc.nbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numbat/modules/units/misc.nbt b/numbat/modules/units/misc.nbt index dfa9c0233..8a63ddad0 100644 --- a/numbat/modules/units/misc.nbt +++ b/numbat/modules/units/misc.nbt @@ -37,7 +37,7 @@ unit horsepower: Power = 735.49875 W unit revolution: Angle = 360° @aliases(RPM: short) -unit rpm: AngularFrequency = rev/min +unit rpm: AngularFrequency = revolutions per minute unit mmHg: Pressure = 133.322387415 pascal From 8779de9d0ebb6282111ce50a8bca04ff2fdf16ad Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 28 Sep 2023 22:35:50 +0200 Subject: [PATCH 07/10] Change deploy path --- numbat-wasm/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numbat-wasm/deploy.sh b/numbat-wasm/deploy.sh index a7369bfa5..0699f6f4f 100644 --- a/numbat-wasm/deploy.sh +++ b/numbat-wasm/deploy.sh @@ -10,5 +10,5 @@ wasm-pack build --features=wee_alloc npm run build ) -rsync --archive --stats --progress --human-readable -r www/ shark.fish:numbat.dev/ -rsync --archive --stats --progress --human-readable -r www/dist/ shark.fish:numbat.dev/ +rsync --archive --stats --progress --human-readable -r www/ shark.fish:numbat.dev/angles/ +rsync --archive --stats --progress --human-readable -r www/dist/ shark.fish:numbat.dev/angles/ From bca052791ccf79d5cb67ee9a8a42cc287c58a3c9 Mon Sep 17 00:00:00 2001 From: David Peter Date: Tue, 10 Oct 2023 12:53:45 +0200 Subject: [PATCH 08/10] Add additional assertion for RPM --- examples/consistency_others.nbt | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/consistency_others.nbt b/examples/consistency_others.nbt index da7b5f4a8..fc7a74074 100644 --- a/examples/consistency_others.nbt +++ b/examples/consistency_others.nbt @@ -52,6 +52,7 @@ assert_eq(1 BTU, 1055.05585262 J) assert_eq(1 lbf, 4.448222 N) assert_eq(1 ozf, (4.448222 / 16.0) N, 1e-5 N) assert_eq(60 RPM, 1 rev / s) +assert_eq(60 RPM, 360° / s) assert_eq(1 fortnight, 2 week) assert_eq(1 mmHg, 133.322387415 Pa, 1e-5 Pa) assert_eq(1 PSI, 6.894757 kPa) From c171c44e56f92489ccd538940c9cb0c41ca0bc65 Mon Sep 17 00:00:00 2001 From: David Peter Date: Tue, 10 Oct 2023 12:56:23 +0200 Subject: [PATCH 09/10] Uncomment alternative expression --- numbat/modules/core/dimensions.nbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numbat/modules/core/dimensions.nbt b/numbat/modules/core/dimensions.nbt index 3384b8c3a..c1ad67d47 100644 --- a/numbat/modules/core/dimensions.nbt +++ b/numbat/modules/core/dimensions.nbt @@ -45,7 +45,7 @@ dimension Inductance = MagneticFlux / Current dimension ElectricChargeDensity = ElectricCharge / Volume dimension CurrentDensity = Current / Area dimension ElectricDipoleMoment = ElectricCharge × Length -dimension MagneticDipoleMoment = Current × Area #= Torque / MagneticFluxDensity +dimension MagneticDipoleMoment = Current × Area = Torque / MagneticFluxDensity * Angle dimension ElectricFieldStrength = Voltage / Length dimension ElectricDisplacementFieldStrength = ElectricCharge / Area dimension ElectricPermittivity = Time^4 × Current^2 / Mass / Length^3 × Angle = ElectricDisplacementFieldStrength / ElectricFieldStrength × Angle From bfbcb50d0c7eaa6e4a001f42398472f6c4eaea4b Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 11 Oct 2023 21:33:14 +0200 Subject: [PATCH 10/10] Modify deploy script --- numbat-wasm/deploy.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/numbat-wasm/deploy.sh b/numbat-wasm/deploy.sh index 8489426ae..c90566a82 100644 --- a/numbat-wasm/deploy.sh +++ b/numbat-wasm/deploy.sh @@ -4,11 +4,6 @@ set -euo pipefail current_branch=$(git rev-parse --abbrev-ref HEAD) -if [[ "$current_branch" != "master" ]]; then - echo "You are currently on the '$current_branch' branch, not 'master'." - exit 1 -fi - wasm-pack build --features=wee_alloc (