[chuck-users] Integer divisions (and Rational package)

Hans Aberg haberg at math.su.se
Tue Dec 15 17:08:52 EST 2009


On 15 Dec 2009, at 20:58, Robert Poor wrote:

> As promised on this topic, I've posted documentation, source code,  
> example code and test suite for a Rational package at:
>
> 	http://wiki.cs.princeton.edu/index.php/Rational_Number_Package
> 	http://wiki.cs.princeton.edu/index.php/Rational.ck
> 	http://wiki.cs.princeton.edu/index.php/Rational_eg.ck
> 	http://wiki.cs.princeton.edu/index.php/Rational_test.ck
>
> ... respectively.  And respectfully. (Editing in Wiki ain't half bad!)

I found continued fraction convergents very useful when analyzing  
floating point data. I have some Haskell code if you want to implement  
it. For example,
   cfc (logBase 2 (3/2))
[0 % 1,1 % 1,1 % 2,3 % 5,7 % 12,24 % 41,31 % 53,179 % 306,389 %  
665,9126 % 15601,18641 % 31867,46408 % 79335,65049 % 111202,111457 %  
190537,6195184 % 10590737,6306641 % 10781274,31421748 %  
53715833,100571885 % 171928773,333137403 % 569502152,2099396303 %  
3588941685,2432533706 % 4158443837,89670609719 %  
153292919817,719797411458 % 1230501802373,809468021177 %  
1383794722190,1529265432635 % 2614296524563,3867998886447 %  
6612387771316,9265263205529 % 15839072067195,40929051708563 %  
69968676040096,50194314914092 % 85807748107291,442483571021299 %  
756430660898424,492677885935391 % 842238409005715,1427839342892081 %  
2440907478909854,1920517228827472 % 3283145887915569,5268873800547025  
% 9007199254740992]

Here, 7 % 12,24 % 41,31 % 53 are the rational numbers 7/12, 24/41,  
31/53, which is the ET sequence E12, E41, E53, with the scale degrees  
the interval 3/2 is on: 7, 24, 13. At least 7, you are well aware  
of. :-) One can get E31 by replacing 3/2 with sqrt(5/4), and a few more.

Also, being able to compute approximations in a n-limit is useful.  
They may hit on harmonies. Though I do not know a got method to  
implement it - I just search through combinations with not too high  
vales of the exponents. Perhaps a version of create(float v, int  
dlimit, int n) where n is in n-limit.

Those are useful for analyzing music data, but I do not know if they  
are useful in ChucK.

(In Scheme R5RS, they use "make" for constructors. Hopefully, ChucK if  
perhaps get C++ style constructors, explicit names won't be needed.)

   Hans




More information about the chuck-users mailing list