2023-04-05

(sph selection)

create and analyse set selections: permutations, combinations and similar

part of sph-lib

module name

(sph selection)

exported bindings

procedure: divisions count ->
integer -> ((integer ...) ...)
returns the compositions.
return all integer selections that sum to count.
distinctness is defined by length, order and value.
example for count 3: ((1 1 1) (1 2) (2 1) (3))
algorithm:
collect all possible values and associate a rest value that following values have to sum to.
for each of those associations, reduce the rest value and the list of possible values while producing possible tails.
the rest values are removed after all combinations have been found
procedure: number-divisions b count ->
number integer -> ((number ...) ...)
return all selections of multiples of b divided by count that sum to b.
distinctness is defined by length, order and value.
example
b: 60, count: 3
result: ((20 20 20) (20 40) (40 20) (60))
variable: sph-selection-description
procedure: vector-distinct-count a [min-width max-width] ->
vector integer integer -> integer
count all distinct sub-vectors in a vector with lengths from min-width to max-width.
distinctness is defined by length, order and value.
how sub-vectors are counted:
#([1 2 3] 4)
#(1 [2 3 4])
#([1 2] 3 4)
#(1 [2 3] 4)
#(1 2 [3 4])
procedure: vector-distinct-maximum width [min-width] ->
integer integer -> integer
calculate the maximum number of possible distinct tuples in a tuple up to width, optionally ignoring widths smaller than min-width
procedure: vector-distinct-stream a [min-width max-width] ->
procedure: vector-numeric-increment-be a base ->
vector integer -> vector
treat integers in a vector as digits of a number to \"base\" and increment it.
the least significant digit is the last element of the vector.
returns false if the maximum value has been reached
procedure: vector-numeric-increment-be! a base ->
vector integer -> true/false
like \"vector-numeric-increment-be\" but modifies the input vector
procedure: vector-numeric-increment-le a base ->
vector integer -> vector
treat integers in a vector as digits of a number to \"base\" and increment it.
the least significant digit is the first element of the vector.
return false if the maximum value has been reached
procedure: vector-numeric-increment-le! a base ->
vector integer -> true/false
like \"vector-numeric-increment-le\" but modifies the input vector
procedure: vector-selection set-indices set ->
vector:#(integer ...) vector -> vector
return a new vector of values at indices in set
procedure: vector-selection-maximum set-length [selection-width] ->
integer integer -> integer
calculate the maximum number of possible distinct selections from a set with length \"set-length\" and
optional \"selection-width\" which defaults to \"set-length\"
procedure: vector-selections set [width] ->
vector integer -> (vector ...)
return a list of all distinct selections of values from \"set\" with duplicate elements allowed. set can contain any datatype.
the optional parameter \"width\" specifies the length of selections.
for example, a width of two creates all possible two element selections of set.
the default for \"width\" is the length of the set
procedure: vector-selections-stream selection [width] ->
vector width -> stream
like vector-selections but returns an srfi-41-stream and calculates next results on demand