code: def gradient_factory(name):
      
  
      if name == 'sin':
          def gradient(self):
              """Return the gradient operator."""
              return cos(self.domain)
      elif name == 'cos':
          def gradient(self):
              """Return the gradient operator."""
              return -sin(self.domain)
      elif name == 'tan':
          def gradient(self):
              """Return the gradient operator."""
              return 1 + square(self.domain) * self
      elif name == 'sqrt':
          def gradient(self):
              """Return the gradient operator."""
              return FunctionalQuotient(ConstantFunctional(self.domain, 0.5),
                                        self)
      elif name == 'square':
          def gradient(self):
              """Return the gradient operator."""
              return ScalingFunctional(self.domain, 2.0)
      elif name == 'log':
          def gradient(self):
              """Return the gradient operator."""
              return reciprocal(self.domain)
      elif name == 'exp':
          def gradient(self):
              """Return the gradient operator."""
              return self
      elif name == 'reciprocal':
          def gradient(self):
              """Return the gradient operator."""
              return FunctionalQuotient(ConstantFunctional(self.domain, -1.0),
                                        square(self.domain))
      elif name == 'sinh':
          def gradient(self):
              """Return the gradient operator."""
              return cosh(self.domain)
      elif name == 'cosh':
          def gradient(self):
              """Return the gradient operator."""
              return sinh(self.domain)
      else:
          # Fallback to default
          gradient = Functional.gradient
  
      return gradient
docs: Create gradient `Functional` for some ufuncs.