1 | initial version |
If p is a simple polynomial with variable x, then sometimes the following (too) simple function can work
def rad_factor(p):
s=solve(p,x,multiplicities=True)
z=zip(map(lambda x:x.rhs(),s[0]),s[1])
return p.leading_coeff(x)*prod([(x-y[0])^y[1] for y in z])
2 | No.2 Revision |
If p is a simple polynomial with variable x, then sometimes the following (too) simple function can work
def rad_factor(p):
s=solve(p,x,multiplicities=True)
z=zip(map(lambda x:x.rhs(),s[0]),s[1])
return p.leading_coeff(x)*prod([(x-y[0])^y[1] for y in z])
Or using the suggestion by John Palmieri
def rad_factor(p):
return p.leading_coeff(x)*(prod((x-_[0])^_[1] for _ in p.roots()))