Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate the zero-free compositions of a positive integer
ResourceFunction["StrictIntegerCompositions"][n] gives a list of all possible ways to form a composition of the integer n into smaller integers. | |
ResourceFunction["StrictIntegerCompositions"][n,k] gives compositions using at most k integers. | |
ResourceFunction["StrictIntegerCompositions"][n,{k}] gives compositions into exactly k integers. | |
ResourceFunction["StrictIntegerCompositions"][n,{kmin,kmax}] gives compositions into between kmin and kmax integers. | |
ResourceFunction["StrictIntegerCompositions"][n,kspec,{s1,s2,…}] gives compositions involving only the numbers si. | |
ResourceFunction["StrictIntegerCompositions"][n,kspec,sspec,m] limits the result to using only first m partitions. |
All the strict compositions of an integer:
| In[1]:= |
| Out[1]= |
All the strict compositions of 5:
| In[2]:= |
| Out[2]= |
The compositions of 5 into at most three integers:
| In[3]:= |
| Out[3]= |
Compositions that involve only 1, 2 and 4:
| In[4]:= |
| Out[4]= |
Compositions of even length only:
| In[5]:= |
| Out[5]= |
Ways to form 3 from any of five given rational numbers:
| In[6]:= |
| Out[6]= | ![]() |
Limit the number of results:
| In[7]:= |
| Out[7]= |
There are 2n-1 strict compositions of n:
| In[8]:= |
| In[9]:= |
| Out[9]= |
| In[10]:= |
| Out[10]= |
| In[11]:= |
| Out[11]= |
Each composition adds up to the original number:
| In[12]:= |
| Out[12]= |
| In[13]:= |
| Out[13]= |
StrictIntegerCompositions gives the permutations of compositions returned by IntegerPartitions:
| In[14]:= |
| Out[14]= |
| In[15]:= |
| Out[15]= |
| In[16]:= |
| Out[16]= |
Results of StrictIntegerCompositions do not include zeros, whereas results of the resource function IntegerCompositions do:
| In[17]:= |
| Out[17]= |
| In[18]:= |
| Out[18]= |
Unlike the resource function IntegerCompositions, StrictIntegerCompositions does not necessarily give compositions in canonical order:
| In[19]:= |
| Out[19]= |
| In[20]:= |
| Out[20]= |
| In[21]:= |
| Out[21]= |
StrictIntegerCompositions cannot give an infinite list of compositions:
| In[22]:= |
| Out[22]= |
Get a finite list instead:
| In[23]:= |
| Out[23]= |
There are no strict compositions of 1/2:
| In[24]:= |
| Out[24]= |
There are, however, compositions into rationals:
| In[25]:= |
| Out[25]= |
If all items requested by the fourth argument are not present, as many as possible are returned:
| In[26]:= |
| Out[26]= |
A compact way to show integer compositions:
| In[27]:= |
| Out[27]= |
This work is licensed under a Creative Commons Attribution 4.0 International License