pub struct ZnReductionMap<R, S>{ /* private fields */ }Expand description
The homomorphism Z/nZ -> Z/mZ that exists whenever m | n. In
addition to the map, this also provides a function ZnReductionMap::smallest_lift()
that computes the “smallest” preimage under the map, and a function
ZnReductionMap::mul_quotient_fraction(), that computes the multiplication
with n/m while also changing from Z/mZ to Z/nZ. This is very
useful in many number theoretic applications, where one often has to switch
between Z/nZ and Z/mZ.
Furthermore, many implementations of ZnRing currently do not support
CanHomFrom-homomorphisms when the moduli are different (but divide each
other).
Implementations§
Source§impl<R, S> ZnReductionMap<R, S>
impl<R, S> ZnReductionMap<R, S>
pub fn new(from: R, to: S) -> Option<Self>
Sourcepub fn mul_quotient_fraction(&self, x: El<S>) -> El<R>
pub fn mul_quotient_fraction(&self, x: El<S>) -> El<R>
Computes the additive group homomorphism Z/mZ -> Z/nZ, x -> (n/m)x.
§Example
let Z5 = Zn::new(5);
let Z25 = Zn::new(25);
let f = ZnReductionMap::new(&Z25, &Z5).unwrap();
assert_el_eq!(Z25, Z25.int_hom().map(15), f.mul_quotient_fraction(Z5.int_hom().map(3)));Sourcepub fn smallest_lift(&self, x: El<S>) -> El<R>
pub fn smallest_lift(&self, x: El<S>) -> El<R>
Computes the smallest preimage under the reduction map Z/nZ -> Z/mZ, where
“smallest” refers to the element that has the smallest lift to Z.
§Example
let Z5 = Zn::new(5);
let Z25 = Zn::new(25);
let f = ZnReductionMap::new(&Z25, &Z5).unwrap();
assert_el_eq!(Z25, Z25.int_hom().map(-2), f.smallest_lift(Z5.int_hom().map(3)));pub fn any_preimage(&self, x: El<S>) -> El<R>
pub fn smallest_lift_ref(&self, x: &El<S>) -> El<R>
Trait Implementations§
Source§impl<R, S> Homomorphism<<R as RingStore>::Type, <S as RingStore>::Type> for ZnReductionMap<R, S>
impl<R, S> Homomorphism<<R as RingStore>::Type, <S as RingStore>::Type> for ZnReductionMap<R, S>
Source§type CodomainStore = S
type CodomainStore = S
RingStore used by this object to store the codomain ring.Source§type DomainStore = R
type DomainStore = R
RingStore used by this object to store the domain ring.Source§fn map(&self, x: El<R>) -> El<S>
fn map(&self, x: El<R>) -> El<S>
Source§fn codomain<'a>(&'a self) -> &'a Self::CodomainStore
fn codomain<'a>(&'a self) -> &'a Self::CodomainStore
Source§fn domain<'a>(&'a self) -> &'a Self::DomainStore
fn domain<'a>(&'a self) -> &'a Self::DomainStore
Source§fn map_ref(&self, x: &Domain::Element) -> Codomain::Element
fn map_ref(&self, x: &Domain::Element) -> Codomain::Element
Source§fn mul_assign_map(&self, lhs: &mut Codomain::Element, rhs: Domain::Element)
fn mul_assign_map(&self, lhs: &mut Codomain::Element, rhs: Domain::Element)
Source§fn mul_assign_ref_map(&self, lhs: &mut Codomain::Element, rhs: &Domain::Element)
fn mul_assign_ref_map(&self, lhs: &mut Codomain::Element, rhs: &Domain::Element)
Source§fn mul_map(
&self,
lhs: Codomain::Element,
rhs: Domain::Element,
) -> Codomain::Element
fn mul_map( &self, lhs: Codomain::Element, rhs: Domain::Element, ) -> Codomain::Element
Source§fn fma_map(
&self,
lhs: &Codomain::Element,
rhs: &Domain::Element,
summand: Codomain::Element,
) -> Codomain::Element
fn fma_map( &self, lhs: &Codomain::Element, rhs: &Domain::Element, summand: Codomain::Element, ) -> Codomain::Element
lhs * rhs + summand, where rhs is mapped
into the ring via this homomorphism. Read moreSource§fn mul_ref_fst_map(
&self,
lhs: &Codomain::Element,
rhs: Domain::Element,
) -> Codomain::Element
fn mul_ref_fst_map( &self, lhs: &Codomain::Element, rhs: Domain::Element, ) -> Codomain::Element
Source§fn mul_ref_snd_map(
&self,
lhs: Codomain::Element,
rhs: &Domain::Element,
) -> Codomain::Element
fn mul_ref_snd_map( &self, lhs: Codomain::Element, rhs: &Domain::Element, ) -> Codomain::Element
Source§fn mul_ref_map(
&self,
lhs: &Codomain::Element,
rhs: &Domain::Element,
) -> Codomain::Element
fn mul_ref_map( &self, lhs: &Codomain::Element, rhs: &Domain::Element, ) -> Codomain::Element
Source§fn compose<F, PrevDomain: ?Sized + RingBase>(
self,
prev: F,
) -> ComposedHom<PrevDomain, Domain, Codomain, F, Self>where
Self: Sized,
F: Homomorphism<PrevDomain, Domain>,
fn compose<F, PrevDomain: ?Sized + RingBase>(
self,
prev: F,
) -> ComposedHom<PrevDomain, Domain, Codomain, F, Self>where
Self: Sized,
F: Homomorphism<PrevDomain, Domain>,
x -> self.map(prev.map(x)).Source§fn mul_assign_ref_map_through_hom<First: ?Sized + RingBase, H: Homomorphism<First, Domain>>(
&self,
lhs: &mut Codomain::Element,
rhs: &First::Element,
hom: H,
)
fn mul_assign_ref_map_through_hom<First: ?Sized + RingBase, H: Homomorphism<First, Domain>>( &self, lhs: &mut Codomain::Element, rhs: &First::Element, hom: H, )
Source§fn mul_assign_map_through_hom<First: ?Sized + RingBase, H: Homomorphism<First, Domain>>(
&self,
lhs: &mut Codomain::Element,
rhs: First::Element,
hom: H,
)
fn mul_assign_map_through_hom<First: ?Sized + RingBase, H: Homomorphism<First, Domain>>( &self, lhs: &mut Codomain::Element, rhs: First::Element, hom: H, )
Auto Trait Implementations§
impl<R, S> Freeze for ZnReductionMap<R, S>where
R: Freeze,
S: Freeze,
<<R as RingStore>::Type as RingBase>::Element: Freeze,
<<<R as RingStore>::Type as ZnRing>::IntegerRingBase as RingBase>::Element: Freeze,
<<S as RingStore>::Type as CanHomFrom<<<S as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: Freeze,
<<R as RingStore>::Type as CanHomFrom<<<R as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: Freeze,
impl<R, S> RefUnwindSafe for ZnReductionMap<R, S>where
R: RefUnwindSafe,
S: RefUnwindSafe,
<<R as RingStore>::Type as RingBase>::Element: RefUnwindSafe,
<<<R as RingStore>::Type as ZnRing>::IntegerRingBase as RingBase>::Element: RefUnwindSafe,
<<S as RingStore>::Type as CanHomFrom<<<S as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: RefUnwindSafe,
<<R as RingStore>::Type as CanHomFrom<<<R as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: RefUnwindSafe,
impl<R, S> Send for ZnReductionMap<R, S>where
R: Send,
S: Send,
<<R as RingStore>::Type as RingBase>::Element: Send,
<<<R as RingStore>::Type as ZnRing>::IntegerRingBase as RingBase>::Element: Send,
<<S as RingStore>::Type as CanHomFrom<<<S as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: Send,
<<R as RingStore>::Type as CanHomFrom<<<R as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: Send,
impl<R, S> Sync for ZnReductionMap<R, S>where
R: Sync,
S: Sync,
<<R as RingStore>::Type as RingBase>::Element: Sync,
<<<R as RingStore>::Type as ZnRing>::IntegerRingBase as RingBase>::Element: Sync,
<<S as RingStore>::Type as CanHomFrom<<<S as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: Sync,
<<R as RingStore>::Type as CanHomFrom<<<R as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: Sync,
impl<R, S> Unpin for ZnReductionMap<R, S>where
R: Unpin,
S: Unpin,
<<R as RingStore>::Type as RingBase>::Element: Unpin,
<<<R as RingStore>::Type as ZnRing>::IntegerRingBase as RingBase>::Element: Unpin,
<<S as RingStore>::Type as CanHomFrom<<<S as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: Unpin,
<<R as RingStore>::Type as CanHomFrom<<<R as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: Unpin,
impl<R, S> UnsafeUnpin for ZnReductionMap<R, S>where
R: UnsafeUnpin,
S: UnsafeUnpin,
<<R as RingStore>::Type as RingBase>::Element: UnsafeUnpin,
<<<R as RingStore>::Type as ZnRing>::IntegerRingBase as RingBase>::Element: UnsafeUnpin,
<<S as RingStore>::Type as CanHomFrom<<<S as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: UnsafeUnpin,
<<R as RingStore>::Type as CanHomFrom<<<R as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: UnsafeUnpin,
impl<R, S> UnwindSafe for ZnReductionMap<R, S>where
R: UnwindSafe,
S: UnwindSafe,
<<R as RingStore>::Type as RingBase>::Element: UnwindSafe,
<<<R as RingStore>::Type as ZnRing>::IntegerRingBase as RingBase>::Element: UnwindSafe,
<<S as RingStore>::Type as CanHomFrom<<<S as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: UnwindSafe,
<<R as RingStore>::Type as CanHomFrom<<<R as RingStore>::Type as ZnRing>::IntegerRingBase>>::Homomorphism: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more