Thanks a lot! I've been using a dummy symbol like
def collect_noncommutative(op,expr):
dummy= sympy.Symbol('dummy', commutative=True)
return expr.subs(op,dummy).collect(dummy).subs(dummy,op)
but I knew there had to be a implemented function I just wasn't able to
find it
El martes, 2 de noviembre de 2021 a las 16:48:17 UTC+1, Oscar escribió:
> On Tue, 2 Nov 2021 at 15:38, Gerardo Suarez <[email protected]> wrote:
> >
> > So basically I have a lot of objects like H:
> >
> > a= sympy.Symbol('a', commutative=False)
> > beta= sympy.Symbol('beta',commutative=True)
> > gamma= sympy.Symbol('\gamma',commutative=True)
> > ad = sympy.Symbol('a^{\dagger}', commutative=False)
> > H=gamma*ad*a+beta*ad*a
> >
> >
> > and all I wanna do is rewrite it as H=(gamma+beta)ad*a but using collect
> throws the error
> >
> > AttributeError: Can not collect noncommutative symbol
> >
> > is there any way to do this ?
>
> You can use factor_nc for noncommutative factorisation:
>
> In [4]: factor_nc(H)
> Out[4]: (\gamma + β)⋅a__{\dagger}⋅a
>
> I wanted to link to the docs but it doesn't look like it shows up in
> the web docs. You can see the code for it here:
>
> https://github.com/sympy/sympy/blob/d85530009457e4716ed91bfeee995e63fd057b94/sympy/core/exprtools.py#L1404
>
> --
> Oscar
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/8bfa57aa-2e6b-465b-9127-22a2ec232f18n%40googlegroups.com.