def RenamePredicate(e, old_name, new_name):
  """Renames predicate in a syntax tree."""
  renames_count = 0
  if isinstance(e, dict):
    if 'predicate_name' in e and e['predicate_name'] == old_name:
      e['predicate_name'] = new_name
      renames_count += 1
    # Field names are treated as predicate names for functors.
    if 'field' in e and e['field'] == old_name:
      e['field'] = new_name
      renames_count += 1
  if isinstance(e, dict):
    for k in e:
      if isinstance(e[k], dict) or isinstance(e[k], list):
        renames_count += RenamePredicate(e[k], old_name, new_name)
  if isinstance(e, list):
    for idx in range(len(e)):
      if isinstance(e[idx], dict) or isinstance(e[idx], list):
        renames_count += RenamePredicate(e[idx], old_name, new_name)
  return renames_count