Re: [PD] number to fractions external?

2012-02-11 Thread Mathieu Bouchard

Le 2011-12-18 à 12:51:00, Alexandre Torres Porres a écrit :

I will take care of that after february, when I finish up my thesis. Can 
I count on you to help me revise it?


Sorry, I meant to say : « Yes ».

 __
| Mathieu BOUCHARD - téléphone : +1.514.383.3801 - Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-18 Thread Alexandre Torres Porres
I will take care of that after february, when I finish up my thesis. Can I
count on you to help me revise it?

thanks
alex

2011/12/18 Mathieu Bouchard ma...@artengine.ca

 Le 2011-12-18 à 02:42:00, Alexandre Torres Porres a écrit :


  by the way, you guys rock :-)


 So, btw, where can people download the psprofile externals ?


  __**__**
 __
 | Mathieu BOUCHARD - téléphone : +1.514.383.3801 - Montréal, QC

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-17 Thread Mike Moser-Booth
The one I posted earlier apparently can run into stack overflows. I
think this version fixes it.

.mmb

On Fri, Dec 16, 2011 at 9:30 PM, Mike Moser-Booth mmoserbo...@gmail.com wrote:
 I just gave this a go, and here's what I have so far based on the
 Wikipedia link Claude gave. Send the decimal through the left inlet,
 and it outputs the numerator and denominator as a list. The argument
 is the maximum value the denominator is allowed to be, which keeps it
 from going crazy trying to figure out irrational numbers and also
 seems to make up for some floating-points errors. You can change the
 max with the right inlet as well. Right now it defaults to 100, but
 that may be too low. Higher values=more accurate, but potentially more
 computation.

 I haven't implemented the rules for decrementing the last value of the
 continuous fractions, so it's not perfect. But it does give 355/113
 for pi. :-)

 .mmb

 On Fri, Dec 16, 2011 at 2:46 PM, Jonathan Wilkes jancs...@yahoo.com wrote:

 From: i go bananas hard@gmail.com
To: Ludwig Maes ludwig.m...@gmail.com
Cc: pd-list@iem.at
Sent: Friday, December 16, 2011 1:16 PM
Subject: Re: [PD] number to fractions external?


if you had read the thread, you would have seen that claude posted a link to 
that technique.

now go and make a PD patch that does it, mr smart guy.


 Wow, how much cpu does that take in Python?  I tried this approach in the 
 form

 of an abstraction, with a nested until, and worst case it can take as much 
 as a quarter of

 a second to compute with the constants provided below.

 (Pentium Dual-core 2.6gHz in WinXP with 0.43 nightly build)

 -Jonathan






On Sat, Dec 17, 2011 at 3:00 AM, Ludwig Maes ludwig.m...@gmail.com wrote:

If you guys 'd done your math, you'd know there is an ancient algorithm for 
approximating numbers by fractions and its called continued fractions.



On 16 December 2011 18:38, Lorenzo Sutton lorenzofsut...@gmail.com wrote:

On 16/12/11 16:05, Alexandre Torres Porres wrote:

looks like a job for an external

 Not really answering the OP question but something could be done in Python:

def find_frac(num):
   f = float(num)
   last_error = 1000
   best = (0,0)
   for i in xrange(1,1001):
       for j in xrange(1,i+1):
           divide = (float(i) / float (j))
           if divide == f:
               return ((i,j),0)
           err = abs(divide - f)
           if err  last_error:
               best = (i,j)
               last_error = err
   return (best,last_error)

This would try to find the exact fraction or the one with the smallest 
error (trying up to 1000/1000). It would return (numerator, denominator, 
error). Guess it would work well at least up to 100 but only for positive 
numbers... and... not for numbers  1.. and surely it's not optimised etc. 
etc. :)

 find_frac(2)
((2, 1), 0)
 find_frac(1.5)
((3, 2), 0)
 find_frac(1.333)
((4, 3), 0)
 find_frac(2.4)
((12, 5), 0)
 find_frac(2.8)
((14, 5), 0)
 find_frac(2.987654321)
((242, 81), 1.234568003383174e-11)
 find_frac(50.32)
((956, 19), 0.004210526315787888)
 find_frac(50.322)
((956, 19), 0.006210526315790332)
 find_frac(50.4)
((252, 5), 0)
 find_frac(10.33)
((971, 94), 0.00021276595744623705)
 find_frac(10.33)
((31, 3), 0)

Lorenzo.




2011/12/16 i go bananas hard@gmail.com mailto:hard@gmail.com


   actually, i'm not going to do anything more on this.

   i had a look at the articles claude posted, and they went a bit
   far over my head.

   my patch will still work for basic things like 1/4 and 7/8, but i
   wouldn't depend on it working for a serious application.  As you
   first suggested, it's not so simple, and if you read claude's
   articles, you will see that it isn't.

   it's not brain science though, so maybe someone with a bit more
   number understanding can tackle it.



   On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres

   por...@gmail.com mailto:por...@gmail.com wrote:

        i had a go at it

       thanks, I kinda had to go too, but no time... :(

        yeah, my patch only works for rational numbers.

       you know what, I think I asked this before on this list,

       deja'vu

        will have a look at the article / method you posted, claude.

       are you going at it too? :)

       by the way, I meant something like 1.75 becomes 7/4 and not
       3/4, but that is easy to adapt on your patch

       thanks

       cheers



       2011/12/16 i go bananas hard@gmail.com

        mailto:hard@gmail.com


           by the way, here is the method i used:

           first, convert the decimal part to a fraction in the form
           of n/10
           next, find the highest common factor of n and 10
           (using the 'division method' like this:
           http://easycalculation.com/what-is-hcf.php )

           then just divide n and 10 by that factor.

           actually, that means it's accurate to 6

Re: [PD] number to fractions external?

2011-12-17 Thread Mathieu Bouchard

Le 2011-12-16 à 00:52:00, Alexandre Torres Porres a écrit :

Is there an external that converts decimal numbers to fractions, like 
1.5 = 3 / 2 ? I bet it's complicated to do it as a vanilla patch, 
right?


Take the number, subtract its whole part to get something less than 1, 
then invert it to get something bigger than 1, and repeat.


You will get a list of characteristic numbers that can be used to make 
good approximations real quick by doing a+1/(b+1/(c+1/(d+1/(e+etc...


But unlike what this latter formula looks like, you don't even need to 
keep a list containing values a b c d e etc... because there's a simple 
shortcut so that you don't have to start with the innermost parentheses.


http://pt.wikipedia.org/wiki/Fra%C3%A7%C3%A3o_cont%C3%ADnua

 __
| Mathieu BOUCHARD - téléphone : +1.514.383.3801 - Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-17 Thread Mathieu Bouchard

Le 2011-12-17 à 03:44:00, i go bananas a écrit :


how do you get from a continued fraction in the form like this:
[0;1,5,2,2] 
to a fraction in the form like this:

27/32
this patch gets as far as that [0; 1,5,2,2] form.  but i'm still not sure how 
to get further


keep track of the last two fractions and feed that to something like expr.

e.g.
$f1 = element of the list
$f2 = last numerator
$f3 = last denominator
$f4 = next-to-last numerator
$f5 = next-to-last denominator

the number before the semicolon should go with the values 1 0 0 1 to start 
the algorithm (yes, you have to pretend that a denominator is zero, but 
don't worry)


then it would be something like :

[expr $f1*$f2+$f4;
  $f1*$f3+$f5;
  $f2;
  $f3]

and then you take the four outputs and feed them back into expr together 
with the next number in the continued fraction...


the advantage of this, is that you can go left-to-right.

With the more obvious method, you have to go right-to-left, because the 
innermost terms (inside many parentheses) are at the right.


The left-to-right formula is something I learned in Number Theory course 
in fév.2003, but naturally, I had to look it up in Wikipédia in order to 
remember, as I don't use this very often...


Let's try the formula with [0;1,5,2,2] :
0 1 0 0 1 gives 0 1 1 0
1 0 1 1 0 gives 1 1 0 1
5 1 1 0 1 gives 5 6 1 1
2 5 6 1 1 gives 11 13 5 6
2 11 13 5 6 gives 27 32 11 13

looks like it works ! 27 32 appear in the 2nd and 1st outlets.

 __
| Mathieu BOUCHARD - téléphone : +1.514.383.3801 - Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-17 Thread Alexandre Torres Porres
when I change the maximum denominator value results are weird and Pd
freezes.

cheers



2011/12/17 Mike Moser-Booth mmoserbo...@gmail.com

 I just added it to my library on GitHub:

 https://github.com/dotmmb/mmb

 But, yeah, feel free to use it however you want.

 .mmb

 On Sat, Dec 17, 2011 at 2:07 PM, Alexandre Torres Porres
 por...@gmail.com wrote:
  this looks great huh?
 
  I have this pd examples that deal with tuning theory, are you releasing
 this
  somewhere so i can use it?
 
  thanks
  alex
 
 
  2011/12/17 Mike Moser-Booth mmoserbo...@gmail.com
 
  They're not working? Huh... Well, here's the text versions:
 
  dec2frac.mmb.pd:
 
  #N canvas 60 22 908 750 10;
  #X obj 298 36 inlet;
  #X obj 573 359 t l;
  #X obj 240 574 list;
  #X obj 198 415 sel 0;
  #X obj 207 168 expr 1/$f1;
  #X obj 478 359 list append;
  #N canvas 203 22 687 744 simplify 0;
  #X obj 144 28 inlet;
  #X obj 198 155 list length;
  #X obj 145 132 t l l;
  #X obj 165 214 spigot;
  #X obj 51 239 spigot;
  #X obj 84 213 == 1;
  #X obj 205 275 list split 2;
  #X obj 98 423 pack f f;
  #X obj 272 371 list split 1;
  #X obj 237 340 list;
  #X obj 198 188  1;
  #X obj 98 377 expr $f2*$f1+1 \; $f1;
  #X obj 305 513 list append;
  #X obj 305 541 expr $f1*$f2+$f3 \; $f2;
  #X obj 307 589 pack f f;
  #X obj 229 423 t b l;
  #X obj 226 631 list;
  #X obj 97 448 t l l;
  #X obj 102 687 outlet;
  #X text 206 80 converts the continued fraction form into a simple
 fraction
  ;
  #X connect 0 0 2 0;
  #X connect 1 0 5 0;
  #X connect 1 0 10 0;
  #X connect 2 0 3 0;
  #X connect 2 0 4 0;
  #X connect 2 1 1 0;
  #X connect 3 0 6 0;
  #X connect 4 0 18 0;
  #X connect 5 0 4 1;
  #X connect 6 0 11 0;
  #X connect 6 1 9 1;
  #X connect 7 0 17 0;
  #X connect 8 0 12 0;
  #X connect 8 1 9 1;
  #X connect 8 2 16 0;
  #X connect 9 0 8 0;
  #X connect 10 0 3 1;
  #X connect 11 0 7 0;
  #X connect 11 1 7 1;
  #X connect 12 0 13 0;
  #X connect 13 0 14 0;
  #X connect 13 1 14 1;
  #X connect 14 0 15 0;
  #X connect 15 0 9 0;
  #X connect 15 1 16 1;
  #X connect 15 1 12 1;
  #X connect 16 0 18 0;
  #X connect 17 0 15 0;
  #X connect 17 1 12 1;
  #X restore 478 385 pd simplify;
  #X obj 325 713 outlet;
  #X obj 368 630 list;
  #X obj 479 411 t l l;
  #X obj 596 577 sel 1;
  #X obj 281 348 spigot;
  #X msg 336 349 0;
  #X obj 281 372 t f b;
  #X obj 505 438 list split 1;
  #X obj 535 469 route bang;
  #X msg 333 382 1;
  #X text 41 573 This is just here for debugging;
  #X obj 634 406 loadbang;
  #X obj 634 427 f \$1;
  #X text 612 683 .mmb;
  #X text 638 625 TODO: implement decrementing rules;
  #X obj 102 674 prepend set;
  #X obj 300 210 expr if($f10 \, int($f1-1) \, int($f1)) \; $f1;
  #X obj 310 268 expr $f2-$f1 \; $f1;
  #X text 533 211 floor;
  #X obj 628 36 inlet;
  #X obj 628 123 max 1;
  #X obj 596 556  1000;
  #X obj 298 100 t b b f b;
  #N canvas 0 22 450 300 test.if.integer 0;
  #X obj 206 117 expr int($f1)==$f1;
  #X obj 151 28 inlet;
  #X obj 151 64 t f f;
  #X obj 129 186 spigot;
  #X obj 179 186 spigot;
  #X obj 164 160 != 1;
  #X obj 129 242 outlet;
  #X obj 179 242 outlet;
  #X msg 179 214 \$1 1;
  #X connect 0 0 4 1;
  #X connect 0 0 5 0;
  #X connect 1 0 2 0;
  #X connect 2 0 3 0;
  #X connect 2 0 4 0;
  #X connect 2 1 0 0;
  #X connect 3 0 6 0;
  #X connect 4 0 8 0;
  #X connect 5 0 3 1;
  #X connect 8 0 7 0;
  #X restore 298 76 pd test.if.integer;
  #X obj 403 111 s \$0-to.outlet;
  #X obj 395 671 r \$0-to.outlet;
  #X msg 101 698;
  #X obj 634 452 max 1;
  #X obj 306 157 until;
  #X obj 335 134 r \$0-stop.until;
  #X obj 306 183 f;
  #X obj 127 483 s \$0-stop.until;
  #X obj 595 604 s \$0-stop.until;
  #X connect 0 0 30 0;
  #X connect 1 0 5 1;
  #X connect 2 0 22 0;
  #X connect 3 0 8 0;
  #X connect 3 0 38 0;
  #X connect 3 1 4 0;
  #X connect 4 0 23 0;
  #X connect 5 0 1 0;
  #X connect 5 0 2 1;
  #X connect 5 0 6 0;
  #X connect 6 0 9 0;
  #X connect 8 0 7 0;
  #X connect 9 0 8 1;
  #X connect 9 1 14 0;
  #X connect 10 0 8 0;
  #X connect 10 0 39 0;
  #X connect 10 1 16 0;
  #X connect 11 0 13 0;
  #X connect 12 0 11 1;
  #X connect 13 0 3 0;
  #X connect 13 1 12 0;
  #X connect 14 1 15 0;
  #X connect 15 0 16 0;
  #X connect 15 1 28 0;
  #X connect 16 0 11 1;
  #X connect 18 0 19 0;
  #X connect 19 0 34 0;
  #X connect 22 0 33 0;
  #X connect 23 0 24 0;
  #X connect 23 1 24 1;
  #X connect 24 0 11 0;
  #X connect 24 1 5 0;
  #X connect 26 0 27 0;
  #X connect 27 0 10 1;
  #X connect 28 0 10 0;
  #X connect 29 0 2 0;
  #X connect 29 1 35 0;
  #X connect 29 2 37 1;
  #X connect 29 3 5 1;
  #X connect 29 3 8 1;
  #X connect 30 0 29 0;
  #X connect 30 1 31 0;
  #X connect 32 0 7 0;
  #X connect 34 0 28 1;
  #X connect 35 0 37 0;
  #X connect 36 0 35 1;
  #X connect 37 0 23 0;
 
 
 
 
  dec2frac.mmb-help.pd:
 
  #N canvas 431 22 944 500 10;
  #X obj 25 12 cnv 15 400 35 empty empty dec2frac.mmb 20 12 0 14 -4160
  -203904 0;
  #X obj 25 48 cnv 15 400 70 empty empty empty 20 12 0 14 -203904 -66577
  0;
  #X text 812 417 .mmb;
  #X 

Re: [PD] number to fractions external?

2011-12-17 Thread Mike Moser-Booth
Oops, the right inlet was connected to a [sel] when it should have
been connected to [ 1000]. I'll upload the fix here and on GitHub.

.mmb

On Sat, Dec 17, 2011 at 7:57 PM, Alexandre Torres Porres
por...@gmail.com wrote:
 when I change the maximum denominator value results are weird and Pd
 freezes.

 cheers



 2011/12/17 Mike Moser-Booth mmoserbo...@gmail.com

 I just added it to my library on GitHub:

 https://github.com/dotmmb/mmb

 But, yeah, feel free to use it however you want.

 .mmb

 On Sat, Dec 17, 2011 at 2:07 PM, Alexandre Torres Porres
 por...@gmail.com wrote:
  this looks great huh?
 
  I have this pd examples that deal with tuning theory, are you releasing
  this
  somewhere so i can use it?
 
  thanks
  alex
 
 
  2011/12/17 Mike Moser-Booth mmoserbo...@gmail.com
 
  They're not working? Huh... Well, here's the text versions:
 
  dec2frac.mmb.pd:
 
  #N canvas 60 22 908 750 10;
  #X obj 298 36 inlet;
  #X obj 573 359 t l;
  #X obj 240 574 list;
  #X obj 198 415 sel 0;
  #X obj 207 168 expr 1/$f1;
  #X obj 478 359 list append;
  #N canvas 203 22 687 744 simplify 0;
  #X obj 144 28 inlet;
  #X obj 198 155 list length;
  #X obj 145 132 t l l;
  #X obj 165 214 spigot;
  #X obj 51 239 spigot;
  #X obj 84 213 == 1;
  #X obj 205 275 list split 2;
  #X obj 98 423 pack f f;
  #X obj 272 371 list split 1;
  #X obj 237 340 list;
  #X obj 198 188  1;
  #X obj 98 377 expr $f2*$f1+1 \; $f1;
  #X obj 305 513 list append;
  #X obj 305 541 expr $f1*$f2+$f3 \; $f2;
  #X obj 307 589 pack f f;
  #X obj 229 423 t b l;
  #X obj 226 631 list;
  #X obj 97 448 t l l;
  #X obj 102 687 outlet;
  #X text 206 80 converts the continued fraction form into a simple
  fraction
  ;
  #X connect 0 0 2 0;
  #X connect 1 0 5 0;
  #X connect 1 0 10 0;
  #X connect 2 0 3 0;
  #X connect 2 0 4 0;
  #X connect 2 1 1 0;
  #X connect 3 0 6 0;
  #X connect 4 0 18 0;
  #X connect 5 0 4 1;
  #X connect 6 0 11 0;
  #X connect 6 1 9 1;
  #X connect 7 0 17 0;
  #X connect 8 0 12 0;
  #X connect 8 1 9 1;
  #X connect 8 2 16 0;
  #X connect 9 0 8 0;
  #X connect 10 0 3 1;
  #X connect 11 0 7 0;
  #X connect 11 1 7 1;
  #X connect 12 0 13 0;
  #X connect 13 0 14 0;
  #X connect 13 1 14 1;
  #X connect 14 0 15 0;
  #X connect 15 0 9 0;
  #X connect 15 1 16 1;
  #X connect 15 1 12 1;
  #X connect 16 0 18 0;
  #X connect 17 0 15 0;
  #X connect 17 1 12 1;
  #X restore 478 385 pd simplify;
  #X obj 325 713 outlet;
  #X obj 368 630 list;
  #X obj 479 411 t l l;
  #X obj 596 577 sel 1;
  #X obj 281 348 spigot;
  #X msg 336 349 0;
  #X obj 281 372 t f b;
  #X obj 505 438 list split 1;
  #X obj 535 469 route bang;
  #X msg 333 382 1;
  #X text 41 573 This is just here for debugging;
  #X obj 634 406 loadbang;
  #X obj 634 427 f \$1;
  #X text 612 683 .mmb;
  #X text 638 625 TODO: implement decrementing rules;
  #X obj 102 674 prepend set;
  #X obj 300 210 expr if($f10 \, int($f1-1) \, int($f1)) \; $f1;
  #X obj 310 268 expr $f2-$f1 \; $f1;
  #X text 533 211 floor;
  #X obj 628 36 inlet;
  #X obj 628 123 max 1;
  #X obj 596 556  1000;
  #X obj 298 100 t b b f b;
  #N canvas 0 22 450 300 test.if.integer 0;
  #X obj 206 117 expr int($f1)==$f1;
  #X obj 151 28 inlet;
  #X obj 151 64 t f f;
  #X obj 129 186 spigot;
  #X obj 179 186 spigot;
  #X obj 164 160 != 1;
  #X obj 129 242 outlet;
  #X obj 179 242 outlet;
  #X msg 179 214 \$1 1;
  #X connect 0 0 4 1;
  #X connect 0 0 5 0;
  #X connect 1 0 2 0;
  #X connect 2 0 3 0;
  #X connect 2 0 4 0;
  #X connect 2 1 0 0;
  #X connect 3 0 6 0;
  #X connect 4 0 8 0;
  #X connect 5 0 3 1;
  #X connect 8 0 7 0;
  #X restore 298 76 pd test.if.integer;
  #X obj 403 111 s \$0-to.outlet;
  #X obj 395 671 r \$0-to.outlet;
  #X msg 101 698;
  #X obj 634 452 max 1;
  #X obj 306 157 until;
  #X obj 335 134 r \$0-stop.until;
  #X obj 306 183 f;
  #X obj 127 483 s \$0-stop.until;
  #X obj 595 604 s \$0-stop.until;
  #X connect 0 0 30 0;
  #X connect 1 0 5 1;
  #X connect 2 0 22 0;
  #X connect 3 0 8 0;
  #X connect 3 0 38 0;
  #X connect 3 1 4 0;
  #X connect 4 0 23 0;
  #X connect 5 0 1 0;
  #X connect 5 0 2 1;
  #X connect 5 0 6 0;
  #X connect 6 0 9 0;
  #X connect 8 0 7 0;
  #X connect 9 0 8 1;
  #X connect 9 1 14 0;
  #X connect 10 0 8 0;
  #X connect 10 0 39 0;
  #X connect 10 1 16 0;
  #X connect 11 0 13 0;
  #X connect 12 0 11 1;
  #X connect 13 0 3 0;
  #X connect 13 1 12 0;
  #X connect 14 1 15 0;
  #X connect 15 0 16 0;
  #X connect 15 1 28 0;
  #X connect 16 0 11 1;
  #X connect 18 0 19 0;
  #X connect 19 0 34 0;
  #X connect 22 0 33 0;
  #X connect 23 0 24 0;
  #X connect 23 1 24 1;
  #X connect 24 0 11 0;
  #X connect 24 1 5 0;
  #X connect 26 0 27 0;
  #X connect 27 0 10 1;
  #X connect 28 0 10 0;
  #X connect 29 0 2 0;
  #X connect 29 1 35 0;
  #X connect 29 2 37 1;
  #X connect 29 3 5 1;
  #X connect 29 3 8 1;
  #X connect 30 0 29 0;
  #X connect 30 1 31 0;
  #X connect 32 0 7 0;
  #X connect 34 0 28 1;
  #X connect 35 0 37 0;
  #X connect 36 0 35 1;
  #X connect 37 0 23 0;
 
 
 
 
  dec2frac.mmb-help.pd:

Re: [PD] number to fractions external?

2011-12-17 Thread Alexandre Torres Porres
i kinda figured that


2011/12/17 Mike Moser-Booth mmoserbo...@gmail.com

 Oops, the right inlet was connected to a [sel] when it should have
 been connected to [ 1000]. I'll upload the fix here and on GitHub.

 .mmb

 On Sat, Dec 17, 2011 at 7:57 PM, Alexandre Torres Porres
 por...@gmail.com wrote:
  when I change the maximum denominator value results are weird and Pd
  freezes.
 
  cheers
 
 
 
  2011/12/17 Mike Moser-Booth mmoserbo...@gmail.com
 
  I just added it to my library on GitHub:
 
  https://github.com/dotmmb/mmb
 
  But, yeah, feel free to use it however you want.
 
  .mmb
 
  On Sat, Dec 17, 2011 at 2:07 PM, Alexandre Torres Porres
  por...@gmail.com wrote:
   this looks great huh?
  
   I have this pd examples that deal with tuning theory, are you
 releasing
   this
   somewhere so i can use it?
  
   thanks
   alex
  
  
   2011/12/17 Mike Moser-Booth mmoserbo...@gmail.com
  
   They're not working? Huh... Well, here's the text versions:
  
   dec2frac.mmb.pd:
  
   #N canvas 60 22 908 750 10;
   #X obj 298 36 inlet;
   #X obj 573 359 t l;
   #X obj 240 574 list;
   #X obj 198 415 sel 0;
   #X obj 207 168 expr 1/$f1;
   #X obj 478 359 list append;
   #N canvas 203 22 687 744 simplify 0;
   #X obj 144 28 inlet;
   #X obj 198 155 list length;
   #X obj 145 132 t l l;
   #X obj 165 214 spigot;
   #X obj 51 239 spigot;
   #X obj 84 213 == 1;
   #X obj 205 275 list split 2;
   #X obj 98 423 pack f f;
   #X obj 272 371 list split 1;
   #X obj 237 340 list;
   #X obj 198 188  1;
   #X obj 98 377 expr $f2*$f1+1 \; $f1;
   #X obj 305 513 list append;
   #X obj 305 541 expr $f1*$f2+$f3 \; $f2;
   #X obj 307 589 pack f f;
   #X obj 229 423 t b l;
   #X obj 226 631 list;
   #X obj 97 448 t l l;
   #X obj 102 687 outlet;
   #X text 206 80 converts the continued fraction form into a simple
   fraction
   ;
   #X connect 0 0 2 0;
   #X connect 1 0 5 0;
   #X connect 1 0 10 0;
   #X connect 2 0 3 0;
   #X connect 2 0 4 0;
   #X connect 2 1 1 0;
   #X connect 3 0 6 0;
   #X connect 4 0 18 0;
   #X connect 5 0 4 1;
   #X connect 6 0 11 0;
   #X connect 6 1 9 1;
   #X connect 7 0 17 0;
   #X connect 8 0 12 0;
   #X connect 8 1 9 1;
   #X connect 8 2 16 0;
   #X connect 9 0 8 0;
   #X connect 10 0 3 1;
   #X connect 11 0 7 0;
   #X connect 11 1 7 1;
   #X connect 12 0 13 0;
   #X connect 13 0 14 0;
   #X connect 13 1 14 1;
   #X connect 14 0 15 0;
   #X connect 15 0 9 0;
   #X connect 15 1 16 1;
   #X connect 15 1 12 1;
   #X connect 16 0 18 0;
   #X connect 17 0 15 0;
   #X connect 17 1 12 1;
   #X restore 478 385 pd simplify;
   #X obj 325 713 outlet;
   #X obj 368 630 list;
   #X obj 479 411 t l l;
   #X obj 596 577 sel 1;
   #X obj 281 348 spigot;
   #X msg 336 349 0;
   #X obj 281 372 t f b;
   #X obj 505 438 list split 1;
   #X obj 535 469 route bang;
   #X msg 333 382 1;
   #X text 41 573 This is just here for debugging;
   #X obj 634 406 loadbang;
   #X obj 634 427 f \$1;
   #X text 612 683 .mmb;
   #X text 638 625 TODO: implement decrementing rules;
   #X obj 102 674 prepend set;
   #X obj 300 210 expr if($f10 \, int($f1-1) \, int($f1)) \; $f1;
   #X obj 310 268 expr $f2-$f1 \; $f1;
   #X text 533 211 floor;
   #X obj 628 36 inlet;
   #X obj 628 123 max 1;
   #X obj 596 556  1000;
   #X obj 298 100 t b b f b;
   #N canvas 0 22 450 300 test.if.integer 0;
   #X obj 206 117 expr int($f1)==$f1;
   #X obj 151 28 inlet;
   #X obj 151 64 t f f;
   #X obj 129 186 spigot;
   #X obj 179 186 spigot;
   #X obj 164 160 != 1;
   #X obj 129 242 outlet;
   #X obj 179 242 outlet;
   #X msg 179 214 \$1 1;
   #X connect 0 0 4 1;
   #X connect 0 0 5 0;
   #X connect 1 0 2 0;
   #X connect 2 0 3 0;
   #X connect 2 0 4 0;
   #X connect 2 1 0 0;
   #X connect 3 0 6 0;
   #X connect 4 0 8 0;
   #X connect 5 0 3 1;
   #X connect 8 0 7 0;
   #X restore 298 76 pd test.if.integer;
   #X obj 403 111 s \$0-to.outlet;
   #X obj 395 671 r \$0-to.outlet;
   #X msg 101 698;
   #X obj 634 452 max 1;
   #X obj 306 157 until;
   #X obj 335 134 r \$0-stop.until;
   #X obj 306 183 f;
   #X obj 127 483 s \$0-stop.until;
   #X obj 595 604 s \$0-stop.until;
   #X connect 0 0 30 0;
   #X connect 1 0 5 1;
   #X connect 2 0 22 0;
   #X connect 3 0 8 0;
   #X connect 3 0 38 0;
   #X connect 3 1 4 0;
   #X connect 4 0 23 0;
   #X connect 5 0 1 0;
   #X connect 5 0 2 1;
   #X connect 5 0 6 0;
   #X connect 6 0 9 0;
   #X connect 8 0 7 0;
   #X connect 9 0 8 1;
   #X connect 9 1 14 0;
   #X connect 10 0 8 0;
   #X connect 10 0 39 0;
   #X connect 10 1 16 0;
   #X connect 11 0 13 0;
   #X connect 12 0 11 1;
   #X connect 13 0 3 0;
   #X connect 13 1 12 0;
   #X connect 14 1 15 0;
   #X connect 15 0 16 0;
   #X connect 15 1 28 0;
   #X connect 16 0 11 1;
   #X connect 18 0 19 0;
   #X connect 19 0 34 0;
   #X connect 22 0 33 0;
   #X connect 23 0 24 0;
   #X connect 23 1 24 1;
   #X connect 24 0 11 0;
   #X connect 24 1 5 0;
   #X connect 26 0 27 0;
   #X connect 27 0 10 1;
   #X connect 28 0 10 0;
   #X connect 29 0 2 0;
   #X connect 29 1 35 0;
   

Re: [PD] number to fractions external?

2011-12-17 Thread i go bananas
thanks mattieu!

i got it working, thanks to your great help!

you have no idea how bummed out i was that i couldn't make this work the
other day.


dec-to-frac-help.pd
Description: Binary data


dec-to-frac.pd
Description: Binary data
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-17 Thread Alexandre Torres Porres
cool, but now we have two patches that behave and work the same way?

thanks
Alex

2011/12/18 i go bananas hard@gmail.com

 thanks mattieu!

 i got it working, thanks to your great help!

 you have no idea how bummed out i was that i couldn't make this work the
 other day.

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-17 Thread Alexandre Torres Porres
I mean one from bananas and another from mike, i guess it was clear

2011/12/18 Alexandre Torres Porres por...@gmail.com

 cool, but now we have two patches that behave and work the same way?

 thanks
 Alex


 2011/12/18 i go bananas hard@gmail.com

 thanks mattieu!

 i got it working, thanks to your great help!

 you have no idea how bummed out i was that i couldn't make this work the
 other day.



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-17 Thread Alexandre Torres Porres
by the way, you guys rock :-)


2011/12/18 Alexandre Torres Porres por...@gmail.com

 I mean one from bananas and another from mike, i guess it was clear


 2011/12/18 Alexandre Torres Porres por...@gmail.com

 cool, but now we have two patches that behave and work the same way?

 thanks
 Alex


 2011/12/18 i go bananas hard@gmail.com

 thanks mattieu!

 i got it working, thanks to your great help!

 you have no idea how bummed out i was that i couldn't make this work the
 other day.




___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-17 Thread Mathieu Bouchard

Le 2011-12-16 à 15:51:00, i go bananas a écrit :


(using the 'division method' like this:  
http://easycalculation.com/what-is-hcf.php )


The division method is much more known as Euclid's Algorithm...

And I never saw it named HCF before. Always PGCD in French and GCD in 
English.


By the way, GridFlow has an operator for computing one or many GCD at 
once : [# gcd].


Here's a visualisation of the GCD of all combinations of numbers from 0 to 
255 :


  http://gridflow.ca/gallery/gcd.gif

I made it in fév.2003... it's one of the oldest GridFlow patches ever.

then just divide n and 10 by that factor. actually, that means it's 
accurate to 6 decimal places, i guess.  well...whatever :D


10 means 5 decimal places. A million is 6 decimal places. You can see 
that by looking at how 10, 100, 1000, etc. multiply with each other, and 
also, logarithms in base 10.


 __
| Mathieu BOUCHARD - téléphone : +1.514.383.3801 - Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-17 Thread Mathieu Bouchard

Le 2011-12-18 à 02:42:00, Alexandre Torres Porres a écrit :


by the way, you guys rock :-)


So, btw, where can people download the psprofile externals ?

 __
| Mathieu BOUCHARD - téléphone : +1.514.383.3801 - Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread Claude Heiland-Allen

On 16/12/11 06:51, i go bananas wrote:

by the way, here is the method i used:

first, convert the decimal part to a fraction in the form of n/10
next, find the highest common factor of n and 10
(using the 'division method' like this:
http://easycalculation.com/what-is-hcf.php )

then just divide n and 10 by that factor.


I don't think that method will give happy results for most simple 
fractions.  Plus it's useful to get approximations that are simpler or 
more accurate, like 3 or 22/7 or 355/113 for pi..


Your patch doesn't work very well for me:

input: 1/7
fraction: 2857/2
input: 8/9
fraction: 1/12500
input: 7/11
fraction: 15909/25000
input: 11/17
fraction: 4313.67/.67

(input is $1 $2--[/], so as accurate as floating point is...)


actually, that means it's accurate to 6 decimal places, i guess.


There's a way to get a simple fraction like 1/7 instead of 143/1000 or 
whatever, could be possible to implement in Pd?  (I've not tried.)


[0] 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-Ratio.html#approxRational


[1] 
http://en.wikipedia.org/wiki/Continued_fraction#Best_rational_approximations



well...whatever :D



Claude

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread i go bananas
yeah, my patch only works for rational numbers.

will have a look at the article / method you posted, claude.







On Fri, Dec 16, 2011 at 7:49 PM, Claude Heiland-Allen cla...@goto10.orgwrote:

 On 16/12/11 06:51, i go bananas wrote:

 by the way, here is the method i used:

 first, convert the decimal part to a fraction in the form of n/10
 next, find the highest common factor of n and 10
 (using the 'division method' like this:
 http://easycalculation.com/**what-is-hcf.phphttp://easycalculation.com/what-is-hcf.php)

 then just divide n and 10 by that factor.


 I don't think that method will give happy results for most simple
 fractions.  Plus it's useful to get approximations that are simpler or more
 accurate, like 3 or 22/7 or 355/113 for pi..

 Your patch doesn't work very well for me:

 input: 1/7
 fraction: 2857/2
 input: 8/9
 fraction: 1/12500
 input: 7/11
 fraction: 15909/25000
 input: 11/17
 fraction: 4313.67/.67

 (input is $1 $2--[/], so as accurate as floating point is...)


  actually, that means it's accurate to 6 decimal places, i guess.


 There's a way to get a simple fraction like 1/7 instead of 143/1000 or
 whatever, could be possible to implement in Pd?  (I've not tried.)

 [0] http://hackage.haskell.org/**packages/archive/base/latest/**
 doc/html/src/Data-Ratio.html#**approxRationalhttp://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-Ratio.html#approxRational

 [1] http://en.wikipedia.org/wiki/**Continued_fraction#Best_**
 rational_approximationshttp://en.wikipedia.org/wiki/Continued_fraction#Best_rational_approximations

  well...whatever :D



 Claude


 __**_
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management - http://lists.puredata.info/**
 listinfo/pd-list http://lists.puredata.info/listinfo/pd-list

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread i go bananas
sorry, should have said 'finite' numbers.
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread Alexandre Torres Porres
 i had a go at it

thanks, I kinda had to go too, but no time... :(

 yeah, my patch only works for rational numbers.

you know what, I think I asked this before on this list,

deja'vu

 will have a look at the article / method you posted, claude.

are you going at it too? :)

by the way, I meant something like 1.75 becomes 7/4 and not 3/4, but that
is easy to adapt on your patch

thanks

cheers



2011/12/16 i go bananas hard@gmail.com

 by the way, here is the method i used:

 first, convert the decimal part to a fraction in the form of n/10
 next, find the highest common factor of n and 10
 (using the 'division method' like this:
 http://easycalculation.com/what-is-hcf.php )

 then just divide n and 10 by that factor.

 actually, that means it's accurate to 6 decimal places, i guess.
 well...whatever :D

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread i go bananas
actually, i'm not going to do anything more on this.

i had a look at the articles claude posted, and they went a bit far over my
head.

my patch will still work for basic things like 1/4 and 7/8, but i wouldn't
depend on it working for a serious application.  As you first suggested,
it's not so simple, and if you read claude's articles, you will see that it
isn't.

it's not brain science though, so maybe someone with a bit more number
understanding can tackle it.



On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres
por...@gmail.comwrote:

  i had a go at it

 thanks, I kinda had to go too, but no time... :(

  yeah, my patch only works for rational numbers.

 you know what, I think I asked this before on this list,

 deja'vu

  will have a look at the article / method you posted, claude.

 are you going at it too? :)

 by the way, I meant something like 1.75 becomes 7/4 and not 3/4, but that
 is easy to adapt on your patch

 thanks

 cheers



 2011/12/16 i go bananas hard@gmail.com

 by the way, here is the method i used:

 first, convert the decimal part to a fraction in the form of n/10
 next, find the highest common factor of n and 10
 (using the 'division method' like this:
 http://easycalculation.com/what-is-hcf.php )

 then just divide n and 10 by that factor.

 actually, that means it's accurate to 6 decimal places, i guess.
 well...whatever :D



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread Alexandre Torres Porres
looks like a job for an external



2011/12/16 i go bananas hard@gmail.com

 actually, i'm not going to do anything more on this.

 i had a look at the articles claude posted, and they went a bit far over
 my head.

 my patch will still work for basic things like 1/4 and 7/8, but i wouldn't
 depend on it working for a serious application.  As you first suggested,
 it's not so simple, and if you read claude's articles, you will see that it
 isn't.

 it's not brain science though, so maybe someone with a bit more number
 understanding can tackle it.



 On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres 
 por...@gmail.com wrote:

  i had a go at it

 thanks, I kinda had to go too, but no time... :(

  yeah, my patch only works for rational numbers.

 you know what, I think I asked this before on this list,

 deja'vu

  will have a look at the article / method you posted, claude.

 are you going at it too? :)

 by the way, I meant something like 1.75 becomes 7/4 and not 3/4, but that
 is easy to adapt on your patch

 thanks

 cheers



 2011/12/16 i go bananas hard@gmail.com

 by the way, here is the method i used:

 first, convert the decimal part to a fraction in the form of n/10
 next, find the highest common factor of n and 10
 (using the 'division method' like this:
 http://easycalculation.com/what-is-hcf.php )

 then just divide n and 10 by that factor.

 actually, that means it's accurate to 6 decimal places, i guess.
 well...whatever :D




___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread i go bananas
it's possible in vanilla, but the mathematics goes over my head

On Sat, Dec 17, 2011 at 1:05 AM, Alexandre Torres Porres
por...@gmail.comwrote:

 looks like a job for an external



 2011/12/16 i go bananas hard@gmail.com

 actually, i'm not going to do anything more on this.

 i had a look at the articles claude posted, and they went a bit far over
 my head.

 my patch will still work for basic things like 1/4 and 7/8, but i
 wouldn't depend on it working for a serious application.  As you first
 suggested, it's not so simple, and if you read claude's articles, you will
 see that it isn't.

 it's not brain science though, so maybe someone with a bit more number
 understanding can tackle it.



 On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres 
 por...@gmail.com wrote:

  i had a go at it

 thanks, I kinda had to go too, but no time... :(

  yeah, my patch only works for rational numbers.

 you know what, I think I asked this before on this list,

 deja'vu

  will have a look at the article / method you posted, claude.

 are you going at it too? :)

 by the way, I meant something like 1.75 becomes 7/4 and not 3/4, but
 that is easy to adapt on your patch

 thanks

 cheers



 2011/12/16 i go bananas hard@gmail.com

 by the way, here is the method i used:

 first, convert the decimal part to a fraction in the form of n/10
 next, find the highest common factor of n and 10
 (using the 'division method' like this:
 http://easycalculation.com/what-is-hcf.php )

 then just divide n and 10 by that factor.

 actually, that means it's accurate to 6 decimal places, i guess.
 well...whatever :D





___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread Lorenzo Sutton

On 16/12/11 16:05, Alexandre Torres Porres wrote:

looks like a job for an external

Not really answering the OP question but something could be done in Python:

def find_frac(num):
f = float(num)
last_error = 1000
best = (0,0)
for i in xrange(1,1001):
for j in xrange(1,i+1):
divide = (float(i) / float (j))
if divide == f:
return ((i,j),0)
err = abs(divide - f)
if err  last_error:
best = (i,j)
last_error = err
return (best,last_error)

This would try to find the exact fraction or the one with the smallest 
error (trying up to 1000/1000). It would return (numerator, denominator, 
error). Guess it would work well at least up to 100 but only for 
positive numbers... and... not for numbers  1.. and surely it's not 
optimised etc. etc. :)


 find_frac(2)
((2, 1), 0)
 find_frac(1.5)
((3, 2), 0)
 find_frac(1.333)
((4, 3), 0)
 find_frac(2.4)
((12, 5), 0)
 find_frac(2.8)
((14, 5), 0)
 find_frac(2.987654321)
((242, 81), 1.234568003383174e-11)
 find_frac(50.32)
((956, 19), 0.004210526315787888)
 find_frac(50.322)
((956, 19), 0.006210526315790332)
 find_frac(50.4)
((252, 5), 0)
 find_frac(10.33)
((971, 94), 0.00021276595744623705)
 find_frac(10.33)
((31, 3), 0)

Lorenzo.




2011/12/16 i go bananas hard@gmail.com mailto:hard@gmail.com

actually, i'm not going to do anything more on this.

i had a look at the articles claude posted, and they went a bit
far over my head.

my patch will still work for basic things like 1/4 and 7/8, but i
wouldn't depend on it working for a serious application.  As you
first suggested, it's not so simple, and if you read claude's
articles, you will see that it isn't.

it's not brain science though, so maybe someone with a bit more
number understanding can tackle it.



On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres
por...@gmail.com mailto:por...@gmail.com wrote:

 i had a go at it

thanks, I kinda had to go too, but no time... :(

 yeah, my patch only works for rational numbers.

you know what, I think I asked this before on this list,

deja'vu

 will have a look at the article / method you posted, claude.

are you going at it too? :)

by the way, I meant something like 1.75 becomes 7/4 and not
3/4, but that is easy to adapt on your patch

thanks

cheers



2011/12/16 i go bananas hard@gmail.com
mailto:hard@gmail.com

by the way, here is the method i used:

first, convert the decimal part to a fraction in the form
of n/10
next, find the highest common factor of n and 10
(using the 'division method' like this:
http://easycalculation.com/what-is-hcf.php )

then just divide n and 10 by that factor.

actually, that means it's accurate to 6 decimal places, i
guess.  well...whatever :D





___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -  
http://lists.puredata.info/listinfo/pd-list



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread Ludwig Maes
If you guys 'd done your math, you'd know there is an ancient algorithm for
approximating numbers by fractions and its called continued fractions.

On 16 December 2011 18:38, Lorenzo Sutton lorenzofsut...@gmail.com wrote:

 On 16/12/11 16:05, Alexandre Torres Porres wrote:

 looks like a job for an external

 Not really answering the OP question but something could be done in Python:

 def find_frac(num):
f = float(num)
last_error = 1000
best = (0,0)
for i in xrange(1,1001):
for j in xrange(1,i+1):
divide = (float(i) / float (j))
if divide == f:
return ((i,j),0)
err = abs(divide - f)
if err  last_error:
best = (i,j)
last_error = err
return (best,last_error)

 This would try to find the exact fraction or the one with the smallest
 error (trying up to 1000/1000). It would return (numerator, denominator,
 error). Guess it would work well at least up to 100 but only for positive
 numbers... and... not for numbers  1.. and surely it's not optimised etc.
 etc. :)

  find_frac(2)
 ((2, 1), 0)
  find_frac(1.5)
 ((3, 2), 0)
  find_frac(1.**333)
 ((4, 3), 0)
  find_frac(2.4)
 ((12, 5), 0)
  find_frac(2.8)
 ((14, 5), 0)
  find_frac(2.987654321)
 ((242, 81), 1.234568003383174e-11)
  find_frac(50.32)
 ((956, 19), 0.004210526315787888)
  find_frac(50.322)
 ((956, 19), 0.006210526315790332)
  find_frac(50.4)
 ((252, 5), 0)
  find_frac(10.33)
 ((971, 94), 0.00021276595744623705)
  find_frac(10.**33)
 ((31, 3), 0)

 Lorenzo.




 2011/12/16 i go bananas hard@gmail.com mailto:hard@gmail.com


actually, i'm not going to do anything more on this.

i had a look at the articles claude posted, and they went a bit
far over my head.

my patch will still work for basic things like 1/4 and 7/8, but i
wouldn't depend on it working for a serious application.  As you
first suggested, it's not so simple, and if you read claude's
articles, you will see that it isn't.

it's not brain science though, so maybe someone with a bit more
number understanding can tackle it.



On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres
por...@gmail.com mailto:por...@gmail.com wrote:

 i had a go at it

thanks, I kinda had to go too, but no time... :(

 yeah, my patch only works for rational numbers.

you know what, I think I asked this before on this list,

deja'vu

 will have a look at the article / method you posted, claude.

are you going at it too? :)

by the way, I meant something like 1.75 becomes 7/4 and not
3/4, but that is easy to adapt on your patch

thanks

cheers



2011/12/16 i go bananas hard@gmail.com
mailto:hard@gmail.com


by the way, here is the method i used:

first, convert the decimal part to a fraction in the form
of n/10
next, find the highest common factor of n and 10
(using the 'division method' like this:

 http://easycalculation.com/**what-is-hcf.phphttp://easycalculation.com/what-is-hcf.php)

then just divide n and 10 by that factor.

actually, that means it's accurate to 6 decimal places, i
guess.  well...whatever :D





 __**_
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -  http://lists.puredata.info/**
 listinfo/pd-list http://lists.puredata.info/listinfo/pd-list



 __**_
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management - http://lists.puredata.info/**
 listinfo/pd-list http://lists.puredata.info/listinfo/pd-list

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread i go bananas
if you had read the thread, you would have seen that claude posted a link
to that technique.

now go and make a PD patch that does it, mr smart guy.



On Sat, Dec 17, 2011 at 3:00 AM, Ludwig Maes ludwig.m...@gmail.com wrote:

 If you guys 'd done your math, you'd know there is an ancient algorithm
 for approximating numbers by fractions and its called continued fractions.


 On 16 December 2011 18:38, Lorenzo Sutton lorenzofsut...@gmail.comwrote:

 On 16/12/11 16:05, Alexandre Torres Porres wrote:

 looks like a job for an external

 Not really answering the OP question but something could be done in
 Python:

 def find_frac(num):
f = float(num)
last_error = 1000
best = (0,0)
for i in xrange(1,1001):
for j in xrange(1,i+1):
divide = (float(i) / float (j))
if divide == f:
return ((i,j),0)
err = abs(divide - f)
if err  last_error:
best = (i,j)
last_error = err
return (best,last_error)

 This would try to find the exact fraction or the one with the smallest
 error (trying up to 1000/1000). It would return (numerator, denominator,
 error). Guess it would work well at least up to 100 but only for positive
 numbers... and... not for numbers  1.. and surely it's not optimised etc.
 etc. :)

  find_frac(2)
 ((2, 1), 0)
  find_frac(1.5)
 ((3, 2), 0)
  find_frac(1.**333)
 ((4, 3), 0)
  find_frac(2.4)
 ((12, 5), 0)
  find_frac(2.8)
 ((14, 5), 0)
  find_frac(2.987654321)
 ((242, 81), 1.234568003383174e-11)
  find_frac(50.32)
 ((956, 19), 0.004210526315787888)
  find_frac(50.322)
 ((956, 19), 0.006210526315790332)
  find_frac(50.4)
 ((252, 5), 0)
  find_frac(10.33)
 ((971, 94), 0.00021276595744623705)
  find_frac(10.**33)
 ((31, 3), 0)

 Lorenzo.




 2011/12/16 i go bananas hard@gmail.com mailto:hard@gmail.com


actually, i'm not going to do anything more on this.

i had a look at the articles claude posted, and they went a bit
far over my head.

my patch will still work for basic things like 1/4 and 7/8, but i
wouldn't depend on it working for a serious application.  As you
first suggested, it's not so simple, and if you read claude's
articles, you will see that it isn't.

it's not brain science though, so maybe someone with a bit more
number understanding can tackle it.



On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres
por...@gmail.com mailto:por...@gmail.com wrote:

 i had a go at it

thanks, I kinda had to go too, but no time... :(

 yeah, my patch only works for rational numbers.

you know what, I think I asked this before on this list,

deja'vu

 will have a look at the article / method you posted, claude.

are you going at it too? :)

by the way, I meant something like 1.75 becomes 7/4 and not
3/4, but that is easy to adapt on your patch

thanks

cheers



2011/12/16 i go bananas hard@gmail.com
mailto:hard@gmail.com


by the way, here is the method i used:

first, convert the decimal part to a fraction in the form
of n/10
next, find the highest common factor of n and 10
(using the 'division method' like this:

 http://easycalculation.com/**what-is-hcf.phphttp://easycalculation.com/what-is-hcf.php)

then just divide n and 10 by that factor.

actually, that means it's accurate to 6 decimal places, i
guess.  well...whatever :D





 __**_
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -  http://lists.puredata.info/**
 listinfo/pd-list http://lists.puredata.info/listinfo/pd-list



 __**_
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management - http://lists.puredata.info/**
 listinfo/pd-list http://lists.puredata.info/listinfo/pd-list



 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -
 http://lists.puredata.info/listinfo/pd-list


___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread i go bananas
how do you get from a continued fraction in the form like this:

[0;1,5,2,2]

to a fraction in the form like this:

27/32

this patch gets as far as that [0; 1,5,2,2] form.  but i'm still not sure
how to get further


continued.pd
Description: Binary data
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread Alexandre Torres Porres
online calculator
http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfCALC.html
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread i go bananas
yes, but it's difficult to embed that in a pd patch, yeah?

On Sat, Dec 17, 2011 at 4:05 AM, Alexandre Torres Porres
por...@gmail.comwrote:

 online calculator
 http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/cfCALC.html

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread Jonathan Wilkes

 From: i go bananas hard@gmail.com
To: Ludwig Maes ludwig.m...@gmail.com 
Cc: pd-list@iem.at 
Sent: Friday, December 16, 2011 1:16 PM
Subject: Re: [PD] number to fractions external?
 

if you had read the thread, you would have seen that claude posted a link to 
that technique.

now go and make a PD patch that does it, mr smart guy.


Wow, how much cpu does that take in Python?  I tried this approach in the form 

of an abstraction, with a nested until, and worst case it can take as much as a 
quarter of 

a second to compute with the constants provided below.

(Pentium Dual-core 2.6gHz in WinXP with 0.43 nightly build)

-Jonathan






On Sat, Dec 17, 2011 at 3:00 AM, Ludwig Maes ludwig.m...@gmail.com wrote:

If you guys 'd done your math, you'd know there is an ancient algorithm for 
approximating numbers by fractions and its called continued fractions.



On 16 December 2011 18:38, Lorenzo Sutton lorenzofsut...@gmail.com wrote:

On 16/12/11 16:05, Alexandre Torres Porres wrote:

looks like a job for an external

Not really answering the OP question but something could be done in Python:

def find_frac(num):
   f = float(num)
   last_error = 1000
   best = (0,0)
   for i in xrange(1,1001):
       for j in xrange(1,i+1):
           divide = (float(i) / float (j))
           if divide == f:
               return ((i,j),0)
           err = abs(divide - f)
           if err  last_error:
               best = (i,j)
               last_error = err
   return (best,last_error)

This would try to find the exact fraction or the one with the smallest error 
(trying up to 1000/1000). It would return (numerator, denominator, error). 
Guess it would work well at least up to 100 but only for positive numbers... 
and... not for numbers  1.. and surely it's not optimised etc. etc. :)

 find_frac(2)
((2, 1), 0)
 find_frac(1.5)
((3, 2), 0)
 find_frac(1.333)
((4, 3), 0)
 find_frac(2.4)
((12, 5), 0)
 find_frac(2.8)
((14, 5), 0)
 find_frac(2.987654321)
((242, 81), 1.234568003383174e-11)
 find_frac(50.32)
((956, 19), 0.004210526315787888)
 find_frac(50.322)
((956, 19), 0.006210526315790332)
 find_frac(50.4)
((252, 5), 0)
 find_frac(10.33)
((971, 94), 0.00021276595744623705)
 find_frac(10.33)
((31, 3), 0)

Lorenzo.




2011/12/16 i go bananas hard@gmail.com mailto:hard@gmail.com


   actually, i'm not going to do anything more on this.

   i had a look at the articles claude posted, and they went a bit
   far over my head.

   my patch will still work for basic things like 1/4 and 7/8, but i
   wouldn't depend on it working for a serious application.  As you
   first suggested, it's not so simple, and if you read claude's
   articles, you will see that it isn't.

   it's not brain science though, so maybe someone with a bit more
   number understanding can tackle it.



   On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres

   por...@gmail.com mailto:por...@gmail.com wrote:

        i had a go at it

       thanks, I kinda had to go too, but no time... :(

        yeah, my patch only works for rational numbers.

       you know what, I think I asked this before on this list,

       deja'vu

        will have a look at the article / method you posted, claude.

       are you going at it too? :)

       by the way, I meant something like 1.75 becomes 7/4 and not
       3/4, but that is easy to adapt on your patch

       thanks

       cheers



       2011/12/16 i go bananas hard@gmail.com

       mailto:hard@gmail.com


           by the way, here is the method i used:

           first, convert the decimal part to a fraction in the form
           of n/10
           next, find the highest common factor of n and 10
           (using the 'division method' like this:
           http://easycalculation.com/what-is-hcf.php )

           then just divide n and 10 by that factor.

           actually, that means it's accurate to 6 decimal places, i
           guess.  well...whatever :D






___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -  
http://lists.puredata.info/listinfo/pd-list



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list




___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-16 Thread Mike Moser-Booth
I just gave this a go, and here's what I have so far based on the
Wikipedia link Claude gave. Send the decimal through the left inlet,
and it outputs the numerator and denominator as a list. The argument
is the maximum value the denominator is allowed to be, which keeps it
from going crazy trying to figure out irrational numbers and also
seems to make up for some floating-points errors. You can change the
max with the right inlet as well. Right now it defaults to 100, but
that may be too low. Higher values=more accurate, but potentially more
computation.

I haven't implemented the rules for decrementing the last value of the
continuous fractions, so it's not perfect. But it does give 355/113
for pi. :-)

.mmb

On Fri, Dec 16, 2011 at 2:46 PM, Jonathan Wilkes jancs...@yahoo.com wrote:

 From: i go bananas hard@gmail.com
To: Ludwig Maes ludwig.m...@gmail.com
Cc: pd-list@iem.at
Sent: Friday, December 16, 2011 1:16 PM
Subject: Re: [PD] number to fractions external?


if you had read the thread, you would have seen that claude posted a link to 
that technique.

now go and make a PD patch that does it, mr smart guy.


 Wow, how much cpu does that take in Python?  I tried this approach in the form

 of an abstraction, with a nested until, and worst case it can take as much as 
 a quarter of

 a second to compute with the constants provided below.

 (Pentium Dual-core 2.6gHz in WinXP with 0.43 nightly build)

 -Jonathan






On Sat, Dec 17, 2011 at 3:00 AM, Ludwig Maes ludwig.m...@gmail.com wrote:

If you guys 'd done your math, you'd know there is an ancient algorithm for 
approximating numbers by fractions and its called continued fractions.



On 16 December 2011 18:38, Lorenzo Sutton lorenzofsut...@gmail.com wrote:

On 16/12/11 16:05, Alexandre Torres Porres wrote:

looks like a job for an external

 Not really answering the OP question but something could be done in Python:

def find_frac(num):
   f = float(num)
   last_error = 1000
   best = (0,0)
   for i in xrange(1,1001):
       for j in xrange(1,i+1):
           divide = (float(i) / float (j))
           if divide == f:
               return ((i,j),0)
           err = abs(divide - f)
           if err  last_error:
               best = (i,j)
               last_error = err
   return (best,last_error)

This would try to find the exact fraction or the one with the smallest 
error (trying up to 1000/1000). It would return (numerator, denominator, 
error). Guess it would work well at least up to 100 but only for positive 
numbers... and... not for numbers  1.. and surely it's not optimised etc. 
etc. :)

 find_frac(2)
((2, 1), 0)
 find_frac(1.5)
((3, 2), 0)
 find_frac(1.333)
((4, 3), 0)
 find_frac(2.4)
((12, 5), 0)
 find_frac(2.8)
((14, 5), 0)
 find_frac(2.987654321)
((242, 81), 1.234568003383174e-11)
 find_frac(50.32)
((956, 19), 0.004210526315787888)
 find_frac(50.322)
((956, 19), 0.006210526315790332)
 find_frac(50.4)
((252, 5), 0)
 find_frac(10.33)
((971, 94), 0.00021276595744623705)
 find_frac(10.33)
((31, 3), 0)

Lorenzo.




2011/12/16 i go bananas hard@gmail.com mailto:hard@gmail.com


   actually, i'm not going to do anything more on this.

   i had a look at the articles claude posted, and they went a bit
   far over my head.

   my patch will still work for basic things like 1/4 and 7/8, but i
   wouldn't depend on it working for a serious application.  As you
   first suggested, it's not so simple, and if you read claude's
   articles, you will see that it isn't.

   it's not brain science though, so maybe someone with a bit more
   number understanding can tackle it.



   On Sat, Dec 17, 2011 at 12:51 AM, Alexandre Torres Porres

   por...@gmail.com mailto:por...@gmail.com wrote:

        i had a go at it

       thanks, I kinda had to go too, but no time... :(

        yeah, my patch only works for rational numbers.

       you know what, I think I asked this before on this list,

       deja'vu

        will have a look at the article / method you posted, claude.

       are you going at it too? :)

       by the way, I meant something like 1.75 becomes 7/4 and not
       3/4, but that is easy to adapt on your patch

       thanks

       cheers



       2011/12/16 i go bananas hard@gmail.com

        mailto:hard@gmail.com


           by the way, here is the method i used:

           first, convert the decimal part to a fraction in the form
           of n/10
           next, find the highest common factor of n and 10
           (using the 'division method' like this:
           http://easycalculation.com/what-is-hcf.php )

           then just divide n and 10 by that factor.

           actually, that means it's accurate to 6 decimal places, i
           guess.  well...whatever :D






___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -  
http://lists.puredata.info

[PD] number to fractions external?

2011-12-15 Thread Alexandre Torres Porres
hi there,

Is there an external that converts decimal numbers to fractions, like 1.5
= 3 / 2 ?

I bet it's complicated to do it as a vanilla patch, right?

thanks
alex
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-15 Thread i go bananas
i had a go at it.  This one converts up to 5 decimal places (you could
probably mod it to do more, but then you get pretty close to the limits of
float-based arithmetic, i think).

i was getting glitches, because of the known issue where 58/1000 comes out
as 57.9..  , so i have just added a tiny amount to each number to stop
this.

also, the one i have done here splits a number into whole and fractional
parts, but it would be trivial to multiply the whole by the denominator to
express the number as a vulgar fraction (3/2, etc)






On Fri, Dec 16, 2011 at 11:52 AM, Alexandre Torres Porres
por...@gmail.comwrote:

 hi there,

 Is there an external that converts decimal numbers to fractions, like 1.5
 = 3 / 2 ?

 I bet it's complicated to do it as a vanilla patch, right?

 thanks
 alex

 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -
 http://lists.puredata.info/listinfo/pd-list




dec2frac.pd
Description: Binary data


dec2frac-help.pd
Description: Binary data
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] number to fractions external?

2011-12-15 Thread i go bananas
by the way, here is the method i used:

first, convert the decimal part to a fraction in the form of n/10
next, find the highest common factor of n and 10
(using the 'division method' like this:
http://easycalculation.com/what-is-hcf.php )

then just divide n and 10 by that factor.

actually, that means it's accurate to 6 decimal places, i guess.
well...whatever :D
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list