Struct SurrealInf

Source
pub struct SurrealInf { /* private fields */ }
Expand description

A struct to represent surreal numbers with at least one infinite set.

Implementations§

Source§

impl SurrealInf

Source

pub fn new( left: Box<dyn Fn(u32) -> Option<Surreal>>, right: Box<dyn Fn(u32) -> Option<Surreal>>, ) -> SurrealInf

Creates a new surreal number with infinite sets, where these sets are described by two closures that return surreal numbers with non-infinite sets. These series can also return the same number to represent a non-infinite set, as all non-infinite sets can be reduced to a single element.

§Panics

Because infinite sets can’t be fully computed, there is no guarantee that all items in the left set are less than all items in the right set. This means that, not only is comparison impossible, but arithmetic is as well.

§Examples
let omega = surreal::SurrealInf::new(
    Box::new(|n: u32| Some(surreal::ftos((n + 1) as f32))),
    Box::new(|n: u32| None),
);

let epsilon = surreal::SurrealInf::new(
    Box::new(|n: u32| Some(surreal::Surreal::new(vec![], vec![]))),
    Box::new(|n: u32| Some(surreal::ftos(1.0/(2_i32.pow(n) as f32)))),
);
Source

pub fn left(&self, index: u32) -> Option<Surreal>

Returns the left set of a surreal number (as a Vec<Surreal> instead of a Vec<&Surreal>).

§Examples
let omega = surreal::SurrealInf::new(
    Box::new(|n: u32| Some(surreal::ftos((n + 1) as f32))),
    Box::new(|n: u32| None),
);

if let Some(i) = omega.left(0) {
    assert!(i == surreal::ftos(1.0));
}
Source

pub fn right(&self, index: u32) -> Option<Surreal>

Returns the right set of a surreal number (as a Vec<Surreal> instead of a Vec<&Surreal>).

§Examples
let epsilon = surreal::SurrealInf::new(
    Box::new(|n: u32| Some(surreal::Surreal::new(vec![], vec![]))),
    Box::new(|n: u32| Some(surreal::ftos(1.0/(2_i32.pow(n) as f32)))),
);

if let Some(i) = epsilon.right(0) {
    assert!(i == surreal::ftos(1.0));
}

Auto Trait Implementations§

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