Icma-Talk Digest #23 on 5 November 1997

Rick Taube taube@uiuc.edu
Wed, 5 Nov 1997 13:59:54 -0500 (EST)


>Surprisingly (to me, at least) the generation of all chords is pretty

>fast.  But the filtering is unbelievably slow.  I've posted to the
common

>music newsgroup to see if anyone has a faster prime-form program than

>mine, but I believe the result will still be relatively slow.



? (time (dotimes (i 1000) (prime-form '( f4 e4 ef5 bf4))))

(DOTIMES (I 1000) (PRIME-FORM '(F4 E4 EF5 BF4))) took 1,999
milliseconds (1.999 seconds) to run.



500 solutions a second doesnt strike me as unbelievably slow for
totally unoptimized code so perhaps you could tell me what you consider
reasonable -- right now the function is spending most of the time
cobbling up lists, which can be done once and then destructivly
modified.


but to do your solution method you apparently need the prime form, not
the best normal.  given what i posted eariler here is a function that
produces prime form, again totally unoptimized so there is lots of room
for improvement:


(defun prime-form (notes)

  ;; return either best normal form or its inversion, whichever

  ;; has the smallest interval content.

  (flet ((invert-normal (n l)

           (loop for f = (first n)

                 for j in l collect (transpose f (- j)))))

    (let (n1 n2 i1 i2)

      (multiple-value-setq (n1 i1) (normal-form notes))

      (multiple-value-setq (n2 i2) (normal-form (invert-normal n1
i1)))

      (if (<< (apply #'+ i2) (apply #'+ i1))

        (values n2 i2)

        (values n1 i1)))))