Brief section 3: pitch classes, edges, triangles, the Euler characteristic and the P, L, R transformations.
This notebook produces computations and figures. The proofs and the report text belong to the students.
Setup
Loads the package and the plotting library. kaydet saves a figure as PNG and SVG into rapor/sekiller. tablo_yaz writes a table as CSV into rapor/tablolar and prints it. t53 is the Tonnetz with 53 divisions, used in the rest of the notebook.
Setup code (imports and helper functions)
from pathlib import Pathimport csvimport matplotlib.pyplot as pltfrom tonnetz import *from tonnetz.plot import draw_latticeRAPOR = Path("..") / ".." / "rapor"SEKIL = RAPOR / "sekiller"; SEKIL.mkdir(parents=True, exist_ok=True)TABLO = RAPOR / "tablolar"; TABLO.mkdir(parents=True, exist_ok=True)def kaydet(fig, ad): for uzanti in ("png", "svg"): fig.savefig(SEKIL / f"{ad}.{uzanti}", dpi=300, bbox_inches="tight")def tablo_yaz(ad, basliklar, satirlar): with open(TABLO / f"{ad}.csv", "w", newline="", encoding="utf-8") as f: w = csv.writer(f); w.writerow(basliklar); w.writerows(satirlar) genislik = [max(len(str(x)) for x in sutun) for sutun in zip(basliklar, *satirlar)] for satir in (basliklar, *satirlar): print(" ".join(str(x).rjust(g) for x, g in zip(satir, genislik)))t53 = Tonnetz.tet(53)Counts
Tonnetz.tet(N) picks the steps closest to the pure intervals in the system that divides the octave into N equal parts: minor third a, major third b and fifth a + b. Nodes, edges and triangles are counted for each N. The Euler characteristic is nodes − edges + triangles. A result of 0 is consistent with the surface being a torus.
In 2
Output
N a b a+b düğüm kenar üçgen Euler 12 3 4 7 12 36 24 0 19 5 6 11 19 57 38 0 31 8 10 18 31 93 62 0 41 11 13 24 41 123 82 0 53 14 17 31 53 159 106 0
Closed surface check
For a surface to be closed, every edge must belong to exactly two triangles. The code counts this for all edges. It also checks that every node belongs to exactly six triangles. If one of the assert lines failed, the cell would raise an error.
In 3
Output
Bütün N değerleri için sağlandı: (12, 19, 31, 41, 53)
The P, L, R transformations
P, L and R take a chord to the neighbouring chord that shares two of its notes. moving_step gives how many steps the one changing note moves. translation gives how many steps the root of a major chord is shifted when two transformations are applied in a row. Composition rule: PL means first P, then L. In every row of the table the R step is the sum of the P and L steps.
In 4
satirlar = []for N in TETS: t = Tonnetz.tet(N) satirlar.append([N, *(moving_step(t, op) for op in "PLR"), *(translation(t, w) for w in ("PL", "PR", "LR"))])tablo_yaz("plr-adimlari", ["N", "P", "L", "R", "PL öteleme", "PR öteleme", "LR öteleme"], satirlar)Output
N P L R PL öteleme PR öteleme LR öteleme 12 1 1 2 8 3 7 19 1 2 3 13 5 11 31 2 3 5 21 8 18 41 2 4 6 28 11 24 53 3 5 8 36 14 31
Planar lattice and fundamental parallelogram
The lattice point (i, j) goes to the pitch i · fifth + j · major third. kernel_basis picks two short vectors among the lattice points whose pitch is 0. These two vectors are the sides of the fundamental parallelogram of the torus. The planar lattice repeats itself along these vectors. The figure draws a window of the lattice with 53 divisions.
In 5
for N in TETS: print(N, kernel_basis(Tonnetz.tet(N)))fig, ax = plt.subplots(figsize=(9, 6))ornek = [t53.major(0), t53.minor(0)]draw_lattice(t53, ax, cols=11, rows=8, chords=ornek)kaydet(fig, "kafes-53")Output
12 ((0, 3), (-4, 1)) 19 ((4, -1), (-1, 5)) 31 ((4, -1), (-1, 8)) 41 ((1, -5), (9, -4)) 53 ((5, -6), (8, 1))

The same drawing for 12 divisions. Because there are few pitches, the same pitch numbers appear several times in the window.
In 6
t12 = Tonnetz.tet(12)fig, ax = plt.subplots(figsize=(7, 5))draw_lattice(t12, ax, cols=8, rows=6, chords=[t12.major(0), t12.minor(0)])kaydet(fig, "kafes-12")