Re: [sympy] Re: Apply factor to subexpressions

2024-05-23 Thread Don Burgess
Thanks Oscar On Tuesday, May 21, 2024 at 4:32:56 PM UTC-4 Oscar wrote: > You can pass factor as the third argument to collect like collect(rhs, > ρ, factor). Then the collected coefficients will be factored. > > On Tue, 21 May 2024 at 21:27, Don Burgess wrote: > > > > Thank you very much for you

Re: [sympy] Re: Apply factor to subexpressions

2024-05-21 Thread Oscar Benjamin
You can pass factor as the third argument to collect like collect(rhs, ρ, factor). Then the collected coefficients will be factored. On Tue, 21 May 2024 at 21:27, Don Burgess wrote: > > Thank you very much for your helpful reply. > > Since I was using collect, I used the following code: > > ```py

[sympy] Re: Apply factor to subexpressions

2024-05-21 Thread Don Burgess
Thank you very much for your helpful reply. Since I was using collect, I used the following code: ```python import sympy as sp from sympy import sin, cos, atan, integrate, diff t,μ,ρ,ψ = sp.symbols(['t','μ','ρ','ψ']) rhs = 2*μ*(1 - ρ*cos(ψ)**2)*ρ*sin(ψ)**2 from sympy.simplify.fu import TR8 rhs

[sympy] Re: Apply factor to subexpressions

2024-05-21 Thread Chris Smith
This is what your code looks like after prefixing with ‘’’python and suffixing with ‘’’ (where back tics were used instead of single quotes): def factor_subexpressions(expr): """Factors all subexpressions of a SymPy expression. Args: expr: A SymPy expression. Returns: A SymPy expression with a

[sympy] Re: Apply factor to subexpressions

2024-05-21 Thread Chris Smith
I would use expr.factor(deep=True) and if that didn’t work, then expr.replace(lambda x: x.is_Mul or x.is_Add, lambda x: x.factor()). Regarding formatting in Google groups, see here where the rec