Skip to content

Generators and relations

generators

generators.py

Symbolic generators for U_q(sl_2).

This module defines the four generators (E, F, K, K^{-1}) and the formal parameter q as noncommutative SymPy symbols. No relations are imposed at this level: the structure is a free algebra. relations.py supplies the relations.

all_generators

all_generators() -> dict

Return the generators as a name-to-symbol dictionary.

Source code in quantum_group/generators.py
26
27
28
def all_generators() -> dict:
    """Return the generators as a name-to-symbol dictionary."""
    return {"E": E, "F": F, "K": K, "K_inv": K_inv, "q": q}

commutator

commutator(a: Expr, b: Expr) -> sp.Expr

Return the expanded commutator [a, b] = ab - ba.

Source code in quantum_group/generators.py
31
32
33
def commutator(a: sp.Expr, b: sp.Expr) -> sp.Expr:
    """Return the expanded commutator [a, b] = a*b - b*a."""
    return sp.expand(a * b - b * a)

relations

relations.py

Defining relations of U_q(sl_2) and their verification.

Defining relations
(R1)  K K^{-1} = K^{-1} K = 1
(R2)  K E K^{-1} = q^{ 2} E
(R3)  K F K^{-1} = q^{-2} F
(R4)  [E, F] = (K - K^{-1}) / (q - q^{-1})

At the symbolic level these relations can only be stated as definitions; a concrete matrix representation is used to check them. The verify_on_representation function tests whether a representation satisfies all four relations by checking that their residual matrices are zero.

RelationCheck dataclass

Result of checking one relation with matrices.

Source code in quantum_group/relations.py
62
63
64
65
66
67
68
69
70
71
@dataclass
class RelationCheck:
    """Result of checking one relation with matrices."""
    name: str
    holds: bool
    residual: sp.Matrix  # LHS - RHS; zero matrix if the relation holds

    def __repr__(self) -> str:  # pragma: no cover - cosmetic
        status = "OK" if self.holds else "FAILED"
        return f"<{self.name}: {status}>"

symbolic_relations

symbolic_relations() -> list[tuple[str, sp.Expr, sp.Expr]]

Return the four defining U_q(sl_2) relations as (LHS, RHS) pairs.

At the symbolic level, these pairs only name the relations.

Source code in quantum_group/relations.py
35
36
37
38
39
40
41
42
43
44
45
46
47
def symbolic_relations() -> list[tuple[str, sp.Expr, sp.Expr]]:
    """Return the four defining U_q(sl_2) relations as (LHS, RHS) pairs.

    At the symbolic level, these pairs only name the relations.
    """
    return [
        ("R1: KK^{-1} = 1", K * K_inv, sp.Integer(1)),
        ("R2: KEK^{-1} = q^2 E", K * E * K_inv, q**2 * E),
        ("R3: KFK^{-1} = q^-2 F", K * F * K_inv, q**(-2) * F),
        ("R4: [E,F] = (K - K^-1)/(q - q^-1)",
         commutator(E, F),
         (K - K_inv) / (q - q**(-1))),
    ]

pretty_print_relations

pretty_print_relations() -> str

Return a readable rendering of the relations.

Source code in quantum_group/relations.py
50
51
52
53
54
55
def pretty_print_relations() -> str:
    """Return a readable rendering of the relations."""
    out = ["Defining relations of U_q(sl_2):"]
    for name, lhs, rhs in symbolic_relations():
        out.append(f"  {name}:  {lhs}  =  {rhs}")
    return "\n".join(out)

verify_on_representation

verify_on_representation(E_mat: Matrix, F_mat: Matrix, K_mat: Matrix, Kinv_mat: Matrix, q_sym: Expr = q) -> dict[str, RelationCheck]

Check the U_q(sl_2) relations for matrices E, F, K, K^{-1}.

Parameters:

Name Type Description Default
E_mat Matrix

Concrete matrix representations of the generators. All must have the same (n+1) x (n+1) shape.

required
F_mat Matrix

Concrete matrix representations of the generators. All must have the same (n+1) x (n+1) shape.

required
K_mat Matrix

Concrete matrix representations of the generators. All must have the same (n+1) x (n+1) shape.

required
Kinv_mat Matrix

Concrete matrix representations of the generators. All must have the same (n+1) x (n+1) shape.

required
q_sym sympy expression

The q parameter used in the relations.

q

Returns:

Type Description
A dictionary mapping relation names to RelationCheck objects.

Raises:

Type Description
(TypeError, ValueError)

If a generator is not a square SymPy matrix, if the four shapes differ, or if q is 0 or ±1.

Source code in quantum_group/relations.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def verify_on_representation(
    E_mat: sp.Matrix,
    F_mat: sp.Matrix,
    K_mat: sp.Matrix,
    Kinv_mat: sp.Matrix,
    q_sym: sp.Expr = q,
) -> dict[str, RelationCheck]:
    """Check the U_q(sl_2) relations for matrices E, F, K, K^{-1}.

    Parameters
    ----------
    E_mat, F_mat, K_mat, Kinv_mat : sympy.Matrix
        Concrete matrix representations of the generators. All must have
        the same (n+1) x (n+1) shape.
    q_sym : sympy expression
        The q parameter used in the relations.

    Returns
    -------
    A dictionary mapping relation names to RelationCheck objects.

    Raises
    ------
    TypeError, ValueError
        If a generator is not a square SymPy matrix, if the four shapes
        differ, or if q is 0 or ±1.
    """
    shapes = {
        name: check_square(M, name)
        for name, M in (("E_mat", E_mat), ("F_mat", F_mat),
                        ("K_mat", K_mat), ("Kinv_mat", Kinv_mat))
    }
    if len(set(shapes.values())) != 1:
        raise ValueError(f"E, F, K and K^-1 must have the same shape; got {shapes}.")
    q_sym = sp.sympify(q_sym)
    if q_sym in (0, 1, -1):
        raise ValueError("The defining commutator quotient requires q != 0, 1, -1; use classical limits separately.")
    n = E_mat.rows
    I = sp.eye(n)

    checks: dict[str, RelationCheck] = {}

    # R1: K K^{-1} = I
    res = K_mat * Kinv_mat - I
    checks["R1"] = RelationCheck("R1: KK^{-1} = 1", is_zero_matrix(res), res)

    # R2: K E K^{-1} = q^2 E
    res = K_mat * E_mat * Kinv_mat - q_sym**2 * E_mat
    checks["R2"] = RelationCheck("R2: KEK^{-1} = q^2 E", is_zero_matrix(res), res)

    # R3: K F K^{-1} = q^{-2} F
    res = K_mat * F_mat * Kinv_mat - q_sym**(-2) * F_mat
    checks["R3"] = RelationCheck("R3: KFK^{-1} = q^{-2} F", is_zero_matrix(res), res)

    # R4: [E, F] = (K - K^{-1}) / (q - q^{-1})
    res = (E_mat * F_mat - F_mat * E_mat) - (K_mat - Kinv_mat) / (q_sym - q_sym**(-1))
    checks["R4"] = RelationCheck(
        "R4: [E,F] = (K - K^{-1})/(q - q^{-1})",
        is_zero_matrix(res),
        res,
    )

    return checks

verify_relations_core

verify_relations_core(E: Matrix, F: Matrix, K: Matrix, K_inv: Matrix, q_sym: Expr = q) -> dict[str, RelationCheck]

Manuscript-compatible wrapper for verify_on_representation.

The repository's stable API is verify_on_representation. The manuscript and older notes sometimes use verify_relations_core for the same matrix-level relation check, so this wrapper preserves that name without duplicating logic.

Source code in quantum_group/relations.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def verify_relations_core(
    E: sp.Matrix,
    F: sp.Matrix,
    K: sp.Matrix,
    K_inv: sp.Matrix,
    q_sym: sp.Expr = q,
) -> dict[str, RelationCheck]:
    """Manuscript-compatible wrapper for ``verify_on_representation``.

    The repository's stable API is ``verify_on_representation``. The manuscript
    and older notes sometimes use ``verify_relations_core`` for the same
    matrix-level relation check, so this wrapper preserves that name without
    duplicating logic.
    """
    return verify_on_representation(E, F, K, K_inv, q_sym=q_sym)

all_relations_hold

all_relations_hold(checks: dict[str, RelationCheck]) -> bool

Return whether all relations hold (convenience function).

Source code in quantum_group/relations.py
161
162
163
def all_relations_hold(checks: dict[str, RelationCheck]) -> bool:
    """Return whether all relations hold (convenience function)."""
    return all(c.holds for c in checks.values())