Status: Accepted
Owner: ----
Labels: Type-Defect Priority-Medium Series Simplify

New issue 3040 by asmeu...@gmail.com: Problem with simplify() with an expression with O()
http://code.google.com/p/sympy/issues/detail?id=3040

In [282]: simplify(collect((a/(x - alpha)).subs(alpha, (1 + sqrt(5))/2 + alpha1*x + alpha2*x**2 + alpha**3*x**3).series(x, 0, 4), x))
---------------------------------------------------------------------------
NonCommutativeExpression                  Traceback (most recent call last)
/Users/aaronmeurer/Documents/Python/sympy/sympy/<ipython-input-282-c34bd6241175> in <module>() ----> 1 simplify(collect((a/(x - alpha)).subs(alpha, (1 + sqrt(5))/2 + alpha1*x + alpha2*x**2 + alpha**3*x**3).series(x, 0, 4), x))

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/simplify/simplify.pyc in simplify(expr, ratio, measure)
   2696
   2697     expr1 = cancel(powsimp(expr))
-> 2698     expr2 = together(expr1.expand(), deep=True)
   2699     if ratio is S.Infinity:
   2700         expr = expr2

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/polys/rationaltools.pyc in together(expr, deep)
     81         return expr
     82
---> 83     return _together(sympify(expr))

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/polys/rationaltools.pyc in _together(expr)
     64                 return expr
     65             elif expr.is_Add:
---> 66 return gcd_terms(map(_together, Add.make_args(expr)))
     67             elif expr.is_Pow:
     68                 base = _together(expr.base)

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/exprtools.pyc in gcd_terms(terms, isprimitive)
    395     isexpr = isinstance(terms, Expr)
    396     if not isexpr or terms.is_Add:
--> 397         cont, numer, denom = _gcd_terms(terms, isprimitive)
    398         coeff, factors = cont.as_coeff_Mul()
    399         return _keep_coeff(coeff, factors*numer/denom)

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/exprtools.pyc in _gcd_terms(terms, isprimitive)
    348             return terms[0], S.One, S.One
    349
--> 350     terms = map(Term, terms)
    351     cont = terms[0]
    352

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/exprtools.pyc in __init__(self, term, numer, denom)
    233         if numer is None and denom is None:
    234             if not term.is_commutative:
--> 235 raise NonCommutativeExpression('commutative expression expected')
    236
    237             coeff, factors = term.as_coeff_mul()

NonCommutativeExpression: commutative expression expected

In [283]: simplify(collect((a/(x - alpha)).subs(alpha, (1 + sqrt(5))/2 + alpha1*x + alpha2*x**2 + alpha**3*x**3).series(x, 0, 4), x).removeO())
               ___
  3          ╲╱ 5     2       2    3  3
- ─ - α₁⋅x - ───── + x  - α₂⋅x  - α ⋅x
  2            2

In [284]: print a
alpha**2 - alpha*x**2 + alpha + x**3 - x*(alpha + 1)

Sorry for the complex example.  I don't have time to simplify it.

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

Reply via email to