 P is for Practical PerlMonks

### Re: Can this be explained in layman's terms?

by jaredor (Priest)
 on Jan 14, 2017 at 07:27 UTC ( #1179559=note: print w/replies, xml ) Need Help??

Hi BrowserUk,

I'm a lackluster mathematics student, but perhaps I can volunteer an explanation that doesn't stray too far from the rigor.

First, I think I would like to recast your statement as "For any set of n elements the number of ways to partition the set into k non-empty subsets is denoted S(n,k) and these numbers are known as Stirling numbers of the second kind."

• S(0,0) = 1 : There is only one way to make no partitions out of nothing.
• S(n,0) = 0 if n>0 : If you have a set of something, you cannot have a partition with no subsets--the elements of the non-empty set have to go somewhere.
• S(n,1) = S(n,n) = 1 : There is only one way to partition a non-empty set into one non-empty subset--the subset being the set itself. There is only one way to partition a set of n elements into n non-empty subsets--each element has to be in its own subset (a singleton set).
• S(n,k) = S(n-1, k-1) + kS(n-1,k) : Every partition of a set of n elements into k non-empty subsets can be created from one of the partitions of a set of n-1 elements. The sum comes about by looking at the two ways a new, identified, element can be added to the partitions (thus making a new partition that is of a larger set of n elements)
1. You can add the singleton set containing just the new element to any partition of n-1 elements into k-1 subsets, thus creating a partition of a set of n elements into k subsets. There are S(n-1, k-1) partitions that we can do this to.
2. You can add the new element to any non-empty subset of a partition of n-1 elements into k non-empty subsets. There are S(n-1, k) partitions that we can do this to and since we have k subsets in any partition, we have k ways to modify each of the S(n-1, k) partitions, i.e., there are k*S(n-1, k) ways to get to a partition of a set of n elements into k non-empty subsets this way.
Note that because we are talking about an identified element being included, then this sum counts each possible partition of a set of n elements into k non-empty subsets exactly once. The identified element must be in any partition of this set of n elements. The identified element is either in a subset by itself (case 1) or in a subset with at least one other element (case 2).

Sometimes the rule S(n,k) = 0 if k>n is given for completeness, i.e., you can't partition something up into more non-empty subsets than for which it has elements, but this is considered obvious and you won't run into the need for it if you start with any reasonable case where n>=k.

• Comment on Re: Can this be explained in layman's terms?

Replies are listed 'Best First'.
Re^2: Can this be explained in layman's terms?
by huck (Parson) on Jan 14, 2017 at 08:19 UTC

Sometimes the rule S(n,k) = 0 if k>n is given for completeness

VERY important if you dont realize n elements ... k non-empty subsets and you just start with

```
for \$n (0..10) {
for \$k (0..10) {
print "\$n \$k '.fs(\$n,\$k)."\n";
}
}

```use strict; use warnings;

my \$l='k ';
\$l.=sprintf "%3d ",0;
for my \$k (0..10){
\$l.=sprintf " %10s",\$k;
}
print \$l."\n";
\$l=~s/./-/g;
print \$l."\n";

for my \$n (0..10){
printf "n %3d ",\$n;
for my \$k (0..10){
printf " %10s",fs(\$n,\$k);
}
print "\n";
}

sub fs {
my \$n=shift;
my \$k=shift;

if ( \$n ==0 && \$k == 0 ) {return 1};
if ( \$k > \$n ) {return 0};           # important
if ( \$n > 0 && \$k == 0 ) {return 0}
if ( \$k == 1 )            {return 1}
if (\$n == \$k )           {return 1}
my \$p1=fs(\$n-1,\$k-1);
my \$p2=fs(\$n-1,\$k  );
return \$p1 + (\$k*\$p2);
}
And i learned never to name my subroutines s
```use strict; use warnings;

my \$l='k ';
\$l.=sprintf "%3d ",0;
for my \$k (0..10){
\$l.=sprintf " %10s",\$k;
}
print \$l."\n";
\$l=~s/./-/g;
print \$l."\n";

for my \$n (0..10){
printf "n %3d ",\$n;
for my \$k (0..10){
printf " %10s",s(\$n,\$k);
}
print "\n";
}

sub s {
my \$n=shift;
my \$k=shift;

if ( \$n ==0 && \$k == 0 ) {return 1};
if ( \$k > \$n ) {return 0};           # important
if ( \$n > 0 && \$k == 0 ) {return 0}
if ( \$k == 1 )            {return 1}
if (\$n == \$k )           {return 1}
my \$p1=s(\$n-1,\$k-1);
my \$p2=s(\$n-1,\$k  );
return \$p1 + (\$k*\$p2);
}
output
```Global symbol "\$p2" requires explicit package name at buk-2.pl line 30
+.
syntax error at buk-2.pl line 31, near "return"
(Might be a runaway multi-line ;; string starting on line 29)
Global symbol "\$p1" requires explicit package name at buk-2.pl line 31
+.
Global symbol "\$p2" requires explicit package name at buk-2.pl line 31
+.
Missing right curly or square bracket at buk-2.pl line 32, at end of l
+ine
syntax error at buk-2.pl line 32, at EOF
Execution of buk-2.pl aborted due to compilation errors.

...And i learned never to name my subroutines s

I wish I could give you more ++ for that !

...it is unhealthy to remain near things that are in the process of blowing up.     man page for WARP, by Larry Wall

Create A New User
Node Status?
node history
Node Type: note [id://1179559]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2020-06-01 15:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Do you really want to know if there is extraterrestrial life?

Results (2 votes). Check out past polls.

Notices?