code: def add(self, pattern: Pattern) -> int:
          
          inner = pattern.expression
          if self.operation is None:
              if not isinstance(inner, Operation) or isinstance(inner, CommutativeOperation):
                  raise TypeError("Pattern must be a non-commutative operation.")
              self.operation = type(inner)
          elif not isinstance(inner, self.operation):
              raise TypeError(
                  "All patterns must be the same operation, expected {} but got {}".format(self.operation, type(inner))
              )
  
          if op_len(inner) < 3:
              raise ValueError("Pattern has not enough operands.")
  
          operands = list(op_iter(inner))
  
          first_name = self._check_wildcard_and_get_name(operands[0])
          last_name = self._check_wildcard_and_get_name(operands[-1])
  
          index = len(self._patterns)
          self._patterns.append((pattern, first_name, last_name))
  
          flatterm = FlatTerm.merged(*(FlatTerm(o) for o in operands[1:-1]))
          self._net.add(flatterm, index)
  
          return index
docs: Add a pattern that will be recognized by the matcher.
  
          Args:
              pattern:
                  The pattern to add.
  
          Returns:
              An internal index for the pattern.
  
          Raises:
              ValueError:
                  If the pattern does not have the correct form.
              TypeError:
                  If the pattern is not a non-commutative operation.