On Thu, Apr 23, 2009 at 6:44 AM, philabuster pollock.p...@gmail.com wrote:
Hi,
I was wondering why Sage expands products of sums in an unexpected
order:
var('a0,a1,b0,b1,b2,c0,c1,c2,c3,d0,d1,d2,d3,d4')
The ordering of these terms is determined by maxima -- Sage doesn't
control that at all, just leaving them in the default order maxima
chooses.
expand((a0+a1)*(b0+b1))
a1*b1 + a0*b1 + a1*b0 + a0*b0
And in Maxima:
wst...@geom:~/db/wuthrich-twist/data$ sage -maxima
Maxima 5.16.3 http://maxima.sourceforge.net
Using Lisp CLISP 2.47 (2008-10-23)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) expand((a0+a1)*(b0+b1));
(%o1)a1 b1 + a0 b1 + a1 b0 + a0 b0
We are currently making a push to rewrite the symbolic calculus part
of Sage using the Ginac C++ library instead of Maxima. When that
happens, the above will be:
sage: var('a0 a1 b0 b1',ns=1) # ns=1 sets a preview mode that
enables new symbolics
(a0, a1, b0, b1)
sage: expand((a0+a1)*(b0+b1))
a0*b0 + a0*b1 + a1*b0 + a1*b1
New symbolics also tend to be easier to work with term-by-term:
sage: v = expand((a0+a1)*(b0+b1))
sage: v[0]
a0*b0
sage: v[1]
a0*b1
sage: v[2]
a1*b0
sage: v[3]
a1*b1
expand((a0+a1)*(b0+b1+b2)*(c0+c1+c2+c3)*(d0+d1+d2+d3+d4))
a1*b2*c3*d4 + a0*b2*c3*d4 + a1*b1*c3*d4 + a0*b1*c3*d4 + a1*b0*c3*d4 +
a0*b0*c3*d4 + a1*b2*c2*d4 + a0*b2*c2*d4 + a1*b1*c2*d4 + a0*b1*c2*d4 +
a1*b0*c2*d4 + a0*b0*c2*d4 + a1*b2*c1*d4 + a0*b2*c1*d4 + a1*b1*c1*d4 +
a0*b1*c1*d4 + a1*b0*c1*d4 + a0*b0*c1*d4 + a1*b2*c0*d4 + a0*b2*c0*d4 +
a1*b1*c0*d4 + a0*b1*c0*d4 + a1*b0*c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1*b0*c3*d0 + a0*b0*c3*d0 + a1*b2*c2*d0 + a0*b2*c2*d0 + a1*b1*c2*d0 +
a0*b1*c2*d0 + a1*b0*c2*d0 + a0*b0*c2*d0 + a1*b2*c1*d0 + a0*b2*c1*d0 +
a1*b1*c1*d0 + a0*b1*c1*d0 + a1*b0*c1*d0 + a0*b0*c1*d0 + a1*b2*c0*d0 +
a0*b2*c0*d0 + a1*b1*c0*d0 + a0*b1*c0*d0 + a1*b0*c0*d0 + a0*b0*c0*d0
This ordering makes it extremely difficult to do index association
from the j-th term of the expansion back into constituent indices of
each sum (i0,i1,i2,i3); for example, (0,1,2,3) corresponds to
a0*b1*c2*d3 and is associated with j=33. A more intuitive left to
right product expansion would have been simpler and more useful when
working with these expansions. Also, other math packages expand these
products in a different order than what's seen in Sage. In the
simpler case (a0+a1)*(b0+b1) I would expect the accepted FOIL ordering
of terms. What was the rationale?
Given j, how would you calculate (i0,i1,i2,i3,...,ik) considering
Sage's expansion order?
Your help is appreciated,
philabuster
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---