I find the integer divisions C rule is problematic when working with intervals. Suppose I have [8/7, 7/6, 7/6, 8/7] and implement it as [Interval.r(8/7), Interval.r(7/6), Interval.r(7/6), Interval.r(8/7)] Then this is the same as: [Interval.r(0), Interval.r(0), Interval.r(0), Interval.r(0)] One has to add ".0" one of the numerator/denominator: [Interval.r(8.0/7), Interval.r(7.0/6), Interval.r(7.0/6), Interval.r(8.0/7)], One possible rule might be converting 32-bit int to 64-bit floats, and then only back to int when needed. The question if it then affects some ChucK legacy code. Hans
2009/12/15 Hans Aberg
I find the integer divisions C rule is problematic
Well integer division is a fundamentally different operation from rational division - which is also a different operation from floating-point division. Augmenting Chuck to have true rationals might be nice, but I can't see the elimination of integer division as useful. Of course the real question is whether the integer remainders are mathematically correct (they aren't in most C-derived computer languages). david rush -- GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
On 15 Dec 2009, at 12:05, David Rush wrote:
2009/12/15 Hans Aberg
: I find the integer divisions C rule is problematic
Well integer division is a fundamentally different operation from rational division - which is also a different operation from floating-point division. Augmenting Chuck to have true rationals might be nice, ...
That is available in Haskell, and I have used it a lot in Hugs. But in ChucK, I just compute rationals directly into log2 intervals - there isn't any need of true rational numbers if one just is going to play the interval.
...but I can't see the elimination of integer division as useful.
Of course the real question is whether the integer remainders are mathematically correct (they aren't in most C-derived computer languages).
If one actually wants to scrap "/" for integers, the replacement would be functions like div(), quot(), rem(), guaranteeing the remainder is the correct range. My biggest worry is having a load of numerical data that must be edited by hand before entering, and forgetting quietly making disastrous results. Hans
I don't know... isn't this how most of the curly bracket languages work?
Might as well keep ChucK in line with the other languages. Btw, shouldn't it
be the same as this:
[Interval.r(1), Interval.r(1), Interval.r(1), Interval.r(1)]
/Stefan
On Tue, Dec 15, 2009 at 11:29 AM, Hans Aberg
I find the integer divisions C rule is problematic when working with intervals. Suppose I have [8/7, 7/6, 7/6, 8/7] and implement it as [Interval.r(8/7), Interval.r(7/6), Interval.r(7/6), Interval.r(8/7)] Then this is the same as: [Interval.r(0), Interval.r(0), Interval.r(0), Interval.r(0)] One has to add ".0" one of the numerator/denominator: [Interval.r(8.0/7), Interval.r(7.0/6), Interval.r(7.0/6), Interval.r(8.0/7)],
One possible rule might be converting 32-bit int to 64-bit floats, and then only back to int when needed. The question if it then affects some ChucK legacy code.
Hans
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Release me, insect, or I will destroy the Cosmos!
On 15 Dec 2009, at 12:07, Stefan Blixt wrote:
I don't know... isn't this how most of the curly bracket languages work?
It is really the C legacy. Typical of C is having a lot of implicit conversion, also when loosing data. In Haskell, or at least running interactively in Hugs, "/" on integers are treated as floats. I figure if one enforces the numbers to be Int (int) or Integer (multiprecision integer), then the result must be Rational - multiprecision rational numbers.
Might as well keep ChucK in line with the other languages. Btw, shouldn't it be the same as this:
[Interval.r(1), Interval.r(1), Interval.r(1), Interval.r(1)]
Yes, I was thinking about cents :-), that is the trivial interval. Hans
Hans: You've forced my hand. Would you be interested in a rational number package (y'know, where numbers are represented as a fraction)? I wrote one "by accident" when I thought that roundoff was causing a problem. It wasn't, but I have a cleanly written and tested Rational class if anyone could use it. Comes with a test suite. Has a stable float-to-rational conversion algorithm where you get to specify the maximum denominator. It even has a to_string() routine. If someone tells me where to put the code, I'm happy to send it. Yours in attempted helpfulness... - Rob On 15 Dec 2009, at 02:29, Hans Aberg wrote:
I find the integer divisions C rule is problematic when working with intervals. Suppose I have [8/7, 7/6, 7/6, 8/7] and implement it as [Interval.r(8/7), Interval.r(7/6), Interval.r(7/6), Interval.r(8/7)] Then this is the same as: [Interval.r(0), Interval.r(0), Interval.r(0), Interval.r(0)] One has to add ".0" one of the numerator/denominator: [Interval.r(8.0/7), Interval.r(7.0/6), Interval.r(7.0/6), Interval.r(8.0/7)],
One possible rule might be converting 32-bit int to 64-bit floats, and then only back to int when needed. The question if it then affects some ChucK legacy code.
Hans
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On 15 Dec 2009, at 14:07, Robert Poor wrote:
You've forced my hand. Would you be interested in a rational number package (y'know, where numbers are represented as a fraction)? I wrote one "by accident" when I thought that roundoff was causing a problem. It wasn't, but I have a cleanly written and tested Rational class if anyone could use it.
Comes with a test suite. Has a stable float-to-rational conversion algorithm where you get to specify the maximum denominator. It even has a to_string() routine.
If someone tells me where to put the code, I'm happy to send it.
I do not have need for such a class right now, as I just play the intervals, and therefore floats are just fine. Though I have written Haskell code for computing continued fraction convergents, which is very useful for analyzing data, which I use in Hugs. So rational numbers are useful - I just don't use them in ChucK, right now. But you bring up a question of where to put the stuff. Putting it up on this list is just convenient for snippets really. Check out http://haskell.org/. It is a wiki, I think. One can search a lot of code there. Perhaps there should be something for ChucK. Hans
Hans;
Check out http://haskell.org/. It is a wiki, I think. One can search a lot of code there. Perhaps there should be something for ChucK.
Like this? http://wiki.cs.princeton.edu/index.php/ChucK Kas.
Kassen:
Check out http://haskell.org/. It is a wiki, I think. One can search a lot of code there. Perhaps there should be something for ChucK.
There's also LiCK, a Library for ChucK. http://github.com/heuermh/lick LiCK was set up as a repository for chuck-users to share various bits of their reusable ChucK code. michael
Kas: Yes indeed -- http://wiki.cs.princeton.edu/index.php/Chuck/Lib looks like the perfect home for a Rational class. I'll post it there real soon now. Thanks. - Rob On 15 Dec 2009, at 07:09, Kassen wrote:
Hans;
Check out http://haskell.org/. It is a wiki, I think. One can search a lot of code there. Perhaps there should be something for ChucK.
Like this? http://wiki.cs.princeton.edu/index.php/ChucK
Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On 15 Dec 2009, at 16:09, Kassen wrote:
Check out http://haskell.org/. It is a wiki, I think. One can search a lot of code there. Perhaps there should be something for ChucK.
Like this? http://wiki.cs.princeton.edu/index.php/ChucK
Only that it would have been http://chuck.cs.princeton.edu/ that would be the wiki, so that the stuff does not get posted somewhere else. A long time, when wikis were new, they started off with a separate wiki, as ChucK has now. But eventually, that was integrated into one system. Hans
Hans;
A long time, when wikis were new, they started off with a separate wiki, as ChucK has now. But eventually, that was integrated into one system.
I don't really see any problem with the system we are using now. I don't think we would want the whole world to be able to edit the front page. Another issue is that the ChucK page is mirrored between Princeton and Stanford, while the WiKi isn't. At any rate; we have space to post code. People lacking their own server may also attach things like the binary resulting from a alternative compile to posts on the forum. If you run out of space for attachments there your quota can be increased. Kas.
On 15 Dec 2009, at 18:13, Kassen wrote:
A long time, when wikis were new, they started off with a separate wiki, as ChucK has now. But eventually, that was integrated into one system.
I don't really see any problem with the system we are using now. I don't think we would want the whole world to be able to edit the front page. Another issue is that the ChucK page is mirrored between Princeton and Stanford, while the WiKi isn't.
A wiki does not mean that everybody can edit it. Don't know exactly how it is done one the Haskell site. As you note, the only problem is to find the stuff. Right now, there is a small link after the electro-communities site, to a separate system. Hans
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!) As a teaser, here's an example its results: === file: t.ck Rational.create(pi, 1000) @=> Rational @ r2; <<< "pi as float is ~ ", pi >>>; <<< "pi as rational is ~ ", r2.toString(), "or", r2.toFloat() >>>; r2.mul(2) @=> Rational @ r3; <<< "2*pi as float is ~ ", 2 * pi >>>; <<< "2*pi as rational is ~ ", r3.toString(), "or", r3.toFloat() >>>; === EOF % chuck rational.ck t.ck pi as float is ~ 3.141593 pi as rational is ~ 355/113 or 3.141593 2*pi as float is ~ 6.283185 2*pi as rational is ~ 710/113 or 6.283186 - Rob On 15 Dec 2009, at 10:24, Hans Aberg wrote:
On 15 Dec 2009, at 18:13, Kassen wrote:
A long time, when wikis were new, they started off with a separate wiki, as ChucK has now. But eventually, that was integrated into one system.
I don't really see any problem with the system we are using now. I don't think we would want the whole world to be able to edit the front page. Another issue is that the ChucK page is mirrored between Princeton and Stanford, while the WiKi isn't.
A wiki does not mean that everybody can edit it. Don't know exactly how it is done one the Haskell site.
As you note, the only problem is to find the stuff. Right now, there is a small link after the electro-communities site, to a separate system.
Hans
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
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
participants (6)
-
David Rush
-
Hans Aberg
-
Kassen
-
Michael Heuer
-
Robert Poor
-
Stefan Blixt