Skip to content

Commit 8ae4c23

Browse files
new wrappers
1 parent 74f5ebe commit 8ae4c23

8 files changed

Lines changed: 801 additions & 3 deletions

File tree

src/acb.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,10 @@ cdef class acb(flint_scalar):
585585
acb_agm1((<acb>u).val, (<acb>s).val, getprec())
586586
return u
587587
else:
588-
return (s / t).agm() * t
588+
t = acb(t)
589+
u = acb.__new__(acb)
590+
acb_agm((<acb>u).val, (<acb>s).val, (<acb>t).val, getprec())
591+
return u
589592

590593
def gamma(s):
591594
"""

src/flint.pxd

Lines changed: 220 additions & 2 deletions
Large diffs are not rendered by default.

src/fmpq.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ cdef class fmpq(flint_scalar):
279279
fmpq_harmonic_ui(v.val, n)
280280
return v
281281

282+
@staticmethod
283+
def dedekind_sum(n, k):
284+
cdef fmpz nv, kv
285+
cdef fmpq v
286+
nv = fmpz(n)
287+
kv = fmpz(k)
288+
v = fmpq()
289+
fmpq_dedekind_sum(v.val, nv.val, kv.val)
290+
return v
291+
282292
def floor(self):
283293
cdef fmpz r = fmpz.__new__(fmpz)
284294
fmpz_fdiv_q(r.val, fmpq_numref(self.val), fmpq_denref(self.val))

src/fmpq_poly.pyx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,17 @@ cdef class fmpq_poly(flint_poly):
298298
fmpq_poly_gcd(res.val, self.val, (<fmpq_poly>other).val)
299299
return res
300300

301+
def xgcd(self, other):
302+
cdef fmpq_poly res1, res2, res3
303+
other = any_as_fmpq_poly(other)
304+
if other is NotImplemented:
305+
raise TypeError("cannot convert input to fmpq_poly")
306+
res1 = fmpq_poly.__new__(fmpq_poly)
307+
res2 = fmpq_poly.__new__(fmpq_poly)
308+
res3 = fmpq_poly.__new__(fmpq_poly)
309+
fmpq_poly_xgcd(res1.val, res2.val, res3.val, self.val, (<fmpq_poly>other).val)
310+
return (res1, res2, res3)
311+
301312
def factor(self):
302313
"""
303314
Factors *self* into irreducible polynomials. Returns (*c*, *factors*)

src/fmpz.pyx

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

319+
def lcm(self, other):
320+
"""
321+
Returns the greatest common divisor of self and other.
322+
323+
>>> fmpz(30).gcd(45)
324+
15
325+
"""
326+
cdef fmpz_struct tval[1]
327+
cdef int ttype = FMPZ_UNKNOWN
328+
ttype = fmpz_set_any_ref(tval, other)
329+
if ttype == FMPZ_UNKNOWN:
330+
raise TypeError("input must be an integer")
331+
u = fmpz.__new__(fmpz)
332+
fmpz_lcm((<fmpz>u).val, self.val, tval)
333+
if ttype == FMPZ_TMP:
334+
fmpz_clear(tval)
335+
return u
336+
319337
def factor(self, trial_limit=None):
320338
"""
321339
Factors self into prime numbers, returning a list of
@@ -366,6 +384,26 @@ cdef class fmpz(flint_scalar):
366384
fmpz_factor_clear(fac)
367385
return res
368386

387+
def factor_smooth(self, bits=15, int proved=-1):
388+
cdef fmpz_factor_t fac
389+
cdef int i
390+
fmpz_factor_init(fac)
391+
fmpz_factor_smooth(fac, self.val, bits, proved)
392+
res = [0] * fac.num
393+
for 0 <= i < fac.num:
394+
u = fmpz.__new__(fmpz)
395+
fmpz_set((<fmpz>u).val, &fac.p[i])
396+
exp = <long> fac.exp[i]
397+
res[i] = (u, exp)
398+
fmpz_factor_clear(fac)
399+
return res
400+
401+
def is_prime(self):
402+
return fmpz_is_prime(self.val)
403+
404+
def is_probable_prime(self):
405+
return fmpz_is_probabprime(self.val)
406+
369407
def is_perfect_power(self):
370408
cdef int k
371409
cdef fmpz v = fmpz()
@@ -563,6 +601,15 @@ cdef class fmpz(flint_scalar):
563601
fmpz_sqrtrem(u.val, v.val, self.val)
564602
return u, v
565603

604+
# warning: m should be prime!
605+
def sqrtmod(self, m):
606+
cdef fmpz v
607+
v = fmpz()
608+
m = fmpz(m)
609+
if not fmpz_sqrtmod(v.val, self.val, (<fmpz>m).val):
610+
raise ValueError("unable to compute modular square root")
611+
return v
612+
566613
def root(self, long n):
567614
cdef fmpz v
568615
if fmpz_sgn(self.val) < 0:
@@ -573,3 +620,15 @@ cdef class fmpz(flint_scalar):
573620
fmpz_root(v.val, self.val, n)
574621
return v
575622

623+
def jacobi(self, other):
624+
cdef fmpz_struct tval[1]
625+
cdef int ttype = FMPZ_UNKNOWN
626+
ttype = fmpz_set_any_ref(tval, other)
627+
if ttype == FMPZ_UNKNOWN:
628+
raise TypeError("input must be an integer")
629+
u = fmpz.__new__(fmpz)
630+
v = fmpz_jacobi(self.val, tval)
631+
if ttype == FMPZ_TMP:
632+
fmpz_clear(tval)
633+
return fmpz(v)
634+

0 commit comments

Comments
 (0)