code: def main():
      print(__doc__)
  
      x = symbols("x")
  
      # a numpy array we can apply the ufuncs to
      grid = np.linspace(-1, 1, 1000)
  
      # set mpmath precision to 20 significant numbers for verification
      mpmath.mp.dps = 20
  
      print("Compiling legendre ufuncs and checking results:")
  
      # Let's also plot the ufunc's we generate
      for n in range(6):
          # Setup the SymPy expression to ufuncify
          expr = legendre(n, x)
          print("The polynomial of degree %i is" % n)
          pprint(expr)
  
          # This is where the magic happens:
          binary_poly = ufuncify(x, expr)
  
          # It's now ready for use with numpy arrays
          polyvector = binary_poly(grid)
  
          # let's check the values against mpmath's legendre function
          maxdiff = 0
          for j in range(len(grid)):
              precise_val = mpmath.legendre(n, grid[j])
              diff = abs(polyvector[j] - precise_val)
              if diff > maxdiff:
                  maxdiff = diff
          print("The largest error in applied ufunc was %e" % maxdiff)
          assert maxdiff < 1e-14
  
          # We can also attach the autowrapped legendre polynomial to a sympy
          # function and plot values as they are calculated by the binary function
          plot1 = plt.pyplot.plot(grid, polyvector, hold=True)
  
      print(
          "Here's a plot with values calculated by the wrapped binary functions"
      )
      plt.pyplot.show()
  
imports: import sys
  from sympy.external import import_module
  import mpmath
  from sympy.utilities.autowrap import ufuncify
  from sympy import symbols, legendre, pprint
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types