Math::...tation(3pm)
π Math::GSL::Permutation π
okay bestie, welcome to the glow-up zone β¨ this is the manual page for Math::GSL::Permutation β yeah the header squishes it into Math::...tation(3pm) but we know exactly what's up π
it lives in the User Contributed Perl Documentation, and it is literally all about creating and manipulating permutations. iconic behavior fr fr.
πΈ NAME πΈ
Math::GSL::Permutation β functions for creating and manipulating permutations. that's the whole vibe, no notes π
β¨ SYNOPSIS β¨
use Math::GSL::Permutation qw/:all/;
my $permutation = Math::GSL::Permutation->new(30); # allocate and initialize a permutation of size 30
my $length = $permutation->length; # returns the length of the permutation object, here it is 30
gsl_permutation_swap($permutation->raw, 2,7);
# the raw method is made to use the underlying permutation structure of the permutation object
my $value = $permutation->get(2); # returns the third value (starting from 0) of the permutation
my @values = $permutation->as_list; # returns all the values of the permutation
my @set = $permutation->get([0,1,2,3]); # returns the four first values of the permutation
like look at her go π the raw method hands you the actual underlying permutation structure so the C-level functions can touch it directly. main character energy.
π¦ DESCRIPTION π¦
Here's the full roster of everything this module brings to the table, bestie:
gsl_permutation_alloc($n)β hands you a freshly allocated permutation of size$n. fresh out the box π«Άgsl_permutation_calloc($n)β same deal, a newly allocated permutation of size$n, but this one comes pre-initialized to the identity. clean slate energy.gsl_permutation_init($p)β initializes the permutation$pto the identity, i.e.(0,1,2, ..., n-1). resetting her back to factory settings β¨gsl_permutation_free($p)β frees up all the memory that the permutation$pwas using. bye bestie, releasing you back into the wild πgsl_permutation_memcpy($dest, $src)β copies the permutation$srcinto the permutation$dest. the two permutations must have the same length. returns0if the operation succeeded,1otherwise.gsl_permutation_fread($stream, $p)β reads into the permutation$pfrom the open stream$stream(opened with thegsl_fopenfunction from the Math::GSL module) in binary format. the permutation$pmust be preallocated with the correct length, because the function uses the size of$pto figure out how many bytes to read. returns1if there was a problem reading from the file. the data is assumed to have been written in the native binary format on the same architecture.gsl_permutation_fwrite($stream, $p)β writes the elements of the permutation$pto the stream$stream(opened with thegsl_fopenfunction from the Math::GSL module) in binary format. returns1if there was a problem writing to the file. and because the data goes out in native binary format, it may not be portable between different architectures β so don't count on shipping that file across machines πgsl_permutation_fscanf($stream, $p)β reads formatted data from the stream$stream(opened with thegsl_fopenfunction from the Math::GSL module) into the permutation$p.$pmust be preallocated with the correct length, since the function uses the size of$pto decide how many numbers to read. returns1if there was a problem reading from the file.gsl_permutation_fprintf($stream, $p, $format)β writes the elements of the permutation$pline-by-line to the stream$stream(opened with thegsl_fopenfunction from the Math::GSL module), using the format specifier$format, which should be suitable."%zu\n"is a suitable format, fyi. returns1if there was a problem writing to the file.gsl_permutation_size($p)β returns the size of the permutation$p. how big is she? now you know πgsl_permutation_dataβ this one's just sitting in the list with no description attached, bestie, that's genuinely all we've got for her πgsl_permutation_get($p, $i)β returns the$i-th element of the permutation$p. if$iis outside the range of 0 to n-1, you get0back.gsl_permutation_swap($p, $i, $j)β exchanges the$i-th position and the$j-th position of the permutation$p. returns0if the operation succeeded,1otherwise. trade places, periodt πgsl_permutation_valid($p)β returns0if the permutation$pis valid (meaning the n elements contain each of the numbers 0 to n-1 once and only once),1otherwise. yes queen, the vibe check passed β¨gsl_permutation_reverse($p)β reverses the elements of the permutation$p. upside down, inside out, that's the vibe πgsl_permutation_inverse($inv, $p)β computes the inverse of the permutation$p, stores it in$inv, and returns0if the operation succeeded,1otherwise.gsl_permutation_next($p)β advances the permutation$pto the next permutation in lexicographic order. returns0if the operation succeeded,1otherwise. on to the next one π«gsl_permutation_prev($p)β steps backward from the permutation$pto the previous permutation in lexicographic order. returns0if the operation succeeded,1otherwise. going back, back, back π¦gsl_permutation_mul($p, $pa, $pb)β combines the two permutations$paand$pbinto a single permutation$p. returns0if the operation succeeded,1otherwise. two become one, collab of the century π₯gsl_permutation_linear_to_canonical($q, $p)β computes the canonical form of the permutation$pand stores it in$q. returns0if the operation succeeded,1otherwise.gsl_permutation_canonical_to_linear($p, $q)β converts a canonical permutation$qback into linear form and stores it in$p. returns0if the operation succeeded,1otherwise.gsl_permutation_inversions($p)β returns the number of inversions in the permutation$p.gsl_permutation_linear_cycles($p)β returns the number of cycles in the permutation$p, given a linear form.gsl_permute_vector_int_inversegsl_permutation_canonical_cycles($p)β returns the number of cycles in the permutation$p, given a canonical form. (yes, that function name really is mashed together like that in the source, bestie β I'm not touching it, I'm just reporting the facts π«‘)gsl_permuteβ listed here, no description attached.gsl_permute_inverseβ listed here, no description attached.gsl_permute_intβ listed here, no description attached.gsl_permute_int_inverseβ listed here, no description attached.gsl_permute_vectorβ listed here, no description attached.gsl_permute_vector_inverseβ listed here, no description attached.gsl_permute_vector_intβ listed here, no description attached.
okay so real talk on importing: you have to add the functions you actually want to use inside the qw/put_function_here/ with spaces between each function. ORRR you can just write use Math::GSL::CDF qw/:all/ to pull in every available function of the module at once. π
other tags are also available, here is a complete list of all tags for this module. (that's what it says, bestie, I'm just the messenger π)
for more information on the functions, they refer you to the GSL official documentation:
L<http://www.gnu.org/software/gsl/manual/html_node/>
π§ EXAMPLES π§
first one β build a permutation, print it out, then swap the ends:
use Math::GSL::Permutation qw/:all/;
$p->{permutation} = gsl_permutation_calloc(5);
print "The permutation contains [";
map { print gsl_permutation_get($p->{permutation}, $_) . ", " } (0..3);
print gsl_permutation_get($p->{permutation}, 4);
print "] \n";
print "We'll then swap the first and last elements of the permutation...\n";
gsl_permutation_swap($p->{permutation}, 0, 4);
print "The permutation now contains [";
map { print gsl_permutation_get($p->{permutation},$_) . ", " } (0..3);
print gsl_permutation_get($p->{permutation}, 4);
print "] \n";
second one β make a permutation, swap the first two, then actually apply it to a vector π:
use Math::GSL::Permutation qw/:all/;
use Math::GSL::Vector qw/:all/;
my $p->{permutation} = gsl_permutation_calloc(6);
gsl_permutation_init($p->{permutation});
gsl_permutation_swap($p->{permutation}, 0, 1);
print "The permutation has his first and second elements swapped : [";
map { print gsl_permutation_get($p->{permutation}, $_) . "," } (0..4);
print gsl_permutation_get($p->{permutation}, 5) . "] \n";
my $vec->{vector} = gsl_vector_alloc(6);
map { gsl_vector_set($vec->{vector}, $_, $_) } (0..5);
print "We will now apply the permutation to this vector : [";
map { print gsl_vector_get($vec->{vector}, $_) . "," } (0..4);
print gsl_vector_get($vec->{vector}, 5) . "] \n";
gsl_permute_vector($p->{permutation}, $vec->{vector});
print "The vector is now : [";
map { print gsl_vector_get($vec->{vector}, $_) . "," } (0..4);
print gsl_vector_get($vec->{vector}, 5) . "] \n";
π«Ά AUTHORS π«Ά
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com> β legends, honestly π
π 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. so go off, do your thing, just keep it free bestie β¨
and that's the whole page, babe π one last thing: this was served up by perl v5.42.3 on 2026-08-20 β write that down for the citation, iykyk π mwah, go manipulate some permutations π
π¦ 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