Absurd

Struct Absurd 

Source
pub struct Absurd<T>
where T: Float + Clone + Debug,
{ pub complex: Complex<T>, pub absurd: Complex<T>, }
Expand description

An Absurd Number representing a + bz where a, b are complex numbers and z = 1/0 is the absurd unit.

§Type Parameters

  • T - The underlying numeric type (must implement Float + Clone + Debug)

§Mathematical Foundation

Absurd numbers extend complex numbers by introducing the absurd unit z = 1/0. This allows division by zero to be defined consistently within the algebraic structure.

§Representation

An absurd number has the form: (a + bi) + (c + di)z where:

  • a, b, c, d ∈ ℝ (real numbers)
  • i is the imaginary unit (i² = -1)
  • z is the absurd unit (z = 1/0)

§Examples

use num_absurd::*;

// Create absurd numbers
let a1: Absurd<f64> = ab!(co!(1.0, 2.0), co!(3.0, 0.0));  // (1+2i) + 3z
let a2: Absurd<f32> = ab!(2.0, 1.0);                       // 2 + z

// Arithmetic operations
let sum = a1 + a1;
let difference = a1 - a2;

Fields§

§complex: Complex<T>

The complex part (coefficient of 1)

§absurd: Complex<T>

The absurd part (coefficient of z)

Implementations§

Source§

impl<T> Absurd<T>
where T: Float + Clone + Debug,

Source

pub fn new(complex: Complex<T>, absurd: Complex<T>) -> Self

Create a new absurd number from complex and absurd parts

§Arguments
  • complex - The complex coefficient (coefficient of 1)
  • absurd - The absurd coefficient (coefficient of z)
§Examples
use num_absurd::*;

let a = Absurd::new(co!(1.0, 2.0), co!(3.0, 0.0));  // (1+2i) + 3z
Source

pub fn from_reals(complex_re: T, absurd_re: T) -> Self

Create an absurd number from real parts only

§Arguments
  • complex_re - Real part of complex coefficient
  • absurd_re - Real part of absurd coefficient
§Examples
use num_absurd::*;

let a = Absurd::from_reals(1.0, 2.0);  // 1 + 2z
// Or use the macro: ab_real!(1.0, 2.0)
Source

pub fn from_complex(complex: Complex<T>) -> Self

Create a pure complex absurd number (absurd part is zero)

§Arguments
  • complex - The complex number
§Examples
use num_absurd::*;

let a = Absurd::from_complex(co!(1.0, 2.0));  // (1+2i) + 0z
Source

pub fn from_absurd(absurd: Complex<T>) -> Self

Create a pure absurd number (complex part is zero)

§Arguments
  • absurd - The absurd coefficient
§Examples
use num_absurd::*;

let a = Absurd::from_absurd(co!(1.0, 2.0));  // 0 + (1+2i)z
Source

pub fn z() -> Self

Get the absurd unit z = 1/0

§Examples
use num_absurd::*;

let z: Absurd<f64> = Absurd::z();  // 0 + 1z
Source

pub fn is_complex(&self) -> bool

Check if this is a pure complex number (absurd part is zero)

§Examples
use num_absurd::*;

let a1 = ab!(co!(1.0, 2.0), co!(0.0, 0.0));
let a2 = ab!(co!(1.0, 2.0), co!(1.0, 0.0));

assert!(a1.is_complex());
assert!(!a2.is_complex());
Source

pub fn is_pure_absurd(&self) -> bool

Check if this is a pure absurd number (complex part is zero)

§Examples
use num_absurd::*;

let a1 = ab!(co!(0.0, 0.0), co!(1.0, 2.0));
let a2 = ab!(co!(1.0, 0.0), co!(1.0, 2.0));

assert!(a1.is_pure_absurd());
assert!(!a2.is_pure_absurd());
Source

pub fn to_complex(&self) -> Option<Complex<T>>

Attempt to convert to a complex number if absurd part is zero

§Returns

Some(complex) if absurd part is zero, None otherwise

§Examples
use num_absurd::*;

let a1 = ab!(co!(1.0, 2.0), co!(0.0, 0.0));
let a2 = ab!(co!(1.0, 2.0), co!(1.0, 0.0));

assert!(a1.to_complex().is_some());
assert!(a2.to_complex().is_none());
Source

pub fn multiply_by_z(&self) -> Self

Multiply by the absurd unit (equivalent to dividing by zero)

For any absurd number a + bz, multiplying by z gives: (a + bz) * z = az + b

This effectively “shifts” the complex part to the absurd part and reduces the absurd part by one power of z.

§Examples
use num_absurd::*;

let a = ab!(co!(1.0, 2.0), co!(3.0, 0.0));  // (1+2i) + 3z
let result = a.multiply_by_z();              // (1+2i)z + 3
Source

pub fn divide_by_zero(&self) -> Self

Divide by zero (equivalent to multiplying by the absurd unit)

This is an alias for multiply_by_z() that makes the operation more explicit in terms of division by zero.

§Examples
use num_absurd::*;

let a = ab!(co!(2.0, 0.0), co!(0.0, 0.0));  // 2 + 0z
let result = a.divide_by_zero();             // 0 + 2z (which is 2z)
Source

pub fn complex_conjugate(&self) -> Self

Get the complex conjugate of the absurd number

For an absurd number (a + bi) + (c + di)z, the complex conjugate is: (a - bi) + (c - di)z

§Examples
use num_absurd::*;

let a = ab!(co!(1.0, 2.0), co!(3.0, 4.0));
let conj = a.complex_conjugate();
// conj = (1-2i) + (3-4i)z
Source

pub fn absurd_conjugate(&self) -> Self

Get the absurd conjugate of the absurd number

For an absurd number a + bz, the absurd conjugate is: a - bz

§Examples
use num_absurd::*;

let a = ab!(co!(1.0, 2.0), co!(3.0, 4.0));
let conj = a.absurd_conjugate();
// conj = (1+2i) - (3+4i)z
Source

pub fn norm_squared(&self) -> T

Calculate the norm squared of the absurd number

For a + bz, this returns |a|² + |b|²

§Examples
use num_absurd::*;

let a = ab!(co!(3.0, 4.0), co!(1.0, 2.0));
let norm_sq = a.norm_squared();
// |3+4i|² + |1+2i|² = 25 + 5 = 30
Source

pub fn norm(&self) -> T

Calculate the norm of the absurd number

For a + bz, this returns √(|a|² + |b|²)

§Examples
use num_absurd::*;

let a = ab!(co!(3.0, 4.0), co!(0.0, 0.0));
let norm = a.norm();
// √(|3+4i|²) = √25 = 5

Trait Implementations§

Source§

impl<T> Add for Absurd<T>
where T: Float + Clone + Debug,

Source§

type Output = Absurd<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T> Clone for Absurd<T>
where T: Float + Clone + Debug + Clone,

Source§

fn clone(&self) -> Absurd<T>

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<T> Debug for Absurd<T>
where T: Float + Clone + Debug + Debug,

Source§

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

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

impl<T> Display for Absurd<T>
where T: Float + Clone + Debug + Display,

Source§

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

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

impl<T> Div for Absurd<T>
where T: Float + Clone + Debug,

Source§

type Output = Absurd<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T> Mul<T> for Absurd<T>
where T: Float + Clone + Debug,

Source§

type Output = Absurd<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Mul for Absurd<T>
where T: Float + Clone + Debug,

Source§

type Output = Absurd<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Neg for Absurd<T>
where T: Float + Clone + Debug,

Source§

type Output = Absurd<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T> One for Absurd<T>
where T: Float + Clone + Debug,

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<T> PartialEq for Absurd<T>
where T: Float + Clone + Debug + PartialEq,

Source§

fn eq(&self, other: &Absurd<T>) -> 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<T> Sub for Absurd<T>
where T: Float + Clone + Debug,

Source§

type Output = Absurd<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T> Zero for Absurd<T>
where T: Float + Clone + Debug,

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<T> StructuralPartialEq for Absurd<T>
where T: Float + Clone + Debug,

Auto Trait Implementations§

§

impl<T> Freeze for Absurd<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Absurd<T>
where T: RefUnwindSafe,

§

impl<T> Send for Absurd<T>
where T: Send,

§

impl<T> Sync for Absurd<T>
where T: Sync,

§

impl<T> Unpin for Absurd<T>
where T: Unpin,

§

impl<T> UnwindSafe for Absurd<T>
where T: 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> 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.