本文整理汇总了Python中sage.libs.pari.all.pari函数的典型用法代码示例。如果您正苦于以下问题:Python pari函数的具体用法?Python pari怎么用?Python pari使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pari函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _call_
def _call_(self, v):
r"""
EXAMPLE::
sage: L.<b> = NumberField(x^4 + 3*x^2 + 1)
sage: K = L.relativize(L.subfields(2)[0][1], 'a')
sage: a0 = K.gen(); b0 = K.base_field().gen()
sage: V, fr, to = K.relative_vector_space()
sage: fr(to(a0 + 2*b0)), fr(V([0, 1])), fr(V([b0, 2*b0])) # indirect doctest
(a0 + 2*b0, a0, 2*b0*a0 + b0)
"""
# Given a relative vector space element, we have to
# compute the corresponding number field element, in terms
# of an absolute generator.
w = self.__V(v).list()
# First, construct from w a PARI polynomial in x with coefficients
# that are polynomials in y:
B = self.__B
_, to_B = B.structure()
# Apply to_B, so now each coefficient is in an absolute field,
# and is expressed in terms of a polynomial in y, then make
# the PARI poly in x.
w = [pari(to_B(a).polynomial('y')) for a in w]
h = pari(w).Polrev()
# Next we write the poly in x over a poly in y in terms
# of an absolute polynomial for the rnf.
g = self.__R(self.__rnf.rnfeltreltoabs(h))
return self.__K._element_class(self.__K, g)
示例2: _pari_modulus
def _pari_modulus(self):
"""
EXAMPLES:
sage: GF(3^4,'a')._pari_modulus()
Mod(1, 3)*a^4 + Mod(2, 3)*a^3 + Mod(2, 3)
"""
f = pari(str(self.modulus()))
return f.subst('x', 'a') * pari("Mod(1,%s)"%self.characteristic())
示例3: _element_constructor_
def _element_constructor_(self, u):
"""
Returns the abstract group element corresponding to the unit u.
INPUT:
- ``u`` -- Any object from which an element of the unit group's number
field `K` may be constructed; an error is raised if an element of `K`
cannot be constructed from u, or if the element constructed is not a
unit.
EXAMPLES::
sage: x = polygen(QQ)
sage: K.<a> = NumberField(x^2-38)
sage: UK = UnitGroup(K)
sage: UK(1)
1
sage: UK(-1)
u0
sage: UK.gens()
(u0, u1)
sage: UK.gens_values()
[-1, 6*a - 37]
sage: UK.ngens()
2
sage: [UK(u) for u in UK.gens()]
[u0, u1]
sage: [UK(u).exponents() for u in UK.gens()]
[(1, 0), (0, 1)]
sage: UK(a)
Traceback (most recent call last):
...
ValueError: a is not a unit
"""
K = self.__number_field
pK = self.__pari_number_field
try:
u = K(u)
except TypeError:
raise ValueError("%s is not an element of %s"%(u,K))
if self.__S:
m = pK.bnfissunit(self.__S_unit_data, pari(u)).mattranspose()
if m.ncols()==0:
raise ValueError("%s is not an S-unit"%u)
else:
if not u.is_integral() or u.norm().abs() != 1:
raise ValueError("%s is not a unit"%u)
m = pK.bnfisunit(pari(u)).mattranspose()
# convert column matrix to a list:
m = [ZZ(m[0,i].python()) for i in range(m.ncols())]
# NB pari puts the torsion after the fundamental units, before
# the extra S-units but we have the torsion first:
m = [m[self.__nfu]] + m[:self.__nfu] + m[self.__nfu+1:]
return self.element_class(self, m)
示例4: exponential_integral_1
def exponential_integral_1(x, n=0):
r"""
Returns the exponential integral `E_1(x)`. If the optional
argument `n` is given, computes list of the first
`n` values of the exponential integral
`E_1(x m)`.
The exponential integral `E_1(x)` is
.. math::
E_1(x) = \int_{x}^{\infty} e^{-t}/t dt
INPUT:
- ``x`` - a positive real number
- ``n`` - (default: 0) a nonnegative integer; if
nonzero, then return a list of values E_1(x\*m) for m =
1,2,3,...,n. This is useful, e.g., when computing derivatives of
L-functions.
OUTPUT:
- ``float`` - if n is 0 (the default) or
- ``list`` - list of floats if n 0
EXAMPLES::
sage: exponential_integral_1(2)
0.04890051070806112
sage: w = exponential_integral_1(2,4); w
[0.04890051070806112, 0.003779352409848906..., 0.00036008245216265873, 3.7665622843924...e-05]
IMPLEMENTATION: We use the PARI C-library functions eint1 and
veceint1.
REFERENCE:
- See page 262, Prop 5.6.12, of Cohen's book "A Course in
Computational Algebraic Number Theory".
REMARKS: When called with the optional argument n, the PARI
C-library is fast for values of n up to some bound, then very very
slow. For example, if x=5, then the computation takes less than a
second for n=800000, and takes "forever" for n=900000.
"""
if n <= 0:
return float(pari(x).eint1())
else:
return [float(z) for z in pari(x).eint1(n)]
示例5: _pari_modulus
def _pari_modulus(self):
"""
Return the modulus of ``self`` in a format for PARI.
EXAMPLES::
sage: GF(3^4,'a')._pari_modulus()
Mod(1, 3)*a^4 + Mod(2, 3)*a^3 + Mod(2, 3)
"""
f = pari(str(self.modulus()))
return f.subst('x', 'a') * pari("Mod(1,%s)"%self.characteristic())
示例6: _pari_modulus
def _pari_modulus(self):
"""
Return PARI object which is equivalent to the
polynomial/modulus of ``self``.
EXAMPLES::
sage: k1.<a> = GF(2^16)
sage: k1._pari_modulus()
Mod(1, 2)*a^16 + Mod(1, 2)*a^5 + Mod(1, 2)*a^3 + Mod(1, 2)*a^2 + Mod(1, 2)
"""
f = pari(str(self.modulus()))
return f.subst('x', 'a') * pari("Mod(1,%s)"%self.characteristic())
示例7: _complex_mpfr_field_
def _complex_mpfr_field_(self, CC):
"""
Return ComplexField element of self.
INPUT:
- ``CC`` -- a Complex or Real Field.
EXAMPLES::
sage: z = gp(1+15*I); z
1 + 15*I
sage: z._complex_mpfr_field_(CC)
1.00000000000000 + 15.0000000000000*I
sage: CC(z) # CC(gp(1+15*I))
1.00000000000000 + 15.0000000000000*I
sage: CC(gp(11243.9812+15*I))
11243.9812000000 + 15.0000000000000*I
sage: ComplexField(10)(gp(11243.9812+15*I))
11000. + 15.*I
"""
# Multiplying by CC(1) is necessary here since
# sage: pari(gp(1+I)).sage().parent()
# Maximal Order in Number Field in i with defining polynomial x^2 + 1
return CC((CC(1)*pari(self))._sage_())
示例8: _sage_
def _sage_(self):
"""
Convert this GpElement into a Sage object, if possible.
EXAMPLES::
sage: gp(I).sage()
i
sage: gp(I).sage().parent()
Number Field in i with defining polynomial x^2 + 1
::
sage: M = Matrix(ZZ,2,2,[1,2,3,4]); M
[1 2]
[3 4]
sage: gp(M)
[1, 2; 3, 4]
sage: gp(M).sage()
[1 2]
[3 4]
sage: gp(M).sage() == M
True
"""
return pari(str(self)).python()
示例9: __init__
def __init__(self, field, num_integer_primes=10000, max_iterations=100):
r"""
Construct a new iterator of small degree one primes.
EXAMPLES::
sage: x = QQ['x'].gen()
sage: K.<a> = NumberField(x^2 - 3)
sage: K.primes_of_degree_one_list(3) # random
[Fractional ideal (2*a + 1), Fractional ideal (-a + 4), Fractional ideal (3*a + 2)]
"""
self._field = field
self._poly = self._field.absolute_field("b").defining_polynomial()
self._poly = ZZ["x"](self._poly.denominator() * self._poly()) # make integer polynomial
# this uses that [ O_K : Z[a] ]^2 = | disc(f(x)) / disc(O_K) |
from sage.libs.pari.all import pari
self._prod_of_small_primes = ZZ(
pari("TEMPn = %s; TEMPps = primes(TEMPn); prod(X = 1, TEMPn, TEMPps[X])" % num_integer_primes)
)
self._prod_of_small_primes //= self._prod_of_small_primes.gcd(self._poly.discriminant())
self._integer_iter = iter(ZZ)
self._queue = []
self._max_iterations = max_iterations
示例10: __mul__
def __mul__(self, right):
"""
Gauss composition of binary quadratic forms. The result is
not reduced.
EXAMPLES:
We explicitly compute in the group of classes of positive
definite binary quadratic forms of discriminant -23.
::
sage: R = BinaryQF_reduced_representatives(-23); R
[x^2 + x*y + 6*y^2, 2*x^2 - x*y + 3*y^2, 2*x^2 + x*y + 3*y^2]
sage: R[0] * R[0]
x^2 + x*y + 6*y^2
sage: R[1] * R[1]
4*x^2 + 3*x*y + 2*y^2
sage: (R[1] * R[1]).reduced_form()
2*x^2 + x*y + 3*y^2
sage: (R[1] * R[1] * R[1]).reduced_form()
x^2 + x*y + 6*y^2
"""
if not isinstance(right, BinaryQF):
raise TypeError, "both self and right must be binary quadratic forms"
# There could be more elegant ways, but qfbcompraw isn't
# wrapped yet in the PARI C library. We may as well settle
# for the below, until somebody simply implements composition
# from scratch in Cython.
v = list(pari('qfbcompraw(%s,%s)'%(self._pari_init_(),
right._pari_init_())))
return BinaryQF(v)
示例11: reduced_form
def reduced_form(self):
"""
Return the unique reduced form equivalent to ``self``. See also
:meth:`~is_reduced`.
EXAMPLES::
sage: a = BinaryQF([33,11,5])
sage: a.is_reduced()
False
sage: b = a.reduced_form(); b
5*x^2 - x*y + 27*y^2
sage: b.is_reduced()
True
sage: a = BinaryQF([15,0,15])
sage: a.is_reduced()
True
sage: b = a.reduced_form(); b
15*x^2 + 15*y^2
sage: b.is_reduced()
True
"""
if self.discriminant() >= 0 or self._a < 0:
raise NotImplementedError, "only implemented for positive definite forms"
if not self.is_reduced():
v = list(pari('Vec(qfbred(Qfb(%s,%s,%s)))'%(self._a,self._b,self._c)))
return BinaryQF(v)
else:
return self
示例12: __float__
def __float__(self):
"""
Return Python float.
EXAMPLES::
sage: float(gp(10))
10.0
"""
return float(pari(str(self)))
示例13: pari
def pari(x):
"""
Return the PARI object constructed from a Sage/Python object.
This is deprecated, import ``pari`` from ``sage.libs.pari.all``.
"""
from sage.misc.superseded import deprecation
deprecation(17451, 'gen_py.pari is deprecated, use sage.libs.pari.all.pari instead')
from sage.libs.pari.all import pari
return pari(x)
示例14: representation_number_list
def representation_number_list(self, B):
"""
Return the vector of representation numbers < B.
EXAMPLES::
sage: Q = DiagonalQuadraticForm(ZZ,[1,1,1,1,1,1,1,1])
sage: Q.representation_number_list(10)
[1, 16, 112, 448, 1136, 2016, 3136, 5504, 9328, 12112]
"""
ans = pari(1).concat(self.__pari__().qfrep(B - 1, 1) * 2)
return ans.sage()
示例15: __init__
def __init__(self, K, V):
r"""
EXAMPLE::
sage: L.<b> = NumberField(x^4 + 3*x^2 + 1)
sage: K = L.relativize(L.subfields(2)[0][1], 'a')
sage: V, fr, to = K.relative_vector_space()
sage: to
Isomorphism map:
From: Number Field in a0 with defining polynomial x^2 - b0*x + 1 over its base field
To: Vector space of dimension 2 over Number Field in b0 with defining polynomial x^2 + 1
"""
self.__V = V
self.__K = K
self.__rnf = K.pari_rnf()
self.__zero = QQ(0)
self.__n = K.relative_degree()
self.__x = pari("'x")
self.__y = pari("'y")
self.__B = K.absolute_base_field()
NumberFieldIsomorphism.__init__(self, Hom(K, V))