code: def legendre_poly(n, x=None, polys=False):
      r"""Generates the Legendre polynomial `P_n(x)`.
  
      Parameters
      ==========
  
      n : int
          Degree of the polynomial.
      x : optional
      polys : bool, optional
          If True, return a Poly, otherwise (default) return an expression.
      """
      return named_poly(
          n, dup_legendre, QQ, "Legendre polynomial", (x,), polys
      )
  
imports: from sympy.core.symbol import Dummy
  from sympy.polys.densearith import dup_mul, dup_mul_ground, dup_lshift, dup_sub, dup_add
  from sympy.polys.domains import ZZ, QQ
  from sympy.polys.polytools import named_poly
  from sympy.utilities import public
label_desc: Use image node_id 14 for calling a global function with example usage: legendre_poly(n, x, polys) and returns: named_poly