Status: New
Owner: matt...@gmail.com
Labels: Type-Defect Priority-Medium Simplify
New issue 2439 by matt...@gmail.com: collect() should allow to apply a
function to coefficients
http://code.google.com/p/sympy/issues/detail?id=2439
I have the following expression:
In [1]: var('a')
Out[1]: a
In [2]: f = series(sqrt(sin(x) + a*x + 1), x, 0, 3)
In [3]: f
Out[3]:
2 2 2 2
x x a⋅x a⋅x a ⋅x
1 + ─ - ── + ─── - ──── - ───── + O(x**3)
2 8 2 4 8
In [4]: collect(_, x)
Out[4]:
⎛ 2 ⎞
⎛a 1⎞ 2 ⎜ a a 1⎟
1 + x⋅⎜─ + ─⎟ + x ⋅⎜- ── - ─ - ─⎟ + O(x**3)
⎝2 2⎠ ⎝ 8 4 8⎠
Now I would like to factor the coefficients of x**n. I can do:
In [5]: sum(map(factor, _.args[:-1]) + [_.args[-1]])
Out[5]:
2 2
x⋅(a + 1) x ⋅(a + 1)
1 + ───────── - ─────────── + O(x**3)
2 8
or using epath():
In [6]: epath("/[:-1]", _4, factor)
Out[6]:
2 2
x⋅(a + 1) x ⋅(a + 1)
1 + ───────── - ─────────── + O(x**3)
2 8
It would be much easier if I could simply write collect(f, x, factor) or
collect(f, x, coeff=factor). Mathematica's Collect[] supports the third
argument.
--
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.