本文整理汇总了Python中sage.all.gcd函数的典型用法代码示例。如果您正苦于以下问题:Python gcd函数的具体用法?Python gcd怎么用?Python gcd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gcd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: make_map_latex
def make_map_latex(map_str):
# FIXME: Get rid of nu when map is defined over QQ
if "nu" not in map_str:
R0 = QQ
else:
R0 = PolynomialRing(QQ,'nu')
R = PolynomialRing(R0,2,'x,y')
F = FractionField(R)
phi = F(map_str)
num = phi.numerator()
den = phi.denominator()
c_num = num.denominator()
c_den = den.denominator()
lc = c_den/c_num
# rescale coeffs to make them integral. then try to factor out gcds
# numerator
num_new = c_num*num
num_cs = num_new.coefficients()
if R0 == QQ:
num_cs_ZZ = num_cs
else:
num_cs_ZZ = []
for el in num_cs:
num_cs_ZZ = num_cs_ZZ + el.coefficients()
num_gcd = gcd(num_cs_ZZ)
# denominator
den_new = c_den*den
den_cs = den_new.coefficients()
if R0 == QQ:
den_cs_ZZ = den_cs
else:
den_cs_ZZ = []
for el in den_cs:
den_cs_ZZ = den_cs_ZZ + el.coefficients()
den_gcd = gcd(den_cs_ZZ)
lc = lc*(num_gcd/den_gcd)
num_new = num_new/num_gcd
den_new = den_new/den_gcd
# make strings for lc, num, and den
num_str = latex(num_new)
den_str = latex(den_new)
if lc==1:
lc_str=""
else:
lc_str = latex(lc)
if den_new==1:
if lc ==1:
phi_str = num_str
else:
phi_str = lc_str+"("+num_str+")"
else:
phi_str = lc_str+"\\frac{"+num_str+"}"+"{"+den_str+"}"
return phi_str
开发者ID:kedlaya,项目名称:lmfdb,代码行数:53,代码来源:web_belyi.py
示例2: xi
def xi(self,A):
r""" The eight-root of unity in front of the Weil representation.
INPUT:
-''N'' -- integer
-''A'' -- element of PSL(2,Z)
EXAMPLES::
sage: A=SL2Z([41,77,33,62])
sage: WR.xi(A)
-zeta8^3]
sage: S,T=SL2Z.gens()
sage: WR.xi(S)
-zeta8^3
sage: WR.xi(T)
1
sage: A=SL2Z([-1,1,-4,3])
sage: WR.xi(A)
-zeta8^2
sage: A=SL2Z([0,1,-1,0])
sage: WR.xi(A)
-zeta8
"""
a=Integer(A[0,0]); b=Integer(A[0,1])
c=Integer(A[1,0]); d=Integer(A[1,1])
if(c==0):
return 1
z=CyclotomicField(8).gen()
N=self._N
N2=odd_part(N)
Neven=ZZ(2*N).divide_knowing_divisible_by(N2)
c2=odd_part(c)
Nc=gcd(Integer(2*N),Integer(c))
cNc=ZZ(c).divide_knowing_divisible_by(Nc)
f1=kronecker(-a,cNc)
f2=kronecker(cNc,ZZ(2*N).divide_knowing_divisible_by(Nc))
if(is_odd(c)):
s=c*N2
elif( c % Neven == 0):
s=(c2+1-N2)*(a+1)
else:
s=(c2+1-N2)*(a+1)-N2*a*c2
r=-1-QQ(N2)/QQ(gcd(c,N2))+s
xi=f1*f2*z**r
return xi
开发者ID:bubonic,项目名称:psage,代码行数:49,代码来源:weil_rep_simple.py
示例3: galois_orbit
def galois_orbit(cusp,G):
N=G.level()
orbit=set([])
for i in xrange(1,N):
if gcd(i,N)==1:
orbit.add(G.reduce_cusp(galois_action(cusp,i,N)))
return tuple(sorted(orbit))
开发者ID:koffie,项目名称:mdsage,代码行数:7,代码来源:maartens_sage_functions.py
示例4: x5__with_prec
def x5__with_prec(prec):
'''
Returns formal q-expansion f s.t. f * q1^(-1/2)*t^(1/2)*q2^(-1/2)
equals to x5 (x10 == x5^2).
'''
if prec not in ZZ:
prec = prec._max_value()
pwsr_prec = (2 * prec - 1) ** 2
def jacobi_g(n, r):
return x5_jacobi_g(n, r, pwsr_prec)
prec = PrecisionDeg2(prec)
fc_dct = {}
for n, r, m in prec:
if 4 * n * m - r ** 2 == 0:
fc_dct[(n, r, m)] = 0
else:
n1 = 2 * n - 1
r1 = 2 * r + 1
m1 = 2 * m - 1
if 4 * n1 * m1 - r1 ** 2 > 0:
fc_dct[(n, r, m)] = sum([d ** 4 * jacobi_g(n1 * m1 // (d ** 2),
r1 // d)
for d in
gcd([n1, r1, m1]).divisors()])
res = QexpLevel1(fc_dct, prec)
return ModFormQsrTimesQminushalf(res, 5)
开发者ID:stakemori,项目名称:degree2,代码行数:29,代码来源:scalar_valued_smfs.py
示例5: __init__
def __init__(self, modulus=1, number=1, update_from_db=True, compute=False):
r"""
Init self.
"""
emf_logger.critical("In WebChar {0}".format((modulus, number, update_from_db, compute)))
if not gcd(number, modulus) == 1:
raise ValueError, "Character number {0} of modulus {1} does not exist!".format(number, modulus)
if number > modulus:
number = number % modulus
self._properties = WebProperties(
WebInt("conductor"),
WebInt("modulus", value=modulus),
WebInt("number", value=number),
WebInt("modulus_euler_phi"),
WebInt("order"),
WebStr("latex_name"),
WebStr("label", value="{0}.{1}".format(modulus, number)),
WebNoStoreObject("sage_character", type(trivial_character(1))),
WebDict("_values_algebraic"),
WebDict("_values_float"),
WebDict("_embeddings"),
WebFloat("version", value=float(emf_version)),
)
emf_logger.debug("Set properties in WebChar!")
super(WebChar, self).__init__(update_from_db=update_from_db)
if self._has_updated_from_db is False:
self.init_dynamic_properties() # this was not done if we exited early
compute = True
if compute:
self.compute(save=True)
# emf_logger.debug('In WebChar, self.__dict__ = {0}'.format(self.__dict__))
emf_logger.debug("In WebChar, self.number = {0}".format(self.number))
开发者ID:sibilant,项目名称:lmfdb,代码行数:34,代码来源:web_character.py
示例6: projective_height
def projective_height(projective_point, abs_val=lambda x: x.abs()):
"""The projective exponential height function (works only over the rationals?)."""
denoms = [v.denominator() for v in projective_point]
nums = [v.numerator() for v in projective_point]
d = lcm(denoms)
g = gcd(nums)
return abs_val(d)/abs_val(g) * max([abs_val(v) for v in projective_point])
开发者ID:OlafMerkert,项目名称:olsage,代码行数:7,代码来源:sage_valuations.py
示例7: label_to_number
def label_to_number(modulus, number, all=False):
"""
Takes the second part of a character label and converts it to the second
part of a Conrey label. This could be trivial (just casting to an int)
or could require converting from an orbit label to a number.
If the label is invalid, returns 0.
"""
try:
number = int(number)
except ValueError:
# encoding Galois orbit
if modulus < 10000:
try:
orbit_label = '{0}.{1}'.format(modulus, 1 + class_to_int(number))
except ValueError:
return 0
else:
number = db.char_dir_orbits.lucky({'orbit_label':orbit_label}, 'galois_orbit')
if number is None:
return 0
if not all:
number = number[0]
else:
return 0
else:
if number <= 0 or gcd(modulus, number) != 1 or number > modulus:
return 0
return number
开发者ID:jvoight,项目名称:lmfdb,代码行数:29,代码来源:main.py
示例8: galoisorbit
def galoisorbit(self):
order = self.order
mod, num = self.modulus, self.number
prim = self.isprimitive
#beware this **must** be a generator
orbit = ( power_mod(num, k, mod) for k in xsrange(1, order) if gcd(k, order) == 1) # use xsrange not xrange
return ( self._char_desc(num, prim=prim) for num in orbit )
开发者ID:JRSijsling,项目名称:lmfdb,代码行数:7,代码来源:WebCharacter.py
示例9: print_as_polynomial_in_E4_and_E6
def print_as_polynomial_in_E4_and_E6(self):
r"""
"""
if(self.level() != 1):
return ""
try:
[poldeg, monomials, X] = self.as_polynomial_in_E4_and_E6()
except ValueError:
return ""
s = ""
e4 = "E_{4}"
e6 = "E_{6}"
dens = map(denominator, X)
g = gcd(dens)
s = "\\frac{1}{" + str(g) + "}\left("
for n in range(len(X)):
c = X[n] * g
if(c == -1):
s = s + "-"
elif(c != 1):
s = s + str(c)
if(n > 0 and c > 0):
s = s + "+"
d4 = monomials[n][0]
d6 = monomials[n][1]
if(d6 > 0):
s = s + e6 + "^{" + str(d6) + "}"
if(d4 > 0):
s = s + e4 + "^{" + str(d4) + "}"
s = s + "\\right)"
return "\(" + s + "\)"
开发者ID:sehlen,项目名称:modforms-db,代码行数:32,代码来源:web_modforms_computing.py
示例10: inverse_gcd
def inverse_gcd(i,N):
"""
Function IG in Mark his code
"""
i = ZZ(i); N = ZZ(N)
if N == 2*i and (i==1 or i==2):
return 1
return N/gcd(i,N)
开发者ID:koffie,项目名称:mdsage,代码行数:8,代码来源:modular_unit_divisors.py
示例11: normal_vertices
def normal_vertices(Delta):
vertices = []
for ineq in Delta.inequalities_list():
c = ineq[0]
ineq = ineq[1:]
assert gcd(ineq) == 1
vertices.append(vector(ZZ, ineq))
return vertices
开发者ID:jdemeyer,项目名称:toricbetti,代码行数:8,代码来源:polygon.py
示例12: diamond_orbit
def diamond_orbit(E,N=None):
"""
"""
if N==None:
N=E([0,0]).order()
for d in xrange(1,N):
if gcd(d,N)==1:
yield diamond_operator(E,d)
开发者ID:koffie,项目名称:mdsage,代码行数:8,代码来源:maartens_sage_functions.py
示例13: render_Dirichletwebpage
def render_Dirichletwebpage(modulus=None, number=None):
if modulus == None:
return render_DirichletNavigation()
modulus = modulus.replace(' ','')
if number == None and re.match('^[1-9][0-9]*\.[1-9][0-9]*$', modulus):
return redirect(url_for(".render_Dirichletwebpage", label=modulus), 301)
args={}
args['type'] = 'Dirichlet'
args['modulus'] = modulus
args['number'] = number
try:
modulus = int(modulus)
except ValueError:
modulus = 0
if modulus <= 0:
flash_error ("%s is not a valid modulus for a Dirichlet character. It should be a positive integer.", args['modulus'])
return redirect(url_for(".render_Dirichletwebpage"))
if modulus > 10**20:
flash_error ("specified modulus %s is too large, it should be less than $10^{20}$.", modulus)
return redirect(url_for(".render_Dirichletwebpage"))
if number == None:
if modulus < 100000:
info = WebDirichletGroup(**args).to_dict()
else:
info = WebSmallDirichletGroup(**args).to_dict()
info['bread'] = [('Characters', url_for(".render_characterNavigation")),
('Dirichlet', url_for(".render_Dirichletwebpage")),
('%d'%modulus, url_for(".render_Dirichletwebpage", modulus=modulus))]
info['learnmore'] = learn()
info['code'] = dict([(k[4:],info[k]) for k in info if k[0:4] == "code"])
info['code']['show'] = { lang:'' for lang in info['codelangs'] } # use default show names
if 'gens' in info:
info['generators'] = ', '.join([r'<a href="%s">$\chi_{%s}(%s,\cdot)$'%(url_for(".render_Dirichletwebpage",modulus=modulus,number=g),modulus,g) for g in info['gens']])
return render_template('CharGroup.html', **info)
try:
number = int(number)
except ValueError:
number = 0;
if number <= 0 or gcd(modulus,number) != 1 or number > modulus:
flash_error("the value %s is invalid. It should be a positive integer coprime to and no greater than the modulus %s.", args['number'],args['modulus'])
return redirect(url_for(".render_Dirichletwebpage"))
if modulus < 100000:
webchar = WebDirichletCharacter(**args)
info = webchar.to_dict()
else:
info = WebSmallDirichletCharacter(**args).to_dict()
info['bread'] = [('Characters', url_for(".render_characterNavigation")),
('Dirichlet', url_for(".render_Dirichletwebpage")),
('%s'%modulus, url_for(".render_Dirichletwebpage", modulus=modulus)),
('%s'%number, url_for(".render_Dirichletwebpage", modulus=modulus, number=number)) ]
info['learnmore'] = learn()
info['code'] = dict([(k[4:],info[k]) for k in info if k[0:4] == "code"])
info['code']['show'] = { lang:'' for lang in info['codelangs'] } # use default show names
return render_template('Character.html', **info)
开发者ID:JRSijsling,项目名称:lmfdb,代码行数:58,代码来源:main.py
示例14: value
def value(self, val):
val = int(val)
chartex = self.char2tex(self.modulus,self.number,val=val,tag=False)
# FIXME: bug in dirichlet_conrey logvalue
if gcd(val, self.modulus) == 1:
val = self.texlogvalue(self.chi.logvalue(val))
else:
val = 0
return '\(%s=%s\)'%(chartex,val)
开发者ID:JRSijsling,项目名称:lmfdb,代码行数:9,代码来源:WebCharacter.py
示例15: polygon_expand
def polygon_expand(Delta, len=1):
ieqs = []
for ineq in Delta.inequalities_list():
c = ineq[0]
ineq = ineq[1:]
assert c in ZZ
assert gcd(ineq) == 1
ieqs.append([c + len] + ineq)
return Polyhedron(ieqs=ieqs)
开发者ID:jdemeyer,项目名称:toricbetti,代码行数:9,代码来源:polygon.py
示例16: circle_drops
def circle_drops(A,B):
# Drops going around the unit circle for those A and B.
# See http://user.math.uzh.ch/dehaye/thesis_students/Nicolas_Wider-Integrality_of_factorial_ratios.pdf
# for longer description (not original, better references exist)
marks = lcm(lcm(A),lcm(B))
tmp = [0 for i in range(marks)]
for a in A:
# print tmp
for i in range(a):
if gcd(i, a) == 1:
tmp[i*marks/a] -= 1
for b in B:
# print tmp
for i in range(b):
if gcd(i, b) == 1:
tmp[i*marks/b] += 1
# print tmp
return [sum(tmp[:j]) for j in range(marks)]
开发者ID:AurelPage,项目名称:lmfdb,代码行数:18,代码来源:plot.py
示例17: _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
开发者ID:stakemori,项目名称:siegel_series,代码行数:10,代码来源:jordan_block_test.py
示例18: degree_cusp
def degree_cusp(i,N):
"""
Function DegreeCusp in Mark his code
returns the degree over Q of the cusp $q^(i/n)\zeta_n^j$ on X_1(N)
"""
i = ZZ(i); N = ZZ(N)
d = euler_phi(gcd(i,N))
if i == 0 or 2*i == N:
return ceil(d/2)
return d
开发者ID:koffie,项目名称:mdsage,代码行数:11,代码来源:modular_unit_divisors.py
示例19: Gelts
def Gelts(self):
res = []
m,n = self.modulus, 1
for k in xrange(1,m):
if gcd(k,m) == 1:
res.append(k)
n += 1
if n > self.maxcols:
self.coltruncate = True
break
return res
开发者ID:StockpotCreative,项目名称:lmfdb,代码行数:12,代码来源:WebCharacter.py
示例20: Gelts
def Gelts(self):
res = []
m,n,k = self.modulus, 1, 1
while k < m and n <= self.maxcols:
if gcd(k,m) == 1:
res.append(k)
n += 1
k += 1
if n > self.maxcols:
self.coltruncate = True
return res
开发者ID:JRSijsling,项目名称:lmfdb,代码行数:12,代码来源:WebCharacter.py
注:本文中的sage.all.gcd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论