-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
444 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
def FormalDerivative(Fx): | ||
return [(x[0] * x[1], x[1] - 1) for x in Fx if x[1] > 0] | ||
return [(x[0] * x[1], x[1] - 1) for x in Fx if x[1] > 0] | ||
|
||
|
||
def polyrep(Fx): | ||
s = ["%dx ^ %d" % x for x in Fx] | ||
return " + ".join(s) | ||
s = ["%dx ^ %d" % x for x in Fx] | ||
return " + ".join(s) | ||
|
||
fx = [(-1,6),(1,0)] | ||
print(polyrep(fx)) | ||
|
||
fx = [(-1, 6), (1, 0)] | ||
print((polyrep(fx))) | ||
fx = FormalDerivative(fx) | ||
print(polyrep(fx)) | ||
print((polyrep(fx))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
|
||
class BarretReduccer(): | ||
class BarretReduccer: | ||
""" | ||
https://en.wikipedia.org/wiki/Barrett_reduction | ||
""" | ||
|
||
def __init__(self, m): | ||
if m <=0: raise ValueError("Modulus must be positive") | ||
if m & (m - 1) == 0: raise ValueError("Modulus must not be a power of 2") | ||
if m <= 0: | ||
raise ValueError("Modulus must be positive") | ||
if m & (m - 1) == 0: | ||
raise ValueError("Modulus must not be a power of 2") | ||
self.m = m | ||
self.shift = m.bit_length() << 1 | ||
self.q = (1 << self.shift) // m | ||
|
||
def reduce(self, a): | ||
#if 0 <= a <= self.m**2: raise ValueError("a must be >0 and < n^2") | ||
# if 0 <= a <= self.m**2: raise ValueError("a must be >0 and < n^2") | ||
a -= ((a * self.q) >> self.shift) * self.m | ||
if a >= self.m: a -= self.m | ||
if a >= self.m: | ||
a -= self.m | ||
return a | ||
|
||
def test(): | ||
br = BarretReduccer(12) | ||
print(br.reduce(6)) | ||
print(br.reduce(13)) | ||
print(br.reduce(18)) | ||
|
||
|
||
|
||
def test(): | ||
br = BarretReduccer(12) | ||
print((br.reduce(6))) | ||
print((br.reduce(13))) | ||
print((br.reduce(18))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ def test(): | |
ff += 1 | ||
else: | ||
nf += 1 | ||
print(n, i, ff, nf, f) | ||
print((n, i, ff, nf, f)) | ||
n += 1 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
def bpp(g,w): | ||
""" | ||
Compute the probability of all elements in group g in the whole set w to have unique birthdays. | ||
""" | ||
proba = 1 | ||
for i in range(w, w - g, -1): | ||
proba *= (i/w) | ||
return proba | ||
def bpp(g, w): | ||
""" | ||
Compute the probability of all elements in group g in the whole set w to have unique birthdays. | ||
""" | ||
proba = 1 | ||
for i in range(w, w - g, -1): | ||
proba *= i / w | ||
return proba | ||
|
||
|
||
print(bpp(23,365)) | ||
print((bpp(23, 365))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.