stirling1(0,0)=1

25 views
Skip to first unread message

Ralf Hemmecke

unread,
Oct 24, 2025, 8:03:04 AMOct 24
to fricas-devel
Ooops.

%%% (309) -> stirling1(0,0)$IntegerCombinatoricFunctions(Integer)

(309) 0
Type: Integer
That should be 1, right?

stirling1(n, m) ==
-- Definition: (-1)^(n-m) S[n, m] is the number of
-- permutations of n symbols which have m cycles.
n < 0 or m < 1 or m > n => 0
m = n => 1
S.Sn = n => coefficient(S.Sp, convert(m)@Z :: N)
x := monomial(1, 1)$SUP(I)
S.Sn := n
S.Sp := x
for k in 1 .. convert(n-1)@Z repeat S.Sp := S.Sp * (x - k::SUP(I))
coefficient(S.Sp, convert(m)@Z :: N)

It seems that the condition "m < 1" in the first line should only be
applied if n>0, i.e. it should be:

n < 0 or (n > 0 and m < 1) or m > n => 0

Probably the same problem in stirling2.

Ralf


Ralf Hemmecke

unread,
Nov 9, 2025, 8:41:00 AMNov 9
to fricas-devel
Patch is attached.

Ralf
0001-correct-stirling1-0-0-stirling2-0-0-1.patch

Waldek Hebisch

unread,
Nov 10, 2025, 9:57:03 AMNov 10
to 'Ralf Hemmecke' via FriCAS - computer algebra system
On Sun, Nov 09, 2025 at 02:40:56PM +0100, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote:
> Patch is attached.

Thanks. Please commit.
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/b4b4d1b7-6dd7-4a8b-a25f-5411d618d4ec%40hemmecke.org.

> From 98709d5d73ddf373c22bae13aca9685b09aad52e Mon Sep 17 00:00:00 2001
> From: Ralf Hemmecke <ra...@hemmecke.org>
> Date: Sun, 9 Nov 2025 14:37:11 +0100
> Subject: correct stirling1(0,0)=stirling2(0,0)=1
>
> ---
> src/algebra/combinat.spad | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/src/algebra/combinat.spad b/src/algebra/combinat.spad
> index 18ac0dee..17452892 100644
> --- a/src/algebra/combinat.spad
> +++ b/src/algebra/combinat.spad
> @@ -157,6 +157,7 @@ IntegerCombinatoricFunctions(I : IntegerNumberSystem) : with
> stirling1(n, m) ==
> -- Definition: (-1)^(n-m) S[n, m] is the number of
> -- permutations of n symbols which have m cycles.
> + zero? n and zero? m => 1
> n < 0 or m < 1 or m > n => 0
> m = n => 1
> S.Sn = n => coefficient(S.Sp, convert(m)@Z :: N)
> @@ -169,6 +170,7 @@ IntegerCombinatoricFunctions(I : IntegerNumberSystem) : with
> stirling2(n, m) ==
> -- definition: SS[n, m] is the number of ways of partitioning
> -- a set of n elements into m non-empty subsets
> + zero? n and zero? m => 1
> n < 0 or m < 1 or m > n => 0
> m = 1 or n = m => 1
> s : I := if odd? m then -1 else 1
> --
> 2.43.0
>


--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages