Nice factor

I have a simple factorization problem in sympy that I cannot figure out. I had great success with nice work with fairly complex integrals, but I'm confused by something simple.

How do i get

phi**2 - 2*phi*phi_0 + phi_0**2 - 8

to multiply by

(phi - phi_0)**2 - 8

?

I already tried the function factor

factor(phi**2 - 2*phi*phi_0 + phi_0**2 - 8,phi-phi_0)

which gives the same old solution.

+3
source share
1 answer

As I noted in the commentary, such “partial factorizations” are not unique (for example, x**2 + 5*x + 7equal to (x + 2)*(x + 3) + 1and (x + 1)*(x + 4) + 3), and as soon as you understand what is happening, it’s not difficult to come up with examples of your own).

, , , , . , , :

>>> print(A.subs(phi, x + phi_0).factor().subs(x, phi - phi_0))
(phi - phi_0)**2 - 8

x = phi - phi_0 (SymPy , phi - phi_0 x, , phi x - phi_0, ). , , . , , , phi - phi_0 - , .

, , , , , . http://docs.sympy.org/latest/tutorial/manipulation.html, . Expr. , ​​, as_*.

+1

Source: https://habr.com/ru/post/1531159/


All Articles