Bug in Rational arithmetic?
- To: mathgroup at smc.vnet.net
- Subject: [mg98978] Bug in Rational arithmetic?
- From: Scott Hemphill <hemphill at hemphills.net>
- Date: Thu, 23 Apr 2009 06:42:06 -0400 (EDT)
- Reply-to: hemphill at alumni.caltech.edu
I am running Mathematica 5.1 for Linux. I know that this is an old version and don't expect a fix to my software. It would be good to know whether anyone can reproduce this problem with mine or any other version of the software. If the members of this list (and the moderator) don't object, I could post the 900+ line input file as a follow-up. Otherwise, does anyone know a good place to upload this file? SYMPTOM: I have a file "foo.m" written by Mathematica, which contains 2 statements: x = <rational number> y = <rational number> The rational numbers have large numerators and denominators. When I add x and y, I get a segmentation fault. ------------------------------------------------------------------------ $ uname -a Linux diamond 2.6.26.8-57.fc8 #1 SMP Thu Dec 18 18:59:49 EST 2008 x86_64 x86_64 x86_64 GNU/Linux $ wc foo.m 932 935 73456 foo.m $ math Mathematica 5.1 for Linux Copyright 1988-2004 Wolfram Research, Inc. -- Motif graphics initialized -- In[1]:= << foo.m; In[2]:= Head /@ {x,y} Out[2]= {Rational, Rational} In[3]:= {Numerator[#],Denominator[#]}& /@ {x,y} // N 18090 18097 Out[3]= {{-2.979268317140882 10 , 2.075577927018556 10 }, 17691 17700 > {-7.573697850202144 10 , 8.012808242587755 10 }} In[4]:= x+y Segmentation fault $ ------------------------------------------------------------------------ DIAGNOSIS: I am not running into any memory limits that I'm aware of. The virtual memory size after loading "foo.m" is only 25MB. I've increased the stack limit from the default 10MB to 100MB with no effect. x*=1/2; y*=1/2; 2(x+y) works. x+=1/2; y-=1/2; x+y segfaults. x+=1/3; y-=1/3; x+y segfaults. x+=1/5; y-=1/5; x+y segfaults. x+=1/7; y-=1/7; x+y segfaults. x+=1/999999893; y-=1/999999893; x+y works. x*=2; y*=2; (x+y)/2 works. CURE: I don't have a cure, but for this particular addition problem, I can work around the problem by multiplying the two addends by 2, then dividing their sum by 2. Scott -- Scott Hemphill hemphill at alumni.caltech.edu "This isn't flying. This is falling, with style." -- Buzz Lightyear