示例#1
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
示例#2
0
文件: zmod.py 项目: 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
示例#3
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)
示例#4
0
文件: zmod.py 项目: 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)
示例#5
0
# module 'zmod'
示例#6
0
文件: zmod.py 项目: mcyril/ravel-ftn
# module 'zmod'