Skip to content

Commit

Permalink
secret-sharing: convert camelcase to snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Apr 20, 2020
1 parent 89ad6a5 commit f3afef3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion secret-sharing/interpolate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_interpolate_degree_3():
points = [(1, 1), (2, 0), (-3, 2), (4, 4)]
actual_polynomial = interpolate(points)
expected_evaluations = points
actual_evaluations = [(x, actual_polynomial.evaluateAt(x))
actual_evaluations = [(x, actual_polynomial(x))
for (x, y) in expected_evaluations]

for (p1, p2) in zip(expected_evaluations, actual_evaluations):
Expand Down
14 changes: 7 additions & 7 deletions secret-sharing/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ def __init__(self, coefficients):
self.indeterminate = 'x'

def add(self, other):
newCoefficients = [
new_coefficients = [
sum(x) for x in zip_longest(self, other, fillvalue=0.)
]
return Polynomial(newCoefficients)
return Polynomial(new_coefficients)

def __add__(self, other):
return self.add(other)

def multiply(self, other):
newCoeffs = [0] * (len(self) + len(other) - 1)
new_coefficients = [0] * (len(self) + len(other) - 1)

for i, a in enumerate(self):
for j, b in enumerate(other):
newCoeffs[i+j] += a*b
new_coefficients[i+j] += a*b

return Polynomial(strip(newCoeffs, 0))
return Polynomial(strip(new_coefficients, 0))

def __mul__(self, other):
return self.multiply(other)
Expand All @@ -70,7 +70,7 @@ def __repr__(self):
return ' + '.join(['%s %s^%d' % (a, self.indeterminate, i) if i > 0 else '%s' % a
for i, a in enumerate(self.coefficients)])

def evaluateAt(self, x):
def evaluate_at(self, x):
'''Evaluate a polynomial at an input point.
Uses Horner's method, first discovered by Persian mathematician
Expand All @@ -94,7 +94,7 @@ def __sub__(self, other):
return self + (-other)

def __call__(self, *args):
return self.evaluateAt(args[0])
return self.evaluate_at(args[0])


ZERO = Polynomial([])

0 comments on commit f3afef3

Please sign in to comment.