On Apr 23, 11:11 pm, Bastian Weber <[email protected]>
wrote:
> Hi,
>
> smichr wrote:
> > One more thing. If you are working with noncommutatives, it would be
> > great to have you testing 1766. There is awareness there that isn't in
> > master yet:
>
> >>>> c, d=symbols('cd', commutative=0)
> >>>> (d**3).coeff(d**2)
> > 0
> >>>> (d**3).coeff(d**2, exact=0)
> > d
> >>>> a=d**2*c*d
> >>>> a.extract_multiplicatively(d**3)
> >>>> a.extract_multiplicatively(d**2)
> > c*d
>
> Thanks for the hints. The iterative list comprehension and
> extract_multiplicatively are the things that I was looking for. Great.
>
> >>>> a.extract_multiplicatively(d)
> > d**2*c
> >>>> a.coeff(c)
>
> > That last one results because you can't pull out everything and have
> > only c on the right.
>
> on my machine (with the your 1766 branch) I get
>
> In [29]: c, d = symbols('c d', commutative = False)
>
> In [30]: a = d**2 * c *d
>
> In [31]: a.coeff(c)
> Out[31]: d**2
>

I'm sorry, I must have copied and pasted incorrectly. The following
sequence may help:

>>> c, d = symbols('c d', commutative = False)
>>> eq=c*d
>>> eq.coeff(c)
1
  -> there is a 1 to the left of the c
>>> eq.coeff(d)
c
  -> there is a c to the left of the d
>>> eq.coeff(c,right=1)
d
  -> there is a d to the right of the c
>>> eq.coeff(d,right=1)
1
  -> there is a 1 to the right of the d
>>> var('x')
x
>>> eq.coeff(x)
>>>
>>> a.coeff(x,right=1)
>>>
  -> there is no x so there is no coefficient to the left (or right)
of it.

Working with your expression I get:

>>> a=d**2*c*d
>>> a.coeff(c)
d**2
>>> a.coeff(c, right=1)
d
>>> a.coeff(d)
1
>>> a.coeff(d**2,right=1)
c*d
>>> a.coeff(d,right=1)
c
 -> seems like this should be c*d or d*c*d, depending on whether you
mark from the start or finish of the 'd' term. I should look into this
after the other 1766 work is finished.

-- 
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.

Reply via email to