本文整理汇总了Python中sage.all.ZZ类的典型用法代码示例。如果您正苦于以下问题:Python ZZ类的具体用法?Python ZZ怎么用?Python ZZ使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ZZ类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: factor_out_p
def factor_out_p(val, p):
val = ZZ(val)
if val == 0 or val == -1:
return str(val)
if val==1:
return '+1'
s = 1
if val<0:
s = -1
val = -val
ord = val.valuation(p)
val = val/p**ord
out = ''
if s == -1:
out += '-'
else:
out += '+'
if ord==1:
out += str(p)
elif ord>1:
out += '%d^{%d}' % (p, ord)
if val>1:
if ord ==1:
out += r'\cdot '
out += str(val)
return out
示例2: nu1_mu_info
def nu1_mu_info(w,n):
""" return data for ST group N(U(1)) x mu(n) (of any wt > 0); these groups are not stored in the database """
assert w > 0 and n > 0
n = ZZ(n)
rec = {}
rec['label'] = "%d.2.1.d%d"%(w,n)
rec['weight'] = w
rec['degree'] = 2
rec['rational'] = boolean_name(True if n <= 2 else False)
rec['name'] = 'U(1)[D%d]'%n if n > 1 else 'N(U(1))'
rec['pretty'] = r'\mathrm{U}(1)[D_{%d}]'%n if n > 1 else r'N(\mathrm{U}(1))'
rec['real_dimension'] = 1
rec['components'] = int(2*n)
rec['ambient'] = '\mathrm{U}(2)'
rec['connected'] = boolean_name(rec['components'] == 1)
rec['st0_name'] = 'U(1)'
rec['identity_component'] = st0_pretty(rec['st0_name'])
rec['st0_description'] = '\\left\\{\\begin{bmatrix}\\alpha&0\\\\0&\\bar\\alpha\\end{bmatrix}:\\alpha\\bar\\alpha = 1,\\ \\alpha\\in\\mathbb{C}\\right\\}'
rec['component_group'] = 'D_{%d}'%n
rec['abelian'] = boolean_name(n <= 2)
rec['cyclic'] = boolean_name(n <= 1)
rec['solvable'] = boolean_name(True)
rec['trace_zero_density']='1/2'
rec['gens'] = r'\left\{\begin{bmatrix} 0 & 1\\ -1 & 0\end{bmatrix}, \begin{bmatrix} 1 & 0 \\ 0 & \zeta_{%d}\end{bmatrix}\right\}'%n
rec['numgens'] = 2
rec['subgroups'] = comma_separated_list([st_link("%d.2.1.d%d"%(w,n/p)) for p in n.prime_factors()])
rec['supgroups'] = comma_separated_list([st_link("%d.2.1.d%d"%(w,p*n)) for p in [2,3,5]] + ["$\ldots$"])
rec['moments'] = [['x'] + [ '\\mathrm{E}[x^{%d}]'%m for m in range(13)]]
nu1moments = ['1','0','1','0','3','0','10','0','35','0','126','0','462']
rec['moments'] += [['a_1'] + [nu1moments[m] if m % n == 0 else '0' for m in range(13)]]
rec['trace_moments'] = trace_moments(rec['moments'])
rec['counts'] = [['a_1', [[0,n]]]]
return rec
示例3: niceideals
def niceideals(F, ideals): #HNF + sage ideal + label
"""Convert a list of ideas from strongs to actual NumberField ideals
F is a Sage NumberField
ideals is a list of strings representing ideals I in the field, of
the form [N,a,alpha] where N is the norm of I, a the least
positive integer in I, and alpha a field element such that I is
generated by a and alpha.
The output is a list
"""
nideals = []
ilabel = 1
norm = ZZ(0)
for i in range(len(ideals)):
N,n,idl,_ = str2ideal(F,ideals[i])
assert idl.norm() == N and idl.smallest_integer() == n
if N != norm:
ilabel = ZZ(1)
norm = N
label = N.str() + '.' + ilabel.str()
hnf = idl.pari_hnf().python()
nideals.append([hnf, idl, label])
ilabel += 1
return nideals
示例4: aplist
def aplist(E, B=100):
"""
Compute aplist for an elliptic curve E over Q(sqrt(5)), as a
string->number dictionary.
INPUT:
- E -- an elliptic curve
- B -- a positive integer (default: 100)
OUTPUT:
- dictionary mapping strings (labeled primes) to Python ints,
with keys the primes of P with norm up to B such that the
norm of the conductor is coprime to the characteristic of P.
"""
from psage.modform.hilbert.sqrt5.tables import canonical_gen
v = {}
from psage.modform.hilbert.sqrt5.sqrt5 import F
labels, primes = labeled_primes_of_bounded_norm(F, B)
from sage.all import ZZ
N = E.conductor()
try:
N = ZZ(N.norm())
except:
N = ZZ(N)
for i in range(len(primes)):
p = primes[i]
k = p.residue_field()
if N.gcd(k.cardinality()) == 1:
v[labels[i]] = int(k.cardinality() + 1 - E.change_ring(k).cardinality())
return v
示例5: randomize
def randomize(self, prime):
assert not self.randomized
prev = None
for i in xrange(0, len(self.bp)):
d_i_minus_one = self.bp[i].zero.nrows()
d_i = self.bp[i].zero.ncols()
MSZp = MatrixSpace(ZZ.residue_field(ZZ.ideal(prime)), d_i_minus_one, d_i)
MSZp_square = MatrixSpace(ZZ.residue_field(ZZ.ideal(prime)), d_i, d_i)
if i != 0:
MSZp = MatrixSpace(ZZ.residue_field(ZZ.ideal(prime)), d_i_minus_one, d_i)
self.bp[i] = self.bp[i].group(MSZp, prime).mult_left(prev.adjoint())
if i != len(self.bp) - 1:
cur = MSZp_square.random_element()
self.bp[i] = self.bp[i].group(MSZp, prime).mult_right(cur)
prev = cur
# compute S * B_0
d_0 = self.bp[0].zero.nrows()
d_1 = self.bp[0].zero.ncols()
S = matrix.identity(d_0)
for i in xrange(d_0):
S[i, i] = random.randint(0, prime - 1)
MSZp = MatrixSpace(ZZ.residue_field(ZZ.ideal(prime)), d_0, d_1)
self.bp[0] = self.bp[0].group(MSZp, prime).mult_left(S)
# compute B_ell * T
r = self.bp[-1].zero.nrows()
c = self.bp[-1].zero.ncols()
T = matrix.identity(c)
for i in xrange(c):
T[i, i] = random.randint(0, prime - 1)
MSZp = MatrixSpace(ZZ.residue_field(ZZ.ideal(prime)), r, c)
self.bp[-1] = self.bp[-1].group(MSZp, prime).mult_right(T)
self.randomized = True
示例6: su2_mu_info
def su2_mu_info(w,n):
""" return data for ST group SU(2) x mu(n) (of any wt > 0); these groups are not stored in the database """
assert w > 0 and n > 0
n = ZZ(n)
rec = {}
rec['label'] = "%d.2.3.c%d"%(w,n)
rec['weight'] = w
rec['degree'] = 2
rec['rational'] = boolean_name(True if n <= 2 else False)
rec['name'] = 'SU(2)[C%d]'%n if n > 1 else 'SU(2)'
rec['pretty'] = r'\mathrm{SU}(2)[C_{%d}]'%n if n > 1 else r'\mathrm{SU}(2)'
rec['real_dimension'] = 3
rec['components'] = int(n)
rec['ambient'] = '\mathrm{U}(2)'
rec['connected'] = boolean_name(rec['components'] == 1)
rec['st0_name'] = 'SU(2)'
rec['identity_component'] = st0_pretty(rec['st0_name'])
rec['st0_description'] = r'\left\{\begin{bmatrix}\alpha&\beta\\-\bar\beta&\bar\alpha\end{bmatrix}:\alpha\bar\alpha+\beta\bar\beta = 1,\ \alpha,\beta\in\mathbb{C}\right\}'
rec['component_group'] = 'C_{%d}'%n
rec['abelian'] = boolean_name(True)
rec['cyclic'] = boolean_name(True)
rec['solvable'] = boolean_name(True)
rec['trace_zero_density']='0'
rec['gens'] = r'\begin{bmatrix} 1 & 0 \\ 0 & \zeta_{%d}\end{bmatrix}'%n
rec['numgens'] = 1
rec['subgroups'] = comma_separated_list([st_link("%d.2.3.c%d"%(w,n/p)) for p in n.prime_factors()])
rec['supgroups'] = comma_separated_list([st_link("%d.2.3.c%d"%(w,p*n)) for p in [2,3,5]] + ["$\ldots$"])
rec['moments'] = [['x'] + [ '\\mathrm{E}[x^{%d}]'%m for m in range(13)]]
su2moments = ['1','0','1','0','2','0','5','0','14','0','42','0','132']
rec['moments'] += [['a_1'] + [su2moments[m] if m % n == 0 else '0' for m in range(13)]]
rec['trace_moments'] = trace_moments(rec['moments'])
rec['counts'] = []
return rec
示例7: nextchr
def nextchr(c):
s = ord('a') - 1 # really 96
l = [ZZ(ord(j) - s) for j in list(c)]
l.reverse()
tot = ZZ(l, 27) + 1
newl = tot.digits(27)
newl.reverse()
newl = map(lambda x: x + 1 if x == 0 else x, newl)
return ''.join([chr(j + s) for j in newl])
示例8: render_hgm_webpage
def render_hgm_webpage(args):
data = None
info = {}
if 'label' in args:
label = clean_input(args['label'])
C = base.getDBConnection()
data = C.hgm.motives.find_one({'label': label})
if data is None:
bread = get_bread([("Search error", url_for('.search'))])
info['err'] = "Motive " + label + " was not found in the database."
info['label'] = label
return search_input_error(info, bread)
title = 'Hypergeometric Motive:' + label
A = data['A']
B = data['B']
tn,td = data['t']
t = latex(QQ(str(tn)+'/'+str(td)))
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
locinfo = data['locinfo']
for j in range(len(locinfo)):
locinfo[j] = [primes[j]] + locinfo[j]
locinfo[j][2] = poly_with_factored_coeffs(locinfo[j][2], primes[j])
hodge = data['hodge']
prop2 = [
('Degree', '\(%s\)' % data['degree']),
('Weight', '\(%s\)' % data['weight']),
('Conductor', '\(%s\)' % data['cond']),
]
# Now add factorization of conductor
Cond = ZZ(data['cond'])
if not (Cond.abs().is_prime() or Cond == 1):
data['cond'] = "%s=%s" % (str(Cond), factorint(data['cond']))
info.update({
'A': A,
'B': B,
't': t,
'degree': data['degree'],
'weight': data['weight'],
'sign': data['sign'],
'sig': data['sig'],
'hodge': hodge,
'cond': data['cond'],
'req': data['req'],
'locinfo': locinfo
})
AB_data, t_data = data["label"].split("_t")
#AB_data = data["label"].split("_t")[0]
friends = [("Motive family "+AB_data.replace("_"," "), url_for(".by_family_label", label = AB_data))]
friends.append(('L-function', url_for("l_functions.l_function_hgm_page", label=AB_data, t='t'+t_data)))
# if rffriend != '':
# friends.append(('Discriminant root field', rffriend))
bread = get_bread([(label, ' ')])
return render_template("hgm-show-motive.html", credit=HGM_credit, title=title, bread=bread, info=info, properties2=prop2, friends=friends)
示例9: _i_func
def _i_func(q):
'''Return i(B) in Katsurada's paper.
'''
m = ZZ(2) * (q.matrix()) ** (-1)
i = valuation(gcd(m.list()), ZZ(2))
m = ZZ(2) ** (-i) * m
if all(m[a, a] % 2 == 0 for a in range(m.ncols())):
return - i - 1
else:
return - i
示例10: read_line
def read_line(line, debug=0):
r""" Parses one line from input file. Returns and a dict containing
fields with keys as above.
Sample line: 11 a 1 0,-1,1,-10,-20 7 1,0 0,1,0 0,0 0,1
Fields: label (3 fields)
a-invariants
p0
For each bad prime: 'a' if additive
lambda,mu if multiplicative (or 'o?' if unknown)
For each good prime: lambda,mu if ordinary (or 'o?' if unknown)
lambda+,lambda-,mu if supersingular (or 's?' if unknown)
"""
data = {}
if debug: print("Parsing input line {}".format(line[:-1]))
fields = line.split()
label = fields[0]+fields[1]+fields[2]
data['label'] = label
N = ZZ(fields[0])
badp = N.support()
nbadp = len(badp)
p0 = int(fields[4])
data['iwp0'] = p0
if debug: print("p0={}".format(p0))
iwdata = {}
# read data for bad primes
for p,pdat in zip(badp,fields[5:5+nbadp]):
p = str(p)
if debug>1: print("p={}, pdat={}".format(p,pdat))
if pdat in ['o?','a']:
iwdata[p]=pdat
else:
iwdata[p]=[int(x) for x in pdat.split(",")]
# read data for all primes
for p,pdat in zip(primes(1000),fields[5+nbadp:]):
p = str(p)
if debug>1: print("p={}, pdat={}".format(p,pdat))
if pdat in ['s?','o?','a']:
iwdata[p]=pdat
else:
iwdata[p]=[int(x) for x in pdat.split(",")]
data['iwdata'] = iwdata
if debug: print("label {}, data {}".format(label,data))
return label, data
示例11: includes_composite
def includes_composite(s):
s = s.replace(" ", "").replace("..", "-")
for interval in s.split(","):
if "-" in interval[1:]:
ix = interval.index("-", 1)
a, b = int(interval[:ix]), int(interval[ix + 1 :])
if b == a:
if a != 1 and not a.is_prime():
return True
if b > a and b > 3:
return True
else:
a = ZZ(interval)
if a != 1 and not a.is_prime():
return True
示例12: finite_field
def finite_field():
"""
Create a random finite field with degree at most 20 and prime at most 10^6.
OUTPUT:
a finite field
EXAMPLES:
sage: sage.rings.tests.finite_field()
Finite Field in a of size 161123^4
"""
from sage.all import ZZ, GF
p = ZZ.random_element(x=2, y=10**6-18).next_prime()
d = ZZ.random_element(x=1, y=20)
return GF(p**d,'a')
示例13: rsa
def rsa(bits):
# only prove correctness up to 1024bits
proof = (bits <= 1024)
p = next_prime(ZZ.random_element(2**(bits // 2 + 1)),
proof=proof)
q = next_prime(ZZ.random_element(2**(bits // 2 + 1)),
proof=proof)
n = p * q
phi_n = (p - 1) * (q - 1)
while True:
e = ZZ.random_element(1, phi_n)
if gcd(e, phi_n) == 1:
break
d = lift(Mod(e, phi_n)**(-1))
return e, d, n
示例14: includes_composite
def includes_composite(s):
s = s.replace(' ','').replace('..','-')
for interval in s.split(','):
if '-' in interval[1:]:
ix = interval.index('-',1)
a,b = int(interval[:ix]), int(interval[ix+1:])
if b == a:
if a != 1 and not a.is_prime():
return True
if b > a and b > 3:
return True
else:
a = ZZ(interval)
if a != 1 and not a.is_prime():
return True
示例15: random_element
def random_element(self, x=None, y=None, distribution=None):
"""
Return a random integer in Pari.
NOTE:
The given arguments are passed to ``ZZ.random_element(...)``.
INPUT:
- `x`, `y` -- optional integers, that are lower and upper bound
for the result. If only `x` is provided, then the result is
between 0 and `x-1`, inclusive. If both are provided, then the
result is between `x` and `y-1`, inclusive.
- `distribution` -- optional string, so that ``ZZ`` can make sense
of it as a probability distribution.
EXAMPLE::
sage: R = PariRing()
sage: R.random_element()
-8
sage: R.random_element(5,13)
12
sage: [R.random_element(distribution="1/n") for _ in range(10)]
[0, 1, -1, 2, 1, -95, -1, -2, -12, 0]
"""
from sage.all import ZZ
return self(ZZ.random_element(x,y,distribution))