---
name: "Math::GSL::Multiset"
section: "3pm"
platform: "linux"
package: "libmath-gsl-perl"
version: "0.45-2+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Math::GSL::Multiset"
---

# Math::GSL::Multiset(3pm)

Multisets manipulation

## NAME

Math::GSL::Multiset - Multisets manipulation

## SYNOPSIS

```
    use Math::GSL::Multiset qw/:all/;
    my $ms = Math::GSL::Multiset->($n, $k);

    my $value = $ms->get(2);
    # compute next multiset
    $ms->next;
    # compute the previous multiset
    # clone a multiset
    my $other = $ms->clone();
```

## DESCRIPTION

A multiset c is represented by an array of k integers  in the range 0 to n-1, where each value c\_i may occur more than once. The multiset c corresponds to indices of k elements  chosen from an n element vector with replacement. In mathematical terms, n is the cardinality of the multiset while k is the maximum multiplicity of any value.

### Object Oriented API

Handy Perl-style OO API for Multisets.

- "new"

  Creates a new multiset with parameters n, k and initializes it to the  lexicographically first multiset element, i.e., 0 repeated k times.

  ```
      my $ms = Math::GSL::Multiset->($n, $k);
  ```

- "init\_first"

  Initializes the multiset to the lexicographically first multiset element, i.e. 0 repeated k times.

  ```
      $ms->init_first;
  ```

- "init\_last"

  Initializes the multiset c to the lexicographically last multiset element, i.e. n-1 repeated k times.

  ```
      $ms->init_last;
  ```

- "get"

  Returns the value of the i-th element of the multiset. If i lies outside the allowed range of 0 to k-1 then the error handler is invoked and 0 is returned.

  ```
      my $val = $ms->get($k-1);
  ```

- "next"

  Advances the multiset to the next multiset element in lexicographic order and returns GSL\_SUCCESS. If no further multisets elements are available it returns GSL\_FAILURE and leaves the multiset unmodified. Starting with the first multiset and repeatedly applying this function will iterate through all possible multisets of a given order.

  ```
      $ms->next();
  ```

- "prev"

  ```
      $ms->prev();
  ```

  Steps backwards from the multiset to the previous multiset element in lexicographic  order, returning GSL\_SUCCESS. If no previous multiset is available it returns GSL\_FAILURE and leaves the multiset unmodified.

- "to\_list"

  Creates a Perl list of integers with the values from the multiset, starting at index 0 and ending at index `$k`-1.

  ```
      @data = $ms->to_list;
  ```

- "clone"

  Creates a new multiset with the same size, and same values.

  ```
      my $new = $ms->clone;
  ```

### GSL API

For reference on these methds, please consult the GSL documentation.

- "gsl\_multiset\_calloc"

  - "gsl\_multiset\_alloc"

  - "gsl\_multiset\_init\_first"

  - "gsl\_multiset\_init\_last"

  - "gsl\_multiset\_free"

  - "gsl\_multiset\_memcpy"

  - "gsl\_multiset\_get"

  - "gsl\_multiset\_n"

  - "gsl\_multiset\_k"

  - "gsl\_multiset\_data"

  - "gsl\_multiset\_valid"

  - "gsl\_multiset\_next"

  - "gsl\_multiset\_prev"

  - "gsl\_multiset\_fwrite"

  - "gsl\_multiset\_fread"

  - "gsl\_multiset\_fprintf"

  - "gsl\_multiset\_fscanf"

  ## 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.
