code: def mutate(tree: Tree, mutation: TreeMutation) -> None:
      """
      Apply a change to the structure of the tree
      Modifies not only the tree, but also the links between the TreeNodes
  
      Parameters
      ----------
      tree: Tree
          The tree to mutate
      mutation: TreeMutation
          The mutation to apply to the tree
      """
      tree.cache_up_to_date = False
  
      if mutation.kind == "prune":
          tree.remove_node(mutation.existing_node)
          tree.remove_node(mutation.existing_node.left_child)
          tree.remove_node(mutation.existing_node.right_child)
          tree.add_node(mutation.updated_node)
  
      if mutation.kind == "grow":
          tree.remove_node(mutation.existing_node)
          tree.add_node(mutation.updated_node.left_child)
          tree.add_node(mutation.updated_node.right_child)
          tree.add_node(mutation.updated_node)
  
      for node in tree.nodes:
          if node.right_child == mutation.existing_node:
              node._right_child = mutation.updated_node
          if node.left_child == mutation.existing_node:
              node._left_child = mutation.updated_node
  
file_path: imodels/imodels/experimental/bartpy/tree.py
imports: from typing import List
  import numpy
  from .mutation import TreeMutation
  from .node import TreeNode, LeafNode, DecisionNode, deep_copy_node
label_desc: Use image node_id 1 for calling a global function with example usage: mutate(tree, mutation) without return types