def legendre(n, monic=False):
 if (n < 0):
  raise ValueError('n must be nonnegative.')
 if (n == 0):
  n1 = (n + 1)
 else:
  n1 = n
 (x, w, mu0) = roots_legendre(n1, mu=True)
 if (n == 0):
  (x, w) = ([], [])
 hn = (2.0 / ((2 * n) + 1))
 kn = ((_gam(((2 * n) + 1)) / (_gam((n + 1)) ** 2)) / (2.0 ** n))
 p = orthopoly1d(x, w, hn, kn, wfunc=(lambda x: 1.0), limits=((-1), 1), monic=monic, eval_func=(lambda x: eval_legendre(n, x)))
 return p

def legendre ( n , monic = False ) : if ( n < 0 ) : raise ValueError ( 'n must be nonnegative.' ) if ( n == 0 ) : n1 = ( n + 1 ) else : n1 = n ( x , w , mu0 ) = roots_legendre ( n1 , mu = True ) if ( n == 0 ) : ( x , w ) = ( [ ] , [ ] ) hn = ( 2.0 / ( ( 2 * n ) + 1 ) ) kn = ( ( _gam ( ( ( 2 * n ) + 1 ) ) / ( _gam ( ( n + 1 ) ) ** 2 ) ) / ( 2.0 ** n ) ) p = orthopoly1d ( x , w , hn , kn , wfunc = ( lambda x : 1.0 ) , limits = ( ( - 1 ) , 1 ) , monic = monic , eval_func = ( lambda x : eval_legendre ( n , x ) ) ) return p
legendre polynomial .