Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions QuantumMechanics/AnyParticle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// ``ParticleLike`` whose type information has been erased.
public struct AnyParticleLike: ParticleLike {
public let spin: Spin
public let charge: Measurement<UnitElectricCharge>
public let charge: ElectricCharge
public let symbol: String

/// ``ParticleLike`` based on which this one was initialized.
Expand All @@ -42,9 +40,9 @@ public struct AnyParticleLike: ParticleLike {
}
}

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> { base.getMass(approximatedBy: approximator) }
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
base.getMass(approximatedBy: approximator)
}
}

extension AnyParticleLike: Equatable {
Expand All @@ -56,7 +54,7 @@ extension AnyParticleLike: Equatable {
/// ``Particle`` whose type information has been erased.
public struct AnyParticle: ParticleLike {
public let spin: Spin
public let charge: Measurement<UnitElectricCharge>
public let charge: ElectricCharge
public let symbol: String

/// ``Particle`` based on which this one was initialized.
Expand All @@ -80,9 +78,9 @@ public struct AnyParticle: ParticleLike {
}
}

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> { base.getMass(approximatedBy: approximator) }
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
base.getMass(approximatedBy: approximator)
}
}

extension AnyParticle: Equatable {
Expand Down
8 changes: 4 additions & 4 deletions QuantumMechanics/Composite/Hadron.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// ``Particle`` composed by two or more ``Quark``s which are bound by strong force. It is the
/// compositor of nucleons — such as protons and neutrons — and, therefore, the most common
/// composite ``Particle`` in the universe.
Expand Down Expand Up @@ -71,8 +69,10 @@ extension Hadron where Self: ParticleLike {
}

extension Hadron where Self: ColoredParticleLike {
public var charge: Measurement<UnitElectricCharge> {
quarks.reduce(.zero) { charge, quark in quark.charge + charge }
public var charge: ElectricCharge {
var quantityInBaseUnit = 0.0
for quark in quarks { quantityInBaseUnit += quark.charge.quantityInBaseUnit }
return .init(quantityInBaseUnit: quantityInBaseUnit)
}
public var colorLike: ColorLike { white as! ColorLike }
}
6 changes: 1 addition & 5 deletions QuantumMechanics/Composite/Pion/NegativePion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// ``Pion`` with a negative ``charge`` (π⁻), resulted from d + ū.
///
/// - SeeAlso: ``DownQuark``
Expand All @@ -27,9 +25,7 @@ public struct NegativePion: Equatable, Pion {

fileprivate init(quarks: [AnyQuarkLike]) { self.quarks = quarks }

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> {
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
approximator.approximate(chargedPionMass, chargedPionMassStatisticalUncertainty, .zero)
}
}
Expand Down
6 changes: 2 additions & 4 deletions QuantumMechanics/Composite/Pion/Pion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// Base value for calculating an approximation of the mass of a charged ``Pion``.
let chargedPionMass = Measurement(value: 139.57039, unit: UnitMass.gigaelectronvolt)
let chargedPionMass = Mass.gigaelectronvoltsPerLightSpeedSquared(139.57039)

/// Statistical uncertainty for calculating an approximation of the mass of a charged ``Pion``.
let chargedPionMassStatisticalUncertainty = Measurement(value: 180, unit: UnitMass.electronvolt)
let chargedPionMassStatisticalUncertainty = Mass.electronvoltsPerLightSpeedSquared(180)

/// ``Meson`` composed by ``Quark``-antiquark pairs, produced most commonly via high-energy
/// collisions between ``Hadron``s and specific ``Particle``-antiparticle annihilation.
Expand Down
6 changes: 1 addition & 5 deletions QuantumMechanics/Composite/Pion/PositivePion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// ``Pion`` with a positive ``charge`` (π⁺), resulted from u + d̄.
///
/// - SeeAlso: ``UpQuark``
Expand All @@ -27,9 +25,7 @@ public struct PositivePion: Equatable, Pion {

fileprivate init(quarks: [AnyQuarkLike]) { self.quarks = quarks }

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> {
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
approximator.approximate(chargedPionMass, chargedPionMassStatisticalUncertainty, .zero)
}
}
Expand Down
4 changes: 1 addition & 3 deletions QuantumMechanics/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// The speed of light.
let c = Measurement(value: 299_792_458, unit: UnitSpeed.metersPerSecond)
let c = Speed.metersPerSecond(299_792_458)
18 changes: 8 additions & 10 deletions QuantumMechanics/Elementary/AnyQuark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// ``QuarkLike`` whose flavor information has been erased.
public struct AnyQuarkLike: Discrete, QuarkLike {
/// ``Quark`` based on which this one was initialized.
Expand All @@ -27,7 +25,7 @@ public struct AnyQuarkLike: Discrete, QuarkLike {
}

public let spin: Spin
public let charge: Measurement<UnitElectricCharge>
public let charge: ElectricCharge
public let symbol: String
public let colorLike: AnySingleColorLike

Expand All @@ -49,9 +47,9 @@ public struct AnyQuarkLike: Discrete, QuarkLike {
}
}

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> { base.getMass(approximatedBy: approximator) }
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
base.getMass(approximatedBy: approximator)
}
}

extension AnyQuarkLike: Equatable {
Expand All @@ -74,7 +72,7 @@ public struct AnyQuark: Discrete, Quark {
}.sorted(by: <)

public let spin: Spin
public let charge: Measurement<UnitElectricCharge>
public let charge: ElectricCharge
public let symbol: String
public let colorLike: AnySingleColor

Expand All @@ -96,9 +94,9 @@ public struct AnyQuark: Discrete, Quark {
}
}

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> { base.getMass(approximatedBy: approximator) }
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
base.getMass(approximatedBy: approximator)
}
}

extension AnyQuark: Equatable {
Expand Down
20 changes: 7 additions & 13 deletions QuantumMechanics/Elementary/BottomQuark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,20 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// Base value for calculating an approximation of the mass of a ``BottomQuark``.
private let baseMass = Measurement(value: 4.18, unit: UnitMass.gigaelectronvolt)

/// Statistical uncertainty for calculating an approximation of the mass of a ``BottomQuark``.
private let massStatisticalUncertainty = Measurement(value: 0.03, unit: UnitMass.gigaelectronvolt)

/// Second heaviest ``Quark``, with a Lagrangian mass of 4.18 ± 0.03 GeV/*c*². Decays to a
/// ``CharmQuark``.
public struct BottomQuark<ColorLike: SingleColor>: Quark {
public let symbol = "b"
public let charge = negativeOneThirdOfE
public let charge = ElectricCharge.elementary(-1 / 3)
public let colorLike: ColorLike

public init(colorLike: ColorLike) { self.colorLike = colorLike }

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> {
approximator.approximate(baseMass, massStatisticalUncertainty, .zero)
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
approximator.approximate(
.gigaelectronvoltsPerLightSpeedSquared(4.18),
.gigaelectronvoltsPerLightSpeedSquared(0.03),
.zero
)
}
}
20 changes: 7 additions & 13 deletions QuantumMechanics/Elementary/CharmQuark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,20 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// Base value for calculating an approximation of the mass of a ``CharmQuark``.
private let baseMass = Measurement(value: 1.275, unit: UnitMass.gigaelectronvolt)

/// Statistical uncertainty for calculating an approximation of the mass of a ``CharmQuark``.
private let massStatisticalUncertainty = Measurement(value: 25, unit: UnitMass.megaelectronvolt)

/// Third heaviest ``Quark``, with a Lagrangian mass of 1.275 ± 0.025 GeV/*c*². Decays to a
/// ``StrangeQuark``.
public struct CharmQuark<ColorLike: SingleColor>: Quark {
public let symbol = "c"
public let charge = twoThirdsOfE
public let charge = ElectricCharge.elementary(2 / 3)
public let colorLike: ColorLike

public init(colorLike: ColorLike) { self.colorLike = colorLike }

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> {
approximator.approximate(baseMass, massStatisticalUncertainty, .zero)
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
approximator.approximate(
.gigaelectronvoltsPerLightSpeedSquared(1.275),
.megaelectronvoltsPerLightSpeedSquared(25),
.zero
)
}
}
23 changes: 7 additions & 16 deletions QuantumMechanics/Elementary/DownQuark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,20 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// Base value for calculating an approximation of the mass of a ``DownQuark``.
private let baseMass = Measurement(value: 4.8, unit: UnitMass.megaelectronvolt)

/// Statistical uncertainty for calculating an approximation of the mass of a ``DownQuark``.
private let massStatisticalUncertainty = Measurement(value: 0.5, unit: UnitMass.megaelectronvolt)

/// Systematic uncertainty for calculating an approxiumation to the mass of a ``DownQuark``.
private let massSystematicUncertainty = Measurement(value: 0.3, unit: UnitMass.megaelectronvolt)

/// Second lightest ``Quark``, with a Lagrangian mass of 4.8 ± 0.5 ± 0.3 MeV/*c*². Decays to an
/// ``UpQuark``.
public struct DownQuark<ColorLike: SingleColor>: Quark {
public let symbol = "d"
public let charge = negativeOneThirdOfE
public let charge = ElectricCharge.elementary(-1 / 3)
public let colorLike: ColorLike

public init(colorLike: ColorLike) { self.colorLike = colorLike }

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> {
approximator.approximate(baseMass, massStatisticalUncertainty, massSystematicUncertainty)
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
approximator.approximate(
.megaelectronvoltsPerLightSpeedSquared(4.8),
.megaelectronvoltsPerLightSpeedSquared(0.5),
.megaelectronvoltsPerLightSpeedSquared(0.3)
)
}
}
22 changes: 7 additions & 15 deletions QuantumMechanics/Elementary/Quark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// Charge of up-type quarks.
let twoThirdsOfE = Measurement(value: 2 / 3, unit: UnitElectricCharge.elementary)

/// Charge of down-type quarks.
let negativeOneThirdOfE = Measurement(value: -1 / 3, unit: UnitElectricCharge.elementary)

/// Base protocol to which ``Quark``s and antiquarks conform.
public protocol QuarkLike: ColoredParticleLike where ColorLike: SingleColorLike {}

extension QuarkLike where Self: ParticleLike { public var spin: Spin { .half } }

extension Anti: QuarkLike where Counterpart: Quark {}

/// A quark (q) is an elementary fermion ``ColoredParticle`` which is confined, bound to at least
/// another one by gluon ``Particle``s via strong force. It is the only ``Particle`` in the Standard
/// Model which experiences each of the four fundamental forces: strong, weak, electromagnetic and
Expand Down Expand Up @@ -73,3 +58,10 @@ extension Anti: QuarkLike where Counterpart: Quark {}
/// - SeeAlso: ``ParticleLike/charge``
/// - SeeAlso: ``Spin/half``
public protocol Quark: ColoredParticle, QuarkLike where ColorLike: SingleColor {}

extension Anti: QuarkLike where Counterpart: Quark {}

/// Base protocol to which ``Quark``s and antiquarks conform.
public protocol QuarkLike: ColoredParticleLike where ColorLike: SingleColorLike {}

extension QuarkLike where Self: ParticleLike { public var spin: Spin { .half } }
20 changes: 7 additions & 13 deletions QuantumMechanics/Elementary/StrangeQuark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@
// not, see https://www.gnu.org/licenses.
// ===-------------------------------------------------------------------------------------------===

import Foundation

/// Base value for calculating an approximation of the mass of a ``StrangeQuark``.
private let baseMass = Measurement(value: 95, unit: UnitMass.megaelectronvolt)

/// Statistical uncertainty for calculating an approximation of the mass of a ``StrangeQuark``.
private let massStatisticalUncertainty = Measurement(value: 5, unit: UnitMass.gigaelectronvolt)

/// Third lightest ``Quark``, with a Lagrangian mass of 95 ± 5 MeV/*c*². Decays to a ``DownQuark``.
public struct StrangeQuark<ColorLike: SingleColor>: Quark {
public let symbol = "s"
public let charge = negativeOneThirdOfE
public let charge = ElectricCharge.elementary(-1 / 3)
public let colorLike: ColorLike

public init(colorLike: ColorLike) { self.colorLike = colorLike }

public func getMass(
approximatedBy approximator: Approximator<Measurement<UnitMass>>
) -> Measurement<UnitMass> {
approximator.approximate(baseMass, massStatisticalUncertainty, .zero)
public func getMass(approximatedBy approximator: Approximator<Mass>) -> Mass {
approximator.approximate(
.megaelectronvoltsPerLightSpeedSquared(95),
.gigaelectronvoltsPerLightSpeedSquared(5),
.zero
)
}
}
Loading