Skip to content

Commit ed1d1cd

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

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

arb/bin.c

+23-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
@@ -10,6 +11,7 @@
1011
*/
1112

1213
#include "arb.h"
14+
#include "fmpz.h"
1315

1416
void
1517
arb_bin_ui(arb_t x, const arb_t n, ulong k, slong prec)
@@ -39,13 +41,30 @@ arb_bin_ui(arb_t x, const arb_t n, ulong k, slong prec)
3941
}
4042
}
4143

44+
static
45+
void
46+
_arb_bin_uiui_small(arb_t x, ulong n, ulong k, slong prec)
47+
{
48+
fmpz_t b;
49+
fmpz_init(b);
50+
fmpz_bin_uiui(b, n, k);
51+
arb_set_round_fmpz(x, b, prec);
52+
fmpz_clear(b);
53+
}
54+
4255
void
4356
arb_bin_uiui(arb_t x, ulong n, ulong k, slong prec)
4457
{
4558
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);
59+
60+
if (n < 3000)
61+
_arb_bin_uiui_small(x, n, k, prec);
62+
else
63+
{
64+
arb_init(t);
65+
arb_set_ui(t, n);
66+
arb_bin_ui(x, t, k, prec);
67+
arb_clear(t);
68+
}
5069
}
5170

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)