On 03/18/2012 10:19 PM, Aaron Meurer wrote:
On Sun, Mar 18, 2012 at 11:12 AM, Alan Bromborsky<[email protected]> wrote:
If a1 is commutative and e1 and e2 are not then
(a1*e1*e2).args_cnc() = [[a1], [e1, e2]]
and
(a1*e1*e1).args_cnc() = [[a1], [e1**2]]
is there anyway to make
(a1*e1*e1).args_cnc() = [[a1], [e1,e1]]
or in general to convert
e1**r to [e1,e1,...,e1] r-times
You could use something along the lines of what Chris said, but why do
you need to have r copies of e1? Wouldn't it be more efficient to
just add special handling for powers in whatever loop you have?
Aaron Meurer
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.
I wound up doing it with:
if isinstance(expr,Mul): #bases in expr
(coefs,bases) = expr.args_cnc()
if len(coefs) == 0: #expr_ij = 1
coefs = [ONE]
coef = Mul(*tuple(coefs))
new_bases = []
for base in bases:
if isinstance(base,Pow):
args = base.args
new_bases += args[1]*[args[0]]
else:
new_bases.append(base)
return(coef*fct(new_bases))
I wanted fct(new_bases) to deal with a consistent input.
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.