Ejemplo n.º 1
0
Archivo: zmod.py Proyecto: B-Rich/breve
def make_elements(n, d):
	if d == 0: return [poly.one(0, 0)]
	sub = make_elements(n, d-1)
	all = []
	for a in sub:
		for i in range(n):
			all.append(poly.plus(a, poly.one(d-1, i)))
	return all
Ejemplo n.º 2
0
def make_elements(n, d):
	if d = 0: return [poly.one(0, 0)]
	sub = make_elements(n, d-1)
	all = []
	for a in sub:
		for i in range(n):
			all.append(poly.plus(a, poly.one(d-1, i)))
	return all
Ejemplo n.º 3
0
def make_inv(all, n, p):
	x = poly.one(1, 1)
	inv = []
	for a in all:
		inv.append(norm(poly.times(a, x), n, p))
	return inv
Ejemplo n.º 4
0
# of n and p: it may well be that some numbers have more than one
# inverse and others have none.  This is what we check.
#
# Remember that a field is a ring where each element has an inverse.
# A ring has commutative addition and multiplication, a zero and a one:
# 0*x = x*0 = 0, 0+x = x+0 = x, 1*x = x*1 = x.  Also, the distributive
# property holds: a*(b+c) = a*b + b*c.
# (XXX I forget if this is an axiom or follows from the rules.)

import poly


# Example N and polynomial

N = 5
P = poly.plus(poly.one(0, 2), poly.one(2, 1)) # 2 + x**2


# Return x modulo y.  Returns >= 0 even if x < 0.

def mod(x, y):
	return divmod(x, y)[1]


# Normalize a polynomial modulo n and modulo p.

def norm(a, n, p):
	a = poly.modulo(a, p)
	a = a[:]
	for i in range(len(a)): a[i] = mod(a[i], n)
	a = poly.normalize(a)
Ejemplo n.º 5
0
Archivo: zmod.py Proyecto: B-Rich/breve
def make_inv(all, n, p):
	x = poly.one(1, 1)
	inv = []
	for a in all:
		inv.append(norm(poly.times(a, x), n, p))
	return inv
Ejemplo n.º 6
0
Archivo: zmod.py Proyecto: B-Rich/breve
# of n and p: it may well be that some numbers have more than one
# inverse and others have none.  This is what we check.
#
# Remember that a field is a ring where each element has an inverse.
# A ring has commutative addition and multiplication, a zero and a one:
# 0*x = x*0 = 0, 0+x = x+0 = x, 1*x = x*1 = x.  Also, the distributive
# property holds: a*(b+c) = a*b + b*c.
# (XXX I forget if this is an axiom or follows from the rules.)

import poly


# Example N and polynomial

N = 5
P = poly.plus(poly.one(0, 2), poly.one(2, 1)) # 2 + x**2


# Return x modulo y.  Returns >= 0 even if x < 0.

def mod(x, y):
	return divmod(x, y)[1]


# Normalize a polynomial modulo n and modulo p.

def norm(a, n, p):
	a = poly.modulo(a, p)
	a = a[:]
	for i in range(len(a)): a[i] = mod(a[i], n)
	a = poly.normalize(a)
Ejemplo n.º 7
0
# module 'zmod'
Ejemplo n.º 8
0
# module 'zmod'