From 055026c79b1cd9285615ce4a8f1246cc57c197e2 Mon Sep 17 00:00:00 2001 From: Jonathan Harker Date: Tue, 24 Sep 2024 19:12:21 +1200 Subject: [PATCH] Add a test for Leonard brightness conjecture --- setclass/tests/test_exploration.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 setclass/tests/test_exploration.py diff --git a/setclass/tests/test_exploration.py b/setclass/tests/test_exploration.py new file mode 100644 index 0000000..1875349 --- /dev/null +++ b/setclass/tests/test_exploration.py @@ -0,0 +1,21 @@ +from setclass.setclass import SetClass + + +def test_brightness_conjecture(): + """ + Test that the difference in brightness between the (darkest) Rahn normal forms of any set class + and its complement (inverted, if assymetrical) satisfy the following quadratic: + + ΔB = (T-1)(T/2 - C) + + where B is brightness, T is tonality (number of divisions of the octave) and C is set + cardinality. + Note: see the performance note in the documentation for `darkest_of_cardinality`. High values of + tonality can take a while to calculate (T=24 takes about a minute on an Intel i7-13700H CPU). + """ + for T in range(1, 13): # 1 to 12 + for C in range(T + 1): # 0 to T + for sc in SetClass.darkest_of_cardinality(C, tonality=T): + test = sc.complement.inversion.darkest_form.brightness - sc.brightness + ΔB = int((T - 1) * (T / 2 - C)) + assert test == ΔB, f"T={T}, C={C}, ΔB={ΔB}, diff={test}: {sc.darkest_form}, {sc.complement.inversion.darkest_form}"