# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Counts the number of times an integer k appears within all possible ways to partition an integer n without calculating n’s integer partitions

Contributed by:
Edmund B Robinson

ResourceFunction["IntegerPartitionFrequency"][ gives the number of times |

ResourceFunction["IntegerPartitionFrequency"][*n*,*k*] requires positive integers *n* and *k* such that *n≥k*.

ResourceFunction["IntegerPartitionFrequency"][*n*,*k*] does not compute the integer partitions of *n* in its calculation.

ResourceFunction["IntegerPartitionFrequency"] makes use of an integer’s partitions being combinations instead of permutations. It calculates the number of partitions {*k*_{1},…} with *k* in position 1 (leaving *n*-*k* to partition), then {*k*_{1},*k*_{2},…} with *k* in positions 1 and 2 (leaving *n*-2*k* to partition), and so on up to {*k*_{1},*k*_{2},…,*k*_{j},…} for *n*−*jk*≥0. Then, it totals these counts.

Calculate how many times the integers 20 to 25 appear in all possible integer partitions of 100:

In[1]:= |

Out[1]= |

Compute how many times the integer 19 appears in all possible integer partitions of 500:

In[2]:= |

Out[2]= |

IntegerPartitionFrequency calculates its count orders of magnitude faster than calculating the partitions of *n* and then counting the occurrences of *k* within the partitions. For example, the number of times 1 appears in all possible integer partitions of 75.

Generate partitions and count:

In[3]:= |

Out[3]= |

Count by IntegerPartitionFrequency:

In[4]:= |

Out[4]= |

Plot how many times each integer 1,2,…,100 appears in all possible integer partitions of 100:

In[5]:= |

Out[5]= |

- 1.0.0 – 10 October 2019

This work is licensed under a Creative Commons Attribution 4.0 International License