Brief 4.2: the lengths of the PL, PR and LR cycles, compared with the formula 2N / gcd(N, d).
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)Cycle lengths
cycle_length(t, "PL") starts from the chord M(0), applies P and L in turn and counts how many chords are visited before returning to the start. The table gives the intervals, the P, L, R steps and the lengths of the three cycles for each N.
In 2
from math import gcdsatirlar = []for N in TETS: t = Tonnetz.tet(N) satirlar.append([N, f"({t.a}, {t.b}, {t.fifth})", *(moving_step(t, op) for op in "PLR"), *(cycle_length(t, w) for w in ("PL", "PR", "LR"))])tablo_yaz("cevrim-uzunluklari", ["N", "(a, b, a+b)", "P", "L", "R", "PL", "PR", "LR"], satirlar)Output
N (a, b, a+b) P L R PL PR LR 12 (3, 4, 7) 1 1 2 6 8 24 19 (5, 6, 11) 1 2 3 38 38 38 31 (8, 10, 18) 2 3 5 62 62 62 41 (11, 13, 24) 2 4 6 82 82 82 53 (14, 17, 31) 3 5 8 106 106 106
Checking the formula
The formula for the cycle length is 2N / gcd(N, d). d is the major third b for PL, the minor third a for PR and the fifth a + b for LR. The loop tries every N from 5 to 200. Tonnetz.tet raises an error for values of N that give no valid network, and those values are skipped. For every remaining N the direct count is compared with the formula.
In 3
denenen = 0for N in range(5, 201): try: t = Tonnetz.tet(N) except ValueError: continue denenen += 1 assert cycle_length(t, "PL") == 2 * N // gcd(N, t.b) assert cycle_length(t, "PR") == 2 * N // gcd(N, t.a) assert cycle_length(t, "LR") == 2 * N // gcd(N, t.fifth)print(denenen, "farklı N için formül tuttu.")Output
123 farklı N için formül tuttu.
Comparing 12 and 53
On the left all chords of the PL cycle for 12 divisions are drawn, on the right the first 12 chords of the same cycle for 53 divisions. The numbers in the titles come from the computation.
In 4
t12 = Tonnetz.tet(12)fig, axes = plt.subplots(1, 2, figsize=(14, 5.5))draw_lattice(t12, axes[0], cols=8, rows=6, chords=cycle(t12, "PL", Chord("M", 0)))axes[0].set_title(f"12: PL çevrimi, {cycle_length(t12, 'PL')} akor")draw_lattice(t53, axes[1], cols=11, rows=6, chords=cycle(t53, "PL", Chord("M", 0))[:12])axes[1].set_title(f"53: PL çevriminin ilk 12 akoru (toplam {cycle_length(t53, 'PL')})")kaydet(fig, "cevrim-pl-12-53")
For 53 divisions the number of chords, whether all chords are different and the first six chords are printed for each of the three cycles. If a cycle visits every chord exactly once, its length equals the total number of chords.
In 5
Output
PL 106 akor, hepsi farklı: True ilk altı: M(0) m(0) M(36) m(36) M(19) m(19) PR 106 akor, hepsi farklı: True ilk altı: M(0) m(0) M(14) m(14) M(28) m(28) LR 106 akor, hepsi farklı: True ilk altı: M(0) m(17) M(31) m(48) M(9) m(26)