Trait FractionField

Source
pub trait FractionField: Field + RingExtension {
    // Required method
    fn as_fraction(
        &self,
        el: Self::Element,
    ) -> (El<Self::BaseRing>, El<Self::BaseRing>);

    // Provided method
    fn from_fraction(
        &self,
        num: El<Self::BaseRing>,
        den: El<Self::BaseRing>,
    ) -> Self::Element { ... }
}
Expand description

Trait for fields that are the field of fractions over a base ring.

Note that a field of fractions is usually the field of fractions of many rings - in particular, every field is technically its own field of fractions. However, such cases don’t add any value, and this trait is mainly designed and implemented for fields that have a “canonical” or “natural” subring whose field of fractions they represent. In many cases, this is the smallest subring whose fractions generate the whole field, but this trait can also be implemented in other cases where it makes sense.

§Availability

This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Required Methods§

Source

fn as_fraction( &self, el: Self::Element, ) -> (El<Self::BaseRing>, El<Self::BaseRing>)

Returns a, b such that the given element is a/b.

The return value does not have to be reduced, i.e. gcd(a, b) is not guaranteed to be a unit (for rings that are not crate::pid::PrincipalIdealRing, this is not even defined). Hence, when you want to convert the result to the base ring, use crate::divisibility::DivisibilityRing::checked_div() as follows:

fn to_base_ring<R>(ring: R, el: El<R>) -> Option<El<<R::Type as RingExtension>::BaseRing>>
    where R: RingStore,
        R::Type: FractionField,
        <<R::Type as RingExtension>::BaseRing as RingStore>::Type: DivisibilityRing
{
    let (a, b) = ring.as_fraction(el);
    ring.base_ring().checked_div(&a, &b)
}
let QQ = RationalField::new(StaticRing::<i64>::RING);
assert_eq!(Some(3), to_base_ring(QQ, QQ.from_fraction(6, 2)));

Provided Methods§

Source

fn from_fraction( &self, num: El<Self::BaseRing>, den: El<Self::BaseRing>, ) -> Self::Element

Computes num / den.

This is functionally equivalent, but may be faster than combining RingExtension::from() and Field::div().

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

OSZAR »