Last active
January 8, 2017 20:25
-
-
Save clumma/65dadc269b84a24e07b5c43d17a4037d to your computer and use it in GitHub Desktop.
generators for a rank-2 temperament
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; computes TE-optimal generators for a pair of vals | |
;; e.g. (generators '(1 2 4) '(0 -1 -4) '(2 3 5)) => (1201.397 504.348) | |
(define generators | |
(lambda (val1 val2 basis) | |
(let* ((square (lambda (x) (* x x))) | |
(log2 (lambda (x) (/ (log x) (log 2)))) | |
(mean (lambda (ls) (/ (apply + ls) (length ls)))) | |
(w1 (map / val1 (map log2 basis))) | |
(w2 (map / val2 (map log2 basis))) | |
(mw1 (mean w1)) | |
(mw2 (mean w2)) | |
(msqw1 (mean (map square w1))) | |
(msqw2 (mean (map square w2))) | |
(mw12 (mean (map * w1 w2))) | |
(common (/ 1200 (- (* msqw1 msqw2) (square mw12))))) | |
(list (* common (- (* mw1 msqw2) (* mw2 mw12))) | |
(* common (- (* mw2 msqw1) (* mw1 mw12))))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment