details:   http://hg.sympy.org/sympy/rev/52988f128d79
changeset: 1804:52988f128d79
user:      Ondrej Certik <[EMAIL PROTECTED]>
date:      Fri Oct 17 15:48:22 2008 +0200
description:
This fixes the (2+pi+x**2).extract_leading_order(x) problem.

The problem was that if there is more than one term to return, we need to be
sure to include both terms in the result. This case was wrongly handled in
Add.extract_leading_order(), which we just fixed.

Then there was a problem that some advanced series tests started to hang after
this patch. As it turned out, sometimes Order(..., x) returns O(2) instead of
O(1). So we fixed that by applying this patch (at 2 different places):

-            if o.expr==1:
+            if o.expr.is_number:

And the final problem was, that by fixing the as_leading_term(), we had to call
collect in Pow._eval_nseries() -- previously the wrong as_leading_term() was
effectively achieving the same thing, but that was just a sheer luck.

diffs (56 lines):

diff -r e02e9a56597f -r 52988f128d79 sympy/core/add.py
--- a/sympy/core/add.py Fri Oct 17 15:48:22 2008 +0200
+++ b/sympy/core/add.py Fri Oct 17 15:48:22 2008 +0200
@@ -325,14 +325,14 @@
         seq = [(f, C.Order(f, *symbols)) for f in self.args]
         for ef,of in seq:
             for e,o in lst:
-                if o.contains(of):
+                if o.contains(of) and o != of:
                     of = None
                     break
             if of is None:
                 continue
             new_lst = [(ef,of)]
             for e,o in lst:
-                if of.contains(o):
+                if of.contains(o) and o != of:
                     continue
                 new_lst.append((e,o))
             lst = new_lst
diff -r e02e9a56597f -r 52988f128d79 sympy/core/power.py
--- a/sympy/core/power.py       Fri Oct 17 15:48:22 2008 +0200
+++ b/sympy/core/power.py       Fri Oct 17 15:48:22 2008 +0200
@@ -502,7 +502,10 @@
                 # express "rest" as: rest = 1 + k*x**l + ... + O(x**n)
                 rest = ((base-prefactor)/prefactor).expand()
                 if rest == 0:
-                    return 1/prefactor
+                    # if prefactor == w**4 + x**2*w**4 + 2*x*w**4, we need to
+                    # factor the w**4 out using collect:
+                    from sympy import collect
+                    return 1/collect(prefactor, x)
                 if rest.is_Order:
                     return ((1+rest)/prefactor).expand()
                 if not rest.has(x):
@@ -580,7 +583,7 @@
         if o is S.Zero:
             r = (1+z)
         else:
-            if o.expr==1:
+            if o.expr.is_number:
                 e2 = ln(o2.expr*x)/ln(x)
             else:
                 e2 = ln(o2.expr)/ln(o.expr)
diff -r e02e9a56597f -r 52988f128d79 sympy/functions/elementary/exponential.py
--- a/sympy/functions/elementary/exponential.py Fri Oct 17 15:48:22 2008 +0200
+++ b/sympy/functions/elementary/exponential.py Fri Oct 17 15:48:22 2008 +0200
@@ -401,7 +401,7 @@
             o = C.Order(z, x)
             if o is S.Zero:
                 return ln(1+z)+ ln(arg0)
-            if o.expr==1:
+            if o.expr.is_number:
                 e = ln(order.expr*x)/ln(x)
             else:
                 e = ln(order.expr)/ln(o.expr)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-commits" group.
To post to this group, send email to sympy-commits@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sympy-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to