本文整理汇总了Python中sage.rings.arith.is_prime函数的典型用法代码示例。如果您正苦于以下问题:Python is_prime函数的具体用法?Python is_prime怎么用?Python is_prime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_prime函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: hadamard_matrix
def hadamard_matrix(n):
"""
Tries to construct a Hadamard matrix using a combination of Paley
and Sylvester constructions.
EXAMPLES::
sage: hadamard_matrix(12).det()
2985984
sage: 12^6
2985984
sage: hadamard_matrix(2)
[ 1 1]
[ 1 -1]
sage: hadamard_matrix(8)
[ 1 1 1 1 1 1 1 1]
[ 1 -1 1 -1 1 -1 1 -1]
[ 1 1 -1 -1 1 1 -1 -1]
[ 1 -1 -1 1 1 -1 -1 1]
[ 1 1 1 1 -1 -1 -1 -1]
[ 1 -1 1 -1 -1 1 -1 1]
[ 1 1 -1 -1 -1 -1 1 1]
[ 1 -1 -1 1 -1 1 1 -1]
sage: hadamard_matrix(8).det() == 8^4
True
"""
if not(n % 4 == 0) and (n != 2):
raise ValueError("The Hadamard matrix of order %s does not exist" % n)
if n == 2:
return matrix([[1, 1], [1, -1]])
if is_even(n):
N = Integer(n / 2)
elif n == 1:
return matrix([1])
if is_prime(N - 1) and (N - 1) % 4 == 1:
return hadamard_matrix_paleyII(n)
elif n == 4 or n % 8 == 0:
had = hadamard_matrix(Integer(n / 2))
chad1 = matrix([list(r) + list(r) for r in had.rows()])
mhad = (-1) * had
R = len(had.rows())
chad2 = matrix([list(had.rows()[i]) + list(mhad.rows()[i])
for i in range(R)])
return chad1.stack(chad2)
elif is_prime(N - 1) and (N - 1) % 4 == 3:
return hadamard_matrix_paleyI(n)
else:
raise ValueError("The Hadamard matrix of order %s is not yet implemented." % n)
开发者ID:NitikaAgarwal,项目名称:sage,代码行数:48,代码来源:hadamard_matrix.py
示例2: __init__
def __init__(self, p, name=None, check=True):
"""
Return a new finite field of order $p$ where $p$ is prime.
INPUT:
- p -- an integer >= 2
- ``name`` -- ignored
- ``check`` -- bool (default: True); if False, do not
check p for primality
EXAMPLES::
sage: FiniteField(3)
Finite Field of size 3
sage: FiniteField(next_prime(1000))
Finite Field of size 1009
"""
p = integer.Integer(p)
if check and not arith.is_prime(p):
raise ArithmeticError, "p must be prime"
self.__char = p
self._IntegerModRing_generic__factored_order = factorization.Factorization([(p,1)], integer.Integer(1))
self._kwargs = {}
# FiniteField_generic does nothing more than IntegerModRing_generic, and
# it saves a non trivial overhead
integer_mod_ring.IntegerModRing_generic.__init__(self, p, category = _FiniteFields)
开发者ID:dagss,项目名称:sage,代码行数:28,代码来源:finite_field_prime_modn.py
示例3: __init__
def __init__(self, p, name=None, check=True):
"""
Return a new finite field of order `p` where `p` is prime.
INPUT:
- ``p`` -- an integer at least 2
- ``name`` -- ignored
- ``check`` -- bool (default: ``True``); if ``False``, do not
check ``p`` for primality
EXAMPLES::
sage: F = FiniteField(3); F
Finite Field of size 3
"""
p = integer.Integer(p)
if check and not arith.is_prime(p):
raise ArithmeticError("p must be prime")
self.__char = p
self._kwargs = {}
# FiniteField_generic does nothing more than IntegerModRing_generic, and
# it saves a non trivial overhead
integer_mod_ring.IntegerModRing_generic.__init__(self, p, category = _FiniteFields)
开发者ID:amitjamadagni,项目名称:sage,代码行数:26,代码来源:finite_field_prime_modn.py
示例4: apply_sparse
def apply_sparse(self, x):
"""
Return the image of x under self. If x is not in self.domain(),
raise a TypeError.
EXAMPLES:
sage: M = ModularSymbols(17,4,-1)
sage: T = M.hecke_operator(4)
sage: T.apply_sparse(M.0)
64*[X^2,(1,8)] + 24*[X^2,(1,10)] - 9*[X^2,(1,13)] + 37*[X^2,(1,16)]
sage: [ T.apply_sparse(x) == T.hecke_module_morphism()(x) for x in M.basis() ]
[True, True, True, True]
sage: N = ModularSymbols(17,4,1)
sage: T.apply_sparse(N.0)
Traceback (most recent call last):
...
TypeError: x (=[X^2,(0,1)]) must be in Modular Symbols space of dimension 4 for Gamma_0(17) of weight 4 with sign -1 over Rational Field
"""
if x not in self.domain():
raise TypeError("x (=%s) must be in %s"%(x, self.domain()))
# old version just to check for correctness
#return self.hecke_module_morphism()(x)
p = self.index()
if is_prime(p):
H = heilbronn.HeilbronnCremona(p)
else:
H = heilbronn.HeilbronnMerel(p)
M = self.parent().module()
mod2term = M._mod2term
syms = M.manin_symbols()
K = M.base_ring()
R = M.manin_gens_to_basis()
W = R.new_matrix(nrows=1, ncols = R.nrows())
B = M.manin_basis()
#from sage.all import cputime
#t = cputime()
v = x.element()
for i in v.nonzero_positions():
for h in H:
entries = syms.apply(B[i], h)
for k, w in entries:
f, s = mod2term[k]
if s:
W[0,f] += s*K(w)*v[i]
#print 'sym', cputime(t)
#t = cputime()
ans = M( v.parent()((W * R).row(0)) )
#print 'mul', cputime(t)
#print 'density: ', len(W.nonzero_positions())/(W.nrows()*float(W.ncols()))
return ans
开发者ID:BlairArchibald,项目名称:sage,代码行数:58,代码来源:hecke_operator.py
示例5: is_primitive
def is_primitive(self,return_base=False):
r"""
A pillowcase cover is primitive if it does not cover an other pillowcase
cover.
"""
from sage.rings.arith import is_prime
if is_prime(self.degree()):
return True
return bool(gap.IsPrimitive(self.monodromy()))
开发者ID:Fougeroc,项目名称:flatsurf-package,代码行数:10,代码来源:pillowcase_cover.py
示例6: create_key_and_extra_args
def create_key_and_extra_args(self, order, name=None, modulus=None, names=None, impl=None, proof=None, **kwds):
"""
EXAMPLES::
sage: GF.create_key_and_extra_args(9, 'a')
((9, ('a',), 'conway', None, '{}', 3, 2, True), {})
sage: GF.create_key_and_extra_args(9, 'a', foo='value')
((9, ('a',), 'conway', None, "{'foo': 'value'}", 3, 2, True), {'foo': 'value'})
"""
from sage.structure.proof.all import WithProof, arithmetic
if proof is None:
proof = arithmetic()
with WithProof("arithmetic", proof):
order = int(order)
if order <= 1:
raise ValueError("the order of a finite field must be > 1.")
if arith.is_prime(order):
name = None
modulus = None
p = integer.Integer(order)
n = integer.Integer(1)
elif arith.is_prime_power(order):
if not names is None:
name = names
name = normalize_names(1, name)
p, n = arith.factor(order)[0]
if modulus is None or modulus == "default":
if exists_conway_polynomial(p, n):
modulus = "conway"
else:
if p == 2:
modulus = "minimal_weight"
else:
modulus = "random"
elif modulus == "random":
modulus += str(random.randint(0, 1 << 128))
if isinstance(modulus, (list, tuple)):
modulus = FiniteField(p)["x"](modulus)
# some classes use 'random' as the modulus to
# generate a random modulus, but we don't want
# to cache it
elif sage.rings.polynomial.polynomial_element.is_Polynomial(modulus):
modulus = modulus.change_variable_name("x")
elif not isinstance(modulus, str):
raise ValueError("Modulus parameter not understood.")
else: # Neither a prime, nor a prime power
raise ValueError("the order of a finite field must be a prime power.")
return (order, name, modulus, impl, str(kwds), p, n, proof), kwds
开发者ID:sageb0t,项目名称:testsage,代码行数:54,代码来源:constructor.py
示例7: is_integral_domain
def is_integral_domain(self, proof = True):
"""
Return True if and only if the order of self is prime.
EXAMPLES::
sage: Integers(389).is_integral_domain()
True
sage: Integers(389^2).is_integral_domain()
False
"""
return is_prime(self.order())
开发者ID:CETHop,项目名称:sage,代码行数:12,代码来源:integer_mod_ring.py
示例8: hadamard_matrix_paleyI
def hadamard_matrix_paleyI(n):
"""
Implements the Paley type I construction.
EXAMPLES::
sage: sage.combinat.matrices.hadamard_matrix.hadamard_matrix_paleyI(4)
[ 1 -1 -1 -1]
[ 1 1 1 -1]
[ 1 -1 1 1]
[ 1 1 -1 1]
"""
p = n - 1
if not(is_prime(p) and (p % 4 == 3)):
raise ValueError("The order %s is not covered by the Paley type I construction." % n)
return matrix(ZZ, [[H1(i, j, p) for i in range(n)] for j in range(n)])
开发者ID:NitikaAgarwal,项目名称:sage,代码行数:16,代码来源:hadamard_matrix.py
示例9: hadamard_matrix_paleyII
def hadamard_matrix_paleyII(n):
"""
Implements the Paley type II construction.
EXAMPLES::
sage: sage.combinat.matrices.hadamard_matrix.hadamard_matrix_paleyI(12).det()
2985984
sage: 12^6
2985984
"""
N = Integer(n/2)
p = N - 1
if not(is_prime(p) and (p % 4 == 1)):
raise ValueError("The order %s is not covered by the Paley type II construction." % n)
S = matrix(ZZ, [[H2(i, j, p) for i in range(N)] for j in range(N)])
return block_matrix([[S + 1, S - 1], [S - 1, -S - 1]])
开发者ID:NitikaAgarwal,项目名称:sage,代码行数:17,代码来源:hadamard_matrix.py
示例10: CO_delta
def CO_delta(r,p,N,eps):
r"""
This is used as an intermediate value in computations related to
the paper of Cohen-Oesterle.
INPUT:
- ``r`` - positive integer
- ``p`` - a prime
- ``N`` - positive integer
- ``eps`` - character
OUTPUT: element of the base ring of the character
EXAMPLES::
sage: G.<eps> = DirichletGroup(7)
sage: sage.modular.dims.CO_delta(1,5,7,eps^3)
2
"""
if not is_prime(p):
raise ValueError("p must be prime")
K = eps.base_ring()
if p%4 == 3:
return K(0)
if p==2:
if r==1:
return K(1)
return K(0)
# interesting case: p=1(mod 4).
# omega is a primitive 4th root of unity mod p.
omega = (IntegerModRing(p).unit_gens()[0])**((p-1)//4)
# this n is within a p-power root of a "local" 4th root of 1 modulo p.
n = Mod(int(omega.crt(Mod(1,N//(p**r)))),N)
n = n**(p**(r-1)) # this is correct now
t = eps(n)
if t==K(1):
return K(2)
if t==K(-1):
return K(-2)
return K(0)
开发者ID:Etn40ff,项目名称:sage,代码行数:46,代码来源:dims.py
示例11: _element_constructor_
def _element_constructor_(self, e):
"""
TESTS::
sage: P = Sets().example()
sage: P._element_constructor_(13) == 13
True
sage: P._element_constructor_(13).parent()
Integer Ring
sage: P._element_constructor_(14)
Traceback (most recent call last):
...
AssertionError: 14 is not a prime number
"""
p = self.element_class(e)
assert is_prime(p), "%s is not a prime number"%(p)
return p
开发者ID:sageb0t,项目名称:testsage,代码行数:17,代码来源:sets_cat.py
示例12: eisen
def eisen(p):
"""
Return the Eisenstein number `n` which is the numerator of
`(p-1)/12`.
INPUT:
- ``p`` - a prime
OUTPUT: Integer
EXAMPLES::
sage: [(p,sage.modular.dims.eisen(p)) for p in prime_range(24)]
[(2, 1), (3, 1), (5, 1), (7, 1), (11, 5), (13, 1), (17, 4), (19, 3), (23, 11)]
"""
if not is_prime(p):
raise ValueError, "p must be prime"
return frac(p-1,12).numerator()
开发者ID:sageb0t,项目名称:testsage,代码行数:19,代码来源:dims.py
示例13: create_key_and_extra_args
def create_key_and_extra_args(self, order, name=None, modulus=None, names=None,
impl=None, proof=None, **kwds):
"""
EXAMPLES::
sage: GF.create_key_and_extra_args(9, 'a')
((9, ('a',), x^2 + 2*x + 2, None, '{}', 3, 2, True), {})
sage: GF.create_key_and_extra_args(9, 'a', foo='value')
((9, ('a',), x^2 + 2*x + 2, None, "{'foo': 'value'}", 3, 2, True), {'foo': 'value'})
"""
from sage.structure.proof.all import WithProof, arithmetic
if proof is None: proof = arithmetic()
with WithProof('arithmetic', proof):
order = int(order)
if order <= 1:
raise ValueError("the order of a finite field must be > 1.")
if arith.is_prime(order):
name = None
modulus = None
p = integer.Integer(order)
n = integer.Integer(1)
elif arith.is_prime_power(order):
if not names is None: name = names
name = normalize_names(1,name)
p, n = arith.factor(order)[0]
if modulus is None or isinstance(modulus, str):
# A string specifies an algorithm to find a suitable modulus.
if modulus == "default": # for backward compatibility
modulus = None
modulus = GF(p)['x'].irreducible_element(n, algorithm=modulus)
elif isinstance(modulus, (list, tuple)):
modulus = GF(p)['x'](modulus)
elif sage.rings.polynomial.polynomial_element.is_Polynomial(modulus):
modulus = modulus.change_variable_name('x')
else:
raise TypeError("wrong type for modulus parameter")
else:
raise ValueError("the order of a finite field must be a prime power.")
return (order, name, modulus, impl, str(kwds), p, n, proof), kwds
开发者ID:CETHop,项目名称:sage,代码行数:43,代码来源:constructor.py
示例14: hadamard_matrix_paleyII
def hadamard_matrix_paleyII(n):
"""
Implements the Paley type II construction.
The Paley type II case corresponds to the case `p \cong 1 \mod{4}` for a
prime `p` (see [Hora]_).
EXAMPLES::
sage: sage.combinat.matrices.hadamard_matrix.hadamard_matrix_paleyII(12).det()
2985984
sage: 12^6
2985984
We note that the method returns a normalised Hadamard matrix ::
sage: sage.combinat.matrices.hadamard_matrix.hadamard_matrix_paleyII(12)
[ 1 1 1 1 1 1| 1 1 1 1 1 1]
[ 1 1 1 -1 -1 1|-1 -1 1 -1 -1 1]
[ 1 1 1 1 -1 -1|-1 1 -1 1 -1 -1]
[ 1 -1 1 1 1 -1|-1 -1 1 -1 1 -1]
[ 1 -1 -1 1 1 1|-1 -1 -1 1 -1 1]
[ 1 1 -1 -1 1 1|-1 1 -1 -1 1 -1]
[-----------------+-----------------]
[ 1 -1 -1 -1 -1 -1|-1 1 1 1 1 1]
[ 1 -1 1 -1 -1 1| 1 -1 -1 1 1 -1]
[ 1 1 -1 1 -1 -1| 1 -1 -1 -1 1 1]
[ 1 -1 1 -1 1 -1| 1 1 -1 -1 -1 1]
[ 1 -1 -1 1 -1 1| 1 1 1 -1 -1 -1]
[ 1 1 -1 -1 1 -1| 1 -1 1 1 -1 -1]
"""
N = Integer(n/2)
p = N - 1
if not(is_prime(p) and (p % 4 == 1)):
raise ValueError("The order %s is not covered by the Paley type II construction." % n)
S = matrix(ZZ, [[H2(i, j, p) for i in range(N)] for j in range(N)])
H = block_matrix([[S + 1, S - 1], [1 - S, S + 1]])
# normalising H so that first row and column have only +1 entries.
return normalise_hadamard(H)
开发者ID:BlairArchibald,项目名称:sage,代码行数:39,代码来源:hadamard_matrix.py
示例15: is_blum_prime
def is_blum_prime(n):
r"""
Determine whether or not ``n`` is a Blum prime.
INPUT:
- ``n`` a positive prime.
OUTPUT:
- ``True`` if ``n`` is a Blum prime; ``False`` otherwise.
Let `n` be a positive prime. Then `n` is a Blum prime if `n` is
congruent to 3 modulo 4, i.e. `n \equiv 3 \pmod{4}`.
EXAMPLES:
Testing some integers to see if they are Blum primes::
sage: from sage.crypto.util import is_blum_prime
sage: from sage.crypto.util import random_blum_prime
sage: is_blum_prime(101)
False
sage: is_blum_prime(7)
True
sage: p = random_blum_prime(10**3, 10**5)
sage: is_blum_prime(p)
True
"""
if n < 0:
return False
if is_prime(n):
if mod(n, 4).lift() == 3:
return True
else:
return False
else:
return False
开发者ID:BlairArchibald,项目名称:sage,代码行数:38,代码来源:util.py
示例16: hadamard_matrix_paleyI
def hadamard_matrix_paleyI(n):
"""
Implements the Paley type I construction.
The Paley type I case corresponds to the case `p \cong 3 \mod{4}` for a
prime `p` (see [Hora]_).
EXAMPLES:
We note that this method returns a normalised Hadamard matrix ::
sage: sage.combinat.matrices.hadamard_matrix.hadamard_matrix_paleyI(4)
[ 1 1 1 1]
[ 1 -1 -1 1]
[ 1 1 -1 -1]
[ 1 -1 1 -1]
"""
p = n - 1
if not(is_prime(p) and (p % 4 == 3)):
raise ValueError("The order %s is not covered by the Paley type I construction." % n)
H = matrix(ZZ, [[H1(i, j, p) for i in range(n)] for j in range(n)])
# normalising H so that first row and column have only +1 entries.
return normalise_hadamard(H)
开发者ID:BlairArchibald,项目名称:sage,代码行数:23,代码来源:hadamard_matrix.py
示例17: has_equivalent_Jordan_decomposition_at_prime
def has_equivalent_Jordan_decomposition_at_prime(self, other, p):
"""
Determines if the given quadratic form has a Jordan decomposition
equivalent to that of self.
INPUT:
a QuadraticForm
OUTPUT:
boolean
EXAMPLES::
sage: Q1 = QuadraticForm(ZZ, 3, [1, 0, -1, 1, 0, 3])
sage: Q2 = QuadraticForm(ZZ, 3, [1, 0, 0, 2, -2, 6])
sage: Q3 = QuadraticForm(ZZ, 3, [1, 0, 0, 1, 0, 11])
sage: [Q1.level(), Q2.level(), Q3.level()]
[44, 44, 44]
sage: Q1.has_equivalent_Jordan_decomposition_at_prime(Q2,2)
False
sage: Q1.has_equivalent_Jordan_decomposition_at_prime(Q2,11)
False
sage: Q1.has_equivalent_Jordan_decomposition_at_prime(Q3,2)
False
sage: Q1.has_equivalent_Jordan_decomposition_at_prime(Q3,11)
True
sage: Q2.has_equivalent_Jordan_decomposition_at_prime(Q3,2)
True
sage: Q2.has_equivalent_Jordan_decomposition_at_prime(Q3,11)
False
"""
## Sanity Checks
#if not isinstance(other, QuadraticForm):
if type(other) != type(self):
raise TypeError, "Oops! The first argument must be of type QuadraticForm."
if not is_prime(p):
raise TypeError, "Oops! The second argument must be a prime number."
## Get the relevant local normal forms quickly
self_jordan = self.jordan_blocks_by_scale_and_unimodular(p, safe_flag= False)
other_jordan = other.jordan_blocks_by_scale_and_unimodular(p, safe_flag=False)
## DIAGNOSTIC
#print "self_jordan = ", self_jordan
#print "other_jordan = ", other_jordan
## Check for the same number of Jordan components
if len(self_jordan) != len(other_jordan):
return False
## Deal with odd primes: Check that the Jordan component scales, dimensions, and discriminants are the same
if p != 2:
for i in range(len(self_jordan)):
if (self_jordan[i][0] != other_jordan[i][0]) \
or (self_jordan[i][1].dim() != other_jordan[i][1].dim()) \
or (legendre_symbol(self_jordan[i][1].det() * other_jordan[i][1].det(), p) != 1):
return False
## All tests passed for an odd prime.
return True
## For p = 2: Check that all Jordan Invariants are the same.
elif p == 2:
## Useful definition
t = len(self_jordan) ## Define t = Number of Jordan components
## Check that all Jordan Invariants are the same (scale, dim, and norm)
for i in range(t):
if (self_jordan[i][0] != other_jordan[i][0]) \
or (self_jordan[i][1].dim() != other_jordan[i][1].dim()) \
or (valuation(GCD(self_jordan[i][1].coefficients()), p) != valuation(GCD(other_jordan[i][1].coefficients()), p)):
return False
## DIAGNOSTIC
#print "Passed the Jordan invariant test."
## Use O'Meara's isometry test 93:29 on p277.
## ------------------------------------------
## List of norms, scales, and dimensions for each i
scale_list = [ZZ(2)**self_jordan[i][0] for i in range(t)]
norm_list = [ZZ(2)**(self_jordan[i][0] + valuation(GCD(self_jordan[i][1].coefficients()), 2)) for i in range(t)]
dim_list = [(self_jordan[i][1].dim()) for i in range(t)]
## List of Hessian determinants and Hasse invariants for each Jordan (sub)chain
## (Note: This is not the same as O'Meara's Gram determinants, but ratios are the same!) -- NOT SO GOOD...
## But it matters in condition (ii), so we multiply all by 2 (instead of dividing by 2 since only square-factors matter, and it's easier.)
j = 0
self_chain_det_list = [ self_jordan[j][1].Gram_det() * (scale_list[j]**dim_list[j])]
other_chain_det_list = [ other_jordan[j][1].Gram_det() * (scale_list[j]**dim_list[j])]
self_hasse_chain_list = [ self_jordan[j][1].scale_by_factor(ZZ(2)**self_jordan[j][0]).hasse_invariant__OMeara(2) ]
other_hasse_chain_list = [ other_jordan[j][1].scale_by_factor(ZZ(2)**other_jordan[j][0]).hasse_invariant__OMeara(2) ]
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:sage-1,代码行数:101,代码来源:quadratic_form__equivalence_testing.py
示例18: green_function
def green_function(self, G,v, **kwds):
r"""
Evaluates the local Green's function at the place ``v`` for ``self`` with ``N`` terms of the series
or, in dimension 1, to within the specified error bound. Defaults to ``N=10`` if no kwds provided
Use ``v=0`` for the archimedean place. Must be over `\ZZ` or `\QQ`.
ALGORITHM:
See Exercise 5.29 and Figure 5.6 of ``The Arithmetic of Dynamics Systems``, Joseph H. Silverman, Springer, GTM 241, 2007.
INPUT:
- ``G`` - an endomorphism of self.codomain()
- ``v`` - non-negative integer. a place, use v=0 for the archimedean place
kwds:
- ``N`` - positive integer. number of terms of the series to use
- ``prec`` - positive integer, float point or p-adic precision, default: 100
- ``error_bound`` - a positive real number
OUTPUT:
- a real number
Examples::
sage: P.<x,y>=ProjectiveSpace(QQ,1)
sage: H=Hom(P,P)
sage: f=H([x^2+y^2,x*y]);
sage: Q=P(5,1)
sage: f.green_function(Q,0,N=30)
1.6460930159932946233759277576
::
sage: P.<x,y>=ProjectiveSpace(QQ,1)
sage: H=Hom(P,P)
sage: f=H([x^2+y^2,x*y]);
sage: Q=P(5,1)
sage: Q.green_function(f,0,N=200,prec=200)
1.6460930160038721802875250367738355497198064992657997569827
.. TODO::
error bounds for dimension > 1
"""
N = kwds.get('N', None) #Get number of iterates (if entered)
err = kwds.get('error_bound', None) #Get error bound (if entered)
prec = kwds.get('prec', 100) #Get precision (if entered)
R=RealField(prec)
if not (v == 0 or is_prime(v)):
raise ValueError("Invalid valuation (=%s) entered."%v)
if v == 0:
K = R
else:
K = Qp(v, prec)
#Coerce all polynomials in F into polynomials with coefficients in K
F=G.change_ring(K,False)
d = F.degree()
D=F.codomain().ambient_space().dimension_relative()
if err is not None:
if D!=1:
raise NotImplementedError("error bounds only for dimension 1")
err = R(err)
if not err>0:
raise ValueError, "Error bound (=%s) must be positive."%err
#if doing error estimates, compute needed number of iterates
res = F.resultant()
#compute maximum coefficient of polynomials of F
C = R(G.global_height(prec))
if v == 0:
log_fact = R(0)
for i in range(2*d+1):
log_fact += R(i+1).log()
B = max((R(res.abs()) - R(2*d).log() - (2*d-1)*C - log_fact).log().abs(), (C + R(d+1).log()).abs())
else:
B = max(R(res.abs()).log() - ((2*d-1)*C).abs(), C.abs())
N = R(B/(err*(d-1))).log(d).abs().ceil()
elif N is None:
N=10 #default is to do 10 iterations
#Coerce the coordinates into Q_v
self.normalize_coordinates()
if self.codomain().base_ring()==QQ:
self.clear_denominators()
P=self.change_ring(K,False)
#START GREEN FUNCTION CALCULATION
#.........这里部分代码省略.........
开发者ID:NitikaAgarwal,项目名称:sage,代码行数:101,代码来源:projective_point.py
示例19: local_genus_symbol
def local_genus_symbol(self, p):
"""
Returns the Conway-Sloane genus symbol of 2 times a quadratic form
defined over ZZ at a prime number p. This is defined (in the
Genus_Symbol_p_adic_ring() class in the quadratic_forms/genera
subfolder) to be a list of tuples (one for each Jordan component
p^m*A at p, where A is a unimodular symmetric matrix with
coefficients the p-adic integers) of the following form:
1. If p>2 then return triples of the form [`m`, `n`, `d`] where
`m` = valuation of the component
`n` = rank of A
`d` = det(A) in {1,u} for normalized quadratic non-residue u.
2. If p=2 then return quintuples of the form [`m`,`n`,`s`, `d`, `o`] where
`m` = valuation of the component
`n` = rank of A
`d` = det(A) in {1,3,5,7}
`s` = 0 (or 1) if A is even (or odd)
`o` = oddity of A (= 0 if s = 0) in Z/8Z
= the trace of the diagonalization of A
NOTE: The Conway-Sloane convention for describing the prime 'p =
-1' is not supported here, and neither is the convention for
including the 'prime' Infinity. See note on p370 of Conway-Sloane
(3rd ed) for a discussion of this convention.
INPUT:
-`p` -- a prime number > 0
OUTPUT:
Returns a Conway-Sloane genus symbol at p, which is an
instance of the Genus_Symbol_p_adic_ring class.
EXAMPLES::
sage: Q = DiagonalQuadraticForm(ZZ, [1,2,3,4])
sage: Q.local_genus_symbol(2)
Genus symbol at 2 : [[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]]
sage: Q.local_genus_symbol(3)
Genus symbol at 3 : [[0, 3, 1], [1, 1, -1]]
sage: Q.local_genus_symbol(5)
Genus symbol at 5 : [[0, 4, 1]]
"""
## Check that p is prime and that the form is defined over ZZ.
if not is_prime(p):
raise TypeError, "Oops! The number " + str(p) + " isn't prime."
if not self.base_ring() == IntegerRing():
raise TypeError, "Oops! The quadratic form is not defined over the integers."
## Return the result
try:
M = self.Hessian_matrix()
return LocalGenusSymbol(M, p)
except StandardError:
raise TypeError, "Oops! There is a problem computing the local genus symbol at the prime " + str(p) + " for this form."
开发者ID:sageb0t,项目名称:testsage,代码行数:64,代码来源:quadratic_form__genus.py
示例20: green_function
def green_function(self, G, v, **kwds):
r"""
Evaluates the local Green's function with respect to the morphism ``G``
at the place ``v`` for ``self`` with ``N`` terms of the
series or to within a given error bound. Must be over a number field
or order of a number field. Note that this is the absolute local Green's function
so is scaled by the degree of the base field.
Use ``v=0`` for the archimedean place over `\QQ` or field embedding. Non-archimedean
places are prime ideals for number fields or primes over `\QQ`.
ALGORITHM:
See Exercise 5.29 and Figure 5.6 of ``The Arithmetic of Dynamics Systems``, Joseph H. Silverman, Springer, GTM 241, 2007.
INPUT:
- ``G`` - a projective morphism whose local Green's function we are computing
- ``v`` - non-negative integer. a place, use v=0 for the archimedean place
kwds:
- ``N`` - positive integer. number of terms of the series to use, default: 10
- ``prec`` - positive integer, float point or p-adic precision, default: 100
- ``error_bound`` - a positive real number
OUTPUT:
- a real number
EXAMPLES::
sage: P.<x,y>=ProjectiveSpace(QQ,1)
sage: H=Hom(P,P)
sage: f=H([x^2+y^2,x*y]);
sage: Q=P(5,1)
sage: f.green_function(Q,0,N=30)
1.6460930159932946233759277576
::
sage: P.<x,y>=ProjectiveSpace(QQ,1)
sage: H=Hom(P,P)
sage: f=H([x^2+y^2,x*y]);
sage: Q=P(5,1)
sage: Q.green_function(f,0,N=200,prec=200)
1.6460930160038721802875250367738355497198064992657997569827
::
sage: K.<w> = QuadraticField(3)
sage: P.<x,y> = ProjectiveSpace(K,1)
sage: H = Hom(P,P)
sage: f = H([17*x^2+1/7*y^2,17*w*x*y])
sage: f.green_function(P.point([w,2],False), K.places()[1])
1.7236334013785676107373093775
sage: print f.green_function(P([2,1]), K.ideal(7), N=7)
0.48647753726382832627633818586
sage: print f.green_function(P([w,1]), K.ideal(17), error_bound=0.001)
-0.70761163353747779889947530309
.. TODO:: Implement general p-adic extensions so that the flip trick can be used
for number fields.
"""
N = kwds.get('N', 10) #Get number of iterates (if entered)
err = kwds.get('error_bound', None) #Get error bound (if entered)
prec = kwds.get('prec', 100) #Get precision (if entered)
R = RealField(prec)
localht = R(0)
BR = FractionField(self.codomain().base_ring())
GBR = G.change_ring(BR) #so the heights work
if not BR in NumberFields():
raise NotImplementedError("Must be over a NumberField or a NumberField Order")
#For QQ the 'flip-trick' works better over RR or Qp
if isinstance(v, (NumberFieldFractionalIdeal, RingHomomorphism_im_gens)):
K = BR
elif is_prime(v):
K = Qp(v, prec)
elif v == 0:
K = R
v = BR.places(prec=prec)[0]
else:
raise ValueError("Invalid valuation (=%s) entered."%v)
#Coerce all polynomials in F into polynomials with coefficients in K
F = G.change_ring(K, False)
d = F.degree()
dim = F.codomain().ambient_space().dimension_relative()
P = self.change_ring(K, False)
if err is not None:
err = R(err)
if not err>0:
raise ValueError("Error bound (=%s) must be positive."%err)
if G.is_endomorphism() == False:
#.........这里部分代码省略.........
开发者ID:bukzor,项目名称:sage,代码行数:101,代码来源:projective_point.py
注:本文中的sage.rings.arith.is_prime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论