Skip to content

Commit 74f5ebe

Browse files
more additions
1 parent def8da5 commit 74f5ebe

7 files changed

Lines changed: 104 additions & 3 deletions

File tree

src/acb.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ cdef class acb(flint_scalar):
184184
other = any_as_acb(other)
185185
return bool(acb_contains(self.val, (<acb>other).val))
186186

187+
def contains_interior(self, other):
188+
other = any_as_acb(other)
189+
return bool(acb_contains_interior(self.val, (<acb>other).val))
190+
187191
def overlaps(self, other):
188192
other = any_as_acb(other)
189193
return bool(acb_overlaps((<acb>self).val, (<acb>other).val))

src/arb.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ cdef class arb(flint_scalar):
491491
other = any_as_arb(other)
492492
return bool(arb_contains(self.val, (<arb>other).val))
493493

494+
def contains_interior(self, other):
495+
other = any_as_arb(other)
496+
return bool(arb_contains_interior(self.val, (<arb>other).val))
497+
494498
def overlaps(self, other):
495499
other = any_as_arb(other)
496500
return bool(arb_overlaps((<arb>self).val, (<arb>other).val))

src/dirichlet.pyx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ cdef class dirichlet_group(object):
3131
def q(self):
3232
return fmpz(self.val.q)
3333

34+
def exponent(self):
35+
return fmpz(self.val.expo)
36+
3437
def __repr__(self):
3538
return "Dirichlet group mod q = %s" % self.q
3639

@@ -95,6 +98,9 @@ cdef class dirichlet_char(object):
9598
assert 1 <= l <= max(q,2)-1 and n_gcd(q, l) == 1
9699
dirichlet_char_log(self.val, self.G.val, l)
97100

101+
def group(self):
102+
return self.G
103+
98104
def index(self):
99105
return dirichlet_index_char(self.G.val, self.val)
100106

@@ -143,6 +149,17 @@ cdef class dirichlet_char(object):
143149
acb_dirichlet_chi((<acb>v).val, self.G.val, self.val, fmpz_get_ui(m.val), getprec())
144150
return v
145151

152+
def chi_exponent(self, n):
153+
cdef fmpz m
154+
cdef ulong v
155+
m = fmpz(n) % self.G.q
156+
expo = self.G.exponent()
157+
v = dirichlet_chi(self.G.val, self.val, fmpz_get_ui(m.val))
158+
if v == DIRICHLET_CHI_NULL:
159+
return None
160+
else:
161+
return fmpz(v)
162+
146163
def l(self, s):
147164
"""
148165
Evaluates the Dirichlet L-function of this character at the given

src/flint.pxd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ cdef extern from "flint/fmpz.h":
273273
void fmpz_rfac_ui(fmpz_t r, const fmpz_t x, ulong n)
274274
void fmpz_rfac_uiui(fmpz_t r, ulong x, ulong n)
275275
void fmpz_primorial(fmpz_t res, ulong n)
276+
int fmpz_is_perfect_power(fmpz_t root, const fmpz_t f)
276277

277278
cdef extern from "flint/fmpz_factor.h":
278279
ctypedef struct fmpz_factor_struct:
@@ -285,6 +286,10 @@ cdef extern from "flint/fmpz_factor.h":
285286
void fmpz_factor_init(fmpz_factor_t factor)
286287
void fmpz_factor_clear(fmpz_factor_t factor)
287288
void fmpz_factor(fmpz_factor_t factor, fmpz_t n)
289+
int fmpz_factor_trial_range(fmpz_factor_t factor, const fmpz_t n, ulong start, ulong num_primes)
290+
void fmpz_factor_expand(fmpz_t n, const fmpz_factor_t factor)
291+
void _fmpz_factor_append(fmpz_factor_t factor, const fmpz_t p, ulong exp)
292+
288293

289294
cdef extern from "flint/fmpz_poly.h":
290295
ctypedef struct fmpz_poly_struct:
@@ -945,6 +950,7 @@ cdef extern from "arb.h":
945950
int arb_contains_si(const arb_t x, long y)
946951
int arb_overlaps(const arb_t x, const arb_t y)
947952
int arb_contains(const arb_t x, const arb_t y)
953+
int arb_contains_interior(const arb_t x, const arb_t y)
948954
void arb_get_interval_fmpz_2exp(fmpz_t a, fmpz_t b, fmpz_t exp, const arb_t x)
949955
int arb_get_unique_fmpz(fmpz_t z, const arb_t x)
950956
void arb_get_fmpz_mid_rad_10exp(fmpz_t mid, fmpz_t rad, fmpz_t exp, const arb_t x, long n)
@@ -1182,6 +1188,7 @@ cdef extern from "acb.h":
11821188
int acb_contains_fmpq(const acb_t x, const fmpq_t y)
11831189
int acb_contains_fmpz(const acb_t x, const fmpz_t y)
11841190
int acb_contains(const acb_t x, const acb_t y)
1191+
int acb_contains_interior(const acb_t x, const acb_t y)
11851192
int acb_get_unique_fmpz(fmpz_t z, const acb_t x)
11861193
int acb_contains_int(const acb_t x)
11871194
void acb_union(acb_t z, const acb_t x, const acb_t y, long prec)

src/fmpq.pyx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,21 @@ cdef class fmpq(flint_scalar):
302302
else:
303303
return max(b1, b2)
304304

305+
def __pow__(self, n, z):
306+
cdef fmpq v
307+
cdef long e
308+
assert z is None
309+
e = n
310+
if type(self) is fmpq:
311+
v = fmpq.__new__(fmpq)
312+
if e >= 0:
313+
fmpz_pow_ui(fmpq_numref(v.val), fmpq_numref((<fmpq>self).val), e)
314+
fmpz_pow_ui(fmpq_denref(v.val), fmpq_denref((<fmpq>self).val), e)
315+
else:
316+
if fmpq_is_zero((<fmpq>self).val):
317+
raise ZeroDivisionError
318+
fmpz_pow_ui(fmpq_denref(v.val), fmpq_numref((<fmpq>self).val), -e)
319+
fmpz_pow_ui(fmpq_numref(v.val), fmpq_denref((<fmpq>self).val), -e)
320+
return v
321+
return NotImplemented
322+

src/fmpq_mat.pyx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,26 @@ cdef class fmpq_mat(flint_mat):
432432
fmpq_mat_minpoly(u.val, self.val)
433433
return u
434434

435+
def __pow__(self, n, z):
436+
cdef fmpq_mat v
437+
assert z is None
438+
n = int(n)
439+
if n == 0:
440+
r, c = self.nrows(), self.ncols()
441+
assert r == c
442+
v = fmpq_mat(r, c)
443+
fmpq_mat_one(v.val)
444+
return v
445+
if n == 1:
446+
return self
447+
if n == 2:
448+
return self * self
449+
if n < 0:
450+
return self.inv() ** (-n)
451+
v = self ** (n // 2)
452+
v = v * v
453+
if n % 2:
454+
v *= self
455+
return v
456+
457+

src/fmpz.pyx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ cdef class fmpz(flint_scalar):
316316
fmpz_clear(tval)
317317
return u
318318

319-
def factor(self):
319+
def factor(self, trial_limit=None):
320320
"""
321-
Factors self into pseudoprimes, returning a list of
321+
Factors self into prime numbers, returning a list of
322322
(prime, exp) pairs. The sign is ignored.
323323
324324
>>> fmpz(5040).factor()
@@ -330,11 +330,33 @@ cdef class fmpz(flint_scalar):
330330
331331
Warning: factoring large integers can be slow unless all
332332
prime factors are small.
333+
334+
If *trial_limit* is set, perform trial division with at most
335+
this many primes, returning an incomplete factorization in which
336+
the largest factor may be composite. Factors largers than the trial
337+
division limit may still be found if it is cheap to do so, but no
338+
expensive algorithms will be run.
339+
340+
>>> fmpz(2**128+10).factor()
341+
[(2, 1), (7, 1), (23, 1), (677, 1), (2957, 1), (1042733, 1), (506256324715258822390969, 1)]
342+
>>> fmpz(2**128+10).factor(trial_limit=200)
343+
[(2, 1), (7, 1), (23, 1), (677, 1), (1560971251139657345905734136865089, 1)]
333344
"""
334345
cdef fmpz_factor_t fac
346+
cdef fmpz_t tmp
335347
cdef int i
336348
fmpz_factor_init(fac)
337-
fmpz_factor(fac, self.val)
349+
if trial_limit is not None:
350+
fmpz_factor_trial_range(fac, self.val, 0, trial_limit)
351+
fmpz_init(tmp)
352+
fmpz_factor_expand(tmp, fac)
353+
fmpz_divexact(tmp, self.val, tmp)
354+
fmpz_abs(tmp, tmp)
355+
if not fmpz_is_one(tmp):
356+
_fmpz_factor_append(fac, tmp, 1)
357+
fmpz_clear(tmp)
358+
else:
359+
fmpz_factor(fac, self.val)
338360
res = [0] * fac.num
339361
for 0 <= i < fac.num:
340362
u = fmpz.__new__(fmpz)
@@ -344,6 +366,12 @@ cdef class fmpz(flint_scalar):
344366
fmpz_factor_clear(fac)
345367
return res
346368

369+
def is_perfect_power(self):
370+
cdef int k
371+
cdef fmpz v = fmpz()
372+
k = fmpz_is_perfect_power(v.val, self.val)
373+
return k != 0
374+
347375
def partitions_p(n):
348376
r"""
349377
Returns `p(n)`, the number of partitions of `n`, as an *fmpz*.

0 commit comments

Comments
 (0)