49
49
and is represented by a sorted list of length k containing elements
50
50
from S.
51
51
52
- .. WARNING::
53
-
54
- The following function is deprecated and will soon be removed.
55
-
56
- - Permutations of a multiset, :func:`permutations`,
57
- :func:`permutations_iterator`, :func:`number_of_permutations`. A
58
- permutation is a list that contains exactly the same elements but possibly
59
- in different order.
60
-
61
52
**Related functions:**
62
53
63
54
- Bernoulli polynomials, :func:`bernoulli_polynomial`
95
86
The ``sage.groups.perm_gps.permgroup_elements``
96
87
contains the following combinatorial functions:
97
88
98
-
99
- - matrix method of PermutationGroupElement yielding the
89
+ - matrix method of :class:`PermutationGroupElement` yielding the
100
90
permutation matrix of the group element.
101
91
102
92
.. TODO::
114
104
115
105
AUTHORS:
116
106
117
- - David Joyner (2006-07): initial implementation.
107
+ - David Joyner (2006-07): initial implementation
118
108
119
109
- William Stein (2006-07): editing of docs and code; many
120
110
optimizations, refinements, and bug fixes in corner cases
132
122
- Punarbasu Purkayastha (2012-12): deprecate arrangements, combinations,
133
123
combinations_iterator, and clean up very old deprecated methods.
134
124
135
- Functions and classes
136
- ---------------------
125
+ - Kwankyu Lee (2025-01): added Lah numbers
137
126
"""
138
127
139
128
# ****************************************************************************
@@ -505,7 +494,7 @@ def narayana_number(n: Integer, k: Integer) -> Integer:
505
494
506
495
- ``n`` -- integer
507
496
508
- - ``k`` -- integer between ``0`` and `` n - 1` `
497
+ - ``k`` -- integer between `0` and `n - 1`
509
498
510
499
OUTPUT: integer
511
500
@@ -890,6 +879,10 @@ def stirling_number1(n, k, algorithm='gap') -> Integer:
890
879
"""
891
880
n = ZZ (n )
892
881
k = ZZ (k )
882
+ if k > n :
883
+ return ZZ .zero ()
884
+ if k == 0 :
885
+ return ZZ .zero () if n else ZZ .one ()
893
886
if algorithm == 'gap' :
894
887
from sage .libs .gap .libgap import libgap
895
888
return libgap .Stirling1 (n , k ).sage ()
@@ -1016,6 +1009,10 @@ def stirling_number2(n, k, algorithm=None) -> Integer:
1016
1009
"""
1017
1010
n = ZZ (n )
1018
1011
k = ZZ (k )
1012
+ if k > n :
1013
+ return ZZ .zero ()
1014
+ if k == 0 :
1015
+ return ZZ .zero () if n else ZZ .one ()
1019
1016
if algorithm is None :
1020
1017
return _stirling_number2 (n , k )
1021
1018
if algorithm == 'gap' :
@@ -1029,6 +1026,44 @@ def stirling_number2(n, k, algorithm=None) -> Integer:
1029
1026
raise ValueError ("unknown algorithm: %s" % algorithm )
1030
1027
1031
1028
1029
+ def lah_number (n , k ) -> Integer :
1030
+ r"""
1031
+ Return the Lah number `L(n,k)`
1032
+
1033
+ This is the number of ways to partition a set of `n` elements into `k`
1034
+ pairwise disjoint nonempty linearly-ordered subsets.
1035
+
1036
+ This is also called the Stirling number of the third kind.
1037
+
1038
+ See :wikipedia:`Lah_number`.
1039
+
1040
+ INPUT:
1041
+
1042
+ - ``n`` -- nonnegative integer
1043
+ - ``k`` -- nonnegative integer
1044
+
1045
+ EXAMPLES:
1046
+
1047
+ sage: lah_number(50, 30)
1048
+ 3242322638238907670866645288893161825894400000
1049
+
1050
+ We verify a well-known identity::
1051
+
1052
+ sage: S1 = stirling_number1; S2 = stirling_number2
1053
+ sage: all(lah_number(n, k) == sum(S1(n, j) * S2(j, k) for j in [k..n])
1054
+ ....: for n in range(10) for k in range(10))
1055
+ True
1056
+ """
1057
+ n = ZZ (n )
1058
+ k = ZZ (k )
1059
+ if k > n :
1060
+ return ZZ .zero ()
1061
+ if k == 0 :
1062
+ return ZZ .zero () if n else ZZ .one ()
1063
+ a = n .factorial () // k .factorial ()
1064
+ return a ** 2 * k // (n * (n - k ).factorial ())
1065
+
1066
+
1032
1067
def polygonal_number (s , n ):
1033
1068
r"""
1034
1069
Return the `n`-th `s`-gonal number.
0 commit comments