Ok, I isolated the code that crashes both gsi and gsc compiled code: it's doing reduced-row-echelon-form. It's a bit long, but this is the best I can do:
;; http://www.cap-lore.com/MathPhys/Field/RREF.html (define (rref x) (if (or (null? x) (null? (car x))) x (let ((a (call-with-current-continuation (lambda (cc) (let df ((y x)) (if (null? y) (cc x) (if (zero? (caar y)) (let ((z (df (cdr y)))) (if (null? z) y (cons (car z) (cons (car y)(cdr z))))) y))))))) (if (zero? (caar a)) (map (lambda (x) (cons 0 x)) (rref (map cdr a))) (let* ( (b (let* ((r (/ (caar a))) (top (map (lambda (z) (* z r)) (car a)))) (cons top (map (lambda (row) (map (lambda (t re) (- re (* t (car row)))) top row)) (cdr a))))) (c (rref (map cdr (cdr b)))) ; now we must ensure a zero in row (cdar b) above each initial 1 a row of c. (d (let w ((sm (cdar b))(i c)) (if (null? i) sm (w (let sr ((x sm) (y (car i))) (if (null? x) '() (if (zero? (car y)) (cons (car x) (sr (cdr x)(cdr y))) (map (lambda (p q)(- p (* (car x) q))) x y)))) (cdr i)))))) (cons (cons 1 d) (map (lambda (x) (cons 0 x)) c)))))))
(define M '((1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4) (1152921504606846976 288230376151711744 72057594037927936 18014398509481984 4503599627370496 1125899906842624 281474976710656 70368744177664 17592186044416 4398046511104 1099511627776 274877906944 68719476736 17179869184 4294967296 1073741824 268435456 67108864 16777216 4194304 1048576 262144 65536 16384 4096 1024 256 64 16 4 1 2) (1073741824 536870912 268435456 134217728 67108864 33554432 16777216 8388608 4194304 2097152 1048576 524288 262144 131072 65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 7) (22539340290692258087863249 3219905755813179726837607 459986536544739960976801 65712362363534280139543 9387480337647754305649 1341068619663964900807 191581231380566414401 27368747340080916343 3909821048582988049 558545864083284007 79792266297612001 11398895185373143 1628413597910449 232630513987207 33232930569601 4747561509943 678223072849 96889010407 13841287201 1977326743 282475249 40353607 5764801 823543 117649 16807 2401 343 49 7 1 3) (205891132094649 68630377364883 22876792454961 7625597484987 2541865828329 847288609443 282429536481 94143178827 31381059609 10460353203 3486784401 1162261467 387420489 129140163 43046721 14348907 4782969 1594323 531441 177147 59049 19683 6561 2187 729 243 81 27 9 3 1 508) (1499378808754598535585630628499515809512621559292630070002567432363673096997044224 2951533088099603416507146906495109861245318030103602500005054000715891923222528 5810104504133077591549501784439192640246689035637012795285539371487976226816 11437213590813144865254924772518095748517104400860261408042400337574756352 22514199981915639498533316481334834150624221261535947653626772318060544 44319291302983542319947473388454397934299648152629818215800732909568 87242699415321933700684002733177948689566236520924839007481757696 171737597274255775001346462073184938365287867167174879935987712 338066136366645226380603271797608146388361943242470236094464 665484520406781941694100928735449107063704612682028023808 1310008898438547129319096316408364383983670497405566976 2578757674091628207321055740961347212566280506703872 5076294634038638203387905001892415772768268713984 9992705972517004337377765751756723962142261248 19670681048261819561767255416843944807366656 38721813087129566066470975230007765368832 76224041510097570996990108720487727104 150047325807278683064941158898597888 295368751589131265875868423028736 581434550372305641487929966592 1144556201520286695842381824 2253063388819461999689728 4435164151219413385216 8730638092951601152 17186295458566144 33831290272768 66597028096 131096512 258064 508 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5) (931322574615478515625 186264514923095703125 37252902984619140625 7450580596923828125 1490116119384765625 298023223876953125 59604644775390625 11920928955078125 2384185791015625 476837158203125 95367431640625 19073486328125 3814697265625 762939453125 152587890625 30517578125 6103515625 1220703125 244140625 48828125 9765625 1953125 390625 78125 15625 3125 625 125 25 5 1 5) (931322574615478515625 186264514923095703125 37252902984619140625 7450580596923828125 1490116119384765625 298023223876953125 59604644775390625 11920928955078125 2384185791015625 476837158203125 95367431640625 19073486328125 3814697265625 762939453125 152587890625 30517578125 6103515625 1220703125 244140625 48828125 9765625 1953125 390625 78125 15625 3125 625 125 25 5 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2) (1073741824 536870912 268435456 134217728 67108864 33554432 16777216 8388608 4194304 2097152 1048576 524288 262144 131072 65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 24) (254880876153761202627773829926908776677376 10620036506406716776157242913621199028224 442501521100279865673218454734216626176 18437563379178327736384102280592359424 768231807465763655682670928358014976 32009658644406818986777955348250624 1333735776850284124449081472843776 55572324035428505185378394701824 2315513501476187716057433112576 96479729228174488169059713024 4019988717840603673710821376 167499529910025153071284224 6979147079584381377970176 290797794982682557415424 12116574790945106558976 504857282956046106624 21035720123168587776 876488338465357824 36520347436056576 1521681143169024 63403380965376 2641807540224 110075314176 4586471424 191102976 7962624 331776 13824 576 24 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3) (205891132094649 68630377364883 22876792454961 7625597484987 2541865828329 847288609443 282429536481 94143178827 31381059609 10460353203 3486784401 1162261467 387420489 129140163 43046721 14348907 4782969 1594323 531441 177147 59049 19683 6561 2187 729 243 81 27 9 3 1 3) (205891132094649 68630377364883 22876792454961 7625597484987 2541865828329 847288609443 282429536481 94143178827 31381059609 10460353203 3486784401 1162261467 387420489 129140163 43046721 14348907 4782969 1594323 531441 177147 59049 19683 6561 2187 729 243 81 27 9 3 1 30) (205891132094649000000000000000000000000000000 6863037736488300000000000000000000000000000 228767924549610000000000000000000000000000 7625597484987000000000000000000000000000 254186582832900000000000000000000000000 8472886094430000000000000000000000000 282429536481000000000000000000000000 9414317882700000000000000000000000 313810596090000000000000000000000 10460353203000000000000000000000 348678440100000000000000000000 11622614670000000000000000000 387420489000000000000000000 12914016300000000000000000 430467210000000000000000 14348907000000000000000 478296900000000000000 15943230000000000000 531441000000000000 17714700000000000 590490000000000 19683000000000 656100000000 21870000000 729000000 24300000 810000 27000 900 30 1 4) (1152921504606846976 288230376151711744 72057594037927936 18014398509481984 4503599627370496 1125899906842624 281474976710656 70368744177664 17592186044416 4398046511104 1099511627776 274877906944 68719476736 17179869184 4294967296 1073741824 268435456 67108864 16777216 4194304 1048576 262144 65536 16384 4096 1024 256 64 16 4 1 10) (1000000000000000000000000000000 100000000000000000000000000000 10000000000000000000000000000 1000000000000000000000000000 100000000000000000000000000 10000000000000000000000000 1000000000000000000000000 100000000000000000000000 10000000000000000000000 1000000000000000000000 100000000000000000000 10000000000000000000 1000000000000000000 100000000000000000 10000000000000000 1000000000000000 100000000000000 10000000000000 1000000000000 100000000000 10000000000 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1 158) (911407522138190370523336355973946907449902506716804668278098100224 5768402038849306142552761746670550047151281688081042204291760128 36508873663603203433878238902978164855387858785323051925897216 231068820655716477429609106980874461110049739147614252695552 1462460890226053654617779158106800386772466703465912991744 9256081583709200345682146570296204979572574072569069568 58582794833602533833431307406938006199826418180816896 370777182491155277426780426626189912657129228992512 2346691028425033401435319155861961472513476132864 14852474863449578490096956682670642231097950208 94003005464870749937322510649814191336062976 594955730790321202134952599049456907190272 3765542599938741785664256956009220931584 23832548100878112567495297189931778048 150838912030874130174020868290707456 954676658423253988443170052472832 6042257331792746762298544635904 38242135011346498495560409088 242038829185737332250382336 1531891323960362862344192 9695514708609891533824 61364017143100579328 388379855336079616 2458100350228352 15557597153344 98465804768 623201296 3944312 24964 158 1 6) (221073919720733357899776 36845653286788892983296 6140942214464815497216 1023490369077469249536 170581728179578208256 28430288029929701376 4738381338321616896 789730223053602816 131621703842267136 21936950640377856 3656158440062976 609359740010496 101559956668416 16926659444736 2821109907456 470184984576 78364164096 13060694016 2176782336 362797056 60466176 10077696 1679616 279936 46656 7776 1296 216 36 6 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2) (1073741824 536870912 268435456 134217728 67108864 33554432 16777216 8388608 4194304 2097152 1048576 524288 262144 131072 65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 12) (237376313799769806328950291431424 19781359483314150527412524285952 1648446623609512543951043690496 137370551967459378662586974208 11447545997288281555215581184 953962166440690129601298432 79496847203390844133441536 6624737266949237011120128 552061438912436417593344 46005119909369701466112 3833759992447475122176 319479999370622926848 26623333280885243904 2218611106740436992 184884258895036416 15407021574586368 1283918464548864 106993205379072 8916100448256 743008370688 61917364224 5159780352 429981696 35831808 2985984 248832 20736 1728 144 12 1 1))) (display (rref M))(newline)
On 4/26/07, Bradley Lucier lucier@math.purdue.edu wrote:
On Apr 25, 2007, at 10:25 PM, dillo gimp wrote:
On 4/26/07, Bradley Lucier lucier@math.purdue.edu wrote:
I hope you don' t mind me CC'ing my reply to th list.
On Apr 25, 2007, at 9:05 PM, dillo gimp wrote:
On 4/26/07, Bradley Lucier lucier@math.purdue.edu wrote: On Apr 25, 2007, at 7:43 PM, dillo gimp wrote:
There might be a bug in big number handling, the same code runs fine under mzscheme and petite, but crashes
with
gambit : *** ERROR IN ##ratnum.* -- Divide by zero (quotient 0 0)
I don't even use "quotient" in my code.
We'd need to see a bit of your code to figure out what you *are* using.
I don't know how to make gambit to report exactly where the code has crashed. The program is not exactly small either. Can you tell me how to make gambit report "crash point"? This is my compilation steps:
cat /lfs/script/gambit.sh #!/bin/bash /usr/4.0b22/bin/gsc -prelude '(define (display x) (write x
(current-
output-port)))' -link $1 prog=${1%.sc} gcc -O2 -fomit-frame-pointer -freg-struct-return \ -I/usr/4.0b22/include -L/usr/4.0b22/lib \ -D___SINGLE_HOST -o $prog $prog.c ${prog}_.c -lgambc -lm -
ldl -
lutil
OK, well I still don't know what you're trying to do, but gambit requires gcc to use certain flags for to correctly compile gambit- generated code. See the options in /usr/4.0b22/bin/
I don't understand. I am following the exact steps from: http://www.iro.umontreal.ca/~gambit/doc/gambit-c.html http://www.iro.umontreal.ca/~gambit/doc/gambit-c_toc.html#TOC17
The documentation is in error.
You are compiling your code with the options
gcc -O2 -fomit-frame-pointer -freg-struct-return \ -I/usr/4.0b22/include -L/usr/4.0b22/lib \ -D___SINGLE_HOST -o $prog $prog.c ${prog}_.c -lgambc -lm -
ldl -
These options are incorrect. You can find the correct options on your machine in
/usr/4.0b22/bin/gsc-cc-o
which is in the same directory in which you installed gsi and gsc.
This may be causing your specific problem, but I don't know for sure.
The program only reports: *** ERROR IN ##ratnum.* -- Divide by zero (quotient 0 0)
Without a more accurate location, I can't guess what's wrong.
The code for numeric operations is in gambc-4.0b22/lib/_num.scm. There you will find
(define-prim (##ratnum.* x y) (let ((p (macro-ratnum-numerator x)) (q (macro-ratnum-denominator x)) (r (macro-ratnum-numerator y)) (s (macro-ratnum-denominator y))) (if (##eq? x y) (macro-ratnum-make (##* p p) (##* q q)) ; already in lowest form (let* ((gcd-ps (##gcd p s)) (gcd-rq (##gcd r q)) (num (##* (##quotient p gcd-ps) (##quotient r gcd-rq))) (den (##* (##quotient q gcd-rq) (##quotient s gcd-ps)))) (if (##eq? den 1) num (macro-ratnum-make num den))))))
So, somehow, gcd-ps or gcd-rq is zero. ##ratnum.* is called only from ##*, which is the library primitive for multiplication, and ##ratnum.* is only called when one of the arguments of * is a ratnum.
The program is not big, but not small either, I can't cut and paste.
Most importantly: I don't use quotient in my code. There shoudn't have any "divide by zero" code, else it would have crashed with other scheme implementations.