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 $p to 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 $p was using. bye bestie, releasing you back into the wild πŸ’œ
  • gsl_permutation_memcpy($dest, $src) β€” copies the permutation $src into the permutation $dest. the two permutations must have the same length. returns 0 if the operation succeeded, 1 otherwise.
  • gsl_permutation_fread($stream, $p) β€” reads into the permutation $p from the open stream $stream (opened with the gsl_fopen function from the Math::GSL module) in binary format. the permutation $p must be preallocated with the correct length, because the function uses the size of $p to figure out how many bytes to read. returns 1 if 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 $p to the stream $stream (opened with the gsl_fopen function from the Math::GSL module) in binary format. returns 1 if 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 the gsl_fopen function from the Math::GSL module) into the permutation $p. $p must be preallocated with the correct length, since the function uses the size of $p to decide how many numbers to read. returns 1 if there was a problem reading from the file.
  • gsl_permutation_fprintf($stream, $p, $format) β€” writes the elements of the permutation $p line-by-line to the stream $stream (opened with the gsl_fopen function from the Math::GSL module), using the format specifier $format, which should be suitable. "%zu\n" is a suitable format, fyi. returns 1 if 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 $i is outside the range of 0 to n-1, you get 0 back.
  • gsl_permutation_swap($p, $i, $j) β€” exchanges the $i-th position and the $j-th position of the permutation $p. returns 0 if the operation succeeded, 1 otherwise. trade places, periodt πŸ’…
  • gsl_permutation_valid($p) β€” returns 0 if the permutation $p is valid (meaning the n elements contain each of the numbers 0 to n-1 once and only once), 1 otherwise. 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 returns 0 if the operation succeeded, 1 otherwise.
  • gsl_permutation_next($p) β€” advances the permutation $p to the next permutation in lexicographic order. returns 0 if the operation succeeded, 1 otherwise. on to the next one πŸ’«
  • gsl_permutation_prev($p) β€” steps backward from the permutation $p to the previous permutation in lexicographic order. returns 0 if the operation succeeded, 1 otherwise. going back, back, back πŸ¦‹
  • gsl_permutation_mul($p, $pa, $pb) β€” combines the two permutations $pa and $pb into a single permutation $p. returns 0 if the operation succeeded, 1 otherwise. two become one, collab of the century πŸ”₯
  • gsl_permutation_linear_to_canonical($q, $p) β€” computes the canonical form of the permutation $p and stores it in $q. returns 0 if the operation succeeded, 1 otherwise.
  • gsl_permutation_canonical_to_linear($p, $q) β€” converts a canonical permutation $q back into linear form and stores it in $p. returns 0 if the operation succeeded, 1 otherwise.
  • 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 (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