bisc_package package

Subpackages

Submodules

bisc_package.cli module

Command-line interface for the BiSC algorithm package.

This module provides console commands for running examples and demonstrations.

bisc_package.cli.run_examples()[source]

Run the main BiSC algorithm examples.

bisc_package.cli.run_demo()[source]

Run the comprehensive BiSC demonstration.

bisc_package.cli.print_basic_info()[source]

Print basic information about the BiSC algorithm.

bisc_package.cli.main()[source]

Main CLI entry point.

Module contents

BiSC Algorithm Package

Implementation of the BiSC algorithm from “BiSC: An algorithm for discovering generalized permutation patterns” by Henning Ulfarsson.

The BiSC algorithm automatically discovers forbidden patterns in sets of permutations, bridging computer science and mathematics through automated conjecture generation.

class bisc_package.Permutation(sequence)[source]

Bases: object

Represents a permutation in one-line notation.

A permutation is a bijection from {1, 2, …, n} to itself. We represent it as a list where position i contains the value π(i).

sequence

The permutation in one-line notation

Type:

List[int]

length

The length of the permutation

Type:

int

__eq__(other)[source]

Check equality with another permutation.

__hash__()[source]

Hash function for use in sets and dictionaries.

__init__(sequence)[source]

Initialize a permutation.

Parameters:

sequence (List[int]) – List representing the permutation in one-line notation

__repr__()[source]

Detailed string representation.

__str__()[source]

String representation of the permutation.

complement()[source]

Return the complement of this permutation.

Return type:

Permutation

contains_classical_pattern(pattern)[source]

Check if this permutation contains a classical pattern.

Parameters:

pattern (List[int]) – The pattern to search for

Return type:

bool

Returns:

True if the pattern is contained, False otherwise

inverse()[source]

Return the inverse of this permutation.

Return type:

Permutation

reverse()[source]

Return the reverse of this permutation.

Return type:

Permutation

subwords(max_length)[source]

Generate all subwords of length at most max_length.

Parameters:

max_length (int) – Maximum length of subwords to generate

Returns:

  • subword is the subsequence of values

  • positions is the list of indices where these values occur

Return type:

List of tuples (subword, positions) where

class bisc_package.MeshPattern(pattern, shading=None)[source]

Bases: object

Represents a mesh pattern (classical pattern + shading).

A mesh pattern consists of: 1. A classical pattern (permutation) 2. A set of shaded regions that forbid elements from appearing

pattern

The classical pattern

Type:

List[int]

shading

Set of shaded regions (i,j)

Type:

frozenset

length

Length of the classical pattern

Type:

int

__eq__(other)[source]

Check equality with another mesh pattern.

__hash__()[source]

Hash function for use in sets and dictionaries.

__init__(pattern, shading=None)[source]

Initialize a mesh pattern.

Parameters:
  • pattern (List[int]) – The classical pattern as a list

  • shading (Set[Tuple[int, int]]) – Set of shaded regions (i,j). Defaults to empty set.

__repr__()[source]

Detailed string representation.

__str__()[source]

String representation of the mesh pattern.

add_shading(region)[source]

Return a new mesh pattern with an additional shaded region.

Parameters:

region (Tuple[int, int]) – The (i,j) region to shade

Return type:

MeshPattern

Returns:

New MeshPattern with the additional shading

get_all_regions()[source]

Get all possible mesh regions for this pattern.

Return type:

Set[Tuple[int, int]]

Returns:

Set of all possible (i,j) mesh regions

get_classical_pattern()[source]

Get the underlying classical pattern.

Return type:

List[int]

get_unshaded_regions()[source]

Get all unshaded mesh regions.

Return type:

Set[Tuple[int, int]]

Returns:

Set of unshaded (i,j) regions

is_classical()[source]

Check if this is a classical pattern (no shading).

Return type:

bool

is_shading_maximal(allowed_shadings)[source]

Check if this shading is maximal among allowed shadings.

Parameters:

allowed_shadings (Set[frozenset]) – Set of allowed shading patterns

Return type:

bool

Returns:

True if this shading is maximal

remove_shading(region)[source]

Return a new mesh pattern with a shaded region removed.

Parameters:

region (Tuple[int, int]) – The (i,j) region to unshade

Return type:

MeshPattern

Returns:

New MeshPattern without the specified shading

to_latex()[source]

Generate LaTeX representation (basic version).

Return type:

str

Returns:

LaTeX string representation

bisc_package.bisc_algorithm(permutations, max_pattern_length)[source]

The full BiSC algorithm.

Combines the MINE and GEN algorithms to discover forbidden patterns in a set of permutations.

Parameters:
  • permutations (List[Permutation]) – Input set of permutations

  • max_pattern_length (int) – Upper bound on pattern length to search for

Return type:

List[MeshPattern]

Returns:

List of conjectured forbidden patterns

Examples

>>> # Stack-sortable permutations
>>> stack_sortable = [Permutation([1]), Permutation([1,2]), ...]
>>> forbidden = bisc_algorithm(stack_sortable, max_pattern_length=3)
>>> # Should find pattern 231 as forbidden
bisc_package.mine_algorithm(permutations, max_pattern_length)[source]

The MINE algorithm (Algorithm 1 from the paper).

Finds all mesh patterns that are contained in permutations in the input. This is the first step of the BiSC algorithm.

Parameters:
  • permutations (List[Permutation]) – List of input permutations

  • max_pattern_length (int) – Upper bound on pattern length to search for

Return type:

Dict[Tuple[int, ...], Set[FrozenSet]]

Returns:

Dictionary mapping classical patterns to sets of maximal shadings

Note

The output maps pattern tuples to sets of frozensets, where each frozenset represents a maximal shading for that pattern.

bisc_package.gen_algorithm(S)[source]

The GEN algorithm (Algorithm 2 from the paper).

Generates forbidden patterns from the allowed patterns found by MINE. This is the second step of the BiSC algorithm.

Parameters:

S (Dict[Tuple[int, ...], Set[FrozenSet]]) – Output from MINE algorithm - patterns with their allowed shadings

Return type:

List[MeshPattern]

Returns:

List of forbidden mesh patterns

Note

This generates minimal forbidden shadings that are not contained in any allowed shading.