Skip to main content

Rational

Struct Rational 

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

A reduced rational number with i128 numerator and positive i128 denominator.

Trait arithmetic panics when an intermediate or result leaves the fixed-width carrier; the checked_* methods expose the same boundary as Option.

Implementations§

Source§

impl Rational

Source

pub fn try_new(num: i128, den: i128) -> Option<Self>

Construct num / den in lowest terms.

Returns None for a zero denominator or if sign normalization cannot be represented in i128.

Source

pub fn new(num: i128, den: i128) -> Self

Construct num / den in lowest terms.

Panics for a zero denominator or unrepresentable sign normalization; use try_new for a checked result.

Source

pub fn sign(&self) -> Ordering

Sign as an Ordering relative to zero (den is always > 0).

Source

pub fn is_integer(&self) -> bool

True iff this rational is a (rational) integer, i.e. its denominator is 1. Used by the omnific-integer backend to test the constant CNF term.

Source

pub fn numer(&self) -> i128

The numerator (in lowest terms; carries the sign).

Source

pub fn denom(&self) -> i128

The denominator (in lowest terms; always > 0).

Source

pub fn cmp(&self, other: &Self) -> Ordering

Total order on values (denominator is always positive).

Source

pub fn floor(&self) -> i128

The greatest integer ≤ this rational.

Source

pub fn sqrt(&self) -> Option<Rational>

The exact rational square root, or None if it is not a perfect square in ℚ (numerator and denominator both perfect squares, and self ≥ 0). √2 is None here on purpose: it is not rational. This is what bounds the surreal sqrt to the ℚ-coefficient subclass.

Source

pub fn nth_root(&self, k: u128) -> Option<Rational>

The exact rational k-th root, or None if it is not a perfect k-th power in ℚ (even k requires self ≥ 0).

Source

pub fn checked_add(&self, rhs: &Self) -> Option<Self>

Checked addition: None on i128 overflow instead of panicking. The Scalar::add impl is a thin .expect() wrapper over this.

Source

pub fn checked_mul(&self, rhs: &Self) -> Option<Self>

Checked multiplication: None on i128 overflow instead of panicking. Cross-reduces first (gcd(a,d), gcd(c,b)) to keep intermediates small, the same cross-gcd-reduction the Scalar::mul impl (a thin .expect() wrapper over this) exposes.

Trait Implementations§

Source§

impl Add for Rational

Source§

type Output = Rational

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl BitXor<u128> for Rational

Source§

fn bitxor(self, k: u128) -> Rational

Square-and-multiply power: x ^ 0 == one(), x ^ k via Scalar::pow.

^ is power (grundy ). The RHS is u128 so element-element ^ does not compile — no BitXor<Self> impl exists on any backend. Precedence caveat: Rust’s ^ binds looser than *; parenthesize when mixing with product.

Source§

type Output = Rational

The resulting type after applying the ^ operator.
Source§

impl ClassifyBrauerWall for Rational

Source§

type BrauerWallClass = RationalBrauerWallClass

The Brauer-Wall class datum for this scalar world.
Source§

fn bw_class( metric: &Metric<Self>, ) -> Result<RationalBrauerWallClass, ClassifyError>

The Brauer-Wall class of Cl(metric).
Source§

impl ClassifyCliffordCenters for Rational

Source§

type CenterDiscriminant = RationalMilnorK1Class

Square or Artin–Schreier class controlling the quadratic center.
Source§

type CenterBrauerWallClass = RationalBrauerWallClass

The field-specific Brauer–Wall carrier used for the coherence check.
Source§

fn clifford_centers( metric: &Metric<Self>, ) -> Result<CliffordCenterInvariants<Self, Self::CenterDiscriminant, Self::CenterBrauerWallClass>, CliffordCenterError>

Construct Z(Cl(q)) and Z(Cl^0(q)) and compare their discriminant class with the existing Brauer–Wall coordinates.
Source§

impl ClassifyForm for Rational

Source§

type Class = RationalCliffordInvariants

The classification datum produced for this field’s characteristic leg.
Source§

fn classify( metric: &Metric<Self>, ) -> Result<RationalCliffordInvariants, ClassifyError>

Classify the form carried by metric.
Source§

impl ClassifyIsometry for Rational

Source§

fn isometric( m1: &Metric<Self>, m2: &Metric<Self>, ) -> Result<bool, ClassifyError>

Whether two forms over the same scalar world are isometric.
Source§

impl ClassifyMilnor for Rational

Source§

fn milnor_e1( metric: &Metric<Self>, ) -> Result<Self::K1Class, MilnorInvariantError>

The strict e_1 : I/I^2 -> K^M_1/2 map.
Source§

fn milnor_e2( metric: &Metric<Self>, ) -> Result<Self::K2Class, MilnorInvariantError>

The strict e_2 : I^2/I^3 -> K^M_2/2 map.
Source§

fn milnor_e0( metric: &Metric<Self>, ) -> Result<MilnorK0Class, MilnorInvariantError>

e_0(q) = dim(q) mod 2.
Source§

impl Clone for Rational

Source§

fn clone(&self) -> Rational

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 Debug for Rational

Source§

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

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

impl Display for Rational

Source§

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

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

impl Eq for Rational

Source§

impl ExactFieldScalar for Rational

Source§

impl ExactRoots for Rational

Source§

fn is_square(&self) -> bool

Whether this element is a square in its world.
Source§

fn sqrt(&self) -> Option<Self>

A square root, or None if this is not a square (in the represented subdomain). When there are two roots, the canonical / residue-lifted one.
Source§

impl ExactScalar for Rational

Source§

impl From<i128> for Rational

Source§

fn from(n: i128) -> Self

The ℤ-embedding: the unique unital ring homomorphism ℤ → ℚ.

Source§

impl GlobalField for Rational

Source§

type Place = Place

A place of the field: /Q_p for , or /finite-π for F_q(t).
Source§

fn try_relevant_places(entries: &[Self]) -> Option<Vec<Self::Place>>

The places that can carry a nontrivial local condition for entries (every other place sees only units): the archimedean place(s) plus the finite places dividing some entry.
Source§

fn try_hilbert_symbol_at( a: &Self, b: &Self, place: &Self::Place, ) -> Option<i128>

The Hilbert symbol (a, b)_v ∈ {+1, −1} over the completion at place.
Source§

fn try_is_local_square(x: &Self, place: &Self::Place) -> Option<bool>

Whether a nonzero x is a square in the local field at place.
Source§

fn try_is_global_square(x: &Self) -> Option<bool>

Whether a nonzero x is a square in the global field.
Source§

fn try_is_isotropic_at_place( entries: &[Self], place: &Self::Place, ) -> Option<bool>

Local isotropy of the nondegenerate diagonal form ⟨a_1,…,a_n⟩ over the completion at place, by rank. The archimedean branch (definiteness) and the finite branch (the Serre rank conditions) live here because the archimedean place exists only over .
Source§

fn try_hasse_at_place(entries: &[Self], place: &Self::Place) -> Option<i128>

The Hasse invariant ε_v(⟨a_1,…,a_n⟩) = ∏_{i<j} (a_i, a_j)_v at place.
Source§

fn try_reciprocity_product(a: &Self, b: &Self) -> Option<i128>

The Hilbert reciprocity product ∏_v (a,b)_v over all places — the product formula for the quaternion-algebra class (a,b). It is +1 for every nonzero a, b by Hilbert/Weil reciprocity.
Source§

fn try_ramified_places(a: &Self, b: &Self) -> Option<Vec<Self::Place>>

The places where the quaternion algebra (a, b) ramifies (symbol −1). The count is always even — reciprocity, additively.
Source§

fn try_is_isotropic_global(entries: &[Self]) -> Option<bool>

Whether ⟨a_1,…,a_n⟩ is isotropic over the global field, by Hasse–Minkowski: isotropic globally iff isotropic at every place. A zero entry is a null direction; rank ≤ 1 is anisotropic; rank 2 needs −a_1a_2 a global square; rank ≥ 3 needs local isotropy at every relevant place.
Source§

impl HasRingOfIntegers for Rational

Source§

type Int = Integer

The ring of integers, itself a ring whose fraction field is Self.
Source§

fn is_integral(&self) -> bool

Whether this element lies in the ring of integers.
Source§

fn to_integer(&self) -> Option<Integer>

This element as a ring-of-integers element, or None if it is not integral.
Source§

impl Mod2MilnorField for Rational

Source§

type K1Class = RationalMilnorK1Class

Carrier of K^M_1(Self)/2.
Source§

type K2Class = Brauer2Class

Carrier of K^M_2(Self)/2.
Source§

fn supports_mod2_milnor() -> bool

Whether this monomorphization is inside the implemented characteristic-not-two field domain.
Source§

fn milnor_symbol_1(a: &Self) -> Option<Self::K1Class>

The degree-one pure symbol {a}. None for a = 0 or when bounded square-class arithmetic leaves the represented domain.
Source§

fn milnor_symbol_2(a: &Self, b: &Self) -> Option<Self::K2Class>

The degree-two pure symbol {a,b}. None if either argument is zero or when the exact Brauer calculation leaves the represented domain.
Source§

impl Mul for Rational

Source§

type Output = Rational

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Rational) -> Rational

Performs the * operation. Read more
Source§

impl Neg for Rational

Source§

type Output = Rational

The resulting type after applying the - operator.
Source§

fn neg(self) -> Rational

Performs the unary - operation. Read more
Source§

impl Ord for Rational

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl Ordered for Rational

Source§

fn sign(&self) -> Ordering

Greater / Less / Equal against zero (the sign of the dominant term).
Source§

impl PartialEq for Rational

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Rational

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Scalar for Rational

Source§

fn from_int(n: i128) -> Self

Faster direct construction; semantically identical to the default double-and-add.

Source§

fn zero() -> Self

The additive identity.
Source§

fn one() -> Self

The multiplicative identity.
Source§

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

Ring addition.
Source§

fn neg(&self) -> Self

Additive inverse.
Source§

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

Ring multiplication.
Source§

fn characteristic() -> u128

Ring characteristic: 0 for characteristic-0 domains, a positive additive order of 1 for finite fields and finite quotient rings (Z/p^k, truncated Witt vectors, etc.). The engine itself gets signs from Scalar::neg; callers that care about characteristic must distinguish fields from local rings separately.
Source§

fn inv(&self) -> Option<Self>

Multiplicative inverse, or None if not invertible (zero) or not finitely representable in this backend (e.g. a non-monomial surreal, whose inverse is an infinite Hahn series).
Source§

fn is_zero(&self) -> bool

Whether this element is the additive identity.
Source§

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

Ring subtraction.
Source§

fn pow(&self, exp: u128) -> Self

self^exp by square-and-multiply over Scalar::mul/Scalar::one; x.pow(0) == one(). The same default-method precedent as Scalar::from_int: one correct implementation for every backend whose mul is total, with per-backend overrides only where a genuinely sharper algorithm exists (e.g. Nimber’s Fermat-tower nim_pow, reached through FiniteField::pow). Read more
Source§

impl Sub for Rational

Source§

type Output = Rational

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more

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