Skip to content

Commit 87e7fc0

Browse files
committed
making a new module for acb_theta
1 parent 5c1a5c4 commit 87e7fc0

File tree

4 files changed

+76
-45
lines changed

4 files changed

+76
-45
lines changed

meson.build

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ endif
2222
# flint.pc was missing -lflint until Flint 3.1.0
2323
if flint_dep.version().version_compare('<3.1')
2424
flint_dep = cc.find_library('flint')
25+
have_acb_theta = false
26+
else
27+
have_acb_theta = true
2528
endif
2629

2730
pyflint_deps = [dep_py, gmp_dep, mpfr_dep, flint_dep]

src/flint/types/acb_mat.pyx

+13-45
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ from flint.flintlib.arb_mat cimport *
1919
from flint.flintlib.arf cimport *
2020
from flint.flintlib.acb cimport *
2121
from flint.flintlib.acb_mat cimport *
22-
from flint.flintlib.acb_theta cimport *
2322

2423
cimport cython
2524

@@ -818,47 +817,16 @@ cdef class acb_mat(flint_mat):
818817

819818
def theta(tau, z, square=False):
820819
r"""
821-
Computes the vector valued Riemann theta function `(\theta_{a,b}{z, tau) : a, b \in \{0,1\}^{g}\)` or its squares.
822-
This is a wrapper for the function `acb_theta_all` and it follows the same conventions for the ordering of the theta characteristics.
823-
824-
>>> from flint import acb, acb_mat, showgood
825-
>>> z = acb(1+1j); tau = acb(1.25+3j)
826-
>>> t0, t1, t2, t3 = acb_mat([[tau]]).theta(acb_mat([[z]]))
827-
>>> sum([abs(x) for x in acb_mat([z.modular_theta(tau)]) - acb_mat([[-t3,t2,t0,t1]])])
828-
[+/- 3.82e-14]
829-
>>> for i in range(4):showgood(lambda: acb_mat([[tau]]).theta(acb_mat([[z]]))[i], dps=25)
830-
...
831-
0.9694430387796704100046143 - 0.03055696120816803328582847j
832-
1.030556961196006476576271 + 0.03055696120816803328582847j
833-
-1.220790267576967690128359 - 1.827055516791154669091679j
834-
-1.820235910124989594900076 + 1.216251950154477951760042j
835-
>>> acb_mat([[1j,0],[0,2*1j]]).theta(acb_mat([[0],[0]]))
836-
([1.09049252082308 +/- 3.59e-15] + [+/- 2.43e-16]j, [1.08237710165638 +/- 4.15e-15] + [+/- 2.43e-16]j, [0.916991251621117 +/- 6.30e-16] + [+/- 2.43e-16]j, [0.910167024735558 +/- 7.93e-16] + [+/- 2.43e-16]j, [0.451696791791346 +/- 5.46e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [0.379830212998946 +/- 4.47e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [0.916991251621117 +/- 6.30e-16] + [+/- 2.43e-16]j, [0.910167024735558 +/- 7.93e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [0.379830212998946 +/- 4.47e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j)
837-
838-
"""
839-
g = tau.nrows()
840-
assert tau.ncols() == g
841-
assert z.nrows() == g
842-
assert z.ncols() == 1
843-
844-
# convert input
845-
cdef acb_ptr zvec
846-
zvec = _acb_vec_init(g)
847-
cdef long i
848-
for i in range(g):
849-
acb_set(zvec + i, acb_mat_entry((<acb_mat>z).val, i, 0))
850-
851-
# initialize the output
852-
cdef slong nb = 1 << (2 * g)
853-
cdef acb_ptr theta = _acb_vec_init(nb)
854-
855-
acb_theta_all(theta, zvec, tau.val, square, getprec())
856-
_acb_vec_clear(zvec, g)
857-
# copy the output
858-
res = tuple()
859-
for i in range(nb):
860-
r = acb.__new__(acb)
861-
acb_set((<acb>r).val, theta + i)
862-
res += (r,)
863-
_acb_vec_clear(theta, nb)
864-
return res
820+
Computes the vector valued Riemann theta function
821+
`(\theta_{a,b}{z, tau) : a, b \in \{0,1\}^{g}\)` or its squares.
822+
This is a wrapper for the C-function `acb_theta_all` and it follows the
823+
same conventions for the ordering of the theta characteristics.
824+
825+
This is a wrapper for :meth:`.acb_theta.acb_mat_theta`; see the
826+
documentation for that method for details for examples.
827+
"""
828+
try:
829+
from .acb_theta import acb_mat_theta
830+
except ImportError:
831+
raise NotImplementedError("acb_mat.theta needs Flint >= 3.1.0")
832+
return acb_mat_theta(z, tau, square=square)

src/flint/types/acb_theta.pyx

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from flint.flint_base.flint_context cimport getprec
2+
from flint.types.acb cimport acb
3+
from flint.types.acb_mat cimport acb_mat
4+
from flint.flintlib.acb cimport *
5+
from flint.flintlib.acb_mat cimport *
6+
from flint.flintlib.acb_theta cimport *
7+
8+
def acb_mat_theta(acb_mat z, acb_mat tau, ulong square=False):
9+
r"""
10+
Computes the vector valued Riemann theta function `(\theta_{a,b}{z, tau) : a, b \in \{0,1\}^{g}\)` or its squares.
11+
This is a wrapper for the function `acb_theta_all` and it follows the same conventions for the ordering of the theta characteristics.
12+
13+
This should be used via method `acb_mat.theta` with the order of `z` and `tau` swapped,
14+
15+
>>> from flint import acb, acb_mat, showgood
16+
>>> z = acb(1+1j); tau = acb(1.25+3j)
17+
>>> t0, t1, t2, t3 = acb_mat([[tau]]).theta(acb_mat([[z]]))
18+
>>> sum([abs(x) for x in acb_mat([z.modular_theta(tau)]) - acb_mat([[-t3,t2,t0,t1]])])
19+
[+/- 3.82e-14]
20+
>>> for i in range(4):showgood(lambda: acb_mat([[tau]]).theta(acb_mat([[z]]))[i], dps=25)
21+
...
22+
0.9694430387796704100046143 - 0.03055696120816803328582847j
23+
1.030556961196006476576271 + 0.03055696120816803328582847j
24+
-1.220790267576967690128359 - 1.827055516791154669091679j
25+
-1.820235910124989594900076 + 1.216251950154477951760042j
26+
>>> acb_mat([[1j,0],[0,2*1j]]).theta(acb_mat([[0],[0]]))
27+
([1.09049252082308 +/- 3.59e-15] + [+/- 2.43e-16]j, [1.08237710165638 +/- 4.15e-15] + [+/- 2.43e-16]j, [0.916991251621117 +/- 6.30e-16] + [+/- 2.43e-16]j, [0.910167024735558 +/- 7.93e-16] + [+/- 2.43e-16]j, [0.451696791791346 +/- 5.46e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [0.379830212998946 +/- 4.47e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [0.916991251621117 +/- 6.30e-16] + [+/- 2.43e-16]j, [0.910167024735558 +/- 7.93e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [0.379830212998946 +/- 4.47e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j, [+/- 2.43e-16] + [+/- 2.43e-16]j)
28+
29+
"""
30+
g = tau.nrows()
31+
assert tau.ncols() == g
32+
assert z.nrows() == g
33+
assert z.ncols() == 1
34+
35+
# convert input
36+
cdef acb_ptr zvec
37+
zvec = _acb_vec_init(g)
38+
cdef long i
39+
for i in range(g):
40+
acb_set(zvec + i, acb_mat_entry(z.val, i, 0))
41+
42+
# initialize the output
43+
cdef slong nb = 1 << (2 * g)
44+
cdef acb_ptr theta = _acb_vec_init(nb)
45+
46+
acb_theta_all(theta, zvec, tau.val, square, getprec())
47+
_acb_vec_clear(zvec, g)
48+
# copy the output
49+
res = tuple()
50+
cdef acb r
51+
for i in range(nb):
52+
r = acb.__new__(acb)
53+
acb_set(r.val, theta + i)
54+
res += (r,)
55+
_acb_vec_clear(theta, nb)
56+
return res

src/flint/types/meson.build

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ exts = [
4141
'fmpz_mpoly',
4242
]
4343

44+
if have_acb_theta
45+
exts += ['acb_theta']
46+
endif
47+
4448
py.install_sources(
4549
pyfiles,
4650
pure: false,

0 commit comments

Comments
 (0)