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: Repeated Distinct Elements (RDE)


Description

Combinatorial structures formed from multisets where each
element type has a fixed number of allowed occurrences.

Very much applicable in scenario where you need to restrict number of occurrences, or string-processing.

Examples:

rep_rde_permutation(s)_

Permutations of a multiset where each element can appear a fixed number of times. Think of it as all possible orderings of repeated elements
$ +rep_rde_permutations 2,1,1 repeat w { e[0] {I[#-1,$>]} }

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

rep_rde_npr_permutation(s)_

Permutations of a multiset where each element can appear a fixed number of times, but only a subset of elements is selected.
$ +rep_rde_npr_permutations 3,2,1,1,2 repeat w { e[0] {I[#-1,$>]} }

[gmic]./ Start G'MIC interpreter (v.3.7.3).
[gmic]./ 0,0,1
[gmic]./ 0,0,2
[gmic]./ 0,0,3
[gmic]./ 0,1,0
[gmic]./ 0,1,2
[gmic]./ 0,1,3
[gmic]./ 0,2,0
[gmic]./ 0,2,1
[gmic]./ 0,2,3
.....
[gmic]./ 3,3,1
[gmic]./ 3,3,2
[gmic]./ Display image [0] = '[>begin( quantity_of_items_in...'.
[0] = '[>begin( quantity_of_items_in_group=vmin([2,1,1,2],3); const ...':
  size = (42,1,1,3) [504 b of float32].
  data = (0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3^0,0,0,1,1,1,2,2,2,3,3,3,3,0,0,0,2,2,3,3,3,0,0,0,1,1,3,3,3,0,0,0,0,1,1,1,2,2,2,3,3,3^1,2,3,0,2,3,0,1,3,0,1,2,3,0,2,3,0,3,0,2,3,0,1,3,0,3,0,1,3,0,1,2,3,0,2,3,0,1,3,0,1,2).
  min = 0, max = 3, mean = 1.5, std = 1.21988, coords_min = (0,0,0,0), coords_max = (29,0,0,0).
[gmic]./ End G'MIC interpreter

rep_rde_combination(s)_

Combinations from a multiset where each element has a fixed number of occurrences. Order does not matter.

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

[gmic]./ Start G'MIC interpreter (v.3.7.3).
[gmic]./ 0,0,1
[gmic]./ 0,0,2
[gmic]./ 0,0,3
[gmic]./ 0,1,2
[gmic]./ 0,1,3
[gmic]./ 0,2,3
[gmic]./ 0,3,3
[gmic]./ 1,2,3
[gmic]./ 1,3,3
[gmic]./ 2,3,3
[gmic]./ Display image [0] = '[>begin( items_count=[2,1,1,2...'.
[0] = '[>begin( items_count=[2,1,1,2]; const number_of_sets_of_items...':
  size = (10,1,1,3) [120 b of float32].
  data = (0,0,0,0,0,0,0,1,1,2^0,0,0,1,1,2,3,2,3,3^1,2,3,2,3,3,3,3,3,3).
  min = 0, max = 3, mean = 1.5, std = 1.25831, coords_min = (0,0,0,0), coords_max = (6,0,0,1).
[gmic]./ End G'MIC interpreter.

rep_rde_compsel_perm(s)_

All permutations of elements of a fixed size where each element appears at least once.

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

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

rep_rde_compsel_comb(s)_

All combinations of elements of a fixed size where each element appears at least once.

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

[gmic]./ Start G'MIC interpreter (v.3.7.3).
[gmic]./ 0,0,0,0,1,2
[gmic]./ 0,0,0,1,1,2
[gmic]./ 0,0,0,1,2,2
[gmic]./ 0,0,1,1,1,2
[gmic]./ 0,0,1,1,2,2
[gmic]./ 0,0,1,2,2,2
[gmic]./ 0,1,1,1,1,2
[gmic]./ 0,1,1,1,2,2
[gmic]./ 0,1,1,2,2,2
[gmic]./ 0,1,2,2,2,2
[gmic]./ Display image [0] = '[>begin( const k=$k; const dk...'.
[0] = '[>begin( const k=$k; const dk=k-1; const P=s; cn=(1<<dk)-1; )...':
  size = (10,1,1,6) [240 b of float32].
  data = (0,0,0,0,0,0,0,0,0,0^0,0,0,0,0,0,1,1,1,1^0,0,0,1,1,1,1,1,1,2^0,1,1,1,1,2,1,1,2,2^1,1,2,1,2,2,1,2,2,2^2,2,2,2,2,2,2,2,2,2).
  min = 0, max = 2, mean = 1, std = 0.816497, coords_min = (0,0,0,0), coords_max = (9,0,0,2).
[gmic]./ End G'MIC interpreter.

Commands

Repeated Distinct Elements (RDE):

rep_rde_permutations    rep_rde_permutation_index2list    rep_rde_permutation_list2index
 rep_rde_npr_permutationsrep_rde_npr_permutation_index2listrep_rde_npr_permutation_list2index
 rep_rde_combinations    rep_rde_combination_index2list    rep_rde_combination_list2index
 rep_rde_compsel_perm    rep_rde_compsel_perm_index2list   rep_rde_compsel_perm_list2index
 rep_rde_compsel_comb    rep_rde_compsel_comb_index2list   rep_rde_compsel_comb_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.