def _torational_factor_list(p, x):
 from sympy.simplify.simplify import simplify
 p1 = Poly(p, x, domain='EX')
 n = p1.degree()
 res = to_rational_coeffs(p1)
 if (not res):
  return None
 (lc, r, t, g) = res
 factors = factor_list(g.as_expr())
 if lc:
  c = simplify(((factors[0] * lc) * (r ** n)))
  r1 = simplify((1 / r))
  a = []
  for z in factors[1:][0]:
   a.append((simplify(z[0].subs({x: (x * r1)})), z[1]))
 else:
  c = factors[0]
  a = []
  for z in factors[1:][0]:
   a.append((z[0].subs({x: (x - t)}), z[1]))
 return (c, a)

def _torational_factor_list ( p , x ) : from sympy . simplify . simplify import simplify p1 = Poly ( p , x , domain = 'EX' ) n = p1 . degree ( ) res = to_rational_coeffs ( p1 ) if ( not res ) : return None ( lc , r , t , g ) = res factors = factor_list ( g . as_expr ( ) ) if lc : c = simplify ( ( ( factors [ 0 ] * lc ) * ( r ** n ) ) ) r1 = simplify ( ( 1 / r ) ) a = [ ] for z in factors [ 1 : ] [ 0 ] : a . append ( ( simplify ( z [ 0 ] . subs ( { x : ( x * r1 ) } ) ) , z [ 1 ] ) ) else : c = factors [ 0 ] a = [ ] for z in factors [ 1 : ] [ 0 ] : a . append ( ( z [ 0 ] . subs ( { x : ( x - t ) } ) , z [ 1 ] ) ) return ( c , a )
helper function to factor polynomial using to_rational_coeffs examples .