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/CAHVvXxRj1O%3DyxxLJ9Pb5_REnReYx-7RPVeeOC%2BA%2BA8%2Bc%3DBduag%40mail.gmail.com.