Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/modular/modsym/apply.pyx
4057 views
1
##########################################################################
2
#
3
# Copyright (C) 2008 William Stein <[email protected]>
4
#
5
# Distributed under the terms of the GNU General Public License (GPL)
6
#
7
# http://www.gnu.org/licenses/
8
#
9
##########################################################################
10
11
12
from sage.rings.integer cimport Integer
13
14
## from sage.rings.all import QQ
15
## R = QQ['X']
16
## def apply_to_monomial_0(int i, int j, int a, int b, int c, int d):
17
## f = R([b,a])
18
## g = R([d,c])
19
## if i < 0 or j-i < 0:
20
## raise ValueError, "i (=%s) and j-i (=%s) must both be nonnegative."%(i,j-i)
21
## h = (f**i)*(g**(j-i))
22
## return [int(z) for z in h.padded_list(j+1)]
23
24
cdef class Apply:
25
def __cinit__(self):
26
"""
27
EXAMPLES::
28
29
sage: import sage.modular.modsym.apply
30
sage: sage.modular.modsym.apply.Apply()
31
<sage.modular.modsym.apply.Apply object at ...>
32
"""
33
fmpz_poly_init(self.f)
34
fmpz_poly_init(self.g)
35
fmpz_poly_init(self.ff)
36
fmpz_poly_init(self.gg)
37
38
def __dealloc__(self):
39
# clear flint polys
40
fmpz_poly_clear(self.f)
41
fmpz_poly_clear(self.g)
42
fmpz_poly_clear(self.ff)
43
fmpz_poly_clear(self.gg)
44
45
cdef int apply_to_monomial_flint(self, fmpz_poly_t ans, int i, int j,
46
int a, int b, int c, int d) except -1:
47
if i < 0 or j-i < 0:
48
raise ValueError, "i (=%s) and j-i (=%s) must both be nonnegative."%(i,j-i)
49
50
# f = b+a*x, g = d+c*x
51
fmpz_poly_set_coeff_si(self.f, 0, b)
52
fmpz_poly_set_coeff_si(self.f, 1, a)
53
fmpz_poly_set_coeff_si(self.g, 0, d)
54
fmpz_poly_set_coeff_si(self.g, 1, c)
55
56
# h = (f**i)*(g**(j-i))
57
fmpz_poly_power(self.ff, self.f, i)
58
fmpz_poly_power(self.gg, self.g, j-i)
59
fmpz_poly_mul(ans, self.ff, self.gg)
60
61
return 0
62
63
64
cdef Apply A = Apply()
65
66
def apply_to_monomial(int i, int j, int a, int b, int c, int d):
67
r"""
68
Returns a list of the coefficients of
69
70
.. math::
71
72
(aX + bY)^i (cX + dY)^{j-i},
73
74
where `0 \leq i \leq j`, and `a`, `b`, `c`, `d` are integers.
75
76
One should think of `j` as being `k-2` for the application to
77
modular symbols.
78
79
INPUT:
80
i, j, a, b, c, d -- all ints
81
82
OUTPUT:
83
list of ints, which are the coefficients
84
of `Y^j, Y^{j-1}X, \ldots, X^j`, respectively.
85
86
EXAMPLE:
87
88
We compute that `(X+Y)^2(X-Y) = X^3 + X^2Y - XY^2 - Y^3`::
89
90
sage: from sage.modular.modsym.manin_symbols import apply_to_monomial
91
sage: apply_to_monomial(2, 3, 1,1,1,-1)
92
[-1, -1, 1, 1]
93
sage: apply_to_monomial(5, 8, 1,2,3,4)
94
[2048, 9728, 20096, 23584, 17200, 7984, 2304, 378, 27]
95
sage: apply_to_monomial(6,12, 1,1,1,-1)
96
[1, 0, -6, 0, 15, 0, -20, 0, 15, 0, -6, 0, 1]
97
"""
98
cdef fmpz_poly_t pr
99
fmpz_poly_init(pr)
100
101
A.apply_to_monomial_flint(pr, i,j,a,b,c,d)
102
103
cdef Integer res
104
v = []
105
for k from 0 <= k <= j:
106
res = <Integer>PY_NEW(Integer)
107
fmpz_poly_get_coeff_mpz(res.value, pr, k)
108
v.append(int(res))
109
110
fmpz_poly_clear(pr)
111
return v
112
113