Skip to content

plr.py

The file math/src/tonnetz/plr.py. 76 lines, 8 definitions.

The P, L, R transformations and their compositions.

Composition rule: "PL" means first P, then L. The code and the text use the same rule.

Code, comments and printed output are in Turkish. The explanations are translated.

Top of file: imports

"""P, L, R dönüşümleri ve bileşimleri.Bileşim kuralı: "PL", önce P, sonra L demektir. Kodda ve metinde aynı kural kullanılır."""from __future__ import annotationsfrom .core import Chord, Tonnetz

P

function

M(x) <-> m(x). The root and the fifth stay.

def P(t: Tonnetz, c: Chord) -> Chord:    """M(x) <-> m(x). Kök ve beşli ortak kalır."""    return Chord("m" if c.kind == "M" else "M", c.root)

L

function

M(x) <-> m(x + b). The third and the fifth stay.

def L(t: Tonnetz, c: Chord) -> Chord:    """M(x) <-> m(x + b). Üçlü ve beşli ortak kalır."""    if c.kind == "M":        return Chord("m", (c.root + t.b) % t.N)    return Chord("M", (c.root - t.b) % t.N)

R

function

M(x) <-> m(x - a). The root and the third stay.

def R(t: Tonnetz, c: Chord) -> Chord:    """M(x) <-> m(x - a). Kök ve üçlü ortak kalır."""    if c.kind == "M":        return Chord("m", (c.root - t.a) % t.N)    return Chord("M", (c.root + t.a) % t.N)

OPS

constant
OPS = {"P": P, "L": L, "R": R}

apply

function

Applies the letters of word from left to right. apply(t, "PL", c) = L(P(c)).

def apply(t: Tonnetz, word: str, c: Chord) -> Chord:    """word içindeki harfleri soldan sağa sırayla uygular. apply(t, "PL", c) = L(P(c))."""    for letter in word:        c = OPS[letter](t, c)    return c

moving_step

function

The size of the step taken by the single note that moves in a transformation (between 0 and N/2).

def moving_step(t: Tonnetz, op: str) -> int:    """Dönüşümde hareket eden tek sesin adım büyüklüğü (0 ile N/2 arasında)."""    c = Chord("M", 0)    d = OPS[op](t, c)    (old,) = t.pitches(c) - t.pitches(d)    (new,) = t.pitches(d) - t.pitches(c)    diff = (new - old) % t.N    return min(diff, t.N - diff)

cycle

function

Starts from the chord start and applies the letters of word in turn, repeating them.

Returns the chords visited until the start chord (and the start of the word) is reached again.

def cycle(t: Tonnetz, word: str, start: Chord) -> list[Chord]:    """start akorundan başlayıp word harflerini sırayla, dönerek uygular.    Başlangıç akoruna (ve kelimenin başına) dönülene kadar uğranan akorları verir.    """    out = [start]    c = start    i = 0    while True:        c = OPS[word[i % len(word)]](t, c)        i += 1        if c == start and i % len(word) == 0:            return out        out.append(c)

cycle_length

function

The length of the cycle starting from the chord M(0) (the number of chords visited).

def cycle_length(t: Tonnetz, word: str) -> int:    """M(0) akorundan başlayan çevrimin uzunluğu (uğranan akor sayısı)."""    return len(cycle(t, word, Chord("M", 0)))

translation

function

The translation that a two-letter composition causes on major chords: M(x) -> M(x + result).

def translation(t: Tonnetz, word: str) -> int:    """İki harfli bileşimin majör akorlardaki ötelemesi: M(x) -> M(x + sonuç)."""    c = apply(t, word, Chord("M", 0))    if c.kind != "M":        raise ValueError("Bileşim majör akoru majöre götürmüyor.")    return c.root

Every number on this site comes from data produced by the Python core and is checked by tests.

TÜBİTAK 2204-A mathematics project