def METHOD_NAME(*matrices):
  """
  Compute the product of the given matrices. The matrices must all have
  elements of type Fraction or float. The type of the output will be the same
  as the type of the input.
  This function is not particularly efficient -- O(n^3) -- and is intended only
  for computing the product of matrices of fractions. The product of matrices
  of floats can be computed more efficiently by numpy or scipy.
  input:
    *matrices: the input matrices
  output:
    the product of inputs matrices
  """
  if len(matrices) == 1:
    return matrices[0]
  elif len(matrices) == 2:
    A, B = matrices
    (rows, size), (temp, cols) = A.shape, B.shape
    if size != temp:
      raise Exception('matrix dimensions do not match')
    dot = lambda U, V: sum(u * v for (u, v) in zip(U, V))
    vals = [[dot(A[r, :], B[:, c]) for c in range(cols)] for r in range(rows)]
    return np.array(vals)
  else:
    return METHOD_NAME(matrices[0], METHOD_NAME(*matrices[1:]))