Skip to content

Commit

Permalink
feat(MLEPolynomial): Add mul_quotients method
Browse files Browse the repository at this point in the history
Remove eval_from_coeffs method and implement mul_quotients for efficient polynomial multiplication using MLE representation
  • Loading branch information
ahy231 committed Sep 30, 2024
1 parent ca36a54 commit 564e09b
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/mle2.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,6 @@ def evaluate_from_coeffs(coeffs, zs):
half >>= 1
return f[0]

@staticmethod
def eval_from_coeffs(coeffs, z):
t = 1
v = 0
for i in range(0, len(coeffs)):
v += coeffs[i] * t
t *= z
return v

def decompose_by_div(self, point):
"""
Divide an MLE at the point: [X_0, X_1, ..., X_{n-1}] in O(N) (Linear!)
Expand Down Expand Up @@ -192,3 +183,25 @@ def decompose_by_div_from_coeffs(coeffs: list, point: list) -> list:
half >>= 1

return quotients, coeffs[0]

def mul_quotients(quotient, remainder, p):
"""
r: current remainder
q: current quotient
p: current point
last_remainder
= r + (xi - p) * q
= r - p * q + xi * q
= (r - p * q) * (1 - xi) + (r - (p - 1) * q) * xi
"""

assert isinstance(quotient, MLEPolynomial), "quotient must be an MLEPolynomial"
assert isinstance(remainder, MLEPolynomial), "remainder must be an MLEPolynomial"

half = len(quotient.evals)
result = [0] * 2 * half
for i, (q, r) in enumerate(zip(quotient.evals, remainder.evals)):
result[i] = r - p * q
result[i + half] = r - (p - 1) * q
return MLEPolynomial(result, quotient.num_var + 1)

0 comments on commit 564e09b

Please sign in to comment.