Math::...nation(3pm)
π Math::GSL::Combination β bestie edition π
okay so this is Math::GSL::Combination, living its best life in the User Contributed Perl Documentation section of the manual, and it is literally here to hand you combinations. yes. the math ones. come with me π¦
β¨ NAME β¨
Math::GSL::Combination β Combinations π
πΈ SYNOPSIS πΈ
okay so first you gotta summon the modules, like calling your girls into the group chat:
use Math::GSL qw/:all/;
use Math::GSL::Combination qw/:all/;
my $c = Math::GSL::Combination->new(6,3);
print join (" ", $c->as_list) . "\n";
$c->next;
print join (" ", $c->as_list) . "\n";
my $fd = gsl_fopen('combination.dat', 'w');
gsl_combination_fwrite($fd, $c->raw);
gsl_fclose($fd);
so you make a combo (6 choose 3, iconic), print it, hit it with $c->next, print it again β glow up π
β and then dump it to a file with gsl_fopen, gsl_combination_fwrite and gsl_fclose. that's the whole vibe. no cap.
π DESCRIPTION π
here's the full roster of every single function in this module, bestie, and I'm not skipping a single one because that would be rude:
gsl_combination_alloc($n, $k)
this one sets aside memory for a brand new combination with params $n and $k. but heads up π«Ά β the combination is not initialized, so its elements are just straight-up undefined. like a new group chat with no name. if you want one that's already sitting at the lexicographically first combination, use gsl_combination_calloc instead. periodt.
gsl_combination_calloc($n, $k)
same deal, allocates memory for a new combination with params $n and $k β except this one actually initializes it to the lexicographically first combination. it's giving "ready to serve" β¨
gsl_combination_init_first($c)
sets the combination $c to the lexicographically first combination, aka (0,1,2,...,k-1). first place, main character energy π
gsl_combination_init_last($c)
sets the combination $c to the lexicographically last combination, aka (n-k,n-k+1,...,n-1). saving the best for last, we love to see it.
gsl_combination_free($c)
frees ALL the memory the combination $c was hogging. bye bestie, you ate but you gotta go π
gsl_combination_memcpy($dest, $src)
copies the elements of $src into $dest. rules are rules though: the two combinations must have the same size. mismatched sizes? not the vibe.
gsl_combination_get($c, $i)
hands you back the value of the i-th element of combination $c. but if $i wanders outside the allowed range of 0 to k-1? the error handler gets invoked and 0 is returned. stay in your lane, $i. π
gsl_combination_fwrite($stream, $c)
writes the elements of combination $c to $stream in binary format β and that stream has to be opened with the gsl_fopen function from the Math::GSL module, iykyk. returns $GSL_EFAILED if there was a problem writing to the file. and because it's written in the native binary format, it may not be portable between different architectures. so like... don't ship it to your friend on a different machine, fr fr.
gsl_combination_fread($stream, $c)
reads elements from the open $stream β again, opened with gsl_fopen from Math::GSL β into combination $c, binary format, as one does. $c must be preallocated with correct values of n and k, because the function uses the size of $c to figure out how many bytes to read. returns $GSL_EFAILED if there was a problem reading from the file. and the data is assumed to have been written in the native binary format on the same architecture. same machine only bestie π§
gsl_combination_fprintf($stream, $c, $format)
writes the elements of $c line-by-line to $stream (opened with gsl_fopen from Math::GSL) using the format specifier $format, which should be suitable for a type of size_t. in ISO C99 the type modifier z represents size_t, so "%zu\n" is a suitable format. returns $GSL_EFAILED if there was a problem writing to the file. human-readable, we stan π
gsl_combination_fscanf($stream, $c)
reads formatted data from $stream into combination $c. same deal as fread: $c must be preallocated with correct values of n and k, because the function uses the size of $c to determine how many numbers to read. returns $GSL_EFAILED if there was a problem reading from the file.
gsl_combination_n($c)
returns the range (n) of combination $c. that's it. tiny function, big heart π
gsl_combination_k($c)
returns the number of elements (k) in combination $c. iconic.
gsl_combination_data($c)
returns a pointer to the array of elements in combination $c. the raw goods π₯
gsl_combination_valid($c)
vibe-checks combination $c for validity. the k elements should lie in the range 0 to n-1, with each value occurring once at most and in increasing order. if it passes, she's valid, slay.
gsl_combination_next($c)
advances combination $c to the next combination in lexicographic order and returns $GSL_SUCCESS. if there are no further combinations available it returns $GSL_FAILURE and leaves $c unmodified. start at the first combination and keep calling this and you'll iterate through all possible combinations of a given order. it's giving infinite scroll but make it math π
gsl_combination_prev($c)
steps backwards from combination $c to the previous combination in lexicographic order, returning $GSL_SUCCESS. if no previous combination is available it returns $GSL_FAILURE and leaves $c unmodified. the rewind button π
π MORE INFO π
for more info on the functions, we refer you to the GSL official documentation: <http://www.gnu.org/software/gsl/manual/html_node/>
π« AUTHORS π«
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
π COPYRIGHT AND LICENSE π
Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page bestie, every last function, no notes π
and a lil sign-off for the record: this was perl v5.42.3, dated 2026-08-20, and the page is Math::...nation(3pm) β go forth and combine β¨π¦π
π¦ where this page comes from
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms