Skip to content

Commit f861566

Browse files
Spell mathematical and physics terms
1 parent 09ed32b commit f861566

8 files changed

Lines changed: 135 additions & 52 deletions

File tree

QuantumMechanics/Dimension+Elementary.swift

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,41 @@ extension UnitMass {
5151
private static let x = 1.78266192
5252

5353
/// Amount in electronvolts (eV/*c*²).
54-
@available(*, deprecated, renamed: "electronvoltsPerC²")
55-
public static let electronvolt = electronvoltsPerC²
54+
@available(*, deprecated, renamed: "electronvoltsPerLightSpeedSquared")
55+
public static let electronvolt = electronvoltsPerLightSpeedSquared
5656

5757
/// Amount in electronvolts per the square of the speed of light (eV/*c*²).
58-
public static let electronvoltsPerC² = UnitMass(
59-
symbol: "eV",
58+
///
59+
/// - SeeAlso: ``Foundation/UnitSpeed/lightSquared``
60+
/// - SeeAlso: ``electronvolt``
61+
public static let electronvoltsPerLightSpeedSquared = UnitMass(
62+
symbol: "eV/c²",
6063
converter: UnitConverterLinear(coefficient: x * pow(10, -36))
6164
)
6265

6366
/// Amount in gigaelectronvolts (GeV/*c*²).
64-
@available(*, deprecated, renamed: "gigaelectronvoltsPerC²")
65-
public static let gigaelectronvolt = gigaelectronvoltsPerC²
67+
@available(*, deprecated, renamed: "gigaelectronvoltsPerLightSpeedSquared")
68+
public static let gigaelectronvolt = gigaelectronvoltsPerLightSpeedSquared
6669

6770
/// Amount in gigaelectronvolts per the square of the speed of light (GeV/*c*²).
68-
public static let gigaelectronvoltsPerC² = UnitMass(
69-
symbol: "GeV",
71+
///
72+
/// - SeeAlso: ``Foundation/UnitSpeed/lightSquared``
73+
public static let gigaelectronvoltsPerLightSpeedSquared = UnitMass(
74+
symbol: "GeV/c²",
7075
converter: UnitConverterLinear(coefficient: x * pow(10, -27))
7176
)
7277

7378
/// Amount in megaelectronvolts (MeV/*c*²).
74-
@available(*, deprecated, renamed: "megaelectronvoltsPerC²")
75-
public static let megaelectronvolt = megaelectronvoltsPerC²
79+
///
80+
/// - SeeAlso: ``Foundation/UnitSpeed/lightSquared``
81+
@available(*, deprecated, renamed: "megaelectronvoltsPerLightSpeedSquared")
82+
public static let megaelectronvolt = megaelectronvoltsPerLightSpeedSquared
7683

7784
/// Amount in gigaelectronvolts per the square of the speed of light (GeV/*c*²).
78-
public static let megaelectronvoltsPerC² = UnitMass(
79-
symbol: "MeV",
85+
///
86+
/// - SeeAlso: ``Foundation/UnitSpeed/lightSquared``
87+
public static let megaelectronvoltsPerLightSpeedSquared = UnitMass(
88+
symbol: "MeV/c²",
8089
converter: UnitConverterLinear(coefficient: x * pow(10, -30))
8190
)
8291
}

QuantumMechanics/Field/Manifold.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,35 @@ public protocol Manifold {
3131
// classical mechanics. However, SourceKitService crashes when such type is extended to conform to
3232
// Differentiable as of Swift 6.2-snapshot-2025-08-21.
3333

34-
/// Calculates the Lagrangian over the given coordinate and moment in time.
34+
/// Calculates the Lagrangian *L* over the given coordinate and moment in time.
3535
///
36-
/// The Lagrangian *L* is a smooth, scalar function on the tangent bundle (the union of every
37-
/// tangent space at all coordinates in which lies the velocity associated to each of them; i.e.,
38-
/// a bundle whose coordinates are (qₙ, q̇ₙ)) of this ``Manifold``. It is the density with which `q`
39-
/// moves over `t`, part of the formula for an action *S* (the path of such coordinate):
36+
/// The Lagrangian is a smooth, scalar function on the tangent bundle (the union of every tangent
37+
/// space at all coordinates in which lies the velocity associated to each of them; i.e., a bundle
38+
/// whose coordinates are (qₙ, q̇ₙ)) of this ``Manifold``. It is the density with which `q` moves
39+
/// over `t`, part of the formula for an action *S* (the path of such coordinate):
4040
///
4141
/// **S[q] = ∫ᵗ²ₜ₁ *L*(q, q̇, t) × ∂*t***; or simply **S = ∫ᵗ²ₜ₁ *L* × ∂*t***.
4242
///
4343
/// - Parameters:
44-
/// - q: Coordinate *q* at which the configuration is located.
45-
/// - : Rate of change of `q` over `t`, *q*’(*t*); its velocity.
46-
/// - t: Time at which the configuration is.
44+
/// - coordinate: Coordinate *q* at which the configuration is located.
45+
/// - velocity: Rate of change of `q` over `t`, *q*’(*t*); its velocity.
46+
/// - time: Time at which the configuration is.
4747
/// - Returns: A scalar in a Lagrangian density 𝐿, determined by the type of coordinate of this
4848
/// ``Manifold``.
49-
@differentiable(reverse,wrt: (q,))
50-
func L(q: Coordinate,: Coordinate.TangentVector, t: Double) -> Double
49+
@differentiable(reverse,wrt: (coordinate, velocity))
50+
func lagrangian(
51+
coordinate: Coordinate,
52+
velocity: Coordinate.TangentVector,
53+
time: Double
54+
) -> Double
5155

5256
/// Calculates the potential energy *V* = E - E₀, scalar whose gradient outputs a force, in this
5357
/// ``Manifold`` at a given coordinate and a specified time.
5458
///
5559
/// - Parameters:
56-
/// - q: Coordinate *q* at which the configuration is located.
57-
/// - t: Time at which the configuration is.
60+
/// - coordinate: Coordinate *q* at which the configuration is located.
61+
/// - time: Time at which the configuration is.
5862
/// - Returns: The potential energy *V* in eV.
5963
/// - SeeAlso: ``Foundation/UnitEnergy/electronvolts``
60-
func V(q: Double, t: Double) -> Double
64+
func potentialEnergy(coordinate: Double, time: Double) -> Double
6165
}

QuantumMechanics/Field/_RealLine.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,34 @@ public struct _RealLine {
3333
}
3434

3535
extension _RealLine: Manifold {
36-
@differentiable(reverse,wrt: (q,))
37-
public func L(q: Double,: Double.TangentVector, t: Double) -> Double { T(:) - V(q: q, t: t) }
36+
@differentiable(reverse,wrt: (coordinate, velocity))
37+
public func lagrangian(coordinate: Double, velocity: Double.TangentVector, time: Double) -> Double
38+
{ kineticTerm(velocity: velocity) - potentialEnergy(coordinate: coordinate, time: time) }
3839

3940
/// Potential energy *V* = E - E₀, scalar whose gradient outputs a force, at the given coordinate
4041
/// and time. Since this ``RealLine`` exists only for testing purposes and strives to be as simple
4142
/// as possible in terms of calculus, its *V* at any coordinate and time will always be zero.
4243
///
4344
/// - Parameters:
44-
/// - q: Coordinate *q* at which the configuration is located.
45-
/// - t: Time at which the configuration is.
45+
/// - coordinate: Coordinate *q* at which the configuration is located.
46+
/// - time: Time at which the configuration is.
4647
/// - Returns: Zero; this implementation of a real line contains no potential energy.
47-
public func V(q: Double, t: Double) -> Double { 0 }
48+
public func potentialEnergy(coordinate: Double, time: Double) -> Double { 0 }
4849

49-
/// The kinetic term describes the amount of energy used by an object in motion for it to perform
50-
/// such movement.
51-
func T(: Double) -> Double { (γ(v:) - 1) * mass }
50+
/// The kinetic term describes the amount of energy of the motion of a coordinate.
51+
///
52+
/// - Parameter velocity: Velocity of the coordinate in m/s.
53+
func kineticTerm(velocity: Double) -> Double { (lorentzFactor(velocity: velocity) - 1) * mass }
5254

5355
/// The Lorentz factor *γ* quantifies the dilation of time, contraction of length and energy
5456
/// relativization in a rest frame in relation to an event occurring at the given velocity `v`.
5557
///
56-
/// - Parameter v: Velocity of the event in m/s.
58+
/// - Parameter velocity: Velocity of the event in m/s.
5759
/// - Returns: The dimensionless change in the system in which this ``RealLine`` is for the
5860
/// inertial observer of the event.
59-
private func γ(v: Double) -> Double {
60-
1 / (1 - pow(v, 2) / c²._converted(to: .metersPerSecond).value).squareRoot()
61+
private func lorentzFactor(velocity: Double) -> Double {
62+
1
63+
/ (1 - pow(velocity, 2) / UnitSpeed.lightSquared.converter.baseUnitValue(fromValue: 1))
64+
.squareRoot()
6165
}
6266
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// ===-------------------------------------------------------------------------------------------===
2+
// Copyright © 2025 Deus
3+
//
4+
// This file is part of the Deus open-source project.
5+
//
6+
// This program is free software: you can redistribute it and/or modify it under the terms of the
7+
// GNU General Public License as published by the Free Software Foundation, either version 3 of the
8+
// License, or (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
11+
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License along with this program. If
15+
// not, see https://www.gnu.org/licenses.
16+
// ===-------------------------------------------------------------------------------------------===
17+
18+
import Foundation
19+
20+
/// The speed of light.
21+
///
22+
/// - SeeAlso: ``cSquared``
23+
@available(*, deprecated, message: "The speed of light c is now a unit (UnitSpeed.light).")
24+
public let c = Measurement(value: 1, unit: UnitSpeed.light)
25+
26+
/// The speed of light, squared.
27+
///
28+
/// - SeeAlso: ``c``
29+
@available(
30+
*,
31+
deprecated,
32+
message: "The square of the speed of light is now a unit (UnitSpeed.lightSquared)."
33+
)
34+
public let cSquared = Measurement(value: 1, unit: UnitSpeed.lightSquared)
35+
36+
extension UnitSpeed {
37+
/// The speed of light *c* in m/s.
38+
private static let coefficient = 299_792_458.0
39+
40+
/// The speed of light *c*.
41+
///
42+
/// - SeeAlso: ``lightSquared``
43+
public static let light = UnitSpeed(
44+
symbol: "c",
45+
converter: UnitConverterLinear(coefficient: coefficient)
46+
)
47+
48+
/// The speed of light *c*, squared: *c*².
49+
///
50+
/// - SeeAlso: ``light``
51+
public static let lightSquared = UnitSpeed(
52+
symbol: "",
53+
converter: UnitConverterLinear(coefficient: pow(coefficient, 2))
54+
)
55+
}

QuantumMechanicsTests/Elementary/QuarkTests.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Testing
2626
% massValue = float(mass[0])
2727
% massUnit = mass[1]
2828
% spelledUnitizedMass = ''.join(char for char in inflect.engine().number_to_words(massValue).title() if char.isalpha()) + massUnit.capitalize()
29-
% massUnitReference = "UnitMass.megaelectronvoltsPerC²" if massUnit == 'MeV' else "UnitMass.gigaelectronvoltsPerC²" if massUnit == "GeV" else "UnitMass.baseUnit()"
29+
% massUnitReference = "UnitMass.megaelectronvoltsPerLightSpeedSquared" if massUnit == 'MeV' else "UnitMass.gigaelectronvoltsPerLightSpeedSquared" if massUnit == "GeV" else "UnitMass.baseUnit()"
3030
% symbol = flavor[0]
3131
struct ${implementation}Tests {
3232
${caseAttribute}

QuantumMechanicsTests/Elementary/QuarkTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct UpQuarkTests {
2525
func baseMassIsTwoPointThreeMev(_ quark: UpQuark<AnySingleColor>) {
2626
#expect(
2727
quark.getMass(approximatedBy: .base)
28-
== Measurement(value: 2.3, unit: UnitMass.megaelectronvolt)
28+
== Measurement(value: 2.3, unit: UnitMass.megaelectronvoltsPerLightSpeedSquared)
2929
)
3030
}
3131

@@ -38,7 +38,7 @@ struct DownQuarkTests {
3838
func baseMassIsFourPointEightMev(_ quark: DownQuark<AnySingleColor>) {
3939
#expect(
4040
quark.getMass(approximatedBy: .base)
41-
== Measurement(value: 4.8, unit: UnitMass.megaelectronvolt)
41+
== Measurement(value: 4.8, unit: UnitMass.megaelectronvoltsPerLightSpeedSquared)
4242
)
4343
}
4444

@@ -51,7 +51,7 @@ struct StrangeQuarkTests {
5151
func baseMassIsNinetyFivePointZeroMev(_ quark: StrangeQuark<AnySingleColor>) {
5252
#expect(
5353
quark.getMass(approximatedBy: .base)
54-
== Measurement(value: 95.0, unit: UnitMass.megaelectronvolt)
54+
== Measurement(value: 95.0, unit: UnitMass.megaelectronvoltsPerLightSpeedSquared)
5555
)
5656
}
5757

@@ -64,7 +64,7 @@ struct CharmQuarkTests {
6464
func baseMassIsOnePointTwoSevenFiveGev(_ quark: CharmQuark<AnySingleColor>) {
6565
#expect(
6666
quark.getMass(approximatedBy: .base)
67-
== Measurement(value: 1.275, unit: UnitMass.gigaelectronvolt)
67+
== Measurement(value: 1.275, unit: UnitMass.gigaelectronvoltsPerLightSpeedSquared)
6868
)
6969
}
7070

@@ -77,7 +77,7 @@ struct BottomQuarkTests {
7777
func baseMassIsFourPointOneEightGev(_ quark: BottomQuark<AnySingleColor>) {
7878
#expect(
7979
quark.getMass(approximatedBy: .base)
80-
== Measurement(value: 4.18, unit: UnitMass.gigaelectronvolt)
80+
== Measurement(value: 4.18, unit: UnitMass.gigaelectronvoltsPerLightSpeedSquared)
8181
)
8282
}
8383

@@ -90,7 +90,7 @@ struct TopQuarkTests {
9090
func baseMassIsOneHundredAndSeventyThreePointTwoOneGev(_ quark: TopQuark<AnySingleColor>) {
9191
#expect(
9292
quark.getMass(approximatedBy: .base)
93-
== Measurement(value: 173.21, unit: UnitMass.gigaelectronvolt)
93+
== Measurement(value: 173.21, unit: UnitMass.gigaelectronvoltsPerLightSpeedSquared)
9494
)
9595
}
9696

QuantumMechanicsTests/Field/ManifoldTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import Testing
2222
struct ManifoldTests {
2323
@Test
2424
func calculatesLagrangian() {
25-
#expect(_RealLine(mass: 2).L(q: 4,: 8, t: 16) == 8.881784197001252e-16)
25+
#expect(
26+
_RealLine(mass: 2).lagrangian(coordinate: 4, velocity: 8, time: 16) == 8.881784197001252e-16
27+
)
2628
}
2729
}

QuantumMechanics/Constants.swift renamed to QuantumMechanicsTests/Measurement+LightTests.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@
1616
// ===-------------------------------------------------------------------------------------------===
1717

1818
import Foundation
19+
import Testing
1920

20-
/// The speed of light.
21-
///
22-
/// - SeeAlso: ``c²``
23-
public let c = Measurement(value: 299_792_458, unit: UnitSpeed.metersPerSecond)
21+
@testable import QuantumMechanics
2422

25-
/// The speed of light, squared.
26-
///
27-
/// - SeeAlso: ``c``
28-
public let c² = Measurement(value: pow(c.value, 2), unit: c.unit)
23+
@Suite("Measurement+Light tests")
24+
struct MeasurementLightTests {
25+
@Test
26+
func
27+
lightIsTwoHundredAndNinetyNineMillionAndSevenHundredAndNinetyTwoAndFourHundredAndFiftyEightMetersPerSecond()
28+
{ #expect(UnitSpeed.light.converter.baseUnitValue(fromValue: 1) == 299_792_458) }
29+
30+
@Test
31+
func lightSquaredIsLightSpeedSquared() {
32+
#expect(
33+
UnitSpeed.lightSquared.converter.baseUnitValue(fromValue: 1)
34+
== pow(UnitSpeed.light.converter.baseUnitValue(fromValue: 1), 2)
35+
)
36+
}
37+
}

0 commit comments

Comments
 (0)