Skip to content

Commit

Permalink
Compute bin_uiui via Flint for small n
Browse files Browse the repository at this point in the history
  • Loading branch information
albinahlback committed Oct 18, 2021
1 parent f951da3 commit 41adb48
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
27 changes: 23 additions & 4 deletions arb/bin.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright (C) 2013 Fredrik Johansson
Copyright (C) 2021 Albin Ahlbäck
This file is part of Arb.
Expand All @@ -10,6 +11,7 @@
*/

#include "arb.h"
#include "flint/fmpz.h"

void
arb_bin_ui(arb_t x, const arb_t n, ulong k, slong prec)
Expand Down Expand Up @@ -39,13 +41,30 @@ arb_bin_ui(arb_t x, const arb_t n, ulong k, slong prec)
}
}

static
void
_arb_bin_uiui_small(arb_t x, ulong n, ulong k, slong prec)
{
fmpz_t b;
fmpz_init(b);
fmpz_bin_uiui(b, n, k);
arb_set_round_fmpz(x, b, prec);
fmpz_clear(b);
}

void
arb_bin_uiui(arb_t x, ulong n, ulong k, slong prec)
{
arb_t t;
arb_init(t);
arb_set_ui(t, n);
arb_bin_ui(x, t, k, prec);
arb_clear(t);

if (n < 3000)
_arb_bin_uiui_small(x, n, k, prec);
else
{
arb_init(t);
arb_set_ui(t, n);
arb_bin_ui(x, t, k, prec);
arb_clear(t);
}
}

8 changes: 6 additions & 2 deletions doc/source/arb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1348,11 +1348,15 @@ Gamma function and factorials

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

.. function:: void arb_bin_uiui(arb_t z, ulong n, ulong k, slong prec)

Computes the binomial coefficient `z = {n \choose k}`, via the
rising factorial as `{n \choose k} = (n-k+1)_k / k!`.

.. function:: void arb_bin_uiui(arb_t z, ulong n, ulong k, slong prec)

Computes the binomial coefficient `z = {n \choose k}`. If `n` is small,
it is computed via Flint's implementation `fmpz_bin_uiui`. If `n` is big,
it is computed via rising factorial as `{n \choose k} = (n-k+1)_k / k!`.

.. function:: void arb_gamma(arb_t z, const arb_t x, slong prec)
void arb_gamma_fmpq(arb_t z, const fmpq_t x, slong prec)
void arb_gamma_fmpz(arb_t z, const fmpz_t x, slong prec)
Expand Down

0 comments on commit 41adb48

Please sign in to comment.