bridge/class-master/depend/pari/src/basemath/bibli2.c
/* Stirling number of the first kind. Up to the sign, the number of
   permutations of n symbols which have exactly m cycles. */
Stirling number of the first kind. Up to the sign, the number of
permutations of n symbols which have exactly m cycles.
Stirling number of the first kind . Up to the sign the number of permutations of n symbols which have exactly m cycles .
GEN
stirling1(ulong n, ulong m)
{
  pari_sp ltop=avma;
  ulong k;
  GEN s, t;
  if (n < m) return gen_0;
  else if (n==m) return gen_1;
  t = binomialuu(2*n-m-1, m-1);
  s = mulii(t, stirling2(2*(n-m), n-m));
  if (odd(n-m)) togglesign(s);
  for (k = n-m-1; k > 0; --k)
  {
    GEN c;
    t = diviuuexact(muluui(n-m+k+1, n+k+1, t), n+k, n-m-k);
    c = mulii(t, stirling2(n-m+k, k));
    s = odd(k)? subii(s, c): addii(s, c);
    if ((k & 0x1f) == 0) {
      t = gerepileuptoint(ltop, t);
      s = gerepileuptoint(avma, s);
    }
  }
  return gerepileuptoint(ltop, s);
}
GEN stirling1 ( ulong n , ulong m ) { pari_sp ltop = avma ; ulong k ; GEN s , t ; if ( n < m ) return gen_0 ; else if ( n == m ) return gen_1 ; t = binomialuu ( 2 * n - m - 1 , m - 1 ) ; s = mulii ( t , stirling2 ( 2 * ( n - m ) , n - m ) ) ; if ( odd ( n - m ) ) togglesign ( s ) ; for ( k = n - m - 1 ; k > 0 ; -- k ) { GEN c ; t = diviuuexact ( muluui ( n - m + k + 1 , n + k + 1 , t ) , n + k , n - m - k ) ; c = mulii ( t , stirling2 ( n - m + k , k ) ) ; s = odd ( k ) ? subii ( s , c ) : addii ( s , c ) ; if ( ( k & 0x1f ) == 0 ) { t = gerepileuptoint ( ltop , t ) ; s = gerepileuptoint ( avma , s ) ; } } return gerepileuptoint ( ltop , s ) ; }
Stirling number of the first kind.
Stirling number of the first kind .
/* t = binomial(n-1+k, m-1) * binomial(2n-m, n-m-k) */ /* k = n-m > 0 */