Added polynomial class

This commit is contained in:
Daniel Sanchez Quiros 2024-02-20 13:02:26 +01:00
parent 9a54d90d14
commit bba8760fc5
2 changed files with 22 additions and 0 deletions

0
da/kzg_rs/__init__.py Normal file
View File

22
da/kzg_rs/poly.py Normal file
View File

@ -0,0 +1,22 @@
from typing import Self, List
from eth2spec.eip7594.mainnet import BLS_MODULUS
import numpy as np
from sympy import ntt, intt
class Polynomial[T](np.polynomial.Polynomial):
def __init__(self, coef, domain=None, window=None, symbol="x"):
self.coef = coef
super().__init__(coef, domain, window, symbol)
def eval(self, x: T) -> T:
return np.polyval(self, x)
def evaluation_form(self, modulus=BLS_MODULUS) -> Self:
return Polynomial(intt(reversed(self), prime=modulus))
# def __truediv__(self, other):
# return Polynomial(list(reversed(np.polydiv(list(reversed(self.coef)), list(reversed(other.coef))))))
def __getitem__(self, item):
return self.coef[item]