Skip to content

Commit 2e8b7f7

Browse files
committed
Compute bin_uiui via Flint for small n
1 parent f951da3 commit 2e8b7f7

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

arb/bin.c

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (C) 2013 Fredrik Johansson
3+
Copyright (C) 2021 Albin Ahlbäck
34
45
This file is part of Arb.
56
@@ -39,13 +40,30 @@ arb_bin_ui(arb_t x, const arb_t n, ulong k, slong prec)
3940
}
4041
}
4142

43+
static
44+
void
45+
_arb_bin_uiui_small(arb_t x, ulong n, ulong k, slong prec)
46+
{
47+
fmpz_t b;
48+
fmpz_init(b);
49+
fmpz_bin_uiui(b, n, k);
50+
arb_set_round_fmpz(x, b, prec);
51+
fmpz_clear(b);
52+
}
53+
4254
void
4355
arb_bin_uiui(arb_t x, ulong n, ulong k, slong prec)
4456
{
4557
arb_t t;
46-
arb_init(t);
47-
arb_set_ui(t, n);
48-
arb_bin_ui(x, t, k, prec);
49-
arb_clear(t);
58+
59+
if (n < 3000)
60+
_arb_bin_uiui_small(x, n, k, prec);
61+
else
62+
{
63+
arb_init(t);
64+
arb_set_ui(t, n);
65+
arb_bin_ui(x, t, k, prec);
66+
arb_clear(t);
67+
}
5068
}
5169

doc/source/arb.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -1348,11 +1348,15 @@ Gamma function and factorials
13481348

13491349
.. function:: void arb_bin_ui(arb_t z, const arb_t n, ulong k, slong prec)
13501350

1351-
.. function:: void arb_bin_uiui(arb_t z, ulong n, ulong k, slong prec)
1352-
13531351
Computes the binomial coefficient `z = {n \choose k}`, via the
13541352
rising factorial as `{n \choose k} = (n-k+1)_k / k!`.
13551353

1354+
.. function:: void arb_bin_uiui(arb_t z, ulong n, ulong k, slong prec)
1355+
1356+
Computes the binomial coefficient `z = {n \choose k}`. If `n` is small,
1357+
it is computed via Flint's implementation `fmpz_bin_uiui`. If `n` is big,
1358+
it is computed via rising factorial as `{n \choose k} = (n-k+1)_k / k!`.
1359+
13561360
.. function:: void arb_gamma(arb_t z, const arb_t x, slong prec)
13571361
void arb_gamma_fmpq(arb_t z, const fmpq_t x, slong prec)
13581362
void arb_gamma_fmpz(arb_t z, const fmpz_t x, slong prec)

0 commit comments

Comments
 (0)