code: def kmp_table(word):
      """Build the 'partial match' table of the Knuth-Morris-Pratt algorithm.
  
      Note: This is applicable to strings or
      quantum circuits represented as tuples.
      """
  
      # Current position in subcircuit
      pos = 2
      # Beginning position of candidate substring that
      # may reappear later in word
      cnd = 0
      # The 'partial match' table that helps one determine
      # the next location to start substring search
      table = []
      table.append(-1)
      table.append(0)
  
      while pos < len(word):
          if word[pos - 1] == word[cnd]:
              cnd = cnd + 1
              table.append(cnd)
              pos = pos + 1
          elif cnd > 0:
              cnd = table[cnd]
          else:
              table.append(0)
              pos = pos + 1
  
      return table
  
file_path: sympy/sympy/physics/quantum/circuitutils.py
imports: from functools import reduce
  from sympy.core.sorting import default_sort_key
  from sympy.core.containers import Tuple
  from sympy.core.mul import Mul
  from sympy.core.symbol import Symbol
  from sympy.core.sympify import sympify
  from sympy.utilities import numbered_symbols
  from sympy.physics.quantum.gate import Gate
label_desc: Use image node_id 1 for calling a global function with example usage: kmp_table(word) and returns: table