pub trait Invertible: Magma {
// Required method
fn inverse(x: &Self::T) -> Self::T;
// Provided methods
fn rinv_operate(x: &Self::T, y: &Self::T) -> Self::T { ... }
fn rinv_operate_assign(x: &mut Self::T, y: &Self::T) { ... }
}
Expand description
$\exists e \in T, \forall a \in T, \exists b,c \in T, b \circ a = a \circ c = e$
Required Methods§
Provided Methods§
Sourcefn rinv_operate(x: &Self::T, y: &Self::T) -> Self::T
fn rinv_operate(x: &Self::T, y: &Self::T) -> Self::T
Examples found in repository?
More examples
crates/competitive/src/algebra/ring.rs (line 47)
46 fn sub(x: &Self::T, y: &Self::T) -> Self::T {
47 <Self::Additive as Invertible>::rinv_operate(x, y)
48 }
49
50 fn sub_assign(x: &mut Self::T, y: &Self::T) {
51 <Self::Additive as Invertible>::rinv_operate_assign(x, y);
52 }
53}
54
55impl<R> Ring for R
56where
57 R: SemiRing,
58 R::Additive: Invertible,
59{
60}
61
62pub trait Field: Ring
63where
64 Self::Additive: Invertible,
65 Self::Multiplicative: Invertible,
66{
67 /// multiplicative inverse: $-$
68 fn inv(x: &Self::T) -> Self::T {
69 <Self::Multiplicative as Invertible>::inverse(x)
70 }
71 /// multiplicative right inversed operaion: $-$
72 fn div(x: &Self::T, y: &Self::T) -> Self::T {
73 <Self::Multiplicative as Invertible>::rinv_operate(x, y)
74 }
Additional examples can be found in:
- crates/competitive/src/math/lcm_convolve.rs
- crates/competitive/src/data_structure/binary_indexed_tree_2d.rs
- crates/competitive/src/math/quotient_array.rs
- crates/competitive/src/data_structure/accumulate.rs
- crates/competitive/src/data_structure/union_find.rs
- crates/competitive/src/graph/minimum_spanning_tree.rs
Sourcefn rinv_operate_assign(x: &mut Self::T, y: &Self::T)
fn rinv_operate_assign(x: &mut Self::T, y: &Self::T)
Examples found in repository?
crates/competitive/src/algebra/ring.rs (line 51)
50 fn sub_assign(x: &mut Self::T, y: &Self::T) {
51 <Self::Additive as Invertible>::rinv_operate_assign(x, y);
52 }
53}
54
55impl<R> Ring for R
56where
57 R: SemiRing,
58 R::Additive: Invertible,
59{
60}
61
62pub trait Field: Ring
63where
64 Self::Additive: Invertible,
65 Self::Multiplicative: Invertible,
66{
67 /// multiplicative inverse: $-$
68 fn inv(x: &Self::T) -> Self::T {
69 <Self::Multiplicative as Invertible>::inverse(x)
70 }
71 /// multiplicative right inversed operaion: $-$
72 fn div(x: &Self::T, y: &Self::T) -> Self::T {
73 <Self::Multiplicative as Invertible>::rinv_operate(x, y)
74 }
75
76 fn div_assign(x: &mut Self::T, y: &Self::T) {
77 <Self::Multiplicative as Invertible>::rinv_operate_assign(x, y);
78 }
More examples
crates/competitive/src/math/quotient_array.rs (line 74)
61 pub fn lucy_dp<G>(mut self, mut mul_p: impl FnMut(T, u64) -> T) -> Self
62 where
63 G: Group<T = T>,
64 {
65 with_prime_list(self.isqrtn, |pl| {
66 for &p in pl.primes_lte(self.isqrtn) {
67 let k = self.quotient_index(p - 1);
68 let p2 = p * p;
69 for (i, q) in Self::index_iter(self.n, self.isqrtn).enumerate() {
70 if q < p2 {
71 break;
72 }
73 let diff = mul_p(G::rinv_operate(&self[q / p], &self.data[k]), p);
74 G::rinv_operate_assign(&mut self.data[i], &diff);
75 }
76 }
77 });
78 self
79 }
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.