# How to factor the coefficient This post is a wiki. Anyone with karma >750 is welcome to improve it.

I have the following code :

r,s,u= var('r s u')
U=u^4-A*u^2+17*B;U
eq1=U.subs({r:-21,s:324});eq1
factor(eq1)


which yields

(u^2 - 4281747124104997066155259836393062400)*(u^2 - 4281747146564836134743374782202380288)


My question : is there a code where I can factor the equation to yield something like this

(u^2 - 2^24*3^36*5^2*17*19^2*29*47^2*173)*(u^2 - 2^24*3^34*29*173*55229^2)


Because my aim is to look at the non-square numbers that appear in both factorization. In this case 29*173.

edit retag close merge delete

We cannot try your code without a proper definition for A and B.

Sort by » oldest newest most voted

Here is one way you could access the factorization you want.

First let's just define

sage: U = (u^2 - 4281747124104997066155259836393062400)*(u^2 - 4281747146564836134743374782202380288)


U is a symbolic expression, which is a product. Let's access the factors.

sage: a, b = U.operands()
sage: a
u^2 - 4281747124104997066155259836393062400
sage: b
u^2 - 4281747146564836134743374782202380288


Now each of a and b are also symbolic expressions, and they are sums. Let's access the summands.

sage: a0, a1 = a.operands()
sage: a0, a1
(u^2, -4281747124104997066155259836393062400)
sage: b0, b1 = b.operands()
sage: b0, b1
(u^2, -4281747146564836134743374782202380288)


Now we can factor a1 and b1 by first turning them into proper Sage integers.

sage: ZZ(a1).factor()
-1 * 2^24 * 3^36 * 5^2 * 17 * 19^2 * 29 * 47^2 * 173
sage: ZZ(b1).factor()
-1 * 2^24 * 3^34 * 29 * 173 * 55229^2


With a little work we could write a function that parses the expression tree and outputs a representation where each integer is decomposed into prime factors...

To get the squarefree part:

sage: bb1 = abs(ZZ(b1))
sage: bb1.squarefree_part()
5017
sage: bb1.squarefree_part().factor()
29 * 173

more