# Miscellaneous functions/classes¶

## Partition¶

class replab.Partition(blockIndex, blocks)

Bases: replab.Str

Represents an unordered partition of the set {1..n} into disjoint subsets

The subsets, or blocks, are represented by sorted integer row vectors. The subsets themselves are sorted by their minimal element.

### Own members

blockIndex

Index of the block for each element

Type

integer(1, n)

blocks

List of blocks

Type

cell(1,*) of integer(1,*)

n

Domain size

Type

integer

Partition(blockIndex, blocks)

Constructs a Partition from blockIndex and list of blocks

Do not use this function direclty, rather use another constructor such as .fromBlocks.

Parameters
• blockIndex

• blocks (cell(1,*) of integer(1,*)) – Disjoint blocks

Returns

The partition

Return type

Partition

block(self, i)

Returns the i-th subset in this partition

Parameters

i (integer) – Block index

Returns

Subset

Return type

integer(1,*)

blockSize(self, i)

Returns the size of the i-th block

Parameters

i (integer) – Block index

Returns

Size of the i-th block in this partition

Return type

integer

blockSizes(self)

Returns the sizes of blocks

Returns

block sizes

Return type

integer(1,*)

check(self)

Verifies the sanity of this partition

eq(self, rhs)

Checks if this partition is equal to another partition

Parameters

rhs (Partition) – Another partition

Returns

True is both partitions are equal

Return type

logical

static finest(n)

Constructs the partition of n singleton blocks

Parameters

n (integer) – Size of the partition and number of blocks

Returns

Partition

Return type

Partition

static fromApproximateVector(vec, tol)

Returns the partition that groups approximately equal coefficients of a vector

Example

>>> replab.Partition.fromApproximateVector([0.1 0.2 0.9 1 0.3], 0.11)
Partition '125|34'
blockIndex: [1, 1, 2, 2, 1]
blocks: {[1, 2, 5], [3, 4]}
n: 5

Parameters
• vec (double(1,*), real) – Vector to group the coefficients of

• tol (double) – Tolerance

Returns

Partition of blocks with approximately equal coefficients

Return type

Partition

static fromBlocks(blocks)

Constructs a partition from disjoint blocks

The blocks will be sorted and reorganized.

Example

>>> replab.Partition.fromBlocks({[1 2 5] [3 4]})
Partition '125|34'
blockIndex: [1, 1, 2, 2, 1]
blocks: {[1, 2, 5], [3, 4]}
n: 5

Parameters

blocks (cell(1,*) of integer(1,*)) – Disjoint blocks

Returns

Constructed partition

Return type

replab.Partition

static fromVector(vec)

Returns the partition that groups equal coefficients of a vector

Example

>>> replab.Partition.fromVector([0 0 1 1 0])
Partition '125|34'
blockIndex: [1, 1, 2, 2, 1]
blocks: {[1, 2, 5], [3, 4]}
n: 5

Parameters

vec (double(1,*)) – Vector to group the coefficients of

Returns

Partition of blocks with equal coefficients

Return type

Partition

ge(self, rhs)

Returns whether the given partition is finer than this partition

Parameters

rhs (Partition) – Partition to compare this one with

Returns

True if every block of the given partition is a subset of a block of this partition

Return type

logical

gt(self, rhs)

Returns whether the given partition is strictly finer than this partition

Parameters

rhs (Partition) – Partition to compare this one with

Returns

True if self >= rhs and self ~= rhs

Return type

logical

join(lhs, rhs)

Returns the finest common coarsening of two partitions

Parameters

rhs (Partition) – Other partition

Returns

The coarsening of the two partitions

Return type

Partition

le(self, rhs)

Returns whether the given partition is coarser than this partition

Parameters

rhs (Partition) – Partition to compare this one with

Returns

True if every block of this partition is a subset of a block of the given partition

Return type

logical

lt(self, rhs)

Returns whether the given partition is strictly coarser than this partition

This is a strict version of le

Parameters

rhs (Partition) – Partition to compare this one with

Returns

True if self <= rhs and self ~= rhs

Return type

logical

meet(self, rhs)

Returns the common refinement of two partitions

Parameters

rhs (Partition) – Other partition

Returns

The refinement of both partitions

Return type

Partition

nBlocks(self)

Returns the number of subsets/blocks in this partition

Returns

Number of blocks

Return type

integer

ne(self, rhs)

Checks if this partition differs to another partition

Parameters

rhs (Partition) – Another partition

Returns

True is both partitions differ

Return type

logical

static permutationsOrbits(permutations)

Returns the partition of the domain 1...N into orbits

Parameters

permutations (integer(nG, d)) – Permutations given as rows in a matrix

Returns

Partition containing the orbits

Return type

Partition

restrictedToBlocks(self, selBlocks)

Returns the partition containing only the given blocks

The selected blocks are ordered

singletons(self)

Returns a set of all points that are singletons of this partition

The singletons are the blocks of size 1.

Returns

Set of points

Return type

integer(1,*)

static trivial(n)

Constructs the trivial partition with a single block of given cardinality

Parameters

n (integer) – Size of the partition and single block

Returns

Trivial partition

Return type

Partition

## Sequence¶

class replab.Sequence(nElements)

Bases: replab.Domain

Describes a sequence of elements

Our indices are (bounded) integers, represented by vpi instances.

The sequence supports element indexing and searching for elements.

### Own members

nElements

Number of elements contained in this enumerator

Type

vpi

at(self, ind)

Retrieves a element by position

Normally, RepLAB encodes big integers using the vpi type. As a user convenience (esp. on the command line), this method must also accept string and double arguments.

Parameters

ind (vpi or double or string) – Index of element to be retrieved, 1 <= ind <= self.nElements

Returns

The element at the “ind” position

find(self, obj)

Returns the index of a given element

If the element is not part of the family, this returns vpi(0).

Parameters

obj – Element to retrieve

Returns

1-based index of the given element

Return type

vpi

static lambda(nElements, atFun, findFun)

Constructs an indexed family from function handles

Parameters
• nElements (vpi) – Size of the indexed family, so that the index set is 1..nElements

• atFun (function_handle) – Handle that implements the at method To simplify implementation, it is guaranteed that atFun will receive an argument of type vpi.

• findFun (function_handle) – Handle that implements the find method

Returns

The constructed indexed family

Return type

Sequence

toCell(self)

Returns a row cell array containing all elements of this family

Returns

A cell array C such that C{i} = self.at(i)

Return type

row cell array of elements

Raises

An error if the enumerator is too big and the elements cannot fit in a cell array.

## msg¶

replab.msg(level, message, varargin)

Displays a diagnostic message on the console output

Additional arguments can be function handles, to be evaluated only when the message is actually displayed.

Parameters
• level (integer) – Verbosity level beginning at which to show the message (see replab.globals.verbosity)

• message (charstring) – Message to display, can include sprintf-style formatting directives