Merge pull request #5 from franklynwang/main

support add/sub scalar for monomial representation
This commit is contained in:
ying tong
2023-01-28 17:30:22 -05:00
committed by GitHub

29
poly.py
View File

@@ -31,10 +31,16 @@ class Polynomial:
)
else:
assert isinstance(other, Scalar)
return Polynomial(
[x + other for x in self.values],
self.basis,
)
if self.basis == Basis.LAGRANGE:
return Polynomial(
[x + other for x in self.values],
self.basis,
)
else:
return Polynomial(
[self.values[0] + other] + self.values[1:],
self.basis
)
def __sub__(self, other):
if isinstance(other, Polynomial):
@@ -47,10 +53,17 @@ class Polynomial:
)
else:
assert isinstance(other, Scalar)
return Polynomial(
[x - other for x in self.values],
self.basis,
)
if self.basis == Basis.LAGRANGE:
return Polynomial(
[x - other for x in self.values],
self.basis,
)
else:
return Polynomial(
[self.values[0] - other] + self.values[1:],
self.basis
)
def __mul__(self, other):
if isinstance(other, Polynomial):