Minkowski

Struct Minkowski 

Source
pub struct Minkowski<const N: usize> {
    pub coordinates: [f64; N],
}
Expand description

A vector in N-dimensional Minkowski space.

Minkowski<N> implements $(N-1,1)$-dimensional Minkowski space with the metric signature $(+ , \cdots , + , -)$. Minkowski supports Vector operations such as vector addition and rescaling.

§Constructing Minkowski vectors

Similar to Cartesian, $N$-dimensional vectors can be constructed using an array of (real-valued) coordinates. Three- and four-dimensional vectors can also be constructed from tuples:

use hoomd_manifold::Minkowski;

fn from_array() -> Minkowski<5> {
    Minkowski::from([1.0, 2.0, 3.0, 4.0, 5.0])
}
fn from_tuples() -> Minkowski<3> {
    Minkowski::from((6.0, 7.0, 8.0))
}

§Operating on Minkowski vectors

Minkowski implements everything from Vector, which includes vector addition/subtraction and multiplication by a scalar.

use hoomd_manifold::Minkowski;

// Vector addition
let mut a = Minkowski::from([1.0, 1.0, 1.0, 1.0]);
let mut b = Minkowski::from([0.0, 0.0, 0.0, 2.0]);
a += b;

// Multiplication by a scalar
let mut c = a * 4.0;

// Division by a scalar
c /= 2.0;

assert_eq!(c, [2.0, 2.0, 2.0, 6.0].into());

The distance metric on Minkowski space is given by the “spacetime interval”

d_M^2(\vec{u},\vec{v}) = (\vec{u}-\vec{v})^T \eta (\vec{u}-\vec{v})
= (u_1-v_1)^2 +\cdots + (u_{N-1}-v_{N-1})^2 - (u_N - v_N)^2

Note that because this metric is not positive-definite, Minkowski this “spacetime interval” is not a true inner-product, and therefore Minkowski does not implement the methods of InnerProduct.

use hoomd_manifold::Minkowski;
use hoomd_vector::Metric;

let x = Minkowski::from([1.0, 0.0, 5.0]);
let y = Minkowski::from([0.0, 0.0, 3.0]);
assert_eq!(-3.0, x.distance_squared(&y));

Fields§

§coordinates: [f64; N]

The vector’s coordinates.

The final component is the one associated with a minus sign (-) in the metric.

Trait Implementations§

Source§

impl<const N: usize> AbsDiffEq for Minkowski<N>

Source§

type Epsilon = <f64 as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximimate equality of two numbers.
§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of [AbsDiffEq::abs_diff_eq].
Source§

impl<const N: usize> Add for Minkowski<N>

Source§

type Output = Minkowski<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl<const N: usize> AddAssign for Minkowski<N>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const N: usize> Clone for Minkowski<N>

Source§

fn clone(&self) -> Minkowski<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Minkowski<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for Minkowski<N>

Source§

fn default() -> Self

Create a 0 vector in Minkowski space.

§Example
use hoomd_manifold::Minkowski;

let v = Minkowski::<3>::default();
assert_eq!(v, [0.0; 3].into())
Source§

impl<'de, const N: usize> Deserialize<'de> for Minkowski<N>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const N: usize> Display for Minkowski<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Distribution<Minkowski<N>> for StandardUniform

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Minkowski<N>

Sample a Minkowski vector from the uniform $[-1, 1]$ hypercube.

§Example
use hoomd_manifold::Minkowski;
use rand::{RngExt, SeedableRng, rngs::StdRng};

let mut rng = StdRng::seed_from_u64(1);
let v: Minkowski<3> = rng.random();
§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl<const N: usize> Div<f64> for Minkowski<N>

Source§

type Output = Minkowski<N>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self

Performs the / operation. Read more
Source§

impl<const N: usize> DivAssign<f64> for Minkowski<N>

Source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl<const N: usize> From<[f64; N]> for Minkowski<N>

Source§

fn from(coordinates: [f64; N]) -> Self

Create a vector in Minkowski space with the given coordinates.

The last component has a (-) signature, while the preceding coordinates have (+) signatures in the metric.

§Example
use hoomd_manifold::Minkowski;

let v = Minkowski::from([1.0, 2.0]);
Source§

impl From<(f64, f64)> for Minkowski<2>

Source§

fn from(coordinates: (f64, f64)) -> Self

Converts to this type from the input type.
Source§

impl From<(f64, f64, f64)> for Minkowski<3>

Source§

fn from(coordinates: (f64, f64, f64)) -> Self

Converts to this type from the input type.
Source§

impl From<(f64, f64, f64, f64)> for Minkowski<4>

Source§

fn from(coordinates: (f64, f64, f64, f64)) -> Self

Converts to this type from the input type.
Source§

impl HyperbolicRotate<Minkowski<4>> for UnitBiquaternion

Source§

fn hyperbolic_rotate(&self, vector: &Minkowski<4>) -> Minkowski<4>

Transform a Minkowski<4> by a UnitBiquaternion.

\overline{\mathbf{q}} \vec{a} \mathbf{q}^*
§Examples

Rotation about z axis:

use approxim::assert_relative_eq;
use hoomd_manifold::{
    Biquaternion, HyperbolicRotate, Minkowski, UnitBiquaternion,
};
use num::complex::Complex;
use std::f64::consts::PI;

let x = Minkowski::from([1.0, 0.0, 0.0, 1.0]);
let q = Biquaternion::from([
    Complex::new(0.0, 0.0),
    Complex::new(0.0, 0.0),
    Complex::new((PI / 4.0).sin(), 0.0),
    Complex::new((PI / 4.0).cos(), 0.0),
]);
let v = q.to_unit_unchecked();
let rotated = v.hyperbolic_rotate(&x);
assert_relative_eq!(rotated, [0.0, 1.0, 0.0, 1.0].into(), epsilon = 1e-12);

Boost in x direction:

use approxim::assert_relative_eq;
use hoomd_manifold::{
    Biquaternion, HyperbolicRotate, Minkowski, UnitBiquaternion,
};
use num::complex::Complex;
use std::f64::consts::PI;

let x = Minkowski::from([0.0, 0.0, 0.0, 1.0]);
let q = Biquaternion::from([
    Complex::new(0.0, PI / 4.0).sin(),
    Complex::new(0.0, 0.0),
    Complex::new(0.0, 0.0),
    Complex::new(0.0, PI / 4.0).cos(),
]);
let v = q.to_unit_unchecked();
let boosted = v.hyperbolic_rotate(&x);
assert_relative_eq!(
    boosted,
    [(PI / 2.0).sinh(), 0.0, 0.0, (PI / 2.0).cosh()].into(),
    epsilon = 1e-12
);
Source§

type Matrix = HyperbolicRotationMatrix<4>

Type of the related rotation matrix
Source§

impl<const N: usize> HyperbolicRotate<Minkowski<N>> for HyperbolicRotationMatrix<N>

Source§

fn hyperbolic_rotate(&self, vector: &Minkowski<N>) -> Minkowski<N>

Rotate a Minkowski<N> by a HyperbolicRotationMatrix

§Examples

Rotate point in 2D hyperbolic space about z-axis:

use hoomd_manifold::{
    HyperbolicAngle, HyperbolicRotate, HyperbolicRotationMatrix, Minkowski,
};
use std::f64::consts::PI;

let v = Minkowski::from([1.0, 0.0, 1.0]);
let spatial_rotation = HyperbolicAngle::from((PI / 2.0, 0.0_f64, 0.0_f64));
let matrix = HyperbolicRotationMatrix::from(spatial_rotation);
let rotated = matrix.hyperbolic_rotate(&v);
let c = Minkowski::from([(PI / 2.0).cos(), (PI / 2.0).sin(), 1.0]);
assert_eq!(c, rotated);

Boost point in 2D hyperbolic space in x direction:

use hoomd_manifold::{
    HyperbolicAngle, HyperbolicRotate, HyperbolicRotationMatrix, Minkowski,
};
use num::complex::Complex;
use std::f64::consts::PI;

let v = Minkowski::from([1.0, 0.0, 1.0]);
let small_boost = HyperbolicAngle::from((0.0_f64, 0.1_f64, 0.0_f64));
let matrix = HyperbolicRotationMatrix::from(small_boost);
let rotated = matrix.hyperbolic_rotate(&v);
let c = Minkowski::from([
    (0.1_f64).sinh() + (0.1_f64).cosh(),
    0.0,
    (0.1_f64).sinh() + (0.1_f64).cosh(),
]);
assert_eq!(c, rotated);

Zero angles and rapidities does nothing:

use hoomd_manifold::{
    HyperbolicAngle, HyperbolicRotate, HyperbolicRotationMatrix, Minkowski,
};
use num::complex::Complex;
use std::f64::consts::PI;

let v = Minkowski::from([1.0, 2.0, 1.0]);
let identity = HyperbolicAngle::from((0.0_f64, 0.0_f64, 0.0_f64));
let matrix = HyperbolicRotationMatrix::from(identity);
let rotated = matrix.hyperbolic_rotate(&v);
let c = Minkowski::from([1.0, 2.0, 1.0]);
assert_eq!(c, rotated);

Rotate point in 3D hyperbolic space about y axis using matrix representation:

use approxim::assert_relative_eq;
use hoomd_manifold::{
    Biquaternion, HyperbolicRotate, HyperbolicRotationMatrix, Minkowski,
    UnitBiquaternion,
};
use num::complex::Complex;
use std::f64::consts::PI;

let q = Biquaternion::from([
    Complex::new(0.0, 0.0),
    Complex::new((PI / 4.0).sin(), 0.0),
    Complex::new(0.0, 0.0),
    Complex::new((PI / 4.0).cos(), 0.0),
]);
let v = q.to_unit()?;
let x = Minkowski::from([1.0, 0.0, 0.0, 1.0]);
let rotation = HyperbolicRotationMatrix::from(v);
let rotated = rotation.hyperbolic_rotate(&x);
assert_relative_eq!(rotated, [0.0, 0.0, -1.0, 1.0].into(), epsilon = 1e-12);

Boost point in 3D hyperbolic space in x direction using biquaternion algebra:

use approxim::assert_relative_eq;
use hoomd_manifold::{
    Biquaternion, HyperbolicRotate, Minkowski, UnitBiquaternion,
};
use num::complex::Complex;
use std::f64::consts::PI;

let x = Minkowski::from([0.0, 0.0, 0.0, 1.0]);
let q = Biquaternion::from([
    Complex::new(0.0, 0.25).sin(),
    Complex::new(0.0, 0.0),
    Complex::new(0.0, 0.0),
    Complex::new(0.0, 0.25).cos(),
]);
let v = q.to_unit()?;
let boosted = v.hyperbolic_rotate(&x);
assert_relative_eq!(
    boosted,
    [(0.5_f64).sinh(), 0.0, 0.0, (0.5_f64).cosh()].into(),
    epsilon = 1e-12
);
Source§

type Matrix = HyperbolicRotationMatrix<N>

Type of the related rotation matrix
Source§

impl<const N: usize, T> Index<T> for Minkowski<N>
where T: Into<usize> + SliceIndex<[f64], Output = f64>,

Source§

fn index(&self, index: T) -> &Self::Output

Get the value of the vector at coordinate i.

§Example
use hoomd_manifold::Minkowski;

let v = Minkowski::<3>::try_from(4..7)?;
assert_eq!((v[0], v[1], v[2]), (4.0, 5.0, 6.0));
Source§

type Output = f64

The returned type after indexing.
Source§

impl<const N: usize, T> IndexMut<T> for Minkowski<N>
where T: Into<usize> + SliceIndex<[f64], Output = f64>,

Source§

fn index_mut(&mut self, index: T) -> &mut Self::Output

Get a mutable reference to the value of the vector at coordinate i.

§Example
use hoomd_manifold::Minkowski;

let mut v = Minkowski::<3>::try_from(4..7)?;
assert_eq!((v[0], v[1], v[2]), (4.0, 5.0, 6.0));
v[0] += 1.0;
assert_eq!(v[0], 5.0);
Source§

impl<const N: usize> Metric for Minkowski<N>

Source§

fn distance_squared(&self, other: &Self) -> f64

Computes the squared distance between two points in Minkowski space.

Employs the “mostly plusses” metric signature (+ … + -).

d^2_M(\vec{x},\vec{y}) = -(x_N-y_N)^2 + \sum_{i=1}^{N-1} (x_i - y_i)^2
§Example
use hoomd_manifold::Minkowski;
use hoomd_vector::{Metric, Vector};

let x = Minkowski::from([0.0, 2.0, 3.0]);
let y = Minkowski::from([1.0, 0.0, 0.0]);
assert_eq!(-4.0, x.distance_squared(&y));
Source§

fn distance(&self, other: &Self) -> f64

Compute the distance between two vectors belonging to a metric space. Read more
Source§

fn n_dimensions(&self) -> usize

Return the number of dimensions in this vector space. Read more
Source§

impl<const N: usize> Mul<f64> for Minkowski<N>

Source§

type Output = Minkowski<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self

Performs the * operation. Read more
Source§

impl<const N: usize> MulAssign<f64> for Minkowski<N>

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl<const N: usize> Neg for Minkowski<N>

Source§

type Output = Minkowski<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const N: usize> PartialEq for Minkowski<N>

Source§

fn eq(&self, other: &Minkowski<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> RelativeEq for Minkowski<N>

Source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of [RelativeEq::relative_eq].
Source§

impl<const N: usize> Serialize for Minkowski<N>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const N: usize> Sub for Minkowski<N>

Source§

type Output = Minkowski<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<const N: usize> SubAssign for Minkowski<N>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<const N: usize> TryFrom<Range<usize>> for Minkowski<N>

Source§

fn try_from(value: Range<usize>) -> Result<Self, Self::Error>

Create a vector in Minkowski space with coordinates given by a range.

§Example
use hoomd_manifold::Minkowski;

let v = Minkowski::<3>::try_from(1..4)?;
assert_eq!(v, [1.0, 2.0, 3.0].into());
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl<const N: usize> TryFrom<Vec<f64>> for Minkowski<N>

Source§

fn try_from(value: Vec<f64>) -> Result<Self, Self::Error>

Create a vector in Minkowski with coordinates given by a Vec<f64>

§Example
use hoomd_manifold::Minkowski;

let v = Minkowski::<3>::try_from(vec![5.0, 4.0, 3.0])?;
assert_eq!(v, [5.0, 4.0, 3.0].into());

Use Minkowski::From<[f64; N]> in performance critical code.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl<const N: usize> Copy for Minkowski<N>

Source§

impl<const N: usize> StructuralPartialEq for Minkowski<N>

Source§

impl<const N: usize> Vector for Minkowski<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Minkowski<N>

§

impl<const N: usize> RefUnwindSafe for Minkowski<N>

§

impl<const N: usize> Send for Minkowski<N>

§

impl<const N: usize> Sync for Minkowski<N>

§

impl<const N: usize> Unpin for Minkowski<N>

§

impl<const N: usize> UnwindSafe for Minkowski<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,