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
impl Rational
Sourcepub fn try_new(num: i128, den: i128) -> Option<Self>
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.
Sourcepub fn new(num: i128, den: i128) -> Self
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.
Sourcepub fn is_integer(&self) -> bool
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.
Sourcepub fn cmp(&self, other: &Self) -> Ordering
pub fn cmp(&self, other: &Self) -> Ordering
Total order on values (denominator is always positive).
Sourcepub fn sqrt(&self) -> Option<Rational>
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.
Sourcepub fn nth_root(&self, k: u128) -> Option<Rational>
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).
Sourcepub fn checked_add(&self, rhs: &Self) -> Option<Self>
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.
Sourcepub fn checked_mul(&self, rhs: &Self) -> Option<Self>
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 BitXor<u128> for Rational
impl BitXor<u128> for Rational
Source§fn bitxor(self, k: u128) -> Rational
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§impl ClassifyBrauerWall for Rational
impl ClassifyBrauerWall for Rational
Source§type BrauerWallClass = RationalBrauerWallClass
type BrauerWallClass = RationalBrauerWallClass
Source§fn bw_class(
metric: &Metric<Self>,
) -> Result<RationalBrauerWallClass, ClassifyError>
fn bw_class( metric: &Metric<Self>, ) -> Result<RationalBrauerWallClass, ClassifyError>
Cl(metric).Source§impl ClassifyCliffordCenters for Rational
impl ClassifyCliffordCenters for Rational
Source§type CenterDiscriminant = RationalMilnorK1Class
type CenterDiscriminant = RationalMilnorK1Class
Source§type CenterBrauerWallClass = RationalBrauerWallClass
type CenterBrauerWallClass = RationalBrauerWallClass
Source§fn clifford_centers(
metric: &Metric<Self>,
) -> Result<CliffordCenterInvariants<Self, Self::CenterDiscriminant, Self::CenterBrauerWallClass>, CliffordCenterError>
fn clifford_centers( metric: &Metric<Self>, ) -> Result<CliffordCenterInvariants<Self, Self::CenterDiscriminant, Self::CenterBrauerWallClass>, CliffordCenterError>
Z(Cl(q)) and Z(Cl^0(q)) and compare their discriminant
class with the existing Brauer–Wall coordinates.Source§impl ClassifyForm for Rational
impl ClassifyForm for Rational
Source§type Class = RationalCliffordInvariants
type Class = RationalCliffordInvariants
Source§fn classify(
metric: &Metric<Self>,
) -> Result<RationalCliffordInvariants, ClassifyError>
fn classify( metric: &Metric<Self>, ) -> Result<RationalCliffordInvariants, ClassifyError>
metric.Source§impl ClassifyIsometry for Rational
impl ClassifyIsometry for Rational
Source§impl ClassifyMilnor for Rational
impl ClassifyMilnor for Rational
Source§fn milnor_e1(
metric: &Metric<Self>,
) -> Result<Self::K1Class, MilnorInvariantError>
fn milnor_e1( metric: &Metric<Self>, ) -> Result<Self::K1Class, MilnorInvariantError>
e_1 : I/I^2 -> K^M_1/2 map.Source§fn milnor_e2(
metric: &Metric<Self>,
) -> Result<Self::K2Class, MilnorInvariantError>
fn milnor_e2( metric: &Metric<Self>, ) -> Result<Self::K2Class, MilnorInvariantError>
e_2 : I^2/I^3 -> K^M_2/2 map.Source§fn milnor_e0(
metric: &Metric<Self>,
) -> Result<MilnorK0Class, MilnorInvariantError>
fn milnor_e0( metric: &Metric<Self>, ) -> Result<MilnorK0Class, MilnorInvariantError>
e_0(q) = dim(q) mod 2.impl Eq for Rational
impl ExactFieldScalar for Rational
Source§impl ExactRoots for Rational
impl ExactRoots for Rational
impl ExactScalar for Rational
Source§impl GlobalField for Rational
impl GlobalField for Rational
Source§fn try_relevant_places(entries: &[Self]) -> Option<Vec<Self::Place>>
fn try_relevant_places(entries: &[Self]) -> Option<Vec<Self::Place>>
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>
fn try_hilbert_symbol_at( a: &Self, b: &Self, place: &Self::Place, ) -> Option<i128>
(a, b)_v ∈ {+1, −1} over the completion at place.Source§fn try_is_local_square(x: &Self, place: &Self::Place) -> Option<bool>
fn try_is_local_square(x: &Self, place: &Self::Place) -> Option<bool>
x is a square in the local field at place.Source§fn try_is_global_square(x: &Self) -> Option<bool>
fn try_is_global_square(x: &Self) -> Option<bool>
x is a square in the global field.Source§fn try_is_isotropic_at_place(
entries: &[Self],
place: &Self::Place,
) -> Option<bool>
fn try_is_isotropic_at_place( entries: &[Self], place: &Self::Place, ) -> Option<bool>
⟨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>
fn try_hasse_at_place(entries: &[Self], place: &Self::Place) -> Option<i128>
ε_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>
fn try_reciprocity_product(a: &Self, b: &Self) -> Option<i128>
∏_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>>
fn try_ramified_places(a: &Self, b: &Self) -> Option<Vec<Self::Place>>
(a, b) ramifies (symbol
−1). The count is always even — reciprocity, additively.Source§fn try_is_isotropic_global(entries: &[Self]) -> Option<bool>
fn try_is_isotropic_global(entries: &[Self]) -> Option<bool>
⟨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
impl HasRingOfIntegers for Rational
Source§impl Mod2MilnorField for Rational
impl Mod2MilnorField for Rational
Source§type K1Class = RationalMilnorK1Class
type K1Class = RationalMilnorK1Class
K^M_1(Self)/2.Source§type K2Class = Brauer2Class
type K2Class = Brauer2Class
K^M_2(Self)/2.Source§fn supports_mod2_milnor() -> bool
fn supports_mod2_milnor() -> bool
Source§fn milnor_symbol_1(a: &Self) -> Option<Self::K1Class>
fn milnor_symbol_1(a: &Self) -> Option<Self::K1Class>
{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>
fn milnor_symbol_2(a: &Self, b: &Self) -> Option<Self::K2Class>
{a,b}. None if either argument is zero or
when the exact Brauer calculation leaves the represented domain.Source§impl Ord for Rational
impl Ord for Rational
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Rational
impl PartialOrd for Rational
Source§impl Scalar for Rational
impl Scalar for Rational
Source§fn from_int(n: i128) -> Self
fn from_int(n: i128) -> Self
Faster direct construction; semantically identical to the default double-and-add.
Source§fn characteristic() -> u128
fn characteristic() -> u128
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>
fn inv(&self) -> Option<Self>
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 pow(&self, exp: u128) -> Self
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