Skip to content

Commit

Permalink
rearrangement + more enhanced tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe Hernandez Acosta committed Sep 13, 2024
1 parent 95042f4 commit 7aeb8f6
Show file tree
Hide file tree
Showing 12 changed files with 420 additions and 205 deletions.
11 changes: 8 additions & 3 deletions src/QEDcore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ using SimpleTraits

@reexport using QEDbase

include("patch_QEDbase.jl")

include("algebraic_objects/dirac_tensors/types.jl")
include("algebraic_objects/dirac_tensors/multiplication.jl")

Expand All @@ -60,10 +62,13 @@ include("algebraic_objects/four_momentum.jl")
include("algebraic_objects/lorentz_vector.jl")
include("algebraic_objects/gamma_matrices.jl")

include("lorentz_boost/general_trafo.jl")
include("lorentz_boost/types.jl")
include("lorentz_boost/boost_parameter/boost_axis/axis_boost.jl")
include("lorentz_boost/boost_parameter/boost_vector/boost_vector.jl")
include("lorentz_boost/boost_parameter/boost_axis/types.jl")
include("lorentz_boost/boost_parameter/boost_axis/convert.jl")
include("lorentz_boost/boost_parameter/boost_axis/beta.jl")
include("lorentz_boost/boost_parameter/boost_vector/types.jl")
include("lorentz_boost/boost_parameter/boost_vector/beta.jl")
include("lorentz_boost/boost_parameter/boost_vector/utils.jl")

include("particles/particle_types.jl")
include("particles/propagators.jl")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
# TODO:
# - test conversions
# - add convenient constructors: Boost(:x,::Real)
# - add convenient constructors: Boost(:rest_frame,::AbstractFourMomentum)
# - add convenient constructors: Boost(::RestFrame,::AbstractFourMomentum)
# - decompose into separate files

"""
AbstractAxisBoostParameter{T}
Abstract base type for boost parameter of type `T` associated to a certain axis in space.
"""
abstract type AbstractAxisBoostParameter{T} <: AbstractBoostParameter end
function convert(
::Type{B}, param::S
) where {T<:Real,B<:AbstractAxisBoostParameter{T},S<:Real}
return B(T(param))
end
function Base.convert(
::Type{B1}, d::B2
) where {B1<:AbstractAxisBoostParameter,B2<:AbstractAxisBoostParameter}
return B1(d.param)
end
function Base.convert(
::Type{B1}, d::B2
) where {T<:Real,B1<:AbstractAxisBoostParameter{T},B2<:AbstractAxisBoostParameter{T}}
return d
end

###########
# Axis Beta
Expand All @@ -35,7 +6,19 @@ end
AbstractAxisBeta{T} <: AbstractAxisBoostParameter{T}
Abstact base type for boost beta parameter of type `T` associated to an axis in space.
An abstract base type for the beta (velocity) parameter of type `T`, representing a Lorentz boost along a specific spatial axis.
`AbstractAxisBeta{T}` extends `AbstractAxisBoostParameter{T}` and provides a general framework for defining beta parameters associated with individual Cartesian axes (x, y, z) in special relativity. The parameter `T` typically represents the numeric type (e.g., `Float64`, `Float32`) used for the beta value.
### Usage
Concrete subtypes of `AbstractAxisBeta{T}` define the beta parameters for Lorentz boosts along the x, y, and z axes:
- [`BetaX{T}`](@ref): Boost parameter for the x-axis.
- [`BetaY{T}`](@ref): Boost parameter for the y-axis.
- [`BetaZ{T}`](@ref): Boost parameter for the z-axis.
These beta parameters are essential for performing axis-specific Lorentz boosts, which transform physical quantities such as four-momentum between different inertial frames.
"""
abstract type AbstractAxisBeta{T} <: AbstractAxisBoostParameter{T} end

Expand All @@ -57,8 +40,9 @@ end
BetaX(beta::T) where {T<:Real}
Beta parameter associated to the x-axis, commonly referred to as ``\\beta_x``.
The corresponding Lorentz boost reads
Represents the beta parameter associated with a Lorentz boost along the x-axis, commonly denoted as ``\\beta_x``.
The transformation for a boost along the x-axis is:
```math
\\begin{pmatrix}
Expand Down Expand Up @@ -101,7 +85,7 @@ julia> p_prime = boost(p)
2.0
1.0
julia> @assert isapprox(p*p,p_prime*p_prime)
julia> @assert isapprox(p*p,p_prime*p_prime) # Invariant mass is preserved
```
## External link
Expand Down Expand Up @@ -133,8 +117,9 @@ end
BetaY(beta::T) where {T<:Real}
Beta parameter associated to the y-axis, commonly referred to as ``\\beta_y``.
The corresponding Lorentz boost reads
Represents the beta parameter associated with a Lorentz boost along the y-axis, commonly denoted as ``\\beta_y``.
The transformation for a boost along the y-axis is:
```math
\\begin{pmatrix}
Expand Down Expand Up @@ -182,7 +167,7 @@ julia> p_prime = boost(p)
0.0
1.0
julia> @assert isapprox(p*p,p_prime*p_prime)
julia> @assert isapprox(p*p,p_prime*p_prime) # Invariant mass is preserved
```
## External link
Expand All @@ -191,9 +176,9 @@ julia> @assert isapprox(p*p,p_prime*p_prime)
* [Kinematics in PDG review](https://pdg.lbl.gov/2024/reviews/rpp2024-rev-kinematics.pdf)
"""
struct BetaY{T} <: AbstractAxisBeta{T}
struct BetaY{T<:Real} <: AbstractAxisBeta{T}
param::T
function BetaY{T}(beta::T) where {T}
function BetaY{T}(beta::T) where {T<:Real}
-one(beta) <= beta < one(beta) ||
throw(InvalidInputError("beta parameter <$beta> must be between zero and one"))
return new{T}(beta)
Expand All @@ -214,8 +199,9 @@ end
BetaZ(beta::T) where {T<:Real}
Beta parameter associated to the z-axis, commonly referred to as ``\\beta_z``.
The corresponding Lorentz boost reads
Represents the beta parameter associated with a Lorentz boost along the z-axis, commonly denoted as ``\\beta_z``.
The transformation for a boost along the z-axis is:
```math
\\begin{pmatrix}
Expand Down Expand Up @@ -263,7 +249,7 @@ julia> p_prime = boost(p)
2.0
-1.1547005383792517
julia> @assert isapprox(p*p,p_prime*p_prime)
julia> @assert isapprox(p*p,p_prime*p_prime) # Invariant mass is preserved
```
Expand All @@ -273,9 +259,9 @@ julia> @assert isapprox(p*p,p_prime*p_prime)
* [Kinematics in PDG review](https://pdg.lbl.gov/2024/reviews/rpp2024-rev-kinematics.pdf)
"""
struct BetaZ{T} <: AbstractAxisBeta{T}
struct BetaZ{T<:Real} <: AbstractAxisBeta{T}
param::T
function BetaZ{T}(beta::T) where {T}
function BetaZ{T}(beta::T) where {T<:Real}
-one(beta) <= beta < one(beta) ||
throw(InvalidInputError("beta parameter <$beta> must be between zero and one"))
return new{T}(beta)
Expand Down
16 changes: 16 additions & 0 deletions src/lorentz_boost/boost_parameter/boost_axis/convert.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

function Base.convert(
::Type{B}, param::S
) where {T<:Real,B<:AbstractAxisBoostParameter{T},S<:Real}
return B(T(param))
end
function Base.convert(
::Type{B1}, d::B2
) where {T<:Real,B1<:AbstractAxisBoostParameter{T},B2<:AbstractAxisBoostParameter}
return B1(T(d.param))
end
function Base.convert(
::Type{B1}, d::B2
) where {T<:Real,B1<:AbstractAxisBoostParameter{T},B2<:AbstractAxisBoostParameter{T}}
return d
end
28 changes: 28 additions & 0 deletions src/lorentz_boost/boost_parameter/boost_axis/types.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# TODO:
# - test conversions
# - decompose into separate files

"""
AbstractAxisBoostParameter{T}
An abstract base type representing a boost parameter of type `T`, associated with a specific axis in space (e.g., ``x``, ``y``, or ``z``).
This type serves as a foundation for concrete boost parameter types that define Lorentz boosts along individual spatial directions, The parameter `T` typically represents the data type for the boost value (e.g., `Float64`, `Float32`).
### Usage
Subtypes of `AbstractAxisBoostParameter{T}` are used to define specific boost transformations along a given axis (such as `BetaX` for the x-axis). These types are essential in performing Lorentz boosts, which transform four-momentum vectors between different inertial reference frames.
This abstract type is meant to be extended by concrete types to represent boosts along different Cartesian axes.
"""
abstract type AbstractAxisBoostParameter{T} <: AbstractBoostParameter end

function (::Type{BP})(
boost_val::S
) where {T<:Real,BP<:AbstractAxisBoostParameter{T},S<:Real}
return BP(T(boost_val))
end

Base.eltype(::AbstractAxisBoostParameter{T}) where {T} = T
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@

# TODO:
# - add interaction with axis boosts
# - add convenient constructors BetaVector(p) for the rest system?
# - test constructor error
"""
AbstractBoostVector<:AbstractBoostParameter
Abstract base type for vector-like boost parameters, modelling boosts in any spatial dimension.
"""
abstract type AbstractBoostVector <: AbstractBoostParameter end

"""
BetaVector(x::Real,y::Real,z::Real)
Spatial vector of beta parameters associated with the three chartesian directions: ``\\vec\\beta = (\\beta_x,\\beta_y,\\beta_z)``.
The corresponding Lorentz boost transformation reads
Represents the spatial vector of velocity parameters (denoted as the "beta" vector) associated with motion in the three Cartesian directions, i.e.,
``\\vec\\beta = (\\beta_x, \\beta_y, \\beta_z)``. These components correspond to the velocity of an object (in units of the speed of light) in each of the
``x``, ``y``, and ``z`` directions.
The Lorentz boost along the direction of the beta vector ``\\vec\\beta`` transforms the four-momentum as follows:
```math
\\begin{pmatrix}
Expand All @@ -35,7 +26,7 @@ p_2 + (\\frac{\\gamma - 1}{\\beta^2} \\vec\\beta\\vec p - \\gamma p_0)
\\beta_z\\\\
\\end{pmatrix}
```
where the kinematic factor is given as ``\\gamma = 1/\\sqrt{1-\\beta_x^2}``)
where the kinematic factor is given as ``\\gamma = 1/\\sqrt{1-\\beta_x^2}``.
## Example
Expand All @@ -62,7 +53,7 @@ julia> p_prime = boost(p)
0.9242054036545237
0.6414018012181746
julia> @assert isapprox(p*p,p_prime*p_prime)
julia> @assert isapprox(p*p,p_prime*p_prime) # Invariant mass is preserved
```
## External link
Expand Down Expand Up @@ -90,38 +81,24 @@ end
BetaVector(x, y, z) = BetaVector(promote(x, y, z)...)

import Base: -

-(b::BetaVector) = BetaVector(-b.x, -b.y, -b.z)

function Base.isapprox(
b1::BetaVector,
b2::BetaVector;
atol::Real=0,
rtol::Real=Base.rtoldefault(b1.x, b1.y, atol),
nans::Bool=false,
norm::Function=abs,
)
return isapprox(b1.x, b2.x; atol=atol, rtol=rtol, nans=nans, norm=norm) &&
isapprox(b1.y, b2.y; atol=atol, rtol=rtol, nans=nans, norm=norm) &&
isapprox(b1.z, b2.z; atol=atol, rtol=rtol, nans=nans, norm=norm)
end

@inline function _mul(p::AbstractFourMomentum, beta::BetaVector)
@inline function _spatial_mul(p::AbstractFourMomentum, beta::BetaVector)
return p[2] * beta.x + p[3] * beta.y + p[4] * beta.z
end

# FIXME: not every component has commutative product
_mul(beta::BetaVector, p::AbstractFourMomentum) = _mul(p, beta)
# assumption: beta vector components are communte with four momentum components
_spatial_mul(beta::BetaVector, p::AbstractFourMomentum) = _spatial_mul(p, beta)

function _square(beta_vec::BetaVector)
function _three_vector_square(beta_vec::BetaVector)
bx = beta_vec.x
by = beta_vec.y
bz = beta_vec.z
return bx^2 + by^2 + bz^2
end

@inline function _transform(beta_vec::BetaVector, p::M) where {M<:AbstractFourMomentum}
b2 = _square(beta_vec)
b2 = _three_vector_square(beta_vec)
if b2 == one(b2)
return p
end
Expand All @@ -131,7 +108,7 @@ end
px = getX(p)
py = getY(p)
pz = getZ(p)
bp = _mul(p, beta_vec)
bp = _spatial_mul(p, beta_vec)
gamma2 = (gamma - one(b2)) / b2
fac = gamma2 * bp - gamma * en
px_prime = px + fac * beta_vec.x
Expand All @@ -142,4 +119,5 @@ end
return M(en_prime, px_prime, py_prime, pz_prime)
end

# inverse is just a boost with -beta
_inv(beta_vec::BetaVector) = BetaVector(-beta_vec.x, -beta_vec.y, -beta_vec.z)
29 changes: 29 additions & 0 deletions src/lorentz_boost/boost_parameter/boost_vector/types.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# TODO:
# - add interaction with axis boosts
# - add convenient constructors BetaVector(p) for the rest system?
# - test constructor error

"""
AbstractBoostVector <: AbstractBoostParameter
An abstract base type representing vector-like boost parameters, used to model Lorentz boosts
in any spatial dimension.
`AbstractBoostVector` extends `AbstractBoostParameter` and provides the framework for
describing boosts that act in multiple spatial dimensions simultaneously, typically in
three-dimensional space. This type is designed to support vector representations of
velocities (in units of the speed of light) associated with Lorentz transformations in
special relativity.
## Usage
Concrete subtypes of `AbstractBoostVector` represent specific boost vectors that describe
the velocity components in each spatial dimension, such as `BetaVector`. These boost
vectors are commonly used in transformations of four-vectors (e.g., four-momentum,
four-position) between different reference frames.
For example:
- [`BetaVector{T}`](@ref): A concrete subtype representing a boost vector with velocity components ``\\beta_x``, ``\\beta_y``, and ``\\beta_z`` (in units of the speed of light).
"""
abstract type AbstractBoostVector <: AbstractBoostParameter end
13 changes: 13 additions & 0 deletions src/lorentz_boost/boost_parameter/boost_vector/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function Base.isapprox(
b1::BetaVector,
b2::BetaVector;
atol::Real=0,
rtol::Real=Base.rtoldefault(b1.x, b1.y, atol),
nans::Bool=false,
norm::Function=abs,
)
return isapprox(b1.x, b2.x; atol=atol, rtol=rtol, nans=nans, norm=norm) &&
isapprox(b1.y, b2.y; atol=atol, rtol=rtol, nans=nans, norm=norm) &&
isapprox(b1.z, b2.z; atol=atol, rtol=rtol, nans=nans, norm=norm)
end
Loading

0 comments on commit 7aeb8f6

Please sign in to comment.