'sympy conversion function? :2*a*b + 2*a*c + 2*b*c --> 2*(a*b + b*c + c*a) : I want string ok

sympy conversion function?

2*a*b + 2*a*c + 2*b*c --> 2*(a*b + b*c + c*a) :

I want string ok

from sympy import *
var('a b c')
f=2*a*b+2*a*c+2*b*c
print("#f  ",f)
print("#f/2",f/2)
#f   2*a*b + 2*a*c + 2*b*c
#f/2 a*b + a*c + b*c

(2022-02-02)

i try factor

i try function

thank you

from sympy import factor, factor_terms
from sympy.abc import a,b,c
def myFactor(h):
    print("# factor       :",h,"--->",factor(h))
    print("# factor_terms :",h,"--->",factor_terms(h))
    return
myFactor(2*a*b + 2*a*c + 2*b*c)
myFactor(a**2 - b**2)
print("# factor:thank you")
# factor       : 2*a*b + 2*a*c + 2*b*c ---> 2*(a*b + a*c + b*c)
# factor_terms : 2*a*b + 2*a*c + 2*b*c ---> 2*(a*b + a*c + b*c)
# factor       : a**2 - b**2 ---> (a - b)*(a + b)
# factor_terms : a**2 - b**2 ---> a**2 - b**2
# factor:thank you


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source