research/mimc_stark/better_lagrange.py

19 lines
409 B
Python
Raw Normal View History

2018-07-04 09:33:51 +00:00
def inv(a, modulus):
if a == 0:
return 0
lm, hm = 1, 0
low, high = a % modulus, modulus
while low > 1:
r = high//low
nm, new = hm-lm*r, high-low*r
lm, low, hm, high = nm, new, lm, low
return lm % modulus
def eval_poly_at(poly, x, modulus):
o, p = 0, 1
for coeff in poly:
o += coeff * p
2018-07-10 12:49:25 +00:00
p = (p * x % modulus)
2018-07-04 09:33:51 +00:00
return o % modulus