Rational simplification bug ("Quotient by a polynomial of higher degree" error message)
Subject: Rational simplification bug ("Quotient by a polynomial of higher degree" error message)
From: Stavros Macrakis
Date: Wed, 28 Nov 2012 17:08:31 -0500
I don't know Sage, but it looks as though you're calculating a large
expression (with presumably many common subexpressions) without trying to
do any simplification other than default simplification along the way.
Depending on the form of the expressions, this might not be the most
efficient way of proceeding.
Also, instead of using ratsimp at the end of your calculation, it's
possible that it will be more efficient to perform the whole calculation
using rational-function format (CRE). Since CRE is contagious, it's enough
to make your initial expressions CRE's using rat(...). This may (or may
not!) also avoid the "inexact quotient" bug. I'm afraid I don't know how
rat(...) works in Sage.
-s
On Wed, Nov 28, 2012 at 5:27 AM, Alan W. Irwin <irwin at beluga.phys.uvic.ca>wrote:
> I am using maxima-5.26 indirectly via sage-5.4.1, and I have only had
> a week's worth of experience with sage (and indirectly maxima).
> But it's been a productive week since I have been able to put together
> a sage script that confirms certain symbolic sums over nbody indices (where
> nbody is the number of gravitational bodies considered in a
> General relativity calculation.)
>
> The confirmation result should be zero and is stored in a Residual
> Vector with just 3 (spatial) components. Here is a typical good
> result for nbody=2.
>
> sage: #attach script (that is attached to this post) that does most of the
> work
> sage: attach "location_check.sage"
>
> sage: Residual[0]
> (2*(beta + gamma)*G*M_1/(sqrt((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 -
> x_1)^2)*c^2) - (vx_0^2 + vy_0^2 + vz_0^2)*gamma/c^2 - 1)*(x_0 -
> x_1)*G*M_1/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2)^(3/2) +
> 1/2*(4*gamma + 3)*G*M_1*a_x1/(sqrt((z_0 - z_1)^2 + (y_0 - y_1)^2 +
> (x_0 - x_1)^2)*c^2) + (x_0 - x_1)*G*M_1/((z_0 - z_1)^2 + (y_0 - y_1)^2
> + (x_0 - x_1)^2)^(3/2) - 1/2*(x_0 - x_1)*(2*(gamma + 1)*(vx_1^2 +
> vy_1^2 + vz_1^2) - 4*(gamma + 1)*(vx_0*vx_1 + vy_0*vy_1 + vz_0*vz_1) -
> 2*(2*beta - 1)*U_1 - (z_0 - z_1)*a_z1 - (y_0 - y_1)*a_y1 - (x_0 -
> x_1)*a_x1 - 3*((z_0 - z_1)*vz_1 + (y_0 - y_1)*vy_1 + (x_0 -
> x_1)*vx_1)^2/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 -
> x_1)^2))*G*M_1/(((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 -
> x_1)^2)^(3/2)*c^2) + (vx_0 - vx_1)*(2*(gamma + 1)*((z_0 - z_1)*vz_0 +
> (y_0 - y_1)*vy_0 + (x_0 - x_1)*vx_0) - (2*gamma + 1)*((z_0 - z_1)*vz_1
> + (y_0 - y_1)*vy_1 + (x_0 - x_1)*vx_1))*G*M_1/(((z_0 - z_1)^2 + (y_0 -
> y_1)^2 + (x_0 - x_1)^2)^(3/2)*c^2) + 1/2*(4*(gamma + 1)*((z_0 -
> z_1)*(vz_0 - vz_1) + (y_0 - y_1)*(vy_0 - vy_1) + (x_0 - x_1)*(vx_0 -
> vx_1))*G*M_1*vx_1/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 -
> x_1)^2)^(3/2) - 4*(gamma + 1)*G*M_1*a_x1/sqrt((z_0 - z_1)^2 + (y_0 -
> y_1)^2 + (x_0 - x_1)^2) - (x_0 - x_1)*(2*(2*gamma + 1)*G*M_1/sqrt((z_0
> - z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2) + vx_0^2 + vy_0^2 +
> vz_0^2)*G*M_1/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2)^(3/2) -
> 2*((2*gamma + 1)*((z_0 - z_1)*(vz_0 - vz_1) + (y_0 - y_1)*(vy_0 -
> vy_1) + (x_0 - x_1)*(vx_0 - vx_1))*G*M_1/((z_0 - z_1)^2 + (y_0 -
> y_1)^2 + (x_0 - x_1)^2)^(3/2) + (z_0 - z_1)*G*M_1*vz_0/((z_0 - z_1)^2
> + (y_0 - y_1)^2 + (x_0 - x_1)^2)^(3/2) + (y_0 - y_1)*G*M_1*vy_0/((z_0
> - z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2)^(3/2) + (x_0 -
> x_1)*G*M_1*vx_0/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 -
> x_1)^2)^(3/2))*vx_0)/c^2 - 1/2*(2*(2*beta - 1)*(x_0 -
> x_1)*G^2*M_1^2/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2)^2 -
> (2*gamma + 1)*(x_0 - x_1)*(vx_0^2 + vy_0^2 + vz_0^2)*G*M_1/((z_0 -
> z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2)^(3/2) - (x_0 - x_1)*(2*(gamma
> + 1)*(vx_1^2 + vy_1^2 + vz_1^2) - 2*(2*beta - 1)*U_1 - (z_0 -
> z_1)*a_z1 - (y_0 - y_1)*a_y1 - (x_0 - x_1)*a_x1 - ((z_0 - z_1)*vz_1 +
> (y_0 - y_1)*vy_1 + (x_0 - x_1)*vx_1)^2/((z_0 - z_1)^2 + (y_0 - y_1)^2
> + (x_0 - x_1)^2))*G*M_1/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 -
> x_1)^2)^(3/2) + (2*(x_0 - x_1)*((z_0 - z_1)*vz_1 + (y_0 - y_1)*vy_1 +
> (x_0 - x_1)*vx_1)^2/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2)^2
> - 2*((z_0 - z_1)*vz_1 + (y_0 - y_1)*vy_1 + (x_0 -
> x_1)*vx_1)*vx_1/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2) -
> a_x1)*G*M_1/sqrt((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2) +
> 4*(gamma + 1)*((x_0 - x_1)*G*M_1*vx_0*vx_1/((z_0 - z_1)^2 + (y_0 -
> y_1)^2 + (x_0 - x_1)^2)^(3/2) + (x_0 - x_1)*G*M_1*vy_0*vy_1/((z_0 -
> z_1)^2 + (y_0 - y_1)^2 + (x_0 - x_1)^2)^(3/2) + (x_0 -
> x_1)*G*M_1*vz_0*vz_1/((z_0 - z_1)^2 + (y_0 - y_1)^2 + (x_0 -
> x_1)^2)^(3/2)))/c^2
>
> sage: Residual[0].simplify_rational(**)
> 0
>
> and similarly for Residual[1] and Residual[2]. Those simplifications
> take just a second or so on an entry level PC.
>
> So all is well for
> nbody=2. When I try the same script except for changing nbody=2 to
> nbody=3, then the result for Residual[0] is roughly twice as long
> (involving additional variables like M2, x_2, y_2, z_2, etc.) and
> therefore presumably more difficult to simplify to zero. In fact,
> I currently get the following maxima error message from that attempt:
>
> sage: Residual[0].simplify_rational(**)
> ------------------------------**------------------------------**
> ---------------
> TypeError Traceback (most recent call last)
>
> /home/irwin/<ipython console> in <module>()
>
> /home/software/sage/sage-5.4.**1/local/lib/python2.7/site-**
> packages/sage/misc/decorators.**pyc in wrapper(*args, **kwds)
> 689 kwds[new_name] = kwds[old_name]
> 690 del kwds[old_name]
> --> 691 return func(*args, **kwds)
> 692
> 693 return wrapper
>
> /home/software/sage/sage-5.4.**1/local/lib/python2.7/site-**
> packages/sage/symbolic/**expression.so in sage.symbolic.expression.**Expression.simplify_rational
> (sage/symbolic/expression.cpp:**30806)()
>
> /home/software/sage/sage-5.4.**1/local/lib/python2.7/site-**
> packages/sage/interfaces/**interface.pyc in __call__(self, x, name)
> 193
> 194 if isinstance(x, basestring):
> --> 195 return cls(self, x, name=name)
> 196 try:
> 197 return self._coerce_from_special_**method(x)
>
> /home/software/sage/sage-5.4.**1/local/lib/python2.7/site-**
> packages/sage/interfaces/**interface.pyc in __init__(self, parent, value,
> is_name, name)
> 620 self._name = parent._create(value, name=name)
> 621 except (TypeError, KeyboardInterrupt, RuntimeError,
> ValueError), x:
> --> 622 raise TypeError, x
> 623
> 624 def _latex_(self):
>
> TypeError: ECL says: Error executing code in Maxima: Quotient by a
> polynomial of higher degree
>
> I did a google search for that last error message, and there appeared
> to be a number of hits for older maxima versions that were due to bugs
> for those versions. If anybody here thinks they know what the Maxima
> problem is for this case of rational simplification, I have the
> capability to rebuild sage with a patched version of maxima-5.26 to
> try out your idea for a fix. However, you might prefer to figure this
> out directly. Therefore, I have attached the relatively short sage
> script to give you the opportunity to (1) verify all is well for the
> rational simplification of Residual[0] generated by that script with
> nbody=2. Such a check should only take you a second or so. However,
> if you edit that script to change one line from nbody=2 ==> nbody=3,
> you should be able to confirm the above rational simplification error
> (which should serve as a good test case for the fix).
>
> Alan
> __________________________
> Alan W. Irwin
>
> Astronomical research affiliation with Department of Physics and Astronomy,
> University of Victoria (astrowww.phys.uvic.ca).
>
> Programming affiliations with the FreeEOS equation-of-state
> implementation for stellar interiors (freeeos.sf.net); the Time
> Ephemerides project (timeephem.sf.net); PLplot scientific plotting
> software package (plplot.sf.net); the libLASi project
> (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
> and the Linux Brochure Project (lbproject.sf.net).
> __________________________
>
> Linux-powered Science
> __________________________
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>