Add a test for Leonard brightness conjecture

This commit is contained in:
Jonathan Harker 2024-09-24 19:12:21 +12:00
parent 6f9cfb62b5
commit 055026c79b

View file

@ -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}"