Forums > MaxMSP

Anyone dare to tackle a stack overflow problem?

June 29, 2007 | 2:59 am

I have a prime factorization patch that seems to work fine up until prime number 239. I have no freaking clue why it generates a stack overflow at that point, all composite and prime numbers below that are totally fine. Prime numbers over 256 seem to crash Max even more thoroughly, which might make more sense, though I’m not using any objects with that limitation (zl, yes, but it’s used to read the length of the prime factor list, nowhere ever near 256).

The subpatch with the factorization seems to be totally OK (though messy) and I can’t figure out why it would overflow at this specific point. I figured (with enough numbers in the counter as possible prime factors) that any number would be OK to factor (with the counter range up to the square root of the main number).

Yes, I *do* have a javascript that factors any number just fine, but I wanted to try and figure it all out in Max. Maybe not the best idea as it’s taken a long time, but it would be nice to understand what’s causing the overflow if anyone has some ideas. Also wondering if others get the same overflow error at the same point (239).

There’s a warning next to the overflow-causing number, so be careful. ;)

-CJ

————————-

max v2;
#N vpatcher 13 73 1222 868;
#P origin -94 -167;
#P window setfont "Arial Black" 14.;
#P window linecount 1;
#P comment 10 261 97 9568270 look inside;
#P comment 468 54 193 9568270 Automation speed;
#P comment 292 53 97 9568270 Automation;
#P window setfont "Sans Serif" 18.;
#P window linecount 2;
#P comment 119 190 441 9109522 WARNING: Stack overflow at 239 and higher primes. Above ~255 , bigger crashes. What’s up ?!?;
#P inlet 1 23 15 0;
#P user multiSlider 321 80 437 28 0. 127. 1 2664 47 0 2 5 0 0 0;
#M frgb 9 255 227;
#M brgb 0 0 0;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P hidden message 668 50 38 9109518 500;
#P window linecount 3;
#P comment 953 272 215 9109518 Can you find the dropdown that uses prime number 23? (#8: for what value? 92);
#P comment 955 210 215 9109518 Can you find the dropdown that uses prime number 11? (#9: for what value? 99);
#P window setfont "Sans Serif" 24.;
#P user ubumenu 616 149 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 9;
#X add 18;
#X add 27;
#X add 36;
#X add 45;
#X add 54;
#X add 63;
#X add 72;
#X add 81;
#X add 90;
#X add 99;
#X prefix_set 0 0 0;
#P user ubumenu 539 150 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 8;
#X add 16;
#X add 24;
#X add 32;
#X add 40;
#X add 48;
#X add 56;
#X add 64;
#X add 72;
#X add 80;
#X add 92;
#X add 96;
#X prefix_set 0 0
0;
#P window setfont "Sans Serif" 18.;
#P window linecount 1;
#N vpatcher 15 55 615 455;
#P toggle 50 130 15 0;
#P window setfont "Sans Serif" 10.;
#P hidden newex 50 107 123 9109514 route m;
#B color 1;
#P hidden newex 50 78 123 9109514 sprintf %c;
#B color 1;
#P hidden newex 50 50 123 9109514 key;
#B color 1;
#P outlet 50 150 15 0;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 0 0;
#P pop;
#P hidden newobj 542 22 115 9109522 p keys;
#P number 16 34 46 18 1 10 3 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P user led 228 36 17 17 2 150;
#P window setfont "Sans Serif" 24.;
#P user ubumenu 695 148 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 10;
#X add 20;
#X add 30;
#X add 40;
#X add 50;
#X add 60;
#X add 70;
#X add 80;
#X add 90;
#X add 100;
#X prefix_set 0 0
0;
#P user ubumenu 461 150 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 7;
#X add 14;
#X add 21;
#X add 28;
#X add 35;
#X add 42;
#X add 49;
#X add 56;
#X add 63;
#X add 70;
#X add 84;
#X add 98;
#X prefix_set 0 0
0;
#P user ubumenu 389 150 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 6;
#X add 12;
#X add 18;
#X add 24;
#X add 36;
#X add 48;
#X add 60;
#X add 72;
#X add 84;
#X add 96;
#X prefix_set 0 0
0;
#P user ubumenu 317 149 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 5;
#X add 10;
#X add 15;
#X add 20;
#X add 25;
#X add 50;
#X add 75;
#X add 100;
#X prefix_set 0 0
0;
#P user ubumenu 242 149 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 3;
#X add 6;
#X add 9;
#X add 12;
#X add 15;
#X add 18;
#X add 21;
#X add 24;
#X add 30;
#X add 36;
#X add 42;
#X add 48;
#X add 60;
#X prefix_set 0 0
0;
#P window setfont "Sans Serif" 14.;
#N vpatcher 719 51 1272 296;
#P window setfont "Sans Serif" 14.;
#P message 494 114 28 9109518 9;
#P message 463 114 28 9109518 10;
#P outlet 385 204 15 0;
#P message 431 114 28 9109518 11;
#P message 400 114 28 9109518 11;
#P message 369 114 28 9109518 9;
#P message 338 114 28 9109518 7;
#P message 307 114 28 9109518 11;
#P message 276 114 28 9109518 12;
#P message 245 114 28 9109518 3;
#P window setfont "Sans Serif" 10.;
#P newex 219 82 317 9109514 sel 1 2 3 4 5 6 7 8 9 10;
#B color 1;
#P window setfont "Sans Serif" 14.;
#P message 214 114 28 9109518 5;
#P window setfont "Sans Serif" 10.;
#N counter 0 5;
#X flags 0 0;
#P newobj 331 179 90 9109514 counter 0 5;
#B color 1;
#P newex 50 50 123 9109514 metro 500;
#B color 1;
#P inlet 50 30 15 0;
#P inlet 163 30 15 0;
#P inlet 219 62 15 0;
#P inlet 387 146 15 0;
#P inlet 427 146 15 0;
#P outlet 331 204 15 0;
#P connect 5 0 6 0;
#P connect 4 0 6 1;
#P connect 9 0 8 0;
#P connect 3 0 9 0;
#P connect 9 1 10 0;
#P connect 9 2 11 0;
#P connect 9 3 12 0;
#P connect 6 0 7 0;
#P connect 7 0 0 0;
#P connect 9 4 13 0;
#P connect 2 0 7 1;
#P connect 9 5 14 0;
#P connect 7 2 17 0;
#P connect 1 0 7 3;
#P connect 9 6 15 0;
#P connect 16 0 7 4;
#P connect 15 0 7 4;
#P connect 14 0 7 4;
#P connect 13 0 7 4;
#P connect 12 0 7 4;
#P connect 11 0 7 4;
#P connect 10 0 7 4;
#P connect 8 0 7 4;
#P connect 19 0 7 4;
#P connect 18 0 7 4;
#P connect 9 7 16 0;
#P connect 9 8 18 0;
#P connect 9 9 19 0;
#P pop;
#P newobj 74 33 150 9109518 p auto_manager;
#P window setfont "Sans Serif" 10.;
#P hidden newex 137 60 56 9109514 t b i;
#B color 1;
#P window setfont "Sans Serif" 36.;
#P user ubumenu 16 69 58 9109540 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 1;
#X add 2;
#X add 3;
#X add 4;
#X add 5;
#X add 6;
#X add 7;
#X add 8;
#X add 9;
#X add 10;
#X prefix_set 0 0
0;
#P window setfont "Sans Serif" 10.;
#P newex 23 121 686 9109514 gate 10 1;
#B color 1;
#P button 85 80 26 1;
#P window setfont "Sans Serif" 18.;
#P user ubumenu 120 84 96 9109522 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add up;
#X add down;
#X add up / down;
#X prefix_set 0 0
0;
#P user led 267 57 17 17 1 150;
#P window setfont "Sans Serif" 20.;
#P number 242 79 66 20 50 0 1 139 0 242 248 58 58 58 222 222 222 0 0 0;
#P window setfont "Sans Serif" 24.;
#P user ubumenu 165 149 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 2;
#X add 4;
#X add 6;
#X add 8;
#X add 12;
#X add 16;
#X add 24;
#X add 32;
#X add 36;
#X add 48;
#X add 64;
#X add 72;
#X add 96;
#X prefix_set 0 0
0;
#P user ubumenu 88 149 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 3;
#X add 9;
#X add 27;
#X add 81;
#X prefix_set 0 0
0;
#P user ubumenu 17 149 65 9109528 0 1 1 0;
#X setrgb 255 255 255 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add 2;
#X add 4;
#X add 8;
#X add 16;
#X add 32;
#X add 64;
#X prefix_set 0 0
0;
#P window setfont "Sans Serif" 14.;
#P hidden message 847 49 38 9109518 0;
#P hidden message 802 50 38 9109518 1;
#P window setfont "Arial Black" 14.;
#P comment 468 248 97 9568270 Separator;
#P user ubumenu 324 246 138 9568270 0 1 1 0;
#X setrgb 0 248 242 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add none;
#X add multiply;
#X add underscore;
#X add vertical bars;
#X add dashes;
#X prefix_set 0 0
0;
#P comment 180 248 132 9568270 Show factor 1;
#P user led 157 249 17 17 1 150;
#P window setfont "Sans Serif" 14.;
#P hidden message 759 50 38 9109518 4;
#P hidden message 713 49 38 9109518 50;
#P window setfont "Sans Serif" 10.;
#P hidden newex 708 22 123 9109514 loadbang;
#B color 1;
#P window setfont "Sans Serif" 18.;
#P window linecount 2;
#P comment 655 190 247 9109522 Factor Numbers 2 to 100 for final project (safely tested);
#P window linecount 1;
#P comment 726 282 207 9109522 Prime Factorization;
#P window setfont "Sans Serif" 14.;
#P window linecount 3;
#P comment 926 446 194 9109518 Histogram of (up to 6 possible) prime factors for each prime number , 2 to 97;
#P comment 953 151 194 9109518 Which number has the most of a single prime factor? 64 = six Twos.;
#P window setfont "Sans Serif" 18.;
#P window linecount 2;
#P comment 952 96 159 9109522 Questions / learning objectives;
#P number 185 283 66 18 5 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P user led 136 400 17 17 2 150;
#P noclick;
#P user led 106 400 17 17 2 150;
#P noclick;
#P user led 76 400 17 17 2 150;
#P noclick;
#P user led 46 400 17 17 2 150;
#P noclick;
#P window setfont "Sans Serif" 12.;
#P window linecount 4;
#P comment 575 764 574 9109516 CALCULATOR — add and / or multiply using all values in a multislider. Can use scale factor so 2 , 4 , 6 , etc… or specialty lists of numbers. Supply sum , average , other?? ; Display specialty functions like sine , normal distribution , Fibonacci , LOTS OF SERIES!!! graphically , and in other displays (over time , beatbox , saturation level , 3D-depth , etc….etc.;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P hidden message 928 421 90 9109513 candycane $1;
#P window setfont "Sans Serif" 18.;
#P number 929 393 48 18 1 23 3 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P user led 16 400 17 17 2 150;
#P noclick;
#P window setfont "Sans Serif" 10.;
#P hidden newex 825 78 123 9109514 bgcolor 80 80 80;
#B color 1;
#P window setfont "Sans Serif" 14.;
#N vpatcher 62 55 1250 892;
#P window setfont "Sans Serif" 12.;
#P window linecount 0;
#P comment 346 71 155 9109516 Factor list (yes I know there’s redundancy but it’s still plenty fast);
#P window setfont "Sans Serif" 14.;
#P message 949 417 32 9109518 1;
#P toggle 878 422 47 0;
#P newex 933 445 49 9109518 gate;
#B color 1;
#P newex 866 386 60 9109518 sel 1;
#B color 1;
#P newex 367 664 132 9109518 prepend set;
#B color 1;
#P button 254 668 18 1;
#P window setfont "Sans Serif" 12.;
#P comment 375 638 210 9109516 Slice if separator , don’t if "none";
#P comment 469 603 140 9109516 Show factor 1 or not;
#P window setfont "Sans Serif" 14.;
#P message 653 143 32 9109518 1;
#P message 609 143 32 9109518 2;
#P newex 278 636 78 9109518 gate 2;
#B color 1;
#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 686 110 168 9109516 No-separator special control (see below left);
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P newex 632 113 49 9109518 sel 1;
#B color 1;
#P window setfont "Arial Black" 12.;
#P window linecount 3;
#P comment 271 728 374 9568268 If "Show factor 1" is OFF (default) , then slice off last separator for looks (UNLESS "no separators" is chosen). Otherwise just tack on the 1 to finish the display list.;
#B color 3;
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P newex 282 600 42 9109518 + 1;
#B color 1;
#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 689 258 94 9109516 Clear display list outside;
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P newex 331 601 91 9109518 gate 2 1;
#B color 1;
#P newex 279 666 74 9109518 zl ecils 1;
#B color 1;
#P window setfont "Arial Black" 14.;
#P comment 978 207 164 9568270 Histogram list;
#B color 3;
#P window setfont "Arial Black" 12.;
#P window linecount 2;
#P comment 166 371 183 9568268 DONE with factorization , bang lists out;
#P window setfont "Sans Serif" 18.;
#P window linecount 1;
#P message 278 567 293 9109522 2 * 2 *;
#P window setfont "Arial Black" 14.;
#P comment 389 464 169 9568270 Separator options;
#N comlet Add 1 to end of list;
#P outlet 989 618 27 0;
#P window linecount 3;
#P comment 709 649 320 9568270 ACTUAL data list (no separators) , using factor 1 , to determine if prime or not — i.e. , if list length = 2 , then prime.;
#B color 3;
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P message 713 591 92 9109518 append $1;
#P window setfont "Sans Serif" 18.;
#P message 706 617 234 9109522 2 2 1;
#P window setfont "Arial Black" 14.;
#P comment 420 697 208 9568270 Send DISPLAY list out;
#B color 3;
#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 877 165 261 9109516 Uses comma for multi-message-making (histo needs this format);
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P message 421 514 94 9109518 append $1 –;
#P message 418 488 94 9109518 append $1 ||;
#P message 322 514 94 9109518 append $1 _;
#P message 322 488 94 9109518 append $1 *;
#P window setfont "Sans Serif" 12.;
#P comment 716 26 145 9109516 Separator type;
#P inlet 671 24 26 0;
#P window setfont "Sans Serif" 18.;
#P user ubumenu 612 67 135 9109522 0 1 1 0;
#X setrgb 0 248 242 0 0 0 100 98 98 4 4 4 141 141 141 112 112 112;
#X add none;
#X add multiply;
#X add underscore;
#X add vertical bars;
#X add dashes;
#X prefix_set 0 0
0;
#P window setfont "Sans Serif" 14.;
#P newex 277 540 126 9109518 switch 5 1;
#B color 1;
#P window setfont "Sans Serif" 12.;
#P comment 628 354 148 9109516 Show factor 1 at end?;
#P inlet 513 26 26 0;
#P toggle 657 376 47 0;
#P window setfont "Sans Serif" 14.;
#P newex 638 462 49 9109518 gate;
#B color 1;
#P inlet 175 26 26 0;
#P window setfont "Sans Serif" 18.;
#P number 120 28 48 18 5 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 1002 448 132 9109516 Set multislider values to those of histogram;
#P comment 837 579 94 9109516 Reset multislider to 0;
#P window setfont "Sans Serif" 10.;
#P window linecount 1;
#N coll prime_mapping 1;
#T flags 1 0;
#T 1 1;
#T 2 2;
#T 3 3;
#T 5 4;
#T 7 5;
#T 11 6;
#T 13 7;
#T 17 8;
#T 19 9;
#T 23 10;
#T 29 11;
#T 31 12;
#T 37 13;
#T 41 14;
#T 43 15;
#T 47 16;
#T 53 17;
#T 59 18;
#T 61 19;
#T 67 20;
#T 71 21;
#T 73 22;
#T 79 23;
#T 83 24;
#T 89 25;
#T 97 26;
#P newobj 865 360 142 9109514 coll prime_mapping 1;
#B color 1;
#P window setfont "Sans Serif" 14.;
#P message 1029 389 105 9109518 set $1 $2;
#P newex 1029 361 91 9109518 pack 0 0;
#B color 1;
#P message 875 206 94 9109518 append $1 \,;
#P message 875 235 218 9109518 2 , 2 , 1;
#P window setfont "Sans Serif" 18.;
#P number 1031 295 59 18 0 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 872 330 59 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P message 887 262 61 9109518 clear;
#P button 61 435 18 1;
#P button 90 435 18 1;
#P button 119 435 18 1;
#P window setfont "Sans Serif" 18.;
#P newex 872 293 147 9109522 histo;
#P window setfont "Sans Serif" 14.;
#P newex 79 406 80 9109518 t b b b b;
#B color 1;
#P newex 72 62 92 9109518 speedlim 50;
#B color 1;
#P button 56 228 21 1;
#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 33 494 193 9109516 If a prime factor , recurse with same factor until it is not;
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P newex 246 238 80 9109518 t i b b;
#B color 1;
#P message 663 432 94 9109518 append 1;
#P window setfont "Sans Serif" 12.;
#P window linecount 3;
#P comment 346 144 224 9109516 No need to skip 4 , 6 , etc. , they will simply not work once 2 has been exhausted , etc. for other small primes;
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P newex 173 464 51 9109518 t i i;
#B color 1;
#P window setfont "Sans Serif" 18.;
#P number 173 430 48 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 148 435 18 1;
#P window setfont "Sans Serif" 14.;
#P newex 81 378 80 9109518 sel 1;
#B color 1;
#P button 49 320 21 1;
#P window setfont "Sans Serif" 24.;
#P number 81 337 63 24 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 18.;
#P number 82 295 48 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P message 81 257 61 9109518 set $1;
#P newex 84 228 49 9109518 /;
#B color 1;
#P newex 72 92 92 9109518 t i i b b;
#B color 1;
#P button 202 53 29 1;
#P button 265 57 21 1;
#N counter 2 300;
#X flags 0 0;
#P newobj 202 87 138 9109518 counter 2 300;
#B color 1;
#P window setfont "Sans Serif" 18.;
#P number 246 266 48 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 36.;
#P number 387 376 81 36 1 0 1 139 0 0 0 247 1 7 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P message 387 338 61 9109518 set $1;
#B color 1;
#P window setfont "Sans Serif" 20.;
#P number 224 122 68 20 2 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 306 270 21 1;
#P button 177 268 34 1;
#P window setfont "Sans Serif" 14.;
#P message 692 192 61 9109518 set;
#B color 4;
#P message 287 462 94 9109518 append $1;
#P newex 175 237 64 9109518 sel 0;
#B color 1;
#P toggle 171 196 37 0;
#P newex 72 166 260 9109518 if ($i1 % $i2 == 0) then 0 else $i1;
#B color 1;
#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 334 241 200 9109516 If not a prime factor , advance counter to next divisor / modulus;
#P inlet 72 24 35 0;
#N comlet Clear message list;
#P outlet 712 226 27 0;
#N comlet Add factors to list;
#P outlet 382 692 27 0;
#N comlet Reset multislider to 0;
#P outlet 841 547 28 0;
#N comlet Set multislider values;
#P outlet 1029 415 27 0;
#P window setfont "Sans Serif" 14.;
#P window linecount 1;
#P newex 637 80 49 9109518 + 1;
#B color 1;
#P connect 24 0 26 0;
#P connect 14 0 35 0;
#P lcolor 3;
#P connect 37 0 41 0;
#P connect 5 0 36 0;
#P connect 36 0 21 0;
#P connect 30 0 7 0;
#P lcolor 3;
#P connect 21 0 7 0;
#P connect 17 0 7 0;
#P lcolor 3;
#P connect 27 0 37 0;
#P connect 22 0 23 0;
#P connect 24 0 25 0;
#P connect 25 0 27 0;
#P connect 12 0 24 0;
#P connect 23 0 24 0;
#P fasten 30 1 22 0 38 470 38 208;
#P lcolor 3;
#P connect 35 0 22 0;
#P lcolor 3;
#P connect 21 1 22 0;
#P connect 37 1 40 0;
#P connect 37 2 39 0;
#P connect 53 0 52 0;
#P connect 14 0 22 1;
#P connect 37 3 28 0;
#P connect 52 0 36 1;
#P connect 7 0 8 0;
#P connect 27 1 29 0;
#P lcolor 3;
#P connect 29 0 30 0;
#P lcolor 3;
#P connect 8 0 9 0;
#P connect 9 0 12 0;
#P connect 21 2 20 0;
#P connect 33 1 20 0;
#P lcolor 3;
#P connect 20 0 18 0;
#P connect 18 0 14 0;
#P connect 9 1 33 0;
#P lcolor 3;
#P connect 33 0 17 0;
#P lcolor 3;
#P connect 21 3 19 0;
#P connect 19 0 18 2;
#P connect 0 0 58 0;
#P connect 11 0 73 0;
#P lcolor 5;
#P connect 41 0 73 0;
#P connect 58 0 73 0;
#P connect 54 0 73 0;
#P lcolor 2;
#P connect 84 0 83 0;
#P lcolor 2;
#P connect 85 0 83 0;
#P lcolor 2;
#P connect 83 0 76 0;
#P lcolor 2;
#P connect 88 0 76 0;
#P lcolor 5;
#P connect 55 0 79 0;
#P lcolor 2;
#P connect 16 0 10 0;
#P lcolor 2;
#P connect 10 0 58 1;
#P connect 33 2 13 0;
#P lcolor 3;
#P connect 14 0 7 1;
#P connect 16 0 62 0;
#P lcolor 2;
#P connect 16 0 63 0;
#P lcolor 2;
#P connect 62 0 58 2;
#P connect 79 0 77 0;
#P lcolor 2;
#P connect 63 0 58 3;
#P connect 77 0 83 1;
#P lcolor 2;
#P connect 77 1 89 0;
#P lcolor 5;
#P connect 83 1 89 0;
#P lcolor 5;
#P connect 76 0 89 0;
#P lcolor 5;
#P connect 64 0 58 4;
#P connect 89 0 3 0;
#P lcolor 5;
#P connect 14 0 15 0;
#P connect 15 0 16 0;
#P connect 12 0 16 0;
#P connect 65 0 58 5;
#P connect 73 0 77 1;
#P lcolor 2;
#P connect 16 0 64 0;
#P lcolor 2;
#P connect 16 0 65 0;
#P lcolor 2;
#P connect 81 0 84 0;
#P lcolor 2;
#P connect 60 0 59 0;
#P connect 0 0 81 0;
#P lcolor 2;
#P connect 59 0 0 0;
#P connect 55 0 54 0;
#P connect 81 1 85 0;
#P lcolor 2;
#P connect 56 0 55 0;
#P connect 28 0 32 0;
#P connect 32 0 54 1;
#P connect 21 3 11 0;
#P lcolor 3;
#P connect 11 0 68 0;
#P lcolor 5;
#P connect 32 0 68 0;
#P connect 41 0 68 0;
#P connect 69 0 68 0;
#P connect 11 0 4 0;
#P lcolor 5;
#P connect 16 0 69 0;
#P lcolor 2;
#P connect 21 3 2 0;
#P lcolor 2;
#P connect 43 0 49 0;
#P connect 49 0 90 0;
#P connect 42 0 38 0;
#P connect 45 0 38 0;
#P connect 38 0 43 0;
#P connect 16 0 46 0;
#P lcolor 2;
#P connect 46 0 45 0;
#P connect 11 0 45 0;
#P lcolor 5;
#P connect 32 0 45 0;
#P connect 41 0 45 0;
#P connect 55 0 92 0;
#P connect 39 0 42 0;
#P connect 92 0 91 0;
#P connect 90 0 93 0;
#P connect 93 0 91 1;
#P connect 68 0 71 0;
#P connect 91 0 47 0;
#P connect 90 1 47 0;
#P connect 47 0 48 0;
#P connect 48 0 1 0;
#P connect 38 1 44 0;
#P connect 44 0 47 1;
#P pop;
#P newobj 18 285 162 9109518 p processing;
#B color 2;
#P window setfont "Sans Serif" 10.;
#N vpatcher 282 59 512 317;
#P window setfont "Sans Serif" 12.;
#P window linecount 1;
#P message 129 193 31 9109516 0;
#P window linecount 0;
#P message 92 193 31 9109516 1;
#P outlet 122 222 15 0;
#P window setfont "Sans Serif" 14.;
#P newex 50 110 69 9109518 sel 2;
#B color 1;
#P window setfont "Sans Serif" 18.;
#P number 50 80 59 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P newex 50 50 92 9109518 zl len;
#B color 1;
#P message 39 166 112 9109518 set Prime;
#P message 91 141 112 9109518 set Not Prime;
#P inlet 50 30 15 0;
#P outlet 55 209 15 0;
#P connect 6 0 3 0;
#P connect 1 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 2 0 0 0;
#P connect 3 0 0 0;
#P connect 6 1 2 0;
#P connect 6 0 8 0;
#P connect 8 0 7 0;
#P connect 9 0 7 0;
#P connect 6 1 9 0;
#P pop;
#P newobj 17 373 128 9109514 p prime_check;
#P window setfont "Sans Serif" 14.;
#P message 135 851 678 9109518 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97;
#P message 139 543 42 9109518 0;
#P message 102 878 94 9109518 append $1 \,;
#P message 137 902 617 9109518 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 ,;
#P user multiSlider 186 393 733 171 0. 6. 26 2921 15 0 2 2 1 0 0;
#M frgb 214 214 214;
#M brgb 0 0 0;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user jit.cellblock 188 572 921 739 146 14 26 8 28 20 0 1 1 1 0 0 0 0 0 9 250 255 0 0 0 248 0 0 0 0 0 191 191 191 0 0 0 215 215 240 1 1 1 0 4 0 0 0;
#X set 0 0 1;
#X set 1 0 2;
#X set 2 0 3;
#X set 3 0 5;
#X set 4 0 7;
#X set 5 0 11;
#X set 6 0 13;
#X set 7 0 17;
#X set 8 0 19;
#X set 9 0 23;
#X set 10 0 29;
#X set 11 0 31;
#X set 12 0 37;
#X set 13 0 41;
#X set 14 0 43;
#X set 15 0 47;
#X set 16 0 53;
#X set 17 0 59;
#X set 18 0 61;
#X set 19 0 67;
#X set 20 0 71;
#X set 21 0 73;
#X set 22 0 79;
#X set 23 0 83;
#X set 24 0 89;
#X set 25 0 97;
#P newex 19 881 69 9109518 change;
#B color 1;
#P message 113 819 94 9109518 append $1;
#P window setfont "Sans Serif" 18.;
#P number 18 849 59 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P message 19 823 61 9109518 set $1;
#P window setfont "Sans Serif" 24.;
#P message 17 423 140 9109528 Not Prime;
#P window setfont "Sans Serif" 36.;
#P message 16 319 895 9109540 2 * 2;
#P number 17 190 93 36 2 300 3 139 255 255 255 58 58 58 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P message 224 807 61 9109518 set;
#P window linecount 2;
#P comment 256 281 320 9109518 milliseconds per update (if manually changing number to factorize);
#P window setfont "Sans Serif" 10.;
#P window linecount 1;
#P hidden newex 129 262 51 9109514 t b i;
#B color 1;
#P hidden newex 333 258 51 9109514 t b i;
#B color 1;
#P hidden newex 18 47 51 9109514 – 1;
#B color 1;
#N vpatcher 15 55 290 263;
#P window setfont "Sans Serif" 10.;
#P newex 50 80 123 9109514 !- 127;
#B color 1;
#P window setfont "Sans Serif" 18.;
#P flonum 180 77 64 18 1. 2. 3 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 10.;
#P newex 51 108 157 9109514 scale 0 127 50 5000 1.035;
#B color 1;
#P inlet 50 60 15 0;
#P outlet 51 133 15 0;
#P connect 1 0 4 0;
#P connect 4 0 2 0;
#P connect 2 0 0 0;
#P connect 3 0 2 5;
#P pop;
#P hidden newobj 310 99 73 9109514 p scaler;
#P hidden connect 43 0 62 0;
#P hidden connect 1 0 53 0;
#P hidden connect 20 0 7 0;
#P hidden connect 20 1 7 0;
#P hidden connect 19 1 22 0;
#P hidden connect 52 0 45 0;
#P hidden connect 38 0 6 0;
#P hidden connect 3 0 6 0;
#P hidden connect 2 0 6 0;
#P hidden connect 45 1 6 0;
#P hidden connect 46 1 6 0;
#P hidden connect 47 1 6 0;
#P hidden connect 57 1 6 0;
#P hidden connect 58 1 6 0;
#P hidden connect 59 1 6 0;
#P hidden connect 60 1 6 0;
#P hidden connect 56 1 6 0;
#P hidden connect 64 1 6 0;
#P hidden connect 65 1 6 0;
#P hidden fasten 20 3 19 0 5 308 5 358;
#P hidden connect 19 0 8 0;
#P hidden connect 62 0 1 0;
#P hidden connect 6 0 20 0;
#P hidden connect 9 0 10 0;
#P hidden connect 10 0 12 0;
#P hidden connect 53 1 52 0;
#P hidden connect 19 1 26 0;
#P hidden connect 30 0 20 1;
#P hidden connect 49 0 55 0;
#P hidden connect 19 1 27 0;
#P hidden connect 54 0 51 0;
#P hidden connect 52 1 46 0;
#P hidden connect 12 0 16 0;
#P hidden connect 19 1 28 0;
#P hidden connect 48 0 55 1;
#P hidden connect 12 0 11 0;
#P hidden connect 3 1 20 2;
#P hidden connect 44 0 50 0;
#P hidden connect 39 0 3 0;
#P hidden connect 11 0 18 0;
#P hidden connect 5 0 18 0;
#P hidden connect 19 1 29 0;
#P hidden connect 53 1 54 0;
#P hidden connect 20 2 17 0;
#P hidden connect 54 1 55 2;
#P hidden connect 44 0 39 0;
#P hidden connect 52 2 47 0;
#P hidden connect 2 1 20 3;
#P hidden connect 50 0 55 3;
#P hidden connect 37 0 30 0;
#P hidden connect 17 0 14 0;
#P hidden connect 24 0 14 0;
#P hidden connect 20 4 14 0;
#P hidden connect 51 0 55 4;
#P hidden connect 55 1 61 0;
#P hidden connect 68 0 48 0;
#P hidden connect 0 0 48 0;
#P hidden connect 52 3 56 0;
#P hidden connect 44 0 49 0;
#P hidden connect 63 0 49 0;
#P hidden connect 69 0 0 0;
#P hidden connect 52 4 57 0;
#P hidden connect 43 0 41 0;
#P hidden connect 41 0 2 0;
#P hidden connect 52 5 58 0;
#P hidden connect 52 6 59 0;
#P hidden connect 52 7 64 0;
#P hidden connect 52 8 65 0;
#P hidden connect 36 0 68 0;
#P hidden connect 52 9 60 0;
#P hidden connect 55 0 52 1;
#P hidden connect 36 0 37 0;
#P hidden connect 36 0 38 0;
#P hidden connect 36 0 43 0;
#P hidden connect 36 0 44 0;
#P hidden connect 23 0 24 0;
#P pop;


June 29, 2007 | 8:22 am

Patches with a lot of cosmetics and lots of crossing patch cords underneath are never a good start for debugging. The first thing I would do is isolate different parts of your patch into plain (and aligned) patches. This most likely leads to the source of the problem.

Mattijs



_j
June 29, 2007 | 10:54 am

yeah mon, they created the patcher object for a reason. try and think of parts of your patch as separate functions and isolate accordingly.


June 29, 2007 | 11:30 am

Your points are very well taken, I wish I could get out of the "put everything into one patch" problem. Will work on it, as well as cleaning my apartment—which kind of looks like a bad Max patch at the moment, heh. Maybe there’s a connection there.

Here’s the same thing stripped down to as small as I can get it and still factorize. Now it overflows at 241 and above primes. I have NO CLUE, I think it should be totally OK for any value, realistically. Is it something about *overall* speed of execution that’s stumping me? Why shouldn’t this work for valules up to 90000 (square of maximum of counter)?!

Thanks, am very curious about this, probably just OCD…!

-CJ

————-

#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 385 465 141 9109516 Only bang through if it is a prime factor;
#P window linecount 1;
#P comment 185 31 274 9109516 Still stack overflow at 241… no idea why;
#P window setfont "Sans Serif" 14.;
#P message 294 519 164 9109518 append $1;
#B color 1;
#P message 23 626 61 9109518 set;
#B color 1;
#P window setfont "Sans Serif" 36.;
#P number 31 35 148 36 2 500 3 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 12.;
#P window linecount 3;
#P comment 381 109 155 9109516 Factor list (yes I know there’s redundancy but it’s still plenty fast);
#P window setfont "Sans Serif" 36.;
#P window linecount 1;
#P message 91 600 494 9109540 240;
#P window setfont "Sans Serif" 14.;
#P newex 31 92 92 9109518 speedlim 50;
#B color 1;
#P button 54 259 21 1;
#P window setfont "Sans Serif" 12.;
#P comment 89 555 447 9109516 If a prime factor , recurse with same factor until it is not;
#P window setfont "Sans Serif" 14.;
#P newex 287 299 56 9109518 t i b;
#B color 1;
#P window setfont "Sans Serif" 12.;
#P window linecount 3;
#P comment 341 189 224 9109516 No need to skip 4 , 6 , etc. , they will simply not work once 2 has been exhausted , etc. for other small primes;
#P window setfont "Sans Serif" 20.;
#P window linecount 1;
#P newex 92 515 77 9109524 t i i;
#B color 1;
#P window setfont "Sans Serif" 18.;
#P number 122 485 48 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P newex 75 452 80 9109518 sel 1;
#B color 1;
#P button 42 407 21 1;
#P window setfont "Sans Serif" 24.;
#P number 77 415 63 24 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 18.;
#P number 116 362 48 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P message 79 288 61 9109518 set $1;
#P newex 82 259 49 9109518 /;
#B color 1;
#P newex 68 150 92 9109518 t i i b b;
#B color 1;
#P button 237 91 29 1;
#P button 300 95 21 1;
#N counter 2 300;
#X flags 0 0;
#P newobj 237 125 138 9109518 counter 2 300;
#B color 1;
#P window setfont "Sans Serif" 18.;
#P number 287 327 48 18 1 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 36.;
#P number 297 458 81 36 1 0 1 139 0 0 0 247 1 7 222 222 222 0 0 0;
#P window setfont "Sans Serif" 14.;
#P message 297 420 61 9109518 set $1;
#B color 1;
#P window setfont "Sans Serif" 20.;
#P number 237 157 68 20 2 0 1 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 218 329 34 1;
#P window setfont "Sans Serif" 14.;
#P newex 216 298 64 9109518 sel 0;
#B color 1;
#P toggle 212 257 37 0;
#P newex 70 197 260 9109518 if ($i1 % $i2 == 0) then 0 else $i1;
#B color 1;
#P window setfont "Sans Serif" 12.;
#P window linecount 2;
#P comment 349 301 200 9109516 If not a prime factor , advance counter to next divisor / modulus;
#P connect 5 0 24 0;
#P lcolor 3;
#P connect 5 0 13 1;
#P connect 5 0 6 0;
#P connect 5 0 1 1;
#P connect 10 0 9 2;
#P connect 12 3 29 0;
#P connect 12 3 10 0;
#P connect 6 0 7 0;
#P connect 4 0 15 0;
#P connect 4 0 7 0;
#P connect 7 0 30 0;
#P connect 22 0 8 0;
#P lcolor 3;
#P connect 3 1 22 0;
#P lcolor 3;
#P connect 9 0 5 0;
#P connect 11 0 9 0;
#P connect 12 2 11 0;
#P connect 22 1 11 0;
#P lcolor 3;
#P connect 3 0 4 0;
#P connect 2 0 3 0;
#P connect 1 0 2 0;
#P connect 18 1 19 0;
#P lcolor 3;
#P connect 14 0 15 0;
#P connect 19 0 20 0;
#P lcolor 3;
#P connect 29 0 26 0;
#P connect 30 0 26 0;
#P connect 12 1 13 0;
#P connect 24 0 13 0;
#P lcolor 3;
#P fasten 20 1 13 0 36 501 36 239;
#P lcolor 3;
#P connect 13 0 14 0;
#P connect 15 0 17 0;
#P connect 15 0 16 0;
#P connect 16 0 18 0;
#P connect 8 0 1 0;
#P lcolor 3;
#P connect 12 0 1 0;
#P connect 20 0 1 0;
#P lcolor 3;
#P connect 25 0 12 0;
#P connect 28 0 25 0;
#P window clipboard copycount 33;


June 29, 2007 | 1:26 pm

Without studying how your patch works I think it can be tidied up a lot.

Somthing like this:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 120 318 27 196617 t b i;
#P newex 103 365 27 196617 i;
#P newex 235 463 27 196617 i;
#P comment 266 463 189 196617 Only bang through if it is a prime factor;
#P comment 92 64 198 196617 Still stack overflow at 241… no idea why;
#P message 235 482 55 196617 append $1;
#P message 106 85 22 196617 set;
#P number 52 64 35 9 2 500 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 297 500 313 196617 Factor list (yes I know there’s redundancy but it’s still plenty fast);
#P message 235 499 57 196617 7;
#P comment 181 404 269 196617 If a prime factor , recurse with same factor until it is not;
#P newex 261 213 27 196617 t i b;
#P window linecount 2;
#P comment 290 254 257 196617 No need to skip 4 , 6 , etc. , they will simply not work once 2 has been exhausted , etc. for other small primes;
#P window linecount 1;
#P newex 125 405 27 196617 t i i;
#P newex 103 385 32 196617 sel 1;
#P newex 120 344 27 196617 /;
#P newex 52 85 53 196617 t i i b b;
#P button 252 126 15 0;
#P message 300 126 14 196617 2;
#N counter 2 300;
#X flags 0 0;
#P newobj 252 144 74 196617 counter 2 300;
#P number 252 165 35 9 2 0 1 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 52 213 204 196617 if ($i1 % $i2 == 0) then bang else out2 $i1;
#P comment 289 213 303 196617 If not a prime factor , advance counter to next divisor / modulus;
#P connect 15 0 6 0;
#P connect 6 0 1 0;
#P fasten 11 0 1 0 266 257 42 257 42 204 57 204;
#P lcolor 13;
#P fasten 9 0 1 0 130 427 42 427 42 204 57 204;
#P lcolor 13;
#P connect 1 0 21 0;
#P connect 21 0 8 0;
#P connect 6 3 16 0;
#P connect 2 0 22 0;
#P connect 22 0 7 0;
#P connect 6 1 7 0;
#P lcolor 1;
#P fasten 9 1 7 0 147 427 154 427 154 340 125 340;
#P lcolor 13;
#P connect 7 0 21 1;
#P connect 8 1 9 0;
#P connect 22 1 7 1;
#P fasten 1 0 20 0 57 460 240 460;
#P connect 20 0 17 0;
#P connect 17 0 13 0;
#P connect 16 0 13 0;
#P lcolor 1;
#P connect 2 0 1 1;
#P connect 11 1 5 0;
#P lcolor 13;
#P connect 5 0 3 0;
#P connect 3 0 2 0;
#P connect 2 0 20 1;
#P connect 1 1 11 0;
#P connect 6 2 4 0;
#P lcolor 1;
#P connect 4 0 3 3;
#P window clipboard copycount 23;

I guess you could use good old Trace on this patch and get an idea of what is actually going on.

Mattijs


July 3, 2007 | 5:44 pm

Seejay James schrieb:
> Here’s the same thing stripped down to as small as I can get it and
> still factorize. Now it overflows at 241 and above primes. I have NO
> CLUE, I think it should be totally OK for any value, realistically.
> Is it something about *overall* speed of execution that’s stumping
> me? Why shouldn’t this work for valules up to 90000 (square of
> maximum of counter)?!
>
> Thanks, am very curious about this, probably just OCD…!

There is feedback in your algorithm. If your break condition is reached
fast this seems fine. But the stack you need will grow exponentially,
its only a matter of time(size) to blow it up.

Usually deferlow somewhere in the feedback loop will help in those
cases. But be careful with your order of execution…

It will slow things down, the Java solution is crossplatform as well,
and last not least, memory is cheap, I came to the conclusion when doing
something similar, to just fill a buffer~ with all primes representable
in 32bit int should be the way to go…

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


July 5, 2007 | 7:36 am

Seejay James schrieb:
> Here’s the updated patch

Thanks for sharing this…

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


Viewing 7 posts - 1 through 7 (of 7 total)