On Apr 23, 2:29 pm, Bastian Weber <[email protected]>
wrote:
> Hello again,
>
>
>
> bastian.weber wrote:
> > Hello,
>
> > currently I have this behavior:
>
> > In <69>: (d**3).subs(d**2,k)
> > Out<69>: k**(3/2)
>
> > Is it somehow possible to get
>
> > In <69>: (d**3).subs(d**2,k)
> > Out<69>: d*k
>
I am doing the following in smichr's 1766 branch from github.
>>> from sympy import *
>>> var('k')
k
>>> d=symbols('d',noncommutative=True)
>>> eq.extract_multiplicatively(d**2)*k
d*k
>
> The expression which I want to handle reads:
>
> In <11>: m, d = symbols('m d', commutative = False)
> In <12>: a = 1 - 4*d**2 + 4*m**2 + d**4 + m**4 - 4*m*d - 2*m**2*d**2
> In <13>: div(a, d**2, d)
>
> of course, I get the SymbolsError too in that case.
>
> Any ideas for a workaround or an elegant solution would be very welcome.
>
My first attempt gives:
>>> a = type(a)(*[(arg.extract_multiplicatively(d**2) or arg/d)*d for arg in
>>> a.args]; a
)
1 - 4*d + 4*m**2 + d**3 + m**4 - 4*m*d - 2*m**2*d
...but that d**4 has become d**3. So either we write the list
comprehension as a loop and iterate until we've extracted all the d**2
or else we run the comprehension again until there is no change.
Running it once more gives
>>> a = type(a)(*[(arg.extract_multiplicatively(d**2) or arg/d)*d for arg in
>>> a.args]; a
)
1 - 4*d + d**2 + 4*m**2 + m**4 - 4*m*d - 2*m**2*d
which is, I think, what you were after?
--
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.