def root_factors(f, *gens, **args):
 args = dict(args)
 filter = args.pop('filter', None)
 F = Poly(f, *gens, **args)
 if (not F.is_Poly):
  return [f]
 if F.is_multivariate:
  raise ValueError('multivariate polynomials are not supported')
 x = F.gens[0]
 zeros = roots(F, filter=filter)
 if (not zeros):
  factors = [F]
 else:
  (factors, N) = ([], 0)
  for (r, n) in ordered(zeros.items()):
   (factors, N) = ((factors + ([Poly((x - r), x)] * n)), (N + n))
  if (N < F.degree()):
   G = reduce((lambda p, q: (p * q)), factors)
   factors.append(F.quo(G))
 if (not isinstance(f, Poly)):
  factors = [f.as_expr() for f in factors]
 return factors

def root_factors ( f , * gens , ** args ) : args = dict ( args ) filter = args . pop ( 'filter' , None ) F = Poly ( f , * gens , ** args ) if ( not F . is_Poly ) : return [ f ] if F . is_multivariate : raise ValueError ( 'multivariate polynomials are not supported' ) x = F . gens [ 0 ] zeros = roots ( F , filter = filter ) if ( not zeros ) : factors = [ F ] else : ( factors , N ) = ( [ ] , 0 ) for ( r , n ) in ordered ( zeros . items ( ) ) : ( factors , N ) = ( ( factors + ( [ Poly ( ( x - r ) , x ) ] * n ) ) , ( N + n ) ) if ( N < F . degree ( ) ) : G = reduce ( ( lambda p , q : ( p * q ) ) , factors ) factors . append ( F . quo ( G ) ) if ( not isinstance ( f , Poly ) ) : factors = [ f . as_expr ( ) for f in factors ] return factors
returns all factors of a univariate polynomial .