code: def legendre(n, monic=False):
      r"""Legendre polynomial.
  
      Defined to be the solution of
  
      .. math::
          \frac{d}{dx}\left[(1 - x^2)\frac{d}{dx}P_n(x)\right]
            + n(n + 1)P_n(x) = 0;
  
      :math:`P_n(x)` is a polynomial of degree :math:`n`.
  
      Parameters
      ----------
      n : int
          Degree of the polynomial.
      monic : bool, optional
          If `True`, scale the leading coefficient to be 1. Default is
          `False`.
  
      Returns
      -------
      P : orthopoly1d
          Legendre polynomial.
  
      Notes
      -----
      The polynomials :math:`P_n` are orthogonal over :math:`[-1, 1]`
      with weight function 1.
  
      Examples
      --------
      Generate the 3rd-order Legendre polynomial 1/2*(5x^3 + 0x^2 - 3x + 0):
  
      >>> from scipy.special import legendre
      >>> legendre(3)
      poly1d([ 2.5,  0. , -1.5,  0. ])
  
      """
      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
  
imports: from __future__ import division, print_function, absolute_import
  import numpy
  from numpy import exp, inf, pi, sqrt, floor, sin, cos, around, int, hstack, arccos, arange
  from scipy import linalg
  from scipy.special import airy
  from .None import _ufuncs
  from .None import _ufuncs
  from .None import specfun
  from ._ufuncs import binom, eval_jacobi, eval_sh_jacobi, eval_gegenbauer, eval_chebyt, eval_chebyu, eval_chebys, eval_chebyc, eval_sh_chebyt, eval_sh_chebyu, eval_legendre, eval_sh_legendre, eval_genlaguerre, eval_laguerre, eval_hermite, eval_hermitenorm
label_desc: Use image node_id 36 for calling a global function with example usage: legendre(n, monic) and returns: p