18  API Reference

Complete reference for scicloj.harmonica — the public API for computational group theory and representation theory.

Group Constructors

cyclic-group

Create the cyclic group Z/nZ of order n. Elements are integers 0, 1, …, n-1. The group operation is addition mod n.

(hm/cyclic-group 5)
{:n 5}

symmetric-group

Create the symmetric group S_n — all permutations of {0, …, n-1}. Elements are 0-indexed one-line notation vectors. The group operation is composition (right-to-left).

(hm/symmetric-group 3)
{:n 3}

dihedral-group

Create the dihedral group D_n — symmetries of a regular n-gon. Order 2n. Elements are [:r k] (rotations) and [:s k] (reflections).

(hm/dihedral-group 4)
{:n 4}

product-group

Create the direct product G₁ × G₂ of two finite groups. Elements are pairs [g h].

(hm/product-group (hm/cyclic-group 2) (hm/cyclic-group 3))
{:G1 {:n 2}, :G2 {:n 3}}

Group Operations

op

Group operation: combine two elements.

(hm/op (hm/cyclic-group 7) 3 5)
1
(hm/op (hm/symmetric-group 3) [1 2 0] [0 2 1])
[1 0 2]

inv

Group inverse of an element.

(hm/inv (hm/cyclic-group 7) 3)
4
(hm/inv (hm/symmetric-group 3) [1 2 0])
[2 0 1]

id

The identity element of a group.

(hm/id (hm/cyclic-group 5))
0
(hm/id (hm/symmetric-group 3))
[0 1 2]
(hm/id (hm/dihedral-group 4))
[:r 0]

elements

Sequence of all elements of a finite group.

(vec (hm/elements (hm/cyclic-group 4)))
[0 1 2 3]

order

Number of elements in a finite group.

(hm/order (hm/symmetric-group 4))
24

conjugacy-classes

Conjugacy classes of a finite group.

(let [classes (hm/conjugacy-classes (hm/symmetric-group 3))]
  (mapv :size classes))
[2 3 1]

Permutation Utilities

cycles

Cycle decomposition of a permutation. Returns a vector of cycles (each a vector), omitting fixed points.

(hm/cycles [1 2 3 0])
[[0 1 2 3]]
(hm/cycles [1 0 3 2])
[[0 1] [2 3]]

cycle-type

The cycle type of a permutation as a partition (descending sorted). Includes 1-cycles (fixed points).

(hm/cycle-type [1 0 3 2])
[2 2]

sign

The sign of a permutation: +1 for even, -1 for odd.

(hm/sign [1 0 2 3])
-1
(hm/sign [0 1 2 3])
1

identity-perm

The identity permutation of size n: [0 1 2 … n-1].

(hm/identity-perm 4)
[0 1 2 3]

transposition

Create a transposition permutation that swaps positions i and j. (transposition n i j) returns a permutation of size n.

(hm/transposition 5 1 3)
[0 3 2 1 4]

adjacent-transposition-decomposition

Decompose a permutation into adjacent transpositions s_i = (i, i+1). Returns a vector of indices [i_1, i_2, …] such that sigma = s_{i_1} ∘ s_{i_2} ∘ … ∘ s_{i_k}.

(hm/adjacent-transposition-decomposition [2 0 1])
[1 0]

Partitions

partitions

All partitions of n, as descending vectors.

(hm/partitions 4)
[[4] [3 1] [2 2] [2 1 1] [1 1 1 1]]

partition-conjugate

Conjugate (transpose) of a partition — swap rows and columns in the Young diagram.

(hm/partition-conjugate [4 2 1])
[3 2 1 1]

Young Tableaux

standard-young-tableaux

All standard Young tableaux of shape lambda (a partition). Each SYT is a vector of row vectors.

(hm/standard-young-tableaux [2 1])
[[[1 2] [3]] [[1 3] [2]]]

hook-length-dimension

Dimension of the irrep of S_n for partition lambda, via the hook-length formula.

(hm/hook-length-dimension [3 2])
5
(hm/hook-length-dimension [2 2 1])
5

Characters

character-table

Compute the character table of a finite group.

(let [ct (hm/character-table (hm/cyclic-group 3))]
  (count (:table ct)))
3
(let [ct (hm/character-table (hm/symmetric-group 3))
      re-table (mapv (fn [row] (mapv #(Math/round (cx/re %)) row))
                     (:table ct))]
  re-table)
[[1 1 1] [2 0 -1] [1 -1 1]]

character-inner-product

Inner product of two class functions.

(let [ct (hm/character-table (hm/symmetric-group 3))
      {:keys [table class-sizes]} ct
      order (hm/order (:group ct))]
  (cx/re (hm/character-inner-product (nth table 0) (nth table 1) class-sizes order)))
0.0

format-cx

Format a complex character value for display. Integers stay as integers, pure imaginary values display as i/-i/ni, and general complex values display as re+imi.

(hm/format-cx (cx/complex 0 1))
"i"

show-character-table

Display a character table as a kind/table with labeled rows and columns. Rows are irreducible representations, columns are conjugacy classes. Complex values are formatted for readability.

(hm/show-character-table (hm/character-table (hm/symmetric-group 3)))
[1 1 1] [2 1] [3]
[3] 1 1 1
[2 1] 2 0 -1
[1 1 1] 1 -1 1

Representations

irrep

Construct an irreducible representation of S_n from a partition. Returns an opaque value to pass to rep-matrix, etc.

(let [ir (hm/irrep [2 1])]
  (hm/rep-dimension ir))
2

rep-matrix

Compute the representation matrix ρ(σ) for a group element.

(let [ir (hm/irrep [2 1])]
  (fm/nrow (hm/rep-matrix ir [1 0 2])))
2

rep-dimension

Dimension of a representation.

(hm/rep-dimension (hm/irrep [3 1]))
3

rep-character

Character value χ(σ) = tr(ρ(σ)).

(let [ir (hm/irrep [2 1])]
  (hm/rep-character ir [0 1 2]))
2.0

rep-generators

Generator matrices for adjacent transpositions s_1, …, s_{n-1}.

(let [ir (hm/irrep [2 1])]
  (count (hm/rep-generators ir)))
2

tensor-product

Tensor product ρ₁ ⊗ ρ₂ of two representations. (ρ₁⊗ρ₂)(g) = ρ₁(g) ⊗ ρ₂(g) (Kronecker product).

(let [ir1 (hm/irrep [2 1])
      ir2 (hm/irrep [2 1])
      tp (hm/tensor-product ir1 ir2)]
  (hm/rep-dimension tp))
4

direct-sum

Direct sum ρ₁ ⊕ ρ₂ of two representations. (ρ₁⊕ρ₂)(g) is block-diagonal with ρ₁(g) and ρ₂(g).

(let [ir1 (hm/irrep [2 1])
      ir2 (hm/irrep [1 1 1])
      ds (hm/direct-sum ir1 ir2)]
  (hm/rep-dimension ds))
3

frobenius-norm-sq

Squared Frobenius norm: ||M||²_F = tr(M Mᵀ).

(let [M (fm/rows->mat [[1.0 0.0] [0.0 1.0]])]
  (hm/frobenius-norm-sq M))
2.0

frobenius-norm

Frobenius norm: ||M||_F = sqrt(tr(M Mᵀ)).

(let [M (fm/rows->mat [[3.0 0.0] [0.0 4.0]])]
  (hm/frobenius-norm M))
5.0

matrix-fourier-transform

Matrix-valued Fourier transform: f̂(ρ) = Σ f(σ)·ρ(σ).

(let [G (hm/symmetric-group 3)
      ir (hm/irrep [2 1])
      f (zipmap (hm/elements G) (repeat 1.0))
      fhat (hm/matrix-fourier-transform ir G f)]
  (fm/nrow fhat))
2

Riffle Shuffles

rising-sequences

Number of rising sequences of a permutation.

(hm/rising-sequences [0 1 2 3])
1
(hm/rising-sequences [3 2 1 0])
4

gsr-probability

Probability of permutation σ after k riffle shuffles (GSR model). Q_a(σ) = C(a+n-r(σ), n) / a^n where a=2^k, r = rising sequences.

(let [p (hm/gsr-probability [0 1 2 3] 1)]
  (> p 0.0))
true

Group Actions

orbit

The orbit of point x under the action of group G. act is a function (act g x) → x’.

(let [G (hm/cyclic-group 4)
      act (fn [g x] (mod (+ g x) 4))]
  (hm/orbit G act 0))
#{0 1 3 2}

orbits

Partition domain into orbits under the action of group G. Returns a vector of sets.

(let [G (hm/cyclic-group 3)
      act (fn [g x] (mod (+ g x) 3))]
  (count (hm/orbits G act (range 3))))
ImportantNo implementation of method: :elements of protocol: #’scicloj.harmonica.protocols/FiniteGroup found for class: scicloj.harmonica.group.cyclic.CyclicGroup
                          clojure.core/eval          core.clj: 3232
                                        ...                       
    harmonica-book.api-reference/eval124310        REPL Input:     
            scicloj.harmonica.action/orbits        action.clj:   35
             scicloj.harmonica.action/orbit        action.clj:   24
scicloj.harmonica.protocols/eval102277/fn/G     protocols.clj:   14
            clojure.core/-cache-protocol-fn  core_deftype.clj:  585
java.lang.IllegalArgumentException: No implementation of method: :elements of protocol: #'scicloj.harmonica.protocols/FiniteGroup found for class: scicloj.harmonica.group.cyclic.CyclicGroup

source: notebooks/harmonica_book/api_reference.clj