MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Bug in Rational arithmetic?

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


I have a file "foo.m" written by Mathematica, which contains 2

  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 #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


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

  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.


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 Hemphill	hemphill at
"This isn't flying.  This is falling, with style."  -- Buzz Lightyear

  • Prev by Date: Re: Using the slider values in a Manipulate
  • Next by Date: Re: pure function with an NIntegrate command
  • Previous by thread: Re: 3D Agent Problem
  • Next by thread: Re: Bug in Rational arithmetic?