Skip to main content

RingExtension

Trait RingExtension 

Source
pub trait RingExtension: RingBase {
    type BaseRing: RingStore;

    // Required methods
    fn base_ring(&self) -> &Self::BaseRing;
    fn from(&self, x: El<Self::BaseRing>) -> Self::Element;

    // Provided methods
    fn from_ref(&self, x: &El<Self::BaseRing>) -> Self::Element { ... }
    fn mul_assign_base(&self, lhs: &mut Self::Element, rhs: &El<Self::BaseRing>) { ... }
    fn fma_base(
        &self,
        lhs: &Self::Element,
        rhs: &El<Self::BaseRing>,
        summand: Self::Element,
    ) -> Self::Element { ... }
    fn mul_assign_base_through_hom<S: ?Sized + RingBase, H: Homomorphism<S, <Self::BaseRing as RingStore>::Type>>(
        &self,
        lhs: &mut Self::Element,
        rhs: &S::Element,
        hom: H,
    ) { ... }
}
Expand description

Trait for rings that are an extension ring of a base ring. This does not have to be a proper extension in the mathematical sense, but is in some cases implemented for a wrapper of a ring object that represents the same ring.

Hence, this is technically just a ring R with an injective homomorphism BaseRing -> R, but unlike CanHomFrom, implementors must provide a reference to BaseRing via RingExtension::base_ring().

§Overlap with CanHomFrom

There is a certain amount of functionality overlap with CanHomFrom, and in a perfect world, this trait would also be a subtrait of CanHomFrom<<Self::BaseRing as RingStore>::Type>. However, due to the issue with multiple blanket implementations for CanHomFrom (see the docs), this is not the case and in fact there are ring extensions that do not implement CanHomFrom<<Self::BaseRing as RingStore>::Type>.

Required Associated Types§

Source

type BaseRing: RingStore

Type of the base ring;

This is bounded by RingStore to encourage implementations of RingExtension to store their base ring as a RingStore (RingStore is designed exactly for this use case). Additionally, it makes using the base ring easier.

Required Methods§

Source

fn base_ring(&self) -> &Self::BaseRing

Returns a reference to the base ring.

Source

fn from(&self, x: El<Self::BaseRing>) -> Self::Element

Maps an element of the base ring into this ring.

This should realize an injective ring homomorphism. Instead of calling it directly, consider using it through RingExtensionStore::inclusion().

Provided Methods§

Source

fn from_ref(&self, x: &El<Self::BaseRing>) -> Self::Element

Maps an element of the base ring (given as reference) into this ring.

Source

fn mul_assign_base(&self, lhs: &mut Self::Element, rhs: &El<Self::BaseRing>)

Computes lhs := lhs * rhs, where rhs is mapped into this ring via RingExtension::from_ref(). Note that this may be faster than self.mul_assign(lhs, self.from_ref(rhs)).

Source

fn fma_base( &self, lhs: &Self::Element, rhs: &El<Self::BaseRing>, summand: Self::Element, ) -> Self::Element

Source

fn mul_assign_base_through_hom<S: ?Sized + RingBase, H: Homomorphism<S, <Self::BaseRing as RingStore>::Type>>( &self, lhs: &mut Self::Element, rhs: &S::Element, hom: H, )

Computes lhs := lhs * rhs, where rhs is mapped into this ring via the given homomorphism, followed by the inclusion (as specified by RingExtension::from_ref()).

This is designed for the case that an extension ring element is represented as a vector of base ring elements, in which case this function can make use of an optimized Homomorphism::mul_assign_map() implementation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§