Symmetric Group Permuter — Group-Theoretic Segment Reordering

Cuts a Sound into n segments, reorders them according to a permutation σ of S(n), raises σ to the k-th power, and reassembles the reordered segments with Praat's overlap concatenation. Includes named group-theoretic presets, cycle notation, five segmentation strategies, exact permutation diagnostics, and a standardized four-panel group-theoretic visualization.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 2.3 (2026) License: MIT License Repo: https://github.com/ShaiCohen-ops/Praat-plugin_AudioTools
Contents:

What this does

This script implements a group-theoretic segment reordering engine. It cuts the selected Sound into n segments (using one of five segmentation methods), reorders them according to a permutation σ of S(n) (the symmetric group on {1..n}), raises σ to the k-th power, and reassembles the reordered segments into a single new Sound using overlap-add crossfades.

What is S(n)? The symmetric group S(n) is the set of all permutations of n objects. A permutation σ maps each source segment i to an output position σ(i). The group-theoretic structure of S(n) — cycles, order, parity, transpositions — determines how the reordering behaves when iterated. This script lets you explore S(n) through named presets (Reverse, Cyclic Shift, Random Permutation, etc.) and custom cycle notation, and reports the full group-theoretic profile of both σ and σ^k.

Key Features:

Permutation convention: σ(i) is read as "segment i MOVES TO output position σ(i)". So (1 3 2) means: segment 1 → position 3, segment 3 → position 2, segment 2 → position 1. Any segment not named (e.g., segment 4 when n=4) stays fixed. This is the ordinary "where does element i go" reading of cycle notation. All presets below are built directly as σ in this convention. σ^k is σ composed with itself k times; k = 0 gives the untouched (identity) order, and a negative k applies the inverse permutation |k| times.

Quick start

  1. In Praat, select exactly one Sound object.
  2. Run script…Symmetric_Group_Permuter.praat.
  3. Choose a preset from the dropdown (Identity, Reverse, Adjacent Transposition, Pairwise Swap, Cyclic Shift, Random Permutation, Random Involution, Random Long Cycle, Derangement, or Custom).
  4. Set Group_degree_n (number of segments).
  5. If Custom, enter Permutation_cycles in cycle notation (e.g., (1 3 2)).
  6. Select Segmentation_mode (Equal Durations, Safe Cut, Silence/Intensity, Acoustic Change Points, or TextGrid).
  7. Set Iterations_k (0 = identity, negative = inverse).
  8. Click OK — the script segments, applies the permutation, reassembles with crossfade, and creates output.
Quick tip: Use Reverse to reverse the order of the segments; each segment itself still plays forward. Pairwise Swap swaps adjacent pairs (1↔2, 3↔4, …). Cyclic Shift rotates the segments by the Shift_amount. Random Long Cycle creates a single n-cycle — all segments participate in one orbit. Derangement has no fixed points (no segment stays in place). Enable Draw_visualization to see the permutation structure and the reordered waveform.
Important: The script uses Concatenate with overlap..., which joins the extracted Sounds in list/creation order. It therefore creates the temporary segments directly in final output order. The requested crossfade is capped at half the shortest actual segment; with n>1 the overlap shortens the output by approximately (n−1) × effective_crossfade. There is no additional peak normalization. Iterations_k accepts 0 and negative integers (σ⁰ = identity; negative values use the inverse). For random presets, Random_seed = 0 derives a seed from the clock; any non-zero seed is made positive and is reproducible.

9 Group-Theoretic Presets

PresetEffectOrderParityDescription
Identityσ(i) = i1evenNo change — segments stay in place.
Reverseσ(i) = n−i+12 for n>1; 1 for n=1even iff ⌊n/2⌋ is evenProduct of ⌊n/2⌋ disjoint transpositions; the middle segment is fixed when n is odd.
Adjacent Transposition(1 2)2 for n≥2; 1 for n=1odd for n≥2; even for n=1Swaps segments 1 and 2; with n=1 the script warns and leaves the identity.
Pairwise Swap(1 2)(3 4)…2 for n>1; 1 for n=1even iff ⌊n/2⌋ is evenRandom-free local involution with ⌊n/2⌋ swaps; final segment fixed for odd n.
Cyclic Shifti → i + shiftn / gcd(shift, n)variesRotation by Shift_amount. An n-cycle when gcd(shift, n)=1.
Random Permutationuniform randomvariesvariesFisher-Yates shuffled — explores S(n) uniformly.
Random Involutionmaximal disjoint transpositions2 for n>1; 1 for n=1even iff ⌊n/2⌋ is evenShuffle the elements, then pair adjacent entries; exactly one fixed point remains when n is odd.
Random Long Cyclesingle n-cyclen (1 when n=1)even iff n is oddA uniformly random n-cycle — all segments belong to one orbit.
Derangementno fixed pointsvariesvariesUniform random derangement by rejection sampling when n>1; n=1 has no derangement, so the script warns and uses identity.
Group-theoretic diagnostics: For both σ and σ^k, the script reports:
  • Cycle type: partition of n, e.g., "3+2+1" (one 3-cycle, one 2-cycle, one fixed point)
  • Order: lcm of cycle lengths — the smallest m > 0 such that (σ^k)^m = identity
  • Parity: even or odd — the sign of the permutation
  • Transpositions: minimum number of transpositions (σ decomposes into)
  • Fixed points: segments that do not move
These are computed, not estimated, from the actual permutation.

5 Segmentation Modes

Equal Durations

Segments are exactly duration / n seconds long. Simple, predictable, grid-aligned.

Equal Durations + Safe Cut

Starts from the equal-duration grid, then moves each interior boundary by at most ±20 ms and at most 20% of one nominal segment. It samples the local Praat Intensity contour and chooses the quietest tested point. This is a local quiet-cut heuristic, not zero-crossing alignment.

Silence/Intensity Threshold

Uses Praat Sound: To TextGrid (silences). Silence_threshold_dB is entered as a positive number and used as that many dB below the file's maximum intensity; minimum silent and sounding intervals are both 50 ms. If the detected transition count is not exactly n−1, the script thins or supplements the candidates as described below.

Acoustic Change Points (energy)

For each nominal boundary, searches ±40% of one nominal segment and chooses the sampled time with the largest absolute Intensity difference across a short symmetric lag. This is explicitly an energy-change heuristic, not spectral-flux onset detection.

Use Selected TextGrid

Uses the start times of the first n intervals on TextGrid_tier from exactly one TextGrid selected together with the Sound, with the Sound end as the last boundary. At least n intervals are required; if the tier contains more, the final output segment absorbs the remainder to the Sound end.

Boundary fallback: Silence/Intensity mode cannot promise exactly n boundaries on arbitrary material. It detects silent/sounding transitions, then either thins them (evenly, if there are more than needed) or pads them (by bisecting the largest remaining gap, if there are fewer than needed) until exactly n−1 interior boundaries exist. Both adjustments are reported in the Info window.

Group Theory — S(n) and Cycle Notation

Permutation σ in S(n)

σ is a bijection from {1, …, n} to itself.

Convention: σ(i) = the output position that source segment i moves to.

Cycle notation

A cycle (a b c) means: σ(a) = b, σ(b) = c, σ(c) = a.

Example: (1 3 2) in S(4): σ(1)=3, σ(3)=2, σ(2)=1, σ(4)=4.

Permutation exponentiation

σ² = σ ∘ σ (apply σ twice). σ⁰ = identity. σ⁻¹ = inverse permutation.

The script computes σ^k for any integer k (0, positive, negative).

Group-theoretic invariants

  • Cycle type: multiset of cycle lengths (e.g., "3+2+1")
  • Order: lcm of cycle lengths — smallest m with σ^m = identity
  • Parity: even if sum(cycle_length - 1) is even, else odd
  • Transpositions: sum(cycle_length - 1) — minimum transpositions to decompose σ
  • Fixed points: number of 1-cycles
Visualisation:
  • Permutation matrix: markers show source segment i → output position σ^k(i); the identity diagonal is a pale reference and cycle membership is colour-coded.
  • Cycle diagram: directed graph of σ^k, with nodes arranged in a circle. Arrows show each segment's destination.
  • Reorder slopegraph: source order (left) vs output order (right) — fixed points in grey.
  • Waveforms: source (top) and permuted output (bottom) share one amplitude scale; dotted lines mark actual source cuts and overlap-adjusted output splice positions, with cycle-coloured segment labels.

Parameters & Defaults

ParameterDefaultMeaning / implementation
PresetCustomChooses Custom cycle notation or one of nine named permutations. Named presets ignore Permutation_cycles.
Segmentation_modeEqual DurationsChooses one of the five boundary-generation methods described above.
Group_degree_n4Number of source segments and the degree of S(n). The script rejects collapsed/non-positive segments after boundary generation.
Permutation_cycles(1 3 2)Custom cycle notation. Unnamed elements stay fixed. Spaces or commas may separate elements. The final mapping must be a bijection.
Shift_amount1Used by Cyclic Shift and reduced modulo n.
Random_seed00 = clock-derived seed; non-zero = reproducible seed using its absolute value.
Crossfade_duration_ms5.0 msRequested overlap at every join; capped to half the shortest actual segment.
Iterations_k1Integer power σk. 0 = identity; negative values apply the inverse permutation.
Silence_threshold_dB25 dBSilence/Intensity mode only. Passed to Praat as a threshold 25 dB below the maximum intensity.
Minimum_pitch_for_silence_Hz100 HzPitch-floor/intensity-analysis setting used by Silence/Intensity, Safe Cut, and Acoustic Change Points.
TextGrid_tier1Interval tier used by Use Selected TextGrid mode.
Draw_visualizationyesDraws the standardized v2.3 group-theoretic diagnostic figure.
Play_resultyesPlays the completed output after reporting.
Output object: The completed Sound is named <source>_S<n>_permuted. Channel count and sampling rate are inherited through extraction and concatenation. The script does not normalize the output after the overlap assembly.

Applications

Compositional reordering

Use case: Create new musical structures by reordering segments of a sound according to group-theoretic permutations.

Settings: Reverse to reverse the order of segments; Cyclic Shift for rotation; Random Long Cycle for a single-orbit reordering. The samples inside each segment are not time-reversed.

Permutation iteration

Use case: Apply the same permutation repeatedly (σ, σ², σ³, …) to see how the structure evolves.

Settings: Set Iterations_k = 2, 3, … The script reports the cycle type of σ^k, so you can see how the permutation decomposes under iteration.

Inverse permutation

Use case: Apply the inverse of a permutation (σ⁻¹) to "undo" a reordering or to explore the opposite direction.

Settings: Iterations_k = -1. The script computes the inverse and applies it.

Random group elements

Use case: Generate random permutations, random involutions, random long cycles, or derangements for generative composition.

Settings: Random Permutation, Random Involution, Random Long Cycle, or Derangement presets. Set Random_seed for reproducibility.

Workflow: Voice recording → Reverse permutation

Source: Spoken word or sung phrase.
Settings: Reverse preset, n=8, Equal Durations, Iterations_k=1.
Result: The order of the eight voice segments is reversed, while the audio inside each segment retains its original time direction.

Workflow: Drum loop → Pairwise Swap

Source: Drum loop.
Settings: Pairwise Swap preset, n=8, Acoustic Change Points (energy), Iterations_k=1.
Result: Adjacent pairs of drum hits are swapped, creating a new rhythmic pattern.

Workflow: Long ambient texture → Random Long Cycle

Source: Long ambient recording.
Settings: Random Long Cycle preset, n=12, TextGrid segmentation, Iterations_k=1.
Result: The 12 segments are arranged in a single cycle — a new ordering that returns to the start after 12 steps.

Troubleshooting:
Segmentation produces fewer than n segments: For Silence/Intensity mode, the script pads by bisecting gaps. For TextGrid mode, it exits with an error if fewer intervals exist. Use a different segmentation mode or reduce n.
Crossfade is capped: The script caps crossfade at half the shortest segment to prevent overrun. The effective crossfade is reported in the Info window.
Random presets produce the same result: Set Random_seed = 0 for clock-derived seed (unpredictable), or a fixed number for reproducibility. The seed used is reported in the Info window.
Cycle notation parser fails: Use ordinary positive element numbers inside parentheses, e.g. (1 3 2). Commas are also accepted and converted to spaces. Cycles should define a genuine bijection; repeated/overlapping assignments that leave a value missing or duplicated cause the script to stop. If no valid cycle is found, the script uses the identity with a warning.
Visualisation labels are crowded: For n > 20, the cycle diagram node labels may overlap. The visualisation is designed for n ≤ 20; for larger n, consider reducing the number of segments or using the permutation matrix panel.

Visualisation (4-panel group-theoretic view)

When Draw_visualization is enabled, the script generates:
  • Panel A — Permutation matrix: Source segment i vs output position σ^k(i), with an identity reference diagonal and cycle membership colours.
  • Panel B — Cycle diagram: Directed graph of σ^k with nodes in a circle. Arrows show each segment's destination. Node colours indicate cycle membership.
  • Panel C — Reorder slopegraph: Source order (left) vs output order (right). Fixed points in grey; moved segments in cycle colours.
  • Panel D — Waveforms: Source (top) and assembled output (bottom) on a shared amplitude scale. Source boundaries use the actual segmentation; output boundaries account for the effective overlap. Labels identify the source segment occupying each output region.
  • Summary bar: Preset name, n, cycle type of σ and σ^k, order, parity, fixed points, transpositions, segmentation mode, crossfade, seed (if random).
The permutation matrix and cycle diagram are the key diagnostics — they show the structure of the permutation and how it decomposes into cycles.