Module math_utils

Source

Structs§

SIGNED_FELT_MAX

Constants§

STWO_PRIME

Functions§

div_mod
Finds a nonnegative integer x < p such that (m * x) % p == n.
ec_add
ec_double
Doubles a point on an elliptic curve with the equation y^2 = x^3 + alpha*x + beta mod p. Assumes the point is given in affine form (x, y) and has y != 0.
ec_double_slope
Computes the slope of an elliptic curve with the equation y^2 = x^3 + alpha*x + beta mod p, at the given point. Assumes the point is given in affine form (x, y) and has y != 0.
is_prime
isqrt
Returns the integer square root of the nonnegative integer n. This is the floor of the exact square root of n. Unlike math.sqrt(), this function doesn’t have rounding error issues.
line_slope
Computes the slope of the line connecting the two given EC points over the field GF(p). Assumes the points are given in affine form (x, y) and have different x coordinates.
pow2_const
Returns the nth (up to the 251th power) power of 2 as a Felt252 in constant time. It silently returns 1 if the input is out of bounds.
pow2_const_nz
Returns the nth (up to the 251th power) power of 2 as a [&stark_felt::NonZeroFelt] in constant time. It silently returns 1 if the input is out of bounds.
pow2147483645
M31 utility function, used specifically for Stwo. M31 operations are to be relocated into https://github.com/lambdaclass/lambdaworks. Computes the inverse in the M31 field using Fermat’s little theorem, i.e., returns v^(STWO_PRIME-2) modulo STWO_PRIME, which is the inverse of v unless v % STWO_PRIME == 0.
qm31_coordinates_to_packed_reduced
QM31 utility function, used specifically for Stwo. QM31 operations are to be relocated into https://github.com/lambdaclass/lambdaworks. Reduces four u64 coordinates and packs them into a single Felt252. STWO_PRIME fits in 36 bits, hence each coordinate can be represented by 36 bits and a QM31 element can be stored in the first 144 bits of a Felt252.
qm31_packed_reduced_add
QM31 utility function, used specifically for Stwo. QM31 operations are to be relocated into https://github.com/lambdaclass/lambdaworks. Computes the addition of two QM31 elements in reduced form. Returns an error if either operand is not reduced.
qm31_packed_reduced_div
QM31 utility function, used specifically for Stwo. QM31 operations are to be relocated into https://github.com/lambdaclass/lambdaworks. Computes the division of two QM31 elements in reduced form. Returns an error if the input is zero.
qm31_packed_reduced_inv
QM31 utility function, used specifically for Stwo. QM31 operations are to be relocated into https://github.com/lambdaclass/lambdaworks. Computes the inverse of a QM31 element in reduced form. Returns an error if the denominator is zero or either operand is not reduced.
qm31_packed_reduced_mul
QM31 utility function, used specifically for Stwo. QM31 operations are to be relocated into https://github.com/lambdaclass/lambdaworks. Computes the multiplication of two QM31 elements in reduced form. Returns an error if either operand is not reduced.
qm31_packed_reduced_neg
QM31 utility function, used specifically for Stwo. QM31 operations are to be relocated into https://github.com/lambdaclass/lambdaworks. Computes the negative of a QM31 element in reduced form. Returns an error if the input is not reduced.
qm31_packed_reduced_sub
QM31 utility function, used specifically for Stwo. QM31 operations are to be relocated into https://github.com/lambdaclass/lambdaworks. Computes the subtraction of two QM31 elements in reduced form. Returns an error if either operand is not reduced.
safe_div
Performs integer division between x and y; fails if x is not divisible by y.
safe_div_bigint
Performs integer division between x and y; fails if x is not divisible by y.
safe_div_usize
Performs integer division between x and y; fails if x is not divisible by y.
signed_felt
Converts Felt252 into a BigInt number in the range: (- FIELD / 2, FIELD / 2).
sqrt_prime_power