G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing
Banner Institutions GREYC CNRS ENSICAEN UNICAEN

A Full-Featured Open-Source Framework for Image Processing



Latest stable version: 4.0.4 (2026/08/19)

Reference

Reptorian's Combinatorics Library: Sum-constrained Permutations


Description

Combinatorics tools for non-negative integers where the values
are restricted by a maximum sum constraint.

For example, { 1,4,2 } is valid sequence when N = 7.

Examples:

rep_sum_permutation(s)_

Generates sequences of permutations of integer numbers that sums up to N.

$ +rep_sum_permutations 3,2 repeat w { e[0] {I[#-1,$>]} }

[gmic]./ Start G'MIC interpreter (v.3.7.3).
[gmic]./ 0,0
[gmic]./ 0,1
[gmic]./ 0,2
[gmic]./ 0,3
[gmic]./ 1,0
[gmic]./ 1,1
[gmic]./ 1,2
[gmic]./ 2,0
[gmic]./ 2,1
[gmic]./ 3,0
[gmic]./ Display image [0] = '[unnamed]'.
[0] = '[unnamed]':
  size = (10,1,1,2) [80 b of float32].
  data = (0,0,0,0,1,1,1,2,2,3^0,1,2,3,0,1,2,0,1,0).
  min = 0, max = 3, mean = 1, std = 1, coords_min = (0,0,0,0), coords_max = (9,0,0,0).
[gmic]./ End G'MIC interpreter.

rep_total_sum_permutation(s)_

Generates sequences of permutations of integer numbers that sums up exactly to N.

$ +rep_total_sum_permutations 5,3 repeat w { e[0] {I[#-1,$>]} }

[gmic]./ Start G'MIC interpreter (v.3.7.3).
[gmic]./ 0,0,5
[gmic]./ 0,1,4
[gmic]./ 0,2,3
[gmic]./ 0,3,2
[gmic]./ 0,4,1
[gmic]./ 0,5,0
[gmic]./ 1,0,4
[gmic]./ 1,1,3
[gmic]./ 1,2,2
[gmic]./ 1,3,1
[gmic]./ 1,4,0
[gmic]./ 2,0,3
[gmic]./ 2,1,2
[gmic]./ 2,2,1
[gmic]./ 2,3,0
[gmic]./ 3,0,2
[gmic]./ 3,1,1
[gmic]./ 3,2,0
[gmic]./ 4,0,1
[gmic]./ 4,1,0
[gmic]./ 5,0,0
[gmic]./ Display image [0] = '[unnamed]'.
[0] = '[unnamed]':
  size = (21,1,1,3) [252 b of float32].
  data = (0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5^0,1,2,3,4,5,0,1,2,3,4,0,1,2,3,0,1,2,0,1,0^5,4,3,2,1,0,4,3,2,1,0,3,2,1,0,2,1,0,1,0,0).
  min = 0, max = 5, mean = 1.66667, std = 1.49071, coords_min = (0,0,0,0), coords_max = (20,0,0,0).
[gmic]./ End G'MIC interpreter.

rep_sum_combination(s)_

Generates sequences of combinations of integer numbers that sums up to N.

$ +rep_sum_combinations 3,2 repeat w { e[0] {I[#-1,$>]} }

[gmic]./ Start G'MIC interpreter (v.3.7.3).
[gmic]./ 0,0
[gmic]./ 0,1
[gmic]./ 0,2
[gmic]./ 0,3
[gmic]./ 1,1
[gmic]./ 1,2
[gmic]./ Display image [0] = '[unnamed]'.
[0] = '[unnamed]':
  size = (6,1,1,2) [48 b of float32].
  data = (0,0,0,0,1,1^0,1,2,3,1,2).
  min = 0, max = 3, mean = 0.916667, std = 0.953794, norm = 4.58258, coords_min = (0,0,0,0), coords_max = (3,0,0,1).
[gmic]./ End G'MIC interpreter.

rep_total_sum_combination(s)_

Generates sequences of combinations of integer numbers that sums up exactly to N.

$ +rep_total_sum_combinations 5,3 repeat w { e[0] {I[#-1,$>]} }

[gmic]./ Start G'MIC interpreter (v.3.7.3).
[gmic]./ 0,0,5
[gmic]./ 0,1,4
[gmic]./ 0,2,3
[gmic]./ 1,1,3
[gmic]./ 1,2,2
[gmic]./ Display image [0] = '[unnamed]'.
[0] = '[unnamed]':
  size = (5,1,1,3) [60 b of float32].
  data = (0,0,0,1,1^0,1,2,1,2^5,4,3,3,2).
  min = 0, max = 5, mean = 1.66667, std = 1.49071, norm = 8.66025, coords_min = (0,0,0,0), coords_max = (0,0,0,2).
[gmic]./ End G'MIC interpreter.

Commands

Sum-Constrained Combinatorics:

rep_sum_permutations     rep_sum_permutation_index2list       rep_sum_permutation_list2index
rep_total_sum_permutationsrep_total_sum_permutation_index2list rep_total_sum_permutation_list2index
rep_sum_combinations      rep_sum_combination_index2list       rep_sum_combination_list2index
rep_total_sum_combinationsrep_total_sum_combination_index2list rep_total_sum_combination_list2index

G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing

G'MIC is an open-source software distributed under the CeCILL free software licenses (LGPL-like and/or
GPL-compatible). Copyrights (C) Since July 2008, David Tschumperlé - GREYC UMR CNRS 6072, Image Team.