Struct ruint::algorithms::LehmerMatrix
source · pub struct LehmerMatrix(pub u64, pub u64, pub u64, pub u64, pub bool);
Expand description
⚠️ Lehmer update matrix
Warning. This struct is not part of the stable API.
Signs are implicit, the boolean .4
encodes which of two sign
patterns applies. The signs and layout of the matrix are:
true false
[ .0 -.1] [-.0 .1]
[-.2 .3] [ .2 -.3]
Tuple Fields§
§0: u64
§1: u64
§2: u64
§3: u64
§4: bool
Implementations§
source§impl Matrix
impl Matrix
pub const IDENTITY: Self = _
sourcepub fn apply<const BITS: usize, const LIMBS: usize>(
&self,
a: &mut Uint<BITS, LIMBS>,
b: &mut Uint<BITS, LIMBS>,
)
pub fn apply<const BITS: usize, const LIMBS: usize>( &self, a: &mut Uint<BITS, LIMBS>, b: &mut Uint<BITS, LIMBS>, )
Applies the matrix to a Uint
.
sourcepub fn from<const BITS: usize, const LIMBS: usize>(
a: Uint<BITS, LIMBS>,
b: Uint<BITS, LIMBS>,
) -> Self
pub fn from<const BITS: usize, const LIMBS: usize>( a: Uint<BITS, LIMBS>, b: Uint<BITS, LIMBS>, ) -> Self
sourcepub fn from_u64(r0: u64, r1: u64) -> Self
pub fn from_u64(r0: u64, r1: u64) -> Self
Compute the Lehmer update matrix for small values.
This is essentially Euclids extended GCD algorithm for 64 bits.
§Panics
Panics if r0 < r1
.
sourcepub fn from_u64_prefix(a0: u64, a1: u64) -> Self
pub fn from_u64_prefix(a0: u64, a1: u64) -> Self
Compute the largest valid Lehmer update matrix for a prefix.
Compute the Lehmer update matrix for a0 and a1 such that the matrix is valid for any two large integers starting with the bits of a0 and a1.
See also mpn_hgcd2
in GMP, but ours handles the double precision bit
separately in lehmer_double
.
https://gmplib.org/repo/gmp-6.1/file/tip/mpn/generic/hgcd2.c#l226
§Panics
Panics if a0
does not have the highest bit set.
Panics if a0 < a1
.
sourcepub fn from_u128_prefix(r0: u128, r1: u128) -> Self
pub fn from_u128_prefix(r0: u128, r1: u128) -> Self
Compute the Lehmer update matrix in full 64 bit precision.
Jebelean solves this by starting in double-precission followed by single precision once values are small enough. Cohen instead runs a single precision round, refreshes the r0 and r1 values and continues with another single precision round on top. Our approach is similar to Cohen, but instead doing the second round on the same matrix, we start we a fresh matrix and multiply both in the end. This requires 8 additional multiplications, but allows us to use the tighter stopping conditions from Jebelean. It also seems the simplest out of these solutions.