Skip to main content

BoundedDrift

Struct BoundedDrift 

Source
pub struct BoundedDrift<F> {
    pub a: i64,
    pub b: i64,
    /* private fields */
}
Expand description

Tracks the drift of a sequence of snap operations on the Eisenstein lattice.

Each step moves along a lattice direction, then applies an imperfect snap that introduces error bounded by ε (epsilon). The cumulative drift (holonomy) after n steps is bounded by n · ε.

§Type Parameters

  • F: The floating-point type used for tracking. Either f32 or f64.

§Example

use holonomy_bounded::BoundedDrift;

let mut tracker = BoundedDrift::<f64>::new(0.1);
tracker.step(3); // a -= 1
tracker.step(0); // a += 1 (back to origin ideally)
println!("Holonomy: {}", tracker.holonomy());

§Safety Proof

For each step, the error e_i satisfies 0 ≤ e_i < ε. After n steps, by the triangle inequality:

holonomy = ||P_n - P_0|| = ||Σ_i e_i · v_i|| ≤ Σ_i ||e_i · v_i|| = Σ_i e_i < n · ε

where v_i are unit vectors. The Eisenstein lattice ensures that adjacent lattice points are unit distance apart, so the maximum drift from a single mis-snap is at most ε.

Fields§

§a: i64

Current position (Eisenstein coordinates)

§b: i64

Current position (Eisenstein coordinates)

Implementations§

Source§

impl<F: Float> BoundedDrift<F>

Source

pub fn new(epsilon: F) -> Self

Create a new bounded drift tracker with a given per-step error bound.

The tracker starts at the origin (0, 0).

Source

pub fn step(&mut self, index: usize)

Take a step in direction index, applying the cumulative drift model.

The direction index corresponds to LATTICE_STEPS:

  • 0: +1 (a += 1)
  • 1: -1 + ω (a -= 1, b += 1)
  • 2: (b -= 1)
  • 3: -1 (a -= 1)
  • 4: 1 - ω (a += 1, b -= 1)
  • 5: (b += 1)

After each step, the drift from origin is bounded by step_count * epsilon.

§Panics

Panics if index >= 6.

Source

pub fn step_with_error(&mut self, index: usize, actual_error: F)

Record a step with a known actual error.

This is useful for simulations that compute the actual snap error and want to track both the empirical drift and the theoretical bound.

The actual_error must be < epsilon for the bound to apply.

Source

pub fn holonomy(&self) -> F

Current holonomy (drift from origin) as Euclidean distance.

This is the actual distance from the current position to the origin, in the complex plane (Cartesian metric).

Source

pub fn bound(&self) -> F

The theoretical bound on holonomy after n steps: n · ε.

Source

pub fn check_bound(&self) -> bool

Check whether the current holonomy satisfies the bound.

Source

pub fn steps(&self) -> usize

Number of steps taken so far.

Source

pub fn total_error(&self) -> F

Total accumulated error (Σ e_i, bounded by n·ε).

Source

pub fn max_step_error(&self) -> F

Maximum single-step error observed.

Source

pub fn reset(&mut self)

Reset the tracker to the origin.

Trait Implementations§

Source§

impl<F: Clone> Clone for BoundedDrift<F>

Source§

fn clone(&self) -> BoundedDrift<F>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<F: Debug> Debug for BoundedDrift<F>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F> Freeze for BoundedDrift<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for BoundedDrift<F>
where F: RefUnwindSafe,

§

impl<F> Send for BoundedDrift<F>
where F: Send,

§

impl<F> Sync for BoundedDrift<F>
where F: Sync,

§

impl<F> Unpin for BoundedDrift<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for BoundedDrift<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for BoundedDrift<F>
where F: UnwindSafe,

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, 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.